function Country(x){
	var temp=document.freg.fCountry_Ref.value;
	var tempS=document.freg.fState_A.value;
	//var tempB=document.freg.fInvoice_Add_Country.value;
	//var tempBS=document.freg.fInvoice_Add_State.value;
	if (x==1){
		if ((document.freg.fTel1_Loc.value == "") && (document.freg.fTel1_No.value == "")){
			if (temp.length>=5) {document.freg.fTel1_Nation.value = temp.substr(4,temp.length-4)}else{document.freg.fTel1_Nation.value=""}
		}
		if ((document.freg.fTel2_Loc.value == "") && (document.freg.fTel2_No.value == "")){
			if (temp.length>=5) {document.freg.fTel2_Nation.value = temp.substr(4,temp.length-4)}else{document.freg.fTel2_Nation.value=""}
		}
		if ((document.freg.fFax_Loc.value == "") && (document.freg.fFax_No.value == "")){
			if (temp.length>=5) {document.freg.fFax_Nation.value = temp.substr(4,temp.length-4)}else{document.freg.fFax_Nation.value=""}
		}		
		if (temp == '239#1'){
			document.freg.action=document.freg.action+'?Country=A#1';
			document.freg.submit();
		} else {
			if (tempS != 'N'){
				document.freg.action=document.freg.action+'?Country=A#1';
				document.freg.submit();
			}
		}
	}else if(x==2){
		var tempB=document.freg.fInvoice_Add_Country.value;
		var tempBS=document.freg.fInvoice_Add_State.value;	
		if (tempB == '239#1'){
			document.freg.action=document.freg.action+'?Country=B#2';
			document.freg.submit();
		} else {
			if (tempBS != 'N'){
				document.freg.action=document.freg.action+'?Country=B#2';
				document.freg.submit();
			}
		}
		}else if (x==3){
			document.freg.action=document.freg.action+'?Show=A#2';
			document.freg.submit();
		}
			else if (x==4){
			document.freg.action=document.freg.action+'?Show=B#2';
			document.freg.submit();
			}	
}
function PCountry(x){
	var temp=document.uProfile.fCountry_Ref.value;
	var tempS=document.uProfile.fState_A.value;
	if (x==1){
		if ((document.uProfile.fTel1_Loc.value == "") && (document.uProfile.fTel1_No.value == "")){
			if (temp.length>=5) {document.uProfile.fTel1_Nation.value = temp.substr(4,temp.length-4)}else{document.uProfile.fTel1_Nation.value=""}
		}
		if ((document.uProfile.fTel2_Loc.value == "") && (document.uProfile.fTel2_No.value == "")){
			if (temp.length>=5) {document.uProfile.fTel2_Nation.value = temp.substr(4,temp.length-4)}else{document.uProfile.fTel2_Nation.value=""}
		}
		if ((document.uProfile.fFax_Loc.value == "") && (document.uProfile.fFax_No.value == "")){
			if (temp.length>=5) {document.uProfile.fFax_Nation.value = temp.substr(4,temp.length-4)}else{document.uProfile.fFax_Nation.value=""}
		}		
		if (temp == '239#1'){
			document.uProfile.action=document.uProfile.action+'?Country=A';
			document.uProfile.submit();
		} else {
			if (tempS != 'N'){
				document.uProfile.action=document.uProfile.action+'?Country=A';
				document.uProfile.submit();
			}
		}
	}else if(x==2){
		var tempB=document.uProfile.fInvoice_Add_Country.value;
		var tempBS=document.uProfile.fInvoice_Add_State.value;	
		if (tempB == '239#1'){
			document.uProfile.action=document.uProfile.action+'?Country=B#2';
			document.uProfile.submit();
		} else {
			if (tempBS != 'N'){
				document.uProfile.action=document.uProfile.action+'?Country=B#2';
				document.uProfile.submit();
			}
		}
		}
				
}
function MaxLen(txtfield) {
	if (txtfield.value.length >= 200) {
		txtfield.value = txtfield.value.slice(0,199);
	}
}
function CheckTelNo(objForm, strField) {
	var Flag = true;

	if (strField == "Tel1") {
		if ((objForm.fTel1_Nation.value == "") || (objForm.fTel1_Loc.value == "") || (objForm.fTel1_No.value == ""))
			Flag = false;
	} else if (strField == "Tel2") {
		if ((objForm.fTel2_Nation.value == "") || (objForm.fTel2_Loc.value == "") || (objForm.fTel2_No.value == ""))
			Flag = false;
	} else if (strField == "Fax") {
		if ((objForm.fFax_Nation.value == "") || (objForm.fFax_Loc.value == "") || (objForm.fFax_No.value == ""))
			Flag = false;
	}

	return Flag;
}
function CheckEMail(mymail) {
	 n=mymail.length
	for (i=0; i< n; i++){
		if (((mymail.charCodeAt(i)==45) || (mymail.charCodeAt(i)==46) || (mymail.charCodeAt(i)==39) || (mymail.charCodeAt(i)==95) || ((mymail.charCodeAt(i)>=48) && (mymail.charCodeAt(i)<=57)) || ((mymail.charCodeAt(i)>=64) && (mymail.charCodeAt(i)<=90)) || ((mymail.charCodeAt(i)>=97) && (mymail.charCodeAt(i)<=122)))==false){
			return false;
			break;
			}
	}
			
	if (mymail.indexOf("@") < 1) {
		return false;
	}
	else if((mymail.indexOf("@")>(mymail.lastIndexOf(".")-2))||(mymail.lastIndexOf(".")==mymail.length-1)){
			return false;
	}
}

