//---------------------------- Function to add stuffall into favorites ----------------------

function bookmark_zapit()
{
var url="http://www.zapitsms.com";                                         // change url here when site domain is decided
var description="ZapitSMS - PC to mobile communications";
netscape="Please press CTRL+D to add a bookmark to this site.";
	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		alert(netscape);
	}

	
}


//------------------------------ Function to validate user login form ----------------


function validateLoginForm()                           // function to validate correct entries into login form
{
	invalidFlag=false;
	var un = window.document.userloginform.UN.value;
	var pw = window.document.userloginform.PW.value;

	if(un.toLowerCase() == "username")
	{
		alert("Please enter you username.");
		return false;
	}
	if(pw.toLowerCase() == "password")
	{
		alert("Please enter you password.");
		return false;
	}


	if((un.length<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((pw.length<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 newAccount() -  contruct a URL to goto New user form based on account type 0 for trial and 1 for normal account-----------------

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';
}





//------------------------------------------------------------Contact Us Submit Function ------------------------


function validateContactUsForm()
{


var invalidFlag=false;                 // initialization

nameL=window.document.ContactUs_Form.nameTextBox.value.length;     // variables followed by letter L hold length of value of var



emailL=window.document.ContactUs_Form.emailTextBox.value.length;

enquiryL=window.document.ContactUs_Form.enquiryMessage.value.length;


var emailText=window.document.ContactUs_Form.emailTextBox.value;

var securityCodeL=window.document.ContactUs_Form.captcha.value.length;


	if((nameL<2) && (invalidFlag==false))
	{
		alert("Please enter your Name");
		invalidFlag=true;
		nameL=window.document.ContactUs_Form.nameTextBox.focus();
	}





	if((emailL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.ContactUs_Form.emailTextBox.focus();
	}




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.ContactUs_Form.emailTextBox.focus();
	}



	if((enquiryL<2) && (invalidFlag==false))
	{
		alert("Please enter your Question");
		invalidFlag=true;
		window.document.ContactUs_Form.enquiryMessage.focus();
	}

	if((securityCodeL<5) && (invalidFlag==false))
	{
		alert("Please enter 5 digit Security Code");
		invalidFlag=true;
		window.document.ContactUs_Form.captcha.focus();
	}



	if(invalidFlag==false)
	{
		//alert("submit");
		//window.document.ContactUs_Form.submit();


		var referenceToSubmitButton=document.getElementById('submitButton');                    // returns reference to passed id as per w3c standards
		referenceToSubmitButton.style.visibility="hidden";

		var referenceToWaitText=document.getElementById('waittext');                    // returns reference to passed id as per w3c standards
		referenceToWaitText.style.visibility="visible";

		return(true);                   // ----- Submit Form as there is no problem with client side validations
	}
	else
	{
		return(false);                // ---- 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 changeInfoBox(boxid)
{
	var title = document.getElementById("box"+boxid);
	title.className = "infoboxes_top_green";
	var text = document.getElementById("box"+boxid+"_text");
	text.className = "infoboxes_green";
}

//------------
function changeInfoBoxBack(boxid)
{
	var title = document.getElementById("box"+boxid);
	title.className = "infoboxes_top";
	var text = document.getElementById("box"+boxid+"_text");
	text.className = "infoboxes";
}


//------------
function changeInfoBoxNew(boxid)
{
	var title = document.getElementById("box"+boxid);
	title.className = "infoboxes_top_green_new";
	var text = document.getElementById("box"+boxid+"_text");
	text.className = "infoboxes_green_new";
}

//------------
function changeInfoBoxBackNew(boxid)
{
	var title = document.getElementById("box"+boxid);
	title.className = "infoboxes_top_new";
	var text = document.getElementById("box"+boxid+"_text");
	text.className = "infoboxes_new";
}




//---------------------------------- Function to validate Contact us form ---------------------------------------

function validateContactUsForm()           // function to validate contact us form
{
	invalidFlag=false;
	var fnL = window.document.ContactUs1.FN.value.length;

	var captchaL = window.document.ContactUs1.captcha.value.length;

	var emL = window.document.ContactUs1.EM.value.length;
	
	var questL = window.document.ContactUs1.quest.value.length;

	if((fnL<2) && (invalidFlag==false))
	{
		alert("Please enter your Full Name");
		invalidFlag=true;
		window.document.ContactUs1.FN.focus();
	}
	
	
//----------- Email validation ------------

	if((emL<6) && (invalidFlag==false))
	{
		alert("Please enter your Email");
		invalidFlag=true;
		window.document.ContactUs1.EM.focus();
	}

	var emailText=window.document.ContactUs1.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.ContactUs1.EM.focus();
	}

//---------------- Email Validation Ends----------------------




	if((questL<10) && (invalidFlag==false))
	{
		alert("Please enter your question");
		invalidFlag=true;
		window.document.ContactUs1.quest.focus();
	}



	
	
	if((captchaL<5) && (invalidFlag==false))
	{
		alert("Please enter 5 digit CODE");
		invalidFlag=true;
		window.document.ContactUs1.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 clearField(field)
{
	if(field.value.toLowerCase() == "username")
	{
		field.value = '';
	}else if(field.value.toLowerCase() == "password")
	{
		field.value = '';
	}
}

function StopSpam()
{
	document.getElementById('email').innerHTML = "<a class='normallink' href='mailto:" + "info" + "@zapitsms.com'>info@zapitsms.com</a><br><a class='normallink' href='mailto:" + "support" + "@zapitsms.com'>support@zapitsms.com</a><br><a class='normallink' href='mailto:" + "sales" + "@zapitsms.com'>sales@zapitsms.com</a>";
}