//---------------------- function AutoLogin() - To goto my account page when user is automatically logged in
function AutoLogin()
{
	var full_url = "../index.php?action=inbox";

	document.location.href=full_url;

}


function ShowLoginScreen()
{

	var full_url = "../index.php?action=loginscreen";

	document.location.href=full_url;		
}


//------------------------------ Function to validate user login form ----------------


function validateLoginForm()                           // function to validate correct entries into login form
{
	invalidFlag=false;
	var unL = window.document.userloginform.UN.value.length;
	var pwL = window.document.userloginform.PW.value.length;




	if((unL<5) && (invalidFlag==false))
	{
		alert("Please enter your User Name of atleast 5 chars");
		invalidFlag=true;
		window.document.userloginform.UN.focus();
	}


//----------------- Password limit and matching with confirm password---------------




	if((pwL<6) && (invalidFlag==false))
	{
		alert("Please enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.userloginform.PW.focus();
	}


	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
		return true;            // all entries entered in correct format i.e. form passes client side scripting
	else
		return false;            // one or more entries incorrect. DO NOT submit form



}         //------------------------------- function closed


//-------------------------- Function AddNewUser() - to navigate to New User (under a existing customer Account) creation page ----

function addNewUser()
{
	var full_url = "../index.php?action=newuserform";
	document.location.href=full_url;		
}


//------------------------------ Function to validate new account registration form ----------------


function validateNewUserAccountForm()                           // function to validate correct entries into new account registration form
{


	invalidFlag=false;
	var unL = window.document.NewUserAccount_Form.UN.value.length;
	var fnL = window.document.NewUserAccount_Form.FN.value.length;
	var emL = window.document.NewUserAccount_Form.EM.value.length;

	var pw1L = window.document.NewUserAccount_Form.PW1.value.length;
	var pw2L = window.document.NewUserAccount_Form.PW2.value.length;

	var mnL= window.document.NewUserAccount_Form.MN.value.length;
	var mnV= window.document.NewUserAccount_Form.MN.value;
	var countryV=window.document.NewUserAccount_Form.country.value;

	var dailysmslimitV=window.document.NewUserAccount_Form.dailysmslimit.value;
	var dailysmslimitL=window.document.NewUserAccount_Form.dailysmslimit.value.length;

	


	if((fnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Full Name");
		invalidFlag=true;
		window.document.NewUserAccount_Form.FN.focus();
	}


	if((unL<5) && (invalidFlag==false))
	{
		alert("Please choose User Name of atleast 5 Characters");
		invalidFlag=true;
		window.document.NewUserAccount_Form.UN.focus();
	}



//----------- Email validation ------------

	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.NewUserAccount_Form.EM.focus();
	}

	var emailText=window.document.NewUserAccount_Form.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.NewUserAccount_Form.EM.focus();
	}

//---------------- Email Validation Ends----------------------



//----------------- Password limit and matching with confirm password---------------

	var pw1Text=window.document.NewUserAccount_Form.PW1.value;
	var pw2Text=window.document.NewUserAccount_Form.PW2.value;



	if((pw1L<6) && (invalidFlag==false))
	{
		alert("Please enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.NewUserAccount_Form.PW1.focus();
	}

	if((pw2L<6) && (invalidFlag==false))
	{
		alert("Please Re enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.NewUserAccount_Form.PW2.focus();
	}

	if((pw1Text!=pw2Text) && (invalidFlag==false))
	{
		alert("Password and Confirm Password fields does not match");
		invalidFlag=true;
		window.document.NewUserAccount_Form.PW1.value="";
		window.document.NewUserAccount_Form.PW2.value="";
		window.document.NewUserAccount_Form.PW1.focus();
	}
//-------------- Password validation ends here ----------------





//---------------- Mobile Number Checking ------------------



	// MOBILE NUMBER IS OPTIONAL - but if entered (mnL>0) then check the format


	if((mnL>0) && (invalidFlag==false))      // if their are characters in mobile number field
	{
		


		var ret=false;
		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)

		if((ret==false) && (invalidFlag==false))
		{
			alert("Invalid characters in Mobile Number");
			invalidFlag=true;
			window.document.NewUserAccount_Form.MN.focus();

		}



		if((mnL<8) && (invalidFlag==false))
		{
			alert("Please enter mobile number with atleast 8 digits");
			invalidFlag=true;
			window.document.NewUserAccount_Form.MN.focus();
		}

	}




//---------- If Replypath is send to mobile then check for existence and format of mobile number -------------
//
//		var setMobileReply = window.document.NewUserAccount_Form.replytomobile.checked;
//
//		if((setMobileReply==true) && (mnL==0) && (invalidFlag==false))
//		{
//			alert("Cannot Select Reply to Mobile as Mobile Number field is empty");
//			window.document.NewUserAccount_Form.MN.focus();
//		
//			invalidFlag=true;
//
//		}



//-------------------------Daily Sms limit checking ------------------

	if((dailysmslimitL==0) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit");
		invalidFlag=true;
		window.document.NewUserAccount_Form.dailysmslimit.focus();


	}


	if(((dailysmslimitV<0) || (dailysmslimitV>5000)) && (invalidFlag==false))

	{
		alert("Please enter Daily Limit between 0 and 5000. For setting limit over 5000 please contact us");
		invalidFlag=true;
		window.document.NewUserAccount_Form.dailysmslimit.focus();


	}
	
	var type1 = isNumeric(dailysmslimitV);

	if((type1==false) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit in numeric format");
		invalidFlag=true;
		window.document.NewUserAccount_Form.dailysmslimit.focus();


	}






//------------ Country selection checking -----------------------

	if((countryV==0) && (invalidFlag==false))
	{
		alert("Please Select your Country");
		invalidFlag=true;
		window.document.NewUserAccount_Form.country.focus();


	}




//---------- Not for Subuser ------------------------
//----------------- Checkbox I Agree to terms and conditions -------------

//	if((!(window.document.NewUserAccount_Form.agreementCheckBox.checked)) && (invalidFlag==false))
//	{
//		alert("Please Tick I Agree box if you agree to our Terms and Conditions");
//		invalidFlag=true;
//		window.document.NewUserAccount_Form.agreementCheckBox.focus();
//
//	}






	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}         //------------------------------- function closed

//--------------- Function to check isNumeric for mobile number ------------

function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
//	var sField = new String(Trim(vTestValue));
	var sField=vTestValue;
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) ==  '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}















//------------------------------ Function to validate sub user updation form ----------------


function validateUpdateSubUserForm()                         
{


	invalidFlag=false;
//	var unL = window.document.UpdateSubUser_Form.UN.value.length;                     // Cannot change username
	var fnL = window.document.UpdateSubUser_Form.FN.value.length;
	var emL = window.document.UpdateSubUser_Form.EM.value.length;

	var pw1L = window.document.UpdateSubUser_Form.PW1.value.length;
	var pw2L = window.document.UpdateSubUser_Form.PW2.value.length;

//	var mnL= window.document.UpdateSubUser_Form.MN.value.length;
//	var mnV= window.document.UpdateSubUser_Form.MN.value;
//	var countryV=window.document.UpdateSubUser_Form.country.value;


	var dailysmslimitV=window.document.UpdateSubUser_Form.dailysmslimit.value;
	var dailysmslimitL=window.document.UpdateSubUser_Form.dailysmslimit.value.length;



	if((fnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Full Name");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.FN.focus();
	}


//	if((unL<2) && (invalidFlag==false))
//	{
//		alert("Please choose your User Name");
//		invalidFlag=true;
//		window.document.UpdateSubUser_Form.UN.focus();
//	}



//----------- Email validation ------------

	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.EM.focus();
	}

	var emailText=window.document.UpdateSubUser_Form.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.EM.focus();
	}

//---------------- Email Validation Ends----------------------



