function CheckNull(Form,Field)
{ 
  var Fieldval,i,Fieldlength; 
  Fieldval = document[Form][Field].value;
  Fieldlength=(document[Form][Field]).value.length;
  for (i=0; i < Fieldlength; i++)
  {
    
    if ((document[Form][Field].value).charAt(i) == " ") 
		{continue;}
	else
        {break;}
  }
  
  if ( Fieldlength == i)
  { 
    alert("Please Enter "+document[Form][Field].name);
    document[Form][Field].focus();
    return(0); 
  }
  else{return(1);}
}
//----------------------------------------



   function codekeypresscheck(x)
   {
     aa = event.keyCode 
     if ((aa<65 || aa>90) && (aa<48 || aa>57) && (aa<97 || aa > 122)) 
     {
           alert("Special Characters not allowed")  
           return false
	 }		
   }
   
 
   function codeblurcheck(x)
   {
     reg = /[A-Z]|[a-z]|[0-9]/
     k=x.value
     if(k!="")
       { 
		for(i=0;i<k.length;i++)
			{
			 if(!reg.test(k.charAt(i)))
			   {
			     alert("Special Characters not allowed")
				 x.focus()	   
			     return false
			   }
			}
		}	
   }



function  removechar(x)
{
if(x.value.indexOf('*')!=-1)
{
a=x.value.split('*')
if(a[1]=="")
x.value=x.value.substring(0,x.value.length-1)
if(!isInteger(a[0]))
x.value=""
}
}


function isInteger(s)
 {   var i;
     for (i = 0; i < s.length; i++)
     {
             var c = s.charAt(i);
         if (((c < "0") || (c > "9"))) return false;
     }
        return true;
 }




function replaceAll(s)
{
	while(s.indexOf('~')!=-1)	
	{
		s=s.replace("~","'")
	}
	while(s.indexOf('^')!=-1)	
	{
		s=s.replace('^','"')
	}
	return s
}

function integerChk(x)
{
aa=event.keyCode;
if(((aa < 48 || aa >57)&& (aa!=13) &&(aa!=8) &&(aa!=32) )) 
{ 

 event.keyCode =0
	return false
	} 
} 

function phonenumber(v)
		{
aa=event.keyCode;
  
if(((aa < 48 || aa >57)&& (aa!=13) &&(aa!=8) &&(aa!=32) &&(aa!=40) &&(aa!=47) &&(aa!=45) && (aa!=41) &&(aa!=38))) 
{ 
 event.keyCode =0
	return false
	} 
}


function correctDiscount(y)
{
	if(parseFloat(y.value)>100.00)
	{
		alert("Discount cannot be greater than 100")
		y.focus()
		return false;
	}
	
	else
	return true
	
	
}


function chkDecimal(a,z)
{

	var a,x,y,i,z,count
	regInt=/^[0-9]|\.$/;
	x=a.length
	count=0
	for(i=0;i<x;i++)
	{

		if(!regInt.test(a.charAt(i)))
		{ 
		
			z.value=""
			z.focus()
			return false
		}
				
		if(a.charAt(i)=='.')
		{
			count++			
			if(count==1)
				y=i
		}
		
	}
	
	if(count>1)
	{
		alert("Only one Decimal Point is allowed")
		//z.value=""
		z.focus()
		return false;
	}
	
	if(x-y-1>2)
	{
	
		alert("Only two decimal digits are allowed")
         z.value=z.value.substring(0,z.value.length-1)
         event.keyCode=""
		z.focus()
		return false;
	}
	
	return true
}

function validatename(x)
{
var d
  d=event.keyCode;
  len=Trim(x.value).length
  flag=0
  //^,~,.
  if (d==94 || d==126)
   flag=1
   //.,',space
  if(d==46 || d==39 ||  d==32)
   	{		
		if(len==0) 	
		 flag=1

	}
	
	if(flag==1)
	{
	// alert("First Character Cannot be a Dot or Single Quote ")
	 //x.value=""
	 x.focus()
	 event.keyCode=0
	 return false
	 }
	 else
	 return true
}





function LTrim(str)
	
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
          var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}
function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;     
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}

	
function Trim(str)
	
  	 
	{
   return RTrim(LTrim(str));
}



//------------------------------------------
function TextAreaMaxlength(Form,Field,Length)   
{
 var Fieldval;
 Fieldval = document[Form][Field].value;
 if( (Fieldval).length > Length )
 { 
   alert(document[Form][Field].name+" Field Length Exceeds Max Allowed ("+Length+")");
   document[Form][Field].value = (document[Form][Field].value).substring(0,Length-2);
   return(0);
 }
 else {return(1);}   
}


