function gfnRetDateDiff(pdtmDate1, pdtmDate2)
	{ 
		return ((pdtmDate1 - pdtmDate2)/1000/60/60/24);
	}
function ValidateDate(itm) {
		var dd;
		var mm;
		var yy;
		var dt;
		dd = "";
		mm = "";
		yy = "";
		dt = itm.value;
		splDt = dt.split("/");
		if(splDt.length != 3){
			itm.select();
			alert("Invalid Date.\nPlease enter the date in mm/dd/yy format.");
			return false;
		}

		dd = splDt[1];
		mm = splDt[0];
		yy = splDt[2];

		if(isNaN(dd) || isNaN(mm) || isNaN(yy)){
			itm.select();
			alert("Invalid Date.\nPlease enter the date in mm/dd/yy format.");
			return false;
		}
	
		if(dd.split(" ").length>1 || mm.split(" ").length>1 || yy.split(" ").length>1){
			itm.select();
			alert("Spaces not allowed for day, month or year.\nPlease enter again.");
			return false;
		}
	
		if(eval(mm)>12 || eval(mm)<1 || eval(dd)>31 || eval(dd)<1){
			itm.select();
			alert("Month or Day is out of limits.\nPlease enter again.");
			return false;
		}

		if(eval(mm)==2){
			if(eval(dd)>29){
				itm.select();
				alert("Invalid date for February.\nPlease enter again.");
				return false;
			}
			yy = "20" + yy;
			if((eval(yy) % 4 == 0 && eval(yy) % 100 != 0) || eval(yy) % 400 == 0){
				if(eval(dd)>29){
					itm.select();
					alert("Invalid date for February.\nPlease enter again.");
					return false;
				}
			}
			else{
				if(eval(dd)>28){
					itm.select();
					alert("Not a leap year.\nPlease enter again.");
					return false;
				}
			}
		}
		return true;
}
function checkQuoteString(caption, obj)
{
	if(obj.value.indexOf('"')!=-1)
	{
		alert(caption + ' can not contain single or double quotes');
		obj.focus();
		return false;
	}
	if(obj.value.indexOf("'")!=-1)
	{
		alert(caption + ' can not contain single or double quotes');
		obj.focus();
		return false;
	}
	return true;
}
function LTrim(lstrTrimStr)
{
	var lintTotLen = lstrTrimStr.length;
	var lstrWhtSpcs = new String(" \t\n\r");
    var lstrCpyStr = new String(lstrTrimStr);
	
	if (lstrWhtSpcs.indexOf(lstrCpyStr.charAt(0)) != -1)
	{
		var lintJCtr=0, lintICtr = lstrCpyStr.length;
        
		while (lintJCtr < lintICtr && lstrWhtSpcs.indexOf(lstrCpyStr.charAt(lintJCtr)) != -1)
			lintJCtr++;
		lstrCpyStr = lstrCpyStr.substring(lintJCtr, lintTotLen);
	}
	return lstrCpyStr;
}
function RTrim(lstrTrimStr)
{
	var lintTotLen = lstrTrimStr.length;
	var lstrWhtSpcs = new String(" \t\n\r");
    var lstrCpyStr = new String(lstrTrimStr);
        
	if (lstrWhtSpcs.indexOf(lstrCpyStr.charAt(lintTotLen-1)) != -1)
	{
		var lintICtr = lintTotLen-1;
        
		while (lintICtr >= 0 && lstrWhtSpcs.indexOf(lstrCpyStr.charAt(lintICtr)) != -1)
                        lintICtr--;
        
		lstrCpyStr = lstrCpyStr.substring(0, lintICtr+1);
	}
	return lstrCpyStr;
}
function Trim(pstrTrimStr)
{
	return RTrim(LTrim(pstrTrimStr));
}
function gfnSetCheckBox(pobjCheckBox, lstrScript)
{
	if(pobjCheckBox.checked){
		eval(lstrScript);
		pobjCheckBox.checked = true;
	}
	return pobjCheckBox.checked;
}
function isEMail(pobjEmailId)
{
	var linta = '';         //Variable to store the last position of Special Character @                    
	var lintb = '';			//Variable to store the last position of Special Character .   
	var lintc = '';			//Variable to store the position of Special Character : 
	var lintd = '';			//Variable to store the position of Special Character / 
	var lstre = '';
	var lintf = '';			//Variable to store the position of Special Character @  
	var lstrg = '';
	var linth = '';			//Variable to store the position of Special Character [ 
	var linti = '';			//Variable to store the position of Special Character ]  
	var lintj = '';			//Variable to store the position of Special Character <  
	var lintk = '';			//Variable to store the position of Special Character >  
	var lstrl = '';
	var lstrm = '';
	var lstrn = '';
	var lintVaidEmail = 0;	//If its value is 0,it means entered EmailId is a valid one

	if (pobjEmailId.value=="")
	{return true;}

	linta = pobjEmailId.value.lastIndexOf("@");
	lintb = pobjEmailId.value.lastIndexOf(".");
	lintc = pobjEmailId.value.indexOf(":");
	lintd = pobjEmailId.value.indexOf("/");
	lstre = pobjEmailId.value.substring(0,linta);
	lintf = lstre.indexOf("@");
	lstrg = pobjEmailId.value.substring(linta+1,pobjEmailId.length);
	linth = lstrg.indexOf("[");
	linti = lstrg.indexOf("]");
	lintj = lstrg.indexOf("<");
	lintk = lstrg.indexOf(">");
	lstrl = pobjEmailId.value.substring(linta+1,lintb);
	lstrm = pobjEmailId.value.substring(lintb+1,pobjEmailId.length);
	lstrn = pobjEmailId.value.substring(0,linta);
	
	lintVaidEmail = 0;	
	
	if (linta > lintb) 
		{lintVaidEmail++};
	if (lintc != -1) 
		{lintVaidEmail++};
	if (lintd != -1) 
		{lintVaidEmail++};
	if (lintf != -1) 
		{lintVaidEmail++};
	if (linth != -1) 
		{lintVaidEmail++};
	if (linti != -1) 
		{lintVaidEmail++};
	if (lintj != -1) 
		{lintVaidEmail++};
	if (lintk != -1) 
		{lintVaidEmail++};
	if (lstrl.length < 3) 
		{lintVaidEmail++};
	if (lstrm.length < 2) 
		{lintVaidEmail++};
	if (lstrn.length < 1) 
		{lintVaidEmail++};	
	lintb = lintb + 1;		
	if (eval(lintb) == eval(pobjEmailId.value.length)) 
		{lintVaidEmail++};		

	if (lintVaidEmail == 0) 
	{
	    return true;
	}
	else 
	{
		return false;
	}
}
function isValidUserName(obj)
{
	var strAllChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
	var iCtr=0;
	var objValue = obj.value;
	if(objValue.substr(0, 1)=='_')
	{
		alert('User Name Can Not Start With An Underscore ( _ )');
		obj.focus();
		obj.select();
		return false;
	}
	for(iCtr=0;iCtr<objValue.length;iCtr++)
	{
		var currentChar = objValue.substr(iCtr, 1);
		if(strAllChars.indexOf(currentChar)==-1)
		{
			alert("User Name Can Contain:\n0123456789\nabcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ_\nPlease enter valid user name");
			obj.focus();
			obj.select();
			return false;
		}
	}
	return true;
}

