/**** 
function for removing blank spaces from the value of text boxes
this function is required when a user just gives space bar as value in a text box.
*****************/
function RemoveBlanks(txtValueInput)	
{
	txtValueOutput = new String("")
	for (i=0; i < txtValueInput.length; i++)
	{
		if (txtValueInput.charAt(i) != " ")
		{
			txtValueOutput = txtValueOutput.concat(txtValueInput.charAt(i))
		}
	}
	return (txtValueOutput)	// ******* returns the string without any blank space

}
/*********function ends here ***********/


function NumValidateDecimal(obj)
{		
	if((window.event.keyCode>=48 && window.event.keyCode<=57)|| window.event.keyCode==46 )
	{
		
		if(window.event.keyCode==46)
		{
			var strVal=String(obj.value);
			var myRegExp=/\./;
			var resIndex=strVal.search(myRegExp);

			if(resIndex!=-1)
				return false;
		}
		
		if(window.event.keyCode==45)
		{
			var strVal=String(obj.value);
			var myRegExp=/\-/;
			var resIndex=strVal.search(myRegExp);

			if(resIndex==-1)
				obj.value="-"+obj.value;

			return false;
		}
			
	}
	else
		return false;
}


/**** function for validating the inout for a number only****/
function validateNumber(strValue)	
{
	strValueTest = RemoveBlanks(strValue);	//removes blank spaces first
	
	/********this condition checks if the value is a number, not blank and 
	does not contain letter e. Letter e is for power function, 
	hence it becomes a valid number********/
		
	if (isNaN(strValue)||isNaN(strValueTest)||strValueTest==""||strValueTest.indexOf("e")!=-1||strValueTest.indexOf("E")!=-1)
		return false;
	else
		return true;
	
}

/*********function ends here*****/


/***function to be used in advance search forms***/
/*********
function to fill the Operator Combo. str, int and dat have been concatinated with the values
of the options fields combo. Based on the data type the combo of Operator tyep has to be filled.
the following function reads the first 3 characters of the value selected in the fields combo amd
accordingly fills the values in the corresponding Operator combo
**********/
function fillOperatorCombo(strSelectedFieldValue, strcboOperator)

{
	// following are the values to be filled in the Operator combo
	var stroption0 = new Option("Equal To","0");
	var stroption1 = new Option("Contains","1");
	var stroption2 = new Option("Starts With","2");
	var stroption3 = new Option("Ends With","3");
	var stroption4 = new Option("Sounds Like","4");
	var stroption5 = new Option("Regular Exp.","5");
	var stroption6 = new Option("Does Not Contain","18");
	var stroption7 = new Option("Does Not Start With","19");
	var stroption8 = new Option("Does Not End With","20");
	var stroption9 = new Option("Greater Than","6");
	var stroption10 = new Option("Less Than","7");
	var stroption11 = new Option("Not Equal To","8");
	var stroption12 = new Option("Is Null","9");
	var stroption13 = new Option("Is Not Null","10");
	
	
	
	/**************************/
	
	var strSelectedField;//stores the value selected in the fields combo
	var strDataType;// stores the value of data type of the selected field value
	
	strSelectedField = new String(strSelectedFieldValue);
	strDataType = strSelectedField.slice(0,3);	// returns the first 3 charcters from the value of fields selected.
	strDataType = strDataType.toUpperCase();
	
	if (strDataType=="STR" || strDataType=="TEX")	// if the data type is string
	{
		if(strcboOperator.length)// this will remove the existing values from the Operator combo.
			strcboOperator.length="";
		for(intX=0;intX<=13;intX++)// only first 5 options will be filled...
  		{	
  			strcboOperator.options[intX] = eval("stroption"+intX);
  		}
  			
  	}
  	
  	else if (strDataType=="INT" || strDataType=="DAT" || strDataType=="CUR" || strDataType=="LON" || strDataType=="DEC")	// if the data type is int or date
  	{
  		if(strcboOperator.length)// this will remove the existing values from the Operator combo.
			strcboOperator.length="";
		/*** only three options are valid for interger and date types***/
		strcboOperator.options[0] = eval(stroption0);
		strcboOperator.options[1] = eval(stroption9);
		strcboOperator.options[2] = eval(stroption10);
		strcboOperator.options[3] = eval(stroption11);
  		strcboOperator.options[4] = eval(stroption12);
  		strcboOperator.options[5] = eval(stroption13);
  		if(strDataType=="DAT")
  			strcboOperator.options[6] = Option("Day Month Year","15");
   	}
  	
  	else
  	{
  		strcboOperator.length ="";	// this will remove the existing values from the Operator combo.
	}
	
}

/****function ends here ***/

/***Function AddOperatorCombo to be used in advance search(Contact_profile_info.asp/company_profile_info.asp/portfolio_info.asp) forms***/
//Function will be called from the above mentioned pages for adding two fields
//Is Assigned and Is Not Assigned

function AddOperatorCombo(strcboOperator)
{
	
	var intIndex = parseInt(strcboOperator.length);
	var strAdditionalOption0 = new Option("Is Assigned","16");
	var strAdditionalOption1 = new Option("Is Not Assigned","17");
	for(intX=0;intX <= 1 ;intX++)
	{ 
		strcboOperator.options[intIndex]=eval("strAdditionalOption"+intX);
		intIndex++;
	}
}


/******Function AddOperatorCombo Ends here *************/





// following function checks for blank spaces in the bgining and in the end of the string and Trims the string.

function TrimString(str)
{
	var stringInput = new String(str)	//variable to store input string 
	startPosition=0;	//variable to store the postion where the first Non Blank character comes
	stringLength = stringInput.length;	//stores string length
	endPosition = stringLength-1;			//stores the position where the last non blank character comes
		
	while(startPosition<stringLength)	//starts finding first non blank character from begining of the string
	{
		if(stringInput.substr(startPosition,1)!=' ' && stringInput.charCodeAt(startPosition)!=13 && stringInput.charCodeAt(startPosition)!=10)	
		{
			break;
		}
		startPosition=startPosition+1;	//if non blank character is found then the position is stored and loop breaks
	}
		
		
	while(endPosition>=startPosition)
	{
		if(stringInput.substr(endPosition,1)!=' ' && stringInput.charCodeAt(endPosition)!=13 && stringInput.charCodeAt(endPosition)!=10)
		{
			break;
		}
		endPosition=endPosition-1;
	}
	var stringReturn = stringInput.substring(startPosition,endPosition+1);	//gets the string between 2 postions
	
	return stringReturn;
}
	
/***
Function to split full name into Last Name, Middle Name, First name. function will 
return an array of 3 elements. the first element will contain the Last Name,second element 
will contain the First Name and the Last element will contain the Middle Name.
***/
function splitName(inputFullName)
{
	var arrSplitName;	// array to store splitted values on "," or " "
	var arrReturnName = new Array;	// array to store the Last Name, First Name and Middle Name
	var txtFullName = new String;	//string to store values of Full Name passed as argument after 
									//removing 2 or more continuous blank spaces if exist in the input string 
									//this is required as split on " " will result to an anwanted element in the array
	var intX;	// variable to handle for loop
	
	for(intX=0 ;intX<inputFullName.length ; intX++ )
	{
		if(inputFullName.charAt(intX)==" ")	//checks for blank space
		{
			if(intX == 0)
			continue;	//if there is a blank at the first position then move to next element
			else if(inputFullName.charAt(intX)==inputFullName.charAt(intX-1))	
			// checks if there are 2 continuous blank spaces
			{
				continue;
			}
			
			else
			{
				txtFullName = txtFullName.concat(inputFullName.charAt(intX));	
				// concats the blank space
			}
		}
		else
		{
			txtFullName = txtFullName.concat(inputFullName.charAt(intX));
			// concats the character other than blank space
		}
	
	}
	
	if(txtFullName.indexOf(",")!="-1")	// checks if there is "," in the string then the splitting will be done on the basis of ","
	{
		arrSplitName = txtFullName.split(",");
		if (arrSplitName.length == 0 || arrSplitName.length == 1)	// if there is only one element then it is assigned as Last Name
			{
				arrReturnName[0] = TrimString(arrSplitName[0]);	//assigning as last name.
				arrReturnName[1] = "";	// assigning first and last name as blank
				arrReturnName[2] = "";
			}
			else if (arrSplitName.length == 2)	// if there are 2 elements then the first element is Last Name and second element is First Name
			{
				arrReturnName[0] = TrimString(arrSplitName[0]);
				arrReturnName[1] = TrimString(arrSplitName[1]);
				arrReturnName[2] = "";
			}
			else if (arrSplitName.length == 3)	// if there are 3 elements then the first elment if Last Name, second element is First Name, and the third element is Middle Name
			{
				arrReturnName[0] = TrimString(arrSplitName[0]);
				arrReturnName[1] = TrimString(arrSplitName[1]);
				arrReturnName[2] = TrimString(arrSplitName[2]);
			}
				
	}
	else
	{
		arrSplitName = txtFullName.split(" ");	// if there is no "," then splitting will be done on  " "
		if (arrSplitName.length == 0 || arrSplitName.length == 1) // if there is only one element then it is assigned as Last Name
			{
				arrReturnName[0] = TrimString(arrSplitName[0]);
				arrReturnName[1] = "";
				arrReturnName[2] = "";
			}
			else if (arrSplitName.length == 2)	// if there are 2 elements then the first element is First Name and the second element is Last Name
			{
				arrReturnName[0] = TrimString(arrSplitName[1]);
				arrReturnName[1] = TrimString(arrSplitName[0]);
				arrReturnName[2] = "";
			}
			else if (arrSplitName.length == 3)	// if there are 2 elements then the first element is First Name, second element is Middle Name and the third element is Last Name
			{
				arrReturnName[0] = TrimString(arrSplitName[2]);
				arrReturnName[1] = TrimString(arrSplitName[0]);
				arrReturnName[2] = TrimString(arrSplitName[1]);
			}
				
	}
	
	return arrReturnName;	// retuns array of splitted Full Name
}



