/* This JavaScript use for iqfreetrial.aspx only */
function ResetUI()
{				
		document.getElementById("txtName").value = "";
		document.getElementById("rbtnOrganization").checked = true;
		document.getElementById("rbtnIndividual").checked = false;
		
		var position = document.getElementById("txtPosition");
		var company = document.getElementById("txtCompany");
		var businesstype = document.getElementById("txtBusinessType");
		
		position.value = "";
		position.disabled = false;			
		position.style.backgroundColor = "#ffffff";			
		position.style.borderColor = "#7F9DB9";
		position.style.borderWidth = 1;
		company.value = "";
		company.disabled = false;
		company.style.backgroundColor = "#ffffff";
		company.style.borderColor = "#7F9DB9"; 
		company.style.borderWidth = 1;
		businesstype.value = "";
		businesstype.disabled = false;
		businesstype.style.backgroundColor = "#ffffff";
		businesstype.style.borderColor = "#7F9DB9"; 
		businesstype.style.borderWidth = 1;
				
		document.getElementById("txtTelephone").value = "";
		document.getElementById("txtMail").value = "";
		return false;
}		

function ValidateForm(){
		var name = document.getElementById('txtName');	
		if (trimAll(name.value)==""){
			alert("กรุณากรอก ชื่อ-สกุล ด้วยค่ะ");
			name.focus();
			return false;
		}	
		
		
		var position = document.getElementById("txtPosition")
		var company = document.getElementById("txtCompany")
		var businesstype = document.getElementById("txtBusinessType")
		
		
		var rbtnOrganize = document.getElementById("rbtnOrganization")
		if (rbtnOrganize.checked) {						
			if (trimAll(position.value)==""){
				//alert("กรุณากรอก ตำแหน่ง ด้วยค่ะ");
				//position.focus();
				//return false;
			}		
			if (trimAll(company.value)==""){
				alert("กรุณากรอก บริษัท/หน่วยงาน ด้วยค่ะ");
				company.focus();
				return false;
			}
			if (trimAll(businesstype.value)==""){
				//alert("กรุณากรอก ลักษณะธุรกิจ ด้วยค่ะ");
				//businesstype.focus();
				//return false;
			}
		}				
		var txtTelephone=document.getElementById('txtTelephone');	
		if (trimAll(txtTelephone.value)==""){
			alert("กรุณากรอก เบอร์โทรศัพท์ ด้วยค่ะ");
			txtTelephone.focus();
			return false;
		}						
		var emailID=document.getElementById('txtMail');
		if (trimAll(emailID.value) == ""){
			alert("กรุณากรอก อีเมล์ ด้วยค่ะ");
			return false;
		}else{										
			if (echeck(emailID.value , 'อีเมล์') == false){			
				emailID.focus();
				return false;
			}						
		}															
		return true;
}			

function DisableTextBox()
{
	
	var position = document.getElementById("txtPosition")
	var company = document.getElementById("txtCompany")
	var businesstype = document.getElementById("txtBusinessType")
			
	var rbtnOrganize = document.getElementById("rbtnOrganization")
	if (rbtnOrganize.checked) {			
		position.disabled = false;			
		position.style.backgroundColor = "#ffffff";			
		position.style.borderColor = "#7F9DB9";
		position.style.borderWidth = 1;
		company.disabled = false;
		company.style.backgroundColor = "#ffffff";
		company.style.borderColor = "#7F9DB9"; 
		company.style.borderWidth = 1;
		businesstype.disabled = false;
		businesstype.style.backgroundColor = "#ffffff";
		businesstype.style.borderColor = "#7F9DB9"; 
		businesstype.style.borderWidth = 1;
						
	}else{
		//document.getElementById("").style.borderColor
		position.disabled = true;
		position.style.backgroundColor = "#E8E8E8";					
		company.disabled = true;	
		company.style.backgroundColor = "#E8E8E8";			
		businesstype.disabled = true;
		businesstype.style.backgroundColor = "#E8E8E8";						
	}	
}


function echeck(str , txtboxname) 
{
	var at="@"
	var dot="."
	var comma=","
	var semecolon=";"
	var colon=":";
	var star="*";
	var flankOpen="{";
	var flankClose="}";
	var parenthesesOpen="(";
	var parenthesesClose=")";
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");		
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false;
	}
	if (str.indexOf(comma)!=-1 || str.indexOf(semecolon)!=-1 || str.indexOf(colon)!=-1 || str.indexOf(flankOpen)!=-1 || str.indexOf(flankClose)!=-1 || str.indexOf(parenthesesOpen)!=-1 || str.indexOf(parenthesesClose)!=-1){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false
	}
	/*		
	if (str.indexOf(" ")!=-1){
		alert("กรุณาตรวจสอบความถูกต้องของ " + txtboxname + " อีกครั้งค่ะ");	
		return false
	}
	*/
 	return true;				
}			

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;			
}