//Holds the boolean value to show the alert message 
//when data modified and User 
//Navigating to another page with out saving
var IsDataChanged
IsDataChanged =false;

//Client and Server Date Formats
var CDateFormat = "MM/dd/yyyy";
var SDateFormat = "MM/dd/yyyy";

var isppsolIE = false;
var isppsolNav = false;
var TypesChanged = false
var isNav7 = false;
var isIE = false;
var isNav = false;

if (navigator.appName == "Netscape"){
	isNav = true;
	if(navigator.appVersion.indexOf("5.0") == 0){
		isNav7 = true		
	}
}
else
	isIE = true;


var popTop = (window.screen.availHeight - 500) / 2
var popLeft = (window.screen.availWidth - 700) / 2

var bars="titlebar=no,scrollbar=no,menubar=no,statusbar=no,location=no"; 
var Myoptions="width=700,height=500,toolbar=no,directories=no,screenX="+popLeft+",screenY="+popTop+",resizable=yes,top="+popTop+",left="+popLeft 

function SetFocusToFirstField()
{
	if(window.document.forms.length>0)
	{
		if(window.document.forms[0].elements.length>0)
		{
			for(i=0;i<window.document.forms[0].elements.length;i++)
			{
				//alert("The Type Name <"+window.document.forms[0].elements[i].type+">");
				if((window.document.forms[0].elements[i].type=="select-one")||(window.document.forms[0].elements[i].type=="checkbox")||(window.document.forms[0].elements[i].type=="text"))
				{
					window.document.forms[0].elements[i].focus();
					break;
				}
				else if(window.document.forms[0].elements[i].type=="button")
				{
					if(window.document.forms[0].elements[i].disabled==false)
					{
						window.document.forms[0].elements[i].focus();
						break;
					}
				}
			}
		}
	}
}

