<!--
//	------------ Set Correct format of Full Name -----------------------

function ChangeName(ee){
	tt = ee.value;
	if (tt!=""){
		ttr = "";
		for(i=0; i<tt.length; i++){
			tti = tt.charAt(i);																				//	get ith letter of Name and check it
			if ((tti>="a" && tti<="z") || (tti>="A" && tti<="Z") || (tti==" ")){		//	check for correct letter
				if (i==0) { tti = tti.toUpperCase(); }									//	Capitalize first letter of name
				else if (tt.charAt(i-1)==" ") { tti = tti.toUpperCase(); } 					//	Capitalize the text
				else {tti = tti.toLowerCase(); }												//	Set as simple other values											
				ttr += tti;																// 	add to result if ith letter is correct letter
			}
		}
		ee.value = ttr;							//	replase FName with result text
	}
}
//	--------------Set Correct fromat for the Display Name ------------------
function ChangeName2(ee){
	ChangeName(ee);
	tt = ee.value;
	if (tt!=""){ document.getElementById("DName").innerHTML = "<img src='tick.png' />"; }
	else{ document.getElementById("DName").innerHTML = ""; }
}

//	------------- Check for corect extentions in file name --------------------

function ChangeImage(){
	tt = document.frm.pic1.value;												// get file path
	len = tt.length;																// get length of the file path
	if (len>0){
		start = 0;
		for(i=0; i<len; i++){ if (tt.charAt(i)=="."){start = i; }}						// find extention starting point
		if (start>0 && len-start<=5){													// check for valid extention
			tti = "";
			for(j=start; j<len; j++){tti += tt.charAt(j); }									// pick extentin from filename
			tti = tti.toLowerCase();							
			if (tti==".gif" || tti==".png" || tti==".jpg" || tti==".jpeg"){
				return true;
				}// do nothing  // check for image files
			else{ 
			alert(" Sorry, Invalid file type. Please select .gif, .jpg, .jpeg or file for picture");	// errer in path and file name send a alert
			document.frm.pic1.focus();
			document.frm.pic1.value = "";
			return false;
			}
		}
		else{
			alert(" Sorry, Invalid file type. Please select .gif, .jpg, .jpeg or file for picture");	// errer in path and file name send a alert
			document.frm.pic1.focus();
			document.frm.pic1.value = "";
			return false;

		}
		
	}
	else{ return true; }
}

//	------------- Set Correct format of Registration Number -------------------

function ChangeRegistrationNumber(){
	tt = document.frm.txtURegNum.value;
	if (tt!=""){
		ttr = "";
		for(i=0;i<tt.length;i++){
			tti = tt.charAt(i);
			if (i==3) { if (tti>=0 && tti<=9 && tti!=" ") { ttr = ttr + tti + "/s/"; }} 						// Check therd index for number and add /S/
			else if (i>4 && i<=6){}
			else if	(tti>=0 && tti<=9 && tti!=" "){ttr += tti;}
		}
		document.frm.txtURegNum.value = ttr;
	}
	if(tt.length==12){ showHint("regNum"); }
	else{ document.getElementById("regNum").innerHTML=""; }
}


//	-------------	Set lowerCase E-mail address ---------------------------------

function ChangeEmail(){
	tt = document.frm.txtEmail.value;
	if (tt!=""){
		tt = tt.toLowerCase();
		document.frm.txtEmail.value = tt;
	}
}


//	------------- Set Correct Phone Number format --------------------------------
function ChangePhoneNumber(ee){
	tt = ee.value;
	if (tt!=""){
		ttr = "";
		for (i=0; i<tt.length; i++){
			tti = tt.charAt(i);
			if (i==0){ ttr = "0"; }
			else if (i==2){ if (tti>=0 && tti<=9 && tti!=" ") { ttr = ttr + tti + "-"; }}
			else if (tti>=0 && tti<=9 && tti!=" ") { ttr += tti; }
		}
		ee.value = ttr;
	}
}
			
//	---------------Set Correct NIC Number format----------------------------
function ChangeNic(ee){
	tt = ee.value;
	if(tt!=""){
		ttr = "";
		for(i=0; i<tt.length; i++){
			tti = tt.charAt(i);
			if(i==8){
				if(tti>=0 && tti<=9 && tti!=" "){ ttr += tti + "V"; }
			}
			else if(i==0){
				if(tti>=7 && tti<=9 && tti!=" "){ ttr += tti; }
			}
			else{
				if(tti>=0 && tti<=9 && tti!=" "){ ttr += tti; }
			}
		}
		ee.value = ttr;
		if(tt.length>=9){
			dd = Number(String(tt.charAt(2))+String(tt.charAt(3))+String(tt.charAt(4)));
			if((dd>0 && dd<367) || (dd>500 && dd<867)){
				document.getElementById("Nic").innerHTML = "<img src='tick.png' />";
			}
			else{
				document.getElementById("Nic").innerHTML = "<img src='err.png' alt='Invalid NIC Number.'/><div class='err'>Invalid NIC Number.</div>";
			}
		}
		else{ document.getElementById("Nic").innerHTML = ""; }
				
	}
}

//	---------------Check user Names for valid format -----------------------
function ChangeUserName(ee){
		tt = ee.value;
		if(tt!=""){
			ttr = "";
			for(i=0; i<tt.length; i++){
				tti = tt.charAt(i);
				if((tti>="0" && tti<="9") || (tti>="a" && tti<="z") || (tti>="A" && tti<="Z") || (tti==" ")){ ttr += tti; }
			}
			ee.value = ttr;
		}
		showHint("UName");
}

		
//  ---------------Check requred field before send--------------------------