function IDC(objForm) {
	if (CheckEMail(objForm.IDEmail.value) == false) {
			alert("'"+objForm.IDEmail.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@digitimes.com'.");
			objForm.IDEmail.focus();
			return false;
	} else if (objForm.IDPassword.value=="" ) {
		alert ("Password is missing!");
		objForm.IDPassword.focus();
		return false;
	} else if (objForm.IDPassword.value.length<4 ) {
		alert ("Password must be 4 characters!");
		objForm.IDPassword.focus();
		return false;
	} 
	 return true;
}

function PWC(objForm) {
	if (objForm.PWOld.value=="" ) {
		alert ("Old password is missing!");
		objForm.PWOld.focus();
		return false;
	} else if (objForm.PWOld.value.length<4 ) {
		alert ("Password must be 4 characters!");
		objForm.PWOld.focus();
		return false;
	} else if (objForm.PWNew.value=="" ) {
		alert ("New password is missing!");
		objForm.PWNew.focus();
		return false;
	} else if (objForm.PWNew.value.length<4 ) {
		alert ("Password must be 4 characters!");
		objForm.PWNew.focus();
		return false;
	} else if ((objForm.PWNew.value != objForm.PWConfirm.value) || (objForm.PWNew.value == "")){
		alert("Your password confirmation does not match!");
		objForm.PWConfirm.focus();
		return false;
	}
	return true;
}

function CheckfReg(objForm) {
	if (CheckEMail(objForm.fEmail.value) == false) {
			alert("'"+objForm.fEmail.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@digitimes.com'.");
			objForm.fEmail.focus();
			return false;
	} else if (objForm.fPassword.value=="" ) {
		alert ("Password is missing!");
		objForm.fPassword.focus();
		return false;
	} else if (objForm.fPassword.value.length<4 ) {
		alert ("Password must be 4 characters!");
		objForm.fPassword.focus();
		return false;
	} else if ((objForm.fPassword.value != objForm.fReEnter.value) || (objForm.fPassword.value == "")){
		alert("Your password confirmation does not match!");
		objForm.fReEnter.focus();
		return false;
	} else if (objForm.fFirst_Name.value == "") {
		alert ("Please input your first name!");
		objForm.fFirst_Name.focus();
		return false;
	} else if (objForm.fSurname.value == "") {
		alert ("Please input your surname!");
		objForm.fSurname.focus();
		return false;
	 } else if (objForm.fAdd_Street.value=="") {
		alert ("Street is required!");
		objForm.fAdd_Street.focus();
		return false;
	} else if ( (objForm.fEmail2.value != "") && (CheckEMail(objForm.fEmail2.value) == false) ) {
		alert("'"+objForm.fEmail2.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@digitimes.com'.");
		objForm.fEmail2.focus();
		return false;
	}
	if (objForm.fTel1_No.value != "") {
		if (CheckTelNo(objForm, "Tel1") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel1_No.focus();
			return false;
			}
	}
	if (objForm.fTel2_No.value != "") {
		if (CheckTelNo(objForm, "Tel2") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel2_No.focus();
			return false;
			}
	} 
	if (objForm.fFax_No.value != "") {
		if (CheckTelNo(objForm, "Fax") == false) {
			alert ("Fax must include the country code, area code, and local phone number!");
			objForm.fFax_No.focus();
			return false;
		}
	}
	 return true;
}
function Renewal(objForm) {
	if (objForm.fFirst_Name.value == "") {
		alert ("Please input your first name!");
		objForm.fFirst_Name.focus();
		return false;
	} else if (objForm.fSurname.value == "") {
		alert ("Please input your surname!");
		objForm.fSurname.focus();
		return false;
	 } else if (objForm.fAdd_Street.value=="") {
		alert ("Street is required!");
		objForm.fAdd_Street.focus();
		return false;
	} else if ( (objForm.fEmail2.value != "") && (CheckEMail(objForm.fEmail2.value) == false) ) {
		alert("'"+objForm.fEmail2.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@digitimes.com'.");
		objForm.fEmail2.focus();
		return false;
	}
	if (objForm.fTel1_No.value != "") {
		if (CheckTelNo(objForm, "Tel1") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel1_No.focus();
			return false;
			}
	}
	if (objForm.fTel2_No.value != "") {
		if (CheckTelNo(objForm, "Tel2") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel2_No.focus();
			return false;
			}
	} 
	if (objForm.fFax_No.value != "") {
		if (CheckTelNo(objForm, "Fax") == false) {
			alert ("Fax must include the country code, area code, and local phone number!");
			objForm.fFax_No.focus();
			return false;
		}
	}
	 return true;
}

function CheckProfile(objForm) {
	if (objForm.fFirst_Name.value == "") {
		alert ("Please input your first name!");
		objForm.fFirst_Name.focus();
		return false;
	} else if (objForm.fSurname.value == "") {
		alert ("Please input your surname!");
		objForm.fSurname.focus();
		return false;
	 } else if (objForm.fAdd_Street.value=="") {
		alert ("Street is required!");
		objForm.fAdd_Street.focus();
		return false;
	} else if ( (objForm.fEmail2.value != "") && (CheckEMail(objForm.fEmail2.value) == false) ) {
		alert("'"+objForm.fEmail2.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@digitimes.com'.");
		objForm.fEmail2.focus();
		return false;
	} 

	if (objForm.fTel1_No.value != "") {
		if (CheckTelNo(objForm, "Tel1") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel1_No.focus();
			return false;
			}
	} 
	if (objForm.fTel2_No.value != "") {
		if (CheckTelNo(objForm, "Tel2") == false) {
			alert ("Telephone must include the country code, area code, and local phone number!");
			objForm.fTel2_No.focus();
			return false;
			}
	} 
	if (objForm.fFax_No.value != "") {
		if (CheckTelNo(objForm, "Fax") == false) {
			alert ("Fax must include the country code, area code, and local phone number!");
			objForm.fFax_No.focus();
			return false;
		}
	}	
	 return true;
}

function JoinCheck(objForm) {
	if  (objForm.EMail.value == "") {
		alert ("Email is missing!");
		objForm.EMail.focus();
		return false;
	} else if (CheckEMail(objForm.EMail.value) == false) {
		alert("'"+objForm.EMail.value+"' entered has a problem. Please check it is correct and includes no spaces or special characters. If in doubt, please email 'zoran@mail.digitimes.com.tw'.");
		objForm.EMail.focus();
		return false;
	} else if (objForm.Password.value=="" ) {
		alert ("Password is missing!");
		objForm.Password.focus();
		return false;
	} else if (objForm.Password.value.length<4 ) {
		alert ("Password must be 4 characters!");
		objForm.Password.focus();
		return false;
	}
	return true;
}
