// JavaScript Document
/* This Function for  to check  textbox value is Email ID  or not */

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
/* This Function for  to check  textbox value is empty or not */
function notEmpty(elem, helperMsg){
	 
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}
return true;
}
/* This Function for  to count  textbox value length */
function countlength(elem, helperMsg,len){
	 
	if(elem.value.length <=len ){
		alert(helperMsg);
		elem.focus();
		return false;
	}
return true;
}
function checkspecialchar(elem, helperMsg,iChars){
	
			var str=elem.value;
			for(var i = 0; i < str.length; i++) {
						if (iChars.indexOf(str.charAt(i)) != -1) 
						{
							alert(helperMsg);
							elem.focus();
						return false;
						}
			}	
			return true;
}
function checkallspace(elem, helperMsg){
	
			var str=elem.value;
			 
			var iChars=" ";
			var  j=0;
		      if(str.length >0)
			  {
			for(var i = 0; i < str.length; i++) {
						if (iChars.indexOf(str.charAt(i)) != -1) 
						{
							 j++;
						
						}
			}	
			if(str.length==j)
			{
                 alert(helperMsg);
			     elem.focus();
			     return false;

			}
			  }
			return true;
}
function checkalldot(elem, helperMsg){
	
			var str=elem.value;
			var iChars=".";
			var  j=0;
			for(var i = 0; i < str.length; i++) {
						if (iChars.indexOf(str.charAt(i)) != -1) 
						{
							 j++;
						
						}
			}	
			if(str.length==j)
			{
                 alert(helperMsg);
			     elem.focus();
			     return false;

			}
			
			return true;
}
function madeSelection(elem, helperMsg){
	if(elem.value == ""){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
function Equal(elem1,elem2, helperMsg){
	 
	if(elem1.value!=elem2.value){
		alert(helperMsg);
		elem1.focus();
		return false;
	}
return true;
}
function IsNumeric(elem1,helperMsg)
   //  check for valid numeric strings	
   {
			var strString=elem1.value
			var strValidChars = "0123456789.";
			var strChar;
			var blnResult = true;

 		  if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
          alert(helperMsg);
		elem1.focus();
		return false;
         }
      }
   return true;
   }

// If the element's string matches the regular expression it is all numbers
function is_Numeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


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;
}


//If the element's string matches the regular expression it is numbers and letters
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
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){
	// 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;
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);
}
/*-------------------------This Function For Compare Date--------------------------------------*/
 function compareDates (value1, value2) 
		{
		   var date1, date2;
		   var month1, month2;
		   var year1, year2;
		
		   month1 = value1.substring (0, value1.indexOf ("-"));
		   date1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
		   year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);
		
		   month2 = value2.substring (0, value2.indexOf ("-"));
		   date2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
		   year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);
		
		   if (year1 > year2) return 1;
		   else if (year1 < year2) return -1;
		   else if (month1 > month2) return 1;
		   else if (month1 < month2) return -1;
		   else if (date1 > date2) return 1;
		   else if (date1 < date2) return -1;
		   else return 0;
		} 
function checkAll(str,iChars)	
{
	var cnt=0;
	for(var i = 0; i < str.length; i++) {
						if (iChars.indexOf(str.charAt(i)) != -1) 
						{
							 cnt++;
						
						}
			}	
			return cnt;
}

 function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}