/**************************************************************/
/* validatelogin: This function validates administrator login.
/* addtherapy: This function validates new therapy entered.
/* validateacctemail: This function validates email for 
/*                    admin acount information
/* validateacctpwd: This function validates password for 
/*                  admin account information
/* register: This function validate all fields required for 
/*           therapist registration.
/**************************************************************/
function returnfalse(obj){
	obj.focus();
	return false;
}

function validatelogin(){
	frm = document.loginfrm;
	//validate user
	if(trim(loginfrm.login.value)==""){
		alert("Please enter User.")
		return returnfalse(loginfrm.login)
	}else if(!validatePassword(trim(loginfrm.login.value))){
		alert("Invalid User.")
		return returnfalse(loginfrm.login)
	}
	//validate password
	if(trim(loginfrm.password.value)==""){
		alert("Please enter Password.")
		return returnfalse(loginfrm.password)
	}else if(!validatePassword(trim(loginfrm.password.value))){
		alert("Invalid Password.")
		return returnfalse(loginfrm.password)
	}
	frm.action="index.asp"
	frm.submit()
}

//Add new therapy validation
function addtherapy(e){
	frm = document.therapyfrm;
	if(trim(frm.therapy.value)==""){
		alert("Please enter Therapy.")
		return returnfalse(frm.therapy)
	}
	if(trim(frm.desc.value)==""){
		alert("Please enter Description.")
		return returnfalse(frm.desc)
	}
	if(e>0) frm.action="addedittherapy.asp?s=y&e="+e
	else frm.action="addedittherapy.asp"
	frm.submit()
}

//Add new special field validation
function addfield(e){
	frm = document.fieldfrm;
	if(trim(frm.field.value)==""){
		alert("Please enter special field.")
		return returnfalse(frm.field)
	}
	if(e>0) frm.action="addeditspfield.asp?s=y&e="+e
	else frm.action="addeditspfield.asp"
	frm.submit()
}

//Validates Admin Account Email 
function validateacctemail(){
	frm = document.emailfrm;
	//validate Email
	if(trim(frm.email.value)==""){
		alert("Please enter Email.")
		return returnfalse(frm.email)
	}else if(!checkEmailAddress(trim(frm.email.value))){
		alert("Invalid Email.")
		return returnfalse(frm.email)
	}
	frm.action="accountinformation.asp"
	frm.submit()
}

//Validate Admin Passwprd
function validateacctpwd(){
	frm = document.pwdfrm;
	//Validate old password
	if(trim(frm.oldpwd.value)==""){
		alert("Please enter Old Password.")
		return returnfalse(frm.oldpwd)
	}else if(trim(frm.oldpwd.value)!=trim(frm.chkoldpwd.value)){
		alert("Incorrect Old Password.")
		return returnfalse(frm.oldpwd)
	}
	
	//validate new password
	if(trim(frm.newpwd.value)==""){
		alert("Please enter New Password.")
		return returnfalse(frm.newpwd)
	}else if(!validatePassword(trim(frm.newpwd.value))){
		alert("Invalid New Password.")
		return returnfalse(frm.newpwd)
	}
	
	//Confirm new password
	if(trim(frm.confpwd.value)==""){
		alert("Please confirm password.")
		return returnfalse(frm.confpwd)
	}else if(trim(frm.confpwd.value)!=trim(frm.newpwd.value)){
		alert("Password confirmation failed.")
		return returnfalse(frm.confpwd)
	}
	frm.action="accountinformation.asp"
	frm.submit()
}