function beforeSend(){
	//	Check Full Name
	with(document.frm){
		if (txtFName.value==""){
			txtFName.focus();
			alert("You must type your Full Name in Full Name field.");
			return false;
		}
	//	Check Display Name
		if (txtDName.value==""){
			txtDName.focus();
			alert("You must type a name in Display Name field.");
			return false;
		}
		
	//	Check for coorect picture format
		if(!ChangeImage()){ return false; }
		
	//	Check for the permanent address
		if (txtPAdd.value==""){
			txtPAdd.focus();
			alert("You must type your permanent address.");
			return false;
		}

	//	Check Phone Number
		if (!(txtTel.value=="" || txtTel.value.length==11)){
			txtTel.focus();
			alert("Invalid telephone number.");
			return false;
		}
	
	//	Check mobile Phone Number
		if (!(txtMob.value=="" || txtMob.value.length==11)){
			txtMob.focus();
			alert("Invalid mobile phone number.");
			return false;
		}
		
	//	Check NIC Number
		if (txtNic.value.length!=10){
			txtNic.focus();
			alert("Invalid NIC number.");
			return false;
		}
	//	Check Registrion Number
		if (txtURegNum.value=="" || txtURegNum.value.length!=12){
			txtURegNum.focus();
			alert("You must type your Registration Number correctly.");
			return false;
		}
		
	//	Check Subject Combination
		if (combination.value == ""){
			combination.focus();
			alert("you must select your subject combination");
			return false;
		}
		
	//	Check E-mail address
		if (txtEmail.value==""){
			txtEmail.focus();
			alert("you must type your E-mail address");
			return false;
		}
	
	//	Check for the User Name
		if (txtUserName.value == ""){
			txtUserName.focus();
			alert("you must type a user name.");
			return false;
		}
	
	//	Check Password
		if(txtPassword.value==""){
			txtCPassword.value = "";
			txtPassword.focus();
			alert("You must type password.");
			return false;
		}
	//  Check cofirm password and maching with password
		if(txtCPassword.value==""){
			txtCPassword.focus();
			alert("you must retype password to confirm it");
			return false;
		}

	//	Check for Security Question
		if (SQuestion.value==""){
			SQuestion.focus();
			alert("You must select security question.");
			return false;
		}
	// 	Check answer for Security Question
		if (txtAnswer.value==""){
			txtAnswer.focus();
			alert("You must type answer for security question.");
			return false;
		}
	//	maching password	
		if(txtPassword.value != txtCPassword.value){		//	confirm password before send
			txtCPassword.value = "";
			txtPassword.value = "";
			txtPassword.focus();
			alert("Password mismatch. Please check and retype password.");
			return false;
		}	
	// 	Check for the agrement
		if(!chkAgree.checked){
			chkAgree.focus();
			alert("You must agree for the rules of the MAS.");
			return false;
		}
	// check for ajax validation
		if(errName.value=="false"){
			txtFName.focus();
			alert("Your name is already registered.");
			return false;
		}
		if(errRegNum.value=="false"){
			txtURegNum.focus();
			alert("Your registration number is already registered.");
			return false;
		}
		if(errEmail.value=="false"){
			txtEmail.focus();
			alert("Invalid E-mail address.");
			return false;
		}
		if(errUName.value=="false"){
			txtUserName.focus();
			alert("Your user name is aldady in use. Please type another one");
			return false;
		}
		return true;
	}
}

// when reset Click
function resetClick(){
	document.getElementById("FName").innerHTML = ""
	document.getElementById("DName").innerHTML = ""
	document.getElementById("Nic").innerHTML = ""
	document.getElementById("regNum").innerHTML = ""
	document.getElementById("Email").innerHTML = ""
	document.getElementById("UName").innerHTML = ""
}
//-->




// when Edit values
function beforeUpdate(){
	//	Check Full Name
	with(document.frm){
		if (txtFName.value==""){
			txtFName.focus();
			alert("You must type your Full Name in Full Name field.");
			return false;
		}
	//	Check Display Name
		if (txtDName.value==""){
			txtDName.focus();
			alert("You must type a name in Display Name field.");
			return false;
		}
		
	//	Check for coorect picture format
		if(!ChangeImage()){ return false; }
		
	//	Check for the permanent address
		if (txtPAdd.value==""){
			txtPAdd.focus();
			alert("You must type your permanent address.");
			return false;
		}

	//	Check Phone Number
		if (!(txtTel.value=="" || txtTel.value.length==11)){
			txtTel.focus();
			alert("Invalid telephone number.");
			return false;
		}
	
	//	Check mobile Phone Number
		if (!(txtMob.value=="" || txtMob.value.length==11)){
			txtMob.focus();
			alert("Invalid mobile phone number.");
			return false;
		}
		
	//	Check NIC Number
		if (txtNic.value.length!=10){
			txtNic.focus();
			alert("Invalid NIC number.");
			return false;
		}
	//	Check Registrion Number
		if (txtURegNum.value=="" || txtURegNum.value.length!=12){
			txtURegNum.focus();
			alert("You must type your Registration Number correctly.");
			return false;
		}
		
	//	Check Subject Combination
		if (combination.value == ""){
			combination.focus();
			alert("you must select your subject combination");
			return false;
		}
		
	//	Check E-mail address
		if (txtEmail.value==""){
			txtEmail.focus();
			alert("you must type your E-mail address");
			return false;
		}
		
	// check for ajax validation
		showHint("Email");
		if(errEmail.value=="false"){
			txtEmail.focus();
			alert("Invalid E-mail address.");
			return false;
		}
		return true;
	}
}