function NavigateToURL(url)
{
	
	if(IsDataChanged==true)
	{
		if(confirm("Do you wish to ignore the changes?"))
		{
			window.location.href=url;
		}
	}
	else
	{
		window.location.href=url;
	}
	
}
		/*var Array checkObjs = new Array();

		function UpdateChecks(checkObj){
			var forSingleOnly = false;
			if(arguments.length == 2)
				forSingleOnly = eval(arguments[1]);
			if(checkObj.checked)
				if(forSingleOnly && checkObjs.length == 1){
					eval(checkObjs[0]).checked = false;
					checkObjs[checkObjs.length] = checkObj;
				}
				else	
					checkObjs[checkObjs.length] = checkObj;
			else{
				Array copyCheckObjs = new Array();
				for(i=0;i<checkObjs.length;i++){
					if(checkObj !== eval(checkObjs[i]))
					   copyCheckObjs[copyCheckObjs.length] = eval(checkObjs[i]);  
				}
				checkObjs = copyCheckObjs;
			}
		}
		
		function TransferChecks(){
			var
		}*/



	/*
		The below functional block is for opening the popup window
		as many as required. then any users calling this function should
		call window the minimum parameters.	All the parameters to
		this function call should be comma separated strings only.
		should not use any other conventions to call this.
		
		the below describes the parameter list which supposed to be
		given in order to open the popup windows.
		
		ParameterNo.		description
		1			should be the popup screens relative path for the
					file from the web context that a open function of
					window should look.	The file type for opening the 
					popup window are '.htm','.html','aspx' only. if the 
					said file types are not matched then the function
					call will alert the user to user appropriate file type.
		2			this parameter is a call index. this parameter right 
					now not used. However this is pre-anticipated for
					the reason that a screen potentially can have multiple 
					popups, where in this parameter can be used to identify 
					and differentiate the calls from which this will be 
					orginated.
		3			This parameter will be used for opening the multi popups.
					The basic functionality implemented like this.
					a)	if the calling function have this value as false and no 
					window is opened then simply opens this window.
					b)	if the calling function have this value as false and a 
					window is opened then asks for the confirmation to close
					the existing child window. on this dialog if a user say
					yes then closed the existing window opens up the new window.
					c)	if the calling function have this value as true then
					simple opens up the new window.
					d)	if the below situation is raised because of opening
					the windows that having too many window and the present calling
					function have this parameter false different dialog box will be
					opened for confirmation if user say 'yes' on this then closes
					all the child windows then opens up the present calling window.
					
		4			window name is used for open of multi windows in case the 
					above parameter is set to true. this is the pre-requesit for
					opening multi windows.
		
		5			form name is used in the url in case the popup screen whats
					use this form in case required only the this form name is
					the present window form name. this name is must.
		
		The above five parameters are must. In case user is not giving these
		then the function call will alert the user to provide this data.
		
		The parameters after this will be appeded to url as a query string.
		These parameters are generally been used in the popup screen rendering
		so, this are the screen specific times. the preferable format for this
		should follow like key value pair.
		
		fkey_user='1' or product_id='ccjjdk'
		
		
		all the user defined parameter should also be comma separated values only 
		with the above format.
		
		note:
		if the value have the spaces then this may not function properly. let me
		know the requirement then this may be modified that time.
		
		
					
					
					
								
	
	
	*/

	var popUpWindow = new Array();
	function NavigateToPopUpURL(){
		var argumentSize = arguments.length;
		
		if(argumentSize < 5 ){
			alert("No suficiant data available for opening popup screen.");
			return;
		}
		var regExp = /(\.htm|\.html|\.aspx)/;
		var url;
		var callIndex;
		var hasMultiPopups;
		var windowName;
		var formName;
		if(regExp.test(arguments[0]))  
			url = arguments[0]+"?";
		else
			alert("No Property Navigation URL identified.");
		 
		callIndex = arguments[1];
		
		hasMultiPopups = arguments[2];
			
		windowName = arguments[3];
		
		formName = arguments[4];
		
		url+= "callIndex="+callIndex;
		
		url+= "&windowName="+windowName;
		
		url+= "&formName="+formName;
		
		for(i=5;i<argumentSize;i++){
			url += "&"+arguments[i];
		}
		
		
		var numberOfWindows = popUpWindow.length;
				
		if(popUpWindow[0] == null && hasMultiPopups == 'false'){
			
			popUpWindow[0] = window.open(url,windowName);
		}
		else if(popUpWindow[0] && popUpWindow.length == 1 && hasMultiPopups == 'false'){
			//alert(eval(popUpWindow[0]).closed)
			if(confirm("Would You like to close opened popup window.")){
			   popUpWindow[0].close();
			   popUpWindow[0] = null;
			   popUpWindow[0] = window.open(url,windowName);
			}
		}
		else if(popUpWindow[0] && popUpWindow.length > 1 && hasMultiPopups == 'false'){
			if(confirm("There are too many windows are opened. Are you willing to close all of them?")){
				for(i = 0;i< popUpWindow.length; i++){
					popUpWindow[i].close();
					popUpWindow[i] = null;
				}
			    popUpWindow[0] = window.open(url,windowName);
			}
		}
		else if(hasMultiPopups == 'true'){
			popUpWindow[popUpWindow.length] = window.open(url,windowName);
		}
	}
	
	function UpdatePopUpWindow(popWindow){
		 if(popUpWindow.length == 1){
			popUpWindow = null;
			popUpWindow[popUpWindow.length] = popWindow;
		 }
	}
	
	function NavigateToFilePopUpURL(){
		var argumentSize = arguments.length;
		var winSettings = 'menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=300,top=0,left=0';
		
		if(argumentSize < 5 ){
			alert("No suficiant data available for opening popup screen.");
			return;
		}
		var regExp = /(\.htm|\.html|\.aspx)/;
		var url;
		var callIndex;
		var hasMultiPopups;
		var windowName;
		var formName;
		if(regExp.test(arguments[0]))  
			url = arguments[0]+"?";
		else
			alert("No Property Navigation URL identified.");
		 
		callIndex = arguments[1];
		
		hasMultiPopups = arguments[2];
			
		windowName = arguments[3];
		
		formName = arguments[4];
		
		url+= "callIndex="+callIndex;
		
		url+= "&windowName="+windowName;
		
		url+= "&formName="+formName;
		
		for(i=5;i<argumentSize;i++){
			url += "&"+arguments[i];
		}
		
		
		var numberOfWindows = popUpWindow.length;
				
		if(popUpWindow[0] == null && hasMultiPopups == 'false'){
			
			popUpWindow[0] = window.open(url,windowName,winSettings);
		}
		else if(popUpWindow[0] && popUpWindow.length == 1 && hasMultiPopups == 'false'){
			//alert(eval(popUpWindow[0]).closed)
			if(confirm("Would You like to close opened popup window.")){
			   popUpWindow[0].close();
			   popUpWindow[0] = null;
			   popUpWindow[0] = window.open(url,windowName,winSettings);
			}
		}
		else if(popUpWindow[0] && popUpWindow.length > 1 && hasMultiPopups == 'false'){
			if(confirm("There are too many windows are opened. Are you willing to close all of them?")){
				for(i = 0;i< popUpWindow.length; i++){
					popUpWindow[i].close();
					popUpWindow[i] = null;
				}
			    popUpWindow[0] = window.open(url,windowName,winSettings);
			}
		}
		else if(hasMultiPopups == 'true'){
			popUpWindow[popUpWindow.length] = window.open(url,windowName,winSettings);
		}
	}
	
	
	/*
		The below function is for writting the popup data
		on to the parent window.
	
	*/
	
	function WritePopUPData(){
		
		var argumentSize = arguments.length;
		if(argumentSize == 0 )
			return;
		
		if(argumentSize < 3)
			alert("No suficiant Arguments.");
		var formName;
		
		if(top.window && top.window.opener)
			formName = "top.window.opener."+trim(arguments[0]);
		else
			formName = "document."+trim(arguments[0]);
			
		//alert(arguments[1]);
		//alert(formName);
		var topWindowForm = eval(formName);
		
		var childWindow = trim(arguments[1]);
		var submitParent = trim(arguments[2]);
		
		var field;
		var params;
		var parray;
		
		if(topWindowForm){
			for(i=3;i<argumentSize;i++){
				parray =  arguments[i].split("^");				
				for(j=0;j<parray.length;j++){
					params = parray[j].split("=")		
						
					if(params.length == 2){
						field = eval(formName+"."+trim(params[0]));
						if(field){							
							field.value = trim(params[1]);						
						}else{
							//This block is used for setting the data to layers in NS and Div tags in IE
							if(top.window.opener)
								field=eval("top.window.opener."+params[0]);
							else{								
								if(isNav7==true){
										top.window.document.getElementById(trim(params[0])).innerHTML = trim(params[1]);
										top.window.document.getElementById(trim(params[0])).style.visibility="hidden" 
										top.window.document.getElementById(trim(params[0])).style.visibility="visible" 
								}else{
									field=eval(params[0]);							
								}
							}							
							//if(field)
							//	field(trim(params[1]));
								
							if (field){
								if (isIE == true){	
									field.innerHTML = trim(params[1]);
								}
								else if (isNav == true){
									if(isNav7==true){
										top.window.document.getElementById(trim(params[0])).innerHTML = trim(params[1]);
										top.window.document.getElementById(trim(params[0])).style.visibility="hidden" 
										top.window.document.getElementById(trim(params[0])).style.visibility="visible" 
									}else{
										field.document.open();
										field.write(trim(params[1]));
										field.close(); 
									}
								}
							}	
						}
					}
				}				
			}
		}


		if(childWindow != null && trim(childWindow) != '' && submitParent=='false'){
			var thisWindow =eval(childWindow);
			thisWindow.close();
			
		}
		if(topWindowForm && submitParent=='true'){
			field = eval(formName+".TargetAction"); 
			if(field){
				var fval = trim(field.value);
				if( !fval || fval === '')
					field.value = "select";
			}
			var thisWindow =eval(childWindow);
			thisWindow.close();
			setTimeout(ClearPopUpWindows,1);
			topWindowForm.submit();
			
		}
			
		setTimeout(ClearPopUpWindows,1);
		
	}
	
	function ClearPopUpWindows(){
		var numberOfWindows = popUpWindow.length;
		var newPopUpWindows = new Array();
		var index = 0;
		for(i=0;i<numberOfWindows;i++){
			if(popUpWindow[i]){
				var obj = eval(popUpWindow[i]);
				//alert(obj.closed)
				if(obj.closed){
					popUpWindow[i] = null;
				}
				else{
					newPopUpWindows[index] = popUpWindow[i];
					index++;
				}
			}
		}
		popUpWindow = newPopUpWindows;
	}
	
	
	var notesWindow = false;
	
	var parentFieldObject;
	var checkObject;
	function OpenNotesWindow()
	{
		var argSize = arguments.length;
		
		if(argSize != 5) {alert("Can not open PopUp.");return;}
		var popupSize = popUpWindow.length;
		if(popupSize > 0 ){
			ClearPopUpWindows();
			return;
		}
		
		var checkBox = arguments[4];

		var pageTitle = trim(arguments[0]);
		var windowName = trim(arguments[1]);
		var formName = trim(arguments[2]);
		var parentFormRef = "window.document."+formName;
		var fieldName = trim(arguments[3]);
		var fieldRef = "window.document."+formName+"."+fieldName;
		//alert(parentFormRef);
		var parentObject = eval(parentFormRef);
		if(!parentObject){
			alert("Object not identified.");
			return;
		}
		
		var fieldObject = eval(fieldRef);
		if(!fieldObject){
			alert("Object not identified.");
			return;
		}
		
		var confirmMessage = "Shall you want to clear the '"+pageTitle+"' then \nclick 'Ok' else click 'Cancel'.\nThe 'Cancel' brings the old notes content with check enabled.";
		if(checkBox){
			if(!checkBox.checked){
				if(popUpWindow.length == 1){
					checkBox.checked = true;
					return;
					
				}
				
				if(confirm(confirmMessage)){
					fieldObject.value = '';
					return;
				}
				else{
					checkBox.checked = true;
				}
			}
			checkObject = checkBox; 
		}
		
		parentFieldObject = fieldObject;
		
		/*
			Note : for the internationalization the 
			below code will be modified and the 
			relative url string should 
			be obtained from the parent function
			call.
		
		*/
		var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
		//if(InternetExplorer)
		//{
			//document.write("<LINK rel='stylesheet' href='../styles/admin/styleie.css' type='text/css'>");
		//}
		//else
		//{
			//document.write("<LINK rel='stylesheet' href='../styles/admin/stylens.css' type='text/css'>");
		//}	
		newWindow=window.open("",windowName,"width=450,height=300");
		newWindow.document.open();
		newWindow.document.write("<HEAD><TITLE class='bodytext'>"+pageTitle+"</TITLE>");
		if(InternetExplorer)
		{
			newWindow.document.writeln("<link rel='stylesheet' href='../styles/admin/styleie.css' type='text/css'>");
		}
		else
		{
			newWindow.document.writeln("<link rel='stylesheet' href='../styles/admin/stylens.css' type='text/css'>");
		}
		newWindow.document.writeln("<style type='text/css'>");
		newWindow.document.writeln("</style></HEAD>");
		newWindow.document.write("<body onLoad='newWindow.document.myform.Text1.focus();' onUnLoad='top.window.opener.ClearPopUpWindows();'><FORM NAME='myform'><center><table border='0' bgColor='#F9EDF1' width='90%'>");
		newWindow.document.write("<tr><td align='center' width='100%'><span class='bodytext'><b>"+pageTitle+"</b></span></td></tr>");
		newWindow.document.write("<tr><td align='center'><TEXTAREA class=s1 NAME='Text1' ROWS=10 COLS=42 ");
		newWindow.document.write(" >"+unescape(fieldObject.value)+"</textarea></td></tr>");		
		newWindow.document.write("<tr><td align='center'>");
		//newWindow.document.write("<a href=\"javascript:top.window.opener.WriteNotesToParent(window.document.myform.Text1.value);window.close();\">");
		newWindow.document.write("<input type='button' class='buttons' name='btnSave' value='Save'onclick=\"javascript:top.window.opener.WriteNotesToParent(window.document.myform.Text1.value);window.close();\" >");
		newWindow.document.write("&nbsp;&nbsp;&nbsp;");
		//newWindow.document.write("<a href=\"javascript:top.window.opener.WriteNotesToParent('close',window.document.myform.Text1.value);window.close();\">");
		newWindow.document.write("<input type='button' class='buttons' name='btnClose' value='Close'onclick=\"javascript:top.window.opener.WriteNotesToParent('close',window.document.myform.Text1.value);window.close();\" ></td></tr>");
		newWindow.document.write("</table>");
		newWindow.document.write("<script language=\"javascript\">");
		newWindow.document.write("document.myform.Text1.focus();");
		newWindow.document.write("</script>");
		newWindow.document.write("</FORM></center>");
		newWindow.document.write("</body></html>");
		popUpWindow[popUpWindow.length] = newWindow;
		//newWindow.document.close();
		newWindow = null;
	}
	
	function WriteNotesToParent(){
		if(arguments.length == 2 && popUpWindow.length == 1 && arguments[0] == 'close'){
			if(checkObject.checked && (trim(arguments[1]) == '' || !arguments[1]))
				checkObject.checked = false;
			parentFieldObject = null;
			popUpWindow[0] = null;	
		}
		else if(parentFieldObject && popUpWindow.length == 1){			
			parentFieldObject.value = arguments[0];
			parentFieldObject = null;
			popUpWindow[0] = null;			
		}
		ClearPopUpWindows();
	}

	
	/*
	   End of coding.
	
	
	*/

function IsValidEmailSyntax( sEmail ) 
{ 

   //return ( sEmail.search( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/ ) != -1); 
   return ( sEmail.search(/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) != -1);

} 

