function fnCheckNull(astrFieldValue,astrFieldName)
{
	if (fnStripSpaces(astrFieldValue.value) == "") 
	{
		alert("Please enter "+astrFieldName+".");
		astrFieldValue.focus();
		return false;
	}
	else 
	{
		return true;
	}	
}
function fnCheckDropDown(astrFieldValue,astrFieldName)
{
	if (astrFieldValue.value == -1) 
	{
		alert( "Please select a " + astrFieldName+"." );
		astrFieldValue.focus();
		return false;
	}
	else 
	{
		return true;
	}	
}
function fnStripSpaces (astrString)  
{		      
var astrOutString;
var astrTempChar;
		astrOutString="";
        for ( Count=0 ; Count < astrString.length ; Count++ )  
	    {
            astrTempChar=astrString.substring (Count, Count+1);
            if ( astrTempChar != " " )
                 astrOutString=astrOutString+astrTempChar;
        }
        return (astrOutString);
}

function fnCheckName(astrFieldValue,astrFieldName)
{		      
    return fnCheckAlphabeticHypAposSpace(astrFieldValue,astrFieldName);
}
function fnCheckAlphabeticHypAposSpace(astrFieldValue,astrFieldName)
{
	var lstrRefString="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '-.";
	var lstrInString = astrFieldValue.value;
	if (lstrInString.length != 0)	
	{
		for (Count=0; Count < lstrInString.length; Count++)
		{
			if (lstrRefString.indexOf(lstrInString.substring (Count, Count+1)) == -1)
			{
				alert("Please enter a valid "+astrFieldName+".");
				astrFieldValue.value="";
				astrFieldValue.focus();
				return(false);
			}
		}
		return(true);
	}
return(true);
}
function fnCheckAgentCode(astrFieldValue,astrFieldName)
{
	var lstrRefString="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var lstrInString = astrFieldValue;
	if (lstrInString.length != 0)	
	{
		for (Count=0; Count < lstrInString.length; Count++)
		{
			if (lstrRefString.indexOf(lstrInString.substring (Count, Count+1)) == -1)
			{
				alert("Please enter a valid "+astrFieldName+".");
				return(false);
			}
		}
		return(true);
	}
return(true);
}
function fnCheckYear(lYear,lFieldName)
{
	if(isNaN(lYear.value))
	{
		alert("Please enter a valid "+lFieldName+".");
		lYear.select();
		lYear.focus();
		return false;
	}
	var curYear = new Date().getYear();
	 if(navigator.appName == "Netscape")
        	{
        	curYear = curYear + 1900;
        	}
	if(lYear.value < 1950 || lYear.value > curYear)
	{
		alert("Please enter a valid "+lFieldName+".");
		lYear.select();
		lYear.focus();
	    return false;
	}
 return true;
}

function fnValidDate(lDay,lMonth,lYear)
{
	var day = lDay.value;
	var mon = lMonth.value;
	var year = lYear.value;
  	if( isNaN(day) || isNaN(mon) || isNaN(year))
	{
		alert("Enter only numeric value for date");
		if (isNaN(day)) 	{	lDay.select();lDay.focus(); }
		if (isNaN(mon)) {	lMonth.select();lMonth.focus(); }
		if (isNaN(year)) 	{	lYear.select();lYear.focus(); }		
		return false;
	} 
		if (day < 1 || day > 31)
		{
		    alert("Please enter a valid Day.");
			lDay.select();lDay.focus();
			return false;
	
		}
		if (mon < 1 || mon > 12)
		{
		    alert("Please enter a valid Month.");
			lMonth.select();lMonth.focus();
			return false;
		}
		 
		if (year < 1900)
		{
	        alert("Please enter a valid Year.");
			lYear.select();lYear.focus();
			return false;
		}
						
		if ((mon == 4) || (mon == 6) || (mon == 9) || (mon == 11))
		{
				if (day == 31) 
				{
		            alert("Please enter a valid Month.");
			        lMonth.select();lMonth.focus();
					return false;
				}
		}

    if (mon == 2)
		{
		
			var lpYear = parseInt(year/4);
				
			if (isNaN(lpYear))
			{
		       alert("Please enter a valid Year.");
			   lYear.select();lYear.focus();
			   return false;
				
			}
			if (day >29)
			{
		      	alert("Please enter a valid Day.");
			    lDay.select();lDay.focus();
				return false;
				
			}
				
			if ((day == 29) && ( (year/4) != parseInt(year/4) )) 
			{
	      	    alert("Please enter a valid Day.");
			    lDay.select();lDay.focus();
				return false;
			}
				
			if ((day == 29) && ( (year%100) == 0) && ( (year%400) != 0 )) 
			{
	      	    alert("Please enter a valid Day.");
			    lDay.select();lDay.focus();
				return false;
			}
				
		}
		
	return true; 
}


function fnCheckPassport(inVal){
   var  valPassport=fnStripSpaces(inVal);
   
   if(valPassport.length ==0) return true;

      if( valPassport.length >0 && valPassport.length<4){
	    alert('Please enter valid passport#.');
		return false;
   }else if(!fnValidatePassport(inVal)){
        return false;
   }
   if(!fnCheckPaasportInvalid(inVal)) return false;

return true;
}
 
function fnValidatePassport(lstrInString)
{
	var lstrRefString="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-:;# ";
	var istRefNum='0123456789';
 	var space=' ';
	var numFlag=0;
	if (lstrInString.length >0)	
	{
		for (Count=0; Count < lstrInString.length; Count++)
		{
			if(space.indexOf(lstrInString.substring (Count, Count+1)) != -1){
				alert("Please enter valid passport#.");
				return false;
			}
 			if (lstrRefString.indexOf(lstrInString.substring (Count, Count+1)) == -1)	{
				alert("Please enter valid passport#.");
				return(false);
			}
			if(istRefNum.indexOf(lstrInString.substring (Count, Count+1))!=-1){
				numFlag=1;
			}
		}
 	}
	if(numFlag==0){
		alert('Please enter valid passport#.');
        return false;
	}
return(true);
} 
/************/
function fnCheckPaasportInvalid(lstrInString){
 	var removePassVal  =new Array("NOT AVAILABLE", "AVAILABLE","AWAITED","APPLIED FOR","APPLIED","NONE","APPLY","EXPECT","APPLICABLE","WAITING","FORGOT","READY","RECEIVE","KNOW","RETURN","REME","PRESENT","EXPIRED","HAVE","VALID","INDIAN","ISSUE","EXIST","LATER","HOLD");
	var len = removePassVal.length;
 	var passFlag = false;
 	if(null != lstrInString && !lstrInString==""){
		lstrInString= lstrInString.toUpperCase();
		for(var i=0; i<len; i++){
  				if(lstrInString.indexOf(removePassVal[i]) != -1){
 					passFlag = true;
					break;
				}
			}
			if(passFlag){
				alert('Please enter the valid passport#.');
				return false;
			}
		}

		return true;
	 
} 


function fnCheckInteger(astrFieldValue,astrFieldName)
{
	var RefString="1234567890";
	var InString = astrFieldValue.value;	

	//check only the characters present in RefString are entered

	for (Count=0; Count < InString.length; Count++)  
	{			
        if (RefString.indexOf (InString.substring (Count, Count+1))==-1)  
		{
				//alert(astrFieldName + " should be numeric");
				alert('Please enter valid '+astrFieldName+'.');
				astrFieldValue.focus();
				return (false);
		}
     }
     return true;
}

function checkEmail(email) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true)
	}
	return (false)
}