function check_pass() {
 var pass = document.signup.pass.value;
  if(pass.length<6) {
    document.getElementById('error7').innerHTML = 'Password must be at least 6 chars long!';
    document.getElementById('error7').style.border = '2px solid #ff0000';
document.getElementById('error7').style.backgroundColor = '#f6a7a7';
    document.getElementById('error7').style.padding = '0 5px 0 5px';
    document.getElementById('error7').style.width = '250px';
    document.getElementById('error7').style.display = 'block';
  } else {
    document.getElementById('error7').innerHTML = 'Password is OK.';
    document.getElementById('error7').style.border = '2px solid #23b53b';
    document.getElementById('error7').style.backgroundColor = '#a7f6b4';
    document.getElementById('error7').style.padding = '0 5px 0 5px';
   document.getElementById('error7').style.width = '250px';
    document.getElementById('error7').style.display = 'block';
 }
}

function check_pass2() {
  var pass = document.signup.pass.value;
  var pass2 = document.signup.pass2.value;
  if(pass!=pass2) {
    document.getElementById('error8').innerHTML = 'Both passwords don\'t match!';
    document.getElementById('error8').style.border = '2px solid #ff0000';
    document.getElementById('error8').style.backgroundColor = '#f6a7a7';
    document.getElementById('error8').style.padding = '0 5px 0 5px';
    document.getElementById('error8').style.width = '250px';
    document.getElementById('error8').style.display = 'block';
  } else {
    document.getElementById('error8').innerHTML = 'Repeated password is OK.';
    document.getElementById('error8').style.border = '2px solid #23b53b';
    document.getElementById('error8').style.backgroundColor = '#a7f6b4';
    document.getElementById('error8').style.padding = '0 5px 0 5px';
    document.getElementById('error8').style.width = '250px';
    document.getElementById('error8').style.display = 'block';
  }
}

function check_mail() {
        var httpRequest;
	var mail = document.signup.mail.value;
        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
            }
        } 
        else if (window.ActiveXObject) {
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                }

        if (!httpRequest) {
            return false;
        }
        httpRequest.onreadystatechange = function() { showresult(httpRequest); };
        httpRequest.open('GET', "script/check_mail.php" + "?m=" + mail + "&sid=" + Math.random(), true);
        httpRequest.send('');

}

function check_user() {
        var httpRequest;
	var user = document.signup.user.value;
        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
            }
        } 
        else if (window.ActiveXObject) {
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                }

        if (!httpRequest) {
            return false;
        }
        httpRequest.onreadystatechange = function() { showresult2(httpRequest); };
        httpRequest.open('GET', "script/check_user.php" + "?u=" + user + "&sid=" + Math.random(), true);
        httpRequest.send('');

}

function check_form() {
  var fname = document.signup.fname.value;
  //var lname = document.signup.lname.value;
  var mail = document.signup.email.value;
  var mail1 = document.signup.con_email.value;
  //var username = document.signup.user.value;
  var pass = document.signup.pass.value;
  var pass2 = document.signup.pass2.value;
  if(fname.length<1) {
    alert('You must enter your first name!');
    document.signup.fname.focus();
    return false;
  }  if ((mail==null)||(mail=="")){
		alert('You must enter your e-mail !');
    document.signup.email.focus();
		return false
	}
	 if (echeck(mail)==false){
		
		document.signup.email.focus();
		return false
	} if(mail != mail1) {
    alert("Both email id don't match!");
    document.signup.con_email.focus();
    return false;
  }if(pass==""||pass=="undefined") {
    alert('You must enter your password!');
    document.signup.pass.focus();
    return false;
  } if(pass.length<4) {
    alert('your password must be  atleast 4 characters!');
    document.signup.pass.focus();
    return false;
  }
   if(!(pass == pass2)) {
    alert("Both passwords don't match!");
    document.signup.pass2.focus();
    return false;
  }  {
    return true;
  }
}