function validEmail(email)
{
	invalidChars="/:,;"

	if(email=="")
	{
		return(false);
	}
	for(i=0;i<invalidChars.length;i++)
	{
		badChar=invalidChars.charAt(i)
		if(email.indexOf(badChar,0)!=-1)
		{
			return(false);
		}
	}
	atPos=email.indexOf("@",1)
	if(atPos==-1)
	{
		return(false);
	}
	if (email.indexOf("@",atPos+1)!=-1)
	{
		return(false);
	}
	periodPos=email.indexOf(".",atPos)
	if(periodPos==-1)
	{
		return(false);
	}
	if(periodPos+3>email.length)
	{
		return(false);
	}
	if(email.charAt(email.length - 1)==".")
	{
		return(false);
	}

	return(true);
}


//THESE ARE THE FUNCTIONS FOR VALIDATING  THE DATE FIELDS
function chkdate(objName)
{
	var datefield = objName;
	if (validDate(objName) == false) 
	{
		datefield.select();
		//alert("That date is invalid.Enter in mm-dd-yyyy format  Please try again.");
		datefield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function checkDate(objName){
	if(!validDate(objName)){
		alert("Date should be in \"" + CDateFormat + "\" format and \nbetween \""+ SetCurrentDateFormat("01/01/1900",SDateFormat,CDateFormat) +"\" and \""+SetCurrentDateFormat("12/31/9999",SDateFormat,CDateFormat)+"\"")
		objName.focus();
		objName.select();
		return false;
	}
	return true;
}


function validDate(objName)
{
	var strDatestyle = "US"; //United States date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array(". ","-"," ","/",".");
	var intElementNr;
	var err = 0;
	var splitStr = ""
	var CDateArray;

	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	datefield.value = trim(datefield.value);
	strDate = datefield.value;
	//alert(strDate)
	var x=new RegExp("[^. 0-9/-]");
		
	if (strDate.length < 1){
			return true;
	}if(strDate.search(x)!=-1){
		return false;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if(CDateFormat.indexOf(strSeparatorArray[intElementNr]) != -1 && splitStr==""){
			splitStr = strSeparatorArray[intElementNr];
			CDateArray = CDateFormat.split(splitStr)
		}
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			//alert(strDateArray)
			if (strDateArray.length != 3){
				err = 1;
				return false;
			}else{
				for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){
					if(CDateArray[intEltNr].indexOf("y")!=-1){
						strYear = strDateArray[intEltNr];					
					}else if(CDateArray[intEltNr].indexOf("M")!=-1){
						strMonth = strDateArray[intEltNr];													
					}else if(CDateArray[intEltNr].indexOf("d")!=-1){
						strDay = strDateArray[intEltNr];
						if (strDateArray[intEltNr].length>2){							
							strDay = strDateArray[intEltNr].substring(0,2)
						}
					}
				}
				//alert("###############Date["+strDay+"]Month["+strMonth+"]Year["+strYear+"]")
					/*strDay = strDateArray[0];
					strMonth = strDateArray[1];
					strYear = strDateArray[2];*/
			}
			booFound = true;
		 }
	}
	if (booFound == false){
		if ((strDate.length>5)&&(strDate.length<9)&&(strDate.length!=7)){
			var tempInt = 0 ;
			//alert(CDateArray)
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++) 
			{
				if(CDateArray[intEltNr].indexOf("y")!=-1){
					if(strDate.length == 6){
						strYear =  strDate.substr(tempInt,2);			
						tempInt = tempInt + 2
					}else{
						strYear =  strDate.substr(tempInt,4);		
						tempInt = tempInt + 4
					}
				}else if(CDateArray[intEltNr].indexOf("M")!=-1){
					strMonth = strDate.substr(tempInt, 2);
					tempInt = tempInt + 2
				}else if(CDateArray[intEltNr].indexOf("d")!=-1){
					strDay = strDate.substr(tempInt, 2);
					tempInt = tempInt + 2
				}
			}
			//alert(">>>>>>>Date["+strDay+"]Month["+strMonth+"]Year["+strYear+"]")
		}else{
			return false;
		}
	}
	if (strYear.length == 2){
			strYear = '20' + strYear;
	}

	// US style
	/*	if (strDatestyle == "US")
		{
				strTemp = strDay;
				strDay = strMonth;
				strMonth = strTemp;
		}
	*/
	intday = parseInt(strDay, 10);
	if (isNaN(intday)){
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for (i = 0;i<12;i++)
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()){
					intMonth = i+1;
					strMonth = strMonthArray[i];
					i = 12;
			}
		}if (isNaN(intMonth)){
				err = 3;
				return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)){
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
			err = 5;
			return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			err = 6;
			//alert("This is not a valid calender date \n This month contains only 31 days.");
			return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)){
			err = 7;
			//alert("This is not a valid calender date \n This month contains only 30 days.");
			return false;
	}
	if (intMonth == 2){
		if (intday < 1){
				err = 8;
				return false;
		}
		if (LeapYear(intYear) == true){
			if (intday > 29){
				err = 9;
				//alert("This is not a valid calender date \n This month contains only 29 days.");
				return false;
			}
		}else{
			if (intday > 28){
				err = 10;
				//alert("This is not a valid calender date \n This month contains only 28 days.");
				return false;
			}
		}
	}
		
		
	var fdate =  new Array ("","","")//CDateArray.clone();
	if (strDatestyle == "US"){
		for (intElementNr = 0; intElementNr < CDateArray.length; intElementNr++) 
		{
			if (intElementNr < fdate.length){
				if(CDateArray[intElementNr].indexOf("y")!=-1){
					if (CDateArray[intElementNr].length>2)
						fdate[intElementNr] = strYear
					else
						fdate[intElementNr] = strYear.substring(2)
					
				}else if(CDateArray[intElementNr].indexOf("M")!=-1){
					if (CDateArray[intElementNr].length<2 || intMonth >= 10)
						fdate[intElementNr] = intMonth
					else
						fdate[intElementNr] = "0"+intMonth
											
				}else if(CDateArray[intElementNr].indexOf("d")!=-1){
					if (CDateArray[intElementNr].length<2 || intday >= 10)
						fdate[intElementNr] = intday
					else{
						fdate[intElementNr] = "0"+intday
					}

					if (CDateArray[intElementNr].length==3)
						fdate[intElementNr] = fdate[intElementNr] + ((CDateArray[intElementNr]).substring(2))
					else if (CDateArray.length==4)
						fdate[intElementNr] = fdate[intElementNr] + splitStr
				}
			}
		}
		datefield.value = fdate.join(splitStr)
	}else{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}

function checkPattern(theForm)
{
		
		theForm.pattern.value =trim(theForm.pattern.value);
        if (theForm.pattern.value == "")
        {
                alert("Please enter the value for search.");
                theForm.pattern.focus();
				return;
                //return (false);
        }

			theForm.submit();
		
}   

//In search when  hitting enter in the text field.
function checkPatternOnSubmit(frm)
{
	checkPattern(frm);
	return false;
}


//****************************/
//This code is for pop up calendar.
var Cal_PopUp_CalWindowObject = null;
var newWindow=null;
var Cal_PopUp_dateObject;

function getPopupCalculator(fieldObject)
{	
	var bars1="titlebar=no,scrollbar=no,menubar=no,statusbar=no,location=no";
	var Myoptions1="width=210,height=230,toolbar=no,directories=no,screenX="+event.screenX+",screenY="+event.screenY+",resizable=yes,top="+event.screenY+",left="+event.screenX+""

	Cal_clearCalWindow();

	Cal_PopUp_dateObject=fieldObject;
	Cal_PopUp_CalWindowObject = window.open('CalendarPopUp.htm','Calendar', bars1+","+Myoptions1);
}

function getPopupCalendar(fieldObject)
{	
	var bars1="titlebar=no,scrollbar=no,menubar=no,statusbar=no,location=no";
	var Myoptions1="width=210,height=230,toolbar=no,directories=no,screenX="+event.screenX+",screenY="+event.screenY+",resizable=yes,top="+event.screenY+",left="+event.screenX+""

	Cal_clearCalWindow();

	Cal_PopUp_dateObject=fieldObject;
	Cal_PopUp_CalWindowObject = window.open('../html/CalendarPopUp.html','Calendar', bars1+","+Myoptions1);
}

function CloseWindow(){
	if(newWindow != null)
	{
		if (navigator.appName.indexOf("Netscape")!=-1)
		{
			if(newWindow.window)
				newWindow.close();
		}else
			newWindow.close();

		newWindow = null
	}
}


function Cal_clearCalWindow()
{
 	if(Cal_PopUp_CalWindowObject!=null)
	{
		if (navigator.appName.indexOf("Netscape")!=-1)
		{
			if(Cal_PopUp_CalWindowObject.window)
				Cal_PopUp_CalWindowObject.close();
		}else
			Cal_PopUp_CalWindowObject.close();

		Cal_PopUp_CalWindowObject = null		
	}
}

