/*
myURL = document.URL;

var myRegEx = new Array();
var myBaseURL = new Array();
var myImgURL = new Array();

myRegEx[0] = "clipmass.net";
myRegEx[1] = "tvmass.net";
myRegEx[2] = "search.clipmass.com";
myRegEx[3] = "forum.clipmass.com";
myRegEx[4] = "club.clipmass.com";
myRegEx[5] = "upload.clipmass.com";
myRegEx[6] = "video.clipmass.com";
myRegEx[7] = "static.clipmass.com";
myRegEx[8] = "live.clipmass.com";
myRegEx[9] = "tv.clipmass.com";
myRegEx[10] = "news.clipmass.com";
myRegEx[11] = "ads.clipmass.com";
myRegEx[12] = "music.clipmass.com";
myRegEx[13] = "game.clipmass.com";
myRegEx[14] = "s2pmedia.sytes.net";
myRegEx[15] = "s2pmedia";
myRegEx[16] = "clipmass.com";

myBaseURL[0] = "http://www.clipmass.net";
myBaseURL[1] = "http://www.tvmass.net";
myBaseURL[2] = "http://search.clipmass.com";
myBaseURL[3] = "http://forum.clipmass.com";
myBaseURL[4] = "http://club.clipmass.com";
myBaseURL[5] = "http://upload.clipmass.com";
myBaseURL[6] = "http://video.clipmass.com";
myBaseURL[7] = "http://static.clipmass.com";
myBaseURL[8] = "http://live.clipmass.com";
myBaseURL[9] = "http://tv.clipmass.com";
myBaseURL[10] = "http://news.clipmass.com";
myBaseURL[11] = "http://ads.clipmass.com";
myBaseURL[12] = "http://music.clipmass.com";
myBaseURL[13] = "http://game.clipmass.com";
myBaseURL[14] = "http://s2pmedia.sytes.net/clipmass";
myBaseURL[15] = "http://s2pmedia/clipmass_utf8";
myBaseURL[16] = "http://www.clipmass.com";

myImgURL[0] = "http://www.clipmass.net/images";
myImgURL[1] = "http://www.tvmass.net/images";
myImgURL[2] = "http://search.clipmass.com/images";
myImgURL[3] = "http://forum.clipmass.com/images";
myImgURL[4] = "http://club.clipmass.com/images";
myImgURL[5] = "http://upload.clipmass.com/images";
myImgURL[6] = "http://video.clipmass.com/images";
myImgURL[7] = "http://static.clipmass.com/images";
myImgURL[8] = "http://live.clipmass.com/images";
myImgURL[9] = "http://tv.clipmass.com/images";
myImgURL[10] = "http://news.clipmass.com/images";
myImgURL[11] = "http://ads.clipmass.com/images";
myImgURL[12] = "http://music.clipmass.com/images";
myImgURL[13] = "http://game.clipmass.com/images";
myImgURL[14] = "http://s2pmedia.sytes.net/clipmass/images";
myImgURL[15] = "http://s2pmedia/clipmass_utf8/images";
myImgURL[16] = "http://www.clipmass.com/images";

for (i = 0; i < myRegEx.length; i++) {
	myTest = new RegExp(myRegEx[i], "i");
	if (results = myURL.match(myTest)) {
		var baseurl = myBaseURL[i];
		var imgurl = myImgURL[i];
		i = myRegEx.length;
	}
}
*/

function copyShareCode(obj) {
	obj.focus();
	obj.select();
	textRange = obj.createTextRange();
	textRange.execCommand("RemoveFormat");
	textRange.execCommand("Copy");
	//alert("Copy code เรียบร้อยแล้วค่ะ สามารถนำไปใส่ในหน้าที่ต้องการได้ทันที โดยกด Ctrl + V ค่ะ");
}

