function isWhiteSpaces(S)
{
	var isNull
	if (S.length == 0 ) 
		isNull = true;
	else
	{
		for (I=0;I < S.length; I++ )
		{
			isNull = S.substring(I,I+1)==" "?true:false
			if (!isNull) break;
		}
	}
	return isNull;
}



function isAlpha(S)
{
	for (var i=0; i<S.length; i++) 
	{
		var ch = S.charAt(i);
		if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' ') && (ch <'0') && (ch >'9')) 
			return false;
	}
	return true;
}


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   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)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function isNumeric(S)
{
	if (!isNaN(S))	
		return true;	
	return false;
}



function isEmail(email)
{
	var isNullEmail = isWhiteSpaces(email)
	var emailLength = email.length
	var isSPACEexists = email.indexOf(" ") + 1
	var isATexistsFirst = email.indexOf("@")
	var isATexistsLast = email.lastIndexOf("@")
	var isDOTexistsFirst = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext1 = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext2 
	var isDOTexistsLast = email.lastIndexOf(".")

	if ((emailLength < 8 ) || (isDOTexistsFirst < isATexistsFirst+3) || (isATexistsFirst < 2) ||
   	 	(isDOTexistsLast == emailLength-1) || (isATexistsLast == emailLength-1) ||
    	(isDOTexistsFirst == 0) || (isATexistsFirst == 0) || (isATexistsFirst == isDOTexistsFirst) ||
    	(isATexistsFirst != isATexistsLast) || isSPACEexists || isNullEmail)
	{
		return false;
	}

	while (isDOTexistsNext1 < isDOTexistsLast)
	{
		isDOTexistsNext2 = email.indexOf(".",isDOTexistsNext1+1)
		if (isDOTexistsNext1+1 == isDOTexistsNext2)
		{
			return false;
		}
		isDOTexistsNext1 = isDOTexistsNext2
	}

	return true;
}



function isMoreEmail(email)
{
	var isNullEmail = isWhiteSpaces(email)
	var emailLength = email.length
	var isSPACEexists = email.indexOf(" ") + 1
	var isATexistsFirst = email.indexOf("@")
	var isATexistsLast = email.lastIndexOf("@")
	var isDOTexistsFirst = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext1 = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext2 
	var isDOTexistsLast = email.lastIndexOf(".")

	if ((emailLength < 8 ) || (isDOTexistsFirst < isATexistsFirst+3) || (isATexistsFirst < 2) ||
   	 	(isDOTexistsLast == emailLength-1) || 
    	(isDOTexistsFirst == 0) || (isATexistsFirst == 0) || (isATexistsFirst == isDOTexistsFirst) ||
    	 isSPACEexists || isNullEmail)
	{
		return false;
	}

	while (isDOTexistsNext1 < isDOTexistsLast)
	{
		isDOTexistsNext2 = email.indexOf(".",isDOTexistsNext1+1)
		if (isDOTexistsNext1+1 == isDOTexistsNext2)
		{
			return false;
		}
		isDOTexistsNext1 = isDOTexistsNext2
	}

	return true;
}
// function for checking spaces




function check(S)
{
var flag;
  
  var Str=S.length
  for(I=0;I<Str;I++)
  {
    var space=S.charAt(I)
    if (space==" ") 
    {
    flag=true;
    break;
    }
  
  }
    if(flag==true)
    {  
    return true;
    }else
    {
      return  false;
     }
}



function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}


function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}



function isDate(ctrl)
{
	var elems = ctrl.value.split("/");
	var month = parseInt(elems[0],10);
  	var day = parseInt(elems[1],10);
 	var year = parseInt(elems[2],10);
	var result = true;
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4)); 	 	
		return result;
}



function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}



function isPhoneNo(str)
{
	return inValidCharSet(str,"-0123456789");
}

	//********** S	T	A	R	T	 	D	A	T	E	 	C	H	E	C	K	**********//
	//************************************************************************************//
var arr_dtt=new Array([0,0,0], [31,'January'],	[28,'February'], [31,'March'], [30,'April'], [31,'May'],[30,'June'],[31,'July'], [31,'August'],	[30,'September'], [31,'October'], [30,'November'],[31,'December']); 