function Cal_PopUp_DoNothing()
{
	return;
}
/********************************/



function checkDateNew(objName)
{
	var strDatestyle = "US"; //United States date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array(". ","-"," ","/",".");
	var intElementNr;
	var err = 0;
	var splitStr = ""
	var CDateArray;

	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	
	var x=new RegExp("[^. 0-9/-]");
		
	if (strDate.length < 1){
			return true;
	}if(strDate.search(x)!=-1){
		return false;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if(CDateFormat.indexOf(strSeparatorArray[intElementNr]) != -1 && splitStr==""){
			splitStr = strSeparatorArray[intElementNr];
			CDateArray = CDateFormat.split(splitStr)
		}
	}
	intElementNr = 0
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length < 3){
				err = 1;
				return false;
			}else{
				for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){					
					if(CDateArray[intEltNr].indexOf("y")!=-1 && !eval(strYear)){
						strYear = strDateArray[intEltNr];					
					}else if(CDateArray[intEltNr].indexOf("M")!=-1 && !eval(strMonth)){
						strMonth = strDateArray[intEltNr];													
					}else if(CDateArray[intEltNr].indexOf("d")!=-1 && !eval(strDay)){
						strDay = strDateArray[intEltNr];
						if (strDay.length>2){							
							strDay = strDay.substring(0,2)
						}
					}
				}
				
					/*strDay = strDateArray[0];
					strMonth = strDateArray[1];
					strYear = strDateArray[2];*/
			}
			booFound = true;
		 }
	}
	
	if (booFound == false){
		if ((strDate.length>5)&&(strDate.length<9)&&(strDate.length!=7)){
			var tempInt = 0 ;
			
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++) 
			{
				if(CDateArray[intEltNr].indexOf("y")!=-1){
					if(strDate.length == 6){
						strYear =  strDate.substr(tempInt,2);			
						tempInt = tempInt + 2
					}else{
						strYear =  strDate.substr(tempInt,4);		
						tempInt = tempInt + 4
					}
				}else if(CDateArray[intEltNr].indexOf("M")!=-1){
					strMonth = strDate.substr(tempInt, 2);
					tempInt = tempInt + 2
				}else if(CDateArray[intEltNr].indexOf("d")!=-1){
					strDay = strDate.substr(tempInt, 2);
					tempInt = tempInt + 2
				}
			}			
		}else{
			return false;
		}
	}
	if (strYear.length == 2){
			strYear = '20' + strYear;
	}

	// US style
	/*	if (strDatestyle == "US")
		{
				strTemp = strDay;
				strDay = strMonth;
				strMonth = strTemp;
		}
	*/
	intday = parseInt(strDay, 10);
	if (isNaN(intday)){
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for (i = 0;i<12;i++)
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()){
					intMonth = i+1;
					strMonth = strMonthArray[i];
					i = 12;
			}
		}if (isNaN(intMonth)){
				err = 3;
				return false;
		}
	}
	
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)){
		err = 4;
		//alert("error 4");
		return false;
	}
	if (intMonth>12 || intMonth<1) {
			err = 5;
			//alert("error 5");
			return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			err = 6;
			//alert("This is not a valid calender date \n This month contains only 31 days.");
			return "Invalid";
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)){
			err = 7;
			//alert("This is not a valid calender date \n This month contains only 30 days.");
			return "Invalid";
	}
	if (intMonth == 2){
		if (intday < 1){
				err = 8;
				//alert("error 8.");
				return false;
		}
		if (LeapYear(intYear) == true){
			if (intday > 29){
				err = 9;
				//alert("This is not a valid calender date \n This month contains only 29 days.");
				return "Invalid";
			}
		}else{
			if (intday > 28){
				err = 10;
				//alert("This is not a valid calender date \n This month contains only 28 days.");
				return "Invalid";
			}
		}
	}
		
		
	var fdate =  new Array ("","","")//CDateArray.clone();
	if (strDatestyle == "US"){
		for (intElementNr = 0; intElementNr < CDateArray.length; intElementNr++) 
		{
			if (intElementNr < fdate.length){
				if(CDateArray[intElementNr].indexOf("y")!=-1){
					if (CDateArray[intElementNr].length>2)
						fdate[intElementNr] = strYear
					else
						fdate[intElementNr] = strYear.substring(2)
					
				}else if(CDateArray[intElementNr].indexOf("M")!=-1){
					if (CDateArray[intElementNr].length<2 || intMonth >= 10)
						fdate[intElementNr] = intMonth
					else
						fdate[intElementNr] = "0"+intMonth
											
				}else if(CDateArray[intElementNr].indexOf("d")!=-1){
					if (CDateArray[intElementNr].length<2 || intday >= 10)
						fdate[intElementNr] = intday
					else{
						fdate[intElementNr] = "0"+intday
					}

					if (CDateArray[intElementNr].length==3)
						fdate[intElementNr] = fdate[intElementNr] + ((CDateArray[intElementNr]).substring(2))
					else if (CDateArray.length==4)
						fdate[intElementNr] = fdate[intElementNr] + splitStr
				}
			}
		}
		datefield.value = fdate.join(splitStr)
	}else{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}


function LeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
			if (intYear % 400 == 0)
			{
					return true;
			}
	}
	else
	{
			if ((intYear % 4) == 0)
			{
					return true;
			}
	}
	return false;
}


function doDateCheck(from, to)
{
		if (Date.parse(from.value) <= Date.parse(to.value))
		{
				//alert("The dates are valid.");
				return true;
		}
		else
		{
				/*if (from.value == "" || to.value == "") 
						alert("Both dates must be entered.");
				else 
						alert("To date must occur after the from date.");*/
				return false;
		}
		
}


function isInteger(n)
	{
		
		var  num=n.value;
		num=trim(num);
		var pat=new RegExp("[^0123456789-]");
		var flag=num.search(pat);
		if (flag!=-1)
		{
			return false;
		}
		if ((num.indexOf('-',0)>0)||(num.indexOf('-',1)!=-1))
		{
			return false;
		}
		
		return true;
				
	}
//THIS FUNCTION IS TO CHECK WHETHER THE INPUT IS VALID FLOAT VALUE
	

	function isFloat(n)
	{
		var  num=n.value;
		num=trim(num);
		var pat=new RegExp("[^.0123456789-]");
		var flag=num.search(pat);
		if (flag!=-1)
		{
			return false;
		}
		if ((num.indexOf('-',0)>0)||(num.indexOf('-',1)!=-1))
		{
			return false;
		}
		var arr=num.split(".");
		if (arr.length>2)
		{
			return false;
		}
		return true;
		
	}

//THIS FUNCTION IS TO CHECK WHETHER THE INPUT IS VALID CURRENCY VALUE
	

	function isCurrency(n)
	{
		var  num=n.value;
		num=trim(num);
		var pat=new RegExp("[^.0123456789]");
		var flag=num.search(pat);
		if (flag!=-1)
		{
			return false;
		}
		if ((num.indexOf('-',0)>0)||(num.indexOf('-',1)!=-1))
		{
			return false;
		}
		var arr=num.split(".");
		if (arr.length>2)
		{
			return false;
		}
		if(num.indexOf('.',0)==0)
		{
			num="0"+num;
		}
		if(num.indexOf('.',0)>0)
		{
			num=num.substring(0,num.indexOf('.',0))+num.substring(num.indexOf('.',0),num.indexOf('.',0)+3);
		}
		n.value=num;
		return true;
		
	}
//THIS FUNCTION IS FOR CHECKING TEH VALUE OF A TEXTFIELD 
// WHETHER IT IS INT THE RANGE -90 TO +90


	function isInRange90(k)
	{
			range=k.value;
			if(isFloat(k))
			{
					if((parseFloat(range)>=-90)&&(parseFloat(range)<=90))
					{
						 
							return true;

					}
					else
					{
							k.select();
							k.focus();
							return false;
					}
			}
			//alert("the number is not valid number");
			k.select();
			k.focus();
			return false;
   }