function scoopPostValid(frm) {
	if (frm.news_title.value == "") {
		alert("กรุณาใส่ title ด้วยค่ะ");
		frm.news_title.focus();
		return false;
	}

	/*
	if (frm.news_detail.value == "") {
		alert("กรุณาใส่ รายละเอียด ด้วยค่ะ");
		frm.news_detail.focus();
		return false;
	}
	*/

	if (frm.news_cat_id.value == "") {
		alert("กรุณา เลือกหมวด ด้วยค่ะ");
		frm.news_cat_id.focus();
		return false;
	}

	return true;
}

function cm_stat(tracking_page) {
	if (tracking_page != "") {
		document.write ('<script language="javascript1.1">page="'+tracking_page+'";</script>');
	}
    document.write ('<script language="javascript1.1" src="http://hits.truehits.in.th/data/r0028370.js"></script>');
}

function fxShowAccInfo(a, b) {
	showMe(a);
	hideMe(b);	
}

function hideMe(myId) {
	document.getElementById(myId).style.display = "none";	
}

function showMe(myId) {
	document.getElementById(myId).style.display = "block";
}

function toggleVisibility(targetId) {
	if (document.getElementById) {
		target = document.getElementById(targetId);
		if (target.style.display == "none"){
			target.style.display = "block";
		} else {
			target.style.display = "none";
		}
	}
}

function addEmotion(fld, emo) {
	fld.value = fld.value + " " + emo + " ";
	fld.focus();
}

function showStars(num){
	for(i=1;i<=5;i++){
		if(i<=num){
			document.getElementById('star'+i).style.background='url('+imgurl+'/star.gif)';
			document.getElementById('star'+i).style.cursor="hand";
		}else{
			document.getElementById('star'+i).style.background='url('+imgurl+'/blank_star.gif)';
			document.getElementById('star'+i).style.cursor="hand";
		}
	}
}

function clearStars(){
	for(i=1;i<=5;i++){
		document.getElementById('star'+i).style.background='url('+imgurl+'/blank_star.gif)';
	}
}

function openShare() {
  var fs = window.open("share?v=f-IDNOL7dkU",
           "ShareVideo", "toolbar=no,width=" + 500  + ",height=" + 400
         + ",status=no,resizable=yes,fullscreen=no");
  fs.focus();
}

function valid(frm) {
	if (frm.txtName.value == "") {
		alert("กรุณาใส่ ชื่อด้วยค่ะ");
		frm.txtName.focus();
		return false;
	}

	if (frm.txtEmail.value == "") {
		alert("กรุณาใส่ อิเมล์ด้วยค่ะ");
		frm.txtEmail.focus();
		return false;
	}

	if (frm.txtSubject.value == "") {
		alert("กรุณาใส่ หัวข้อด้วยค่ะ");
		frm.txtSubject.focus();
		return false;
	}

	if (frm.txtDetail.value == "") {
		alert("กรุณาใส่ รายละเอียดด้วยค่ะ");
		frm.txtDetail.focus();
		return false;
	}

	return true;
}

