//-----------validate email ID
function validateEmail(strEmail) 
{ 
    var at="@"; 
	var dot="."; 
    var lat=strEmail.indexOf(at); 
              var lstr=strEmail.length;
              var ldot=strEmail.indexOf(dot);
             if (strEmail.indexOf(at)==-1)
             {
                       alert("Invalid E-mail ID"); 
                        return false; 
                }
              if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)
             {
                 alert("Invalid E-mail ID"); 
                return false; 
                } 
             if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)
              {
                       alert("Invalid E-mail ID");
                          return false;
                  } 
                if (strEmail.indexOf(at,(lat+1))!=-1)
              {
                        alert("Invalid E-mail ID"); 
                        return false;
                  } 
             if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)
            { 
                    alert("Invalid E-mail ID");
                   return false; 
               } 
          if (strEmail.indexOf(dot,(lat+2))==-1)
                    { 
                            alert("Invalid E-mail ID");
                             return false; 
                    }
                if (strEmail.indexOf(" ")!=-1)
         { 
                 alert("Invalid E-mail ID");
                   return false;
              }
              if(strEmail.substring(lstr-1,lstr)==dot)
              {
                alert("Invalid E-mail ID");
                   return false;
              }
        return true;
 } 
 //----------------------------------------
	function dateVerify(datevalue)
{
	var strDate ;
	var month,day,year ;
	var datearray ;
	strDate = datevalue ;
	if(strDate.search("/") != -1 )
		datearray = strDate.split("/") ;
	else if(strDate.search("-") != -1 )
		datearray = strDate.split("-") ;
	else
		return(false) ;
	if(( datearray.length < 3 ) || ( datearray.length > 3 ) )
		return(false);
	
	m = datearray[0] ;
        d = datearray[1] ;
        y = datearray[2] ;
	if(isNaN(m))
		return(false) ;
	month = parseInt(m,10) ;
	if(isNaN(d))
		return(false) ;
	day = parseInt(d,10) ;
	if(isNaN(y))
		return(false) ;
	year = parseInt(y,10) ;
	if((day >= 1 && day <= 31) && ( month == 1 ) ||
		(day >= 1 && day <= 31) && ( month == 3 ) ||
		(day >= 1 && day <= 31) && ( month == 5 ) ||
		(day >= 1 && day <= 31) && ( month == 7 ) ||
		(day >= 1 && day <= 31) && ( month == 8 ) ||
		(day >= 1 && day <= 31) && ( month == 10 ) ||
		(day >= 1 && day <= 31) && ( month == 12 ))
	{
		if( year >= 1900 && year <= 9999 )
		{
			return(true) ;
		}
		else
			return(false) ;
	}
	else if((day >= 1 && day <= 30) && ( month == 4 ) ||
		(day >= 1 && day <= 30) && ( month == 6 ) ||
		(day >= 1 && day <= 30) && ( month == 9 ) ||
		(day >= 1 && day <= 30) && ( month == 11 ))
	{
		if( year >= 1900 && year <= 9999 )
		{
			return(true) ;
		}
		else
			return(false) ;	
	}
	else if((month == 2) && (year%4 == 0) && (day >= 1 && day <= 29))
	{
		if( year >= 1900 && year <= 9999 )
		{
			return(true) ;
		}
		else
			return(false) ;
	}
	else if((month == 2) && (day >= 1 && day <= 28))
	{
		if( year >= 1900 && year <= 9999 )
		{
			return(true) ;
		}
		else
			return(false) ;
		}
	else
		return(false) ;
}

function dateOnly(datevalue,datefield)
  {
	if(dateVerify(datevalue))
		return(true);
	else
	{
		//alert("The "+datefield+" is Invalalid Date. Please Enter Valid Date mm/dd/yyyy.") ;
		return(false) ;
	}
  }
  

///*************************
// --------------------- Triming string from left sides  ----------------------

function leftTrim(ltrimvalue)
{
	while(ltrimvalue.charAt(0)==' ')
		ltrimvalue = ltrimvalue.substr(1,ltrimvalue.length-1);
		
	return(ltrimvalue) ;
}

// --------------------- Triming string from right sides ----------------------

function rightTrim(rtrimvalue)
{
	while(rtrimvalue.charAt(rtrimvalue.length-1)==' ')
		rtrimvalue = rtrimvalue.substr(0,rtrimvalue.length-1);
	
	return(rtrimvalue) ;
}