///////////////////////////////////////////////////////////////
//Date Time Functions
//////////////////////////

var DateDiffCountGlobal=0; //global variable stores Start nad End date difference.
var vFormat=""; //global variable stores Date format

/*
Following function compares Date & TIME depending on the KEY pressed.
*/
function Return_Date_Compare(objStart_Date,objEnd_Date,objWithCursor_Time,objOther_Time,val)
{
	var D_Cursor;
	var D_Other;
	
	if(objStart_Date.value!='')
	{
		if((Date.parse(new Date(GetStandardDate(objStart_Date.value)))==Date.parse(new Date(GetStandardDate(objEnd_Date.value)))))
		{
			D_Cursor=new Date(GetStandardDate(objStart_Date.value)+" "+objWithCursor_Time.value);
			D_Other=new Date(GetStandardDate(objEnd_Date.value)+" "+objOther_Time.value);
			
			switch(val)
			{
				case 1:
					if(D_Cursor > D_Other)
						objOther_Time.value=objWithCursor_Time.value;
					break;
				case 2:
					if(D_Cursor < D_Other)
						objOther_Time.value=objWithCursor_Time.value;
					break;
			}					
		}
	}
	else
		objOther_Time.value=objWithCursor_Time.value;
		
}





//////////////////////////////////////////////////////////////


/*
Following function sets TIME to the controls(START & END) depending on the KEY pressed.

*/

function SetTime(objStartTime,objEndTime,objStart_Date,objEnd_Date,val,strDateFormat)
{	vFormat=strDateFormat;
	var strDate=new Date();
	var strTime=""; // stores TIME string
	var objWithCursor;
	var objOther;
	var tempMin;

	if(val==1) // if focus on START DATE control
	{	
		objWithCursor=objStartTime; //assign reference of ACTIVE(START DATE) element object
		objOther=objEndTime;
	}
	else // if focus on END DATE control
	{
		objWithCursor=objEndTime; //assign reference of ACTIVE(END DATE) element object
		objOther=objStartTime;
	}	
	
	var strTemp=new String(objWithCursor.value) // stores temporary string
	var arr=strTemp.split(":") //Array stores HH,MM,SS
	var objValue=objWithCursor.value; //stores reference of Active(control with Focus) Element 
	var temp;

	switch(window.event.keyCode)
	{
		case 9: // TAB Key
		case 65: // A Key
		case 80: // P Key
		case 109:	// - Key
		case 189:
		case 107: // + Key
		case 187:
		case 78: // N/n Key
		case 186: // : Key
		case 36: // HOME Key
		case 35: // END Key

			break;
		default: 
			if(!((window.event.keyCode>=48 && window.event.keyCode<=57)||(window.event.keyCode>=96 && window.event.keyCode<=105)))
				return false;

	}
	
	switch(window.event.keyCode)
	{
		case 9: return true; // TAB KEY
		case 46://Delete
		case 8:	//Backspace
			break;

		case 65: // A Key
			if(objWithCursor.value!="")
			{
				if(strTemp.search(":")==-1)
					strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())
				else
				{
					temp=arr[1].split(" ");

					if(temp[1]=="AM")
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" PM";
					else
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" AM";
				}	
				objWithCursor.value=strTime;
			}
			return false
			break;
		
		case 80: // P Key
			if(objWithCursor.value!="")
			{
				if(strTemp.search(":")==-1)
					strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())
				else
				{
					temp=arr[1].split(" ");

					if(temp[1]=="PM")
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" AM";
					else
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" PM";
				}	
				objWithCursor.value=strTime;
			}
			return false
			break;
				
		case 109:	// - Key
		case 189:
		// If Active control is BLANK then assign current DATE 
			if(strTemp.search(":")==-1)
				objValue=new Date();
			else
			{	
				if(objValue=="")	
					objValue=new Date();
				else // construct DATE with Control values
				{	temp=arr[1].split(" ");
					if(temp[1]=="PM")
						arr[0]=((arr[0]<12) ? arr[0]-12 :arr[0])
					else
						arr[0]=((arr[0]==12) ? arr[0]-12 :arr[0])
						
					objValue=new Date(strDate.getYear(),strDate.getMonth(),strDate.getDay(),arr[0],temp[0]);
					
					if(isNaN(objValue))
						objValue=new Date();
				}
			}

		// construct NEW DATE after subtracting 15 minutes		
			tempMin=objValue.getMinutes()%15;
			if(tempMin==0)
				strDate=new Date(Date.parse(objValue)-(15*60*1000));
			else
				strDate=new Date(Date.parse(objValue)-(tempMin*60*1000));
		
		// Extract TIME from newly constructed DATE object
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		// Assign TIME to Active Element			
			objWithCursor.value=strTime;
			
			Return_Date_Compare(objStart_Date,objEnd_Date,objWithCursor,objOther,val)			

		// If both (START & END) Time controls are blank 
		//then assign current TIME to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			if(objOther.value=="")
				objOther.value=strTime;

			
			return false;
			break;
			
		case 107: // + Key
		case 187:
			if(strTemp.search(":")==-1)
				objValue=new Date();
			else
			{	
				if(objValue=="")
					objValue=new Date() ;
				else // construct DATE with Control values
				{	temp=arr[1].split(" ");
					if(temp[1]=="PM")
						arr[0]=((arr[0]<12) ? arr[0]-12 :arr[0])
					else
						arr[0]=((arr[0]==12) ? arr[0]-12 :arr[0])
												
					objValue=new Date(strDate.getYear(),strDate.getMonth(),strDate.getDay(),arr[0],temp[0]);
				}
			}
		// construct NEW DATE after ADDING 15 minutes		
			tempMin=objValue.getMinutes()%15;
			if(tempMin==0)
				strDate=new Date(Date.parse(objValue)+(15*60*1000));
			else
				strDate=new Date(Date.parse(objValue)+((15-tempMin)*60*1000));

		// Extract TIME from newly constructed DATE object
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		// Assign TIME to Active Element			
			objWithCursor.value=strTime;
	
			Return_Date_Compare(objStart_Date,objEnd_Date,objWithCursor,objOther,val)			

		// If both (START & END) Time controls are blank 
		//then assign current TIME to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			if(objOther.value=="")
				objOther.value=strTime;
			
			return false;
			break;
			
		case 78: // N/n Key
		// Stores CURRENT TIME 
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		//Assign current TIME to both(START & END) TIME controls
			//if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			//if(objOther.value=="")
				objOther.value=strTime;
			return false;
			break;
		
		default: //return false;
		
	}

}
/*
Following function DELETES values from control
if user DELETES value from one of the controls(START & END).
*/
function check(objWithCursor,objOther)
{
	switch(window.event.keyCode)
	{
			
		case 46:	//Delete
		case 8:
		//Following lines DELETES values from both the controls
		//Only if one of them is blank.
			objOther.value="";
			objWithCursor.value="";
				
			break;
			
		default: return false;
	}	
}

