
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}

function vote_picture( uc ){
	if( window.confirm('ต้องการที่จะโหวตรูปภาพนี้ !?') == true ) {
		mywindow=NewWindow('vote.php?uc='+uc,'mywin','150','100','no','center'); 
	}
}

	var alpha = "[^A-Za-zก-์ ิ-ู]";
	var alpha_th = "[^ก-์ ิ-ู]";
	var alpha_en = "[^A-Za-z]";
	var numeric = "[^0-9]";
	var numeric_d = "[^0-9.]";
	var numeric_m = "[^0-9\-_.]";
	var num_phone = "[^0-9\-#\ ]";
	var alpha_num = "[^A-Za-z0-9_]";
	var alpha_thnum = "[^A-Za-zก-์ ิ-ู0-9_]";
	var alnumhyphen = "[^A-Za-zก-์ ิ-ู0-9\-_.@]";


function doSubmitBook ( theform ) {
	if (typeof(theform.picture.label) == "undefined")	{
		var strLabel = "Security Code";
	} else {
		var strLabel =  theform.picture.label;
	}
	if (theform.picture.value.length > 2)	{
		var l_picture = theform.picture.value.toLowerCase();
		Temp = l_picture.charAt(l_picture.length-4) + l_picture.charAt(l_picture.length-3) + l_picture.charAt(l_picture.length-2) + l_picture.charAt(l_picture.length-1);

		if(Temp =='.jpg' || Temp =='.gif' || Temp =='jpeg' || Temp =='.png') {

		} else {
			strError = strLabel +" : จำเป็นต้องมีนามสกุล JPG, GIF, PNG เท่านั้น ";                        
			alert(strError); 
			theform.picture.focus();
			return false; 
		}
	} 

	if (typeof(theform.code.label) == "undefined")	{
		var strLabel = "Security Code";
	} else {
		var strLabel =  theform.code.label;
	}
	if (theform.sc.value != theform.code.value) {
		strError = strLabel +" : ไม่ถูกต้อง";                        
		alert(strError); 
		theform.code.focus();
		return false; 
	}

	if (typeof(theform.uname.label) == "undefined")	{
		var strLabel = "ชื่อของคุณ";
	} else {
		var strLabel =  theform.uname.label;
	}
	if (theform.uname.value.length > 0) {
		var charpos = theform.uname.value.search(alpha_thnum); 
		if (typeof(theform.uname.label) == "undefined")	{
			var strLabel = "ชื่อของคุณ";
			
		} else {
			var strLabel =  theform.uname.label;
		}
		if (charpos >= 0)	{
			strError = strLabel +" : ไม่สามารถกรอกตัวอักษรบางตัวได้";                        
			alert(strError + "\n [ผิดพลาดที่ตัวอักษรที่  " + eval(charpos+1)+"]"); 
			theform.uname.focus();
			return false; 
		}
	} else {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.uname.focus();
		return false; 
	}

	if (typeof(theform.email.label) == "undefined")	{
		var strLabel = "E-Mail";
	} else {
		var strLabel =  theform.email.label;
	}
	if (theform.email.value.length > 5) {
		if (!emailCheck(theform.email.value))	{
			strError = strLabel +" : รูปแบบไม่ถูกต้อง";                        
			alert(strError); 
			theform.email.focus();
			return false; 
		}
	} else {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 6 ตัวอักษร";                        
		alert(strError); 
		theform.email.focus();
		return false; 
	}

	if (typeof(theform.message.label) == "undefined")	{
		var strLabel = "ข้อความ";
	} else {
		var strLabel =  theform.message.label;
	}
	if (theform.message.value.length <= 0 {
		strError = strLabel + " : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.message.focus();
		return false; 
	}

	return true;
}

function doSubmitQuestion ( theform ) {
	if (typeof(theform.uname.label) == "undefined")	{
		var strLabel = "ชื่อของคุณ";
	} else {
		var strLabel =  theform.uname.label;
	}
	if (theform.uname.value.length > 0) {
		var charpos = theform.uname.value.search(alpha_thnum); 
		if (charpos >= 0)	{
			strError = strLabel +" : ไม่สามารถกรอกตัวอักษรบางตัวได้";                        
			alert(strError + "\n [ผิดพลาดที่ตัวอักษรที่  " + eval(charpos+1)+"]"); 
			theform.uname.focus();
			return false; 
		}
	} else {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.uname.focus();
		return false; 
	}

	if (typeof(theform.email.label) == "undefined")	{
		var strLabel = "E-Mail";
	} else {
		var strLabel =  theform.email.label;
	}
	if (theform.email.value.length > 5) {
		if (!emailCheck(theform.email.value))	{
			strError = strLabel +" : รูปแบบไม่ถูกต้อง";                        
			alert(strError); 
			theform.email.focus();
			return false; 
		}
	} else {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 6 ตัวอักษร";                        
		alert(strError); 
		theform.email.focus();
		return false; 
	}

	if (typeof(theform.subject.label) == "undefined")	{
		var strLabel = "คำถาม";
	} else {
		var strLabel =  theform.subject.label;
	}
	if (theform.subject.value.length <= 0) {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.subject.focus();
		return false; 
	}

	if (typeof(theform.detail.label) == "undefined")	{
		var strLabel = "รายละเอียด";
	} else {
		var strLabel =  theform.detail.label;
	}
	if (theform.detail.value.length <= 0) {
		strError = strLabel +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.detail.focus();
		return false; 
	}

	if (typeof(theform.code.label) == "undefined")	{
		var strLabel = "Security Code";
	} else {
		var strLabel =  theform.code.label;
	}
	if (theform.sc.value != theform.code.value) {
		strError = strLabel +" : ไม่ถูกต้อง";                        
		alert(strError); 
		theform.code.focus();
		return false; 
	}

	return true;
}

function doSubmitComment ( theform ) {
	if (theform.name.value.length > 0) {
		var charpos = theform.name.value.search(alpha_thnum); 
		if (charpos >= 0)	{
			strError = theform.name.label +" : ไม่สามารถกรอกตัวอักษรบางตัวได้";                        
			alert(strError + "\n [ผิดพลาดที่ตัวอักษรที่  " + eval(charpos+1)+"]"); 
			theform.name.focus();
			return false; 
		}
	} else {
		strError = theform.name.label +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.name.focus();
		return false; 
	}

	if (theform.comment.value.length <= 0) {
		strError = theform.comment.label +" : จำเป็นต้องกรอกข้อมูลอย่างน้อย 1 ตัวอักษร";                        
		alert(strError); 
		theform.comment.focus();
		return false; 
	}

	return true;
}

function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
	{
    	return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				return false
			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)

	if (domainArray==null) 
	{
    	return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	{
		return false
	}

	if (len<2) 
	{
		return false
	}
	return true;
}