// JavaScript Document

function checkform ()
{
  // see http://www.thesitewizard.com/archive/validation.shtml
  // for an explanation of this script and how to use it on your
  // own website

  // ** START **
// alert (document.signup.plan[1].checked);

  if (document.signup.userName.value=="") {
    alert( "Please enter your desired username" );
    document.signup.userName.focus();
    return false ;
	
  }
  
  if (document.signup.password.value=="") {
    alert( "Please enter your desired password" );
    document.signup.password.focus();
    return false ;
	
  }
    if (document.signup.password2.value=="") {
    alert( "Please retype your password" );
    document.signup.password2.focus();
    return false ;	
  }
  if (document.signup.password.value!=document.signup.password2.value) {
    alert( "The passwords you entered doesn't match, Please verify them" );
	document.signup.password.value="";
	document.signup.password2.value="";
    document.signup.password.focus();
    return false ;	
  }
   /* if (document.signup.firstName.value=="") {
    alert( "Please enter your first name" );
    document.signup.firstName.focus();
    return false ;	
  }
  
      if (document.signup.lastName.value=="") {
    alert( "Please enter your last name" );
    document.signup.lastName.focus();
    return false ;	
  }
    if (document.signup.address.value=="") {
    alert( "Please enter your address" );
    document.signup.address.focus();
    return false ;	
  }
    if (document.signup.city.value=="") {
    alert( "Please enter the city name" );
    document.signup.city.focus();
    return false ;	
  }
    if (document.signup.state.value=="") {
    alert( "Please enter the state" );
    document.signup.state.focus();
    return false ;	
  }    if (document.signup.zip.value=="") {
    alert( "Please enter your Zip Code" );
    document.signup.zip.focus();
    return false ;	
  }    if (document.signup.country.value=="") {
    alert( "Please enter your country" );
    document.signup.country.focus();
    return false ;	
  }    
  
      if (ValidatePhone()==false)
	{
	return false ;	
	}

     // if (ValidateFax()==false)
//	{
	//return false ;	
	//}

 */
    if (ValidateEmail()==false)
	{
	return false ;	
	}
	
    if (document.signup.email.value!=document.signup.email2.value) {
    alert( "The e-mail addresses you entered doesn't match, Please verify them" );
    document.signup.email.focus();
    return false ;	
  }
  
    if (document.signup.Iagree.checked != true) {
    alert( "In order to Sign up, You have to read and accept the Terms of Service" );
    document.signup.Iagree.focus();
    return false ;
	}
  // ** END **
 // document.signup.password.value=document.signup.password.value + "@";
  document.signup.submit();
  return true ;
}

function checkupdateform()
{
  // see http://www.thesitewizard.com/archive/validation.shtml
  // for an explanation of this script and how to use it on your
  // own website

  // ** START **

  
  if (document.signup.password.value=="") {
    alert( "Please enter your desired password" );
    document.signup.password.focus();
    return false ;
	
  }
    if (document.signup.password2.value=="") {
    alert( "Please retype your passwords" );
   // document.signup.password2.focus();
	document.signup.firstName.focus();
    return false ;	
  }
  if (document.signup.password.value!=document.signup.password2.value) {
    alert( "The passwords you entered doesn't match, Please verify them" );
	document.signup.password.value="";
	document.signup.password2.value="";
    document.signup.password.focus();
    return false ;	
  }
    if (document.signup.firstName.value=="") {
    alert( "Please enter your first name" );
   // document.signup.firstName.focus();
    return false ;	
  }
    if (document.signup.lastName.value=="") {
    alert( "Please enter your last name" );
   // document.signup.lastName.focus();
    return false ;	
  }
    if (document.signup.address.value=="") {
    alert( "Please enter your address" );
    document.signup.address.focus();
    return false ;	
  }
    if (document.signup.city.value=="") {
    alert( "Please enter the city name" );
    document.signup.city.focus();
    return false ;	
  }
    if (document.signup.state.value=="") {
    alert( "Please enter the state" );
    document.signup.state.focus();
    return false ;	
  }    if (document.signup.zip.value=="") {
    alert( "Please enter your Zip Code" );
    document.signup.zip.focus();
    return false ;	
  }    if (document.signup.country.value=="") {
    alert( "Please enter your country" );
    document.signup.country.focus();
    return false ;	
  }    
  
      if (ValidatePhone()==false)
	{
	return false ;	
	}

     // if (ValidateFax()==false)
//	{
	//return false ;	
	//}

 
    if (ValidateEmail()==false)
	{
	return false ;	
	}
	
    if (document.signup.email.value!=document.signup.email2.value) {
    alert( "The e-mail addresses you entered doesn't match, Please verify them" );
    document.signup.email.focus();
    return false ;	
  }
  

  // ** END **

  document.signup.submit();
  return true ;
}

function checkadmupdateform()
{
  // see http://www.thesitewizard.com/archive/validation.shtml
  // for an explanation of this script and how to use it on your
  // own website

  // ** START **

  
  if (document.signup.password.value=="") {
    alert( "Please enter your desired password" );
    document.signup.password.focus();
    return false ;
	
  }

    if (document.signup.name.value=="") {
    alert( "Please enter your name" );
    document.signup.name.focus();
    return false ;	
  }
    if (document.signup.address.value=="") {
    alert( "Please enter your address" );
    document.signup.address.focus();
    return false ;	
  }
    if (document.signup.city.value=="") {
    alert( "Please enter the city name" );
    document.signup.city.focus();
    return false ;	
  }
    if (document.signup.state.value=="") {
    alert( "Please enter the state" );
    document.signup.state.focus();
    return false ;	
  }    if (document.signup.zip.value=="") {
    alert( "Please enter your Zip Code" );
    document.signup.zip.focus();
    return false ;	
  }    if (document.signup.country.value=="") {
    alert( "Please enter your country" );
    document.signup.country.focus();
    return false ;	
  }    
  
      if (ValidatePhone()==false)
	{
	return false ;	
	}

     // if (ValidateFax()==false)
//	{
	//return false ;	
	//}



  // ** END **

  document.signup.submit();
  return true ;
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("You have entered an invalid e-mail address. Please type it again")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("You have entered an invalid e-mail address. Please type it again")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("You have entered an invalid e-mail address. Please type it again")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("You have entered an invalid e-mail address. Please type it again")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("You have entered an invalid e-mail address. Please type it again")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("You have entered an invalid e-mail address. Please type it again")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("You have entered an invalid e-mail address. Please type it again")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(){
 if (document.signup.email.value=="") {
    alert( "Please your e-mail address" );
    document.signup.email.focus();
    return false ;	
  }

  if (document.signup.email2.value=="") {
    alert( "Please retype your e-mail address" );
    document.signup.email2.focus();
    return false ;	
  }
  	var emailID=document.signup.email;


	if (echeck(emailID.value)==false){
		document.signup.email.value="";
		document.signup.email2.value="";
		document.signup.email.focus()
		return false
	}
	return true
 }


/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(){
	var Phone=document.signup.phone;
	
	
	  if (document.signup.phone.value=="") {
    alert( "Please Enter your Phone Number" );
    document.signup.phone.focus();
    return false ;	
  }
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		document.signup.phone.value=""
		document.signup.phone.focus()
		return false
	}
	return true
 }

function ValidateFax(){
	var Phone=document.signup.fax;

  if (Phone=="") {
     Phone = "817-602-6884";
  }
	if (checkInternationalPhone(Phone)==false){
		alert("Please Enter a Valid Fax Number")
		document.signup.fax.value=""
		document.signup.fax.focus()
		return false
	}
	return true
 }