/*
Following function Sets ALARM TIME to Alarm Time control.
*/
function SetAlarmTime(objAlarmDate,objAlarmTime,strDateFormat)
{	vFormat=strDateFormat;
	var strDate=new Date();
	var strTime="";  // stores TIME string
	var strTemp=new String(objAlarmTime.value) // stores temporary string
	var arr=strTemp.split(":") //Array stores HH,MM,SS
	var objValue=objAlarmTime.value; //stores reference of Active(control with Focus) Element 
	var temp;
	var tempMin;

	switch(window.event.keyCode)
	{
		case 9: // TAB Key
			return true;
			break;
		case 65: // A Key
		case 80: // P Key
		case 109:	// - Key
		case 189:
		case 107: // + Key
		case 187:
		case 84: //t key
		case 78: // N/n Key
		case 186: // : Key
				if(objAlarmDate.value=="")
					objAlarmDate.value=SetDateFormat(strDate);
			break;		
		case 36: // HOME Key
		case 35: // END Key

			break;
		default: 
			if(!((window.event.keyCode>=48 && window.event.keyCode<=57)||(window.event.keyCode>=96 && window.event.keyCode<=105)))
				return false;
			else
			{
				// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
				if(objAlarmDate.value=="")
					objAlarmDate.value=SetDateFormat(strDate);
			}
	}
		
	switch(window.event.keyCode)
	{
		case 9: return true; // TAB KEY
		case 46:	//Delete
		case 8:
			break;


		case 65: // A Key
			
			if(objAlarmTime.value=="")
				objAlarmTime.value=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())

			else
			{
				if(strTemp.search(":")==-1)
					strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())
				else
				{
					temp=arr[1].split(" ");

					if(temp[1]=="AM")
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" PM";
					else
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" AM";
				}	
				objAlarmTime.value=strTime;
			}
			return false
			break;
		
		case 80: // P Key
			
			if(objAlarmTime.value=="")
				objAlarmTime.value=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())

			else
			{
				if(strTemp.search(":")==-1)
					strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes())
				else
				{
					temp=arr[1].split(" ");

					if(temp[1]=="PM")
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" AM";
					else
						strTime=(arr[0]=="" ?(parseInt(strDate.getHours()) >12 ? parseInt(strDate.getHours())-12 :strDate.getHours()):arr[0])+":"+(temp[0]=="" ? strDate.getMinutes():temp[0])+" PM";
				}	
				objAlarmTime.value=strTime;
			}
			return false
			break;
				
		case 109:
		case 189:
			if(strTemp.search(":")==-1)
				objValue=new Date();
			else
			{	
		
				var D_Cursor=new Date(GetStandardDate(objAlarmDate.value)+" "+objAlarmTime.value);
				if(D_Cursor < new Date())
					return false;
		
			// If Active control is BLANK then assign current DATE 
				if(objValue=="")
					objValue=new Date();
				else // construct DATE with Control values
				{	temp=arr[1].split(" ");
					if(temp[1]=="PM")
						arr[0]=((arr[0]<12) ? arr[0]-12 :arr[0])
					else
						arr[0]=((arr[0]==12) ? arr[0]-12 :arr[0])

					objValue=new Date(strDate.getYear(),strDate.getMonth(),strDate.getDay(),arr[0],temp[0]);
				}
		
				// construct NEW DATE after subtracting 15 minutes	
				tempMin=objValue.getMinutes()%15;
				if(tempMin==0)
				{	strDate=new Date(Date.parse(objValue)-(15*60*1000));
					D_Cursor=new Date(GetStandardDate(objAlarmDate.value)+" "+SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds()));
					if(D_Cursor < new Date())
						return false;
				}
				else
					strDate=new Date(Date.parse(objValue)-(tempMin*60*1000));
			}
		// Extract TIME from newly constructed DATE object
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		// Assign TIME to Active Element			
			objAlarmTime.value=strTime;
			
		// Following lines Checks whether ALARM DATE field is BLANK 
		// then CALL function 'SetAlarmDate' to set CURRENT DATE to ALARM DATE Control
			if(objAlarmDate.value=="")
				SetAlarmDate(objAlarmDate,objAlarmTime);

			return false;
			break;
			
		case 107: // + KEY
		case 187: // = KEY
			if(strTemp.search(":")==-1)
				objValue=new Date();
			else
			{	

				if(objValue=="")
					objValue=new Date() ;
				else // construct DATE with Control values
				{	temp=arr[1].split(" ");
					if(temp[1]=="PM")
						arr[0]=((arr[0]<12) ? arr[0]-12 :arr[0])
					else
						arr[0]=((arr[0]==12) ? arr[0]-12 :arr[0])

					objValue=new Date(strDate.getYear(),strDate.getMonth(),strDate.getDay(),arr[0],temp[0]);
				}
			}
		// construct NEW DATE after ADDING 15 minutes		
			tempMin=objValue.getMinutes()%15;
			if(tempMin==0)
				strDate=new Date(Date.parse(objValue)+(15*60*1000));
			else
				strDate=new Date(Date.parse(objValue)+((15-tempMin)*60*1000));
		
		// Extract TIME from newly constructed DATE object
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		// check if alarm Date/time is less than current time
		/*	var D_Cursor=new Date(GetStandardDate(objAlarmDate.value)+" "+strTime);
			if(D_Cursor < new Date())
				return false;
		*/

		// Assign TIME to Active Element			
			objAlarmTime.value=strTime;

		// Following lines Checks whether ALARM DATE field is BLANK 
		// then CALL function 'SetAlarmDate' to set CURRENT DATE to ALARM DATE Control
			if(objAlarmDate.value=="")
				SetAlarmDate(objAlarmDate,objAlarmTime);

			return false;
			break;
			
		case 78: // N/n KEY
		case 84: // T/t
		// Stores CURRENT TIME		
			strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

		//Assign current TIME to both(START & END) TIME controls
				objAlarmTime.value=strTime;
		// Following lines Checks whether ALARM DATE field is BLANK 
		// then CALL function 'SetAlarmDate' to set CURRENT DATE to ALARM DATE Control
			if(objAlarmDate.value=="")
				SetAlarmDate(objAlarmDate,objAlarmTime);

			return false;
			break;
			
		default: 	
		
			//return false;
	}


}

function SetAlarm_DefaultTime(objAlarmDate,objAlarmTime,strDateFormat)
{	vFormat=strDateFormat;
	var strDate=new Date();
	var strTime="";  // stores TIME string
	var strTemp=new String(objAlarmTime.value) // stores temporary string
	var arr=strTemp.split(":") //Array stores HH,MM,SS
	var objValue=objAlarmTime.value; //stores reference of Active(control with Focus) Element 


	strTime=SetTime_AM_PM(strDate.getHours(),strDate.getMinutes(),strDate.getSeconds());

	//Assign current TIME to both(START & END) TIME controls
		objAlarmTime.value=strTime;
	// Following lines Checks whether ALARM DATE field is BLANK 
	// then CALL function 'SetAlarmDate' to set CURRENT DATE to ALARM DATE Control
	if(objAlarmDate.value=="")
		SetAlarmDate(objAlarmDate,objAlarmTime);
}

//******* Function for checking the time in hh:mm am/pm format ********	
function chkTime(objTime)
{	
	if(objTime.value=="")
		return false;
	var strPat=/^(\d{1,2})(:)(\d{1,2})(\s)([a|A|p|P])([m|M])$/;
		
	var strVal=new String(objTime.value);
	var matchArray = strVal.match(strPat); 
	
	if(matchArray==null)
	{
		alert("Enter Time in 12 Hours (hh:mm AM/PM) format.");
		objTime.focus();
		return false;
	}
	var Hrs=parseInt(matchArray[1]);
	var Min=parseInt(matchArray[3]);
	if(Hrs > 12)
	{
		alert("Hours cannot be greater than 12.");
		objTime.focus();
		return false;
	}	
	else if(Min > 59)
	{
		alert("Minutes cannot be greater than or equal to 60.");
		objTime.focus();
		return false;
	}
		
	return true;
}
//***************************************************************************


/*
Following function sets TIME in AM/PM

*/
function SetTime_AM_PM(hours,minutes,seconds)
{
    var timeValue = "" + ((hours >12) ? hours -12 :hours);
    if(parseInt(timeValue)==0)
		timeValue="12"
    timeValue = ((parseInt(timeValue) < 10) ? "0" : "")+ parseInt(timeValue); 
    
    timeValue += ((parseInt(minutes) < 10) ? ":0" : ":") + parseInt(minutes);
    //timeValue += ((seconds < 10) ? ":0" : ":") + seconds

	timeValue += (hours >= 12) ? " PM" : " AM"
	
	return timeValue;	
}


