/*
'*******************************************************************************************************
'Project Name 		: KDC
'File Name			: CCommon.js
'Version No.		: 1.00
'Description   		:
'Purpose  			:  Global javascript functions.
'					  
'Author				: *************
'Creation Date		: *************
'Reviewed By		: Amar
'Review Date		: 01/10/03
'Modified Date		: 
'Modified By		: 
'*******************************************************************************************************
*/

//The Global Variables First
var lstrLookUpValues;
var lobjControlToReturn;
var gstrRowColorsArr = new Array("#DDDDDD","#EEEEEE");
var gobjLongText;
var blnBorder = false;
var __RECAP=false;
var __ProjectionID='';
document.onstop=gfnOnStop;

function gfnOnStop()
{
	for(var j=0;j<document.forms.length;j++)
	{
		for(var i=0;i<document.forms(j).length;i++)
		{
			if(document.forms(j).item(i).className=="cssDisabled")
			{
				document.forms(j).item(i).disabled=true;
			}
		}
	}
}


//To Replace leading and ending space from string 
String.prototype.trim = function()
						{
							var str;
							//LTrim
							str = this.replace(/^\s+|\s+$/, ''); 
						
							//RTrim
							return str.replace(/((\s*\S+)*)\s*/, '$1');
						};
						
//I- LENGTH CHECK FUNCTIONS

//USE TO CHECK LENGTH
//PARAMETER 1: String Control Name
//PARAMETER 2: Control Caption
function gfnCheckLen(pobjControl, pintLength, pstrCaption)
{
	if (pobjControl.value.length > pintLength)
	{
		gfnShowError(536, pstrCaption, pintLength);
		pobjControl.focus();
		return false;
	}
	return true;
}

function gfnCheckLen1(pobjControl, pintLength)
{
	if (pobjControl.value.length > pintLength)
	{
		window.event.returnValue = false;
		return false;
	}
	return true;
}

//II- CHARACTER CHECK FUNCTIONS

//USE TO CHECK EMPTY
//PARAMETER 1: Control Name
//PARAMETER 2: Control Caption
function gfnCheckEmpty(pobjControl, pstrCaption, pstrMessage)
{
	var lstrValue = pobjControl.value;
 	if (pstrMessage != "N")
		pstrMessage = "Y";
	lstrValue = Trim(lstrValue);
	if (lstrValue.length == 0)
	{
		pobjControl.value = "";
		if (pstrMessage == "Y")
			{
			gfnShowError(501, pstrCaption);
			pobjControl.focus();
			}
		return false;
	}
	return true;
}

function limitText(textObj, maxCharacters)
{
if (textObj.innerText.length >= maxCharacters)
	{
	if ((event.keyCode >= 32 && event.keyCode <= 126) || (event.keyCode >= 128 && event.keyCode <= 254))
		{
			event.returnValue = false;
		}
	}
}
	
	
function gfnIsCHECKED(pstrChkOptValue, pstrCheckWithValue)
{
	if (pstrChkOptValue = pstrCheckWithValue)
	{
		return true;
	}
	return false;	
}


//USE TO ALLOWS ALPHABETS ONLY 
//PARAMETER 1: String Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: Characters to be allowed
function gfnCheckString(pobjControl, pstrCaption, pstrAllow)
{
	var lstrPattern= new RegExp("[a-z,A-Z," + pstrAllow + "]", "g");
	var lstrRetArr=pobjControl.value.match(lstrPattern);
	if (lstrRetArr==null)
	{
		gfnShowError(535, pstrCaption);
		pobjControl.focus();
		return false;
	}
	else
	{
		if (lstrRetArr.length==pobjControl.value.length)
			return true;
		else
		{
			gfnShowError(535, pstrCaption);
			pobjControl.focus();
			return false;
		}
	}
}

//USE TO ALLOW ALPHA-NUMERICS ONLY 
//PARAMETER 1: String Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: Spl Characters to be allowed
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;
		}
	}
}

//USE TO ALLOW NUMERICS ONLY
//PARAMETER 1: Numeric Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: Spl Characters to be allowed
function CheckNumeric(pobjControl, pstrCaption, pstrAllow)
{
	var lstrString=pobjControl.value;

	if (lstrString.length==0)
		return true;
	var lstrPattern= new RegExp("[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;
		}
	}
}

//USE TO DIS-ALLOW SPECIFIC CHARACTERS
//PARAMETER 1: String Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: Spl Characters to be Dis-allowed
function gfnBarSplChrs(pobjControl, pstrCaption, pstrBarChars,pstrMuteFlag)
{
	var lstrString=pobjControl.value;
	if (lstrString.length==0)
		return true;
	var lstrPattern= new RegExp("[" + pstrBarChars + "]", "g");
	var lstrRetArr=lstrString.match(lstrPattern);
	if (lstrRetArr==null && ! gfnIsContainSlash(lstrString,pstrBarChars))
	{
		return true;
	}
	else
	{
		if (pstrMuteFlag!='Y')
		{
			gfnShowError(531, pstrCaption);
			pobjControl.focus();
		}
		return false;
	}
}
/*
This checks for back slash in the input.It returns true if bar character
as well as input char contains back slash
*/
function gfnIsContainSlash(pstrInput,pstrBarChars){			
	var lstrSplChar = '\\';			
	var lintSlashInInput;
	var lintSlashInBarChars;
	lintSlashInInput = pstrInput.indexOf(lstrSplChar);
	lintSlashInBarChars = pstrBarChars.indexOf(lstrSplChar);	
	if (lintSlashInBarChars == -1){
		return false;
	}
	else{
		if(lintSlashInInput != -1){
			return true;
		}
	}		
	return false;
}




//III- NUMERIC CHECK FUNCTIONS

//USE TO ALLOW NUMERICS ONLY
//PARAMETER 1: Numeric Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: Spl Characters to be allowed
//PARAMETER 4: 'O' if Numeric Field is a Optional Field, 'M' if Numeric Field is Mandatory
//PROPOSED FUTURE SIGNATURE: function gfnCheckNumeric(pobjControl, pstrCaption, pstrAllow, pstrFormat)
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;
		}
	}
}



//IV- DATE CHECK FUNCTIONS
//USE TO GET DATE DIFFERENCE IN NO OF DAYS
//PARAMETER 1: Date No 1 (Date Type)
//PARAMETER 2: Date No 2 (Date Type)
function gfnRetDateDiff(pdtmDate1, pdtmDate2)
{
	return ((pdtmDate1 - pdtmDate2)/1000/60/60/24);
}



