
/***************************************************************************************************************
*  
*      isWhitespace is using the if  Field Empty 
*
****************************************************************************************************************/
 var whitespace =" \t\n\r ";
function isEmpty(str)
{  
	//alert('asfd : '+str.length);
	return ((str == null) || (str.length == 0))
}
function validatePwd(pw1,pw2) 
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var maxLength = 20; 
	var pw11 = pw1.value;
	var pw12 = pw2.value;
// check for a value in both fields.
	if (pw11 == '' || pw12 == '') 
	{
		alert('Please Enter Password twice.');
		return false;
	}
	// check for minimum length
	if (pw1.value.length >= minLength && pw1.value.length <= maxLength) 
	{
		alert('Password should be between 6 - 20 characters');
		return false;
	}
	// check for spaces
	if (pw1.value.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		return false;
	}
	else
	{
	if (pw1 != pw2)
	{
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		return false;
	}
	else 
	{
			return true;
      }
   }
}

function isWhitespace(str)//where str=str.value
{    var i;
	 var flag
 	 if (isEmpty(str)) return true;	
	    for (i = 0; i < str.length; i++)
 	   {   
 	       // Check that current character isn't whitespace.
 	       var c = str.charAt(i);

		   if (whitespace.indexOf(c) == -1)
		   		return false
 	   }	
 	   // All characters are whitespace.
		    return true;
			
			//alert("Please Enter Username");
}
/***************************************************************************************************************
*  
*     END --- isWhitespace is using the if  Field Empty 
*
****************************************************************************************************************/
/***************************************************************************************************************
*  
*      emailValidator is using for email validation 
*
****************************************************************************************************************/
function emailValidator(email) 
{
	//email = document.f1.Email.value
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	//Message = ""
	str=email.substring(AtPos,StopPos)
	pos=str.indexOf(".")
	if (email == "")
	{
		/*Message = "Not a valid Email address" + "\n"
		*/
		return false;
	}
	else if (AtPos == -1 || StopPos == -1)
	{
		/*Message = "Not a valid email address"
		*/
		return false;
	}
	else if (StopPos < AtPos)
	{
		/*Message = "Not a valid email address"
		*/
		return false;
	}
	else if (StopPos - AtPos == 1) 
	{
		/*Message = "Not a valid email address"
			*/
		return false;
	}
	else if(pos!=-1)
	{
		return false;
	}
	else
	{
	return true
	}
}
/*function emailValidator(str)// wher str=str no .value
{
	//var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(str.value.match(emailExp))
	{
		return false;
	}
	else
	{
		//alert(helperMsg);
		//elem.focus();
		return true;
	}
}
*/

/***************************************************************************************************************
*  
*     END END--- emailValidator is using for email validation 
*
****************************************************************************************************************/
/***************************************************************************************************************
*  
*     password validation 
*
****************************************************************************************************************/
function checkPassword (str) //where str=str.value
{
 	//var error = "";
	if (isWhitespace(str))
	{
		// error = "You didn't enter a password.\n";
		return true;
	}
    var illegalChars = /[\W_]/; // allow only letters and numbers no underscores this time
    if ((str.length < 6) || (str.length > 12))
	{
       //error = "The password is the wrong length.\n";
	   return true;
    }
    else if (str.match(illegalChars)) 
	{
      //error = "The password contains illegal characters.\n";
	  return true;
    }
	/*else if (!((strng.search(/[a-z]+/) > -1)
  && (strng.search(/[A-Z]+/) > -1)
  && (strng.search(/[0-9]+/) > -1))) {
  error = "The password must contain at least one 
    uppercase letter, one lowercase letter,
    and one numeral.\n";*/

	return false;
 }
  
/***************************************************************************************************************
*  
*     END END--- password validation
*
****************************************************************************************************************/
/***************************************************************************************************************
*  
*     Username validation
*
****************************************************************************************************************/
function checkUsername (str) //where str=str.value
{
 	//var error = "";
	if (isWhitespace(str))
	{
		// error = "You didn't enter a password.\n";
		return true;
	}
    var illegalChars = /\W/; // allow only letters , numbers and underscores this time
    if ((str.length < 4) || (str.length > 24))
	{
       //error = "The password is the wrong length.\n";
	   return true;
    }
    else if (str.match(illegalChars)) 
	{
      //error = "The password contains illegal characters.\n";
	  return true;
    }
	/*else if (!((strng.search(/[a-z]+/) > -1)
  && (strng.search(/[A-Z]+/) > -1)
  && (strng.search(/[0-9]+/) > -1))) {
  error = "The password must contain at least one 
    uppercase letter, one lowercase letter,
    and one numeral.\n";*/

	return false;
 }
  
/***************************************************************************************************************
*  
*     END END--- Username validation
*
****************************************************************************************************************/

/***************************************************************************************************************
*  
*      Phone number validation
*
****************************************************************************************************************/
function checkPhonenumber(str)
{
		var stripped = str.replace(/[\(\)\.\-\ ]/g, '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped)))
		{
				//error = "The phone number contains illegal characters.";
				return true;
		}
		if (!(stripped.length == 10)) 
		{
			//error = "The phone number is the wrong length.
			 // Make sure you included an area code.\n";
			 return true;
			 
		}
		return false;
}
/***************************************************************************************************************
*  
*     End EndEnd Phone number validation
*
****************************************************************************************************************/
/***************************************************************************************************************
*  
*     checkDropdown()
*
****************************************************************************************************************/
function checkDropdown(choice)//choice=choice.value
{
    var error = "";
    if (choice == 0)
	{
       //error = "You didn't choose an option
        // from the drop-down list.\n";
		return true;
    }    
	return false; 
}   
		   
/***************************************************************************************************************
*  
*     End EndEnd checkDropdown()
*
****************************************************************************************************************/
/************************************************************************************************************************************Phone number validation
 * 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 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);
}

function ValidatePonenumber(Phone)
{
	//var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		//alert("Please Enter your Phone Number"+Phone.value)
		//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*****************************************************************************************************************************isNumeric(elem)----Phone number validation-----------------End of phone number validation
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*********************************************************************************************************************************/
function isNumeric(elem)
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))
	{
		return false;
	}
	else
	{
		//alert(helperMsg);
		//elem.focus();
		return true;
	}
}
/************************************************************************************************************************************END---isNumeric(elem
 
 *********************************************************************************************************************************/

/********************************************************************
function to check numeric values
*********************************************************************/

function checkNumeric(number,msgString)
{
   
	if(isNaN(number.value))
	{
		number.value = "";
		alert("Please enter only numeric value for " + msgString);
		//number.focus();
		return false;	
	}
	else
	{
		if (number.value.indexOf('e') >= 0)
		{
			number.value = "";
			alert("Please enter only numeric value for " + msgString);
			//number.focus();
			return false;	
		}
		else if (number.value < 0)
		{
		    number.value = "";
			alert("Please do not enter negative value for " + msgString);
			//number.focus();
			return false;
		}  
		else
		{
		return true;
		} 		
	}
	  
}

/********************************************************************
Emd
*********************************************************************/