/*
Following function SETS Alarm DATE to ALARM DATE control

*/
function SetAlarmDate(objAlarmDate,objAlarmTime,strDateFormat)
{	vFormat=strDateFormat;
	var objWithCursor=objAlarmDate; // Stores reference of Alarm Date control
	var objOther=objAlarmTime; // Stores reference of Alarm Time control
	var strDate=new Date(); // stores reference of DATE object
	var strTime=""; // stores TIME string
	var strTemp=new String(objWithCursor.value) // stores temporary string
	var objValue=objWithCursor.value; //stores reference of Active(control with Focus) Element 
				
	if(objValue=="")
		objValue=new Date();
	else
		objValue=GetMonth(strTemp); //Function 'GetMonth' returns DATE in STANDARD format 
									// using 'strTemp' as CONSTRUCTOR parameter 

	switch(window.event.keyCode)
	{
		case 9: return true; // TAB KEY
	
		case 46:	//Delete/Backspace
		case 8:
			break;

		case 109: // - KEY
		case 189: 
			var D_Cursor=new Date(GetStandardDate(objAlarmDate.value)+" "+objAlarmTime.value);
			
			if(D_Cursor < new Date())
				return false;

		// construct NEW DATE after subtracting 1 DAY	
			strDate=new Date(Date.parse(objValue)-86400000); //86400000=24*60*60*1000
			
			
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}
			return false;
			break;
			
		case 107: // + KEY
		case 187: // = KEY
		// construct NEW DATE after ADDING 1 DAY		
			strDate=new Date(Date.parse(objValue)+86400000);//86400000=24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;

		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;
		
		case 84: // T/t KEY
 		case 78: // N/n KEY
		
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// If DATE control is blank 
		//then assign current DATE to it
//++++++	//if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
//++++++		
			//if(objOther.value=="")
			if(objAlarmDate.name!="DueDate")
				SetAlarmTime(objWithCursor,objOther);

			return false;
			break;

		case 89: // Y/y KEY 
		// 'IsLeap' function checks for LEAP Year
			if (!IsLeap(objValue))  //if not LEAP year then subtract 1 Year(365 Days)
				strDate=new Date(Date.parse(objValue)-31536000000); // 31536000000=365*24*60*60*1000
			else //if not LEAP year then subtract 1 Year(366 Days)
				strDate=new Date(Date.parse(objValue)-31622400000); // 31536000000=366*24*60*60*1000
		
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

			var D_Cursor=new Date(GetStandardDate(strTime)+" "+objAlarmTime.value);
			if(D_Cursor < new Date())
				return false;

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;

		case 82: // R/r KEY
		// 'IsLeap' function checks for LEAP Year
			if (!IsLeap(objValue)) //if not LEAP year then ADD 1 Year(365 Days)
				strDate=new Date(Date.parse(objValue)+31536000000);// 31536000000=365*24*60*60*1000
			else  //if LEAP year then ADD 1 Year(366 Days)
				strDate=new Date(Date.parse(objValue)+31622400000);// 31622400000=366*24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;
			
		case 87: // W/w KEY
		// construct NEW DATE after Subtracting 1 WEEK		
			strDate=new Date(Date.parse(objValue)-604800000); //604800000=7*24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);
		
			var D_Cursor=new Date(GetStandardDate(strTime)+" "+objAlarmTime.value);
			if(D_Cursor < new Date())
				return false;
	
		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
			
		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;
		case 75: // K/k KEY
		// construct NEW DATE after Adding 1 WEEK		
			strDate=new Date(Date.parse(objValue)+604800000); //604800000=7*24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
			
		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}
	
			return false;
			break;
		case 77: // M/m KEY
			if(objValue.getMonth()==1) //IF month is FEB then check for LEAP Year
			{	// 'IsLeap' function checks for LEAP Year
				if (!IsLeap(objValue)) //If not LEAP year then Subtract 1 month(28 Days)
					strDate=new Date(Date.parse(objValue)-2419200000);//2419200000=28*24*60*60*1000
				else //If LEAP year then Subtract 1 month(29 Days)
					strDate=new Date(Date.parse(objValue)-2505600000);//2505600000=29*24*60*60*1000
			}
			else //if month other then FEB
			{
				switch(objValue.getMonth())
				{
					case 0:	// months of 31 DAYS
					case 2:	
					case 4:	
					case 6:	
					case 7:	
					case 9:	
					case 11: //Subtract 1 month(31 Days)
						strDate=new Date(Date.parse(objValue)-2678400000);//2678400000=31*24*60*60*1000
						break;
					case 3:	//months of 30 DAYS
					case 5:	
					case 8:	
					case 10://Subtract 1 month(30 Days)
						strDate=new Date(Date.parse(objValue)-2592000000);//2592000000=30*24*60*60*1000
						break;
				}
			}
			
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

			var D_Cursor=new Date(GetStandardDate(strTime)+" "+objAlarmTime.value);
			if(D_Cursor < new Date())
				return false;

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
			
		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;
		case 72: // H/h KEY
			if(objValue.getMonth()==1)//IF month is FEB then check for LEAP Year
			{ // 'IsLeap' function checks for LEAP Year
				if (!IsLeap(objValue)) //If not LEAP year then ADD 1 month(28 Days)
					strDate=new Date(Date.parse(objValue)+2419200000);//2419200000=28*24*60*60*1000
				else //If LEAP year then ADD 1 month(29 Days)
					strDate=new Date(Date.parse(objValue)+2505600000);//2505600000=29*24*60*60*1000
			}
			else //if month other then FEB
			{
				switch(objValue.getMonth())
				{
					case 0:	// months of 31 DAYS
					case 2:	
					case 4:	
					case 6:	
					case 7:	
					case 9:	
					case 11: // ADD 1 month(31 Days)
						strDate=new Date(Date.parse(objValue)+2678400000);//2678400000=31*24*60*60*1000
						break;
					case 3:	// months of 30 DAYS
					case 5:	
					case 8:	
					case 10: // ADD 1 month(30 Days)
						strDate=new Date(Date.parse(objValue)+2592000000);//2592000000=30*24*60*60*1000
						break;
				
				}
			}
			
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
			
		// If DATE control is blank 
		//then assign current DATE to it
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
				
		// Following lines Checks whether ALARM TIME field is BLANK 
		// then CALL function 'SetAlarmTime' to set CURRENT TIME to ALARM TIME Control
			if(objOther.value=="")
			{	if(objAlarmDate.name!="DueDate")
					SetAlarmTime(objWithCursor,objOther);
			}

			return false;
			break;

		default: 
			return false;
	}
}