//THIS FUNCTION IS FOR CHECKING TEH VALUE OF A TEXTFIELD 
// WHETHER IT IS INT THE RANGE -180 TO +180
   function isInRange180(k)
	{
			range=k.value;
			if(isFloat(k))
			{
					if((parseFloat(range)>=-180)&&(parseFloat(range)<=180 ))
					{
						 
							return true;
					}
					else
					{
							k.select();
							k.focus();
							return false;
					}
			}
			
			k.select();
			k.focus();
			return false;
   }

   function isInRange30(k)
	{
			range=k.value;
			if(isInteger(k))
			{
					if((parseInt(range)>=0)&&(parseInt(range)<=30))
					{
						 
							return true;

					}
					else
					{
							
							k.select();
							k.focus();
							return false;
					}
			}
			
			k.select();
			k.focus();
			return false;
   }
   function isInRange31(k)
	{
			range=k.value;
			if(isInteger(k))
			{
					if((parseInt(range)>=0)&&(parseInt(range)<=31))
					{
						 
							return true;

					}
					else
					{
							
							k.select();
							k.focus();
							return false;
					}
			}
			
			k.select();
			k.focus();
			return false;
   }

   function patMatch(str)
   {
		   var pat=new RegExp("[^-0123456789]","i");
		   return str.substring(0,str.search(pat)); 
   }
   
   //   THIS FUNCTION CHECKS WHETHER THE FIELD IS EMPTY OR NOT

   function isEmpty(theFieldValue)
   {
			var boolVal = (theFieldValue=="");
	   		if(theFieldValue=="")
			{
			 	return true;
			}
			else
			{
				return false;
			}
   }
	
   function noSpaces(l)
   {
			var strGiven
			strGiven=l;
			for(i=0;i<l.length;i++)
			{
				 if(strGiven.charAt(i)==" ") 
				{
					
					return false;		
				}
			}
			return true;
   }

   function noDots(l)
   {
			var strGiven
			strGiven=l;
			for(i=0;i<l.length;i++)
			{
				 if(strGiven.charAt(i)==".") 
				{
					
					return false;		
				}
			}
			return true;
   }
	//THIS FUNCTION TRIMS THE INPUT STRING BY REMOVING THE LEADING AND TRIALING BLANK SPACES 
		
   function trim(value)
   {
			/*var strResult;
			var charTemp;
			var i;
			strResult="";
			//remove the left space
			var regexp1 = /^[\s]/;
			var regexp2 = /[\s]$/;
			
			for(i=0;i<strMessage.length;i++)
			{
				charTemp=strMessage.charAt(i);
				if(charTemp!=" ")  
				{
					strResult=strMessage.substring(i);
					break;
			    }
		    }
			//remove the right space
			for(i=strResult.length-1;i>=0;i=i-1)
			{
				charTemp=strResult.charAt(i);
				if(charTemp!=" " )
				{
					strResult=strResult.substring(0,i+1);
					break;
				}
			}
			return(strResult);*/
			
			if(arguments.length != 1) return "";
			if(!value) return "";
			
			var regexp1 = /^[\s]/;
			var regexp2 = /[\s]$/;
			
			while(regexp1.test(value)){
				value = value.substring(value.search(regexp1)+1,value.length);
			}
			
			while(regexp2.test(value)){
				value = value.substring(0,value.search(regexp2));
			}
			
			return value;

	}



function isMonth(field)//we have to pass the field object(ie for example : text)
{
	field.value=trim(field.value);
	var month=field.value;
	if(!isInteger(field))
	 {
			  field.focus();
			  return false;
	 }
	  if((month>12)||(month<1))
	  {
		   //alert(month);
		   field.focus();
		  return false;
	  }
	 return true;
}

function isDate(field)//we have to pass the field object(ie for example : text)
{
	field.value=trim(field.value);
	var day=field.value;
	if(!isInteger(field))
	 {
			  field.focus();
			  return false;
	 }
	  if((day>31)||(day<1))
	  {
		   //alert(month);
		   field.focus();
		  return false;
	  }
	 return true;
}



function isYear(field)//we have to pass the field object(ie for example : text)
{
field.value=trim(field.value);
if(!isInteger(field))
		 {		 
			  field.focus();
			  return false;
		 }
var year=parseInt(field.value);
if((year>=0)&&(year<100))
		 {		 
				  field.value = "20"+field.value;
		 }
year=parseInt(field.value);
	 if((year<1000)||(year>9999))
		  {
		   field.focus();
		  return false;
		  }
	return true;
}




function isPhoneNum(field)
{
	    var fval=field.value;
		var x=new RegExp("[^. #@ a-z A-Z 0-9()-]");

		if(fval.search(x)!=-1) 
		{
			return false ;
		}
		else
		{
		return true;
		}

}

function dateRange(from,to)//    /*from/*'parameter is grater than /*to/* parameter then this function
								//will return TRUE else FALSE'
{
    if(!validDate(from))
	{
		//alert("Not valid from");
		return false;
	}
	if(!validDate(to))
	{
		//alert("Not Valid to");
		return false;
	}
	return tempDateRange(from.value,to.value);
}
function CurrentDateFormat(field,cdf,sdf){
	var arr1 = new Array("","",""); //holds MM, dd, yyyy
	var strSeparatorArray = new Array(". ","-"," ","/",".");
	var intElementNr;
	var splitStr = ""
	var CDateArray;
	var strDateArray;
	var SDateSplitStr="";
	var SDateArray;
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if(cdf.indexOf(strSeparatorArray[intElementNr]) != -1 && splitStr==""){
			splitStr = strSeparatorArray[intElementNr];
			CDateArray = cdf.split(splitStr)
		}
		if(sdf.indexOf(strSeparatorArray[intElementNr]) != -1 && SDateSplitStr==""){
			SDateSplitStr = strSeparatorArray[intElementNr];
			SDateArray = sdf.split(SDateSplitStr)
			//alert(SDateArray +" "+SDateSplitStr)
		}
	}
	intElementNr = 0
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (field.value.indexOf(strSeparatorArray[intElementNr]) != -1){
			strDateArray = field.value.split(strSeparatorArray[intElementNr]);
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){
				if(CDateArray[intEltNr].indexOf("y")!=-1){
					arr1[2] = strDateArray[intEltNr];					
				}else if(CDateArray[intEltNr].indexOf("M")!=-1){
					arr1[0] = strDateArray[intEltNr];													
				}else if(CDateArray[intEltNr].indexOf("d")!=-1){
					arr1[1] = strDateArray[intEltNr];
					
					if (arr1[1].length>2){							
						arr1[1] = arr1[1].substring(0,2)
					}
					//alert("################" + arr1[1])
				}
			}	
			//field.value = arr1.join("/")	
		}
	}
	
	var fdate =  new Array ("","","")//CDateArray.clone();
	for (intElementNr = 0; intElementNr < SDateArray.length; intElementNr++) 
	{
		if (intElementNr < fdate.length){
			if(SDateArray[intElementNr].indexOf("y")!=-1){
				//if (SDateArray[intElementNr].length > 2 && arr1[2].length < 3)
				//fdate[intElementNr] = "20" + arr1[2];
				//else
				fdate[intElementNr] = arr1[2]				
			}else if(SDateArray[intElementNr].indexOf("M")!=-1){
				//if (SDateArray[intElementNr].length<2 || arr1[0]*1 > 10)
					fdate[intElementNr] = arr1[0]
				//else
				//	fdate[intElementNr] = "0"+arr1[0]
										
			}else if(SDateArray[intElementNr].indexOf("d")!=-1){
				//if (SDateArray[intElementNr].length<2 || arr1[1]*1 > 10)
					fdate[intElementNr] = arr1[1]
				//else{
				//	fdate[intElementNr] = "0"+arr1[1]
				//}				
			}
		}
	}
	//alert(field.value + " = " + fdate.join(SDateSplitStr))
	field.value = fdate.join(SDateSplitStr)
	
}

function tempDateRange(from,to)//Onle strings are allowed
{

	var arr1 = new Array("","","");
	var arr2 = new Array("","","");
	
	//populate array to MM, dd, yyyy

	var strSeparatorArray = new Array(". ","-"," ","/",".");
	var intElementNr;
	var splitStr = ""
	var CDateArray;
	var strDateArray;
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if(CDateFormat.indexOf(strSeparatorArray[intElementNr]) != -1 && splitStr==""){
			splitStr = strSeparatorArray[intElementNr];
			CDateArray = CDateFormat.split(splitStr)
		}
	}
	intElementNr = 0
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (from.indexOf(strSeparatorArray[intElementNr]) != -1){
			strDateArray = from.split(strSeparatorArray[intElementNr]);
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){
					if(CDateArray[intEltNr].indexOf("y")!=-1){
						arr1[2] = strDateArray[intEltNr];					
					}else if(CDateArray[intEltNr].indexOf("M")!=-1){
						arr1[0] = strDateArray[intEltNr];													
					}else if(CDateArray[intEltNr].indexOf("d")!=-1){
						arr1[1] = strDateArray[intEltNr];
						if (arr1[1].length>2){							
							arr1[1] = arr1[1].substring(0,2)
						}
					}
			}			
		}
	}	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{		
		if (to.indexOf(strSeparatorArray[intElementNr]) != -1){
			strDateArray = to.split(strSeparatorArray[intElementNr]);
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){
					if(CDateArray[intEltNr].indexOf("y")!=-1){
						arr2[2] = strDateArray[intEltNr];					
					}else if(CDateArray[intEltNr].indexOf("M")!=-1){
						arr2[0] = strDateArray[intEltNr];													
					}else if(CDateArray[intEltNr].indexOf("d")!=-1){
						arr2[1] = strDateArray[intEltNr];
						if (arr2[1].length>2){							
							arr2[1] = arr1[1].substring(0,2)
						}
					}
			}			
		}
	}	
	
	//arr1=from.split('/');
	//arr2=to.split('/');

	if ((arr1.length==3)&&(arr2.length==3))
	{
		
		//var year= parseInt(arr1[2]) - parseInt(arr2[2])
		//removed parseInt as it is not validating 08,09... Veerendra.
		var year= arr1[2] - arr2[2];
		var month=0;
       //	month=parseInt(arr1[0])-parseInt(arr2[0]);
	   month=arr1[0]-arr2[0];
		if (month<0)
			{
			year=year-1;
			month=month+12;
			 }
		 var  date=0;
		 //date=(parseInt(arr1[1])-parseInt(arr2[1]));
		 date=arr1[1]-arr2[1];
			if (date<0) 
			 {
			  month=month-1;
			  date=date+30;
						if (month<0)
						{
							year=year-1;
							month=month+12;
						 }

			 }
		//alert(date+"..days.."+month+"...months.."+year+"..years");
		var stryear=(year<=0)? " ": year+"  years,";
		var strmon=(month<=0)? " ": month+"  months";
		//target.value=stryear+" "+strmon ;
		if ((date<0)||(month<0)||(year<0))
		{	
			return false;
		}

		return true;
	}
	
}