//----------------- Password limit and matching with confirm password---------------

	var pw1Text=window.document.UpdateSubUser_Form.PW1.value;
	var pw2Text=window.document.UpdateSubUser_Form.PW2.value;


if((pw1L>0) ||(pw2L>0))	                                // if admin actuallly want to change password by inputing value in pw1 or pw2 
{
	if((pw1L<6) && (invalidFlag==false))
	{
		alert("Please enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.PW1.focus();
	}

	if((pw2L<6) && (invalidFlag==false))
	{
		alert("Please Re enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.PW2.focus();
	}

	if((pw1Text!=pw2Text) && (invalidFlag==false))
	{
		alert("Password and Confirm Password fields does not match");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.PW1.value="";
		window.document.UpdateSubUser_Form.PW2.value="";
		window.document.UpdateSubUser_Form.PW1.focus();
	}

}
//-------------- Password validation ends here ----------------






//-------------------------Daily Sms limit checking ------------------

	if((dailysmslimitL==0) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.dailysmslimit.focus();


	}


	if(((dailysmslimitV<0) || (dailysmslimitV>5000)) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit between 0 and 5000. For setting limit over 5000 please contact us");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.dailysmslimit.focus();


	}
	
	var type1 = isNumeric(dailysmslimitV);

	if((type1==false) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit in numeric format");
		invalidFlag=true;
		window.document.UpdateSubUser_Form.dailysmslimit.focus();


	}






//---------------- Mobile Number Checking ------------------



// MOBILE NUMBER IS OPTIONAL - but if entered (mnL>0) then check the format
//
//
//	if((mnL>0) && (invalidFlag==false))      // if their are characters in mobile number field
//	{
//		
//
//
//		var ret=false;
//		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)
//
//		if((ret==false) && (invalidFlag==false))
//		{
//			alert("Invalid characters in Mobile Number");
//			invalidFlag=true;
//			window.document.UpdateSubUser_Form.MN.focus();
//
//		}
//
//
//
//		if((mnL<8) && (invalidFlag==false))
//		{
//			alert("Please enter mobile number with atleast 8 digits");
//			invalidFlag=true;
//			window.document.UpdateSubUser_Form.MN.focus();
//		}
//
//	}




//---------- If Replypath is send to mobile then check for existence and format of mobile number -------------

//		var setMobileReply = window.document.UpdateSubUser_Form.replytomobile.checked;
//
//		if((setMobileReply==true) && (mnL==0) && (invalidFlag==false))
//		{
//			alert("Cannot Select Reply to Mobile as Mobile Number field is empty");
//			window.document.UpdateSubUser_Form.MN.focus();
//		
//			invalidFlag=true;
//
//		}

//------------ Country selection checking -----------------------

//	if((countryV==0) && (invalidFlag==false))
//	{
//		alert("Please Select your Country");
//		invalidFlag=true;
//		window.document.UpdateSubUser_Form.country.focus();


//	}





//----------------- Checkbox I Agree to terms and conditions -------------

//	if((!(window.document.UpdateSubUser_Form.agreementCheckBox.checked)) && (invalidFlag==false))
//	{
//		alert("Please Tick I Agree box if you agree to our Terms and Conditions");
//		invalidFlag=true;
//		window.document.UpdateSubUser_Form.agreementCheckBox.focus();

//	}






	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}         //------------------------------- function closed


//----------------------- This function sets the value of replypath in hidden text box edit sub user form when reply path chackboxes are clicked -----------------
function setReplyPathValue()
{

	var emailreply = window.document.UpdateSubUser_Form.replytoemail.checked;
	var mobreply = window.document.UpdateSubUser_Form.replytomobile.checked;
	
	if((emailreply==true) && (mobreply==true))
	window.document.UpdateSubUser_Form.replypath.value ="3";
	
	if((emailreply==true) && (mobreply==false))
	window.document.UpdateSubUser_Form.replypath.value ="1";
	
	if((emailreply==false) && (mobreply==true))
	window.document.UpdateSubUser_Form.replypath.value ="2";
	
	if((emailreply==false) && (mobreply==false))
	window.document.UpdateSubUser_Form.replypath.value ="0";

	

}




//----------------------- This function sets the value of replypath in hidden text box edit sub user form when reply path chackboxes are clicked -----------------
function setReplyPathValue2()
{

	var emailreply = window.document.updatenonadminuserdetails_Form.replytoemail.checked;
	var mobreply = window.document.updatenonadminuserdetails_Form.replytomobile.checked;
	
	if((emailreply==true) && (mobreply==true))
	window.document.updatenonadminuserdetails_Form.replypath.value ="3";
	
	if((emailreply==true) && (mobreply==false))
	window.document.updatenonadminuserdetails_Form.replypath.value ="1";
	
	if((emailreply==false) && (mobreply==true))
	window.document.updatenonadminuserdetails_Form.replypath.value ="2";
	
	if((emailreply==false) && (mobreply==false))
	window.document.updatenonadminuserdetails_Form.replypath.value ="0";

	

}



//-------------------------------- Function to count the number of messages and characters in sms text typed by user --------------------

function countCharacters(charcount,smscount)
{



	var valueofmessage = document.smsform1.smsmessagebox.value;

	var lengthofmessage = document.smsform1.smsmessagebox.value.length;
			
	var numberofenterkeys = CountEnterKey(valueofmessage); 		// javascript treats carriage return as 2 chars but we have to treat is as 1 therefore, no. of carriage returns(1) is subtracted from fulllength(2)

	var actualmessagelength=document.smsform1.actuallength.value;			// will hold actual message length with carriage return counted as 2

	lengthofmessage = lengthofmessage - numberofenterkeys;
	
	if(lengthofmessage>765)
	{
		alert("Maximum Length is Reached");
		TruncateExtraText(actualmessagelength);
	}
	else
	{	
		actualmessagelength = lengthofmessage + numberofenterkeys;
		document.smsform1.actuallength.value = actualmessagelength;
	

	
	var remchar = 765 - lengthofmessage;

	var numofsms=0;
	if(lengthofmessage > 160)
	{
		if((lengthofmessage % 153) ==0)				// sms length in multiples of 153
		numofsms = (lengthofmessage / 153);
		else									// sms length not in multiples of 153 and remainder is present therefore increase sms count by 1
		numofsms = (parseInt(lengthofmessage / 153)) + 1;
	}

	else if((lengthofmessage > 0) && (lengthofmessage <= 160))
	{
		numofsms=1;				// sms less that 160 chars therefore sms count is only 1
	}

	document.smsform1.charcount.value = lengthofmessage;
	document.smsform1.remcharcount.value = remchar;
	document.smsform1.smscount.value = numofsms;
	document.smsform1.numsms.value = numofsms;
	
var numberofrecipients = document.smsform1.numrecipients.value;
document.smsform1.totalsms.value = numberofrecipients * numofsms;

	
}
		

}

//-------------------- Returns no. of carriage returns in a message / string ----------------------
function CountEnterKey(message)
{

var len = message.length;	
var counter=0;

for(var i=0;i<len;i++)
	{
		var c= message.charCodeAt(i);
		if(c==13)				// 13 and 10 both values are printed when a carriage return is encountered
		counter++;
		

	}

return counter;

}
//--------------------------------- Trucates extra text entered in message text area -----------------------------

function TruncateExtraText(actualmessagelength)
{
	var valueofmessage = document.smsform1.smsmessagebox.value;

	valueofmessage = valueofmessage.substring(0,actualmessagelength);
	
	document.smsform1.smsmessagebox.value = valueofmessage;
	
	
}

//----------------------------
function NumberOfRecipients()
{


	var reslist = document.smsform1.tosms.value;
	
	var reslistlength = document.smsform1.tosms.value.length;
	
	var counter=0;

	if(reslistlength!=0)
	{
		counter=1;						// atleast one recipient is present in list
		for(var i=0;i<reslistlength;i++)
		{
			if((reslist.charAt(i)==';') && (i != reslistlength-1))
			{
				counter++;
			}
				
		}
	
	
	}
	else
	{
		counter=0;
	}

document.smsform1.numrecipients.value = counter;

var numberofsms = document.smsform1.numsms.value;

document.smsform1.totalsms.value = counter * numberofsms;



}






//------------------- function to validate Add new contact group form -----------------------

function ValidateAddNewContactGroupForm()
{

var gnL = window.document.addnewcontactgroup.GN.value.length;
if(gnL<2)
{
	alert("Please Enter Atleast 2 Chars in Group name");
	window.document.addnewcontactgroup.GN.focus();
	return false;
}
else
{
	return true;
}


}




//---------------- function to validate add new contact form ------------------

function ValidateAddNewContactForm()
{

var invalidFlag=false;
var cnL = window.document.addnewcontact.CN.value.length;
var mnL = window.document.addnewcontact.MN.value.length;
var mnV = window.document.addnewcontact.MN.value;

var emL = window.document.addnewcontact.EM.value.length;

//---------- Contact Name checking -----------------------------
	if((cnL<2) && (invalidFlag==false))
	{
		alert("Please enter Contact Name");
		invalidFlag=true;
		window.document.addnewcontact.CN.focus();
	}


//---------------- Mobile Number Checking ------------------



	// MOBILE NUMBER IS COMPULSORY
	
	if((mnL==0) && (invalidFlag==false))
	{
		alert("Please Enter Mobile Number");
		invalidFlag=true;
		window.document.addnewcontact.MN.focus();
	}


	if((mnL>0) && (invalidFlag==false))      // if their are characters in mobile number field
	{
		


		var ret=false;
		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)

		if((ret==false) && (invalidFlag==false))
		{
			alert("Invalid characters in Mobile Number");
			invalidFlag=true;
			window.document.addnewcontact.MN.focus();

		}



		if((mnL<8) && (invalidFlag==false))
		{
			alert("Please enter mobile number with atleast 8 digits");
			invalidFlag=true;
			window.document.addnewcontact.MN.focus();
		}

	}

//----------- Email validation ------------

if((emL>0)&& (invalidFlag==false))			// --- EMAIL is Optional
{

	
	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter Email Address");
		invalidFlag=true;
		window.document.addnewcontact.EM.focus();
	}

	var emailText=window.document.addnewcontact.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.addnewcontact.EM.focus();
	}

}

