sp = new Array();
mysp = new Array();


function returnFalse(obj){
	obj.focus();
	return false;
}
function checkLogin()
	{
	
	if (trim(document.loginFrm.login.value)=="")	
	{
		alert("Please enter Login name.");
		return returnFalse(document.loginFrm.login);
	}
	else
		{
		if (validatePasswordpadQuotes(trim(document.loginFrm.login.value))==false)
		{
			alert("Invalid Login name.");
			return returnFalse(document.loginFrm.login);
		}
	}
	if (trim(document.loginFrm.pwd.value)=="")	
	{
		alert("Please enter password.");
		return returnFalse(document.loginFrm.pwd);
	}
	else
		{
		if (validatePasswordpadQuotes(trim(document.loginFrm.pwd.value))==false)
		{
			alert("Invalid password.");
			return returnFalse(document.loginFrm.pwd);
		}
	}
	document.loginFrm.submit();
}

function valid(form)
{	
	if(trim(document.form.feedback.value) ==""){
		alert("Please enter feedback.");
		return returnFalse(document.form.feedback);
	}
	if(trim(document.form.email.value) ==""){
		alert("Please enter email address.");
		return returnFalse(document.form.email);
	  }	  
	if(trim(document.form.email.value) !==''){		
		if (checkEmailAddress(trim(document.form.email.value))==false){
			alert("Invalid email address.");
			return returnFalse(document.form.email);
		  }
	  }
	/*else if(checkcity(trim(document.form.feedback.value))==false){
		alert("Invalid feedback.");
		return returnFalse(document.form.feedback);
	}*/
}

function ValidateForm(frm)	{ 	
	if(trim(document.form.cust_name.value) ==""){
		alert("Please enter business name.");
		return returnFalse(document.form.cust_name);
	}
	else if(checkcity(trim(document.form.cust_name.value))==false){
		alert("Invalid business name.");
		return returnFalse(document.form.cust_name);
	}
	
	if(trim(document.form.cont_name.value) ==""){
		alert("Please enter contact name.");
		return returnFalse(document.form.cont_name);
	}else if(checkcity(trim(document.form.cont_name.value))==false){
		alert("Invalid contact name.");
		return returnFalse(document.form.cont_name);
	}
	if(trim(document.form.address1.value) ==""){
		alert("Please enter address1.");
		return returnFalse(document.form.address1);
	}
	/*if(trim(document.form.address2.value) ==""){
		alert("Please enter address2.");
		return returnFalse(document.form.address2);
	}*/
	if(trim(document.form.city.value) ==""){
		alert("Please enter city.");
		return returnFalse(document.form.city);
	}
	else if(checkcity(trim(document.form.city.value))==false){
		alert("Invalid city.");
		return returnFalse(document.form.city);
	}
	if(trim(document.form.state.value) ==""){
		alert("Please enter state.");
		return returnFalse(document.form.state);
	}
	else if(checkcity(trim(document.form.state.value))==false){
		alert("Invalid state.");
		return returnFalse(document.form.state);
	}
	if(trim(document.form.zip.value) ==""){
		alert("Please enter zip.");
		return returnFalse(document.form.zip);
	}
	else if(trim(document.form.zip.value) != ""){
		var valid = ".0123456789-() "
		var ok = "yes";
		var temp;
		for (var i=0; i<document.form.zip.value.length; i++) {
			temp = "" + document.form.zip.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") 
			ok = "no";
		}
		if (ok == "no"){
			alert("Invalid Entry! Only Numbers Are Accepted!");
			return returnFalse(document.form.zip);
		}
	}	

	if(trim(document.form.phone.value) ==""){
		alert("Please enter phone.");
		return returnFalse(document.form.phone);
	}
	else if(trim(document.form.phone.value) !=""){
			var valid = ".0123456789-() "
			var ok = "yes";
			var temp;
			for (var i=0; i<document.form.phone.value.length; i++) {
				temp = "" + document.form.phone.value.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") 
				ok = "no";
			}
			if (ok == "no"){
				alert("Invalid Entry! Only Numbers Are Accepted!");
				return returnFalse(document.form.phone);
			}
		}	
		if(trim(document.form.email.value) ==""){
			alert("Please enter email address.");
		    return returnFalse(document.form.email);
		  }	  
		if(trim(document.form.email.value) !==''){		
		    if (checkEmailAddress(trim(document.form.email.value))==false){
				alert("Invalid email address.");
		        return returnFalse(document.form.email);
		      }
	      }
	document.form.submit();		
}	