//USE TO CHECK IF DATE IS VALID
//PARAMETER 1: Date Control Name
//PARAMETER 2: Control Caption
//PARAMETER 3: 'O' if Date is a Optional Field, 'M' if Date is Mandatory
function gfnCheckDate(pobjControl, pstrCaption, pstrOptionalFlag)
{
	var ldtmValidDate;
	var lstrDateValue = pobjControl.value;

	// If the Date is optional and the user leaves it blank then 
	// let it be so and do not proceed with validating the date 
	if ((pstrOptionalFlag == 'O') && (lstrDateValue == ''))
	{
		return true; //Exit if Optional
	}
	if ((pstrOptionalFlag == 'M') && (lstrDateValue == ''))
	{
		gfnShowError(501, pstrCaption);
		pobjControl.focus();
		return false;
	}

	if (gfnCheckSplCharacters(pobjControl, pstrCaption, "/") == false)
	{
		pobjControl.focus();
		return false;
	}
	if (lstrDateValue.length != 10)
	{
		gfnShowError(521, pstrCaption);
		pobjControl.focus();
		return false;
	}
	ldtmValidDate = gfnConvertToDate(lstrDateValue, pstrCaption);

	if (ldtmValidDate == false)
	{
		pobjControl.focus();
		return false;
	}
	else
	{
		return ldtmValidDate;
	}
}


//USE TO VALIDATE AND THEN CONVERT A STRING OF DD/MM/YYYY FORMAT TO A VALID JS DATE
//Converts String To Date
function gfnConvertToDate(lstrDateValue, pstrCaption)
{
	var ldtmBaseDate;
	ldtmBaseDate=new Date(1900, 00, 01);
	// Checks for the following valid date formats:
	// DD/MM/YYYY
	// Also separates date into month, day, and year variables

	var lstrDatePattern = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/;
	var lstrMatchArray = lstrDateValue.match(lstrDatePattern);//CHECK FORMAT
	if (lstrMatchArray == null) 
	{
		gfnShowError(521);
		return false;
	}

	// parse date into variables
	var day = lstrMatchArray[1];
	var month = lstrMatchArray[3];
	var year = lstrMatchArray[4];

	if (month < 1 || month > 12) // check month range
	{
		gfnShowError(532,"Month","1","12");
		return false;
	}
	if (day < 1 || day > 31)
	{
		gfnShowError(532,"Day","1","31");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day == 31)
	{
		gfnShowError(533, month);
		return false;
	}
	if (month == 2) // check for february 29th
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap))
		{
			gfnShowError(534, year, day);
			return false;
		}
	}
	var ldtmCheckDate=new Date(year, month-1, day);
	if (gfnRetDateDiff(ldtmCheckDate, ldtmBaseDate)<0)
	{
		gfnShowError(504,"Date","Base Date");
		return false;
	}
	return ldtmCheckDate; //Sucess
}


function gfnShowLookup(pstrURL)
{
  	window.open(pstrURL,null,"scrollbars=yes,resizable=yes");
}



//USE TO CONFIRM THE USER ON CLICK OF DELETE BUTTON
//Confirm's User For Record Deletion
function gfnDeleteConfirm()
{
	var lstrConfirm;
	
	if(arguments.length != 0)
	{
		lstrConfirm = "You have opted to " + arguments[0] + ", Shall the System proceed with " + arguments[1] + "?";
	}	
	else
	{
		lstrConfirm = "You have opted to Delete , Shall the System proceed with Deletion?";
	}
	
	if(confirm(lstrConfirm))
	{
		return true;
	}
	else
	{
		return false;
	}
}




//USE TO SHOW A ERROR MESSAGE
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("Invalid " + arguments[1] + ", 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("Invalid " + arguments[1] + ", " + 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;
	}
}





//To Remove a Row
function gsbCallToRemove()
{
	var lobjTable =	arguments[0];

	if (mlngCurrRecCnt > 1)
	{
		lobjTable.deleteRow(mlngCurrRecCnt);
		mlngCurrRecCnt --;
		mintSwitchColor = (mintSwitchColor == 0)?1:0;
	}
}

//To Create values for Add
function gsbCaptureContents()
{
	var lintICtr;
	var lobjTable =	arguments[0];
	var lintColCnt = arguments[1];
	var lstrMyMode = arguments[2];
	var lintNoOfRecs = arguments[3];

	for(lintICtr=0; lintICtr < lintColCnt ; lintICtr++)
	{
		mstrColStr[lintICtr] = lobjTable.rows[1].cells(lintICtr).innerHTML;
		//alert(mstrColStr[lintICtr]);
	}

	if (lintNoOfRecs >= 1)
		mlngCurrRecCnt = lintNoOfRecs;
}

//To retrieve Combo/List/Option/Check Boxes values
//PARAMETER 1: Control Name From Which the value need to be retrieved
//PARAMETER 2: Control Type Legends as used by this function to identify the control type
//RETURNS : The Values of the Passed Control, if more than 1 is Selected then these are | Seperated

function gfnGetSelectedValue()
{
	var lintICtr;
	var lstMyValues = ""; //Used for List/Check Box

	var lobjCntrlName = arguments[0];
	var lstrCntrlType = arguments[1];

	switch(lstrCntrlType)
	{
		case "C"://Combo Box
		case "L"://List Box
			if (lobjCntrlName.selected)
			{
				lstMyValues = lobjCntrlName.value;
			}
			else
			{
               			for(lintICtr=0;lintICtr < lobjCntrlName.length;lintICtr++)
               			{
               				if (lobjCntrlName[lintICtr].selected)
                				lstMyValues = lstMyValues + lobjCntrlName[lintICtr].value + "|";
               			}
        			lstMyValues = (lstMyValues == 'undefined')? "":lstMyValues.substr(0,lstMyValues.length-1);
			}
			return lstMyValues;
			break;
		case "O"://Option Button
			if (lobjCntrlName.checked)
			{
				lstMyValues = lobjCntrlName.value;
			}
			else
			{
               			for(lintICtr=0;lintICtr < lobjCntrlName.length;lintICtr++)
               			{
               				if (lobjCntrlName[lintICtr].checked)
                				lstMyValues = lobjCntrlName[lintICtr].value;
               			}
        			lstMyValues = (lstMyValues == 'undefined')? "":lstMyValues;
			}
			return lstMyValues;
			break;
		case "H"://Check Box
			if (lobjCntrlName.checked)
			{
				lstMyValues = lobjCntrlName.value;
			}
			else
			{
        			for(lintICtr=0;lintICtr < lobjCntrlName.length;lintICtr++)
        			{
        				if (lobjCntrlName[lintICtr].checked)
        					lstMyValues = lstMyValues + lobjCntrlName[lintICtr].value + "|";
               			}
        			lstMyValues = (lstMyValues == 'undefined')? "":lstMyValues.substr(0,lstMyValues.length-1);
			}
			return lstMyValues;
			break;
	}
}


//To retrieve Server URL
//RETURNS : URL
function gfnLookUpURL()
	{
		var lstrURL = "http://" + location.host + "/crpf/";
		return lstrURL;
	}