//---------------- Email Validation Ends----------------------






	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}		//function closed






//------------------------------ function to goto editcontactgroups page on button click -----------------------
function EditContactGroups()
{
	var full_url = "../index.php?action=editcontactgroups";

	document.location.href=full_url;


}






//--------------------------- function to validate Edit Contact Form ---------------------------


function ValidateEditContactForm()
{

var invalidFlag=false;
var cnL = window.document.editcontactform.CN.value.length;
var mnL = window.document.editcontactform.MN.value.length;
var mnV = window.document.editcontactform.MN.value;

var emL = window.document.editcontactform.EM.value.length;

//---------- Contact Name checking -----------------------------
	if((cnL<2) && (invalidFlag==false))
	{
		alert("Please enter Contact Name");
		invalidFlag=true;
		window.document.editcontactform.CN.focus();
	}


//---------------- Mobile Number Checking ------------------


		if((mnL<8) && (invalidFlag==false))
		{
			alert("Please enter mobile number with atleast 8 digits");
			invalidFlag=true;
			window.document.editcontactform.MN.focus();
		}




		var ret=false;
		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)

		if((ret==false) && (invalidFlag==false))
		{
			alert("Invalid characters in Mobile Number");
			invalidFlag=true;
			window.document.editcontactform.MN.focus();

		}



//----------- Email validation ------------
   
   if((emL>0) && (invalidFlag==false))
   {
	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter Email Address");
		invalidFlag=true;
		window.document.editcontactform.EM.focus();
	}

	var emailText=window.document.editcontactform.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.editcontactform.EM.focus();
	}
    }
//---------------- Email Validation Ends----------------------






	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}




//------------------ ValidateRenameContactGroupForm() - Used to validate rename group form present in mycontacts.php --------------------------------------------

function ValidateRenameContactGroupForm()
{
	var newgroupnameL = window.document.renamecontactgroup.newgroupname.value.length;
	if(newgroupnameL<2)
	{
		alert("Please Enter Atleast 2 Chars in Group name");
		window.document.renamecontactgroup.newgroupname.focus();
		return false;
	}
	else
	{
		return true;
	}

}




//------------------- ContactGroupDeletionCancelled() - During Deletion Confirmation of Contact group if user click on Cancel Delete -------------

function ContactGroupDeletionCancelled()
{
	var full_url = "../index.php?action=editcontactgroups";

	document.location.href=full_url;
}



//------------------- ContactDeletionCancelled() - During Deletion Confirmation of Contact  if user click on Cancel Delete -------------

function ContactDeletionCancelled()
{
	var full_url = "../index.php?action=mycontacts";

	document.location.href=full_url;
}



//------------------- UserDeletionCancelled() - During Deletion Confirmation of user if user click on Cancel Delete -------------

function UserDeletionCancelled()
{
	var full_url = "../index.php?action=useraccounts";

	document.location.href=full_url;
}





//---------------------- During deletion of contact group if user clicked on Delete Contact group button i.e. deletion confirmed -----------------

function ContactGroupDeletionConfirmed()
{
	var full_url= document.location;

	full_url= full_url + "&confirm=confirmed";

	document.location.href=full_url;

}



//---------------------- During deletion of contact if user clicked on Delete Contact button i.e. deletion confirmed -----------------

function ContactDeletionConfirmed()
{
	var full_url= document.location;

	full_url= full_url + "&confirm=confirmed";

	document.location.href=full_url;

}


//---------------------- During deletion of user if user clicked on Delete user button i.e. deletion confirmed -----------------

function UserDeletionConfirmed()
{
	var full_url= document.location;

	full_url= full_url + "&confirm=confirmed";

	document.location.href=full_url;

}



//------------------------- After group category is changed (personal or shared) then this fuction will take user back to action=contactus page ----------
function DisplayEditContactGroups()
{
	var full_url = "../index.php?action=editcontactgroups";

	document.location.href=full_url;

}


//--------------------------- ValidateMoveContactsForm - used to validate movecontactform responsible to move contacts from one group to another -----------------------

function ValidateMoveContactsForm()
{

anycontactselected = 0; 	// represents if user has selected any contact for moving or not - 0 -no contact selected and 1 for atleast one contact selected

document.movecontactsform.hiddencontactidlist.value="";

var numberofcontacts= document.movecontactsform.contactsarray.length;
if(numberofcontacts==undefined)			// if only one contact is present then javascript is not treating the contactarray as array and showing undefined as length therefore set it to 1
numberofcontacts=1;

//alert("Length = " + a);

for (i = 0; i < numberofcontacts; i++)
{
    if(numberofcontacts==1)					// if only one contact is present then javascript does not treat contactarray as array[]
    {
		if(document.movecontactsform.contactsarray.checked)	
		{
				anycontactselected=1;				// user has selected atleast one contact		
				document.movecontactsform.hiddencontactidlist.value = (document.movecontactsform.contactsarray.value + ';');

		}
	}
	else									// if contact are more than 1 then javascript treat contactarray as array[]
	{
		if (document.movecontactsform.contactsarray[i].checked)
		{

			anycontactselected=1;				// user has selected atleast one contact
			document.movecontactsform.hiddencontactidlist.value = document.movecontactsform.contactsarray[i].value + ';' + document.movecontactsform.hiddencontactidlist.value;
		}
	}
}


var anygroupselected = 0;     // represent if user has selected any group or not as destination group to move contacts - 0 not selected , 1 selected

var destinationgroupid = document.movecontactsform.gp.value;
if(destinationgroupid>0)		// possible values here are -1 for Select Group, 0 for SHARED GROUP or PERSONAL GROUP and >0 for a groupid
{
	anygroupselected = 1;			// user has selected a valid group to move contacts		
}




var sourcegroupid = document.movecontactsform.hiddengroupid.value;
var destinationgroupid = document.movecontactsform.gp.value;			// accessible groups drop down box



if(anycontactselected==0)
{
	alert("Please Select(TICK) a Contact to Move into different Group");
	document.movecontactsform.hiddencontactidlist.value="";
	return false;
}

if(anygroupselected==0)
{
	alert("Please Select a Group to move Contact into");
	document.movecontactsform.gp.focus();
	document.movecontactsform.hiddencontactidlist.value="";
	return false;
}


if(sourcegroupid == destinationgroupid)				// the source and destination groups are same therefore do not submit form
{
	alert("You Cannot Move Contacts to same group. Please Choose a different group.");
	document.movecontactsform.gp.focus();
	return false;	

}



return true;			// every check is done and now submit form


}




