// APSIPA
// for reg.asp
function FormSubmit(sFormId,sTarget,sAction,sMethod)
{// form submit
	var x=document.getElementById(sFormId);
	if(x==null){return false;}
	x.target=sTarget;
	x.action=sAction;
	x.method=sMethod;
	x.submit();
	return true;
}
function DisplayAlertMsg(sAlertId,sMsg)
{
	var y=document.getElementById(sAlertId);
	if(y!=null){y.innerHTML=sMsg;}
}
function IsRadioNotEmtpy(radioObject,sAlertId,sMsg)
{// return true if the radio input is not empty. Otherwise, false.
// also show the alert message at the specific location.
	var b;var y;var i,N;
	try{
		if(radioObject!=null){
			N=radioObject.length;b=false;
			for(i=0;i<N && b==false;i++){
				if(radioObject[i].checked){b=true;}
			}
			y=document.getElementById(sAlertId);
			if(y!=null){y.innerHTML=b?"":sMsg;}
			return b;
		}else{return false;}
	}catch(err){
		s="Error.\n\n";
		//s+="IsRadioNotEmtpy(). " + err.description + "\n\n";
		s+=err.description + "\n\n";
		alert(s);
		return false;
	}
}
function IsSelectNotEmpty(sId,sNull,sAlertId,sMsg)
{// return true if the "select" input is not empty. Otherwise, false.
// also show the alert message at the specific location.
	var x;var b;var i;
	try{
		x=document.getElementById(sId);
		if(x!=null){
			i=x.options[x.selectedIndex].text.indexOf(sNull);
			b=(i==0)?false:true;//x.options[x.selectedIndex].value
			y=document.getElementById(sAlertId);
			if(y!=null){y.innerHTML=b?"":sMsg;}
			return b;
		}else{return false;}
	}catch(err){
		s="Error.\n\n";
		//s+="IsSelectNotEmpty(). " + err.description + "\n\n";
		s+=err.description + "\n\n";
		alert(s);
		return false;
	}
}
function IsTxtNotEmpty_main(sValue)
{// return true if not empty. Otherwise, false.
	if(sValue.length<1){return false;}
	return true;
}

function IsTxtLenChar(sId,sAlertId,sMsg, sMin, sMax)
{
	// return true if the lenght in between sMin and sMax. Otherwise, false.
// also show the alert message at the specific location.
	var b;var y;
	var x=document.getElementById(sId);
	if(x!=null){
		b=(x.value.length>=sMin && x.value.length<=sMax)?true:false;// validation
		y=document.getElementById(sAlertId);
		if(y!=null){y.innerHTML=b?"":sMsg;}
		return b;
	}else{return false;}
	
}
function IsTxtNotEmpty(sId,sAlertId,sMsg)
{// return true if not empty. Otherwise, false.
// also show the alert message at the specific location.
	var b;var y;
	var x=document.getElementById(sId);
	if(x!=null){
		b=(x.value.length>0)?true:false;// validation
		y=document.getElementById(sAlertId);
		if(y!=null){y.innerHTML=b?"":sMsg;}
		return b;
	}else{return false;}
}