function ValidateForm1()	{ 	
	form=document.frm;
	if(trim(form.buss_name.value) ==""){
		alert("Please enter business name.");
		//form.buss_name.focus();
		return returnFalse(form.buss_name);
	}
	else if(checkcity(trim(form.buss_name.value))==false){
		alert("Invalid business name.");
		return returnFalse(form.buss_name);
	}
	
	if(trim(form.cont_name.value) ==""){
		alert("Please enter contact name.");
		return returnFalse(form.cont_name);
	}else if(checkcity(trim(form.cont_name.value))==false){
		alert("Invalid contact name.");
		return returnFalse(form.cont_name);
	}
	if(trim(form.address1.value) ==""){
		alert("Please enter address1.");
		return returnFalse(form.address1);
	}
	/*if(trim(form.address2.value) ==""){
		alert("Please enter address2.");
		return returnFalse(form.address2);
	}*/
	if(trim(form.city.value) ==""){
		alert("Please enter city.");
		return returnFalse(form.city);
	}
	else if(checkcity(trim(form.city.value))==false){
		alert("Invalid city.");
		return returnFalse(form.city);
	}
	if(trim(form.state.value) ==""){
		alert("Please enter state.");
		return returnFalse(form.state);
	}
	else if(checkcity(trim(form.state.value))==false){
		alert("Invalid state.");
		return returnFalse(form.state);
	}
	if(trim(form.zip.value) ==""){
		alert("Please enter zip.");
		return returnFalse(form.zip);
	}
	else if(trim(form.zip.value) != ""){
		var valid = ".0123456789-() "
		var ok = "yes";
		var temp;
		for (var i=0; i<form.zip.value.length; i++) {
			temp = "" + form.zip.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") 
			ok = "no";
		}
		if (ok == "no"){
			alert("Invalid entry! only numbers are accepted!");
			return returnFalse(form.zip);
		}
	}	

	if(trim(form.phone.value) ==""){
		alert("Please enter phone.");
		return returnFalse(form.phone);
	}
	else if(trim(form.phone.value) !=""){
			var valid = ".0123456789-() "
			var ok = "yes";
			var temp;
			for (var i=0; i<form.phone.value.length; i++) {
				temp = "" + form.phone.value.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") 
				ok = "no";
			}
			if (ok == "no"){
				alert("Invalid entry! only numbers are accepted!");
				return returnFalse(form.phone);
			}
		}	
		if(trim(form.email.value) ==""){
			alert("Please enter email address.");
		    return returnFalse(form.email);
		  }	  
		if(trim(form.email.value) !==''){		
		    if (checkEmailAddress(trim(form.email.value))==false){
				alert("Invalid email address.");
		        return returnFalse(form.email);
		      }
	      }
		  i=0
		for(cnt=0;cnt<form.R1.length;cnt++){
			msg="";
			if(form.R1[cnt].checked) {
					i=1
			}		
		}
		if(i==0) {alert("Please check atleast one checkbox for web portal features.  "); return false;}
		
}		

//This function validates update account information from My Account page.
function updateAccount(){
	form = document.acctinfoFrm;
	if(trim(form.fname.value)==""){
		alert("Please enter first name.");
		return returnFalse(form.fname);
	}
	else if(checkname(trim(form.fname.value))==false){
		alert("Invalid first name.");
		return returnFalse(form.fname);
	}
	if(trim(form.lname.value)==""){
		alert("Please enter last name.");
		return returnFalse(form.lname);
	}
	else if(checkname(trim(form.lname.value))==false){
		alert("Invalid last name.");
		return returnFalse(form.lname);
	}
	
	///
		email_field =form.email.value;
		var re = /; /g;
		email_field = email_field.replace(re,',');
		var re = /;/g;
		email_field = email_field.replace(re,',');
		var re = /,/g;
		email_field = email_field.replace(re,',');
		var re = /, /g;
		email_field = email_field.replace(re,',');
		form.email.value=email_field;
	///
	if(trim(email_field) ==""){
		alert("Please enter email address.");
		return returnFalse(form.email);
	}	  
	else if (multiEmail(trim(email_field))==false){
		alert("Invalid email address.");
		return returnFalse(form.email);
	}
	form.action="myaccount.asp?u=y";
	form.submit();
}