//------------------------------- function to select all contact checkboxes when select all contact box is ticked and Vice versa (unselect) -----------

function SelectAllCheckboxes()
{

	var numberofcontacts= document.movecontactsform.contactsarray.length;
	if(numberofcontacts==undefined)			// if only one contact is present then javascript is not trating the contactarray as array and showing undefined as length therefore set it to 1
	numberofcontacts=1;
	
	if(document.movecontactsform.selectallcheckbox.checked)
	{
		for (i = 0; i < numberofcontacts; i++)
		{
		    if(numberofcontacts==1)
			document.movecontactsform.contactsarray.checked=true;
       	    else	
			document.movecontactsform.contactsarray[i].checked=true;
		}
	}
	else
	{
		for (i = 0; i < numberofcontacts; i++)
		{
		    if(numberofcontacts==1)
			document.movecontactsform.contactsarray.checked=false;
       	    else	
			document.movecontactsform.contactsarray[i].checked=false;
		}
	}

}



//-------------------- function to validate Update Postal address form -------------------

function ValidateUpdatePostalAddressForm()
{
	invalidFlag=false;

	var addressline1L = window.document.updatepostaladdressform.addressline1.value.length;

	var addressline2L = window.document.updatepostaladdressform.addressline2.value.length;

	var addressline3L = window.document.updatepostaladdressform.addressline3.value.length;

	var postcodeL = window.document.updatepostaladdressform.postcode.value.length;



	//------------------- Address lines 1-3 and postcode entry checking ----------------------
	if((addressline1L<4) && (invalidFlag==false))
	{
		alert("Please Enter your Address - Street Number and Name");
		invalidFlag=true;
		window.document.updatepostaladdressform.addressline1.focus();
	}

	if((addressline2L<3) && (invalidFlag==false))
	{
		alert("Please Enter your Address - Suburb and City");
		invalidFlag=true;
		window.document.updatepostaladdressform.addressline2.focus();
	}


	if((addressline3L<2) && (invalidFlag==false))
	{
		alert("Please Enter your Address - State");
		invalidFlag=true;
		window.document.updatepostaladdressform.addressline3.focus();
	}

	
	if((postcodeL<2) && (invalidFlag==false))
	{
		alert("Please Enter your Address - Post Code");
		invalidFlag=true;
		window.document.updatepostaladdressform.postcode.focus();
	}


if(invalidFlag==false)
{
	return true;			// all validations are performed and their is no problem
}
else
{
	return false;			// one or more validation failed  - do not submit form
}


}


//----------------------------- To got to Edit Contact Groups Page ---------
function GoBackToEditGroupsPage()
{
	var full_url = "../index.php?action=editcontactgroups";
	document.location.href=full_url;

}



//----------------------------- To got to Edit My Details for  ---------
function GotoUpdateMyDetails()
{
	var full_url = "../index.php?action=updatemydetails";
	document.location.href=full_url;

}

//---------------- to got to Update my Postal Address --------

function GotoUpdatePostalAddress()
{
	var full_url = "../index.php?action=updatepostaladdress";
	document.location.href=full_url;

}

//----------------- Used to go to configure account settings page ---------------------
function GotoConfigureAccountSettings()
{
	var full_url = "../index.php?action=configureaccountsettings";
	document.location.href=full_url;

}





function GotoURL(url)
{
	var full_url = "../index.php?action=" + url;
	document.location.href=full_url;
}



//-------------------------------------------------------------------


//------------------------------ Function to validate sub user updation form ----------------


function ValidateUpdateNonAdminUserDetailsForm()
{


	invalidFlag=false;
	var fnL = window.document.updatenonadminuserdetails_Form.FN.value.length;
	var emL = window.document.updatenonadminuserdetails_Form.EM.value.length;

	var pw1L = window.document.updatenonadminuserdetails_Form.PW1.value.length;
	var pw2L = window.document.updatenonadminuserdetails_Form.PW2.value.length;

	var mnL= window.document.updatenonadminuserdetails_Form.MN.value.length;
	var mnV= window.document.updatenonadminuserdetails_Form.MN.value;





	if((fnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Full Name");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.FN.focus();
	}






//----------- Email validation ------------

	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.EM.focus();
	}

	var emailText=window.document.updatenonadminuserdetails_Form.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.EM.focus();
	}

//---------------- Email Validation Ends----------------------



//----------------- Password limit and matching with confirm password---------------

	var pw1Text=window.document.updatenonadminuserdetails_Form.PW1.value;
	var pw2Text=window.document.updatenonadminuserdetails_Form.PW2.value;


if((pw1L>0) ||(pw2L>0))	                                // if admin actuallly want to change password by inputing value in pw1 or pw2 
{
	if((pw1L<6) && (invalidFlag==false))
	{
		alert("Please enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.PW1.focus();
	}

	if((pw2L<6) && (invalidFlag==false))
	{
		alert("Please Re enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.PW2.focus();
	}

	if((pw1Text!=pw2Text) && (invalidFlag==false))
	{
		alert("Password and Confirm Password fields does not match");
		invalidFlag=true;
		window.document.updatenonadminuserdetails_Form.PW1.value="";
		window.document.updatenonadminuserdetails_Form.PW2.value="";
		window.document.updatenonadminuserdetails_Form.PW1.focus();
	}

}
//-------------- Password validation ends here ----------------





//---------------- Mobile Number Checking ------------------



	// MOBILE NUMBER IS OPTIONAL - but if entered (mnL>0) then check the format


	if((mnL>0) && (invalidFlag==false))      // if their are characters in mobile number field
	{
		


		var ret=false;
		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)

		if((ret==false) && (invalidFlag==false))
		{
			alert("Invalid characters in Mobile Number");
			invalidFlag=true;
			window.document.updatenonadminuserdetails_Form.MN.focus();

		}



		if((mnL<8) && (invalidFlag==false))
		{
			alert("Please enter mobile number with atleast 8 digits");
			invalidFlag=true;
			window.document.updatenonadminuserdetails_Form.MN.focus();
		}

	}




//---------- If Replypath is send to mobile then check for existence and format of mobile number -------------
//
//		var setMobileReply = window.document.updatenonadminuserdetails_Form.replytomobile.checked;
//
//		if((setMobileReply==true) && (mnL==0) && (invalidFlag==false))
//		{
//			alert("Cannot Select Reply to Mobile as Mobile Number field is empty");
//			window.document.updatenonadminuserdetails_Form.MN.focus();
//		
//			invalidFlag=true;
//
//		}
//




	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}         //------------------------------- function closed










//--------------- Function to check isNumeric for mobile number ------------