/*
Following function sets DATE to START & END DATE controls
*/
function SetDate(objStartDate,objEndDate,val,strDateFormat)
{
	vFormat=strDateFormat;
	var objWithCursor=""; // stores reference of ACTIVE(Control with CURSOR) control
	var objOther=""; // stores reference of Other control(START/END)
	
	if(val==1) //if focus on START Date
	{
		objWithCursor=objStartDate; // assign reference of START DATE Control
		objOther=objEndDate; // assign reference of END DATE Control
	}
	else //if focus on END Date
	{
		objWithCursor=objEndDate;// assign reference of END DATE Control
		objOther=objStartDate;// assign reference of START DATE Control
	}
	
	var strDate=new Date(); // stores reference of DATE object
	var strTime=""; // stores Time string
	var strTemp=new String(objWithCursor.value)// Stores temporary String 
	var objValue=objWithCursor.value; // stores value of ACTIVE element
	var DateDiffCount=0; //stores start date and end date difference

	if(objValue=="") // if ACTIVE element is BLANK
		objValue=new Date();
	else
		objValue=GetMonth(strTemp);//Function 'GetMonth' returns DATE in STANDARD format 
									// using 'strTemp' as CONSTRUCTOR parameter 


	switch(window.event.keyCode)
	{
		case 9: return true; // TAB KEY
		case 46:	//Delete/Backspace
		case 8:
			break;

		case 109: // - KEY
		case 189:
		// construct NEW DATE after subtracting 1 DAY	
			strDate=new Date(Date.parse(objValue)-86400000);//86400000=24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);
		
		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
		
		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"-",86400000);

			
			return false;
			break;
			
		case 107: // + KEY
		case 187: // = KEY
		// construct NEW DATE after ADDING 1 DAY		
			strDate=new Date(Date.parse(objValue)+86400000);//86400000=24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"+",86400000);
			

			return false;
			break;
		
		case 84: // T/t KEY
		
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);
			
		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objStartDate.value!="")
				DateDiffCount=Date.parse(GetMonth(objEndDate.value))-Date.parse(GetMonth(objStartDate.value))

			objWithCursor.value=strTime;

			if(objOther.value=="")
				objOther.value=strTime;
			else					
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,objEndDate.value,"n",DateDiffCount);
			
			return false;
			break;

 
		case 89: // Y/y KEY

		// 'IsLeap' function checks for LEAP Year
			if (!IsLeap(objValue)) //if not LEAP year then subtract 1 Year(365 Days)
			{	strDate=new Date(Date.parse(objValue)-31536000000);// 31536000000=365*24*60*60*1000
				DateDiffCount=31536000000;
			}
			else //if LEAP year then subtract 1 Year(366 Days)
			{	strDate=new Date(Date.parse(objValue)-31622400000);// 31536000000=366*24*60*60*1000
				DateDiffCount=31622400000;
			}
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);
		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"-",DateDiffCount);
		
			
			return false;
			break;
			
		case 87: // W/w KEY

		// construct NEW DATE after Subtracting 1 WEEK		
			strDate=new Date(Date.parse(objValue)-604800000); //604800000=7*24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"-",604800000);
		
			return false;
			break;
		case 75: // K/k KEY
		// construct NEW DATE after Adding 1 WEEK		
			strDate=new Date(Date.parse(objValue)+604800000); //604800000=7*24*60*60*1000

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
		
		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"+",604800000);

			return false;
			break;
		case 77: // M/m KEY

			if(objValue.getMonth()==1)//IF month is FEB then check for LEAP Year
			{// 'IsLeap' function checks for LEAP Year
				if (!IsLeap(objValue)) //If not LEAP year then Subtract 1 month(28 Days)
				{	strDate=new Date(Date.parse(objValue)-2419200000);//2419200000=28*24*60*60*1000
					DateDiffCount=2419200000;
				}
				else //If LEAP year then Subtract 1 month(29 Days)
				{	strDate=new Date(Date.parse(objValue)-2505600000);//2505600000=29*24*60*60*1000
					DateDiffCount=2505600000;
				}				
			}
			else //if month other then FEB
			{
				switch(objValue.getMonth())
				{
					case 0:	// months of 31 DAYS
					case 2:	
					case 4:	
					case 6:	
					case 7:	
					case 9:	
					case 11://Subtract 1 month(31 Days)
						strDate=new Date(Date.parse(objValue)-2678400000);//2678400000=31*24*60*60*1000
						DateDiffCount=2678400000;
						break;
					case 3:	//months of 30 DAYS
					case 5:	
					case 8:	
					case 10://Subtract 1 month(30 Days)
						strDate=new Date(Date.parse(objValue)-2592000000);//2592000000=30*24*60*60*1000
						DateDiffCount=2592000000;
						break;
				
				}
			}
			
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
		
		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"-",DateDiffCount);

			return false;
			break;
		case 72: // H/h KEY
			if(objValue.getMonth()==1)//IF month is FEB then check for LEAP Year
			{// 'IsLeap' function checks for LEAP Year
				if (!IsLeap(objValue)) //If not LEAP year then ADD 1 month(28 Days)
				{	strDate=new Date(Date.parse(objValue)+2419200000);//2419200000=28*24*60*60*1000
					DateDiffCount=2419200000
				}
				else //If LEAP year then ADD 1 month(29 Days)
				{	strDate=new Date(Date.parse(objValue)+2505600000);//2505600000=29*24*60*60*1000
					DateDiffCount=2505600000
				}			
			}
			else //if month other then FEB
			{
				switch(objValue.getMonth())
				{
					case 0:	// months of 31 DAYS
					case 2:	
					case 4:	
					case 6:	
					case 7:	
					case 9:	
					case 11: // ADD 1 month(31 Days)
						strDate=new Date(Date.parse(objValue)+2678400000);//2678400000=31*24*60*60*1000
						DateDiffCount=2678400000
						break;
					case 3:	// months of 30 DAYS
					case 5:	
					case 8:	
					case 10: // ADD 1 month(30 Days)
						strDate=new Date(Date.parse(objValue)+2592000000);//2592000000=30*24*60*60*1000
						DateDiffCount=2592000000
						break;
				
				}
			}
			

		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);
	
		// Assign DATE to Active Element			
			objWithCursor.value=strTime;
		
		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"+",DateDiffCount);

			return false;
			break;
		case 82: // R/r KEY
		 	// 'IsLeap' function checks for LEAP Year
			if (!IsLeap(objValue))//if not LEAP year then ADD 1 Year(365 Days)
			{	strDate=new Date(Date.parse(objValue)+31536000000);// 31536000000=365*24*60*60*1000
				DateDiffCount=31536000000;
			}
			else //if LEAP year then ADD 1 Year(366 Days)
			{	strDate=new Date(Date.parse(objValue)+31622400000);// 31622400000=366*24*60*60*1000
				DateDiffCount=31622400000;
			}	
		// 'SetDateFormat' function sets format of DATE to "DD-MON-YYYY"
			strTime=SetDateFormat(strDate);

		// Assign DATE to Active Element			
			objWithCursor.value=strTime;

		// Following lines Checks whether STRAT/END DATE field is BLANK 
		// then set CURRENT DATE to both of them
			if(objWithCursor.value=="")
				objWithCursor.value=strTime;
			
			if(objOther.value=="")
				objOther.value=strTime;
			else
			// Following function compares START & END DATES
				Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,"+",DateDiffCount);
		
			return false;
			break;

		default: return false;
		
	}
}

///////////////////////////////////////////////////////////////////////

function Compare_Dates(objStartDate,objEndDate,val,strDate,strDateFormat)
{
	/*
		1)val - may have 1/2
			1 - focus on Start Date Control
			2 - focus on End Date Control

		2)strDate - DATE to be compared
	*/
	vFormat=strDateFormat;
	var objCompare="";
	var strTemp=new String(objStartDate.value)
	var objValue=GetMonth(strTemp);
	strDate=new Date(Date.parse(objValue));
	
	switch(val) // if focus on START DATE control
	{	
	case 1:	
		strTemp=new String(objStartDate.value)
		objValue=GetMonth(strTemp);
		strDate=new Date(Date.parse(objValue));
		//if(objStartDate.value!="")
		//	DateDiffCountGlobal=Date.parse(GetMonth(objEndDate.value))-Date.parse(GetMonth(objStartDate.value))

		objWithCursor=objStartDate; //assign reference of ACTIVE(START DATE) element object
		objCompare=objEndDate;	//assign reference of Other Object
		// Following line compares DATES 
		// If value of START Date exceeds the END Date then it will assign
		// value of START Date to END Date also.
		if(strDate > GetMonth(new String(objEndDate.value)))
			objCompare.value=objWithCursor.value;	
		
		if(objEndDate.value=="")
			objCompare.value=objWithCursor.value;

		if(DateDiffCountGlobal!=0)
			Compare_Start_End_Dates(objWithCursor,objEndDate,1,objEndDate.value,"n",DateDiffCountGlobal);
		
		break;		
	
	case 2: // if focus on END DATE control
		strTemp=new String(objEndDate.value)
		objValue=GetMonth(strTemp);
		strDate=new Date(Date.parse(objValue));
		
		objWithCursor=objEndDate; //assign reference of ACTIVE(END DATE) element object
		objCompare=objStartDate; //assign reference of Other Object
		
		// Following line compares DATES 
		// If value of END Date becomes less than the START Date then it will assign
		// value of END Date to START Date also.
		if(strDate < GetMonth(new String(objStartDate.value)))
			objCompare.value=objWithCursor.value;	
		
		if(objStartDate.value=="")
			objCompare.value=objWithCursor.value;
		
		break;	
	
	case 3:		
		if(new Date(GetStandardDate(objStartDate))> new Date(GetStandardDate(objEndDate)))
		{
			return false;
		}
	default : break; 	
	}
}

///////////////////////////////////////////////////////////////////////

function Compare_Alarm_Date(objAlarmDate,objAlarmTime,strDateFormat)
{	
	vFormat=strDateFormat;
	if(objAlarmDate.value!="")
	{	if(objAlarmDate.name!="DueDate")
		{	if(objAlarmTime.value=="")
				SetAlarm_DefaultTime(objAlarmDate,objAlarmTime);
		}		
	}
}		