//Validates Therapist...............ADMIN
function register111(f){
	frm = document.regfrm
	
	//validate first name
/*	if(trim(frm.fname.value)==""){
		alert("Please enter first name.")
		return returnfalse(frm.fname)
	}else if(!checkname(trim(frm.fname.value))){
		alert("Invalid first name.")
		return returnfalse(frm.fname)
	}
	//validate surname
	if(trim(frm.sname.value)==""){
		alert("Please enter surname.")
		return returnfalse(frm.sname)
	}else if(!checkname(trim(frm.sname.value))){
		alert("Invalid first surname.")
		return returnfalse(frm.sname)
	}
	//Validate postcode
	if(trim(frm.pcode.value)==""){
		alert("Please enter Postcode.")
		return returnfalse(frm.pcode)
	}
	//validate qualification
	if(trim(frm.quali.value)==""){
		alert("Please enter qualification.")
		return returnfalse(frm.quali)
	}
	//validate practiced therapies
	if(frm.th1.value=="" && frm.th2.value=="" && frm.th3.value=="" && frm.th4.value==""){
		alert("Please select atleast one therapies practiced.")
		return returnfalse(frm.th1)
	}
	//validate specialized field
	if(frm.spf.value=="" && frm.spf2.value=="" && frm.spf3.value=="" && frm.spf4.value=="" && frm.spf5.value=="" && frm.spf6.value=="" && frm.spf7.value=="" && frm.spf8.value==""){
		alert("Please select atleast one specialized field for each Therapy selected.")
		return returnfalse(frm.spf)
	}
	//validate phone
	if(trim(frm.phone.value)==""){
		alert("Please enter phone.")
		return returnfalse(frm.phone)
	}else if(!checkPhone(trim(frm.phone.value))){
		alert("Invalid phone.")
		return returnfalse(frm.phone)
	}
	//validate email
	if(trim(frm.email.value)!=""){
		if(!checkEmailAddress(trim(frm.email.value))){
			alert("Invalid Email.")
			return returnfalse(frm.email)
		}
	}else{
		alert("Please enter email.")
		return returnfalse(frm.email)
	}
	//validate county
	if(frm.county.value==""){
		alert("Please select county.")
		return returnfalse(frm.county)
	}
	//validate city
	if(frm.pcity.value==""){
		alert("Please select practise city.")
		return returnfalse(frm.pcity)
	} */
	frm.chk.value="ok"
	if(f==0) frm.action="addedittherapist.asp"
	else frm.action="therapistRegisterDetails.asp"
	frm.submit()
}

//Validates Therapist.............SITE
function register(f){
	frm = document.regfrm
	
	//validate first name
	if(trim(frm.fname.value)==""){
		alert("Please enter first name.")
		return returnfalse(frm.fname)
	}else if(!checkname(trim(frm.fname.value))){
		alert("Invalid first name.")
		return returnfalse(frm.fname)
	}
	//validate surname
	if(trim(frm.sname.value)==""){
		alert("Please enter surname.")
		return returnfalse(frm.sname)
	}else if(!checkname(trim(frm.sname.value))){
		alert("Invalid first surname.")
		return returnfalse(frm.sname)
	}
	//Validate postcode
	if(trim(frm.pcode.value)==""){
		alert("Please enter Postcode.")
		return returnfalse(frm.pcode)
	}
	//validate qualification
	if(trim(frm.quali.value)==""){
		alert("Please enter qualification.")
		return returnfalse(frm.quali)
	}
	//validate practiced therapies
	if(frm.th1.value=="" && frm.th2.value=="" && frm.th3.value=="" && frm.th4.value==""){
		alert("Please select atleast one therapies practiced.")
		return returnfalse(frm.th1)
	}
	//validate specialized field
	if(frm.spf.value=="" && frm.spf2.value=="" && frm.spf3.value=="" && frm.spf4.value=="" && frm.spf5.value=="" && frm.spf6.value=="" && frm.spf7.value=="" && frm.spf8.value==""){
		alert("Please select atleast one specialized field for each Therapy selected.")
		return returnfalse(frm.spf)
	}
	//validate phone
	if(trim(frm.phone.value)==""){
		alert("Please enter phone.")
		return returnfalse(frm.phone)
	}else if(!checkPhone(trim(frm.phone.value))){
		alert("Invalid phone.")
		return returnfalse(frm.phone)
	}
	//validate email
	if(trim(frm.email.value)!=""){
		if(!checkEmailAddress(trim(frm.email.value))){
			alert("Invalid Email.")
			return returnfalse(frm.email)
		}
	}else{
		alert("Please enter email.")
		return returnfalse(frm.email)
	}
	//validate county
	if(frm.county.value==""){
		alert("Please select county.")
		return returnfalse(frm.county)
	}
	//validate city
	if(frm.pcity.value==""){
		alert("Please select practise city.")
		return returnfalse(frm.pcity)
	}
	frm.chk.value="ok"
	if(f==0) frm.action="addedittherapist.asp"
	else frm.action="therapistRegisterDetails.asp"
	frm.submit()
}

function selectOption11(){
	var theSel = document.getElementById("s1");
	var t=0;
	for(var i=0; i<theSel.length;i++){
		var tval = trim(document.getElementById("fname").value+" "+document.getElementById("sname").value+" "+document.getElementById("pcode").value);
		if (theSel[i].text.toLowerCase().substring(0,(tval).length)==tval.toLowerCase()){
			theSel.selectedIndex = i;
			t=1;
		}
		if((t==0) || (document.getElementById("fname").value=="")) theSel.selectedIndex = 0;
	}
}