function gfnEnableAll()
{
	for(var j=0;j<document.forms.length;j++)
	{
		for(var i=0;i<document.forms(j).length;i++)
		{
			document.forms(j).item(i).disabled=false;
		}
	}
}

function gfnSetOptionalText()
{
	for(var j=0;j<document.forms.length;j++)
	{
		for(var i=0;i<document.forms(j).length;i++)
		{
			if(document.forms(j).item(i).type=="text" && document.forms(j).item(i).value=="NA")
				document.forms(j).item(i).value="";
		}
	}
}

function gfnSetIMG(pstrControlName, pstrInnerHTML,pstrPrevClass,pstrCurClass)
{
	var lstrHTML;
	var lstrFinalHTML;
	lstrHTML=pstrInnerHTML.split("<");
	lstrFinalHTML="";
	for(var k=1;k<lstrHTML.length;k++)
	{
		lstrFinalHTML=lstrFinalHTML + "<" + lstrHTML[k];
		if (k+1<lstrHTML.length)
		{
			if (lstrHTML[k+1].substring(0,3)=="IMG" && lstrHTML[k].search(pstrControlName)!=-1)
			{
				if (lstrHTML[k+1].search("class=" + pstrPrevClass)!=-1)
					lstrFinalHTML=lstrFinalHTML + "<" + lstrHTML[k+1].replace("class=" + pstrPrevClass,"class=" + pstrCurClass);
				else if (lstrHTML[k+1].search("class=" + pstrCurClass)!=-1)
					lstrFinalHTML=lstrFinalHTML + "<" + lstrHTML[k+1];	
				else
					lstrFinalHTML=lstrFinalHTML + "<" + lstrHTML[k+1].replace("IMG","IMG class=" + pstrCurClass);
				k++;
			}
		}
	}
	return lstrFinalHTML;

}

function gfnSetBgColor()
{
	var lintCtrls,i;
	if(arguments.length==0)
	{	
		for(var j=0;j<document.forms.length;j++)
		{
			lintCtrls=document.forms(j).length;
			for(var i=0;i<lintCtrls;i++)
			{
				if (document.forms(j).item(i).readOnly==true || document.forms(j).item(i).disabled==true)
				{
					document.forms(j).item(i).className="cssDisabled";
					if(document.forms(j).item(i).parentElement.innerHTML.toUpperCase().search("IMG")>0)
						document.forms(j).item(i).parentElement.innerHTML=gfnSetIMG(document.forms(j).item(i).name, document.forms(j).item(i).parentElement.innerHTML,"cssVisible","cssInvisible");
				}
				else
				{
					if(document.forms(j).item(i).parentElement.innerHTML.toUpperCase().search("IMG")>0)
						document.forms(j).item(i).parentElement.innerHTML=gfnSetIMG(document.forms(j).item(i).name,document.forms(j).item(i).parentElement.innerHTML,"cssInvisible","cssVisible");

					if(!(document.forms(j).item(i).type=="radio" && document.forms(j).item(i).type=="checkbox"))
						document.forms(j).item(i).className="cssOptional";
				}
				if(document.forms(j).item(i).id=="M" && !(document.forms(j).item(i).readOnly==true || document.forms(j).item(i).disabled==true))
				{
					document.forms(j).item(i).className="cssMandatory";
				}
				if(document.forms(j).item(i).type=="submit")
					document.forms(j).item(i).className="cssSubmit";
				if(document.forms(j).item(i).type=="reset")
					document.forms(j).item(i).className="cssCancel";
				if(document.forms(j).item(i).type=="button")
					document.forms(j).item(i).className="cssButton";
			}
		}
	}
	else
	{
		var lobjControl,larrControlArr;
		for(var j=0;j<arguments.length;j++)
		{
			larrControlArr=arguments[j].split(",");
			for(var i=0;i<larrControlArr.length;i++)
			{
				lobjControl = eval(larrControlArr[i]);
				if (lobjControl.readOnly==true || lobjControl.disabled==true)
				{
					lobjControl.className="cssDisabled";
					if(lobjControl.parentElement.innerHTML.toUpperCase().search("IMG")>0)
					{
						lobjControl.parentElement.innerHTML=gfnSetIMG(lobjControl.name, lobjControl.parentElement.innerHTML,"cssVisible","cssInvisible");
						lobjControl = eval(larrControlArr[i]);
					}
				}
				else
				{
					if(lobjControl.parentElement.innerHTML.toUpperCase().search("IMG")>0)
					{
						lobjControl.parentElement.innerHTML=gfnSetIMG(lobjControl.name,lobjControl.parentElement.innerHTML,"cssInvisible","cssVisible");
						lobjControl = eval(larrControlArr[i]);
					}
					if(!(lobjControl.type=="radio" && lobjControl.type=="checkbox"))
						lobjControl.className="cssOptional";
				}
				if(lobjControl.id=="M" && !(lobjControl.readOnly==true || lobjControl.disabled==true))
				{
					lobjControl.className="cssMandatory";
				}
				if(lobjControl.type=="submit")
					lobjControl.className="cssSubmit";
				if(lobjControl.type=="reset")
					lobjControl.className="cssCancel";
				if(lobjControl.type=="button")
					lobjControl.className="cssButton";
			}
		}
	}
}

function gfnSetControlBgColor(pobjControlName)
{
	var lobjControl;
	lobjControl = eval(pobjControlName);
	if (lobjControl.readOnly==true || lobjControl.disabled==true)
	{
		lobjControl.className="cssDisabled";
		lobjControl.parentElement.innerHTML=gfnSetIMG(lobjControl.name, lobjControl.parentElement.innerHTML,"cssVisible","cssInvisible");
		lobjControl = eval(pobjControlName);
	}
	else
	{
		lobjControl.parentElement.innerHTML=gfnSetIMG(lobjControl.name,lobjControl.parentElement.innerHTML,"cssInvisible","cssVisible");
		lobjControl = eval(pobjControlName);
		lobjControl.className="cssOptional";
	}
	if(lobjControl.id=="M" && !(lobjControl.readOnly==true || lobjControl.disabled==true))
	{
		lobjControl.className="cssMandatory";
	}
	if(lobjControl.type=="submit")
		lobjControl.className="cssSubmit";
	if(lobjControl.type=="reset")
		lobjControl.className="cssCancel";
	if(lobjControl.type=="button")
		lobjControl.className="cssButton";
}