//This function validates password information from My Account page.
function changePassword(){
	form = document.pwdFrm;
	if(trim(form.cpwd.value)==""){
		alert("Please enter current password.");
		return returnFalse(form.cpwd);
	}
	/*else if(trim(form.cpwd.value).length<8){
		alert("Current password should be at least 8 characters long.");
		return returnFalse(form.cpwd);
	}*/
	else if(checkAtleastOneNumber(trim(form.cpwd.value))==false){
		alert("Password should contain at least 1 number.");
		return returnFalse(form.cpwd);
	}
	else if(trim(form.cpwd.value.toLowerCase())!=trim(form.pname.value.toLowerCase())){
		alert("Incorrect Current password.");
		return returnFalse(form.npwd);
	}
	if(trim(form.npwd.value)==""){
		alert("Please enter new password.");
		return returnFalse(form.npwd);
	}
	else if(trim(form.npwd.value).length<8){
		alert("New password should be at least 8 characters long.");
		return returnFalse(form.npwd);
	}
	else if(checkAtleastOneNumber(trim(form.npwd.value))==false){
		alert("New Password should contain at least 1 number.");
		return returnFalse(form.npwd);
	}
	else if(checkAtleastOneOtherThanNumber(trim(form.npwd.value))==false){
		alert("New Password should contain at least 1 alphabet other than number.");
		return returnFalse(form.npwd);
	}
	if(trim(form.cpwd.value.toLowerCase())==trim(form.npwd.value.toLowerCase())){
		alert("Current password and new password can not be same.");
		return returnFalse(form.npwd);
	}
	if(trim(form.npwd.value.toLowerCase())==trim(form.uname.value.toLowerCase())){
		alert("New password and username can not be same.");
		return returnFalse(form.npwd);
	}
	if(trim(form.npwd.value.toLowerCase())!=trim(form.confpwd.value.toLowerCase())){
		alert("Confirm password failed.");
		return returnFalse(form.confpwd);
	}
	/////form.action="myaccount.asp?p=y";
	form.submit();
}
function validateMsg(id,today,e){
	
	form = document.serFrm;
	if(trim(form.title.value)==""){
		alert("Please enter message title.");
		return returnFalse(form.title);
	}
	if(trim(form.desc.value)==""){
		alert("Please enter message description.");
		return returnFalse(form.desc);
	}
	
	if(trim(form.pubDateTxt.value)==""){
		alert("Please enter publish date.");
		return returnFalse(form.pubDateTxt);
	}else if(istodayorgreaterDate(today,trim(form.pubDateTxt.value))==false){
		alert("Publish date should be todays date or greater.");
		return returnFalse(form.pubDateTxt);
	}
	if(trim(form.expDateTxt.value)==""){
		//alert("Please enter expiry date.");
		//return returnFalse(form.expDateTxt);
	}else if(istodayorgreaterDate(trim(form.pubDateTxt.value),trim(form.expDateTxt.value))==false){
		alert("Expiration date should be equal to publish date or greater.");
		return returnFalse(form.expDateTxt);
	}
	if(id>0) form.action="message.asp?id="+id+"&e="+e;
	else form.action="message.asp?e="+e;	
	form.submit();
}