/*
Following function Compares START & END DATES 
*/
function Compare_Start_End_Dates(objStartDate,objEndDate,val,strDate,Operator,DiffValue,strDateFormat)
{
	/*
		1)val - may have 1/2
			1 - focus on Start Date Control
			2 - focus on End Date Control

		2)strDate - DATE to be compared
	*/
	vFormat=strDateFormat;
	var objCompare="";
	var DateDiff=0;
	 
	if(val==1) // if focus on START DATE control
	{	
		objWithCursor=objStartDate; //assign reference of ACTIVE(START DATE) element object
		objCompare=objEndDate;	//assign reference of Other Object
		// Following line compares DATES 
		// If value of START Date exceeds the END Date then it will assign
		// value of START Date to END Date also.

		switch(Operator)
		{
			case "-":
				objCompare.value=SetDateFormat(new Date(Date.parse(GetMonth(new String(objEndDate.value)))-DiffValue));
				break;
			case "+":
				objCompare.value=SetDateFormat(new Date(Date.parse(GetMonth(new String(objEndDate.value)))+DiffValue));				
				break;
			case "n":
				objCompare.value=SetDateFormat(new Date(Date.parse(GetMonth(new String(objStartDate.value)))+DiffValue));				
				break;
					
			default: break;
		}
	}
	else // if focus on END DATE control
	{
		objWithCursor=objEndDate; //assign reference of ACTIVE(END DATE) element object
		objCompare=objStartDate; //assign reference of Other Object
		// Following line compares DATES 
		// If value of END Date becomes less than the START Date then it will assign
		// value of END Date to START Date also.
		if(strDate < GetMonth(new String(objStartDate.value)))
			objCompare.value=objWithCursor.value;	
	}
	//reset golbal variable
	DateDiffCountGlobal=0;
}

/*
Following function sets format of DATE to "DD-MON-YYYY"

*/
function SetDateFormat(strDate)
{	
	var strMonth="";

	switch(strDate.getMonth())
	{
		case 0:	strMonth="JAN";	break;
		case 1:	strMonth="FEB"; break;
		case 2:	strMonth="MAR"; break;
		case 3:	strMonth="APR"; break;
		case 4:	strMonth="MAY"; break;
		case 5:	strMonth="JUN";	break;
		case 6:	strMonth="JUL"; break;
		case 7:	strMonth="AUG"; break;
		case 8:	strMonth="SEP"; break;
		case 9:	strMonth="OCT"; break;
		case 10: strMonth="NOV"; break;
		case 11: strMonth="DEC"; break;
	}

	switch(new String(vFormat).toUpperCase())
	{
		case "DD-MON-YYYY":
			return strDate.getDate() + "-" + strMonth + "-" + strDate.getFullYear();
			break;
			
		case "DD/MM/YYYY":
			return strDate.getDate() + "/" + (parseInt(strDate.getMonth())+1) + "/" + strDate.getFullYear();
			break;
			
		case "MM/DD/YYYY":
			return (parseFloat(strDate.getMonth())+1) + "/" + strDate.getDate() + "/" + strDate.getFullYear();
			break;
			
		case "YYYY/MM/DD":
			return strDate.getFullYear() + "/" + (parseInt(strDate.getMonth())+1) + "/" + strDate.getDate();
			break;
			
		case "YYYY/DD/MM":
			return strDate.getFullYear() + "/" + strDate.getDate() + "/" + (parseInt(strDate.getMonth())+1);
			break;
			
		default :	
			return strDate.getDate() + "-" + strMonth + "-" + strDate.getFullYear();
	}		
}

/*
Following function sets DATE to Standard format.
*/
function GetMonth(strTemp)
{
	var strMonth=0;
	var arr=strTemp.split("-");
	switch(arr[1])
	{
		case "JAN":	strMonth=0;	break;
		case "FEB":	strMonth=1; break;
		case "MAR":	strMonth=2; break;
		case "APR":	strMonth=3; break;
		case "MAY":	strMonth=4; break;
		case "JUN":	strMonth=5;	break;
		case "JUL":	strMonth=6; break;
		case "AUG":	strMonth=7; break;
		case "SEP":	strMonth=8; break;
		case "OCT":	strMonth=9; break;
		case "NOV": strMonth=10; break;
		case "DEC": strMonth=11; break;
	}
	
	switch(new String(vFormat).toUpperCase())
	{
		case "DD-MON-YYYY":
			return new Date(arr[2],strMonth,arr[0]);
			break;
			
		case "DD/MM/YYYY":
			arr=strTemp.split("/");
			return new Date(arr[2],(parseInt(arr[1])-1),arr[0]);
			break;
		case "MM/DD/YYYY":
			arr=strTemp.split("/");
			return new Date(arr[2],(parseFloat(arr[0])-1),arr[1]);
			break;
		case "YYYY/MM/DD":
			arr=strTemp.split("/");
			return new Date(arr[0],(parseInt(arr[1])-1),arr[2]);
			break;
		case "YYYY/DD/MM":
			arr=strTemp.split("/");
			return new Date(arr[0],(parseInt(arr[2])-1),arr[1]);
			break;
			
		default :	
			return new Date(arr[2],strMonth,arr[0]);
	}		
	
}

/*
following function will return date in (yyyy/mm/dd) format
*/
function GetStandardDate(strTemp)
{
	var strMonth=0;
	var arr=strTemp.split("-");
	switch(arr[1])
	{
		case "JAN":	strMonth=0;	break;
		case "FEB":	strMonth=1; break;
		case "MAR":	strMonth=2; break;
		case "APR":	strMonth=3; break;
		case "MAY":	strMonth=4; break;
		case "JUN":	strMonth=5;	break;
		case "JUL":	strMonth=6; break;
		case "AUG":	strMonth=7; break;
		case "SEP":	strMonth=8; break;
		case "OCT":	strMonth=9; break;
		case "NOV": strMonth=10; break;
		case "DEC": strMonth=11; break;
	}
	
	switch(new String(vFormat).toUpperCase())
	{
		case "DD-MON-YYYY":
			return (arr[2]+"/"+(parseInt(strMonth)+1)+"/"+arr[0]);
			break;
			
		case "DD/MM/YYYY":
			arr=strTemp.split("/");
			return (arr[2]+"/"+arr[1]+"/"+arr[0]);
			break;
		case "MM/DD/YYYY":
			arr=strTemp.split("/");
			return (arr[2]+"/"+arr[0]+"/"+arr[1]);
			break;
		case "YYYY/MM/DD":
			arr=strTemp.split("/");
			return (arr[0]+"/"+arr[1]+"/"+arr[2]);
			break;
		case "YYYY/DD/MM":
			arr=strTemp.split("/");
			return (arr[0]+"/"+arr[2]+"/"+arr[1]);
			break;
			
		default :	
			return (arr[2]+"/"+(parseInt(strMonth)+1)+"/"+arr[0]);
	}		
	
}



/*
Following function checks for LEAP Year.
*/
function IsLeap(objValue)
{
	var year=objValue.getFullYear(); // assign YEAR value of DaTE
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	return isleap;
}

function SetGlobalDateDiff(objStartDate,objEndDate)
{
	DateDiffCountGlobal=Date.parse(GetMonth(objEndDate.value))-Date.parse(GetMonth(objStartDate.value))
	if(isNaN(DateDiffCountGlobal))
		DateDiffCountGlobal=0;
}

//Function checks for valid date and returns true/false accordingly
function isValidDate(dateStr) 
{
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat); 

	if (matchArray == null) 
	{
		return false;
	}
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];

	if(year < 1800)
	{
		return false;
	}
	if (month < 1 || month > 12) 
	{ 
		return false;
	}
	if (day < 1 || day > 31) 
	{
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		return false;
	}
	if (month == 2) 
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			return false;
		}
	}
	return true;
}

function IsValidEmail(strEmail)
{

/*
Purpose: For validating Email Address.
Author: Ritesh Yadav
*/
	// following line define a Regular Expression using pattering matching 
	// for validating Email Address.
	//var objRegExp =/^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/;
    var objRegExp =/^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
	var flag=strEmail.match(objRegExp);//validate Email Address.
	
	if(flag==null)	//if not valid Email address.
		return false;
	else
		return true;
}