function  IsLeapYear(yy)
 {
 	yr=parseInt(yy);
 	if((yr % 4)==0)
		return true;
	else
		return false;
 }


function IsValidDate(dd,mm,yy)
 {
	ct_dd=document.getElementById(dd);
	ct_mm=document.getElementById(mm);	
	ct_yy=document.getElementById(yy);	
	vl_dd=parseInt(ct_dd.value);
	vl_mm=parseInt(ct_mm.value);
	vl_yy=parseInt(ct_yy.value);
	if(vl_yy!=0 && vl_mm!=0 && vl_dd!=0){
		if(IsLeapYear(vl_yy)&& vl_mm==2 && vl_dd!=0 && vl_dd>29){
			alert(vl_yy+' is a Leap Year, Day of February can\'t exceed 29');
			ct_dd.focus();
			return false;
		}
		if(!IsLeapYear(vl_yy)&& vl_mm==2 && vl_dd!=0 && vl_dd>28){
			alert('Day of February can\'t exceed 28');
			ct_dd.focus(); return false;
		}
		if(vl_dd>parseInt(arr_dtt[vl_mm][0])){
			alert('Day of '+arr_dtt[vl_mm][1]+' can\'t exceed '+arr_dtt[vl_mm][0]);
			ct_dd.focus(); return false;
		}
		return true;
	}	
	return false;
 }
 


function date_chck(frm_dd,frm_mm,frm_yy,to_dd,to_mm,to_yy){
	ct_dd_frm=document.getElementById(frm_dd);
	ct_mm_frm=document.getElementById(frm_mm);	
	ct_yy_frm=document.getElementById(frm_yy);	
	vl_dd_frm=parseInt(ct_dd_frm.value);
	vl_mm_frm=parseInt(ct_mm_frm.value);
	vl_yy_frm=parseInt(ct_yy_frm.value);
	ct_dd_to=document.getElementById(to_dd);
	ct_mm_to=document.getElementById(to_mm);	
	ct_yy_to=document.getElementById(to_yy);	
	vl_dd_to=parseInt(ct_dd_to.value);
	vl_mm_to=parseInt(ct_mm_to.value);
	vl_yy_to=parseInt(ct_yy_to.value);
	//if(vl_)
	if(vl_dd_frm==0)
		{alert("Pls select the Day [FROM Date]"); ct_dd_frm.focus(); return false; }
	else if(vl_mm_frm==0)
		{alert("Pls select the Month [FROM Date]"); ct_mm_frm.focus();return false;}
	else if(vl_yy_frm==0)
		{alert("Pls select the Year [FROM Date]");ct_yy_frm.focus();return false;}
	else if(vl_dd_to==0)
		{alert("Pls select the Day [TO Date]"); ct_dd_to.focus(); return false; }
	else if(vl_mm_to==0)
		{alert("Pls select the Month [TO Date]"); ct_mm_to.focus();return false;}
	else if(vl_yy_to==0)
		{alert("Pls select the Year [TO Date]");ct_yy_to.focus();return false;}
	else if(!IsValidDate(frm_dd,frm_mm,frm_yy))
		{return false;}
	else if(!IsValidDate(to_dd,to_mm,to_yy))
		{return false;}
	
	else if((IsValidDate(frm_dd,frm_mm,frm_yy))&&(IsValidDate(to_dd,to_mm,to_yy))){
		if((vl_yy_frm==vl_yy_to)&&(vl_mm_frm==vl_mm_to)&&(vl_dd_frm>vl_dd_to)){
				alert("Plz.. Change [ To Date] !!  back dated is not allowed");
				ct_dd_to.focus(); return false;	
		}
		else if((vl_yy_frm==vl_yy_to)&&((vl_mm_frm>vl_mm_to)||(vl_dd_frm>vl_dd_to))){
				alert("Plz.. Change [ To Date] !!  back dated is not allowed");
				ct_mm_to.focus(); return false;	
		}
		else if(vl_yy_frm>vl_yy_to){
				alert("Plz.. Change [ To Date] !!  back dated is not allowed");
				ct_yy_to.focus(); return false;	
		}
	}
	return true;
}
//********** E	N	D	 	D	A	T	E	 	C	H	E	C	K	**********//
	//************************************************************************************//

/****88888888888888888888888*********/