///UNDER TESTING
//To Add/Copy a Row
function gsbCallToAdd()
{
	var lintICtr;
	var lstrPrevCell;

	var lstrAddTyp = arguments[0];
	var lobjTable =	arguments[1];
	var lintColCnt = arguments[2];
	var lstrCurCellHTML;
	var lstrControlNames="",lstrTestName;

	lintICtr = lobjTable.insertRow()

	mlngCurrRecCnt++;

	document.all.hdnNoOfRecs.value = mlngCurrRecCnt;

	lobjTable.rows[mlngCurrRecCnt].align = "center";

	if (lstrAddTyp == "C")
	{
		for(lintICtr=0; lintICtr < lintColCnt ; lintICtr++)
		{
			lstrPrevCell = lobjTable.rows[mlngCurrRecCnt].insertCell();
			if (lintICtr > 0) //Not To Copy Col 0
			{
				lobjTable.rows[mlngCurrRecCnt].cells[lintICtr].style.backgroundColor = (mintSwitchColor == 0)?gstrRowColorsArr[0]:gstrRowColorsArr[1];
				
				lstrCurCellHTML=lobjTable.rows[mlngCurrRecCnt-1].cells(lintICtr).innerHTML;
				
				lstrTestName = gfnRetControlName(lstrCurCellHTML,mlngCurrRecCnt-1);
				if (lstrTestName!=false) lstrControlNames = lstrControlNames + lstrTestName + ",";

				lstrPrevCell.innerHTML = lstrCurCellHTML;
			}
		}
		lstrControlNames = lstrControlNames.substr(0,lstrControlNames.length-1);

		if (document.all.cmdCopy != "UNDEFINED")
			document.all.cmdCopy.focus();
	}
	else if (lstrAddTyp == "A")
	{
		for(lintICtr=0; lintICtr < lintColCnt ; lintICtr++)
		{
			lstrPrevCell = lobjTable.rows[mlngCurrRecCnt].insertCell();
			
			if (lintICtr > 0) //Not To Copy Col 0
			{
				lstrCurCellHTML=mstrColStr[lintICtr];
				
				lstrTestName = gfnRetControlName(lstrCurCellHTML,mlngCurrRecCnt-1);
				if (lstrTestName!=false) lstrControlNames = lstrControlNames + lstrTestName + ",";
				
				do
				{					
					lstrCurCellHTML=lstrCurCellHTML.replace("%%",mlngCurrRecCnt-1);
				}while(lstrCurCellHTML.search("%%")!=-1)

				lobjTable.rows[mlngCurrRecCnt].cells[lintICtr].style.backgroundColor = (mintSwitchColor == 0)?gstrRowColorsArr[0]:gstrRowColorsArr[1];
				lstrPrevCell.innerHTML = lstrCurCellHTML;
			}
			else
			{
				var lintTemp = mlngCurrRecCnt - 1
				lstrPrevCell.id = "err" + lintTemp;
			}
		}
		lstrControlNames = lstrControlNames.substr(0,lstrControlNames.length-1);
//		document.all.cmdAddNew.focus();
		lobjTable.rows[mlngCurrRecCnt].cells[1].style.backgroundColor = (mintSwitchColor == 0)?gstrRowColorsArr[0]:gstrRowColorsArr[1];
	}
	mintSwitchColor = (mintSwitchColor == 0)?1:0;
	
	if (arguments[3]!="N")
		gfnSetBgColor(lstrControlNames);

}

//
function gfnRetControlName(pstrHTML,plngSubscript)
{
	var lintCtr,lstrSearchStr,lstrControlName="";
	lstrSearchStr = pstrHTML.toUpperCase();
	
	lintCtr = lstrSearchStr.search(" NAME ");

	if (lintCtr<0)
		lintCtr= lstrSearchStr.search(" NAME=");

	if (lintCtr<0)
		return false;
	
	lintCtr= lintCtr + 5;

	for(;lintCtr<lstrSearchStr.length;lintCtr++)
		if((lstrSearchStr.charAt(lintCtr)>='A' && lstrSearchStr.charAt(lintCtr)<='Z') || (lstrSearchStr.charAt(lintCtr)>='a' && lstrSearchStr.charAt(lintCtr)<='z') || (lstrSearchStr.charAt(lintCtr)>='0' && lstrSearchStr.charAt(lintCtr)<='9'))
			break;

	for(;lintCtr<lstrSearchStr.length;lintCtr++)
	{
		if((lstrSearchStr.charAt(lintCtr)>='A' && lstrSearchStr.charAt(lintCtr)<='Z') || (lstrSearchStr.charAt(lintCtr)>='a' && lstrSearchStr.charAt(lintCtr)<='z') || (lstrSearchStr.charAt(lintCtr)>='0' && lstrSearchStr.charAt(lintCtr)<='9') || lstrSearchStr.charAt(lintCtr)=='%')
			lstrControlName = lstrControlName + pstrHTML.charAt(lintCtr);
		else
			break;
	}

	if(lstrControlName.substr(lstrControlName.length-2,2)=="%%")
		lstrControlName = lstrControlName.substr(0,lstrControlName.length-2) + plngSubscript; 
	else
		lstrControlName = lstrControlName + '[' + plngSubscript + ']'; 

	return "document." + document.forms(0).name + '.' + lstrControlName;
}

//Returns the financial year in which the date falls
function gfnGetFinancialYear()
{
	var ldtmCheckDate = arguments[0];
	var lintMonth = ldtmCheckDate.getMonth();
	var lintYear = ldtmCheckDate.getFullYear();
	
	lintMonth = lintMonth + 1;
	if (lintMonth >= 4 && lintMonth <= 12)
		return(lintYear);
	else 	return(lintYear - 1); 
}



// This function will add items to a combo
// Argument 1 : combo box control
// Argument 2 : Display Value
// Argument 3 : Stored value

function gfnAddToCombo()
{
	var oOption;
	oOption = document.createElement("OPTION");
	oOption.text=arguments[1];
	oOption.value=arguments[2];
	arguments[0].add(oOption);
}


// This function will remove items from combo
// Argument 1 : combo box control
// Argument 2 : Index of the item to be removed.  This argument is optional.  
		//If the value is not specified, all items are removed

function gfnRemoveFromCombo()
{
	var lintCtr,lintTotCtr;
	
	if (parseInt(arguments[1])==arguments[1])
	{
		if(arguments[1]<arguments[0].length)
			arguments[0].remove(arguments[1]);
	}
	else
	{
		lintTotCtr=arguments[0].length;
		for(lintCtr=0;lintCtr<lintTotCtr;lintCtr++)
		{
			arguments[0].remove(0);
		}
	}
}


// This function will remove set Check box for single selection
// Argument 1 : Check Box Control
// Argument 2 : Check Box Script

function gfnSetCheckBox(pobjCheckBox, lstrScript)
{
	if(pobjCheckBox.checked){
		eval(lstrScript);
		pobjCheckBox.checked = true;
	}
	return pobjCheckBox.checked;
}

//USE TO TRIM LEFT SPACES IN A STRING 
//PARAMETER 1: String To Be Processed
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;
	}
        
//USE TO TRIM RIGHT SPACES IN A STRING 
//PARAMETER 1: String To Be Processed
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;
        }
        
        
