// JavaScript Document
function validate_admin(inForm){
	if(inForm == "classes"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtTitle.value == ""){
				alert("You must enter a title for this class.");
				document.frmAdmin.txtTitle.focus();
				return false;
			}
			if(document.frmAdmin.txtDescription.value == ""){
				alert("You must enter a description for this class.");
				document.frmAdmin.txtDescription.focus();
				return false;
			}
			if(document.frmAdmin.txtMenu.value == ""){
				alert("You must enter a menu for this class.");
				document.frmAdmin.txtMenu.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "clients"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtFirstName.value == ""){
				alert("You must enter a first name for this client.");
				document.frmAdmin.txtFirstName.focus();
				return false;
			}
			if(document.frmAdmin.txtLastName.value == ""){
				alert("You must enter a last name for this client.");
				document.frmAdmin.txtLastName.focus();
				return false;
			}
			if(document.frmAdmin.txtAddress1.value == ""){
				alert("You must enter an address for this client.");
				document.frmAdmin.txtAddress1.focus();
				return false;
			}
			if(document.frmAdmin.txtCity.value == ""){
				alert("You must enter a city for this client.");
				document.frmAdmin.txtCity.focus();
				return false;
			}
			if(document.frmAdmin.txtProvinceState.value == ""){
				alert("You must enter a province or state for this client.");
				document.frmAdmin.txtProvinceState.focus();
				return false;
			}
			if(document.frmAdmin.txtPostalZip.value == ""){
				alert("You must enter a postal or zip code for this client.");
				document.frmAdmin.txtPostalZip.focus();
				return false;
			}
			if(document.frmAdmin.txtMailingAddress1.value == ""){
				alert("You must enter a mailing address.");
				document.frmAdmin.txtMailingAddress1.focus();
				return false;
			}
			if(document.frmAdmin.txtMailingCity.value == ""){
				alert("You must enter a mailing city for this client.");
				document.frmAdmin.txtMailingCity.focus();
				return false;
			}
			if(document.frmAdmin.txtMailingProvinceState.value == ""){
				alert("You must enter a mailing province or state for this client.");
				document.frmAdmin.txtMailingProvinceState.focus();
				return false;
			}
			if(document.frmAdmin.txtMailingPostalZip.value == ""){
				alert("You must enter a mailing postal or zip code for this client.");
				document.frmAdmin.txtMailingPostalZip.focus();
				return false;
			}
			
			if(document.frmAdmin.txtPhoneArea.value == ""){
				alert("You must enter the area code for this client.");
				document.frmAdmin.txtPhoneArea.focus();
				return false;
			}
			if(document.frmAdmin.txtPhonePrefix.value == ""){
				alert("You must enter the phone prefix for this client.");
				document.frmAdmin.txtPhonePrefix.focus();
				return false;
			}
			if(document.frmAdmin.txtPhoneSuffix.value == ""){
				alert("You must enter the phone suffix for this client.");
				document.frmAdmin.txtPhoneSuffix.focus();
				return false;
			}
			
			if(echeck(document.frmAdmin.txtEmail.value) == false){
				alert("Please enter a valid email address.");
				document.frmAdmin.txtEmail.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "instructors"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtFirst_Name.value == ""){
				alert("You must enter a first name for this instructor.");
				document.frmAdmin.txtFirst_Name.focus();
				return false;
			}
			if(document.frmAdmin.txtLast_Name.value == ""){
				alert("You must enter a last name for this instructor.");
				document.frmAdmin.txtLast_Name.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "locations"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtLocation.value == ""){
				alert("You must enter a location name.");
				document.frmAdmin.txtLocation.focus();
				return false;
			}
			if(document.frmAdmin.txtAddress1.value == ""){
				alert("You must enter an address for this location.");
				document.frmAdmin.txtAddress1.focus();
				return false;
			}
			if(document.frmAdmin.txtCity.value == ""){
				alert("You must enter a city for this location.");
				document.frmAdmin.txtCity.focus();
				return false;
			}
			if(document.frmAdmin.txtProvinceState.value == ""){
				alert("You must enter a province or state for this location.");
				document.frmAdmin.txtProvinceState.focus();
				return false;
			}
			if(document.frmAdmin.txtPostalZip.value == ""){
				alert("You must enter a postal or zip code for this location.");
				document.frmAdmin.txtPostalZip.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "registration"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
		}
		return true;
	}
	if(inForm == "sessions"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtStartTime.value == ""){
				alert("You must enter the start time for this session.");
				document.frmAdmin.txtStartTime.focus();
				return false;
			}
			if(document.frmAdmin.txtEndTime.value == ""){
				alert("You must enter the end time for this session.");
				document.frmAdmin.txtEndTime.focus();
				return false;
			}
			if(document.frmAdmin.txtPrice.value == ""){
				alert("You must enter a price for this session.");
				document.frmAdmin.txtPrice.focus();
				return false;
			}
			if(document.frmAdmin.txtMaxParticipants.value == ""){
				alert("You must enter the max participants for this session.");
				document.frmAdmin.txtMaxParticipants.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "status_list"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
		}
		return true;
	}
	if(inForm == "testimonials"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
			if(document.frmAdmin.txtFirstName.value == ""){
				alert("You must enter the first name for this testimonial.");
				document.frmAdmin.txtFirstName.focus();
				return false;
			}
			if(document.frmAdmin.txtLastName.value == ""){
				alert("You must enter the last name for this testimonial.");
				document.frmAdmin.txtLastName.focus();
				return false;
			}
			if(document.frmAdmin.txtTestimonial.value == ""){
				alert("You must enter the testimonial.");
				document.frmAdmin.txtTestimonial.focus();
				return false;
			}
		}
		return true;
	}
	if(inForm == "users"){
		if(document.frmAdmin.cmdAction.value == "Save" || document.frmAdmin.cmdAction.value == "Update"){
		}
		return true;
	}
	return true;
}