function validForm(form,field)//,required,type,message)
{    
     var fname,minval,maxval,flag,fval,type,required,message,farraylength;
	 var i;
	 var tempintarr;
	 var guiname;
	 for(i=0; i<=field.length-1; i++)
	 {      
				guiname='';
				tempintarr=field[i].split(",");
			    fname=tempintarr[0];
				required=tempintarr[1];
				type=tempintarr[2];
				message=tempintarr[3];
				if(eval(message))
					message = eval(message);
				minval=tempintarr[4];
				maxval=tempintarr[5];
				farraylength=tempintarr.length;
				if(farraylength>6)
				{
					guiname=trim(tempintarr[6]);
					//alert(guiname)
				}
				for(j=0;j < form.elements.length;j++)
				{      
			       	    if(form.elements[j].name==fname)
						{
								if (form.elements[j].value == ""){
									fval = "";
								}else{
									fval=trim(form.elements[j].value);
								}
								form.elements[j].value = fval;
								if((required=="y")&&(type!="select"))
								{
									
									if(isEmpty(fval))
									{   
										alert(message);
										form.elements[j].focus();
										return false;

									}
								}//end of ( required[i]=="y" )  loop
								//alert(type);
								switch (type)
								{								
								case "nospaces":  {		
													if(!isEmpty(fval))
													{	
														if(!(noSpaces(form.elements[j].value)))
														{       
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false;
														}
													}//end of isempty block
													break;
												  }

							
								case "int":  {		
													if(!isEmpty(fval))
													{	
														if(!(isInteger(form.elements[j])))
														{       
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false;
														}
														else
														{   
																if(farraylength>=6)
																{	
																	minval=parseInt(minval);
																	maxval=parseInt(maxval);
																	
																	if(( minval > parseInt(fval)) || (maxval < parseInt(fval)))
																	 {
																			alert(message);
																			form.elements[j].select();
																			form.elements[j].focus();
																			return false;
																	 }
																}
														}
													}
													//end of isempty block
													break;
											  }
								case "float"		:{ 						
														if(!isEmpty(fval))
														{	
															if(!(isFloat(form.elements[j])))
															{       
																	alert(message);
																	form.elements[j].select();
																	form.elements[j].focus();
																	return false;
															}
															else
															{   
																	if(farraylength>=6)
																	{	
																		minval=parseFloat(minval);
																		maxval=parseFloat(maxval);
																		
																		if(( minval > parseFloat(fval)) || (maxval < parseFloat(fval)))
																		 {
																				alert(message);
																				form.elements[j].select();
																				form.elements[j].focus();
																				return false;
																		 }
																	}
															}
														}
														//end of isempty block

														break;
													 }
								case "currency"		:{ 						
														if(!isEmpty(fval))
														{	
															fval = removeChar(fval,",");
															//fval = removeChar(fval,".00");															
															form.elements[j].value=fval;
															if(!(isCurrency(form.elements[j])))
															{       
																	alert(message);
																	form.elements[j].select();
																	form.elements[j].focus();
																	return false;
															}
															else
															{   
																	if(farraylength>=6)
																	{	
																		minval=parseFloat(minval);
																		maxval=parseFloat(maxval);
																		//alert(minval);
																		//alert(maxval);
																		if(( minval > parseFloat(fval)) || (maxval < parseFloat(fval)))
																		 {
																				alert(message);
																				form.elements[j].select();
																				form.elements[j].focus();
																				return false;
																		 }
																	}
															}
															
														}
														//end of isempty block

														break;
													 }

								case "phonenum"		:{
								                       if(!isEmpty(fval))
														{
															var x=new RegExp("[^- 0-9()+]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}

															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}															

														}//end of isempty block

														break;
													 }
								
								case "numeric"		:{
								                       if(!isEmpty(fval))
														{
															var x=new RegExp("[^. 0-9]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																//alert(minval);
																//alert(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	

														}//end of isempty block

														break;
													 }

								case "CrimeCode" :{
																if(!isEmpty(fval))
																{
																	var x=new RegExp("[^/ 0-9]");
																	var y=	fval.split("/");
																	if((fval.search(x)!=-1)||(y.length>2) )
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false ;
																	}
																	
																}//end of isempty block
																if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
																break;
													}
								
								
			
								case "postalcode" :{
																if(!isEmpty(fval))
																{
																	var x=new RegExp("[^- 0-9]");
																	var y=	fval.split("-");
																	if((fval.search(x)!=-1)||(y.length>2) )
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false ;
																	}
																	
																}//end of isempty block
																if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
																break;
													}
							
									case "password"	:{
														
														if(!isEmpty(fval))
														{
															var x=new RegExp("[^a-zA-Z0-9]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
														}
														else
														{
															form.elements[j].value=' ';
														}//end of isempty block

														break;
													 }
								case "alphanumeric"	:{
														if(!isEmpty(fval))
														{
															var x=new RegExp("[^a-zA-Z0-9 ,.]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
														}
														else
														{
															form.elements[j].value=' ';
														}//end of isempty block

														break;
													 }
							case "productalphanumeric"	:{
														if(!isEmpty(fval))
														{
															var x=new RegExp("[^a-zA-Z0-9 ,.,_]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
														}
														else
														{
															form.elements[j].value=' ';
														}//end of isempty block

														break;
													 }
							case "allchars"	:{
														if(!isEmpty(fval))
														{
															/*var x=new RegExp("[^a-zA-Z0-9 ,.;:_#=$@*)(/\-]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}*/
															form.elements[j].value=fval;
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
														}
														

														break;
													 }
								case "Email"	:{
														if(!isEmpty(fval))
														{
															var x=new RegExp("[^a-zA-Z0-9 ,._#=$*)(@-]");
															if(fval.search(x)!=-1) 
															{
																alert(message);
																form.elements[j].select();
																form.elements[j].focus();
																return false ;
															}
															form.elements[j].value=fval;
															if(farraylength>4)
															{	
																minval=parseFloat(minval);
																maxval=parseFloat(maxval);
																	
																if(minval!=null)
																{
																	if(fval.length<minval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
																if(maxval!=null)
																{
																	if(fval.length>maxval)
																	{
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																}
															}	
														}
														else
														{
															form.elements[j].value=' ';
														}//end of isempty block

														break;
													 }

								case "date"			:{ // alert("date");
														if(!isEmpty(fval))
														{    //alert("date inside if");
																
																if("Invalid"==checkDateNew(form.elements[j]))
																	{   
																		alert("This is not a valid calender date \n Please change it.");
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false;
																	}
																														
															
																	
															if(!checkDateNew(form.elements[j]))
																	{   
																		alert(message);
																		form.elements[j].select();
																		form.elements[j].focus();
																		return false ;
																	}
																
															fval=form.elements[j].value;
															if(minval!=null)
															{
																
																if(!tempDateRange(fval,minval))
																{
																	alert(message);
																	form.elements[j].select();
																	form.elements[j].focus();
																	return false;
																}
															}
															if(maxval!=null)
															{
																if(!tempDateRange(maxval,fval))
																{
																	alert(message);
																	form.elements[j].select();
																	form.elements[j].focus();
																	return false;
																}
															}
														}//end of isempty block

														break;
													 }
								case "check"		:{
														if(!form.elements[j].checked)
														{
															alert(message);
															form.elements[j].focus();
															return false;
														}
														break;
													 }	
								case "nonspace"    :{														
												if(minval!=null)
												{
													if(fval.split(" ").join("").length<minval)
													{
														alert(message);
														form.elements[j].select();
														form.elements[j].focus();
														return false;
													}
												}
												if(maxval==null)
													maxval = 1000;
												
													if(fval.split(" ").join("").length>maxval)
													{
																	alert(message);
																	form.elements[j].select();
																	form.elements[j].focus();
																	return false;
													}
													break;
													 }																
								case "select"		:{	
														var tmpSelectIndex = -1;
														
														if (minval==null)
															{
															if(form.elements[j].selectedIndex==tmpSelectIndex)
																{
																	alert(message);

																	form.elements[j].focus();
																	return false;
																}
															}
														//}
														else
														{
															tmpSelectIndex=parseInt(minval);
															if(form.elements[j].selectedIndex == -1
															 || form.elements[j].options[form.elements[j].selectedIndex].value == tmpSelectIndex)
															{
																alert(message);
																form.elements[j].focus();
																return false;
															}
														}
													break;
													 }
								
								
								}//end of switch statement
						}//end of if(name==elements[].name) loop
				}//end of elements for loop
	 }
	 return true;

}

function changeDateFormat(dateValue)
{
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr = 0 ;
	 
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (dateValue.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			//alert("in if");
				strDateArray = dateValue.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) 
				{
				return dateValue;
				}
				else
				{
					if((strDateArray[0].length==4)&&(strDateArray[1].length==2)&&(strDateArray[2].length==2))
					{
						return (strDateArray[1]+"/"+strDateArray[2]+"/"+strDateArray[0])
					}
					else
					{
						return (strDateArray[0]+"/"+strDateArray[1]+"/"+strDateArray[2])
					}
				 }
		}

	}
	return dateValue;
}



function amountFormat(value)
{
	val=trimZeros(value);
	if (val==0)
	{
		val="0";
	}

	if(val.length>0)
	{
		val = removeChar(val,",");
		var dec=".00";
		var mod="";
		var result="";
		if(val.indexOf(".")!=-1)
		{
			dec=val.substring(val.indexOf("."));
			dec ="."+removeChar(dec.substring(1),".");
			if(dec.length>3)
			{
				dec=dec.substring(0,3);
			}
			else if(dec.length==1)
			{
			   dec=".00";
			}
			val=val.substring(0,val.indexOf("."));
		}
		if (val==0)
		{
			val="0";
		}

		while(val.length!=0)
		{
			
			if(val.length>3)
			{
				result=","+val.substring(val.length-3)+result;
				val=val.substring(0,val.length-3);
			}
			else
			{
				result=val+result;
				val="";
			}
		}
		result=result+dec;
		return(result);
		}
	return(val);
	}

function trimZeros(value)
{
	temp=value.split("");
	result=value;
	for (i=0;i<temp.length;i++)
	{
		if("0"!=temp[i])
		{
			break;
		}
		else
		{
			result=result.substring(1);
		}
	}
	return(result);
}

function amountOnBlur(val)
{
	  //if(noSpaces(val))
	  if(hasSpaces(val))
	  {
			  alert(" Spaces are not allowed.");
			  val.select();
			  return false;
	  }
	  else
	  {		
			var num=val.value;
			var pat=new RegExp("[^.,0123456789]");
			var flag=num.search(pat);
			if (flag!=-1)
			{
					 alert(" Amount entered is not valid.");
					 val.select();
					 return false ;
			}
			else
			{
					val.value=formatCurrency(val.value);
					 return true ;
			}
	  }

}

function hasSpaces(field)
{
		if(field.value.indexOf(" ")!=-1)
		{
			return true;
		}
		else
		{
			return false;
		}
}

function removeChar(value,ch)
{		
	while(value.indexOf(ch)!=-1)
	{
			value=value.substring(0,value.indexOf(ch))+value.substring(value.indexOf(ch)+ch.length);
	}
	//alert(value);
	return value;
}

function currencyFormat(fld, milSep, decSep, e,maxlength,onnew) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (onnew.value=="true")
{
	fld.value = '';
	onnew.value="false"
}
len = fld.value.length;
if ((strCheck.indexOf(key) == -1)||(len>= maxlength)) return false;  // Not a valid key
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

function formatCurrency(num) {
num=trim(num);
num1 = num.toString().replace(/\$|\,/g,'');
if (num=='')
{
	return num;
}
if(isNaN(num1))
return num;
//num = "0";
num = num1;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

function formatHours(num) {
num=trim(num);
num1 = num.toString().replace(/\$|\,/g,'');
if (num=='')
{
	return num;
}
if(isNaN(num1))
return num;
//num = "0";
num = num1;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
return (((sign)?'':'-') + num + '.' + cents);
}

function numericFormat( numstr, numDecimals)
{
		//this formatCurrencyNew( numstr, numDecimals)
		//this method is added by Ramkumar
		numstr=trim(numstr);
		numstr = removeChar(numstr,",");
		if(isNaN(numstr))
		{
			
			return numstr;
			
		}
		
		
		
		if( numstr==null || numstr =='')
		{
			return "";		
		}
		var sign="";
		var result="";
		var intpart="";
		var decpart="";

		if(numstr.indexOf('-')==0)
		{
			sign="-";
			numstr=numstr.substring(1);
		}

		if(numstr.indexOf('.')!=-1)
		{
			intpart=numstr.substring(0,numstr.indexOf('.'));
			if(numstr.indexOf('.')< numstr.length-1)
			decpart=numstr.substring(numstr.indexOf('.')+1);
		}
		else
		{
			intpart=numstr;
		}

		while(intpart.length!=0)
		{
						if(intpart.length>3)
						{
								result=intpart.substring(intpart.length-3)+result;
								intpart=intpart.substring(0,intpart.length-3);
						}
						else
						{
								result=intpart+result;
								intpart="";
						}
		}

		var hasDecimal=0;

		if(numDecimals)
		{
				if(numDecimals > 0)	
				{
					hasDecimal=1;
				}
				if(hasDecimal==1)
				for(i=0;i<numDecimals;i++)
				{ 
					decpart=decpart+"0";
				}
				return sign+result+((hasDecimal)? "."+decpart.substring(0,numDecimals) : "");

		}else
		{
			if(decpart.length>0) 	hasDecimal=1;
				return sign+result+((hasDecimal)? "."+decpart : "");
		}


	}



function Del(Word) {
a = Word.indexOf("<");
b = Word.indexOf(">");
len = Word.length;
c = Word.substring(0, a);
if(b == -1)
b = a;
d = Word.substring((b + 1), len);
Word = c + d;
tagCheck = Word.indexOf("<");
if(tagCheck != -1)
Word = Del(Word);
return Word;
}
function CheckHTMLTags(text) {
ToCheck = text.value;
Checked = Del(ToCheck);
text.value = Checked;
return true;
}

function goBack()
	{
		window.history.go(-1);
	}
	
function trimData(strMessage)
   {
			var strResult;
			var charTemp;
			var i;
			strResult="";
			//remove the left space
			for(i=0;i<strMessage.length;i++){
				charTemp=strMessage.charAt(i);
				if(charTemp!=" "){
					strResult=strMessage.substring(i);
					break;
			    }
		    }
			//remove the right space
			for(i=strResult.length-1;i>=0;i=i-1){
				charTemp=strResult.charAt(i);
				if(charTemp!=" " ){
					strResult=strResult.substring(0,i+1);
					break;
				}
			}
			return(strResult);

	}

function SetCurrentDateFormat(field,cdf,sdf){
	var arr1 = new Array("","",""); //holds MM, dd, yyyy
	var strSeparatorArray = new Array(". ","-"," ","/",".");
	var intElementNr;
	var splitStr = ""
	var CDateArray;
	var strDateArray;
	var SDateSplitStr="";
	var SDateArray;
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if(cdf.indexOf(strSeparatorArray[intElementNr]) != -1 && splitStr==""){
			splitStr = strSeparatorArray[intElementNr];
			CDateArray = cdf.split(splitStr)
		}
		if(sdf.indexOf(strSeparatorArray[intElementNr]) != -1 && SDateSplitStr==""){
			SDateSplitStr = strSeparatorArray[intElementNr];
			SDateArray = sdf.split(SDateSplitStr)
			//alert(SDateArray +" "+SDateSplitStr)
		}
	}
	intElementNr = 0
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (field.indexOf(strSeparatorArray[intElementNr]) != -1){
			strDateArray = field.split(strSeparatorArray[intElementNr]);
			for (intEltNr = 0; intEltNr < CDateArray.length; intEltNr++){
				if(CDateArray[intEltNr].indexOf("y")!=-1){
					arr1[2] = strDateArray[intEltNr];					
				}else if(CDateArray[intEltNr].indexOf("M")!=-1){
					arr1[0] = strDateArray[intEltNr];													
				}else if(CDateArray[intEltNr].indexOf("d")!=-1){
					arr1[1] = strDateArray[intEltNr];
					
					if (arr1[1].length>2){							
						arr1[1] = arr1[1].substring(0,2)
					}
					//alert("################" + arr1[1])
				}
			}	
			//field.value = arr1.join("/")	
		}
	}
	
	var fdate =  new Array ("","","")//CDateArray.clone();
	for (intElementNr = 0; intElementNr < SDateArray.length; intElementNr++) 
	{
		if (intElementNr < fdate.length){
			if(SDateArray[intElementNr].indexOf("y")!=-1){
				//if (SDateArray[intElementNr].length > 2 && arr1[2].length < 3)
				//fdate[intElementNr] = "20" + arr1[2];
				//else
				fdate[intElementNr] = arr1[2]				
			}else if(SDateArray[intElementNr].indexOf("M")!=-1){
				//if (SDateArray[intElementNr].length<2 || arr1[0]*1 > 10)
					fdate[intElementNr] = arr1[0]
				//else
				//	fdate[intElementNr] = "0"+arr1[0]
										
			}else if(SDateArray[intElementNr].indexOf("d")!=-1){
				//if (SDateArray[intElementNr].length<2 || arr1[1]*1 > 10)
					fdate[intElementNr] = arr1[1]
				//else{
				//	fdate[intElementNr] = "0"+arr1[1]
				//}				
			}
		}
	}
	//alert(field.value + " = " + fdate.join(SDateSplitStr))
	//field.value = fdate.join(SDateSplitStr)
	return fdate.join(SDateSplitStr);
	
}

function DateTickler(field){
	var myKeycode
	if (navigator.appName.indexOf("Netscape")!=-1)
		myKeycode = window.event.which 
	else
		myKeycode = window.event.keyCode;
		
	
	if(myKeycode == 38){	//up arrow
		if(!checkDateNew(field)){
			var fromDate=new Date();
			field.value=(fromDate.getMonth()+1)+"/"+fromDate.getDate()+"/"+fromDate.getFullYear();
			CurrentDateFormat(field,SDateFormat,CDateFormat)
			return false;
		}
		var maxDate = Date.parse("12/31/9999")
		CurrentDateFormat(field,CDateFormat,SDateFormat)	
		if(maxDate > Date.parse(field.value) ){
			var fromDate=new Date(Date.parse(field.value)+60*60*24*1000);
			field.value=(fromDate.getMonth()+1)+"/"+fromDate.getDate()+"/"+fromDate.getFullYear();
		}
		CurrentDateFormat(field,SDateFormat,CDateFormat);
		IsDataChanged=true;
	}else if(myKeycode == 40){
		if(!checkDateNew(field)){
			var fromDate=new Date();
			field.value=(fromDate.getMonth()+1)+"/"+fromDate.getDate()+"/"+fromDate.getFullYear();
			CurrentDateFormat(field,SDateFormat,CDateFormat)
			return false;
		}
		var minDate = Date.parse("01/01/1900")
		CurrentDateFormat(field,CDateFormat,SDateFormat)	
		if(minDate < Date.parse(field.value) ){
			var fromDate=new Date(Date.parse(field.value)-60*60*24*1000);
			field.value=(fromDate.getMonth()+1)+"/"+fromDate.getDate()+"/"+fromDate.getFullYear();
		}
		CurrentDateFormat(field,SDateFormat,CDateFormat);		
		IsDataChanged=true;
	}


}

/*
* The following function has been modified to remove the numeric decimals
* by Mr.Mitra on the request of Srinivas. on the 02 Feb 2002. 
*/
function formatCurrencyNew(numstr, numDecimals)
{
	numstr=trim(numstr);
	numstr = removeChar(numstr,",");
	if(isNaN(numstr)){
		alert("The entered data is invalid. Please enter numeric data.");
		//return numstr;		
		return "";
	}
	
	
	
	
	if( numstr==null || numstr =='' ){
		return "";		
	}
		
	var sign="";
	var result="";
	var intpart="";
	var decpart="";

	if(numstr.indexOf('-')==0){
		sign="-";
		numstr=numstr.substring(1);
	}

	if(numstr.indexOf('.')!=-1){
		intpart=numstr.substring(0,numstr.indexOf('.'));
		if(numstr.indexOf('.')< numstr.length-1)
			decpart=numstr.substring(numstr.indexOf('.')+1);
	}else{
		intpart=numstr;
	}

	while(intpart.length!=0)
	{
		if(intpart.length>3){
			result=","+intpart.substring(intpart.length-3)+result;
			intpart=intpart.substring(0,intpart.length-3);
		}else{
			result=intpart+result;
			intpart="";
		}
	}

	var hasDecimal=0;

	if(numDecimals){
		if(numDecimals > 0){
			hasDecimal=1;
		}
		if(hasDecimal==1)
		for(i=0;i<numDecimals;i++){ 
			decpart=decpart+"0";
		}
		
		return  sign+result+((hasDecimal)? "."+decpart.substring(0,numDecimals) : "");

	}else{
		if(decpart.length>0) 	hasDecimal=1;
		return  sign+result+((hasDecimal)? "."+decpart : "");
	}
}		//end of functiion formatCurrencyNew

function ReplaceDollar(value)
{
	var numstr;
	numstr = removeChar(value,",");
	numstr= removeChar(numstr,"$");
	return numstr;
}

var isNetscape = false;
if(navigator.appName == "Netscape")
{
	isNetscape = true;
	document.captureEvents(Event.KEYPRESS);
	document.onkeypress = isEnterKey;
}
function isEnterKey(evt,frm){
	var myKeycode = isNetscape ? evt.which : window.event.keyCode;
	if(myKeycode == 13)
	{
		//myKeycode = 0;		
		//if(typeof(ApplySearch)=="function")

		if(typeof(ApplySearch)=="function")
			ApplySearch(frm);
	}
}

// special character validates.
// currently validates 
// [,],{,},<,>,;,"
function HasSpecialChars(valObj,message)
{	
	if(valObj && valObj.value.search(/[<>;\[\]\{\}""]/) != -1)
	{
		alert(message);
		valObj.focus();
		return true;
	}	
	return false;
}


//****************************/
//This code is for pop up calendar.
var Cal_PopUp_CalWindowObject;
var newWindow=null;
var Cal_PopUp_dateObject;

function getPopupCalculator(fieldObject)
{	
	var bars="titlebar=no,scrollbar=no,menubar=no,statusbar=no,location=no";
	var Myoptions="width=210,height=230,toolbar=no,directories=no,screenX="+event.screenX+",screenY="+event.screenY+",resizable=yes,top="+event.screenY+",left="+event.screenX+""

	CloseWindow();

	Cal_PopUp_dateObject=fieldObject;
	newWindow = window.open('CalendarPopup.html','Calendar', bars+","+Myoptions);
}

function CloseWindow(){
	if(newWindow != null)
	{
		if (navigator.appName.indexOf("Netscape")!=-1)
		{
			if(newWindow.window)
				newWindow.close();
		}else
			newWindow.close();

		newWindow = null
	}
}
function Cal_clearCalWindow()
{
	if(Cal_PopUp_CalWindowObject!=null)
	{
		Cal_PopUp_CalWindowObject.close();
	}
}

function Cal_PopUp_DoNothing()
{
	return;
}
/********************************/

/********* Uploaded File Attributes Window **************************/

function ShowFileAttributes(currentSide, ec){
	CloseFileAttrWindow();
	var toolBars="titlebar=no,scrollbars=yes,menubar=no,statusbar=no,location=no";
	var myOptions="width=350,height=150,resizable=yes"
	var url = "../web/ViewFileAttributes.aspx?side="+currentSide;
	if(ec != "") url = url + "&ec="  + ec;
	fileAttrWindow = window.open(url,"FileAttributeWindow",toolBars+","+myOptions);
	fileAttrWindow.focus();
}

var hasPOBoxInTextFld = false;
function CheckPOBox(txtfld){
	if(hasPOBoxInTextFld) return true;
    var arrPoBox = new Array("po box", "p o box", "p.o. box", "po. box", "p.o box",
							"pobox", "p obox", "p.o.box", "po.box", "p.obox");
		
	var addrLine = txtfld.value;				
	addrLine = addrLine.toLowerCase();
	var isPOOk = true;
	for(iPo=0; iPo < arrPoBox.length; iPo++){
		if(addrLine.indexOf(arrPoBox[iPo])==0){
			if(!confirm("Please note that our shipper UPS, does not ship to PO Boxes. If you cannot provide a regular address, we will ship your package by United States Postal Service. We cannot guarantee that your package will arrive within the time provided. We also do not provide any tracking numbers for Shipments to PO Boxes. This is not applicable to Direct Mail orders. Please confirm.")){
				txtfld.focus();
				isPOOk = false
			}else{
				hasPOBoxInTextFld = true;
			}
			break;
		}
	}
	return isPOOk;	
}
        	
var fileAttrWindow;
function CloseFileAttrWindow(){
	if(fileAttrWindow != null)
	{
		if (navigator.appName.indexOf("Netscape")!=-1)
		{
			if(fileAttrWindow.window)
				fileAttrWindow.close();
		}else
			fileAttrWindow.close();

		fileAttrWindow = null
	}
}
/********* Uploaded File Attributes Window **************************/