function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
//	var sField = new String(Trim(vTestValue));
	var sField=vTestValue;
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == '+' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == '+' || (sField.charAt(x) ==  '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}




//------------- isChar equivalent in Javascript --------------

function isChar (Data)
{
varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";		// a-z plus 1 white space in the end
var isChar = true;
var index = 0;
	while ((index < Data.length) && (isChar))
	{
		isChar = (varChars.indexOf(Data.charAt(index)) != -1);
		index ++;
	}
	
	if (!isChar)
		return false;				// contains invalid char(s)
	else
		return true;				// does not contains invalid chars
}





//--------------------
function show()
{
	alert(window.document.NewAccount_Form.replytoemail.checked);
	alert(window.document.NewAccount_Form.replytomobile.checked);
}





//---------------------------------------------------------------------------------

function CheckMobile_Enable_Reply_To_Mobile(optionid)
{
/*
	var MNV = document.NewAccount_Form.MN.value;
	var MNL = document.NewAccount_Form.MN.value.length;
	
	var referenceToSpan1=document.getElementById(optionid);                    // returns reference to passed id as per w3c standards

	if(MNL>=8)					// mobile number has more than 8 digits
	{
		var returntype = isNumeric(MNV);
		if(returntype==true)			// mobile number entered is in digits and 8 or more chars long
		{
			referenceToSpan1.style.visibility="visible";		
//			document.NewAccount_Form.replytomobile.checked=false;
		}
	}
	else
	{
			referenceToSpan1.style.visibility="hidden";		
//			document.NewAccount_Form.replytomobile.checked=false;
	}

*/
	
}



//-----------------------------------------------------------------------------

function ValidateEnterMobileForm()
{

	var MNV = document.entermobileform.MN.value;
	var MNL = document.entermobileform.MN.value.length;
	
	if(MNL>=8)					// mobile number has more than 8 digits
	{
		return true;
	}
	else
	{
		alert("Please Enter Mobile Number with atleast 8 Digits");
		window.document.entermobileform.MN.focus();
		return false;
	}
//	return false;

}





//------------------------------------------------------------------------------


function ShowMessage(msgid)
{


	var msg = messages[msgid];
	alert(msg);


}




//---------------------------------------------------------------------------

function RefreshInbox()
{

	var full_url = document.location.href;
	document.location.href=full_url;	


}

//----------------------------------------------------------------------------
function ValidateDeleteSelectedFromInbox()
{

		anymessageselected = 0; 	// represents if user has selected any message for deletion or not - 0 -no message selected and 1 for atleast one message selected

		document.inboxform.hiddenmessageidlist.value="";

		var numberofmessages= document.inboxform.messagesarray.length;
			
		

		if(numberofmessages==undefined)			// if only one message is present then javascript is not treating the messagesarray as array and showing undefined as length therefore set it to 1
		numberofmessages=1;


		for (i = 0; i < numberofmessages; i++)
		{
		    if(numberofmessages==1)					// if only one contact is present then javascript does not treat messagesarray as array[]
		    {
				if(document.inboxform.messagesarray.checked)	
				{
						anymessageselected=1;				// user has selected atleast one message		
						document.inboxform.hiddenmessageidlist.value = (document.inboxform.messagesarray.value + ';');

				}
		   }
	         else									// if contact are more than 1 then javascript treat messagesarray as array[]
    	         {
    		           if (document.inboxform.messagesarray[i].checked)
 			     {

  					anymessageselected=1;				// user has selected atleast one contact
					document.inboxform.hiddenmessageidlist.value = document.inboxform.messagesarray[i].value + ';' + document.inboxform.hiddenmessageidlist.value;
			     }
	         }
          
		}

		if(anymessageselected==0)
		{
			alert("Please select message(s) for deletetion");
			return false;
		}  
		else					// one or more message selected for deletion
		{
			return true;
		}
		return false;

}



//---------------------------------------------------------------------
var globalcounter1=1;			// to record status of the select all button

function SelectAllCheckboxes_Inbox()
{


	globalcounter1++;
	
	var numberofmessages= document.inboxform.messagesarray.length;


	if(numberofmessages==undefined)			// if only one contact is present then javascript is not trating the contactarray as array and showing undefined as length therefore set it to 1
	numberofmessages=1;
	
	if(globalcounter1%2==0)					// button has text Select All	
	{
		for (i = 0; i < numberofmessages; i++)
		{
		    if(numberofmessages==1)
			document.inboxform.messagesarray.checked=true;
       	    else	
			document.inboxform.messagesarray[i].checked=true;
		}
		document.inboxform.selectall1.value="Unselect All";
	}
	else								// button has text unselect all 
	{
		for (i = 0; i < numberofmessages; i++)
		{
		    if(numberofmessages==1)
			document.inboxform.mesagesarray.checked=false;
       	    else	
			document.inboxform.messagesarray[i].checked=false;
		}
		document.inboxform.selectall1.value="  Select All  ";
		
	}

}

//-----------------------------------------------------------------

function newAccount(accounttype)
{
	if(accounttype == 1)
		document.getElementById('js1').value='1';
	else if(accounttype == 2)
		document.getElementById('js2').value='1';
	else if(accounttype == 3)
		document.getElementById('js3').value='1';
}

function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'width=500,height=400,resizable=yes,scrollbars=yes');
	return false;
}






//------------------------------------------------------------------------------------------------

function SendConfirmationCode()
{

	var mobile = window.document.entermobileform.MN.value;
	var mobileL = window.document.entermobileform.MN.value.length;
	
	if(mobileL<8)
	{
		alert("Please Enter Mobile Number with Atleast 8 digits");
		window.document.entermobileform.MN.focus();
		return false;

	}
	else
	{
		var full_url = "index.php?action=entermobile&sendcode=true&mobile=" + mobile;
		document.location.href=full_url;	

	}
	
}


//------------------------------------------------------------------------------------------------

function ReplyOptions()
{

	var referenceToSpan1 = document.getElementById("additional1");                    // returns reference to passed id as per w3c standards

	if(document.replysettings.mainreplygroup[0].checked==true)
	{
		referenceToSpan1.style.visibility="visible";

	}
	else
	{
		referenceToSpan1.style.visibility="hidden";


	}

}

//---------------------------------------------------------------------------------------------------



function ReplyOptions1()
{
	

	var referenceToSpan1 = document.getElementById("additional1");                    // returns reference to passed id as per w3c standards

	if(document.replysettings.mainreplygroup.checked==true)
	{
		referenceToSpan1.style.visibility="visible";

	}
	else
	{
		referenceToSpan1.style.visibility="hidden";


	}

}



//-----------------------------------------------------------------------------------------------------

function ValidateChangeDailySmsLimitForm()
{

	var dl = window.document.changedailysmslimit.dailylimit.value;
	var dlL = window.document.changedailysmslimit.dailylimit.value.length;
	if(dlL == 0)
	{
		alert("Please Enter Daily SMS Limit between 5-500");
		window.document.changedailysmslimit.dailylimit.focus();
		return false;			
	}
	else if(!(isNumeric(dl)))
	{
		alert("Please Enter Numeric SMS Daily Limit between 5-500");
		window.document.changedailysmslimit.dailylimit.focus();
		return false;			

	}
	else if((dl<5) || (dl>500))
	{
		alert("Please Enter Daily SMS Limit between 5-500");
		window.document.changedailysmslimit.dailylimit.focus();
		return false;			

	}	

	return true;	

}


//--------------------------------------------------------------------------------------------------------

function PaymentPreference1()
{

	var referenceTopid = document.getElementById("registercard1");                    // returns reference to passed id as per w3c standards
	referenceTopid.style.display="";
	

}

//--------------------------------------------------------------------------------------------------------

function PaymentPreference2()
{

	var referenceTopid = document.getElementById("registercard1");                    // returns reference to passed id as per w3c standards

	referenceTopid.style.display="none";
	
}