function IsValidWebsite(strWebsite)
{

/*
Purpose: For validating website.
Author: Rajesh Srivastava
*/
	// following line define a Regular Expression using pattering matching 
	// for validating website.
	
	//var objRegExp =	/^(http):[/][/]([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$/;
	//var objRegExp = /^http:\/\/([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$/;
	var objRegExp =	/^(http|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?$/;
 
	//var objRegExp = /(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)/;
 
	var flag=strWebsite.match(objRegExp); //validate website.
	
	if(flag==null)	//if not valid wegsite address.
		return false;
	else
		return true;
}


/*
Function to allow numeric entry in Presentation Id and Number Of Copies fields
*/
function CheckNum(obj)
{
	if(window.event.keyCode==13) 
	{
		if(isNaN(obj.value)||obj.value=='') 
			obj.value=1;
	}
	if(!(window.event.keyCode>47&&window.event.keyCode<=58||window.event.keyCode==13)) 
		return false;
}
/*
Function to allow numeric entry 
*/
function CheckNumber(obj)
{
    var lIndex = obj.value.indexOf(".")
    
	if(window.event.keyCode==13) 
	{
		if(isNaN(obj.value)||obj.value.indexOf("e")!=-1 || obj.value.indexOf("E")!=-1) 
		{
			alert("Please enter Investment Number.")
			obj.select();
			return false;
		}
	    else if(lIndex!=-1)
	    {
	        alert("Please enter Integer Investment Number.")
			obj.select();
			return false;
	    }
	     	
	}
	if(!(window.event.keyCode>47&&window.event.keyCode<=58||window.event.keyCode==13)) 
		return false;
}

var oPopup = window.createPopup();

function ShowHelp(arrHelpText, vIndex, vPopupHeight)
{
	
	var oPopBody = oPopup.document.body;
	
	
	oPopBody.style.backgroundColor = "lightyellow";
	oPopBody.style.fontSize= "11px";
	oPopBody.style.fontFamily= "Tahoma";
	oPopBody.style.paddingLeft= "3px";
	oPopBody.style.border = "solid black 1px";

	oPopBody.innerHTML = arrHelpText[vIndex];
	oPopup.show(window.event.clientX + 15, window.event.clientY, 300,vPopupHeight, document.body);
}

function HideHelp()
{
	oPopup.hide();
}

function VerifyWebsite(objSiteURL)
/*
Purpose : Function to open a new window for the URL provided as Contact or Company Website.
Notes:	The regular expression is created to verify if the URL provided contains http:// pr https://
		If http:// or https:// is not provided then this is added and new window is opened for that link
*/
{
	// regular expression for http:// or https://
	//var objRegExp = /^((h|H)(t|T)(t|T)(p|P)|(h|H)(t|T)(t|T)(p|P)(s|S))(:)(\/\/)/;
	var objRegExp = /^(:)(\/\/)$/;
		
	// varaiable to store the value of Site URL
	var SiteURL;
	
	//variable to store the value returned by matching the URL with regular expression
	var flag;
	
	SiteURL = objSiteURL.value;
	
	if (RemoveBlanks(SiteURL) != "")
	{
		// matches the URL with regular Expression
		flag = SiteURL.indexOf("://");
		
		// if the URL does not contain http:// or https:// then add http:// to the URL
		if(flag==-1)
		{
			SiteURL = "//" + SiteURL;
		}
		
		// opens the URL in new window
		window.open(SiteURL,"NewWin")
	}
	else
	{
		alert(strEnterURLMessage);
		objSiteURL.focus();
	}
}	

function WebsiteVerify(objSiteURL)
/*
Purpose : Function to open a new window for the URL provided as Contact or Company Website.
Notes:	The regular expression is created to verify if the URL provided contains http:// pr https://
		If http:// or https:// is not provided then this is added and new window is opened for that link
*/
{
	// regular expression for http:// or https://
	var objRegExp = /^((h|H)(t|T)(t|T)(p|P)|(h|H)(t|T)(t|T)(p|P)(s|S))(:)(\/\/)/;
	
	// varaiable to store the value of Site URL
	var SiteURL;
	
	//variable to store the value returned by matching the URL with regular expression
	var flag;
	
	SiteURL = eval("window."+objSiteURL+".innerText");
	//alert(eval("window."+objSiteURL+".innerText"))
	
	if (RemoveBlanks(SiteURL) != "")
	{
		// matches the URL with regular Expression
		flag = SiteURL.match(objRegExp);
		
		// if the URL does not contain http:// or https:// then add http:// to the URL
		if(flag==null)
		{
			SiteURL = "http://" + SiteURL;
		}
		
		// opens the URL in new window
		objVerifyWebsiteWin=window.open(SiteURL,"NewWin")
	}
	else
	{
		alert(strEnterURLMessage);
		objSiteURL.focus();
	}
}	

/*******************************
'Function :GoToRelate
'Purpose  :Get the URL of relate by calling function GetRelateApplicationPath
'			which is in pagebase class
'Algorithm:
'Input    :Nothing
'Output   :Nothing
'Author   :Deepak Bhatia
'Created On:7th Oct. 2002
'**************************************************************/
//Get the URL of relate by calling function GetRelateApplicationPath
//which is in pagebase class
function GoToRelate()
{
	//Goto Relate
	
	//if(confirm("Are you sure you want to Cancel"))
	if(confirm(strAlertCancel))
	{
		window.location.href=strRelateApplicationPath;
	}	
}
	


//Function checks for valid date and returns true/false accordingly
function CheckValidDate(objDateField) 
{
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = (objDateField.value).match(datePat); 
	var strMonth = "";
	if (matchArray == null) 
	{
		alert(strDateFormat); //alert("Date is not in a valid format.")
		objDateField.select();
		return false;
	}
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];
	switch(month)
	{
		
		case "4":
		case "04":
					strMonth=strApril;
					break;
		case "6":
		case "06":
					strMonth=strJune; 
					break;
		case "9":
		case "09":	
					strMonth=strSeptember; 
					break;
		case "11":	
					strMonth=strNovember;
					 break;
		
		
	}
	if(year < 1900)
	{
		alert(strMinValidYear)			//alert("Year can not be less than 1900.");
		objDateField.select();
		return false;
	}
	if (year > 2078)
	{
		alert(strMaxValidYear)								//alert("Year cannot be greater than 2078")
		objDateField.select();
		return false;
	} 
	if (month < 1 || month > 12) 
	{ 
		alert(strMonthBetween);						//alert("Month must be between 1 and 12");
		objDateField.select();
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert(strDayBetween); //alert("Day must be between 1 and 31.");
		objDateField.select();
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert(strMonth +" "+ strSecondMonthDay); //alert("Month "+month+" doesn't have 31 days!")
		objDateField.select();
		return false;
	}
	if (month == 2) 
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert(strFebruaryDay + " "+ day + " "+strsecondFebDay); //alert("February doesn't have " + day + " days!");
			objDateField.select();
			return false;
		}
	}
	return true;
}

//Function checks for valid date and returns true/false accordingly
function CheckValidDateofDeath(objDateField,objBirthField,objDeathField) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = (objDateField.value).match(datePat); 
	var strMonth = "";
	if (matchArray == null) 
	{
		alert(strDateFormat); //alert("Date is not in a valid format.")
		objDateField.select();
		return false;
	}
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];
	switch(month)
	{
		
		case "4":
		case "04":
					strMonth=strApril;
					break;
		case "6":
		case "06":
					strMonth=strJune; 
					break;
		case "9":
		case "09":	
					strMonth=strSeptember; 
					break;
		case "11":	
					strMonth=strNovember;
					 break;
		
		
	}
	if(year < 1900)
	{
		alert(strMinValidYear)			//alert("Year can not be less than 1900.");
		objDateField.select();
		return false;
	}
	if (year > 2078)
	{
		alert(strMaxValidYear)								//alert("Year cannot be greater than 2078")
		objDateField.select();
		return false;
	} 
	if (month < 1 || month > 12) 
	{ 
		alert(strMonthBetween);						//alert("Month must be between 1 and 12");
		objDateField.select();
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert(strDayBetween); //alert("Day must be between 1 and 31.");
		objDateField.select();
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert(strMonth +" "+ strSecondMonthDay); //alert("Month "+month+" doesn't have 31 days!")
		objDateField.select();
		return false;
	}
	if (month == 2) 
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert(strFebruaryDay + " "+ day + " "+strsecondFebDay); //alert("February doesn't have " + day + " days!");
			objDateField.select();
			return false;
		}
	}
	
	if(new Date(objDateField.value)> new Date())
	{
		if(objDateField == objDeathField)
		
			//alert("Date of Death cannot be greater than Today's date.");
			alert(strAlertGreaterThanCurrentDate);
		else
			//alert("Date of Birth cannot be greater than Today's date.");
			alert(strAlertDOBGreaterToCurrent);
	
		objDateField.select();
		return false;
	}
	if (objDateField == objDeathField)
		DateCompare(objDateField,objDeathField,objBirthField)	
	
	return true;
}