function validUpload(frm) {
	var allow_extensions = /(avi|wmv|flv|mov|3gp|mp4|mpeg|mpg|divx|dat)$/i;

	if (frm.field_video_option.value == 1) {
		if (frm.videoFile.value != "") {
			if(!frm.videoFile.value.match(allow_extensions)) {
				var string = frm.videoFile.value;
				var num_of_last_slash = string.lastIndexOf("\\");

				if(num_of_last_slash < 1) { num_of_last_slash = string.lastIndexOf("/"); }

				var file_name = string.slice(num_of_last_slash + 1, string.length);
				var file_extension = file_name.slice(file_name.indexOf(".")).toLowerCase();
				
				alert('Sorry, uploading a file with the extension "' + file_extension + '" is not allowed.');
				return false;
			}
		} else {
			alert("กรุณาใส่ ไฟล์วีดีโอด้วยค่ะ");
			frm.videoFile.focus();
			return false;
		}
	} else {
		if (frm.field_embed_code.value == "") {
			alert("กรุณาใส่ Embed code ด้วยค่ะ");
			frm.field_embed_code.focus();
			return false;
		}

		if (frm.field_embed_thumb.value == "") {
			alert("กรุณาใส่ รูปวีดีโอ ด้วยค่ะ");
			frm.field_embed_thumb.focus();
			return false;
		}

	}

	if (frm.field_myvideo_title.value == "") {
		alert("กรุณาใส่ ไตเติ้ลวีดีโอด้วยค่ะ");
		frm.field_myvideo_title.focus();
		return false;
	}

	if (frm.field_myvideo_descr.value == "") {
		alert("กรุณาใส่ รายละเอียดวีดีโอด้วยค่ะ");
		frm.field_myvideo_descr.focus();
		return false;
	}

	if (frm.field_myvideo_keywords.value == "") {
		alert("กรุณาใส่ คำค้นหาวีดีโอด้วยค่ะ");
		frm.field_myvideo_keywords.focus();
		return false;
	}

	/*
	total = 0;
	//selectedChannels = "";
	for(var i=0; i < frm.chlist.length; i++){
		if(frm.chlist[i].checked) {
			total++;
			//if (selectedChannels == "") {
			//	selectedChannels = frm.chlist[i].value;
			//} else {
			//	selectedChannels += ", " + frm.chlist[i].value;
			//}
		}
	}
	if (total < 1 || total > 3) {
		alert("กรุณาเลือกช่องวีดีโอด้วยค่ะ");
		return false;
	}
	*/

	if (frm.chlist.value == "") {
		alert("กรุณาเลือกช่องวีดีโอด้วยค่ะ");
		frm.chlist.focus();
		return false;
	}

	//frm.upload.disabled = true;
	
	frm.upload_btn.disabled = true;

	//frm.chlist_selected.value = selectedChannels;

	return true;
}

function echeck(str) {

	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(str))) { 
		alert ("รูปแบบ email ไม่ถูกต้อง");
		return false;
	}
	return true;

/*
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("รูปแบบ email ไม่ถูกต้อง");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("รูปแบบ email ไม่ถูกต้อง");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("รูปแบบ email ไม่ถูกต้อง");
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("รูปแบบ email ไม่ถูกต้อง");
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("รูปแบบ email ไม่ถูกต้อง");
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("รูปแบบ email ไม่ถูกต้อง");
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("รูปแบบ email ไม่ถูกต้อง");
		return false;
	 }

	 return true;
*/
}

function trim(_data) {
  return _data.replace(/^\s+|\s+$/g, '');
}

function forumPostValid(frm) {
	err = 0;
	if (frm.name.value == "") {
		alert("กรุณาใส่ ชื่อ ด้วยค่ะ");
		frm.name.focus();
		err++;
		return false;
	}

	if (frm.email.value != "") {
		if (echeck(frm.email.value) == false) {
			err++;
			return false;
		}
	} else {
		alert("กรุณาใส่ email ของคุณด้วยค่ะ");
		frm.email.focus();
		err++;
		return false;
	}

	if (frm.forum_title.value == "") {
		alert("กรุณาใส่ หัวข้อ ด้วยค่ะ");
		frm.forum_title.focus();
		err++;
		return false;
	}

	/*
	if (frm.forum_detail.value == "") {
		alert("กรุณาใส่ รายละเอียด ด้วยค่ะ");
		frm.forum_detail.focus();
		err++;
		return false;
	}

	if (document.getElementById("forum_detail").value == "") {
		alert("กรุณาใส่ รายละเอียด ด้วยค่ะ");
		err++;
		return false;
	}

	if (frm.captcha.value == "") {
		alert("กรุณาใส่ รหัสรูปภาพ ด้วยค่ะ");
		frm.captcha.focus();
		err++;
		return false;
	}
	*/

	return true;
}