//-----------------------------------------------------------------------------------------------------------
function ValidateChangePaymentPreferenceForm()
{

	if(window.document.changepaymentpreference.preferencegroup[0].checked==true)			// pay by credit card preference selected	
	{
		var cn = window.document.changepaymentpreference.cardnumber.value;
		var cnL = window.document.changepaymentpreference.cardnumber.value.length;
		

		var ch = window.document.changepaymentpreference.cardholder.value;
		var chL = window.document.changepaymentpreference.cardholder.value.length;
		
		if(cnL<13)
		{
			alert("Please Enter Card Number");
			window.document.changepaymentpreference.cardnumber.focus();
			return false;
		}

		if(isNumeric(cn)==false)
		{
			alert("Please Enter Card Number in Numeric Format");
			window.document.changepaymentpreference.cardnumber.focus();
			return false;
		
		}
		
		
		if(chL < 3)
		{
			alert("Please Enter Card holder name");
			window.document.changepaymentpreference.cardholder.focus();
			return false;
		}
		


	}
	
	return true;
	
	


}

//-----------------------------------------------------------------------------------------------------------
function ValidateChangeCardDetailsForm()
{


		var cn = window.document.changecarddetails.cardnumber.value;
		var cnL = window.document.changecarddetails.cardnumber.value.length;
		

		var ch = window.document.changecarddetails.cardholder.value;
		var chL = window.document.changecarddetails.cardholder.value.length;
		
		if(cnL<13)
		{
			alert("Please Enter Card Number");
			window.document.changecarddetails.cardnumber.focus();
			return false;
		}

		if(isNumeric(cn)==false)
		{
			alert("Please Enter Card Number in Numeric Format");
			window.document.changecarddetails.cardnumber.focus();
			return false;
		
		}
		
		
		if(chL < 3)
		{
			alert("Please Enter Card holder name");
			window.document.changecarddetails.cardholder.focus();
			return false;
		}
		

	return true;

}






//---------------------------- Function to validate forgot password form -------------------------

function ValidateForgotPasswordForm()        //  function to validate Password Request form
{
	invalidFlag=false;
	var unL = window.document.ForgotPassword1.UN.value.length;

	var unV = window.document.ForgotPassword1.UN.value;

	var captchaL = window.document.ForgotPassword1.captcha.value.length;



	if((unL<2) && (invalidFlag==false))
	{
		alert("Please enter your User Name");
		invalidFlag=true;
		window.document.ForgotPassword1.UN.focus();
	}



	//-------- Check Presence of white spaces in user name (white spaces not allowed)
	var whitespacepresence = unV.indexOf(" ");
	if((whitespacepresence!=-1) && (invalidFlag==false))
	{
		alert("No spaces allowed in Username. Please Remove spaces");
		invalidFlag=true;
		window.document.ForgotPassword1.UN.focus();
	}




	if((captchaL<5) && (invalidFlag==false))
	{
		alert("Please enter 5 digit CODE");
		invalidFlag=true;
		window.document.ForgotPassword1.captcha.focus();
	}



	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{
		var referenceToSendingImage=document.getElementById('sending1');                    // returns reference to passed id sending please wait image as per w3c standards
		referenceToSendingImage.style.visibility="visible";

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}



}         //------------------------------- function closed


//---------------------------------------------------------------------------------------------------------------------------------------------

function ValidateConfirmPayments(mode)
{

	

	var cardnum = window.document.confirmpaymentform.cardnum.value;
	var cardnumL = window.document.confirmpaymentform.cardnum.value.length;
	
	var csv = window.document.confirmpaymentform.csv.value;
	var csvL = window.document.confirmpaymentform.csv.value.length;

	var cardholder = window.document.confirmpaymentform.cardholder.value;
	var cardholderL = window.document.confirmpaymentform.cardholder.value.length;

	
	if((cardnumL < 13) || (cardnumL > 19))						// min. length is 13 chars - max 19 chars
	{
		alert("Please Enter Card Number with atleast 13 digits and max. of 19 digits");
		window.document.confirmpaymentform.cardnum.focus();
		return false;
	}
	if(isNumeric(cardnum)==false)
	{
		alert("Please Enter Card Number in Numeric Format");
		window.document.confirmpaymentform.cardnum.focus();
		return false;

	}
	
	
	if((csvL < 3) || (csvL > 4))						// min. length is 13 chars - max 19 chars
	{
		alert("Please Enter Card Security Code with atleast 3 digits");
		window.document.confirmpaymentform.csv.focus();
		return false;
	}
	if(isNumeric(csv)==false)
	{
		alert("Please Enter Card Security Code in Numeric Format");
		window.document.confirmpaymentform.csv.focus();
		return false;

	}

	if(cardholderL<2)
	{
		alert("Please Enter Card Holder Name");
		window.document.confirmpaymentform.cardholder.focus();
		return false;
	}

	//------------------- ALL CHECKS COMPLETED ---------------------------------------

	
	if(mode==0)			// 1 - prefilled form is submitted - 0 main form is submitted
	{	
		s1.style.visibility="visible";
		s1.style.zIndex=3;				// set table on top of the page
		setTimeout('img1.src = "zapitadmin/_images/wait.gif"', 1000); 		// reload the image so that the animation does not stop - Very Important here to enable Animation
	}

	return true;

}




//--------------------------------------------------------------------------------------------------

function DisplaySecurityCodePicture()
{

	s2.style.position="absolute";
	s2.style.display="";


}

function CloseBox()
{
	s2.style.display="none";

}

//----------------------------------------------------------------------------------------------------------------------------

//------------------------------ Function to validate new account registration form ----------------