function isValidSNo(obj)
{
	var strAllChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var iCtr=0;
	var objValue = obj.value;
	if(objValue.substr(0, 1)=='_')
	{
		alert('User Name Can Not Start With An Underscore ( _ )');
		obj.focus();
		obj.select();
		return false;
	}
	for(iCtr=0;iCtr<objValue.length;iCtr++)
	{
		var currentChar = objValue.substr(iCtr, 1);
		if(strAllChars.indexOf(currentChar)==-1)
		{
			alert("Please enter valid Serial No.");
			obj.focus();
			obj.select();
			return false;
		}
	}
	return true;
}

function gfnCheckNumeric(pobjControl, pstrCaption, pstrAllow, pstrOptionalFlag)
{
	var lintNumValue = pobjControl.value;

	// If the Number is optional and the user leaves it blank then 
	// let it be so and do not proceed with validating the Numeric
	if ((pstrOptionalFlag == 'O') && (lintNumValue == ''))
	{
		return true;//Exit if Optional
	}
	if ((pstrOptionalFlag == 'M') && (lintNumValue == ''))
	{
		gfnShowError(501, pstrCaption);
		pobjControl.focus();
		pobjControl.select();
		return false;
	}

	var lstrPattern= new RegExp("[0-9," + pstrAllow + "]", "g");
	var lstrRetArr=lintNumValue.match(lstrPattern);

	if (lstrRetArr==null || lstrRetArr.length!=lintNumValue.length)
	{
		// check for negative sign		
		lstrPattern= new RegExp("[0-9," + pstrAllow + "-" + "]", "g");
		lstrRetArr=lintNumValue.match(lstrPattern);
		if (lstrRetArr!=null && lstrRetArr.length == lintNumValue.length){
			if (parseFloat(lintNumValue) == lintNumValue){
				// error was due to -ve sign only				
				gfnShowError(519, pstrCaption);
				pobjControl.focus();
				pobjControl.select();
				return false;
			}		
		}
		// error is due to some other character		
		gfnShowError(508, pstrCaption);
		pobjControl.focus();
		pobjControl.select();
		return false;
	}
	else
	{
		if (parseFloat(lintNumValue) == lintNumValue)
			return true;
		else
		{
			gfnShowError(508, pstrCaption);
			pobjControl.focus();
			pobjControl.select();
			return false;
		}
	}
}

