// JavaScript Document

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
 
// email related functions
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("Please Enter a valid Email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please Enter a valid Email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please Enter a valid Email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please Enter a valid Email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please Enter a valid Email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please Enter a valid Email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please Enter a valid Email")
		    return false
		 }

 		 return true					
	}
// end of email related functions 

// phone no related functions

/**
 * 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 ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
*/
// end of phone number related functions


 
 function validate(){
	 
	  if (document.myForm.name.value==""){
	alert("Please Enter Full Name")
	
	document.myForm.name.focus()
		return false;
	 }
	  var emailID=document.myForm.email;
	 if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter a valid Email");
		emailID.focus();
		return false;
	 }
	if (echeck(emailID.value)==false){
		
		emailID.focus();
		return false;
	}
	 
	 if ((document.myForm.phone.value==null)||(document.myForm.phone.value=="")){
		alert("Please Enter Phone no")
		
		document.myForm.phone.focus()
		return false
	 }
	
	if ((document.myForm.address.value==null)||(document.myForm.address.value=="")){
		alert("Please Enter Address")
		
		document.myForm.address.focus()
		return false
	 }
	 	if ((document.myForm.company.value==null)||(document.myForm.company.value=="")){
		alert("Please Enter Company Name")
		
		document.myForm.company.focus()
		return false
	 }
	
if ((document.myForm.username.value==null)||(document.myForm.username.value=="")){
		alert("Please Enter Username")
		
		document.myForm.username.focus()
		return false
	 }
	var x=document.myForm.password.value;
if (x.length<6){
		alert("The Password should have a minimum of 6 characters")
		
		document.myForm.password.focus()
		return false
	 }
	if ((document.myForm.password.value==null)||(document.myForm.password.value=="")){
		alert("Please Enter Password")
		
		document.myForm.password.focus()
		return false
	 }
	

if (document.myForm.password.value!=document.myForm.confirm_password.value){
		alert(" Password and Confirm Password should be identical")
		document.myForm.confirm_password.focus()
		return false
	 }
 

	return true;
 }

 
 function validate_update(){
	 
	  if (document.myForm.name.value==""){
	alert("Please Enter Full Name")
	
	document.myForm.name.focus()
		return false;
	 }
	  var emailID=document.myForm.email;
	 if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter a valid Email");
		emailID.focus();
		return false;
	 }
	if (echeck(emailID.value)==false){
		
		emailID.focus();
		return false;
	}
	 
	 if ((document.myForm.phone.value==null)||(document.myForm.phone.value=="")){
		alert("Please Enter Phone no")
		
		document.myForm.phone.focus()
		return false
	 }
	
	if ((document.myForm.address.value==null)||(document.myForm.address.value=="")){
		alert("Please Enter Address")
		
		document.myForm.address.focus()
		return false
	 }
	 	if ((document.myForm.company.value==null)||(document.myForm.company.value=="")){
		alert("Please Enter Company Name")
		
		document.myForm.company.focus()
		return false
	 }
	

	

if (document.myForm.new_password.value!=document.myForm.confirm_new_password.value){
		alert(" New Password and Confirm New Password should be identical")
		document.myForm.new_password.focus()
		return false
	 }
 

	return true;
 }