function forumReplyValid(frm) {
	err = 0;
	if (frm.name.value == "") {
		alert("กรุณาใส่ ชื่อ ด้วยค่ะ");
		frm.name.focus();
		err++;
		return false;
	}

	if (frm.email.value != "") {
		if (echeck(frm.email.value) == false) {
			err++;
			return false;
		}
	} else {
		alert("กรุณาใส่ email ของคุณด้วยค่ะ");
		frm.email.focus();
		err++;
		return false;
	}

	/*
	if (frm.detail.value == "") {
		alert("กรุณาใส่ รายละเอียด ด้วยค่ะ");
		frm.detail.focus();
		err++;
		return false;
	}

	if (document.getElementById("detail").value == "") {
		alert("กรุณาใส่ รายละเอียด ด้วยค่ะ");
		err++;
		return false;
	}

	if (frm.captcha.value == "") {
		alert("กรุณาใส่ รหัสรูปภาพ ด้วยค่ะ");
		frm.captcha.focus();
		err++;
		return false;
	}
	*/

	return true;
}


function send2CM(frm) {
	err = 0;
	if (frm.name.value == "") {
		alert("กรุณาใส่ ชื่อ ด้วยค่ะ");
		frm.name.focus();
		err++;
		return false;
	}

	if (frm.email.value != "") {
		if (echeck(frm.email.value) == false) {
			err++;
			return false;
		}
	} else {
		alert("กรุณาใส่ email ของคุณด้วยค่ะ");
		frm.email.focus();
		err++;
		return false;
	}

	if (frm.message.value == "") {
		alert("กรุณาใส่ ข้อความ ด้วยค่ะ");
		frm.message.focus();
		err++;
		return false;
	}

	/*
	if (frm.captcha.value == "") {
		alert("กรุณาใส่ รหัสรูปภาพ ด้วยค่ะ");
		frm.captcha.focus();
		err++;
		return false;
	}
	*/

	return true;
}

function openWind(theURL, Title, W, H, SB) {
	if (SB == "") {
		SB = "no";
	}
	wname = Title;
	windowX = Math.ceil((window.screen.width - W) / 2);
	windowY = Math.ceil((window.screen.height - H) / 2);
	window.open(theURL, wname, "scrollbars="+SB+", toolbar=no, location=0, directories=no, status=no, menubar=0, resizable=no, width="+W+", height="+H+", left="+windowX+", top="+windowY);
}

function printIframe(src, W, H, border, resize, scrolling, bgcolor, frameID) {

	if (src != "") srcF = " src='"+src+"'"; else srcF ="";
	if (W != "") WF = " width='"+W+"'"; else WF = " width='100";
	if (H != "") HF = " height='"+H+"'"; else HF = " height='100'";
	if (border != "") borderF = " frameborder='"+border+"'"; else borderF = " frameborder='0'";
	//if (resize == "yes") resizeF = " noresize"; else resizeF = "";
	if (scrolling != "") scrollingF = " scrolling='"+scrolling+"'"; else scrollingF = " scrolling='auto'";
	if (bgcolor != "") bgcolorF = " style='background-color: "+bgcolor+";'"; else bgcolorF = "background-color: transparent;";
	
	iframe = "<iframe marginwidth='0' marginheight='0'";
	iframe += srcF;
	iframe += WF;
	iframe += HF;
	iframe += borderF;
	//iframe += resizeF;
	iframe += scrollingF;
	iframe += bgcolorF;
	iframe += "></iframe>";
	//alert(iframe);
	document.write(""+iframe+"");

}

function copyit(field) {
	var temp = document.getElementById(field);
	temp.focus();
	temp.select();
	therange = temp.createTextRange();
	therange.execCommand("copy");
}

function switchClass(_obj, _cur, _over) {
	if (_obj.className != _cur) {
		_obj.className = _over;
	}
}