//USE TO TRIM LEFT and RIGHT SPACES IN A STRING 
//PARAMETER 1: String To Be Processed
function Trim(pstrTrimStr)
        {
        	return RTrim(LTrim(pstrTrimStr));
        }


///Validate Date for FY - It should lie between current date and last transaction date
//Input Parameters - 1) Financial Year string in the form of [FY~~Date^^FY~~Date~~^^]
//					 2) Date to be checked like Sanction Order Date
//					 3) Caption of Field to be displayed in case of error
//					 4) Caption of Field for which Max value is calculated - Last Transaction Date for Sanction Order
//					 5) Current Date from gfnCurrentDate()
//Returns		    - False in case of Error
//					- Financial Year if Date suffices the criteria
	
function gfnValidateDateforFY()
{
	var lstrDflt = arguments[0];								//Stores Financial Details String
	var larrDflt;												//Array Stores all the Financial Year~~Max Date
	var lintFyear;												//Stores Financial Year
	var ldtmCurrentDate = arguments[4];							//Stores Current Date
	var ldtmLstTrnsctnDate = '';								//Transaction Date
	var lintDtFYear=0;
	var lblnFlag='N';
	var ldtmDate = arguments[1];								//The Date To be Checked
	var lstrCaption = arguments[2];								//Caption of Field to be displayed in case of error
	var lstrCaption2 = arguments[3];							//Max of which field is calculated - Last Transaction Date for Sanction Order
		
	// txtSancOrderDate: DATE CHECK
	if (ldtmDate != '')
	{
		ldtmDate = gfnCheckDate(ldtmDate, lstrCaption, "M");
		ldtmCurrentDate = gfnConvertToDate(ldtmCurrentDate,'Current Date');
		if (ldtmDate == false)
		{
			return false;
		}
		if (gfnRetDateDiff(ldtmCurrentDate,ldtmDate) <  0)
		{
			gfnShowError(503,lstrCaption,"Current Date and greater than equal to the last transaction date");
			return false;
		}
		lintDtFYear = gfnGetFinancialYear(ldtmDate);
		larrDflt = lstrDflt.split('^^');
		for(var lintCntr=0;lintCntr<larrDflt.length-1;lintCntr++)
		{
			larrDflt[lintCntr] += '~~';
			var larrDtls = larrDflt[lintCntr].split('~~');
			lintFyear = larrDtls[0];
			ldtmLstTrnsctnDate=gfnConvertToDate(larrDtls[1],lstrCaption2);
			if(lintDtFYear==lintFyear)
			{
				if (ldtmDate < ldtmLstTrnsctnDate)
				{
					gfnShowError(504,lstrCaption,larrDtls[1]);
					return false;
				}
				else
				{
					lblnFlag = 'Y';
					return lintDtFYear;
				}
			}
		}
		if(lblnFlag=='N')
		{
			gfnShowError(554);
			return false;
		}
	}
	else
	{
		gfnShowError(501,lstrCaption);
		return false;
	}
}

//Function to Round off
function gfnRound(psngValue,pintNoOfPlaces)
{
	var lintNum = Math.pow(10,pintNoOfPlaces);
	return parseFloat(Math.round(psngValue*lintNum)/lintNum);
}


//Checks for two or more occurences of "." in Amount Field
function gfnCheckAmount(pobjControl, pstrCaption)
{
	var ldblNumvalue = pobjControl.value;
	var ldblNumdecimals = ldblNumvalue.split('.');
	if (ldblNumdecimals.length > 2)
	{
		gfnShowError(522, pstrCaption);
		pobjControl.focus();
		return false;
	}
	return true;
}		

function  gfnCheckTime(pobjCtrl,pstrCaption,pstrOptionalFlag) 
{
	// Numeric Check, Empty check
	if (gfnCheckNumeric(pobjCtrl, pstrCaption, "",pstrOptionalFlag) == false)
	{
		return false;
	}
	//Length = 4
	if (pobjCtrl.value.length < 4)
	{
		gfnShowError(504,pstrCaption,"4 characters");
		pobjCtrl.focus();
		return false;
	}
	//First two digits between 0 and 24
	if ((parseInt(pobjCtrl.value.substring(0,2)) < 0) || (parseInt(pobjCtrl.value.substring(0,2)) > 23))
	{
		gfnShowError(532,"Hours in " + pstrCaption,"0","23");
		pobjCtrl.focus();
		return false;
	}
	//Last two digits between 0 and 60
	if ((parseInt(pobjCtrl.value.substring(2,4)) < 0) || (parseInt(pobjCtrl.value.substring(2,4)) > 59))
	{
		gfnShowError(532,"Minutes in " + pstrCaption,"0","59");
		pobjCtrl.focus();
		return false;
	}
	//Maximum value should be 2359 
	if (parseInt(pobjCtrl.value) > 2359)
	{
		gfnShowError(508,pstrCaption);
		pobjCtrl.focus();
		return false;
	}
	return true;
}

//USE TO RETURN DATE IN DD/MM/YYYY format
//PARAMETER 1: Date
function gfnDateToString(pdtmDate)
{
	return (gfnLpad(pdtmDate.getDate(),"0",2) + "/" + gfnLpad(pdtmDate.getMonth()+1,"0",2) + "/" + pdtmDate.getFullYear());
}


function gfnLpad(pstrVal,pstrPadChar,pintLen)
{
	var lintCtr,lstrPad,lintValLen;
	lstrPad="";
	lintValLen=String(pstrVal).length;
	if (lintValLen < pintLen)
		for(lintCtr=1;lintCtr<=(pintLen-(lintValLen));lintCtr++)
			lstrPad=lstrPad + pstrPadChar;
	return (lstrPad + pstrVal);
}

function showHideContent(id,bOn)
{
	var bMO = false;
	var oContent = document.all.item(id+"Content");
	var oImage   = document.all.item(id+"Tab2");
	if (!oContent || !oImage) return;

	if (event.srcElement)
	{
		bMO = (event.srcElement.src.toLowerCase().indexOf("_mo.gif") != -1);
		bOn = (oContent.style.display.toLowerCase() == "none");
	}

	if (bOn == false)
	{
		oContent.style.display = "none";
		oImage.src = "/crpf/images/expand" + (bMO? "_mo.gif" : ".gif");
	}
	else
	{
		oContent.style.display = "";
		oImage.src = "/crpf/images/collapse" + (bMO? "_mo.gif" : ".gif");
	}
}