function DateCompare(objDateField,objDeathField,objBirthField)
{
	if(objBirthField.value !='' && objDeathField.value  != '')
	{
		if(new Date(objBirthField.value)> new Date(objDeathField.value))
		{
			//alert("Birth Date cannot be greater than Date of Death.")
			alert(strAlertDOBGreaterDOD)
			objDeathField.select();
			
			return false;
		}
		return true;
	}
	return true;
}


	







		function CheckFileIfExists(strAttachedFiles)
		{
			var strMsg="", strElementName="";
			var objAttachedFiles = document.getElementById(strAttachedFiles);			
			if(objAttachedFiles != null)
			{	
				if(objAttachedFiles.length==0) 
				{
					strMsg = strMsg + "- No File available for deletion." + "\n";
					strElementName = "objAttachedFiles";
				}
				else if(objAttachedFiles.selectedIndex == -1)
				{
					strMsg = strMsg + "- Please select a File to delete." + "\n";
					strElementName = "objAttachedFiles";
				}
				if(strMsg == "")
				{
					return true;
				}
				else
				{
					strMsg = "Following error(s) found." + "\n" + strMsg;  
					alert(strMsg)
					eval(strElementName + ".focus()");
					return false;  
				}
			}
			return false;
		}
		
		var objWin;
		function OpenSelectedFile(strAttachedFiles,strBasePath)
		{
			try
			{
				var strMsg="", strElementName="";
				var strFile ;
				var objAttachedFiles = document.getElementById(strAttachedFiles);
				if(objAttachedFiles != null)
				{	
					if(objAttachedFiles.length==0) 
					{
						strMsg = strMsg + "- No File available for view." + "\n";
						strElementName = "objAttachedFiles";
					}			
					else if(objAttachedFiles.selectedIndex == -1)
					{
						strMsg = strMsg + "- Please select a File to view." + "\n";
						strElementName = "objAttachedFiles";
					}
					else
					{
						strFile = objAttachedFiles.options[objAttachedFiles.selectedIndex].value;
						objWin = window.open(strBasePath + "Task/View/ShowAttachment.aspx?FileName=" + strFile,"DisplayFile",'toolbar=1, menubar=1, scrollbars=1, resizable=1');
						if(objWin != null)
							objWin.focus();
						return false;
					}
				}
				else
				{
					strMsg = strMsg + "- No File available for view." + "\n";
					strElementName = "objAttachedFiles";
				}		
				
				if(strMsg == "")
				{
					return true;
				}
				else
				{
					strMsg = "Following error(s) found." + "\n" + strMsg;  
					alert(strMsg)
					eval(strElementName + ".focus()");
					return false;  
				}
			}
			catch(e)
				{alert(e.Description);}
		}		
		
		/****************************************/		
		function ValidateUpload(strFileUpload)
		{
			try
			{
				var strElementName="", strMsg=""; 
				var objFileUpload = document.getElementById(strFileUpload);
//				alert("validateupload");
				if(objFileUpload != null)
				{
					if(objFileUpload.value == "")
					{
						strMsg = strMsg + "- Please select File to Upload." + "\n";
						strElementName = "objFileUpload";
					}
					else
					{
						if (CheckFileExtension(objFileUpload) == false)
						{
							strMsg = strMsg + "- Please select a valid file format." + "\n";
							strElementName = "objFileUpload";
							//eval(strElementName + ".value = ''");					
						}				
					}				
				}
				
				if(strMsg == "")
				{
					return true;
				}
				else
				{
					strMsg = "Following error(s) found." + "\n" + strMsg;  
					alert(strMsg)
					eval(strElementName + ".focus()");
					return false;  
				}
			}
			catch(e)
			{
				alert(e.Description);
			}
			
		}

/*
'*****************************************************************
'Function :CheckFileExtension
'Purpose  :Check for file extension & validate it against allowed file formats.
'Algorithm:
'Input    :
'Output   :True/False
'Author   :
'Created On: 
'*****************************************************************
*/

function CheckFileExtension(objsource)
{
		var Str = new String(objsource.value);
		var fileName = Str.substr(Str.lastIndexOf(".")+1);
		fileName = fileName.toLowerCase();
		if ( !((fileName=="doc") || (fileName=="xls") || (fileName=="ppt") || (fileName=="rtf") || (fileName=="zip") || (fileName=="jpg") || (fileName=="gif") || (fileName=="txt") || (fileName=="vsd") || (fileName=="mpp") || (fileName=="jpeg") || (fileName=="mdl") || (fileName=="pdf")) )
			{
			return false ; // invalid 
			}
		else
			{			
			return true ; // valid string
			}
}
		
/************************************************************/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
		
		
function IsBlank(objTextbox)
{
	if(TrimString(objTextbox.value) == "")
		{
			return true;
		}
	return false;
}
/*
'*****************************************************************
'Function :IsSelected
'Purpose  :
'Algorithm:
'Input    :none 
'Output   :none
'Author   :
'Created On: 27/11/2003
'*****************************************************************
*/
function IsSelected(objSource)
{
	if(objSource.selectedIndex != 0)
	{
		return true;
	}
	return false;
}
/*
'*****************************************************************
'Function :IsChecked
'Purpose  :
'Algorithm:
'Input    :none 
'Output   :none
'Author   :Rajesh Srivastava
'Created On: 27/11/2003
'*****************************************************************
*/
function IsChecked(objSource)
{
	if(objSource.checked != 0)
	{
		return true;
	}
	return false;
}

/*'*****************************************************************
'Function   :ResetTextarea 
'Purpose    :Resets the text area
'Algorithm  :
'Input      :Form object
'Output     :
'Author     :Ashish Dawra
'Created On :27/11/2003
'*****************************************************************
*/

function ResetTextarea (oForm) 
{
	for (var i = 0; i < oForm.length; i++) 
	{
		if (oForm.elements[i].type == "textarea")
		oForm.elements[i].value = oForm.elements[i].defaultValue;
	}
}

/*'*****************************************************************
'Function   :isPhone
'Purpose    :to validate phone no.
'Algorithm  :
'Input      :Form object
'Output     :
'Author     :Rajesh Srivastava
'Created On :09/12/2003
'*****************************************************************
*/

function isPhone(strPhone)
{
	// following line define a Regular Expression for validating Phone Numbers
	//A regular expression to match phone numbers, allowing for an international dialing code at the start and hyphenation and spaces that are sometimes entered.  
	//Matches: [(+44)(0)20-12341234], [02012341234], [+44 (0) 1234-1234]   [ More Details]  
	//Non-Matches: [(44+)020-12341234], [12341234(+020)] [ Test Expression] 
	
	//var objPhoneRegExp = /^(\(\+?[0-9]*\))?[0-9_\-]*$/; ///^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;
	var objPhoneRegExp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/; 
	var flag = strPhone.match(objPhoneRegExp); //validate Phone
	
	if(flag==null)	//if not valid Phone Number
		return false;
	else
		return true;
}
/*****************************************************************
    Function :catchKeyPress
    Purpose  : to catch Key Press
    Algorithm:  1) Check for Key Code
				2) if Key Code is '13' 
				3) click 'Submit' button available on form
    Input    :Key Code , Submit Button Id 
    Output   :
    Author   : Ashish Dawra
    Created On:09/16/2003
 *****************************************************************/
function catchKeyPress(code,ElementId) {
    var ret=null;
	if (code == '13') {
		event.cancelBubble = true;
		event.returnValue = false;
        ret=document.getElementById(ElementId);
		if(ret) { 
			ret.click(); 
		}

    }
}
/*****************************************************************
    Function :catchKeyPressTextArea
    Purpose  : to catch Key Press
    Algorithm:  1) Check for Key Code
				2) if Key Code is '13' 
				3) Let is do enter functionality
    Input    :Key Code
    Output   :
    Author   : Ashish Dawra
    Created On:09/16/2003
    Note: Use this function with text area
 *****************************************************************/
function catchKeyPressTextArea(code) {
    if (code == '13') {
		event.cancelBubble = true;
		event.returnValue = true;
    }
}