function allTrim(atrimvalue)
{
	return(rightTrim(leftTrim(atrimvalue))) ;
}

function validcharOnly(charvalue,fieldname)
{
	invalid = "~/:<>`|^!;"
	charvalue = allTrim(charvalue) ;
	for(i=0;i<invalid.length;i++)
	{
		for(j=0;j<invalid.length;j++)
		{
			if(charvalue.charAt(j) ==  invalid.charAt(i))
			{
				alert("Only valid characters are allowed ") ;
				return(false);
			}
		}
	}
	for(i=0;i<charvalue.length;i++)
	{
		if(charvalue.charAt(i) == 66 || charvalue.charAt(i) == 39)
		{
			alert("Only valid characters are allowed ") ;
			return(false);
		}
	}
	return(true);
}
  
  //------------autoTab()moves mouse cursor automatically from one text field to next--------------
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
		}
		function containsElement(arr, ele) {
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			found = true;
			else
			index++;
			return found;
			}
		function getIndex(input) {
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
			return index;
			}
			return true;
			}
			
	//------------------Function to ckh float--------------------
	function isFloat(s)
		{   
			var i;
			var  defaultEmptyOK=false ;
			var emptyOk ;
			
			if (isEmpty(s))
			if (isFloat.arguments.length == 1)
			return defaultEmptyOK;
			else return (isFloat.arguments[1] == true);

			// Search through string's characters one by one
			// until we find a non-numeric character.
			// When we do, return false; if we don't, return true.

			for (i = 0; i < s.length; i++)
			{
				// Check that current character is number.
				var c = s.charAt(i);

				if (!isChar(c)) return false;
			}

				// All characters are numbers.
				return true;
			}	
			
				function isChar(c)
			{   return ((c >= "0") && (c <= "9") || (c == ".") )
			}	
	//-------------------function to chk integer-----------------
		function isInteger (s)
		{   
			var i;
			var  defaultEmptyOK=false ;
			var emptyOk ;
			
			if (isEmpty(s))
			if (isInteger.arguments.length == 1)
			return defaultEmptyOK;
			else return (isInteger.arguments[1] == true);

			// Search through string's characters one by one
			// until we find a non-numeric character.
			// When we do, return false; if we don't, return true.

			for (i = 0; i < s.length; i++)
			{
				// Check that current character is number.
				var c = s.charAt(i);

				if (!isDigit(c)) return false;
			}

				// All characters are numbers.
				return true;
			}
			
			function isEmpty(s)
			{
			   return ((s == null) || (s.length == 0))
		    }
                
			// Returns true if character c is a digit
			// (0 .. 9).
			function isDigit (c)
			{   return ((c >= "0") && (c <= "9"))
			}
     	//-----isWhitespace() functoin checks for empty values--------------------------
	
	 function isWhitespace (s)
	  { 
	    var whitespace = " \t\n\r";
	     var i;
		// Is s empty?
		if (isEmpty(s)) return true;

		// Search through string's characters one by one
		// until we find a non-whitespace character.
		// When we do, return false; if we don't, return true.

		for (i = 0; i < s.length; i++)
		{
			// Check that current character isn't whitespace.
			var c = s.charAt(i);

			if (whitespace.indexOf(c) == -1) return false;
		}

		// All characters are whitespace.
		return true;
	}
	
	//----------myRound() use for declare decimal place---------------
			 function myRound(num, numDecimalPlaces) {
			if (isNaN(num)) {
			alert ("Not a valid number");
			return;
		}
	      
		var strNum = new Number(num).toString();
		var decPos = strNum.indexOf(".")
		if (decPos == -1) {
			return num;
		} else {
			strDecPart = strNum.substring(decPos + 1);
	         
			if (strDecPart.length <= numDecimalPlaces) {
				return num;
			} else {
				if (strDecPart.charAt(numDecimalPlaces) >= 5) {
				var lastNum = new Number(strDecPart.charAt(numDecimalPlaces-1)) + 1;
				strDecPart = strDecPart.substring(0, numDecimalPlaces-1) + lastNum;
				} else {
				strDecPart = strDecPart.substring(0, numDecimalPlaces);
				}
				return new Number (strNum.substring(0, decPos) + "." + strDecPart);
			}
		}
   }