function validateAccountinfo(id,e)	{ 	
	form = document.serFrm;
	if(trim(form.fname.value) ==""){
		alert("Please enter first name.");
		return returnFalse(form.fname);
	}
	else if(checkname(trim(form.fname.value))==false){
		alert("Invalid first name.");
		return returnFalse(form.fname);
	}
	if(trim(form.lname.value) ==""){
		alert("Please enter last name.");
		return returnFalse(form.lname);
	}
	else if(checkname(trim(form.lname.value))==false){
		alert("Invalid last name.");
		return returnFalse(form.lname);
	}
	if(trim(form.uname.value)==""){
		alert("Please enter user name.");
		return returnFalse(form.uname);
	}
	else if(trim(form.uname.value).length<6){
		alert("User name should be at least 6 characters long.");
		return returnFalse(form.uname);
	}
	else if(validatePasswordpadQuotes(trim(form.uname.value))==false){
		alert("Invalid user name.\nCharachers not allowed are: \"-/' =");
		return returnFalse(form.uname);
	}
	if(trim(form.pwd.value)==""){
		alert("Please enter password.");
		return returnFalse(form.pwd);
	}
//	else if(trim(form.pwd.value).length<8){
//		alert("password should be at least 8 characters long.");
//		return returnFalse(form.pwd);
//	}
//	else if(checkAtleastOneNumber(trim(form.pwd.value))==false){
//		alert("Password should contain at least 1 number.");
//		return returnFalse(form.pwd);
//	}
//	else if(checkAtleastOneOtherThanNumber(trim(form.pwd.value))==false){
//		alert("Password should contain at least 1 alphabet other than number.");
//		return returnFalse(form.pwd);
//	}
	if(trim(form.pwd.value.toLowerCase())==trim(form.uname.value.toLowerCase())){
		alert("password and username can not be same.");
		return returnFalse(form.pwd);
	}
	if(trim(form.pwd.value.toLowerCase())!=trim(form.confpwd.value.toLowerCase())){
		alert("Confirm password failed.");
		return returnFalse(form.confpwd);
	}
	
	else if(validatePasswordpadQuotes(trim(form.pwd.value))==false){
		alert("Invalid password.\nCharachers not allowed are: \"-/ =");
		return returnFalse(form.pwd);
	}
	if(trim(form.pwd.value)==trim(form.uname.value)){
		alert("User name and password can not be same.");
		return returnFalse(form.confpwd);
	}
	if(trim(form.pwd.value)!=trim(form.confpwd.value)){
		alert("Confirm password failed.");
		return returnFalse(form.confpwd);
	}
	email_field =form.email.value;
	var re = /; /g;
	email_field = email_field.replace(re,',');
	var re = /;/g;
	email_field = email_field.replace(re,',');
	var re = /,/g;
	email_field = email_field.replace(re,',');
	var re = /, /g;
	email_field = email_field.replace(re,',');
	form.email.value=email_field;
	if(trim(email_field) ==""){
		alert("Please enter email address.");
		return returnFalse(form.email);
	}	  
	
	else if (multiEmail(trim(email_field))==false){
		alert("Invalid email address.");
		return returnFalse(form.email);
	}
	/*else if (checkEmailAddress(trim(form.email.value))==false){
		alert("Invalid email address.");
		return returnFalse(form.email);
	}*/
	i=0
	for(cnt=0;cnt<form.R1.length;cnt++){
		msg="";
		if(form.R1[cnt].checked) {
			if(form.R1[cnt].value==1) {
				i=1
			}else if(form.R1[cnt].value==2) {
				i=1
			}
		}		
	}
	if(i==0) {alert("Please check atleast one account security profile.  "); return false;}

	for(cnt=0;cnt<form.R1.length;cnt++){
		msg="";
		if(form.R1[cnt].checked) {
			if(form.R1[cnt].value==1) {
				if (trim(form.elxun.value)=="") { msg+="Missing ELX username\n"; }
				if (trim(form.elxpw.value)=="") { msg+="Missing ELX password\n"; }
			}else if(form.R1[cnt].value==2) {
				if (trim(form.pcid.value)=="") { msg+="Missing ELX PCID\n"; }
			}
		}		
		if(msg!="") {alert(msg); return false;}
	}

	if(id>0) form.action="addupdatedeleteAccount.asp?acct=up&id="+id+"&e="+e;
	else form.action="addupdatedeleteAccount.asp?acct=in&e="+e;
	form.submit();
}	
function getPassword(){
	form = document.pwdFrm;
	if(trim(form.uname.value)==""){
		alert("Please enter user name.");
		return returnFalse(form.uname);
	}
	else if(trim(form.uname.value).length<6){
		alert("User name should be at least 6 characters long.");
		return returnFalse(form.uname);
	}
	else if(validatePassword(trim(form.uname.value))==false){
		alert("Invalid user name.\nCharachers not allowed are: \"-/' =");
		return returnFalse(form.uname);
	}
	form.submit();
}
///Function to change the class of link 