function validateNewAccountForm()                           // function to validate correct entries into new account registration form
{


	invalidFlag=false;

	var cnL = window.document.NewAccount_Form.CN.value.length;
	var cnV = window.document.NewAccount_Form.CN.value;
	
	var unL = window.document.NewAccount_Form.UN.value.length;
	var unV = window.document.NewAccount_Form.UN.value;

	var fnL = window.document.NewAccount_Form.FN.value.length;
	var fnV = window.document.NewAccount_Form.FN.value;


	var emL = window.document.NewAccount_Form.EM.value.length;

	var pw1L = window.document.NewAccount_Form.PW1.value.length;
	var pw2L = window.document.NewAccount_Form.PW2.value.length;

	var mnL= window.document.NewAccount_Form.MN.value.length;
	var mnV= window.document.NewAccount_Form.MN.value;


	//---- Physical Address

//	var addressline1L = window.document.NewAccount_Form.addressline1.value.length;

//	var addressline2L = window.document.NewAccount_Form.addressline2.value.length;

//	var addressline3L = window.document.NewAccount_Form.addressline3.value.length;

//	var postcodeL = window.document.NewAccount_Form.postcode.value.length;


	var countryV=window.document.NewAccount_Form.country.value;


	//---- Postal Address	

//	var postaladdressline1L = window.document.NewAccount_Form.postaladdressline1.value.length;

//	var postaladdressline2L = window.document.NewAccount_Form.postaladdressline2.value.length;

//	var postaladdressline3L = window.document.NewAccount_Form.postaladdressline3.value.length;

//	var postalpostcodeL = window.document.NewAccount_Form.postalpostcode.value.length;


//	var postalcountryV=window.document.NewAccount_Form.postalcountry.value;






	var defaultsecretquestionsV=window.document.NewAccount_Form.defaultsecretquestions.value;
	
	var usersecretquestionV=window.document.NewAccount_Form.usersecretquestion.value;
	var usersecretquestionL=window.document.NewAccount_Form.usersecretquestion.value.length;

	
	var usersecretanswerV=window.document.NewAccount_Form.usersecretanswer.value;
	var usersecretanswerL=window.document.NewAccount_Form.usersecretanswer.value.length;

	var dailysmslimitV=window.document.NewAccount_Form.dailysmslimit.value;
	var dailysmslimitL=window.document.NewAccount_Form.dailysmslimit.value.length;


		

	var captchaL = window.document.NewAccount_Form.captcha.value.length;


//-------------- company name length validation ---------------
	if((cnL>0)&&(cnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Company Name with atleast 2 chars");
		invalidFlag=true;
		window.document.NewAccount_Form.CN.focus();
	}




//-------------- fullname length validation ---------------	
	if((fnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Full Name");
		invalidFlag=true;
		window.document.NewAccount_Form.FN.focus();
	}

//---------------- Full name check for character other than a-z A-Z or white spaces ------------

	if((fnL>=2) && (invalidFlag==false))
	{
		 var noinvalidchar = false;
		 noinvalidchar = isChar (fnV);
		if(noinvalidchar == false)		// invalid chars exists
		{
			alert("Invalid Character in Fullname");
			window.document.NewAccount_Form.FN.focus();
			invalidFlag=true;

		}

	}


//--------- User name length validation -------------------------
	if((unL<5) && (invalidFlag==false))
	{
		alert("Please choose your User Name of atleast 5 Characters");
		invalidFlag=true;
		window.document.NewAccount_Form.UN.focus();
	}

//----------- User Name Check for Spaces -----------------
	if((unL>=5) && (invalidFlag==false))
	{
		var spacespresent = -1;			// initialization -1 means spaces not present 
		spacespresent = unV.indexOf(' ');		// returns -1 if string is not present

		if(spacespresent!=-1)				//space(s) present in username - do not submit form
		{
			alert("Spaces are not allowed in user name.");
			window.document.NewAccount_Form.UN.focus();
			invalidFlag=true;
		}
				
	}

//----------- Email validation ------------

	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.NewAccount_Form.EM.focus();
	}

	var emailText=window.document.NewAccount_Form.EM.value;

	var val1=emailText.indexOf("@");              // for existence of @ in email address

	var val2=emailText.indexOf(".");                  // for existence of . in email address

	var val3=emailText.indexOf(" ");                  // for existence of <space> in email address


	if(((val1==-1) || (val2==-1) || (val3!=-1)) && invalidFlag==false)                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter Correct Email Address");
		invalidFlag=true;
		window.document.NewAccount_Form.EM.focus();
	}

//---------------- Email Validation Ends----------------------



//----------------- Password limit and matching with confirm password---------------

	var pw1Text=window.document.NewAccount_Form.PW1.value;
	var pw2Text=window.document.NewAccount_Form.PW2.value;



	if((pw1L<6) && (invalidFlag==false))
	{
		alert("Please enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.NewAccount_Form.PW1.focus();
	}

	if((pw2L<6) && (invalidFlag==false))
	{
		alert("Please Re enter Password of atleast 6 characters");
		invalidFlag=true;
		window.document.NewAccount_Form.PW2.focus();
	}

	if((pw1Text!=pw2Text) && (invalidFlag==false))
	{
		alert("Password and Confirm Password fields does not match");
		invalidFlag=true;
		window.document.NewAccount_Form.PW1.value="";
		window.document.NewAccount_Form.PW2.value="";
		window.document.NewAccount_Form.PW1.focus();
	}
//-------------- Password validation ends here ----------------





//---------------- Mobile Number Checking ------------------
	

	// MOBILE NUMBER IS OPTIONAL

	//if((mnL==0) && (invalidFlag==false))      
	//{
	//	alert("Please Enter your Mobile Number");	
	//	invalidFlag=true;
	//	window.document.NewAccount_Form.MN.focus();
	//}

	

	

	if((mnL>0) && (invalidFlag==false))      // if their are characters in mobile number field
	{
		


		var ret=false;
		ret = isNumeric(mnV);                                      // isNumeric is not system function. It is defined in this file (see below)

		if((ret==false) && (invalidFlag==false))
		{
			alert("Invalid characters in Mobile Number");
			invalidFlag=true;

			window.document.NewAccount_Form.MN.focus();

		}



		if((mnL<8) && (invalidFlag==false))
		{
			alert("Please enter mobile number with atleast 8 digits");
			invalidFlag=true;
			window.document.NewAccount_Form.MN.focus();
		}

	}







//-------------------------Daily Sms limit checking ------------------

	if((dailysmslimitL==0) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit");
		invalidFlag=true;
		window.document.NewAccount_Form.dailysmslimit.focus();


	}


	if(((dailysmslimitV<0) || (dailysmslimitV>5000)) && (invalidFlag==false))

	{
		alert("Please enter Daily Limit between 0 and 5000. For setting limit over 5000 please contact us");
		invalidFlag=true;
		window.document.NewAccount_Form.dailysmslimit.focus();


	}
	
	var type1 = isNumeric(dailysmslimitV);

	if((type1==false) && (invalidFlag==false))
	{
		alert("Please enter Daily Limit in numeric format");
		invalidFlag=true;
		window.document.NewAccount_Form.dailysmslimit.focus();


	}












//---------- If Replypath is send to mobile then check for existence and format of mobile number -------------

//		var setMobileReply = window.document.NewAccount_Form.replytomobile.checked;
//
//		if((setMobileReply==true) && (mnL==0) && (invalidFlag==false))
//		{
//			alert("Cannot Select Reply to Mobile as Mobile Number field is empty");
//			window.document.NewAccount_Form.MN.focus();
//		
//			invalidFlag=true;
//
//		}



//------------------- Address lines 1-3 and postcode entry checking ----------------------
//	if((addressline1L<4) && (invalidFlag==false))
//	{
//		alert("Please Enter your Address - Street Number and Name");
//		invalidFlag=true;
//		window.document.NewAccount_Form.addressline1.focus();
//	}
//
//	if((addressline2L<3) && (invalidFlag==false))
//	{
//		alert("Please Enter your Address - Suburb and City");
//		invalidFlag=true;
//		window.document.NewAccount_Form.addressline2.focus();
//	}
//
//
//	if((addressline3L<2) && (invalidFlag==false))
//	{
//		alert("Please Enter your Address - State");
//		invalidFlag=true;
//		window.document.NewAccount_Form.addressline3.focus();
//	}
//
//	
//	if((postcodeL<2) && (invalidFlag==false))
//	{
//		alert("Please Enter your Address - Post Code");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postcode.focus();
//	}

//------------ Country selection checking -----------------------

	if((countryV==0) && (invalidFlag==false))
	{
		alert("Please Select your Country");
		invalidFlag=true;
		window.document.NewAccount_Form.country.focus();


	}




//-------------- Postal Address Validation -------------------------------------

//------------------- Address lines 1-3 and postcode entry checking ----------------------
//	if((postaladdressline1L<4) && (invalidFlag==false))
//	{
//		alert("Please Enter your Postal Address - Street Number and Name / P O Box");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postaladdressline1.focus();
//	}
//
//	if((postaladdressline2L<3) && (invalidFlag==false))
//	{
//		alert("Please Enter your Postal Address - Suburb and City");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postaladdressline2.focus();
//	}
//
//
//	if((postaladdressline3L<2) && (invalidFlag==false))
//	{
//		alert("Please Enter your Postal Address - State");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postaladdressline3.focus();
//	}
//
//	
//	if((postalpostcodeL<2) && (invalidFlag==false))
//	{
//		alert("Please Enter your Postal Address - Post Code");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postalpostcode.focus();
//	}
//
//------------ Country selection checking -----------------------

//	if((postalcountryV==0) && (invalidFlag==false))
//	{
//		alert("Please Select your Country in Postal Address");
//		invalidFlag=true;
//		window.document.NewAccount_Form.postalcountry.focus();
//
//
//	}








//------------------- Secret Question Validation **** NOW OPTIONAL----------------------------------
/*

	if((defaultsecretquestionsV!="0") && (invalidFlag==false))				// user has choosen secret question out of the given choices
	{
		if(usersecretanswerL<6)
		{
			alert("Please enter your secret answer (atleast 6 chars.)");
			window.document.NewAccount_Form.usersecretanswer.focus();
			invalidFlag=true;
		}

	}
	
	if((defaultsecretquestionsV=="0") && (invalidFlag==false))				// user has typed his own secret question
	{

		if(usersecretquestionL<6)
		{
			alert("Please enter your secret question (atleast 6 chars.)");
			window.document.NewAccount_Form.usersecretquestion.focus();
			invalidFlag=true;

		}	
		else if(usersecretanswerL<6)
		{
			alert("Please enter your secret answer (atleast 6 chars.)");
			window.document.NewAccount_Form.usersecretanswer.focus();
			invalidFlag=true;
		}

	}
*/


//---------------- Security Code Validation

	if((captchaL<5) && (invalidFlag==false))
	{
		alert("Please enter 5 digit CODE");
		invalidFlag=true;
		window.document.NewAccount_Form.captcha.focus();
	}



//----------------- Checkbox I Agree to terms and conditions -------------

	if((!(window.document.NewAccount_Form.agreementCheckBox.checked)) && (invalidFlag==false))
	{
		alert("Please Tick I Agree box if you agree to our Terms and Conditions");
		invalidFlag=true;
		window.document.NewAccount_Form.agreementCheckBox.focus();

	}






	// return either true or false to form tag which will determine wheather to submit form or not
	if(invalidFlag==false)
	{

		return true;            // all entries entered in correct format i.e. form passes client side scripting
	}
	else
	{
		return false;            // one or more entries incorrect. DO NOT submit form
	}




}         //------------------------------- function closed







//---------------------------------------------------------------------------------------------------------------------------------

function FillSecretQuestion()
{
	var defaultsecretquestionsV=window.document.NewAccount_Form.defaultsecretquestions.value;
	
	if(defaultsecretquestionsV!="0")
	{
		
		window.document.NewAccount_Form.usersecretquestion.value=defaultsecretquestionsV;
	}

	

}

//----------------------------------------------------------------------------------------------------------------------------------------

function ValidateEmailApiSettings()
{

	var eas = window.document.emailapisettingsform.emailapisettings.value;	
	if(eas=="-1")
	{
		alert("Please Choose new setting first");
		window.document.emailapisettingsform.emailapisettings.focus();
		return false;
	}
	
	return true;
	
}




//----------------------------------------------------------------------------------------------------------------------------------------

function SameAsAboveAddress()
{
	if(window.document.NewAccount_Form.sameasabove.checked)
	{
		window.document.NewAccount_Form.postaladdressline1.value = window.document.NewAccount_Form.addressline1.value;
		window.document.NewAccount_Form.postaladdressline2.value = window.document.NewAccount_Form.addressline2.value;
		window.document.NewAccount_Form.postaladdressline3.value = window.document.NewAccount_Form.addressline3.value;
		window.document.NewAccount_Form.postalpostcode.value = window.document.NewAccount_Form.postcode.value;
		window.document.NewAccount_Form.postalcountry.selectedIndex = window.document.NewAccount_Form.country.selectedIndex;

	}

	

}


//-----------------------------------------------------------------------------------------------------------------------------------------

function ValidatePurchaseOrderForm()
{
/*		// Customer should be able to set purchase number to empty string
	var pr = window.document.purchaseordersettingsform.prnum.value.length;
	if(pr==0)
	{
		alert("Please Enter Purchase Order Number");
		window.document.purchaseordersettingsform.prnum.focus();
		return false;
	}
*/
	return true;

}



//-----------------------------------------------------------------------------------------------------------------------------------------

function ValidateChangeBillingContactForm()
{
	var billcontactL = window.document.changebillingcontactform.billcontactname.value.length;
	if(billcontactL<2)
	{
		alert("Please Enter billing contact with atleast 2 chars");
		window.document.changebillingcontactform.billcontactname.focus();
		return false;
	}
	return true;

}





//---------------------------------------------------------------------------------------------------

function ValidateChangeUserDailyLimitForm()
{

	var dailylimitL = window.document.changedailylimit.dl.value.length;

	var dailylimit = window.document.changedailylimit.dl.value;
	
	if(dailylimitL==0)
	{
		alert("Please Enter daily limit");
		window.document.changedailylimit.dl.focus();
		return false;
	}
	
	if(isNumeric(dailylimit)==false)
	{
		alert("Please Enter daily limit in Numeric Format");
		window.document.changedailylimit.dl.focus();
		return false;

	}
	else
	{
		if((dailylimit<0) || (dailylimit>5000))
		{
			alert("Please Enter daily limit between 0 and 5000. For above 5000 please contact us");
			window.document.changedailylimit.dl.focus();
			return false;
		}
		else
		{

			return true;
		}
	}	

return false;

}

//-----------------------------------------------------------------------------------


function PrintReceipt()                                               // function for printing the Invoices
{
 this.print();
}




//-------------------------------------------------------------------------------

function ValidateChangeLowBalanceForm()
{
	invalidFlag=false;
	var lbV = window.document.lowbalanceform.newlb.value;

	var lbL = window.document.lowbalanceform.newlb.value.length;

	if(lbL==0)
	{
		alert("Please enter new threshold value between 0-5000");
		window.document.lowbalanceform.newlb.focus();
		return false;
	}
	else
	{
		if(isNumeric(lbV)==false)
		{
			alert("Please enter new threshold value between 0-5000");
			window.document.lowbalanceform.newlb.focus();
			return false;

		}
		else
		{
			if((lbV<0) || (lbV>5000))
			{
				alert("Please enter new threshold value between 0-5000");
				window.document.lowbalanceform.newlb.focus();
				return false;
			}
			else
			{

				return true;
			}

		}

	}

}





//-----------------------------------------------------------------------------------------------------------------------------------------

function ValidateChangeBillingEmailForm()
{
	var billemailL = window.document.changebillingcontactform.billemail.value.length;
	var billemail = window.document.changebillingcontactform.billemail.value;


		
	//----------- Email validation ------------

	if(billemailL<6)
	{
		alert("Please enter valid email address");
		window.document.changebillingcontactform.billemail.focus();
		return false;

	}

	

	var val1=billemail.indexOf("@");              // for existence of @ in email address

	var val2=billemail.indexOf(".");                  // for existence of . in email address

	var val3=billemail.indexOf(" ");                  // for existence of <space> in email address


	if((val1==-1) || (val2==-1) || (val3!=-1))                    // -1 will be returned if @ or . is missing from email address
	{
		alert("Please enter valid email address");
		window.document.changebillingcontactform.billemail.focus();
		return false;

	}

	//---------------- Email Validation Ends----------------------

	

	return true;

}



//--------------------------------------------------------------------------------------------------------------------------------------------------



function EnterBundleID(v)
{
	

	
}
//-------------------------------------------------------------------------------------------------------------------------------------------------


function validateSpecialChristmasForm()                           // function to validate correct entries into login form
{
	var cpL = window.document.buycr2.spcoupon.value.length;
	var cpV = window.document.buycr2.spcoupon.value;
	
	
	if(cpL<7)
	{
		alert("You need to have Coupon to buy this bundle. Please enter a valid coupon.");
		window.document.buycr2.spcoupon.focus();
		return false;
	}

	return true;
}



//--------------------------------------------------------------------------------------------------

function ShowFullComment(flag,id)
{
	
	var referenceToSpan=document.getElementById(id);                    // returns reference to passed id as per w3c standards
	
	if(flag==1)
	{
		
		referenceToSpan.style.display = "";	
		
	}
	else
	{
		referenceToSpan.style.display = "none";		
	}
}

//-----------------------------------------------------------------------------------------