function setBorder(id,bOn)
{
	var oTab    = document.all.item(id+"Tab");
	var oTab1   = document.all.item(id+"Tab1");
	var oTab2   = document.all.item(id+"Tab2");
	var oBorder = document.all.item(id+"Content");

	if (!oTab || !oTab1 || !oTab2 || !oBorder) 
		return;

	if (bOn)
	{
		oBorder.style.borderColor = "#cccccc";
		oTab.bgColor = "#3366CC";
//		oTab1.src    = "/crpf/images/curve_mo.gif";
		oTab1.color  = "#FFFFFF";
		if (oBorder.style.display == "none")
			oTab2.src = "/crpf/images/expand_mo.gif";
		else
			oTab2.src = "/crpf/images/collapse_mo.gif";
	}
	else
	{
		oBorder.style.borderColor = blnBorder? "#cccccc" : "#ffffff";
		oTab.bgColor = "#CCCCCC";
//		oTab1.src	 = "/crpf/images/curve.gif";
		oTab1.color  = "#003399";
		if (oBorder.style.display == "none")
			oTab2.src = "/crpf/images/expand.gif";
		else
			oTab2.src = "/crpf/images/collapse.gif";
	}
}

//USE TO SET VALUES IN LONG FIELDS USING ANOTHER FILE
//PARAMETER 1: String Control Name
function gfnSetText(pobjLongText)
{
	gobjLongText=pobjLongText;
	var lintLeft,lintTop,lstrLeftTop;
	lintLeft = screen.width/2-175;
	lintTop = screen.height/2-100;
	lstrLeftTop = ",left=" + lintLeft + ",top=" + lintTop;
	window.open("SetText.htm","SetText","height=200,width=350,toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0" + lstrLeftTop);
}


function gfnAppendQuotes(strParameters)
{
	var strParam = "";

	strParameters = Trim(strParameters);
	strParam = Replace(strParameters, "'", "");
	strParam = Replace(strParam, ",", "','");
	if (strParam.length !=0 )
	{
		strParam = "'" + strParam + "'";
	}
	return strParam;
}

function Replace(strParameters, SearchStr, ReplaceStr)
{
	var strParam = "";
	if (strParameters.length != 0)
	{
		for (var iCounter = 1 ; iCounter <= strParameters.length ; iCounter++)
		{
			if (strParameters.substring(iCounter-1,iCounter) == SearchStr) 
			{
				strParam+=ReplaceStr;
			}
			else
			{
				strParam+=strParameters.substring(iCounter-1,iCounter); 
			}
		}	
	}
	return strParam;
}

function gfnIsFromGtTo(pobjControl1,pobjControl2,pstrCaption1,pstrCaption2)
{
  	frcharday 	= pobjControl1.value.charAt(0)+pobjControl1.value.charAt(1)
	frcharmonth 	= pobjControl1.value.charAt(3)+pobjControl1.value.charAt(4)
	frcharyear 	= pobjControl1.value.charAt(6)+ pobjControl1.value.charAt(7) + pobjControl1.value.charAt(8)+pobjControl1.value.charAt(9)
	tocharday 	= pobjControl2.value.charAt(0)+pobjControl2.value.charAt(1)
	tocharmonth 	= pobjControl2.value.charAt(3)+pobjControl2.value.charAt(4)
	tocharyear 	= pobjControl2.value.charAt(6)+ pobjControl2.value.charAt(7) + pobjControl2.value.charAt(8)+pobjControl2.value.charAt(9)
	frday 		= parseInt(frcharday,10)
	frmonth 	= parseInt(frcharmonth,10)
	fryear 		= parseInt(frcharyear,10)
	today 		= parseInt(tocharday,10)
	tomonth 	= parseInt(tocharmonth,10)
	toyear 		= parseInt(tocharyear,10)
	
	if (fryear > toyear)
	{
		gfnShowError(507,pstrCaption1,pstrCaption2);
		pobjControl1.focus()
		return false;
        }
    	if (toyear == fryear)
	{
	 
		if (frmonth > tomonth)
	      	{
			gfnShowError(507,pstrCaption1,pstrCaption2);
			pobjControl1.focus()
			return false;
	      	}	
	     	if  (frmonth == tomonth)
	      	{
	        	if (frday > today)
	        	{		
				gfnShowError(507,pstrCaption1,pstrCaption2);
				pobjControl1.focus()
				return false;
	        	} 
          	}    
      	}
	//return true;
}


//used just for check the date but no alert is given
function gfnIsSessionFromGtTo(pobjControl1,pobjControl2,pstrCaption1,pstrCaption2)
{
  	frcharday 	= pobjControl1.value.charAt(0)+pobjControl1.value.charAt(1)
	frcharmonth 	= pobjControl1.value.charAt(3)+pobjControl1.value.charAt(4)
	frcharyear 	= pobjControl1.value.charAt(6)+ pobjControl1.value.charAt(7) + pobjControl1.value.charAt(8)+pobjControl1.value.charAt(9)
	tocharday 	= pobjControl2.value.charAt(0)+pobjControl2.value.charAt(1)
	tocharmonth 	= pobjControl2.value.charAt(3)+pobjControl2.value.charAt(4)
	tocharyear 	= pobjControl2.value.charAt(6)+ pobjControl2.value.charAt(7) + pobjControl2.value.charAt(8)+pobjControl2.value.charAt(9)
	frday 		= parseInt(frcharday,10)
	frmonth 	= parseInt(frcharmonth,10)
	fryear 		= parseInt(frcharyear,10)
	today 		= parseInt(tocharday,10)
	tomonth 	= parseInt(tocharmonth,10)
	toyear 		= parseInt(tocharyear,10)
	
	if (fryear > toyear)
	{
		return false;
    }
    	if (toyear == fryear)
	{
	 
		if (frmonth > tomonth)
	   	{
			return false;
		}
	}	
	if  (frmonth == tomonth)
	{
		if (frday > today)
		{		
			return false;
		}

    } 


	return true;
}