function check_form2() {
  var fname = document.signup.fname.value;
  var lname = document.signup.lname.value;
  var phone = document.signup.phone.value;
  var city = document.signup.city.value;
  var state = document.signup.state.value;
  var mail = document.signup.mail.value;
  var pass = document.signup.pass.value;
  var pass2 = document.signup.pass2.value;
  var bttc = document.signup.bttc.value;
  if(fname.length<1) {
    alert('You must enter your first name!');
    document.signup.fname.focus();
    return false;
  }  if(lname.length<1) {
    alert('You must enter your last name!');
    document.signup.lname.focus();
    return false;
  } 
   if(phone.length<1) {
    alert('You must enter your proper Phone No!');
    document.signup.phone.focus();
    return false;
  }
  if(phone!=""){
 if(checkInternationalPhone(phone)==false) {
   alert('You must enter your proper Phone No!');
   document.signup.phone.focus();
   return false;
  }}
   if(city.length<1) {
    alert('You must enter your city name!');
    document.signup.city.focus();
    return false;
  }  if(state.length<1) {
    alert('You must enter your state name!');
    document.signup.state.focus();
    return false;
  } if ((mail==null)||(mail=="")){
		alert('You must enter your e-mail !');
    document.signup.mail.focus();
		return false
	}
	 if (echeck(mail)==false){
		document.signup.mail.value=""
		document.signup.mail.focus();
		return false
	}  if(pass.length>0) {
     if(pass.length<4) {
    alert('your password must be 4 character!');
    document.signup.pass.focus();
    return false;
  } 
   if(!(pass == pass2)) {
    alert("Both passwords don't match!");
    document.signup.pass.focus();
    return false;
  } } 
    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("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function showresult(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
	        if (httpRequest.responseText == "1") {
		  document.getElementById('error6').innerHTML = 'Mail format is not valid!';
		  document.getElementById('error6').style.border = '2px solid #ff0000';
		  document.getElementById('error6').style.backgroundColor = '#f6a7a7';
		  document.getElementById('error6').style.padding = '0 5px 0 5px';
		  document.getElementById('error6').style.width = '250px';
		  document.getElementById('error6').style.display = 'block';
		}
	        else if (httpRequest.responseText == "2") {
		  document.getElementById('error6').innerHTML = 'Mail is already in use!';
		  document.getElementById('error6').style.border = '2px solid #ff0000';
		  document.getElementById('error6').style.backgroundColor = '#f6a7a7';
		  document.getElementById('error6').style.padding = '0 5px 0 5px';
		  document.getElementById('error6').style.width = '250px';
		  document.getElementById('error6').style.display = 'block';
		}
	        else {
		  document.getElementById('error6').innerHTML = 'Mail is OK.';
		  document.getElementById('error6').style.border = '2px solid #23b53b';
		  document.getElementById('error6').style.backgroundColor = '#a7f6b4';
		  document.getElementById('error6').style.padding = '0 5px 0 5px';
		  document.getElementById('error6').style.width = '250px';
		  document.getElementById('error6').style.display = 'block';
		}
		return httpRequest.responseText;
            }
        }
}

function showresult2(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
	        if (httpRequest.responseText == "1") {
		  document.getElementById('error9').innerHTML = 'User must be at least 3 chars long!';
		  document.getElementById('error9').style.border = '2px solid #ff0000';
		  document.getElementById('error9').style.backgroundColor = '#f6a7a7';
		  document.getElementById('error9').style.padding = '0 5px 0 5px';
		  document.getElementById('error9').style.width = '250px';
		  document.getElementById('error9').style.display = 'block';
		}
	        else if (httpRequest.responseText == "2") {
		  document.getElementById('error9').innerHTML = 'This user is already in use!';
		  document.getElementById('error9').style.border = '2px solid #ff0000';
		  document.getElementById('error9').style.backgroundColor = '#f6a7a7';
		  document.getElementById('error9').style.padding = '0 5px 0 5px';
		  document.getElementById('error9').style.width = '250px';
		  document.getElementById('error9').style.display = 'block';
		}
	        else {
		  document.getElementById('error9').innerHTML = 'User Name is OK.';
		  document.getElementById('error9').style.border = '2px solid #23b53b';
		  document.getElementById('error9').style.backgroundColor = '#a7f6b4';
		  document.getElementById('error9').style.padding = '0 5px 0 5px';
		  document.getElementById('error9').style.width = '250px';
		  document.getElementById('error9').style.display = 'block';
		}
		return httpRequest.responseText;
            }
        }
}

// Declaring required variables for checking valid phone number
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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
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){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