function changeclassoflink(obj){

	 var inc=0; 
	 var alltags= parent.document.getElementsByName("usedinclass"); 
	 for (i=0; i<alltags.length; i++){ 
	   if (alltags[i].className=="menu1")
		 alltags[i].className="menu";
	 } 
 	parent.document.getElementById(obj).className="menu1";	
	}
	
function changeclassoflink1(obj1,obj2){
 	parent.document.getElementById(obj1).className="menu11";	
	parent.document.getElementById(obj2).className="menu11";	
	}
	
/* Validate Event */	
	
function validateevent(id){
	
	form = document.EventFrm;
	if (!radio_button_checker (form.status,"Please select status.")){return false;} 
	
	if(trim(form.Event_name.value)==""){
		alert("Please enter event name.");
		return returnFalse(form.Event_name);
	}else if(checkEventactivity(trim(form.Event_name.value))==false){
		alert("Invalid event name.");
		return returnFalse(form.Event_name);
	}
	if(trim(form.Event_DateTxt.value)==""){
		alert("Please enter event date.");
		return returnFalse(form.Event_DateTxt);
	}
	if(id>0) form.action="../includes/addupdatedeleteevent.asp?id="+id+"&a=u";
	else form.action="../includes/addupdatedeleteevent.asp?a=i";	
	form.submit();
}

function validateactivity(id,eventid){
	if(id==0) form = document.addevent;
	else form = document.editevent;
	
	if(trim(form.activity_name.value)==""){
		alert("Please enter activity name.");
		return returnFalse(form.activity_name);
	}else if(checkEventactivity(trim(form.activity_name.value))==false){
		alert("Invalid activity name.");
		return returnFalse(form.activity_name);
	}
	
	if(id>0) form.action="../includes/addupdatedeleteactivity.asp?id="+id+"&a=u&eventid="+eventid;
	else form.action="../includes/addupdatedeleteactivity.asp?a=i&eventid="+eventid;	
	form.submit();
}


function eventregister(id,eventid,action){
	if(id==0) form = document.frmEventregister;
	else form = document.editevent;
	
	if(trim(form.fname.value)==""){
		alert("Please enter first name.");
		return returnFalse(form.fname);
	}else if(checkname(trim(form.fname.value))==false){
		alert("Invalid first name.");
		return returnFalse(form.fname);
	}
	if(trim(form.lname.value)==""){
		alert("Please enter last name.");
		return returnFalse(form.lname);
	}else if(checkname(trim(form.lname.value))==false){
		alert("Invalid last name.");
		return returnFalse(form.lname);
	}
	
		if (!radio_button_checker (form.PurchaseAuthority,"Please select purchasing authority.")){return false;} 

		if (trim(form.actycount.value) >1){
			if (!radio_button_checker (form.activity,"Please select at least one activity.")){return false;} 
		}else if (form.activity.checked==false)
		{alert("Please select at least one activity.");return false;}
		
	
	if (!action) action = "../includes/addupdatedeleteeventregister.asp";
	
	if(id>0) form.action=action+"?id="+id+"&a=u&eventid="+eventid;
	else form.action=action+"?a=i&eventid="+eventid;	
	return true;
}


function validateimportAccount(){
	
	form = document.frmImport;
	if(trim(form.accounts.value)==""){
		alert("Please enter first name.");
		return returnFalse(form.accounts);
	}
	if(trim(form.filetype.value)==""){
		alert("Please enter first name.");
		return returnFalse(form.filetype);
	}
	if(trim(form.blob.value)==""){
		alert("Please enter first name.");
		return returnFalse(form.blob);
	}else{
		filename = form.blob.value;
		if(filename.substring(filename.length-3).toLowerCase()!="csv"){
			alert("Please select a CSV File.");
			return returnFalse(form.blob);
		}
	}
	form.submit();
}