function validate_login(){
	if(echeck(document.frmLogin.txtEmail.value) == false){
		alert("Please enter a valid email address.");
		return false;
	}
	if(document.frmLogin.txtPassword.value == ""){
		alert("Please enter your password.");
		return false;
	}
	return true;
}

function validate_retrieval(){
	if(echeck(document.frmPassword.txtEmail.value) == false){
		alert("Please enter a valid email address.");
		return false;
	}
	return true;
}

function validate_friend(){
	if(document.frmFriend.txtFromName.value == ""){
		alert("Please enter your name.");
		return false;
	}
	if(echeck(document.frmFriend.txtFromEmail.value) == false){
		alert("Your email address must be a valid email address.");
		return false;
	}
	if(document.frmFriend.txtToName.value == ""){
		alert("Please enter your friends name.");
		return false;
	}
	if(echeck(document.frmFriend.txtToEmail.value) == false){
		alert("Your friends email address must be a valid email address.");
		return false;
	}
	return true;
}

function validate_register(){
	if(document.frmRegister.txtFirstName.value == ""){
		alert("You must enter your first name.");
		return false;
	}
	if(document.frmRegister.txtLastName.value == ""){
		alert("You must enter your last name.");
		return false;
	}
	if(document.frmRegister.txtAddress1.value == ""){
		alert("You must enter your address.");
		return false;
	}
	if(document.frmRegister.txtCity.value == ""){
		alert("You must enter your city.");
		return false;
	}
	if(document.frmRegister.txtProvinceState.value == ""){
		alert("You must enter your province or state.");
		return false;
	}
	if(document.frmRegister.txtPostalZip.value == ""){
		alert("You must enter your postal or zip code.");
		return false;
	}
	if(document.frmRegister.txtMailingAddress1.value == ""){
		alert("You must enter your mailing address.");
		return false;
	}
	if(document.frmRegister.txtMailingCity.value == ""){
		alert("You must enter your mailing city.");
		return false;
	}
	if(document.frmRegister.txtMailingProvinceState.value == ""){
		alert("You must enter your mailing province or state.");
		return false;
	}
	if(document.frmRegister.txtMailingPostalZip.value == ""){
		alert("You must enter your mailing postal or zip code.");
		return false;
	}
	if(document.frmRegister.txtPhoneArea.value == ""){
		alert("You must enter your telephone area code.");
		return false;
	}
	if(document.frmRegister.txtPhonePrefix.value == ""){
		alert("You must enter your telephone prefix.");
		return false;
	}
	if(document.frmRegister.txtPhoneSuffix.value == ""){
		alert("You must enter your telephone suffix.");
		return false;
	}
	if(document.frmRegister.txtEmail.value == ""){
		alert("You must enter your email address.");
		return false;
	}
	if(document.frmRegister.txtPassword.value == ""){
		alert("You must enter a password.");
		return false;
	}
	return true;
}

function show_mailing(){
	document.frmRegister.txtMailingAddress1.value = document.frmRegister.txtAddress1.value;
	document.frmRegister.txtMailingAddress2.value = document.frmRegister.txtAddress2.value;
	document.frmRegister.txtMailingCity.value = document.frmRegister.txtCity.value;
	document.frmRegister.txtMailingProvinceState.value = document.frmRegister.txtProvinceState.value;
	document.frmRegister.txtMailingPostalZip.value = document.frmRegister.txtPostalZip.value;
	document.frmRegister.cboMailingCountry.value = document.frmRegister.cboCountry.value;
}

function show_mailing_admin(){
	document.frmAdmin.txtMailingAddress1.value = document.frmAdmin.txtAddress1.value;
	document.frmAdmin.txtMailingAddress2.value = document.frmAdmin.txtAddress2.value;
	document.frmAdmin.txtMailingCity.value = document.frmAdmin.txtCity.value;
	document.frmAdmin.txtMailingProvinceState.value = document.frmAdmin.txtProvinceState.value;
	document.frmAdmin.txtMailingPostalZip.value = document.frmAdmin.txtPostalZip.value;
	document.frmAdmin.cboMailingCountry.value = document.frmAdmin.cboCountry.value;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail Address");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail Address");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail Address");
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail Address");
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail Address");
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail Address");
		return false;
	}
	if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail Address");
		return false;
	}
	return true;		
}

function isNumeric(inNum) {	
	//CHECK FOR NUMBERS
	//ALLOWS -'s
	var x=inNum
	var anum=/(\-)|(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
		testresult=true;
	else{
		testresult=false;
	}
	return (testresult);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function formatDate(date,format) {
	alert(getMonth(date));
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
}