//For the sessions entry or edit screens
function gfnSessionDateConfirm()
{
	if(confirm("The session Date entered is outside the date range of batch, continuing will update the batch date range. Are you sure you want to continue?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//For the sessions entry or edit screens
function gfnPatternDayConfirm()
{
	if(confirm("The session Date entered does not confirm to the batch pattern. Are you sure you want to continue?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//For the sessions entry or edit screens
function gfnPatternTimeConfirm()
{
	if(confirm("The session Time entered does not confirm to the batch pattern. Are you sure you want to continue?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Trainer honorarium has not been processed
function gfnTrainerHonConfirm()
{
	if(confirm("Trainer honorarium has not been processed even for a single session.Do you still want to complete the batch?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Assistant Trainer honorarium has not been processed
function gfnAsstTrainerHon()
{
	if(confirm("Assistant Trainer honorarium has not been processed even for a single session.Do you still want to complete the batch?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//===========================================================================================
//for pagination 

	// This function will trim leading and/or trailing spaces from a string
	// arg = the value you wish to have trimmed..
	// func = "left" for Ltrim(), "right" for RTrim() or "both" for Trim()
	function gfnDoTrim(arg,func)
	{
		var trimvalue = "";
		arglen = arg.length;
		if (arglen < 1) return trimvalue;	

		if (func == "left" || func== "both")
		{
			i = 0;
			pos = -1;
			while (i < arglen) 
			{
				if (arg.charCodeAt(i) != 32 &&
					!isNaN(arg.charCodeAt(i)))
				{	
					pos = i;
					break;
				}
				i++;
			}
		}

		if (func == "right" || func== "both")
		{
			var lastpos = -1;
			i = arglen;
			while (i >= 0) 
			{
				if (arg.charCodeAt(i) != 32 &&
					!isNaN(arg.charCodeAt(i))) 
				{
					lastpos = i;
					break;
				}
				i--;
			}
		}

		if (func == "left") 
		{
			trimvalue = arg.substring(pos,arglen-1);
		}

		if (func == "right") 
		{
			trimvalue = arg.substring(0,lastpos+1);
		}

		if (func == "both") 
		{
			trimvalue = arg.substring(pos,lastpos + 1);
		}
	return trimvalue;
	}


//==============================================================================================
//Used for deleting a Array element in pagination
	function gfnDeleteElement(array,ElementPostion) 
	{
		size = array.length;
		delindex = ElementPostion; 
		validNo = (delindex != "NaN");
		inRange = ( (delindex >= 0) && (delindex <= array.length) );
		if (validNo && inRange) 
		{
			for (var i=0; i<=size; i++)
			array[i] = ((i == delindex) ? "delete" : array[i]);
			for (var j=delindex; j<size-1; j++)
			if (j != size) array[j] = array[j+1];
			array.length = size-1;
		}
	}


//To check that the Start Date and End Date must be greater then or equal to Current Date
	function gfnIsFromGtCurrent(pobjControl1,pobjControl2,pstrCaption1,pstrCaption2)
	{
	  	frcharday 	= pobjControl1.value.charAt(0)+pobjControl1.value.charAt(1)
		frcharmonth = pobjControl1.value.charAt(3)+pobjControl1.value.charAt(4)
		frcharyear 	= pobjControl1.value.charAt(6)+ pobjControl1.value.charAt(7) + pobjControl1.value.charAt(8)+pobjControl1.value.charAt(9)
		tocharday 	= pobjControl2.value.charAt(0)+pobjControl2.value.charAt(1)
		tocharmonth = pobjControl2.value.charAt(3)+pobjControl2.value.charAt(4)
		tocharyear 	= pobjControl2.value.charAt(6)+ pobjControl2.value.charAt(7) + pobjControl2.value.charAt(8)+pobjControl2.value.charAt(9)
		frday 		= parseInt(frcharday,10)
		frmonth 	= parseInt(frcharmonth,10)
		fryear 		= parseInt(frcharyear,10)
		today 		= parseInt(tocharday,10)
		tomonth 	= parseInt(tocharmonth,10)
		toyear 		= parseInt(tocharyear,10)
				
		if (fryear > toyear)
		{
			gfnShowError(506,pstrCaption1,pstrCaption2);
			pobjControl1.focus()
			return false;
	        }
	    	if (toyear == fryear)
		{
				 
			if (frmonth > tomonth)
		      	{
				gfnShowError(507,pstrCaption1,pstrCaption2);
				pobjControl1.focus()
				return false;
		      	}	
		     	if  (frmonth == tomonth)
		      	{
		        	if (frday > today)
		        	{		
					gfnShowError(506,pstrCaption1,pstrCaption2);
					pobjControl1.focus()
					return false;
		        	} 
	          	}    
	      	}
	}



	//Format Number to show number in 999.99 format
	//Parameter passed is document.formName.controlName
	function gfnFormatNumber(Element) 
	{
		lstrDecimalPlace=Element.value.indexOf(".",0); 
		if (lstrDecimalPlace==-1) 
		{ 
		Element.value=Element.value+".00"; 
		} 
		else
		{ 
			if (Element.value.substr(lstrDecimalPlace).length==2)
			{ 
			Element.value=Element.value+.0;
			}
			else 
			{ 
			Element.value=Element.value; 
			} 
		}

	}


	//Removes the , from the the number given 
	function gfnRemoveComma(pintNumber)
	{
		var lstrFinalValue="";
		for(var lintCount=0;lintCount<pintNumber.length;lintCount++)
		{
			
			if (pintNumber.charAt(lintCount)==",")
			{
			}
			else
			{
				lstrFinalValue=lstrFinalValue+pintNumber.charAt(lintCount);
			}		
		}
		return lstrFinalValue;
	}
	
	
	
// function for validating email
function mfnvalidEmail(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,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 
	{
		gfnShowError(508,"email id");
		pobjEmailId.focus();
		return false;
	}
}


function gfnCheckDecimal(pobjControl, pintDecimals, pstrName) 
{ 
	// check that only two digit after decimal is entered 
	var ldblNumvalue = pobjControl.value; 
	var ldblNumdecimals = ldblNumvalue.split('.'); 
	if(ldblNumdecimals.length ==2) 
	{ 
		if (ldblNumdecimals[1].length > pintDecimals) 
		{ 
			gfnShowError(1047, pstrName, pintDecimals); 
			pobjControl.focus(); 
			return false; 
		} 
	}
	return true; 
} 
// function for validating email
function mfnvalidEmail1(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=="")
	{return true;}

	linta = pobjEmailId.lastIndexOf("@");
	lintb = pobjEmailId.lastIndexOf(".");
	lintc = pobjEmailId.indexOf(":");
	lintd = pobjEmailId.indexOf("/");
	lstre = pobjEmailId.substring(0,linta);
	lintf = lstre.indexOf("@");
	lstrg = pobjEmailId.substring(linta+1,pobjEmailId.length);
	linth = lstrg.indexOf("[");
	linti = lstrg.indexOf("]");
	lintj = lstrg.indexOf("<");
	lintk = lstrg.indexOf(">");
	lstrl = pobjEmailId.substring(linta,lintb);
	lstrm = pobjEmailId.substring(lintb+1,pobjEmailId.length);
	lstrn = pobjEmailId.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.length)) 
		{lintVaidEmail++};		

	if (lintVaidEmail == 0) 
	{
	    return true;
	}
	else 
	{
		//gfnShowError(508,"E Mail ID");
		//pobjEmailId.focus();
		return false;
	}
}

function KeyPressed()
{
	if(event.keyCode==46)
		return false;
	if((event.keyCode<48) || (event.keyCode>57))
	{
		window.event.returnValue = false;
	}
}
function CheckQuoteString(obj)
{
	if((obj.value.indexOf("'") > -1) || (obj.value.indexOf('"') > -1))
	{
		alert("Can't contain Single Or Double Quotes");
		obj.focus();
		obj.select();
		return false;
	}
	if(obj.value.length>255)
	{
		alert('Please Specify less than 255 Character');
		obj.focus();
		return false;
	}
}
function getDuplicateCount(str1, str2)
{
	var arrSplit=str1.split(str2)
	var iSNCount=0;
	for(i=0;i<arrSplit.length;i++)
	{
		iSNCount++;
	}
	return iSNCount-1;
}
function checkLen(obj, thisLen, caption)
{
	if(parseFloat(obj.value.length)>parseFloat(thisLen))
	{
		alert(caption + ' can not be greater than ' + parseFloat(thisLen) + ' chars');
		obj.focus();
		return false;
	}
	return true;
}
function returnFormatValue(iValue)
{
	var result   = iValue.toString();
	var dot      = result.indexOf('.');
	if(dot==-1)
	{
		if(!isNaN(result))
		{
			result = result + '.00';
		}
		else
		{
			result = '0.00';
		}
	}
	else
	{
		var rightChars = (result.substr(dot+1, result.length-dot).substr(0, 2));
		var leftChars  = result.substr(0, dot);
		
		if(isNaN(leftChars))
			leftChars=0;
		
		if(isNaN(rightChars))
			rightChars=0;
				
		result = leftChars.toString() + '.' + rightChars.toString();
	}
	return result;
}
function Round(iValue,iDec)
{
	var result   = iValue.toString();
	var dot      = result.indexOf('.');
	var strTemp  = '';
	for(var i=0;i<iDec;i++)
		strTemp+='0';

	if(dot==-1)
	{
		if(!isNaN(result)){
			result = result + '.' + strTemp;
		}
		else{
			result = '0.' + strTemp;
		}
	}
	else
	{
		var rightChars = (result.substr(dot+1, result.length-dot).substr(0, iDec));
		var leftChars  = result.substr(0, dot);
		
		if(isNaN(leftChars))
			leftChars=0;
		
		if(isNaN(rightChars))
			rightChars=0;
		
		var iRightRoundedValue=0;		
		
		rightChars=getRoundedValue(rightChars);
		if(parseInt(rightChars)>=50)
		{
			rightChars=0;
			leftChars++;
		}
			
		result = leftChars.toString() +  '.' + rightChars.toString();
	}
	return result;
}
function getRoundedValue(value)
{
	if(value.toString().length>1)
	{
		var iTemp = Math.round('.'+value.toString().substr(value.toString().length-1,1)); 
		var strLeft = value.toString().substr(0,value.toString().length-1);
		
		return parseFloat(strLeft)+parseFloat(iTemp)+'0';
	}
	else
	{
		return Math.round(value);
	}
}
/*
------------- A.M.A.R --------------
			Project KDC
	Aug.02,2003 Saturday 10:46 PM
   --------------------------------
*/
function ResizeGridToFit(spID){
	window.setTimeout("window.parent.window." + spID + ".style.height = document.body.scrollHeight.toString() + 'px';window.location.hash='SearchResults';",100)}

function MakeSQLAvailable(objID,frmID){
	var obj = document.all.item(objID);
	if(InvalidSQL(obj)){
		obj.value = FetchSQL(obj.id);
		doPostBack(frmID);}}
function FetchSQL(objID){
	return window.parent.document.all.item(objID).value;}
function doPostBack(frmID){
	document.all.item(frmID).submit();}
function InvalidSQL(obj){
	return (obj.value=='')}
	
function AddToParent(formID, objID, TextFld, ValueFld)
{
	var objElement			= window.document.createElement('OPTION');
	var objDest				= eval("window.document." + objID + ";");
	var arr					= objID.toString().split['.'];

	objElement.value		= ValueFld;
	objElement.text			= TextFld;
	objDest.add(objElement)
	objDest.selectedIndex	= objDest.length-1;
			
	//window.close();
}

function AddAnotherOption(FileName, ControlID, Height, Width)
{
	var objPopup = window.open(FileName + '?objID=' + ControlID,'objPopup','status=yes,toolbars=no,scrollbars=no,height=' + Height + ',width=' + Width );
}
function ResetPostedOption()
{
	document.all.item('PostedOption.value')='';
	return true;
}
function Lookup(FileName, TxtID, HidID, Height, Width)
{
	var objLookup = window.open(FileName + '?txtID=' + TxtID + '&hidID=' + HidID,'objLookup','status=yes,toolbars=no,scrollbars=no,height=' + Height + ',width=' + Width );
}
function Select(txtID, hidID, stext, svalue)
{
	if(Trim(txtID)!=''){
		eval("window.parent.window.opener.window." + txtID + ".value = '" + stext + "';");
	}
	
	if(Trim(hidID)!=''){
		eval("window.parent.window.opener.window." + hidID + ".value = '" + svalue + "';");
	}
	
	window.parent.window.close();
}
function OpenNewWindow(FileName, Height, Width, scrollBar,windowName)
{
	var sScrollStyle = (scrollBar)?'scrollbars=yes':'scrollbars=no';
	var sWindName    = (windowName=='')?'objNewWin':windowName;
	eval("var " + sWindName + ";");
	var WindowObj = eval(sWindName);
	WindowObj     = window.open(FileName,sWindName,'status=yes,toolbars=no,resizable=yes,' + sScrollStyle + ',height=' + Height + ',width=' + Width);
}
function OpenReport(ReportURL, Height, Width, scrollBar, windowName)
{
	var sScrollStyle = (scrollBar)?'scrollbars=yes':'scrollbars=no';
	var sWindName    = (windowName=='')?'objNewWin':windowName;
	eval("var " + sWindName + ";");
	var WindowObj = eval(sWindName);
	WindowObj     = window.open(ReportURL,sWindName,'menubar=yes, status=yes,toolbars=no, resizable=yes,' + sScrollStyle + ',height=' + Height + ',width=' + Width);
}
function ValidateLength(obj, length)
{
	if(obj.value.length>=length){obj.value = obj.value.toString().substr(0,length);}
}
function AddMoreStyles()
{
	if(__RECAP)
		OpenNewWindow('Style_Search_Popup.aspx?Option=AddToCart&Recap=Y',400,600,true);
	else
	{
		if(__ProjectionID!=''){
			OpenNewWindow('Style_Search_Popup.aspx?Option=AddToCart&ProjectionID='+__ProjectionID,400,600,true);
		}
		else{
			OpenNewWindow('Style_Search_Popup.aspx?Option=AddToCart',400,600,true);
		}
	}
}

function PatternHistory(PatternID, NewWindow)
{
	if(NewWindow)
		OpenNewWindow('Pattern_History.aspx?PatternID=' + PatternID + '&Close=Y',500,700,true);
	else
	{
		window.location.href='Pattern_History.aspx?PatternID=' + PatternID + '&Close=N';
	}
}

function ShowCustomCalendar(objid)
{
	var WindowObj = window.open('Calendar.aspx?objid=' + objid,'','status=no,toolbars=no,scrollbars=no,height=130,width=200');
}

function AlignCenter(Object, height, width)
{
	windowX = (screen.availWidth -width)/2;
	windowY = (screen.availHeight -height)/2;
	Object.moveTo(windowX, windowY)
}