function IsTxtNotEmpty2(sId,sAlertId,sMsg)
{// return true if not empty. Otherwise, false.
// also show the alert message at the specific location.
	var b;var y;
	var x=document.getElementById(sId);
	if(x!=null){
		b=(x.value.length>0)?true:false;// validation
		
		return b;
	}else{return false;}
}
function IsEmail_main(sValue)
{// return true if the email address is valid. Otherwise false.
	var s="";
	var i;
	try{
		i=sValue.indexOf("@");
		if(i<1){return false;}
		else{
			if(sValue.indexOf(".",i)<(i+2)){return false;}
		}
		return true;
	}catch(err){
		s="Error.\n\n";
		//s+="IsEmail_main(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
}
function IsEmail(sId,sAlertId,sMsg)
{// return true if the email address is valid. Otherwise false.
// also show the alert message at the specific location.
	var b;var y;
	var x=document.getElementById(sId);
	if(x!=null){
		b=IsEmail_main(x.value);
		y=document.getElementById(sAlertId);
		if(y!=null){y.innerHTML=b?"":sMsg;}
		return b;
	}else{return false;}
}
function IsPasswordSame_main(s1,s2)
{// return true if two passwords are same. Otherwise false.
	var s;var i,i2;
	try{
		i1=s1.indexOf(s2);
		i2=s2.indexOf(s1);
		if((i1==0) && (i2==0)){return true;}
		else{return false;}
	}catch(err){
		s="Error.\n\n";
		s+="IsPasswordSame_main(). " + err.description + "\n\n";
		alert(s);
		return false;
	}
}
function IsPasswordSame(sId1,sId2,sAlertId,sMsg)
{// return true if two passwords are same. Otherwise false.
// also show the alert message at the specific location.
	var y;var b=false;var i1,i2;
	var x1=document.getElementById(sId1);
	var x2=document.getElementById(sId2);
	if((x1!=null) && (x2!=null)){
		b=IsPasswordSame_main(x1.value,x2.value);
		y=document.getElementById(sAlertId);
		if(y!=null){y.innerHTML=b?"":sMsg;}
		return b;
	}else{return false;}
	return false;
}

////////////////////////////// 
/*
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))){ return false;}
    }
    // All characters are numbers.
    return true;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}

function IsDateT(sYearId,sMonthId,sDayId,sAlertId)
{// is the date valid?
	var minYear=1800;
	var maxYear=2100;
	var iYear,iMonth,iDay;
	var daysInMonth = DaysArray(12);
	var y;var b=false;
	var x1=document.getElementById(sYearId);
	var x2=document.getElementById(sMonthId);
	var x3=document.getElementById(sDayId);
	if(x1!=null && x2!=null && x3!=null){
		y=document.getElementById(sAlertId);
		if ((isInteger(x1.value)==false) || (isInteger(x2.value)==false) || (isInteger(x3.value)==false)){
			if(y!=null){y.innerHTML="<< Please input a valid date!";}
			return false;
		}
		iYear=parseInt(x1.value,10);
		iMonth=parseInt(x2.value,10);
		iDay=parseInt(x3.value,10);
		if (iMonth<1 || iMonth>12){
			if(y!=null){y.innerHTML="<< Invalid month!";}
			return false;
		}
		if (iDay<1 || iDay>31 || (iMonth==2 && iDay>daysInFebruary(iYear)) || iDay > daysInMonth[iMonth]){
			if(y!=null){y.innerHTML="<< Invalid day!";}
			return false;
		}
		if (iYear==0 || iYear<minYear || iYear>maxYear){
			//if(y!=null){y.innerHTML="Please enter a valid 4 digit year between "+minYear+" and "+maxYear;}
			if(y!=null){y.innerHTML="<< Invalid year!";}
			return false;
		}
	}else{return false;}

	return true;
}
//////////////////////////////
function FormFirstValidationReg()
{// form validation for reg.asp
	var s;var x;var b,bb,b3,b4;
	var sEmpty,sEmail,sPassword,sLen,sAlertNonEnglish;
	b=true;
	// define the error message
	sEmpty="<< This field is required!";	
	//sEmail="<< Invalid email address!";
	sLen="<< Password must be 6-20 characters!";
	sPassword="<< Two passwords are different!";
	sAlertNonEnglish = "<< Allow English Only!";
	
	try{
		// empty validation
		bb=IsTxtNotEmpty("txtUserID","a_userID",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtUserID", "a_userID", sAlertNonEnglish); b=b&&bb;
		}

		// email address validation
		//if(bb){bb=IsEmail("txtUserID","a_userID",sEmail);b=b && bb;}
		
		// password validation

		bb=IsTxtLenChar("txtPwd","a_pwd",sLen,6,20);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtPwd", "a_pwd", sAlertNonEnglish); b=b&&bb;
		}
		
		b3=IsTxtLenChar("txtPwd2","a_pwd2",sLen,6,20);b=b && b3;
		if(bb && b3){bb=IsPasswordSame("txtPwd","txtPwd2","a_pwd2",sPassword);b=b && bb;}

		// radio validation
		bb=IsRadioNotEmtpy(document.reg.member,"a_member",sEmpty);b=b && bb;	

		
	}catch(err){
		s="Error.\n\n";
		//s+="FormValidationReg(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	return b;
}
//////////////////////////////
function FormValidationReg()
{// form validation for reg.asp
	var s;var x;var b,bb,b3,b4;var sEmpty,sEmail,sPassword,sLen,sBirth;
	var b5,b6,b7;
	b=true;
	// define the error message
	sEmpty="<< This field is required!";
	sBirth="<< Invaild Date!";
	sEmail="<< Invalid email address!";
	sLen="<< Password must be 6-20 characters!";
	sPassword="<< Two passwords are different!";
	try{
		// empty validation
		bb=IsTxtNotEmpty("txtUserID","a_userID",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtFamName","a_famName",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtGivenName","a_givenName",sEmpty);b=b && bb;
		//bb=IsTxtNotEmpty("txtUniversity","a_university",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtAffiliation","a_affiliation",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtPosition","a_position",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtAddline1","a_addline1",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtCity","a_city",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtOrganName","a_OrganName",sEmpty);b=b && bb;

		// email address validation
		if(bb){bb=IsEmail("txtUserID","a_userID",sEmail);b=b && bb;}
		
		// password validation
		//bb=IsTxtNotEmpty("txtPwd","a_pwd",sEmpty);b=b && bb;
		//b3=IsTxtNotEmpty("txtPwd2","a_pwd2",sEmpty);b=b && b3;
		bb=IsTxtLenChar("txtPwd","a_pwd",sLen,6,20);b=b && bb;
		b3=IsTxtLenChar("txtPwd2","a_pwd2",sLen,6,20);b=b && b3;
		if(bb && b3){bb=IsPasswordSame("txtPwd","txtPwd2","a_pwd2",sPassword);b=b && bb;}

		// birth validation
		//bb=IsTxtNotEmpty("txtBirthDay","a_birth",sEmpty);b=b && bb;
		//b3=IsTxtNotEmpty("txtBirthMonth","a_birth",sEmpty);b=b && b3;
		//b4=IsTxtNotEmpty("txtBirthYear","a_birth",sEmpty);b=b && b4;
		b5=IsTxtNotEmpty2("txtBirthDay","","");//b=b && bb;
		b6=IsTxtNotEmpty2("txtBirthMonth","","");//b=b && b3;
		b7=IsTxtNotEmpty2("txtBirthYear","","");//b=b && b4;
		
		if(b5 && b6 && b7)
		{			
			bb=IsDateT("txtBirthYear","txtBirthMonth","txtBirthDay","a_birth");
			b=b && bb;
		}
		else
		{		
			if(b5 || b6 || b7)
			{
				DisplayAlertMsg("a_birth",sBirth);b=b && false;
							
			}
			else{DisplayAlertMsg("a_birth","");}
		}		

		// radio validation
		bb=IsRadioNotEmtpy(document.reg.gender,"a_gender",sEmpty);b=b && bb;
		bb=IsRadioNotEmtpy(document.reg.member,"a_member",sEmpty);b=b && bb;
		bb=IsRadioNotEmtpy(document.reg.addType,"a_addType",sEmpty);b=b && bb;
		
		bb=IsRadioNotEmtpy(document.reg.title,"a_Title",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdoTitleOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtOtherTitle","a_Title",sEmpty);b=b && bb;}
			}
		}
		
		// highDeg validation
		bb=IsRadioNotEmtpy(document.reg.highDeg,"a_highDeg",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdohighDegOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtHighDeg","a_highDeg",sEmpty);b=b && bb;}
			}
		}

		// select input validation
		bb=IsSelectNotEmpty("selectCountry","Please select a country","a_country",sEmpty);b=b && bb;
	}catch(err){
		s="Error.\n\n";
		//s+="FormValidationReg(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	return b;
}

//////////////////////////////
function FormNextStdValidationReg()
{// form validation for reg.asp
	var s;var x;var b,bb,b3,b4;var sEmpty,sEmail,sBirth,sAlertNonEnglish;
	var b5,b6,b7;
	sAlertNonEnglish = "<< Allow English Only!";
	b=true;
	// define the error message
	sEmpty="<< This field is required!";
	sBirth="<< Invaild Date!";
	sEmail="<< Invalid email address!";

	try{
		// empty validation
		//bb=IsTxtNotEmpty("txtUserID","a_userID",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtFamName","a_famName",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtFamName", "a_famName", sAlertNonEnglish); b=b&&bb;
		}
		
		
		bb=IsTxtNotEmpty("txtGivenName","a_givenName",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtGivenName", "a_givenName", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtUniversity","a_university",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtUniversity", "a_university", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtAffiliation","a_affiliation",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAffiliation", "a_affiliation", sAlertNonEnglish); b=b&&bb;
		}
		//bb=IsTxtNotEmpty("txtPosition","a_position",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtAddline1","a_addline1",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAddline1", "a_addline1", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtCity","a_city",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCity", "a_city", sAlertNonEnglish); b=b&&bb;
		}
		//bb=IsTxtNotEmpty("txtOrganName","a_OrganName",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtEmail","a_email",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtEmail", "a_email", sAlertNonEnglish); b=b&&bb;
		}
		
		bb=IsTxtNotEmpty("txtCountry","a_country",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCountry", "a_country", sAlertNonEnglish); b=b&&bb;
		}
		

		// email address validation
		if(bb){bb=IsEmail("txtEmail","a_email",sEmail);b=b && bb;}
		
		
		
		b5=IsTxtNotEmpty2("txtBirthDay","","");//b=b && bb;
		b6=IsTxtNotEmpty2("txtBirthMonth","","");//b=b && b3;
		b7=IsTxtNotEmpty2("txtBirthYear","","");//b=b && b4;
		
		if(b5 && b6 && b7)
		{			
			bb=IsDateT("txtBirthYear","txtBirthMonth","txtBirthDay","a_birth");
			b=b && bb;
		}
		else
		{		
			if(b5 || b6 || b7)
			{
				DisplayAlertMsg("a_birth",sBirth);b=b && false;
							
			}
			else{DisplayAlertMsg("a_birth","");}
		}		

		// radio validation
		bb=IsRadioNotEmtpy(document.regnext.gender,"a_gender",sEmpty);b=b && bb;		
		bb=IsRadioNotEmtpy(document.regnext.addType,"a_addType",sEmpty);b=b && bb;
		
		bb=IsRadioNotEmtpy(document.regnext.title,"a_Title",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdoTitleOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtOtherTitle","a_Title",sEmpty);b=b && bb;}
			}
		}
		
		// highDeg validation
		bb=IsRadioNotEmtpy(document.regnext.highDeg,"a_highDeg",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdohighDegOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtHighDeg","a_highDeg",sEmpty);b=b && bb;}
			}
		}

		// select input validation
		//bb=IsSelectNotEmpty("selectCountry","Please select a country","a_country",sEmpty);b=b && bb;
	}catch(err){
		s="Error.\n\n";
		//s+="FormValidationReg(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	return b;
}

//////////////////////////////
function FormNextValidationReg()
{// form validation for reg.asp
	var s;var x;var b,bb,b3,b4;var sEmpty,sEmail,sPassword,sLen,sBirth,sAlertNonEnglish;
	var b5,b6,b7;
	b=true;
	// define the error message
	sEmpty="<< This field is required!";
	sBirth="<< Invaild Date!";
	sEmail="<< Invalid email address!";
	sLen="<< Password must be 6-20 characters!";
	sPassword="<< Two passwords are different!";
	sAlertNonEnglish = "<< Allow English Only!";
	try{
		// empty validation
		
		bb=IsTxtNotEmpty("txtFamName","a_famName",sEmpty);b=b && bb;
		
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtFamName", "a_famName", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtGivenName","a_givenName",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtGivenName", "a_givenName", sAlertNonEnglish); b=b&&bb;
		}		
		bb=IsTxtNotEmpty("txtAffiliation","a_affiliation",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAffiliation", "a_affiliation", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtPosition","a_position",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtPosition", "a_position", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtAddline1","a_addline1",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAddline1", "a_addline1", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtCity","a_city",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCity", "a_city", sAlertNonEnglish); b=b&&bb;
		}
		//bb=IsTxtNotEmpty("txtOrganName","a_OrganName",sEmpty);b=b && bb;
		bb=IsTxtNotEmpty("txtEmail","a_email",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtEmail", "a_email", sAlertNonEnglish); b=b&&bb;
		}
		bb=IsTxtNotEmpty("txtCountry","a_country",sEmpty);b=b && bb;
		// added by wai 090611
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCountry", "a_country", sAlertNonEnglish); b=b&&bb;
		}

		// email address validation
		if(bb){bb=IsEmail("txtEmail","a_email",sEmail);b=b && bb;}
		
		// birth validation
		//bb=IsTxtNotEmpty("txtBirthDay","a_birth",sEmpty);b=b && bb;
		//b3=IsTxtNotEmpty("txtBirthMonth","a_birth",sEmpty);b=b && b3;
		//b4=IsTxtNotEmpty("txtBirthYear","a_birth",sEmpty);b=b && b4;
		b5=IsTxtNotEmpty2("txtBirthDay","","");//b=b && bb;
		b6=IsTxtNotEmpty2("txtBirthMonth","","");//b=b && b3;
		b7=IsTxtNotEmpty2("txtBirthYear","","");//b=b && b4;
		
		if(b5 && b6 && b7)
		{			
			bb=IsDateT("txtBirthYear","txtBirthMonth","txtBirthDay","a_birth");
			b=b && bb;
		}
		else
		{		
			if(b5 || b6 || b7)
			{
				DisplayAlertMsg("a_birth",sBirth);b=b && false;
							
			}
			else{DisplayAlertMsg("a_birth","");}
		}		

		// radio validation
		bb=IsRadioNotEmtpy(document.regnext.gender,"a_gender",sEmpty);b=b && bb;
		bb=IsRadioNotEmtpy(document.regnext.addType,"a_addType",sEmpty);b=b && bb;
		
		bb=IsRadioNotEmtpy(document.regnext.title,"a_Title",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdoTitleOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtOtherTitle","a_Title",sEmpty);b=b && bb;}
			}
		}
		
		// highDeg validation
		bb=IsRadioNotEmtpy(document.regnext.highDeg,"a_highDeg",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdohighDegOther");
			if(x!=null){
				if(x.checked==true){bb=IsTxtNotEmpty("txtHighDeg","a_highDeg",sEmpty);b=b && bb;}
			}
		}

		// select input validation
		//bb=IsSelectNotEmpty("selectCountry","Please select a country","a_country",sEmpty);b=b && bb;
	}catch(err){
		s="Error.\n\n";
		//s+="FormValidationReg(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	return b;
}
function GetCountry()
{// get the full name of the country
	var s;
	try{
		var x1=document.getElementById("selectCountry");
		var x2=document.getElementById("txtCountry2");
		if(x1!=null && x2!=null){
			x2.value=x1.options[x1.selectedIndex].text;// store in the hidden input
		}
	}catch(err){
		s="Error.\n\n";
		s+="GetCountry(). " + err.description + "\n\n";
		alert(s);
	}
}
function FormSubmitReg()
{// form submit for reg.asp
	var b;
	GetCountry();// get the full name of the country
	b=FormValidationReg();
	if(b==true){
		b=FormSubmit('reg','_self','ShowMemberInput.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#reg";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

function FormNextSubmitReg()
{// form submit for reg.asp
	var b;
	GetCountry();// get the full name of the country
	b=FormNextValidationReg();
	if(b==true){
		b=FormSubmit('regnext','_self','ShowMemberInput.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#regnext";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

function FormNextStdSubmitReg()
{// form submit for reg.asp
	var b;
	GetCountry();// get the full name of the country
	b=FormNextStdValidationReg();
	if(b==true){
		b=FormSubmit('regnext','_self','ShowMemberInput.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#regnext";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

function FormFirstSubmitReg()
{// form submit for reg.asp
	var b;
	GetCountry();// get the full name of the country
	b=FormFirstValidationReg();
	if(b==true){
		b=FormSubmit('reg','_self','redirect.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#reg";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

function FormSubmitAdminLogin()
{// form submit for reg.asp
	var b;	
	b=FormValidationLogin();
	if(b==true){
		b=FormSubmit('login','_self','ShowAdminlogin.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#login";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

function FormSubmitLogin()
{// form submit for reg.asp
	var b;	
	b=FormValidationLogin();
	if(b==true){
		b=FormSubmit('login','_self','Showmemberlogin.asp','post');
	}else{
		alert("Incorrect input!");
		window.location="#login";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}
// modified by wai 090611
function FormSubmitRenewLogin()
{// form submit for reg.asp
	var b;	
	b=FormValidationLogin();
	if(b==true){
		b=FormSubmit('renewLogin','_self','ShowRenewMember.asp','post');
	}else{
		alert("Incorrect input!");
		Window.location="#login";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}

//////////////////////////////
function FormValidationLogin()
{// form validation for reg.asp
	var s;var x;var b,bb,b3;var sEmpty,sEmail;
	b=true;
	// define the error message
	sEmpty="<< This field is required!";
	//sEmail="<< Invalid email address!";
	
	try{
		// empty validation
		bb=IsTxtNotEmpty("txtUserID","a_userID",sEmpty);b=b && bb;
		
		// email address validation
		//if(bb){bb=IsEmail("txtUserID","a_userID",sEmail);b=b && bb;}
		
		// password validation
		bb3=IsTxtNotEmpty("txtPwd","a_pwd",sEmpty);b=b && bb3;
			
		
	}catch(err){
		s="Error.\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	return b;
}

function ButtonVisible(sId,sValue)
{// make the button visible or hidden
	var x=document.getElementById(sId);
	if(x!=null){x.style.visibility=sValue;}
}//<input type="button"   style="visibility:visible;" />
//<input type="button" style="visibility:hidden;" />

function hiddenFuct(sId)
{

	ButtonVisible(sId,"hidden");

}
function ButtonHKDVisible()
{
	var x,y,z;
	y=document.getElementById("ShowStdMember");
	if(y!=null){y.innerHTML="Student Member (HK $78) ";}	
	
	x=document.getElementById("ShowFullMember");
	if(x!=null){x.innerHTML="Full Member (HK $234) ";}
	
	z=document.getElementById("ShowLifeMember");
	if(z!=null){z.innerHTML="Life Member (HK $2,340) ";}
}

function ButtonUSDVisible()
{
	var x,y,z;
	y=document.getElementById("ShowStdMember");
	if(y!=null){y.innerHTML="Student Member (US $10) ";}	
	
	x=document.getElementById("ShowFullMember");
	if(x!=null){x.innerHTML="Full Member (US $30) ";}
	
	z=document.getElementById("ShowLifeMember");
	if(z!=null){z.innerHTML="Life Member (US $300) ";}
}
//// added on 2009-08-30 by Thomas
// modified on 2009-09-24 by wai
// modified on 2011-05-30 by Pong
function FormValidationLoginEdit()
{// form validation for ShowMemberLogin.asp
	var s;var x;var b,bb,b3,b4;var sEmpty,sEmail,sPassword,sLen,sBirth,sPostCode,sPhone,sAlertNonEnglish;
	var b5,b6,b7;
	var i;
	b=true;
	// define the error message
	sEmpty="<< This field is required!";
	sBirth="<< Invaild Date!";
	sEmail="<< Invalid email address!";
	sLen="<< Password must be 6-20 characters!";
	sPassword="<< Two passwords are different!";
	sPostCode="<< Numeric Only!";
	sPhone="<< Numeric, '-' , '(', ')' Only!";
	sAlertNonEnglish = "<< Allow English Only!";
	
	try{
		// empty validation
		bb=IsTxtNotEmpty("txtFamName","a_famName",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtFamName", "a_famName", sAlertNonEnglish); b=b&&bb;
		}
				
		bb=IsTxtNotEmpty("txtGivenName","a_givenName",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtGivenName", "a_givenName", sAlertNonEnglish); b=b&&bb;
		}
		
		bb=IsTxtNotEmpty("txtAffiliation","a_affiliation",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAffiliation", "a_affiliation", sAlertNonEnglish); b=b&&bb;
		}
				
		bb=IsTxtNotEmpty("txtAddline1","a_addline1",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtAddline1", "a_addline1", sAlertNonEnglish); b=b&&bb;
		}
				
		bb=IsTxtNotEmpty("txtCity","a_city",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCity", "a_city", sAlertNonEnglish); b=b&&bb;
		}		
		
		bb=IsTxtNotEmpty("txtCountry","a_country",sEmpty);b=b && bb;
		if (bb) {
		    // check non english text
		    bb = isTextEnglish("txtCountry", "a_country", sAlertNonEnglish); b=b&&bb;
		}
		
		x=document.getElementById("member");
		if(x!=null){
			i=x.value.indexOf("Student");
			if(i==0){
			    bb=IsTxtNotEmpty("txtUniversity","a_university",sEmpty);b=b && bb;
		        if (bb) {
		            // check non english text
		            bb = isTextEnglish("txtUniversity", "a_university", sAlertNonEnglish); b=b&&bb;
		            
		            // position
		            bb = isTextEnglish("position", "a_position", sAlertNonEnglish); b=bb&b;
		            if (document.getElementById("position").value == "") {
		                document.getElementById("position").value = " ";
		            }
		        }
			} else {
	            // position
	            bb = isTextEnglish("txtPosition", "a_position", sAlertNonEnglish); b=b&&bb;
	            if (document.getElementById("txtPosition").value == "") {
	                document.getElementById("txtPosition").value = " ";
	            }	            
	            
                // university		
	            bb = isTextEnglish("university", "a_university", sAlertNonEnglish);b=bb && b;
	            if (document.getElementById("university").value == "") {
	                document.getElementById("university").value = " ";
	            }
			}
		}

		// email address validation
		bb=IsTxtNotEmpty("txtEmail","a_email",sEmpty);b=b && bb;
		if(bb){bb=IsEmail("txtEmail","a_email",sEmail);b=b && bb;}
		
		// radio validation
		//bb=IsRadioNotEmtpy(document.formShowMemberLogin.gender,"a_gender",sEmpty);b=b && bb;// modified on 2009-09-24 by wai
		//bb=IsRadioNotEmtpy(document.formShowMemberLogin.addType,"a_addType",sEmpty);b=b && bb;// modified on 2009-09-24 by wai
		
		bb=IsRadioNotEmtpy(document.formShowMemberLogin.title,"a_title",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdoTitleOther");
			if(x!=null){
				if(x.checked==true) {
				    bb=IsTxtNotEmpty("txtTitleOther","a_title",sEmpty);b=b && bb;
				    if (bb) {
				        bb = isTextEnglish("txtTitleOther", "a_title", sAlertNonEnglish);b=b && bb;
				    }				    
				} else {
					x=document.getElementById("txtTitleOther");
					if(x!=null){x.value=" ";}
				}
			}
		}
		
		// highDeg validation
		bb=IsRadioNotEmtpy(document.formShowMemberLogin.highDeg,"a_highDeg",sEmpty);b=b && bb;
		if(bb){
			x=document.getElementById("rdohighDegOther");
			if(x!=null){
				if(x.checked==true){
				    bb=IsTxtNotEmpty("txtHighDegOther","a_highDeg",sEmpty);b=b && bb;
				    if(bb) {
				        bb = isTextEnglish("txtHighDegOther", "a_highDeg", sAlertNonEnglish);b=b && bb;
				    }
				} else{
			    	x=document.getElementById("txtHighDegOther");
					if(x!=null){x.value=" ";}
				}
			}
		}
		
		// postal code
		if (document.getElementById("postcode").value == "") {
		    document.getElementById("postcode").value = " ";
		} else {
		    bb=validatePostalCode(document.getElementById("postcode").value); b = b && bb;
		    if (!bb) {
		        document.getElementById("a_postcode").innerHTML = sPostCode;
		    } else {
		        document.getElementById("a_postcode").innerHTML = "";
		    }		
		}
		
		// phone
		if (document.getElementById("phone").value == "") {
		    document.getElementById("phone").value = " ";
		} else {
		    bb=validatePhoneFaxMobile(document.getElementById("phone").value); b = b && bb;
		    if (!bb) {
		        document.getElementById("a_phone").innerHTML = sPhone;
		    } else {
		        document.getElementById("a_phone").innerHTML = "";
		    }		
		}
		
		// fax
		if (document.getElementById("fax").value == "") {
		    document.getElementById("fax").value = " ";
		} else {
		    bb=validatePhoneFaxMobile(document.getElementById("fax").value); b = b && bb;
		    if (!bb) {
		        document.getElementById("a_fax").innerHTML = sPhone;
		    } else {
		        document.getElementById("a_fax").innerHTML = "";
		    }		
		}		
		
		// mobile
		if (document.getElementById("mobile").value == "") {
		    document.getElementById("mobile").value = " ";
		} else {
			bb=validatePhoneFaxMobile(document.getElementById("mobile").value); b = b && bb;
		    if (!bb) {
		        document.getElementById("a_mobile").innerHTML = sPhone;
		    } else {
		        document.getElementById("a_mobile").innerHTML = "";
		    }		
		}	
		
		// prefer name
		bb = isTextEnglish("preName", "a_preName", sAlertNonEnglish);b=bb && b;
		if (document.getElementById("preName").value == "") {
		    document.getElementById("preName").value = " ";
		}
		
		// url
		bb = isTextEnglish("url", "a_url", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("url").value == "") {
		    document.getElementById("url").value = " ";
		}
		
		// organName
		bb = isTextEnglish("organName", "a_organName", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("organName").value == "") {
		    document.getElementById("organName").value = " ";
		}
		
		
		// addline2
		bb = isTextEnglish("addline2", "a_addline2", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("addline2").value == "") {
		    document.getElementById("addline2").value = " ";
		}
		
		// addline3
		bb = isTextEnglish("addline3", "a_addline3", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("addline3").value == "") {
		    document.getElementById("addline3").value = " ";
		}	
		
		// state
		bb = isTextEnglish("state", "a_state", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("state").value == "") {
		    document.getElementById("state").value = " ";
		}
		
		// other research
		bb = isTextEnglish("txtOtherResearch", "a_otherResearch", sAlertNonEnglish); b=bb&&b;
		if (document.getElementById("txtOtherResearch").value == "") {
		    document.getElementById("txtOtherResearch").value = " ";
		}
				
		// password validation
	//	bb=IsPasswordSame("txtPwdNew","txtPwdNew2","a_pwd"," << Two passwords are not same!");b=b && bb;
	}catch(err){
		s="Error.\n\n";
		//s+="FormValidationReg(). " + err.description + "\n\n";
		s+= err.description + "\n\n";
		alert(s);
		return false;
	}
	
	if (b==0) {
	    b = false;
	}
	
	return b;	
}
//// added on 2009-08-30 by Thomas
function FormSubmitLoginEdit()
{// form submit for ShowMemberLogin.asp
	var b;
//	GetCountry();// get the full name of the country
	b=FormValidationLoginEdit();
	if(b==true){
	//	var r=confirm("Confirm to update?");
	//	if(r==true){b=FormSubmit('formShowMemberLogin','_self','ShowMemberLoginEditResult.asp','post');}
		var x=document.getElementById("flag_edit");
		if(x!=null){
			x.value="edit";
			
		//	b=IsPasswordSame("txtPwd","txtPwdNew","","");
		//	if(b==true){pwdOld=prompt("Please enter the password.");}
		//	else{pwdOld=prompt("Please enter the old password.");}
		
		//	var pwdOld;
		//	pwdOld=prompt("Please enter the password.");
		//	x=document.getElementById("txtPwdOld");
		//	if(x!=null){x.value=pwdOld;}
			var r=confirm("Confirm to update?");
			if(r==true){
			    b=FormSubmit('formShowMemberLogin','_self','ShowMemberLoginEdit.asp','post');
			} else {
			    return false;
			}
		}
		
	}else{
		alert("Incorrect input!");
	//	window.location="#formShowMemberLogin";
	//	b=FormSubmit('reg','_self','reg.asp','post');
	}
	return b;
}
// added on 209-09-02 by Thomas
function ChangeRadioDollarType()
{
	var s;
	var x;
	try{
		x=document.getElementById("rdoDollarTypeUSD");
		if(x!=null){if(x.checked==true){ButtonUSDVisible();}}
		x=document.getElementById("rdoDollarTypeHKD");
		if(x!=null){if(x.checked==true){ButtonHKDVisible();}}
	}catch(err){
		s="Error.\n\nChangeRadioDollarType( )";
		s+=err.description+"\n\n";
		alert(s);
	}
}
// Pong 20110510
// use by ForgotInfo.asp
function FormSubmitForgotInfo(queryString_type) {
    var familyName, givenName, email;
    var isValid = true;
    // get user input
    familyName = document.getElementById("txtFamilyName").value;
    email = document.getElementById("txtEmail").value;
    
    // validate user input
    if (familyName == null || familyName.length <= 0) {
        document.getElementById("errFamilyName").innerHTML = "<< This field is required!";
        isValid = false;
    } else {
         document.getElementById("errFamilyName").innerHTML = "";   
    }
    if (email == null || email.length <=0) {
        document.getElementById("errEmail").innerHTML = "<< This field is required!";
        isValid = false;
    } else if (!validateEmail(email)) {
        document.getElementById("errEmail").innerHTML = "<< Incorrect email format!";
        isValid = false;
    } else {
        document.getElementById("errEmail").innerHTML = "";
    }
    
    // submit form    
    if (isValid == true) {
        if (queryString_type == "n") {
            queryString_type = "rn";
        } else if (queryString_type == "p") {
            queryString_type = "rp";
        }
        document.forms["forgotInfo"].action = "ForgotInfo.asp?type=" + queryString_type;
        //document.forms["forgotInfo"].submit();
        return true;
    } else {
        return false;
    }
}


// use by ForgotRenewInfo.asp
function FormSubmitForgotRenewInfo(queryString_type) {
    var familyName, givenName, email;
    var isValid = true;
    // get user input
    familyName = document.getElementById("txtFamilyName").value;
    email = document.getElementById("txtEmail").value;
    
    // validate user input
    if (familyName == null || familyName.length <= 0) {
        document.getElementById("errFamilyName").innerHTML = "<< This field is required!";
        isValid = false;
    } else {
         document.getElementById("errFamilyName").innerHTML = "";   
    }
    if (email == null || email.length <=0) {
        document.getElementById("errEmail").innerHTML = "<< This field is required!";
        isValid = false;
    } else if (!validateEmail(email)) {
        document.getElementById("errEmail").innerHTML = "<< Incorrect email format!";
        isValid = false;
    } else {
        document.getElementById("errEmail").innerHTML = "";
    }
    
    // submit form    
    if (isValid == true) {
        if (queryString_type == "n") {
            queryString_type = "rn";
        } else if (queryString_type == "p") {
            queryString_type = "rp";
        }
        document.forms["ForgotRenewInfo"].action = "ForgotRenewInfo.asp?type=" + queryString_type;
        //document.forms["forgotInfo"].submit();
        return true;
    } else {
        return false;
    }
}


// used by EditUsername.asp
function submitEditUserName() {
    var eleNewUserID;
    var sNewUserID;
    var sConfirmNewUserID;
    
    sNewUserID=document.getElementById("txtNewUserID").value;
    sConfirmNewUserID=document.getElementById("txtConfirmNewUserID").value;
    
    // basic checking on the newUserName
    if (sNewUserID == null || sNewUserID.length <=0) {
        document.getElementById("a_newUserID").innerHTML = "<< This field is required!";
        return false;    
    }
    if (sConfirmNewUserID == null || sConfirmNewUserID.length <=0) {
        document.getElementById("a_confirmNewUserID").innerHTML = "<< This field is required!";
        return false;    
    }
    if (sNewUserID != sConfirmNewUserID) {
            document.getElementById("a_confirmNewUserID").innerHTML = "<< Not match with new username entered!";
            return false;    
    }
            
    //document.forms["editUsername"].submit();
    return true;
}

function goToEditUserNamePage() {
    //window.location = "../APSIPA/EditUsername.asp";
    FormSubmit("formShowMemberLogin","_self","EditUsername.asp","Post");
}

function goToEditPasswordPage() {
    //window.location = "../APSIPA/EditPassword.asp";
    FormSubmit("formShowMemberLogin","_self","EditPassword.asp","Post");
}

function goToLoginPage() {
    setTimeout("window.location =\"./login.asp\"", 3000);
} 

function cancelEditUserName() {
    var userID;
    var password;
    var form;
    
    userID=document.getElementById("hiddenUserID").value;
    password=document.getElementById("hiddenPwd").value;
    
    FormSubmit("editUsername","_self","ShowMemberLoginEdit.asp","Post");
    
    return false;
}

function cancelEditPassword() {
    var userID;
    var password;
    var form;
    
    userID=document.getElementById("hiddenUserID").value;
    password=document.getElementById("hiddenPwd").value;
    
    FormSubmit("editPwd","_self","ShowMemberLoginEdit.asp","Post");
    
    return false;
}

function submitEditPassword() {
    var sOldPwd;
    var sNewPwd;
    var sConfirmPwd;
    
    sNewPwd=document.getElementById("txtNewPwd").value;
    sOldPwd=document.getElementById("txtCurrentPwd").value;
    sConfirmPwd=document.getElementById("txtConfirmNewPwd").value;
    
    // basic checking on the newUserName
    if (sOldPwd == null || sOldPwd.length <=0) {
        document.getElementById("a_currentPwd").innerHTML = "<< This field is required!";
        return false;    
    }    
    if (sNewPwd == null || sNewPwd.length <=0) {
        document.getElementById("a_newPwd").innerHTML = "<< This field is required!";
        return false;    
    }
    if (sConfirmPwd == null || sConfirmPwd.length <=0) {
        document.getElementById("a_confirmNewPwd").innerHTML = "<< This field is required!";
        return false;    
    }
    if (sNewPwd.length < 6) {
            document.getElementById("a_newPwd").innerHTML = "<< At least 6 characters!";
            return false; 
    }
    
    if (sNewPwd != sConfirmPwd) {
            document.getElementById("a_confirmNewPwd").innerHTML = "<< Not match with new password entered!";
            return false;    
    }

            
    //document.forms["editPwd"].submit();
    return true;
}

function clearTxtBox(textBoxId) {
    document.getElementById(textBoxId).value = " ";
}

function isTextEnglish(sTextEleName, sAlertEleName, sAlert) {
    var bb;
    var oTextEle, oAlertEle;
    
    bb = true;
    
    oTextEle = document.getElementById(sTextEleName);
    if (oTextEle != null) {
        bb=isInputEnglish(oTextEle.value);
        oAlertEle = document.getElementById(sAlertEleName);
        if (oAlertEle != null) {
            if (bb) {
                oAlertEle.innerHTML = "";
            } else {
                oAlertEle.innerHTML = sAlert;
            }
        }        
    }
   return bb;    
}