function CheckEmail(Form,Field,Required)
{
 var str= document[Form][Field].value; 
 if (str != "")
 {
  var pos;
  pos = (str).indexOf("@");
   if ( pos < 0 ) 
     { alert("Email should be host@somexyz.com");
       document[Form][Field].focus();
       return(0);
     }
   else
    {
      if( (str).indexOf(".",pos) < 0 )  
       { alert("Email should be host@somexyz.com"); 
         document[Form][Field].focus();
         return(0);
       }
       else
       {   return(1); }
    } 
 }
 else if(Required)
 {
  alert("Email should be somexyz@domain.com");
  document[Form][Field].focus();
  return(0);
 }
 else if(!Required)
 {
   return(1);
 }  
}

function CheckSpecialChar(Form,Field)
{
 var Fieldval,Patterns;
 Patterns=/[']/;
 Fieldval = document[Form][Field].value;

  if( (Fieldval).indexOf("'") == -1)// && (Fieldval).indexOf("<") == -1 && (Fieldval).indexOf(">") == -1)
   { 
   return(1);
   }
  else
   { 
     alert("Special Character single quote(') is not Allowed, Please Check # "+document[Form][Field].name+" #");
      document[Form][Field].value=(document[Form][Field].value).replace(Patterns,"");
      document[Form][Field].focus();
      return(0);
   }
}

function SpaceBet(Form,Field)
{	
var Fieldval;
Fieldval=document[Form][Field].value;
if( (Fieldval).indexOf(" ") == -1)
   { 
   return(1);
   }
  else
   { 
alert("Blank Space Not Allowed In This Field");
document[Form][Field].value=(document[Form][Field].value).replace(" ","");
document[Form][Field].focus();
	}
}

function NumericOnly(Form,Field)
{
  var Patterns;
  Patterns=/\D/;
  document[Form][Field].value = (document[Form][Field].value).replace(Patterns,"");
  document[Form][Field].focus();
}

function CharOnly(Form,Field)
{
  var Patterns;
  Patterns=/\\|\||\^|\[|\]|[^\x20|^A-^Z]/i;
  document[Form][Field].value = (document[Form][Field].value).replace(Patterns,"");
  document[Form][Field].focus();
}


function Alphanumeric(Form,Field)
{
  var Patterns;
  Patterns=/\\|\||\^|\[|\]|[^\x20|^A-^Z|^0-^9]/i;
  document[Form][Field].value = (document[Form][Field].value).replace(Patterns,"");
  document[Form][Field].focus();
}


function datecheck(Form,Field1,Field2)
 {
 
var fieldval=document[Form][Field1].value; 
var fieldval2=document[Form][Field2].value; 

var arr=new Array(2);
var arr1=new Array(2);

var FMM,FDD,FYYYY;
var TMM,TDD,TYYYY;

arr =fieldval.split("/");
arr1 =fieldval2.split("/");

FMM=arr[0];
FDD=arr[1];
FYYYY=arr[2];

TMM=arr1[0];
TDD=arr1[1];
TYYYY=arr1[2];

if(FDD=="09")
	{
		FDD=9
	}
if(FDD=="08")
	{
		FDD=8
	}
if(FMM=="09")
	{
		FMM=9
	}
if(FMM=="08")
	{
		FMM=8
	}

if(TDD=="09")
	{
		TDD=9
	}
if(TDD=="08")
	{
		TDD=8
	}
if(TMM=="09")
	{
		TMM=9
	}
if(TMM=="08")
	{
		TMM=8
	}
if (parseInt(TMM) >= parseInt(FMM) && parseInt(TYYYY) == parseInt(FYYYY))  	
		{ 
			return(1);
		}
			else
				{ 
				alert("To  Month Should Be Greater than Or Equal To  From   Month");
				document[Form][Field2].focus();
				return(0);
 		}	

if (parseInt(TYYYY) <  parseInt(FYYYY))
		{ 
			return(1);
		}
			else
				{	
		alert("To   Year Should Be Greater than Or Equal To  From    Year");
		document[Form][Field2].focus();
				return(0);
		
		}
	 
if (parseInt(TDD) > parseInt(FDD) )  	
		{ 
			return(1);
		}
			else
				{
		
		alert("To    Date Should Be Greater than Or Equal To From Date");
		
		document[Form][Field2].focus();
				return(0);
			}		
	
}

function CheckedNull(Form,Field)
  {
  if(!document[Form][Field].checked)
     {
      alert("Please Accept our terms & conditions by click on the check box ")
      document[Form][Field].focus();
      return false;
     }
  else
     {
      return true;
     }
}







function datevalidate(element)
	{
		if(element.value.split(" ").join("")!="" )
		{
			var arr = new Array(2)
			var arr1 = new Array(2)
			var MM,DD,YYYY,sysDate,FDate
			arr = element.value.split("/")
			MM = arr[1]
			DD = arr[0]
			YYYY = arr[2]
			FDate   = element.value
			sysDat= new Date()
			var hour        = sysDat.getHours();
			var minute      = sysDat.getMinutes();
			var second      = sysDat.getSeconds();
			var monthnumber = parseInt(sysDat.getMonth()) +1; 
			var monthday    = sysDat.getDate();
			var year        = sysDat.getYear();
			sysDate=monthday +"/" + monthnumber  + "/" + year //+ " " + hour + ":" + minute +":" + second;
			arr1 = FDate.split("/")
			if(DD=="09")
				{
					DD=9
				}
			if(DD=="08")
				{
					DD=8
				}
			if(MM=="09")
				{
					MM=9
				}
			if(MM=="08")
				{
					MM=8
				}
			if(isNaN(MM) || (parseInt(MM) < 1 || parseInt(MM) > 12))
			{
				element.focus();
				alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \n\tT h e  D a t e  F o r m a t  i s \n\n \t DD/MM/YYYY \n\n The Month Should be BETWEEN 1 to 12 \n \n Example   \t " + sysDate);
				element.select();
			}
			else if(isNaN(DD) || (parseInt(DD) < 1 || parseInt(DD) > 31) )
			{
				element.focus();
				alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \ntT h e  D a t e  F o r m a t  i s \n\n \t DD/MM/YYYY  \n\n The Day Should be BETWEEN 1 to 28/29/30/31 \n \n Example   \t " + sysDate);
				element.select();
			}
			else if(isNaN(YYYY))
			{
				element.focus();
				alert ("yyyY o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n\tT h e  D a t e  F o r m a t  i s \n\n \t DD/MM/YYYY  \n\n The Year Should be > 1999 \n \n Example   \t " + sysDate);
				element.select();
			}
			/*else if( parseInt(YYYY)< parseInt(arr1[2]) )
			{
				element.focus();
				alert ("To Date should be greaterthan \n\n or equal to From Date ");
				element.select();
			}
			else if( parseInt(YYYY)== parseInt(arr1[2]) && parseInt(MM) < parseInt(arr1[0]))
			{
				element.focus();
				alert ("To Date should be greaterthan \n\n or equal to From Date ");
				element.select();
			}
			else if( parseInt(YYYY)== parseInt(arr1[2]) && parseInt(MM) <= parseInt(arr1[0]) && parseInt(DD) < parseInt(arr1[1]))
			{
				element.focus();
				alert ("To Date should be greaterthan \n\n or equal to From Date ");
				element.select();
			}
			else if(parseInt(YYYY) > ((parseInt(arr1[2])+10)) )
			{
				element.focus()
				alert("To Date should be with in TEN years from From Date ")
				element.select()
			}*/
			else if((parseInt(MM) == 4 || parseInt(MM) == 6 || parseInt(MM) == 9 || parseInt(MM) == 11 )  && parseInt(DD) == 31 )
			{
				element.focus()
				alert("31 is an invalid Date in "+MM + "th Month")
				element.select()
			}
			else if(parseInt(MM) == 2 && (parseInt(DD) > 29) )
			{
				element.focus()
				alert(DD +" is an invalid Date in "+MM + "nd Month")
				element.select()
			}
			else if(parseInt(MM) == 2 && parseInt(DD) == 29 && ((parseInt(YYYY)%4)!= 0))
			{
				element.focus()
				alert( YYYY + " is not a LEAP year \n 29 is not a valid date " )
				element.select()
			}
		}
	}




function datecompare(Form,Field1,Field2)
	{

		var Farr1 = new Array(2);
		var Tarr2 = new Array(2);
		Farr = document[Form][Field1].value.split("/");

		FMM = Farr[1];
		FDD = Farr[0];
		FYYYY = Farr[2];

		Tarr = document[Form][Field2].value.split("/");
		TMM = Tarr[1];
		TDD = Tarr[0];
		TYYYY = Tarr[2];
			sysDat= new Date()
			var hour        = sysDat.getHours();
			var minute      = sysDat.getMinutes();
			var second      = sysDat.getSeconds();
			var monthnumber = parseInt(sysDat.getMonth()) +1;
			var monthday    = sysDat.getDate();
			var year        = sysDat.getYear();
		sysDate=monthday +"/" + monthnumber  + "/" + year //+ " " + hour + ":" + minute +":" + second;
					
			

		if(FDD=="09")
			{
				FDD=9;
			}
		if(FDD=="08")
				{
				FDD=8;
			}
		if(FMM=="09")
			{
			FMM=9;
			}
		if(FMM=="08")
			{
				FMM=8;
			}

		if(TDD=="09")
			{
				TDD=9;
			}
		if(TDD=="08")
			{
				TDD=8;
			}
		if(TMM=="09")
			{
				TMM=9;
			}
		if(TMM=="08")
			{
				TMM=8;
			}

		if(isNaN(FMM) || (parseInt(FMM) < 1 || parseInt(FMM) > 12))
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \n\tT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Month Should be BETWEEN 1 to 12 \n \n Example   \t " + sysDate);
			return false;
		}
		else if(isNaN(FDD) || (parseInt(FDD) < 1 || parseInt(FDD) > 31) )
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \ntT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Day Should be BETWEEN 1 to 28/29/30/31 \n \n Example   \t " + sysDate);
			return false;
		}
		else if(isNaN(FYYYY))
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n\tT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Year Should be > 1999 \n \n Example   \t " + sysDate);
			return false;
		}
		if(isNaN(TMM) || (parseInt(TMM) < 1 || parseInt(TMM) > 12))
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \n\tT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Month Should be BETWEEN 1 to 12 \n \n Example   \t " + sysDate);
			return false;
		}
		else if(isNaN(TDD) || (parseInt(TDD) < 1 || parseInt(TDD) > 31) )
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n \ntT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Day Should be BETWEEN 1 to 28/29/30/31 \n \n Example   \t " + sysDate);
			return false;
		}
		else if(isNaN(TYYYY))
		{
			alert ("Y o u  S h o u l d  E n t e r  a  V a l i d  D a t e \n\tT h e  D a t e  F o r m a t  i s \n\n \t MM/DD/YYYY \n\n The Year Should be > 1999 \n \n Example   \t " + sysDate);
			return false;
		}

		else if( parseInt(TYYYY) < parseInt(FYYYY) )
		{
			alert ("To Year should be greater than \n\n or equal to From Year");
			return false;
		}
		else if( parseInt(TYYYY)== parseInt(FYYYY) && parseInt(TMM) < parseInt(FMM))
		{
			alert ("To Month should be greaterthan \n\n or equal to From Month");
			return false;
		}
		else if( parseInt(TYYYY)== parseInt(FYYYY) && parseInt(TMM) <= parseInt(FMM) && parseInt(TDD) < parseInt(FDD))
		{
			alert ("To Date should be greaterthan \n\n or equal to From Date ");
			return false;
		}
		else if(parseInt(TYYYY) > ((parseInt(FYYYY)+10)) )
		{
			alert("To Date should be with in TEN years from From Date ");
			return false;
		}
		else if((parseInt(FMM) == 4 || parseInt(FMM) == 6 || parseInt(FMM) == 9 || parseInt(FMM) == 11 )  && parseInt(FDD) == 31)
		{
			alert("31 is an invalid Date in "+FMM + "th Month");
			return false;
		}
		else if((parseInt(TMM) == 4 || parseInt(TMM) == 6 || parseInt(TMM) == 9 || parseInt(TMM) == 11 )  && parseInt(TDD) == 31)
		{
			alert("31 is an invalid Date in "+TMM + "th Month");
			return false;
		}
		else if(parseInt(FMM) == 2 && (parseInt(FDD) > 29) )
		{
			alert(FDD +" is an invalid Date in "+FMM + "nd Month");
			return false;
		}
		else if(parseInt(TMM) == 2 && (parseInt(TDD) > 29) )
		{
			alert(TDD +" is an invalid Date in "+TMM + "nd Month");
			return false;
		}
		else if(parseInt(FMM) == 2 && parseInt(FDD) == 29 && ((parseInt(FYYYY)%4)!= 0))
		{
			alert( FYYYY + " is not a LEAP year \n 29 is not a valid date " );
			return false;
		}
		else if(parseInt(TMM) == 2 && parseInt(TDD) == 29 && ((parseInt(TYYYY)%4)!= 0))
		{
			alert( TYYYY + " is not a LEAP year \n 29 is not a valid date " );
			return false;
		}

		return true;
}

