//swap images

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//------------------------------------------------------------------------------
//Email  validation

function validMail(obj)	{				
	var EmailOk  = true
	var Temp     = obj
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(obj.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      EmailOk = false
		      alert("Please enter a valid e-mail address!");
			      Temp.value="";
			      Temp.focus();
		      return EmailOk;
   			}
		}
	}
	
function Email_Validation(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
		
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	
	
	//Email
	
	theForm.Email.value = LTrim(theForm.Email.value);
	theForm.Email.value = RTrim(theForm.Email.value);
	if (!emptystring(theForm.Email.value))
		 {
			alert("Please enter the Email Address");
			theForm.Email.focus();
			flag=false;
			return (false);
		}
		
		// Name
	theForm.firstName.value = LTrim(theForm.firstName.value);
	theForm.firstName.value = RTrim(theForm.firstName.value);
	if (!emptystring(theForm.firstName.value))
		 {
			alert("Please enter your Name");
			theForm.firstName.focus();
			flag=false;
			return (false);
		}
  
	   else {

           var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' .";
			if (!(validate(theForm.firstName.value,checkOk)))
				{
				alert("Please enter the Name properly");
				theForm.firstName.value="";
				theForm.firstName.focus();
				flag=false;
				return (false);
				}
		}
		
				// Phonenumber
	theForm.phNo.value = LTrim(theForm.phNo.value);
	theForm.phNo.value = RTrim(theForm.phNo.value);
	if (!emptystring(theForm.phNo.value))
		 {
			alert("Please enter your Phone Number");
			theForm.phNo.focus();
			flag=false;
			return (false);
		}
  
	   else {

           var checkOk = "0123456789";
			if (!(validate(theForm.phNo.value,checkOk)))
				{
				alert("Please enter the Phone Number properly");
				theForm.phNo.focus();
				flag=false;
				return (false);
				}
		}
		
   	
	//Set this return value to true when you want to submit the form
	return (flag);
}


//-------------------------------------------------------

// sign up page
//Email  validation

function validMail(obj)	{				
	var EmailOk  = true
	var Temp     = obj
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(obj.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      EmailOk = false
		      alert("Please enter a valid e-mail address!");
			      Temp.value="";
			      Temp.focus();
		      return EmailOk;
   			}
		}
	}
	
function signup_Validation(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
		
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	
	
	//Email
	
	theForm.Email.value = LTrim(theForm.Email.value);
	theForm.Email.value = RTrim(theForm.Email.value);
	if (!emptystring(theForm.Email.value))
		 {
			alert("Please enter the Email Address");
			theForm.Email.focus();
			flag=false;
			return (false);
		}
		
		// FirstName
	theForm.FirstName.value = LTrim(theForm.FirstName.value);
	theForm.FirstName.value = RTrim(theForm.FirstName.value);
	if (!emptystring(theForm.FirstName.value))
		 {
			alert("Please enter your First Name");
			theForm.FirstName.focus();
			flag=false;
			return (false);
		}
  
	   else {

           var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' .";
			if (!(validate(theForm.FirstName.value,checkOk)))
				{
				alert("Please enter the First Name properly");
				theForm.FirstName.focus();
				flag=false;
				return (false);
				}
		}
		
		//Address
	theForm.StreetAddress.value = LTrim(theForm.StreetAddress.value);
	theForm.StreetAddress.value = RTrim(theForm.StreetAddress.value);
	if (!emptystring(theForm.StreetAddress.value))
		 {
			alert("Please enter the Address");
			theForm.StreetAddress.focus();
			flag=false;
			return (false);
		}
			
		//city
	theForm.city.value = LTrim(theForm.city.value);
	theForm.city.value = RTrim(theForm.city.value);
	if (!emptystring(theForm.city.value))
		 {
			alert("Please enter the City");
			theForm.city.focus();
			flag=false;
			return (false);
		}
		
			//State
	theForm.State.value = LTrim(theForm.State.value);
	theForm.State.value = RTrim(theForm.State.value);
	if (!emptystring(theForm.State.value))
		 {
			alert("Please enter the City");
			theForm.State.focus();
			flag=false;
			return (false);
		}
		
						
		
	//Set this return value to true when you want to submit the form
	return (flag);
}
		
		
		function signup_phone(){
	
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }
	
var p=document.form.phNo.value;

if((p.charAt(3)=='-')&&(p.charAt(7)=='-')&&(p.length=='12')){
	
	var checkOk = "1234567890-";
			if (!(validate(form.phNo.value,checkOk)))
				{
				alert("Invalid Telephone Number");
				form.phNo.value="";
				form.phNo.focus();
				flag=false;
				return (false);
				}
	
} else{
alert('Invalid Telephone Number.Please enter in ###-###-#### format');
document.form.phNo.value="";
document.form.phNo.focus();
}
} 