function gfnCheckSplCharacters(pobjControl, pstrCaption, pstrAllow)
{
	var lstrString=pobjControl.value;

	if (lstrString.length==0)
		return true;
	var lstrPattern= new RegExp("[a-z,A-Z,0-9," + pstrAllow + "]", "g");
	var lstrRetArr=lstrString.match(lstrPattern);
	if (lstrRetArr==null)
	{
		gfnShowError(531, pstrCaption);
		pobjControl.focus();
		return false;
	}
	else
	{
		if (lstrRetArr.length==pobjControl.value.length)
			return true;
		else
		{
			gfnShowError(531, pstrCaption);
			pobjControl.focus();
			return false;
		}
	}
}

function gfnShowError()
{
	switch (arguments[0])
	{
		case 501:
			alert(arguments[1] + " cannot be left Blank, please enter a valid " + arguments[1]);
			break;
		case 502:
			alert(arguments[1] + " must be less than " + arguments[2]);
			break;
		case 503:
			alert(arguments[1] + " must be less than or equal to " + arguments[2]);
			break;

		case 504:
			alert(arguments[1] + " cannot be less than " + arguments[2]);
			break;

		case 505:
			alert(arguments[1] + " must be greater than " + arguments[2]);
			break;

		case 506:
			alert(arguments[1] + " must be greater than or equal to " + arguments[2]);
			break;

		case 507:
			alert(arguments[1] + " cannot be greater than " + arguments[2]);
			break;

		case 508:
			alert("Please enter valid " + arguments[1]);
			break;

		case 511:
			alert("This record has been successfully saved");
			break;

		case 514:
			alert("Please select a " + arguments[1] + "from the " + arguments[2]);
			break;

		case 515:
			alert(arguments[1] + " already exists in " + arguments[2]);
			break;

		case 516:
			alert("No records found");
			break;

		case 517:
			alert(arguments[1] + " can not contain characters, please enter numeric value");
			break;

		case 519:
			alert(arguments[1] + " cannot accept negative values");
			break;
	
		case 520:
			alert(arguments[1] + " cannot accept more than 2 Decimal Places");
			break;

		case 521:
			alert("Invalid Date Format, Please specify date in DD/MM/YYYY format");
			break;

		case 522:
			alert(arguments[1] + " must be numeric");
			break;

		case 524:
			alert(arguments[1] + " does not match " + arguments[2]);
			break;

		case 526:
			alert("Invalid " + arguments[1] + ", duplicate " + arguments[1] + " not allowed");
			break;

		case 528:
			alert("Invalid " + arguments[1]);
			break;

		case 531:
			alert(arguments[1] + " cannot contain special characters");
			break;

		case 532:
			alert(arguments[1] + " must be between " + arguments[2] + " and " + arguments[3]);
			break;

		case 533:
			alert("Month " + arguments[1] + " does not have 31 days!");
			break;

		case 534:
			alert("February " + arguments[1] + " does not have " + arguments[2] + " days!");
			break;

		case 535:
			alert("Invalid  " + arguments[1] + ", " + arguments[1] + " cannot contain numeric or special characters");
			break;

		case 536:
			alert("Invalid  " + arguments[1] + ", " + arguments[1] + " cannot be more than " + arguments[2] + " characters");
			break;

		case 538:
			alert("Either of " + arguments[1] + " or " + arguments[2] + " should be specified");
			break;

		case 539:
			alert(arguments[1] + " can not be same as " + arguments[2]);
			break;

		case 540:
			alert("Invalid  " + arguments[1] + ", " + arguments[1] + " must be in Upper Case Alphabets");
			break;

		case 541:
			alert("Please specify some search criteria");
			break;

		case 542:
			alert("Please Select atleast one Record to Continue");
			break;

		case 544:
			alert(arguments[1] + " not found for " + arguments[2]);
			break;

		case 546:
			alert("Connection with the server could not be established.  Please try again.");
			break;

		case 547:
			alert(arguments[1] + " Not Found");
			break;

		case 549:
			alert("Invalid " + arguments[1] + ", " + arguments[1] + " must contain exactly " + arguments[2] + " characters");
			break;


		case 551:
			alert("Sum of " + arguments[1] + " is not equal to " + arguments[2]);
			break;

		case 552:
			alert("Please add atleast " + arguments[1]);
			break;

		case 554:
			alert("Transaction for this Financial Year has been closed");
			break;

		case 556:
			alert("No promotions for this rank");
			break;

		case 555:
			alert(arguments[1] + " must be " + arguments[2]);
			break;

		case 557:
			alert("No records found in " + arguments[1]);
			break;

		case 560:
			alert(arguments[1] + " not allowed for " + arguments[2]);
			break;

		case 561:
			alert("No " + arguments[1] + " available");
			break;

		case 562:
			alert("Database Error : " + arguments[1] );
			break;

		case 565:
			alert("Cannot assign Accession Number for this RV and Book Code as all books have already got Accession Number" );
			break;

		case 566:
			alert("Please make an entry in Casualty Screen for ceasing HRA" );
			break;

		case 568:
			alert("This Scheme is not applicable for " + arguments[1] );
			break;

		case 570:
			alert(arguments[1] + " is invalid, it should be " + arguments[2]);
			break;

		case 571:
			alert("Cannot Attach to the same Unit");
			break;

		case 572:
			alert("Person Already Attached");
			break;

		case 574:
			alert("Either Unit Code And Force No are to be entered together or Complementary Flag and Name of the Person are to be entered together");
			break;

		case 575:
			alert("Grace Time Period Lapsed");
			break;

		case 576:
			alert("Suspended , LTC Only Available for the Family");
			break;

		case 577:
			alert("Cannot take 2 consecutive Al India LTC");
			break;

		case 578:
			alert("LTC already Availed for this Block");
			break;

		case 579:
			alert("The 6 months Time Period between LTC has lapsed");
			break;

		case 580:
			alert("LTC is only available to you or your spouse");
			break;

		case 588:
			alert("This is the last Grant for this IRLA No.");
			break;
		case 1001:
			alert("Select Either " + arguments[1] + " or " + arguments[2]);
			break;

		case 1002:
			alert("Atleast one Room should be selected to generate the schedule");
			break;

		case 1003:
			alert("You cannot enter " + arguments[1] + " if course code is entered");
			break;

		case 1004:
			alert("Atleast one " + arguments[1] + " should be selected");
			break;

		case 1005:
			alert("The Schedule has been Successfully Generated");
			break;
		
		case 1006:
			alert("Reservation not possible for all the trainees.");
			break;

		case 1007:
			alert("No more seats available for the reserved list.");
			break;

		case 1008:
			alert(arguments[1] + " can not be 0.");
			break;

		case 1009:
			alert(arguments[1] + " is not allowed for " + arguments[2]);
			break;

		case 1010:
			alert(arguments[1] + " can have only one entry.");
			break;

		case 1011:
			alert("Same Voucher Id for a Voucher Set can ot be used.");
			break;

		case 1012:
			alert("Either " + arguments[1] + " or " + arguments[2] + " should be given.");
			break;

		case 1013:
			alert(arguments[1] + " should be equal to the " + arguments[2] + " as Partial Payment is not allowed.");
			break;

		case 1014:
			alert("Enter either of the values:Block/House No,Floor-Unit No,Street Name,Building Name.");
			break;

		case 1015:
			alert("Gender can not be left blank,Please select Gender.");
			break;

		case 1016:
			alert("Batch cannot be completed as attendance has been captured but not frozen.");
			break;

		case 1017:
			alert("Batch cannot be completed as " + arguments[1] + " Claim has not been processed.");
			break;

		case 1018:
			alert("Batch cannot be completed as trainer honorarium has not been processed for all the sessions.");
			break;

		case 1019:
			alert("Batch cannot be completed as Assistant trainer honorarium has not been processed for all the sessions.");
			break;

		case 1020:
			if(confirm("Do you want to waive the selected Trainees?" ))
			{
				return true;
			}
			else
			{
				return false;
			}

		case 1021:
			alert("Please deselect all cancel checkBox.");
			break;

		case 1022:
			alert("Please select " + arguments[1]);
			break;

		case 1023:
			alert("This company booking " + arguments[1] + " cannot be cancelled as it has confirmed trainee.");
			break;

		case 1024:
			alert("Scheme cannot be modified as advice has been generated .");
			break;

		case 1025:
			alert("This " + arguments[1] + " scheme is not applicable for this course .");
			break;

		case 1026:
			alert("This value on this page cannot be modified \n as advice has already been generated .");
			break;

		case 1027:
			alert("Scheme cannot be modified as trainee has been confirmed .");
			break;

		case 1028:
			alert("At least one trainee record must be selected for issuing the course material .");
			break;

		case 1029:
			alert("Batch cannot be completed as billing is pending for " + arguments[1] + " company booking .");
			break;	

		case 1030:
			alert("Company booking cannot be done as batch capacity is full.");
			break;

		case 1031:
			alert(arguments[1] + " cannot be selected until " + arguments[2] + " is selected.");
			break;		

		case 1032:
			if(confirm(arguments[1] + " selected is different than the default " + arguments[1] + " for the batch.Are you sure you want to continue?" ))
			{
				return true;
			}
			else
			{
				return false;
			}

		case 1033:
			alert("Registration details cannot be entered for miscellaneous receipt type.");
			break;

		case 1034:
			alert("Used voucher can only be cancelled.");
			break;

		case 1035:
			if(confirm("Do you want to go ahead with the cancellation?" ))
			{
				return true;
			}
			else
			{
				return false;
			}

		case 1036:
			alert("Numbers should be consequtive.");
			break;

		case 1037:
			alert(arguments[1] + " should start from " + arguments[2]);
			break;
			
		case 1038:
			alert(arguments[1] + " do not match with " + arguments[2]);
			break;

		case 1039:
			if(confirm("Are you sure you want to change the status of Blacklisted candidate as amount is still pending against him?" ))
			{
				return true;
			}
			else
			{
				return false;
			}

		case 1040:
			if(confirm("Do you want to change the status of Blacklisted candidate?" ))
			{
				return true;
			}
			else
			{
				return false;
			}
			
		case 1041:
			alert("No changes were made to any records. No, data to save.");
			break;
			
		case 1042:
			alert("You can not " + arguments[1] + " for transaction type " + arguments[2]);
			break;
			
		case 1043:
			if(confirm("You have not entered any Actual Information. Do you wish to continue ?" ))
			{
				return true;
			}
			else
			{
				return false;
			}
			
		case 1044:
			alert(arguments[1] + " should be selected for " + arguments[2]);
			break;

		case 1045:
			alert("Please enter details of atleast one record to continue.");
			break;

		case 1046:
			alert("No " + arguments[1] + " to be processed.");
			break;
			
		case 1047:
			alert(arguments[1] + " cannot have more than " + arguments[2] + " decimal places.");
			break;
			
		case 1048:
			alert("Honorarium choosen is same as the currently attached honorarium.");
			break;
			
		case 1049:
			alert("Please mark " + arguments[1] + " applicable to make it upfront.");
			break;
			
		case 1050:
			alert(arguments[1] + " cannot be entered if " + arguments[2]);
			break;
			
		case 1051:
			if(confirm("Capacity entered is greater than the " + arguments[1] + " Capacity ("+arguments[2]+").\n Are you sure you want to continue?"))
			{
				return true;
			}
			else
			{
				return false;
			}
			
		case 1052:
			if(confirm("Capacity of the room (" + arguments[1] + ") entered is less than the batch size.\n Are you sure you want to continue?")==false)
			{
				return false;
			}
			else
			{
				break;
			}
			
		case 1053:
			alert("The timings entered are overlapping with holiday timings");
			break;
			
		case 1054:
			alert("For " + arguments[1] + " , " + arguments[2] + " can not be left blank");
			break;
			
		case 1055:
			alert(arguments[1] + " is applicable only for " + arguments[2]);
			break;
			
		case 1056:
			alert("Remarks Can not be left blank as " + arguments[1] + " has been modified");
			break;
			
		case 1057:
			alert("For requested cancellation, administrative charges can be deducted from the refund amount.");
			break;
			
		case 1058:
			alert(arguments[1] + " and " + arguments[2] + " should be either both entered or both left blank.");
			break;

		case 1059:
			alert("Specify " + arguments[1] + " if preferred mode of communication is " + arguments[2]);
			break;
			
		case 1060:
			alert("No confirmed trainee exists in the batch");
			break;
			
		case 1061:
			alert("Date can not be less than 6 months from today's date");
			break;			

		default :
			alert("An error has occured in the page");
			return true;
	}
}


