var separator	= ",";  // use comma as 000's separator
var decpoint	= ".";  // use period as decimal point
var percent		= "%";
var currency	= "$";  // use dollar sign for currency
var telephonenum = 8;
var teleMessage = 'Please Enter a 8 digit Telephone Number';
var decimalPlace = 3;	// Global Decimal Postion 
var varMaxAge = 65;		// Maximum Age of the Customer
var varMinAge = 18;		// Minimum Age of the Customer
var timer	  = 1;		// Window Close Time in secs
printFlag = true;		// Print Flag
var waitMsg = "Your request is being processed. Please wait.....";
var DATE_FORMAT = "dd-MM-yyyy";
var DATE_SEP = "-";
var CLIENT_VALIDATION = true;

var passwordflag = "A";   // C -> Only Characters  N -> Only Numeric   A -> Alpha Numeric

var montharray = new Array(12);
montharray[1] = 31;
montharray[2] = 28;  
montharray[3] = 31;
montharray[4] = 30;
montharray[5] = 31;
montharray[6] = 30;
montharray[7] = 31;
montharray[8] = 31;
montharray[9] = 30;
montharray[10] = 31;
montharray[11] = 30;
montharray[12] = 31;

// regex patterns
var VAL_SCREEN_NAME_PATTERN = "^[a-zA-Z0-9_\\-\\s]+$"; // small letters, capital letters, numbers, underscore any number of times
var VAL_NAME_PATTERN = "^[a-zA-Z0-9.'\\s]+$"; // small letters, capital letters, numbers, dot, single quote, space any number of times
var VAL_PHONE_NUMBER_PATTERN = "^[0-9+()\\-\\s]+$"; // numbers, open paranthesis, close paranthesis, hyphen, space
var VAL_ADDRESS_PATTERN = "^[a-zA-Z0-9_\\s.,\\-;:'\"/]+$"; // small letters, capital letters, numbers, underscore, space, dot, comma,hyphen,semi colon, colon, single quote, double quotes
var VAL_INTEGER_NUMBER_PATTERN = "^[0-9]+$"; // numbers
var VAL_DECIMAL_NUMBER_PATTERN = "^[0-9.]+$"; // numbers and decimal point
var VAL_PROJECT_TITLE_PATTERN = "^[a-zA-Z0-9\\s\\-&@$,;:'.]+$"; // small letters, capital letters, numbers, hyphen, ampersand, at the rate, dollar, comma, semi colon, colon, single quote
var VAL_ZIP_PATTERN = "^[a-zA-Z0-9\\s]+$"; // small letters, capital letters, numbers
var VAL_ALPHA_NUMERIC_PATTERN = "^[a-zA-Z0-9]+$"; // alpha numeric pattern - small, caps and numbers
var VAL_CITY_PATTERN = "^[a-zA-Z0-9\\s\\-()\\[\\]]+$"; // small letters, caps, numbers, space, hyphen, paranthesis, square braces
var VAL_CORP_NAME_PATTERN = "^[a-zA-Z0-9&/\\s\\-,_.]+$"; // small letters, caps, numbers, ampersand, forward slash, space, hyphen, comma, underscore, dot
var VAL_CORP_DESC_PATTERN = "^[a-zA-Z0-9&\\-\\s!().,'\"@$]+"; // small letters, caps, numbers, amp, hyphen, space, exclamation, braces, dot, comma, single quote, double quotes, at the rate, dollar.
var VAL_EDU_DEGREE_PATTERN = "^[a-zA-Z0-9.,\\s]+$"; // alpha numeric pattern - small, caps, numbers, dot, comma, space
var VAL_TAGLINE_PATTERN = "^[a-zA-Z0-9\\s\\-&,.'\"+#/]+$"; // alpha numeric pattern - small, caps, numbers, dot, comma, hyphen, space,single quote, double quotes
var VAL_VCE_NAME_PATTERN = "^[a-zA-Z0-9\\s\\-&@$_.,;:'\"]+$"; // small letters, capital letters, numbers, hyphen, ampersand, at the rate, dollar, underscore,dot, colon, single quote, double quotes
var VAL_SUB_VCE_DESC_PATTERN = "^[a-zA-Z0-9\\s\\-&@$_.,;:'\"]+$"; // small letters, caps, numbers, amp, hyphen, space, exclamation, braces, dot, comma, single quote, double quotes, at the rate, dollar.
var VAL_MILE_STONE_NAME_PATTERN = "^[a-zA-Z0-9\\s\\-&@$_.,;:'\"/\\[\\]()\\{\\}]+$"; // small letters, caps, numbers, amp, hyphen, space, exclamation, braces, dot, comma, single quote, double quotes, at the rate, dollar.

/*************************************************************************
 * Function Name : trimSpaces
 * Description   : Trims the given data
 *************************************************************************/

function trimSpaces (Field)  
{  				 
	var inDate = Field.value;  
	if(isWhitespace (inDate))   
	{  
		Field.value='';  
		inDate = Field.value;  
	}  
	if(inDate.length!=0)  
	{  
		var i=0 ;  
		var j=0 ;  
		for(i=0;i<inDate.length;i++)  
		{   
			if(inDate.charAt(i)==' ')  
			{
				j++;  
			}
			else
			{
				break;  
			}
		} 
		inDate =inDate.substring(j,inDate.length);  
		var k=0  
		if(inDate.charAt(inDate.length-1)==' ')  
		{   
			for(i=inDate.length-1;i>=0;i--)  
			{   
				if(inDate.charAt(i)==' ')  
				{  
					k++;
				}  
				else  
				{  
					break;
				}  
			}    
		}  
		inDate =inDate.substring(0,inDate.length-k);  
	}  
	Field.value= inDate;  
} 

/*************************************************************************
 * Function Name : getDescListData
 * Description   : Assign the respective value of an array from one to another by passing index
 * Usage         : onChange
 * Parameters    :
                   descArray - Destination Array
				   codeArray - Source Array
				   theObj    - Source Object - Combo
				   descObj   - Destination Object - Combo
				   index     - 
*************************************************************************/

function getDescListData(descArray,codeArray,theObj,descObj,index) 
{

	if (descObj.options.length == 0)
	{
		descObj.options[0] = new Option();
	}
//	alert('codeArray ]'+codeArray.length);
	for(var i=0;i<descArray.length;i++)
	{
		var selectedid = getSelectedListValue(theObj);
//		alert('selectedid'+selectedid);
//		alert('codeArray[i]'+codeArray[i]);
		if(selectedid==codeArray[i])
		{ 
//			alert('codeArray[i]'+codeArray[i]);
			descObj.options[index].text =descArray[i]; 
			descObj.options[index].value=descArray[i]; 
			break;
		}
		else
		{
			descObj.options[index].text =''; 
			descObj.options[index].value=''; 
//			break;
		}
	}
	if(0==theObj.selectedIndex)
	{     
		descObj.value="";    
	}
}


/*************************************************************************
 * Function Name : getDescData
 * Description   : assign the respective value of an array from one to another
 * Usage         : onChange
 * Parameters    :
                   descArray - Description Array
				   codeArray - Code Array
				   theObj    - Source Object - Combo
				   descObj   - Destination Object

*************************************************************************/

function getDescData(descArray,codeArray,theObj,descObj) 
{	
//	alert("inside getdescdata");
	for(var i=0;i<descArray.length;i++)
	{
		var selectedid = getSelectedListValue(theObj);
//		alert('selectedid'+selectedid);
//		alert('codeArray[i]'+codeArray[i]);
		if(selectedid==codeArray[i])
		{ 
			descObj.value=descArray[i]; 
//			alert('Val'+descObj.value);
			break;
		}	  
	}
	if(0==theObj.selectedIndex)
	{     
		descObj.value="";    
	}
}

/*************************************************************************
 * Function Name : getDescDataOverRide
 * Description   : assign the respective value of an array from one to another
 * Usage         : onChange
 * Parameters    :
                   descArray - Description Array
				   codeArray - Code Array
				   codeArray2 - Code Array
				   theObj    - Source Object - Combo
				   selval	- Source Object - Combo
				   descObj   - Destination Object


*************************************************************************/

function getDescDataOverRide(descArray,codeArray,codeArray2,theObj,descObj,selval) 
{	
//	alert("inside getdescdata");
	for(var i=0;i<descArray.length;i++)
	{
		var selectedid = getSelectedListValue(theObj);
		var selectedid2 = getSelectedListValue(selval);
//		alert('selectedid :'+selectedid);
//		alert('codeArray[i] :'+codeArray[i]);
//		alert('codeArray2[i] :'+codeArray2[i]);
		if(selectedid==codeArray[i] && selectedid2==codeArray2[i])
		{ 
			descObj.value=descArray[i]; 
//			alert('Val ---- >'+descObj.value);
			break;
		}	  
	}
	if(0==theObj.selectedIndex)
	{     
		descObj.value="";    
	}
}


/*************************************************************************
 * Function Name : getSelectedListValue
 * Description   : getting the value selected in the optionBox
 * Usage         : onSubmit
 * Parameters    :
                   selectList - object from where the value is to be retrieved
 *************************************************************************/

function getSelectedListValue(selectList)
{
	var value = selectList.options[selectList.selectedIndex].value;
//	alert(value);
	if (typeof value == 'undefined' || value == null || value == '')
		value = selectList.options[selectList.selectedIndex].text;
	
	return value;
}


/*************************************************************************
 * Function Name : setLovValues
 * Description   : Sets the selected value in the option box
 * Parametrs     : 
                   lovName  - object where the value be set.
                   lovValue - value which is to be set. 
*************************************************************************/

function setLovValues(lovName,lovValue)
{
	var i ;
	for(i=0;i<lovName.options.length;i++)
	{	     
		if(lovName.options[i].value==lovValue)
			lovName.options[i].selected=true;	 
	}
}	 	
	
/*************************************************************************
 * Function Name : clearForm
 * Description   : Clears the form Objects of the screen
 * Parameters    : 
                   formObj - form object/name
  *************************************************************************/

function clearForm(formObj)
{
	for( i = 0; i < formObj.elements.length; i++)
	{
		if(formObj.elements[i].type=="textarea")
		{
			formObj.elements[i].value="";
		}
		else if(formObj.elements[i].type=="text")
		{
			formObj.elements[i].value="";
		}
		else if(formObj.elements[i].type=="select-one" )
		{
			if(formObj.elements[i].length > 0)
				formObj.elements[i].options[0].selected=true;
		}
		else if(formObj.elements[i].type=="checkbox" )
		{
			formObj.elements[i].checked=false;
		}
		else if(formObj.elements[i].type=="radio" )
		{
			formObj.elements[i].checked=false;
		}
	}
}

/*************************************************************************
 * Function Name : fillOption
 * Description   : Populates the single array from first postion
 * Parameters    : 
				   elname - object where values to be populated
 *************************************************************************/

function fillOption(elname,elValues)
{
	var objField = document.getElementById(elname);
	if(elValues != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for ( var i = 0; i< elValues; i++ ) 
		{
			objField.options[i+1] = new Option();
			objField.options[i+1].text  = i+1;
			objField.options[i+1].value = i+1;
		}
	}
	return;
}


/*************************************************************************
 * Function Name : Optpopulate
 * Description   : Populates the single array from first postion
 * Parameters    : 
                   obj    - array values to be populated
				   elname - object where values to be populated
 *************************************************************************/

function Optpopulate(obj,elname)
{
	var objField = document.getElementById(elname);
	if(obj.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for ( var i = 0; i< obj.length; i++ ) 
		{			
			if(obj[i]!="")
			{   objField.options[i+1] = new Option();
				objField.options[i+1].text  = obj[i];
				objField.options[i+1].value = obj[i];
			}
		}
	}
	return;
}

/*************************************************************************
 * Function Name : OptpopulateRem
 * Description   : Removes the previous values and Populates the single array from first postion
 * Parameters    : 
                   obj1   - values(array) to be populated
				   obj2   - text values   to be populated 
				   elname - object to be populated
 *************************************************************************/

function OptpopulateRem(obj,elname)
{
	var objField = document.getElementById(elname);
	for ( var i = (objField.length-1); i>=0 ; i-- ) 
	{
		objField.remove(i);
	}

	if(obj.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for ( var i = 0; i< obj.length; i++ ) 
		{			
			if(obj[i]!="")
			{   objField.options[i+1] = new Option();
				objField.options[i+1].text  = obj[i];
				objField.options[i+1].value = obj[i];
			}
		}
	}
	return;
}

/*************************************************************************
 * Function Name : Optpopulate1
 * Description   : Populates the list of arrays from first postion
 * Parameters    : 
                   obj1   - array containing the values
				   obj2   - array containing the text(display)
				   elname -  object to be populated
*************************************************************************/

function Optpopulate1(obj1,obj2,elname)
{
	var objField = document.getElementById(elname);
	if(obj1.length != 0 && obj2.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for (var i = 0; i< obj1.length; i++ ) 
		{
			if(obj1[i]!="" && obj2[i]!="")
			{				
				objField.options[i+1] = new Option();
				objField.options[i+1].text  = obj2[i];
				objField.options[i+1].value = obj1[i];
			}		
		}
	}
	else
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
	}
	return;
}


/*************************************************************************
 * Function Name : Optpopulate0
 * Description   : Populates the list of arrays from zero postion
  * Parameters   : 
                   obj1   - array containing the values
				   obj2   - array containing the text(display)
				   elname -  object to be populated
*************************************************************************/

function Optpopulate0(obj1,obj2,elname)
{
	var objField = document.getElementById(elname);
	if(obj1.length != 0 && obj2.length != 0)
	{
		for ( var i = 0; i< obj1.length; i++ ) 
		{
			if(obj1[i]!="" && obj2[i]!="")
			{   
				objField.options[i] = new Option();
				objField.options[i].text  = obj2[i];
				objField.options[i].value = obj1[i];
			}
		}
	}
	return;
}

/*******************************************************************************
Function Name	:	checkDecimalPostion(amt,name)
Description		:	To check the valid decimals 
Usage           :   onSubmit
Parameters      :    
                    amt - amount field
					name- object name (For Eg . Transaction Amount)
*******************************************************************************/

function checkDecimalPostion(amt,name)
{
	var amount=amt.value;
    if(amt.value=="") return true;
	
	if (isFloat(amt,name))
    {
		for (var i=0;i<amt.value.length;i++)
        {
			var c=amt.value.charAt(i);
			if(c==".")
			{
				if((i!=(amt.value.length-3)) && (i!=(amt.value.length-2)))
               	{
					alert("Invalid decimal position for "+ name + "\n Put atleast one digit before decimal and not more than two digits after decimal");
                	amt.focus();
                	return false;
               	}
			}
		}
        return true;
    }
    else
    {
		return false;
	}
}


/*******************************************************************************
Function Name	:	isFloat(varIn)
Description		:	To check the float value 
Usage           :   onSubmit
Parameters      :
                    varIn - object
*******************************************************************************/

function isFloat(varIn)
{
	if(!parseFloat(varIn.value) && parseFloat(varIn.value)!=0)
	  {
		return false;
	  }
     return true;
}


/*************************************************************************
 * Function Name		: Numval
 * Description			: Validates the given Amount;
 * Called From (with arguments):on blur event of the amount  fields 
 * Calls (with Parameters): form name
 * Parameters             : param - amount field
 *************************************************************************/

function Numval(param)
{  
	var curedit = 3;
	var num = param.value; 
	if(isWhitespace (num)) 
	{
		param.value='';
		num = param.value; 
	}
	var i=0 ;
	var j=0 ;
	for(i=0;i<num.length;i++)
	{ 
		if(num.charAt(i)==' ')
			j++;
		else 
			break;
	} 
	num =num.substring(j,num.length);
	var k=0
	if(num.charAt(num.length-1)==' ')
	{ 
		for(i=num.length-1;i>=0;i--)
		{ 
			if(num.charAt(i)==' ')
			{
				k++;
			}
			else
			{
				break 
			}
		}  
	}
	num =num.substring(0,num.length-k);
	var numlen = num.length;
	if(numlen==0) 
	{
		param.value=''; 
		return true;
	}
	var num = param.value; 
	var to = num.indexOf('.',0);
	if(isNaN(param.value))
	{
		alert('Please Enter a Valid Amount');
		param.value ='';
		param.focus();
		return false;
	}
	for(i=0;i<=num.length;i++)
	{ 
		if(num.charAt(i)=='-')
		{
			alert('Please Enter a Valid Amount');
			param.value ='';
			param.focus();
			return false;
		}
	}
	if(num.indexOf('.') > -1) 
	{
		var v4 = num.substring(num.indexOf('.')+1);
		if(v4.length>parseInt(curedit))
		{
			if(curedit == 0)
				alert('Decimal digits not allowed for the selected currency');
			else
				alert('Maximum Decimal digits allowed for the selected currency is '+curedit);
			param.value ='';
			param.focus();
			return false;
		}
	}		
	return true;
}


/*************************************************************************
 * Function Name : isWhitespace
 * Description   : Checks White Spaces
  *************************************************************************/

function isWhitespace (s)
{   
	var reWhitespace = /^[ ]+$/ 
	return (reWhitespace.test(s));
}


/*************************************************************************
 * Function Name : amountFormat
 * Description   : Adds Zeros to the Given Amount
 * Parameters    : 
                   amtObj - amount field
				   Zeros  - n. of. zeros to be added
 *************************************************************************/

function amountFormat(amtObj,Zeros)
{
	var amt = amtObj.value;
	var addzero = '';
	for(i=0;i<Zeros;i++)
		addzero += '0';
	
	amtObj.value = amt+addzero;
	return;
}


/*************************************************************************
 * Function Name : checkAlphaNumeric
 * Description   : Validates Non - AlphaNumeric Characters
 * Usage         :   onSubmit

 * Parameters    : 
                   param - object
 *************************************************************************/
  
function checkAlphaNumeric(param)
{

	var numflag = false;
	var charflag = false;
	var val=param.value;


	for(var i=0;i<val.length;i++)
	{
		var pos1 = i;
		var pos2 = i+1;
		var element = val.substring(parseInt(pos1),parseInt(pos2));

		if(isNaN(element))
		{
			charflag = true;
		}
		else
		{
			numflag = true;
		}
	}
	if(!numflag)
	{
		//alert('Password should contain atleast one Number');
		return  true;
	}
	else if(!charflag)
	{
		//alert('Password should contain atleast one Character');
		return true;
	}
}

/*************************************************************************
 * Function Name : checkEmail
 * Description   : Validates Email Id
 *  Usage        :   onSubmit

 * Parameters    : 
                   emailStr - value of the email field 
*************************************************************************/

function checkEmail(emailStr) 
{
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address	fits the user@domain format.  It also is used to separate the username 	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special	characters.  We don't want to allow special characters in the address. 	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.For example, in john.doe@somewhere.com, john and doe are words.Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			//alert("Ths username contains invalid characters.");
			return false;	
	   }
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			//alert("Ths domain name contains invalid characters.");
			return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) 
	{
		// user is not valid
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				//alert("Destination IP address is invalid!");
				return false;
		   }
		}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			//alert("The domain name does not seem to be valid.");
			return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word,representing country (uk, nl), and that there's a hostname preceding the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len < 2)
	{
		//alert("This address is missing a hostname!");
		return false;
	}
	return true;
}


/*************************************************************************
 * Function Name : checkBlankSpace
 * Description   : Validates Blank Characters 
 * Usage         : onSubmit

 * Parameters    : s - field value
 *************************************************************************/

function checkBlankSpace(s) 
{
	while (s.substring(0,1) == ' ') 
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') 
	{
		s = s.substring(0,s.length-1);
	}
	return trim(s);
}


/*************************************************************************
 * Function Name : checkSpecialChars
 * Description   : Validates Special Characters 
 *  Usage        : onSubmit

 * Parameters    : Field - object which is to be checked
 *************************************************************************/

function checkSpecialChars(Field)
{
	var val = Field.value;
	var flag;
	for(i=0;i<val.length;i++)
	{
		if(val.charAt(i)=='#' || val.charAt(i)=='~' || val.charAt(i)=='^' || val.charAt(i)=='~' || val.charAt(i)==',' || val.charAt(i)=='.')
			return true;		
	}
}

/*************************************************************************
 * Function Name : checkNumber
 * Description   : Validates Number 
 *  Usage        : onSubmit

 * Parameters    : field - object

*************************************************************************/

function checkNumber(field)
{
	var num = field.value; 
	var i=0 ;
	var j=0 ;
	for(i=0;i<num.length;i++)
	{ 
		if(num.charAt(i)==' ')
			j++;
		 else 
			break;
	} 
	num =num.substring(j,num.length);
	var k=0
	if(num.charAt(num.length-1)==' ')
	{ 
		for(i=num.length-1;i>=0;i--)
		{ 
			if(num.charAt(i)==' ')
				k++;
			else
			   break 
		}  
	}
	num =num.substring(0,num.length-k);
	var numlen = num.length;
	if(numlen==0) 
	{ 
		field.value=''; 
		field.focus();
		return false;
	}
	var num = field.value; 
  	var to = num.indexOf('.',0);
	if(isNaN(field.value))
		return true;
	for(i=0;i<=num.length;i++)
	{ 
		if(num.charAt(i)=='-')
			return true;
	}
	if(num.indexOf('.') == -1)
	{
		if (parseInt(num) == 0)
			return true; 
	}
	else 
	{
		var n1 = num.substring(0,num.indexOf('.'));
		var n2 = num.substring(num.indexOf('.')+1);
		if((parseInt(n1) == 0) && (parseInt(n2) == 0))
			return true; 
	}
}


/*************************************************************************
 * Function Name : checkDecimalPlaces
 * Description   : Validates Decimal Places 
 * Usage         : onSubmit
 * Parameters    : obj           - amount field
				   decimalplaces - no. of decimals 
 *************************************************************************/

function checkDecimalPlaces(obj,decimalplaces)
{
	amt=obj.value;
	if(amt.indexOf('.')> -1) 
	{ 
		amt=amt.substring(amt.indexOf('.')+1,amt.length)
		if(amt.length > decimalplaces)
			return true;
		else 
			return false;
	}
	else
		return false;
}

/*************************************************************************
 * Function Name : checkValidDate
 * Description   : Validates the Date
 *************************************************************************/

function checkValidDate(Field) 
{
	var inDate = Field.value;
	var FName  = Field.name;
	var i=0 ;
	var j=0 ;
	for(i=0;i<inDate.length;i++)
	{ 
		if(inDate.charAt(i)==' ')
		    j++;
		else break;
	} 
	inDate =inDate.substring(j,inDate.length);
	var k=0;
	if(inDate.charAt(inDate.length-1)==' ')
	{ 
		for(i=inDate.length-1;i>=0;i--)
		{ 
			if(inDate.charAt(i)==' ')
				k++;
			else break; 
		}  
	}
	inDate = inDate.substring(0,inDate.length-k);
	if(inDate.length==0)
		return false; 
	else
	{
		var daysInMonth = new Array(12);
		daysInMonth[1] = 31;
		daysInMonth[2] = 29;  
		daysInMonth[3] = 31;
		daysInMonth[4] = 30;
		daysInMonth[5] = 31;
		daysInMonth[6] = 30;
		daysInMonth[7] = 31;
		daysInMonth[8] = 31;
		daysInMonth[9] = 30;
		daysInMonth[10] = 31;
		daysInMonth[11] = 30;
		daysInMonth[12] = 31;
		var sep = '/';
		var strDate = '';
		var strMonth = '00';
		var strCon = '0';
		var invalidDate = 0;

		invalidDate = 0;
		if (inDate.indexOf('-') > 0)
			sep = '-';

		if (inDate.indexOf('.') > 0)
			sep = '.';
		
		var inDay = inDate.substring(0,inDate.indexOf( sep ));
		if (inDay.length> 0 && inDay.length <= 2) 
		{
			inDay = parseInt(inDay, 10);
		} 
		else
		{
			invalidDate = 1;
		}
		var inMonth   = inDate.substring(inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ));
		if (inMonth.length> 0 && inMonth.length <= 2)
		{
			inMonth = parseInt(inMonth, 10);
		}
		else
		{
			invalidDate = 1;
		}
		var inYear  = inDate.substring(inDate.lastIndexOf( sep ) + 1, inDate.length);
		if (inYear.length < 1 || inYear.length> 4 || inYear.length == 3 )
		{
			invalidDate = 1;
		}
		else 
		{
			inYear = parseInt(inYear, 10);
		}
		if (invalidDate==0) 
		{
			if (inYear < 100 && inYear> 40) 
			{
				inYear += 1900;
			}
			if (inYear < 100 && inYear <= 40) 
			{
				inYear += 2000;
			}
		}
		if( inMonth < 1 || inMonth> 12 )
		{
			invalidDate = 1;
		}
		if ((inDay < 1) || (inDay> daysInMonth[inMonth]) )
		{
			invalidDate = 1; 
		}
		if ((inMonth == 2) && (inDay>  (  ( (inYear % 4 == 0) && ( !(inYear % 100 == 0) || (inYear % 400 == 0) ) ) ? 29 : 28 ) )) 
		{
			invalidDate = 1;
		}
		if (invalidDate == 1 || isNaN(inDay) || isNaN(inMonth) || isNaN(inYear) )
		{
			return false;
		}
		else 
		{
			return true;
		}
	}
}

/*************************************************************************
 * Function Name : checkInteger
 * Description   : Validates the Integer
 * Usage         : onSubmit
 * Parameters    : 
                    s - field value
*************************************************************************/

function checkInteger(s)
{
	var i;
    for (i = 0;i<s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function isDigit(c)
{   
	return ((c >= "0") && (c <= "9"))
}


/*************************************************************************
 * Function Name : checkWhitespace
 * Description   : Validates the White Spaces
 * Usage         : onSubmit
 * Parameters    : 
                    Field - object
 *************************************************************************/

function checkWhitespace(Field)
{
	var inDate = Field.value;
	if(isWhitespace (inDate)) 
	{
		Field.value='';
		inDate = Field.value;
	}
	if(inDate.length!=0)
	{
		var i=0 ;
		var j=0 ;
		for(i=0;i<inDate.length;i++)
		{ 
			if(inDate.charAt(i)==' ')
				j++;
			else break;
		} 
		inDate =inDate.substring(j,inDate.length);
		var k=0
		if(inDate.charAt(inDate.length-1)==' ')
		{ 
			for(i=inDate.length-1;i>=0;i--)
			{ 
				if(inDate.charAt(i)==' ')
					k++;
				else break; 
			}  
		}
		inDate =inDate.substring(0,inDate.length-k);
	}
	Field.value= inDate;
}


/*****************************************************************************************
 * Function Name : checkGreaterDate
 * Description   : Compares the greater than date (dd-mm-yy)
 * Usage         : onSubmit
 * Parameters    :
                   dateObj1 - from Date Field
				   dateObj2  - To Date Field
*****************************************************************************************/

function checkGreaterDate(dateObj1,dateObj2)
{
	var startDate	= dateObj1.value;
	var endDate		= dateObj2.value;
	var separator	= "-";
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();

	fromDateArray		= startDate.split(separator);
	toDateArray			= endDate.split(separator);
//	alert('fromDateArray'+fromDateArray);
//	alert('toDateArray'+toDateArray);

	if(toDateArray[1].length==1)
	{
	   toDateArray[1]='0'+toDateArray[1]
	}
	if(fromDateArray[1].length==1)
	{
	   fromDateArray[1]='0'+fromDateArray[1]
	}
	if(toDateArray[0].length==1)
	{
       toDateArray[0]='0'+toDateArray[0]
	}
	if(fromDateArray[0].length==1)
	{
	   fromDateArray[0]='0'+fromDateArray[0]
	}
//	alert('toDateArray[2] :'+toDateArray[2]);
//	alert('fromDateArray[2] :'+fromDateArray[2]);
	if (toDateArray[2] < fromDateArray[2]) 
	{
		return false;
	}
//	alert('toDateArray[1] :'+toDateArray[1]);
//	alert('fromDateArray[1] :'+fromDateArray[1]);

	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] < fromDateArray[1])) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] < fromDateArray[0])) 
	{
		return false;
	}
	return true;
}

/*****************************************************************************************
 * Function Name : populateArray
 * Description   : populates the javascript array for dependencies combo boxes dynamically
 * Usage         : onChange
 * Parameters    :
                   array - array value to be populated
				   id    - Destination Object
*****************************************************************************************/

function populateArray(array,id)
{
	var x,counter;

	counter=id.options.length;

	for(x=counter-1;x>0;x--)
		id.options.remove(x);
	for(x=0;x<array.length;x++)
	{
		element=document.createElement("OPTION");
		element.text=array[x];
		id.options.add(element,x+1);
	}	 	 
}

/*****************************************************************************************
 * Function Name : loadArray
 * Description   : populates the javascript array for dependencies combo boxes dynamically
 * Usage         : onChange
 * Parameters    :
                   destarray - array value to be populated
				   id1       - Souce object
				   id1       - Destination Object
*****************************************************************************************/

function loadArray(destarray,id1,id2)
{
	var array1	= new Array();
	var var1 = id1.options[id1.selectedIndex].value;
	var var2 = var1;//var1.substring(var1.indexOf('^')+1);
	if(var2=='ALL COMPANIES')
	{
		populateArray(destarray,id2);
		return;
	}
	j = 0;
	for(i=0;i<destarray.length;i++)
	{
		var var3	= destarray[i];
		var var4	= var3.substring(0,var3.indexOf('-'));
		if(var4==var2)
		{
			array1[j] = var3;
			j++;
		}		
	}
	if (id1.selectedIndex != 0)
	{
		populateArray(array1,id2);
	}
	else
		return;
}

/*****************************************************************************************
 * Function Name : checkDuplicateCombo
 * Description   : Validates the duplicate values in the Combo Box
 * Usage         : onSubmit,OnBlur
 * Parameters    : 
                   id     -  object
                   obj    -  
				   length - object length
				   index  - selected index of the object
				   elem   - 
******************************************************************************************/

function checkDuplicateCombo(id,obj,length,index,elem)
{
	var val = id.options[id.selectedIndex].value;
	var objValue = '';

	for(i=0;i<length;i++)
	{
		if(i==index)
		{
		}
		else
		{
			objValue = document.forms[1].elements[obj+i].options[document.forms[1].elements[obj+i].selectedIndex].value;
//			alert('objValue :'+objValue);
//			alert('val :'+val);
			if(objValue != '')
			if(objValue==val)
			{
//				document.forms[1].elements[obj+i].options[document.forms[1].elements[obj+i].selectedIndex].value =='';
				document.forms[1].elements[elem].options[0].value =='';
				document.forms[1].elements[elem].options[0].selected =true;
//				alert(document.forms[1].elements[obj+i.id].options.length);
				alert('Please do not Select the Duplicate Values');
				return;
			}
			else
			{
//				alert('It Looks Fine');
//				return;
			}
		}		
	}
}

/*****************************************************************************************
 * Function Name : checkDuplicateText
 * Description   : Validates the duplicate values in the looping text box
 * Usage         : onSubmit
 * Parameters    :
                   obj1 - no. of. textboxes
				   obj2 - object
 *****************************************************************************************/
function checkDuplicateText(obj1,obj2)
{
	for(i=0;i<obj1;i++)
	{
		 for(j=1;j<obj1;j++)
		 {       
			if(i!=j)
			{
				if(obj2[i].value ==obj2[j].value)
				{
					alert('Please do not Select the Duplicate Values');
					obj2[i].focus();
					return;
				}
			}
		}
	}	
}

/*************************************************************************
 * Function Name : comboRemover
 * Description   : Empty the Combo Box
 * Parameters    : elname - object to be emptied.
 *************************************************************************/

function comboRemover(elname)
{
	var objField = document.getElementById(elname);
	for ( var i = (objField.length-1); i>=0 ; i-- ) 
	{
		objField.remove(i);
	}
	objField.options[0] = new Option();
	objField.options[0].text  = "";
	objField.options[0].value = "";
	return;
}


/*************************************************************************
 * Function Name : DateValidation
 * Description   : Validates the Date and changes to Specified Format
 * Usage         : onBlur,onSubmit
 * Parameters    : 
                   dateformat - desired format
				   dateField  - Date Field
 *************************************************************************/

function DateValidation(dateFormat,dateField)
{
	if(!(dateField.value=="" || dateField.value==null))
	{
		var strDate=dateField.value;
		if (strDate.indexOf('-') < 0 )
		{
			var strDay=strDate.substring(0,2);
			var strMonth=strDate.substring(2,4);
			var strYear=strDate.substring(4,6);
			 
			strDate = strDay + "-" + strMonth +"-" + strYear;
			dateField.value=strDate;
		}
		var inDate = dateField.value;
		var consFormat = dateFormat.value;

		var daysInMonth = new Array(12);
		daysInMonth[1] = 31;
		daysInMonth[2] = 29;  
		daysInMonth[3] = 31;
		daysInMonth[4] = 30;
		daysInMonth[5] = 31;
		daysInMonth[6] = 30;
		daysInMonth[7] = 31;
		daysInMonth[8] = 31;
		daysInMonth[9] = 30;
		daysInMonth[10] = 31;
		daysInMonth[11] = 30;
		daysInMonth[12] = 31;
 
		var inDay = '';
		var inMonth = '';
		var inYear = '';
		var FormatSep = '';
		var sep = '/';
		var strDate = '';
		var strMonth = '00';
		var strCon = '0';
		var invalidDate = 0;

		if (inDate.indexOf('-') > 0 )
			sep = '-';
		if (inDate.indexOf('.') > 0 ) 
			sep = '.';
		
		if( consFormat.substring(0,2) == 'dd' )
		{
			FormatSep = consFormat.substring(2,3);
			inDay = inDate.substring( 0, inDate.indexOf( sep ) );
			inMonth = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
			inYear  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );
		}
		else if( consFormat.substring(0,2) == 'MM' )
		{
			FormatSep = consFormat.substring(2,3);
			inMonth = inDate.substring( 0, inDate.indexOf( sep ) );
			inDay = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
			inYear  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );
		}
		else
		{
			FormatSep = consFormat.substring(4,5);
			inYear = inDate.substring( 0, inDate.indexOf( sep ) );
			inMonth = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
			inDay  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );
		};
		invalidDate = 0;
		if (inDay.length > 0 && inDay.length <= 2) 
			inDay = parseInt(inDay, 10);
		else
			invalidDate = 1;

		if (inMonth.length > 0 && inMonth.length <= 2)
			inMonth = parseInt(inMonth, 10);
		else
			invalidDate = 1;

		if (inYear.length < 1 || inYear.length > 4 || inYear.length == 3 )
			invalidDate = 1;
		else 
			inYear = parseInt(inYear, 10);

		if (invalidDate==0) 
		{
			if (inYear < 100 && inYear > 40) 
				inYear += 1900;

			if (inYear < 100 && inYear <= 40) 
				inYear += 2000;
		}
		if( inMonth < 1 || inMonth > 12 )
			invalidDate = 1;

		if ((inDay < 1) || (inDay > daysInMonth[inMonth]) )
			invalidDate = 1; 

		if ((inMonth == 2) && (inDay >  (  ( (inYear % 4 == 0) && ( !(inYear % 100 == 0) || (inYear % 400 == 0) ) ) ? 29 : 28 ) )) 
			invalidDate = 1;

		if (invalidDate == 1 || isNaN(inDay) || isNaN(inMonth) || isNaN(inYear) )
		{
			alert('Please Enter a Valid Date\r\nExpected Date Format is '+consFormat+' or ddmmyy');
			dateField.value="";
			dateField.focus();
			return; 
		}
		else 
		{
			inDay = strCon + inDay;
			inMonth = strCon + inMonth;

			if( consFormat.substring(0, 2) == 'dd' )
			{
				strDate = inDay.substring(inDay.length-2,inDay.length) + FormatSep + inMonth.substring(inMonth.length-2,inMonth.length) + FormatSep + inYear;
			}
			else if( consFormat.substring(0, 2) == 'MM' )
			{
				strDate = inMonth.substring(inMonth.length-2,inMonth.length) + FormatSep + inDay.substring(inDay.length-2,inDay.length) + FormatSep + inYear;
			}
			else
			{
				strDate =  inYear + FormatSep + inMonth.substring(inMonth.length-2,inMonth.length) + FormatSep + inDay.substring(inDay.length-2,inDay.length)
			};
		}
		dateField.value=strDate;  
		return;
	}
}


/*************************************************************************
 * Function Name : validateDate
 * Description   : Validates the Date and changes to Specified Format
 * Usage         : onSubmit
 * Parameters    : 
                   dateformat - desired format
				   dateField  - Date Field 
 *************************************************************************/

function validateDate(dateField)
{
 	if(!(dateField=="" || dateField==null))
	{
		var inDate = dateField;
		var daysInMonth = new Array(12);
		daysInMonth[1] = 31;
		daysInMonth[2] = 29;  
		daysInMonth[3] = 31;
		daysInMonth[4] = 30;
		daysInMonth[5] = 31;
		daysInMonth[6] = 30;
		daysInMonth[7] = 31;
		daysInMonth[8] = 31;
		daysInMonth[9] = 30;
		daysInMonth[10] = 31;
		daysInMonth[11] = 30;
		daysInMonth[12] = 31;
 
		var inDay = '';
		var inMonth = '';
		var inYear = '';
		var sep = DATE_SEP;
		var strDate = '';
		var strMonth = '00';
		var strCon = '0';
		var invalidDate = 0;

		if (inDate.indexOf('-') > 0 )
			sep = '-';
		if (inDate.indexOf('.') > 0 ) 
			sep = '.';

		inDay = inDate.substring( 0, inDate.indexOf( sep ) );
		inMonth = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
		inYear  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );
		
		invalidDate = 0;		
		if (inDay.length > 0 && inDay.length <= 2) 
			inDay = parseInt(inDay, 10);
		else
			invalidDate = 1;
			
		if (inMonth.length > 0 && inMonth.length <= 2)
			inMonth = parseInt(inMonth, 10);
		else
			invalidDate = 1;

		if (inYear.length < 1 || inYear.length > 4 || inYear.length == 3 )
			invalidDate = 1;
		else 
			inYear = parseInt(inYear, 10);

		if (invalidDate==0) 
		{
			if (inYear < 100 && inYear > 40) 
				inYear += 1900;

			if (inYear < 100 && inYear <= 40) 
				inYear += 2000;
		}
	
		if( inMonth < 1 || inMonth > 12 )
			invalidDate = 1;	

		if ((inDay < 1) || (inDay > daysInMonth[inMonth]) )
			invalidDate = 1; 		

		if ((inMonth == 2) && (inDay >  (  ( (inYear % 4 == 0) && ( !(inYear % 100 == 0) || (inYear % 400 == 0) ) ) ? 29 : 28 ) )) 
			invalidDate = 1;	
		
		if (invalidDate == 1 || isNaN(inDay) || isNaN(inMonth) || isNaN(inYear) )
		{
//			alert('Please Select a Valid Date');
//			dateField.value = "";
//			dateField.focus();
			return false; 
		}
		return true;
	}
}


/*************************************************************************
 * Function Name : formatDate
 * Description   : validates the date and format the date to long format Considering Month starts from 1 and
 					input date fromat 'dd-MM-yyyy'
 * Parameters    : 
                   dateField  - Date Field 
                   
 *************************************************************************/
 
 function getLongFormattedDate(dateField) {
	
 	if(validateDate(dateField)) {
 	
		var inDate = dateField;
 		var daysInMonth = new Array(12);
		daysInMonth[1] = "January";
		daysInMonth[2] = "February";  
		daysInMonth[3] = "March";
		daysInMonth[4] = "April";
		daysInMonth[5] = "May";
		daysInMonth[6] = "June";
		daysInMonth[7] = "July";
		daysInMonth[8] = "August";
		daysInMonth[9] = "September";
		daysInMonth[10] = "October";
		daysInMonth[11] = "November";
		daysInMonth[12] = "December";
		
		var inDay = '';
		var inMonth = '';
		var inYear = '';
		var sep = DATE_SEP;
		
		
		if (inDate.indexOf('-') > 0 )
			sep = '-';
		
		
		inDay = inDate.substring( 0, inDate.indexOf( sep ) );
		inMonth = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
		inYear  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );
		
		
		var strMonth = daysInMonth[parseInt(inMonth,10)];
		
		var formattedDate = inDay+" "+strMonth+" "+inYear;
		
		return formattedDate;
		
 	} else {
 		alert("Please select a valid date");
 	}
 	return "";
 	
 }
 
 

/*************************************************************************
 * Function Name : OptpopulateRem1
 * Description   : Removes the previous values and Populates the single array from first postion
 * Parameters    : 
                   obj1   - values(array) to be populated
				   obj2   - text values   to be populated 
				   elname - object to be populated
 *************************************************************************/

function OptpopulateRem1(obj1,obj2,elname)
{
	var objField = document.getElementById(elname);

	for ( var i = (objField.length-1); i>=0 ; i-- ) 
	{
		objField.remove(i);
	}

	if(obj1.length != 0 && obj2.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for ( var i = 0; i< obj1.length; i++ ) 
		{
			if(obj1[i]!="" && obj2[i]!="")
			{   
				objField.options[i+1] = new Option();
				objField.options[i+1].text  = obj2[i];
				objField.options[i+1].value = obj1[i];
			} 
		}
	}
	return;
}
 
/*************************************************************************
 * Function Name : OptpopulateRem
 * Description   : Removes the previous values and Populates the single array from first postion
 * Parameters    : 
                   obj    - values(array) to be populated
				   elname - object where values to be populated
*************************************************************************/
 
function OptpopulateRem(obj,elname)
{
	var objField = document.getElementById(elname);
	for ( var i = (objField.length-1); i>=0 ; i-- ) 
	{
		objField.remove(i);
	}

	if(obj.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		for ( var i = 0; i< obj.length; i++ ) 
		{   
			if(obj[i]!="")
			{   
				objField.options[i+1] = new Option();
				objField.options[i+1].text  = obj[i];
				objField.options[i+1].value = obj[i];
			}
		}
	}
	return;
}

/*************************************************************************
 * Function Name : Optpopulateall
 * Description   : populate two arrays in a single combo 
 * Parameters    : 
                   obj1 - values of the first list
				   obj2 - text values of the first list
				   obj3 - values of the second list
				   obj4 - text values of the second list
				   elname - object to be populated
				   
*************************************************************************/

function Optpopulateall(obj1,obj2,obj3,obj4,elname)
{
	var objField = document.getElementById(elname);
	if(obj1.length != 0 && obj2.length != 0)
	{
		objField.options[0] = new Option();
		objField.options[0].text  = "";
		objField.options[0].value = "";
		objField.options[1] = new Option();
		objField.options[1].text  = "All";
		objField.options[1].value = "A";
		for ( var i = 0; i< obj1.length; i++ ) 
		{	
			if(obj1[i]!="" && obj2[i]!="")
			{   
				objField.options[i+2] = new Option();
				objField.options[i+2].text  = obj2[i];
				objField.options[i+2].value = obj1[i];
			}		
		}
		if(obj1.length != 0 && obj2.length != 0)
		{
			for ( var j = 0; j< obj3.length; j++ ) 
			{		
				if(obj3[j]!="" && obj4[j]!="")
				{   
					objField.options[j+i+2] = new Option();
					objField.options[j+i+2].text  = obj4[j];
					objField.options[j+i+2].value = obj3[j];
				}		
			}
		}
	}
	return;
}

/*************************************************************************
 * Function Name : populateCombo
 * Description   : populates the javascript array for dependencies combo boxes dynamically
 * Parameters    : 
                   array1 - Values of the  first combo
				   array2 - Values of the  Second combo
				   array3 - Text Values of the Second Combo
				   obj    -  First Combo object
				   val    -   Second Combo object
                   
*************************************************************************/

function populateCombo(array1,array2,array3,obj,val)
{
//	alert('Value :'+val);
//	alert('Object :'+obj.value);
	var j=0,entry=0;
	var dumarray1 = new Array();
	var dumarray2 = new Array();
	var nullarray = new Array();
	comboRemover(val);
	
	for(i=0;i<array1.length;i++)
	{  
//		alert('Array :'+array1[i]);
		if(array1[i]==obj.value)
		{  
			dumarray1[j] = array2[i];
			dumarray2[j] = array3[i];
			j++;
			entry=1;
		}
		else
		{
			nullarray[j] = "";
		}
	}
	if(entry==1)
	{
		Optpopulate1(dumarray1,dumarray2,val);
	}
	else
	{
		Optpopulate(nullarray,val);
	}
}

/*************************************************************************
* Function Name : compareDateTime
* Description   : To Compare two Datetimes to find the greater ones. Used for Greater or Smaller DateTime Checking
* Parameters    : 
			      dateObj1    - Start DateTime
			      dateObj2    - End DateTime
*************************************************************************/

function compareDateTime(dateObj1, dateObj2) 
{
	var startDate	= dateObj1.value;
	var endDate		= dateObj2.value;
	var separator	= "-";
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();

	fromDateArray		= startDate.split(separator);
	toDateArray			= endDate.split(separator);
	
	if(toDateArray[1].length==1)
	{
	   toDateArray[1]='0'+toDateArray[1]
	}
	if(fromDateArray[1].length==1)
	{
	   fromDateArray[1]='0'+fromDateArray[1]
	}
	if(toDateArray[0].length==1)
	{
       toDateArray[0]='0'+toDateArray[0]
	}
	if(fromDateArray[0].length==1)
	{
	   fromDateArray[0]='0'+fromDateArray[0]
	}
	
	// hour
	var varToDateHour = toDateArray[3];
	if((varToDateHour != 12) && (toDateArray[5] == 'PM' || toDateArray[5] == 'pm' || toDateArray[5] == '1')) // '1' because AM = 0 and PM = 1
	{
		varToDateHour = 12 + toDateArray[3];
	}
	var varFromDateHour = fromDateArray[3];
	if((varFromDateHour != 12) && (fromDateArray[5] == 'PM' || fromDateArray[5] == 'pm'))
	{
		varFromDateHour = 12 + fromDateArray[3];
	}
	// minute
	if(toDateArray[4].length==1)
	{
	   toDateArray[4]='0'+toDateArray[4]
	}
	if(fromDateArray[4].length==1)
	{
	   fromDateArray[4]='0'+fromDateArray[4]
	}
		
	if (toDateArray[2] < fromDateArray[2]) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] < fromDateArray[1])) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] < fromDateArray[0])) 
	{
		return false;
	}
	
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] == fromDateArray[0]) && (varToDateHour < varFromDateHour)) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] == fromDateArray[0]) && (varToDateHour == varFromDateHour) && (toDateArray[4] < fromDateArray[4])) 
	{
		return false;
	}
	
	return true;
}

/*************************************************************************
* Function Name : compareDate
* Description   : To Compare two Dates to find the greater ones.Used for Greater or Smaller Date Checking
* Parameters    : 
			      dateObj1    - Start Date
			      dateObj2    - End Date
*************************************************************************/

function compareDate(dateObj1, dateObj2) 
{
	var startDate	= dateObj1.value;
	var endDate		= dateObj2.value;
	var separator	= "-";
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();

	fromDateArray		= startDate.split(separator);
	toDateArray			= endDate.split(separator);

	if(toDateArray[1].length==1)
	{
	   toDateArray[1]='0'+toDateArray[1]
	}
	if(fromDateArray[1].length==1)
	{
	   fromDateArray[1]='0'+fromDateArray[1]
	}
	if(toDateArray[0].length==1)
	{
       toDateArray[0]='0'+toDateArray[0]
	}
	if(fromDateArray[0].length==1)
	{
	   fromDateArray[0]='0'+fromDateArray[0]
	}
	if (toDateArray[2] < fromDateArray[2]) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] < fromDateArray[1])) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] < fromDateArray[0])) 
	{
		return false;
	}
	return true;
}

/*************************************************************************
* Function Name : compareGreaterDate
* Description   : To Compare two Dates to find the greater ones.Used for Greater or Smaller Date Checking
* Parameters    : 
			      dateObj1    - Start Date
			      dateObj2    - End Date
*************************************************************************/

function compareGreaterDate(dateObj1, dateObj2)
{
	var startDate	= dateObj1.value;
	var endDate		= dateObj2.value;
	var separator	= "-";
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();

	fromDateArray		= startDate.split(separator);
	toDateArray			= endDate.split(separator);

	if(toDateArray[1].length==1)
	{
	   toDateArray[1]='0'+toDateArray[1]
	}
	if(fromDateArray[1].length==1)
	{
	   fromDateArray[1]='0'+fromDateArray[1]
	}
	if(toDateArray[0].length==1)
	{
       toDateArray[0]='0'+toDateArray[0]
	}
	if(fromDateArray[0].length==1)
	{
	   fromDateArray[0]='0'+fromDateArray[0]
	}
	if (toDateArray[2] < fromDateArray[2]) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] < fromDateArray[1])) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] <= fromDateArray[0])) 
	{
		return false;
	}
	return true;
}

/*************************************************************************
* Function Name : checkEqualDate
* Description   : To Compare two Dates to find if both dates are equal
* Parameters    : 
			      dateObj1    - Start Date
			      dateObj2    - End Date
*************************************************************************/

function checkEqualDate(dateObj1, dateObj2) 
{
	var startDate	= dateObj1.value;
	var endDate		= dateObj2.value;
	var separator	= "-";
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();

	fromDateArray		= startDate.split(separator);
	toDateArray			= endDate.split(separator);
	if(toDateArray[1].length==1)
	{
	   toDateArray[1]='0'+toDateArray[1]
	}
	if(fromDateArray[1].length==1)
	{
	   fromDateArray[1]='0'+fromDateArray[1]
	}
	if(toDateArray[0].length==1)
	{
       toDateArray[0]='0'+toDateArray[0]
	}
	if(fromDateArray[0].length==1)
	{
	   fromDateArray[0]='0'+fromDateArray[0]
	}
	if (toDateArray[2] != fromDateArray[2]) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] != fromDateArray[1])) 
	{
		return false;
	}
	if ((toDateArray[2] == fromDateArray[2]) && (toDateArray[1] == fromDateArray[1]) && (toDateArray[0] != fromDateArray[0])) 
	{
		return false;
	}
	return true;
}

/*************************************************************************
 * Function Name : checkBoxSelectAll
 * Description   : To check all the checkboxes when the selectall checkbox is checked
 * Parameters    : 
                   formObj - form name 
				   field1  - select all checkbox field
				   field2  - loop checkboxes
*************************************************************************/

function checkBoxSelectAll(formObj,field1,field2)
{
	if (formObj != null)
	{
		var checkall = false;
		var length = formObj.elements.length;
		for (i = 0; i < length; i++)
		{
			if(formObj.elements[i].type == "checkbox" && formObj.elements[i].name == field1 && formObj.elements[i].checked == true)
			{
				checkall = true;
				continue;
			}
//			alert('a :'+formObj.elements[i].name)
			if (formObj.elements[i].type == "checkbox" && formObj.elements[i].name == field2 && checkall)
			{
				formObj.elements[i].checked = true;
			}
			else
			{
				formObj.elements[i].checked = false;
			}		
//			else
//				alert('b :'+formObj.elements[i].name);
		}			
	}
}

/*************************************************************************
 * Function Name : checkCharacter
 * Description   : Allows to enter alphanumeric characters
 * Usage         : onkeypress
*************************************************************************/

function checkCharacter(obj)
{
	if(trim(obj.value)=='' && (event.keyCode >= 48 && event.keyCode <=57))
		event.keyCode=0;
	if(!((event.keyCode >= 65 && event.keyCode <=90) || (event.keyCode >= 97 && event.keyCode <=122) || (event.keyCode >= 48 && event.keyCode <=57))&& event.keyCode !=32)
	{
		event.keyCode = 0;
	    return false;
	}
}

 /*************************************************************************
 * Function Name : Allows no SpecialCharacters in the textarea
 * Description   : Removes the previous values and Populates the single array from first postion
 * Usage         : onkeypress
 * Key Codes	 : space = 32	" = 34	$ = 36	& = 38	% = 37	( = 40	) = 41	* = 42	+ = 43	, = 44	- = 45	. = 46	/ = 47	
				   : = 58		; = 59	? = 63	@ = 64	} = 125	{ = 123
				   		
 *************************************************************************/

function checkTextSpecialCharacter(obj)
{
//	alert(event.keyCode);
	if(!((event.keyCode >= 65 && event.keyCode <=90) || (event.keyCode >= 97 && event.keyCode <=122) || (event.keyCode >= 48 && event.keyCode <=57)) && event.keyCode != 32 && event.keyCode != 34 && event.keyCode != 36 && event.keyCode != 37 && event.keyCode != 38   && event.keyCode != 40 && event.keyCode != 41 && event.keyCode != 42 && event.keyCode != 43 && event.keyCode != 44 && event.keyCode != 45 && event.keyCode != 46 &&  event.keyCode != 47 && event.keyCode != 58 && event.keyCode != 59 && event.keyCode != 63 && event.keyCode != 64 && event.keyCode != 123 && event.keyCode != 125)
	{
		event.keyCode = 0;
	    return false;
	}
}


 /*************************************************************************
 * Function Name : Allows no to enter SpecialCharacters
 * Description   : Removes the previous values and Populates the single array from first postion
 * Usage         : onkeypress
 *************************************************************************/

function checkSpecialCharacter(obj)
{
//	alert(event.keyCode);
	if(!((event.keyCode >= 65 && event.keyCode <=90) || (event.keyCode >= 97 && event.keyCode <=122) || (event.keyCode >= 48 && event.keyCode <=57)) && event.keyCode != 32 && event.keyCode != 44 && event.keyCode != 46)
	{
		event.keyCode = 0;
	    return false;
	}
}

 /*************************************************************************
 * Function Name : checkName
 * Description   : Allows to enter valid alphabets 
 * Usage         : onkeypress
 *************************************************************************/

function checkName()
{
	if(!((event.keyCode >= 65 && event.keyCode <=90) || (event.keyCode >= 97 && event.keyCode <=122)) && event.keyCode != 32)
	{
		event.keyCode = 0;
	    return false;
	}
}


/*************************************************************************
 * Function Name : checkNumberMinus
 * Description   : Allows to Enter Minus and Integer Numbers only 
 * Usage         : onkeypress
                   
*************************************************************************/

function checkNumberMinus()
{
	if(!(event.keyCode >= 45 && event.keyCode <=57))
	{
		event.keyCode = 0;
		return false;
	}
}



/*************************************************************************
 * Function Name : checkNumber
 * Description   : Allows to Enter Integer Numbers only 
 * Usage         : onkeypress
                   
*************************************************************************/

function checkNumber()
{

	if(!(event.keyCode > 45 && event.keyCode <=57))
	{
		event.keyCode = 0;
		return false;
	}
}


/*************************************************************************
 * Function Name : validatecustomerid
 * Description   : Allows to enter valid alphabets,numeric and / for validating prospect id
 * Usage         : onkeypress
 *************************************************************************/

function checkCustomerid()
{
	if(!((event.keyCode >= 65 && event.keyCode <=90) || (event.keyCode >= 97 && event.keyCode <=122) || (event.keyCode >= 48 && event.keyCode <=57)) && event.keyCode != 47)
	{
		event.keyCode = 0;
	    return false;
	}
}

/*************************************************************************
 * Function Name : checkDecimal
 * Description   : Allows to Enter Decimal Numbers only 
 * Usage         : onkeypress
                   
*************************************************************************/

function checkDecimal()
{
	if(!(event.keyCode >= 46 && event.keyCode <=58))
	{
		event.keyCode = 0;
		return false;
	}
}

/*************************************************************************
 * Function Name : checkDecimals
 * Description   : Allows to Enter Negative Decimal Numbers only 
 * Usage         : onkeypress
                   
*************************************************************************/

function checkDecimals()
{
	if(!(event.keyCode >= 45 && event.keyCode <=57))
	{
		event.keyCode = 0;
		return false;
	}
}
 /*************************************************************************
 * Function Name : formatNumber
 * Description   : formatting the number (Number/Percent/Currency)
 * Parameters    : 
                   number -  field value
				   format -  format value
 *************************************************************************/

function formatNumber(number, format)
{
	if (number - 0 != number) return null;				// if number is NaN return null

	var useSeparator = format.indexOf(separator) != -1;	// use separators in number
	var usePercent = format.indexOf(percent) != -1;		// convert output to percentage
	var useCurrency = format.indexOf(currency) != -1;		// use currency format
	var isNegative = (number < 0);
	number = Math.abs (number);
  
	if (usePercent) 
		number *= 100;

	format = strip(format, separator + percent + currency);  // remove key characters
	number = "" + number;  // convert number input to string

// split input value into LHS and RHS using decpoint as divider
	var dec = number.indexOf(decpoint) != -1;
	var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
	var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

// split format string into LHS and RHS using decpoint as divider
	dec = format.indexOf(decpoint) != -1;
	var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
	var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

// adjust decimal places by cropping or adding zeros to LHS of number
   if (srightEnd.length < nrightEnd.length) 
   {
		var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
		nrightEnd = nrightEnd.substring(0, srightEnd.length);
		if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up
 
		while (srightEnd.length > nrightEnd.length)
		{
			nrightEnd = "0" + nrightEnd;
		}
		if (srightEnd.length < nrightEnd.length)
		{
			nrightEnd = nrightEnd.substring(1);
			nleftEnd = (nleftEnd - 0) + 1;
		}
	}
	else
	{
		for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) 
		{
			if (srightEnd.charAt(i) == "0") 
				nrightEnd += "0";					// append zero to RHS of number
			else
				break;
		}
    }

// adjust leading zeros
	sleftEnd = strip(sleftEnd, "#");				// remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) 
	{
		nleftEnd = "0" + nleftEnd;					// prepend zero to LHS of number
    }

	if (useSeparator) 
		nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative)
	{
		output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
}

function ltrim ( s )
{
	return s.replace( /^\s*/, "" );
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim( s )
{
	return rtrim(ltrim(s));
} 
   
/*************************************************************************
 * Function Name : WordConvert & convertTri
 * Description   : Converting Number to Words
 * Parameters    : 
                   no -  Input Number
				   words -  Return value in words
 *************************************************************************/

var ones = new Array('',' One',' Two',' Three',' Four',' Five',' Six',' Seven',' Eight',' Nine',
' Ten',' Eleven',' Twelve',' Thirteen',' Fourteen',' Fifteen',' Sixteen',' Seventeen',' Eighteen',' Nineteen');

var tens = new Array('','',' Twenty',' Thirty',' Forty',' Fifty',' Sixty',' Seventy',' Eighty',' Ninety');

var triplets = new Array('',' Thousand',' Million',' Billion',' Trillion',' Quadrillion',' Quintillion',' Sextillion',' Septillion',
' Octillion',' Nonillion');

function convertTri(num, tri)
{
	var str = '', comma='',
	r = Math.round( ( num / 1000 ) - 0.5 ),
	x = Math.round( ( num / 100 ) - 0.5 ) % 10,
	y = Math.round( ( num % 100 ) - 0.5 );

	if (x > 0)
	{  
		//  hundreds
		str = ones[x] + ' hundred';
	}

	if (y < 20)
	{  
		//  ones and tens
		str += ones[y];
	} 

	else
	{
		str += tens[Math.round( (y / 10) - 0.5 )] + ones[y % 10];
	}

	if (str)
	{  
		//  thousands
		str += triplets[tri];
	}
	if (r > 0)
	{ 
		//  continue recursing?
		return convertTri(r, tri+1)+comma+str;
	}
	return str;
}

function WordConvert(no,words) 
{
	alert('1');
	var f = no.value;
	var num = f;
	var temp=f;
	if(!num)
	{
		return;
	}

	var flip = 1; 
	var t;
	var d;

	while( ( num.charAt(0)==' ' || num.charAt(0)=='0' ) && num.length>1 ) 
	{
		num=num.substring(1);
	}

	if( num.charAt(0)=='-' )
	{ 
		flip=-1;
		num=num.substring(1);
	}

	var deci;
	var number;

	if(num.indexOf('.')> -1) 
	{ 
		deci=num.substring(num.indexOf('.')+1,num.length);
		deci = deci.replace( /[^0-9]/g, '' );
		var len=deci.length;
		if(len == 1)
			deci=deci * 100;
		else if (len == 2)
			deci=deci * 10;  
		else
			deci = deci;

		num=num.substring(0,num.indexOf('.'));
		num = num.replace( /[^0-9]/g, '' );
		number = flip * parseInt( num );
	}
	else
	{
		num = num.replace( /[^0-9]/g, '' );
		number = flip * parseInt( num );
	}  

	if (number > 0)
	{
		t = convertTri(number, 0);
	}
	else if (number < 0)
	{
		t = 'minus' + convertTri( number*(-1), 0);
	}
	else if (number === 0)
	{
		t = 'zero';
	}
	
	if (deci > 0)
	{
		d = convertTri( deci, 0);
	}

	var txt = "";
	if(temp.indexOf('.')> -1 && deci > 0) 
	{ 
		if(t == "")
			txt = d + " Baisas" ;
		else
			txt = " Rial Omani " + t + " and " + d + " Baisas" ;
	}
	else
	{
		var txt = " Rial Omani " + t ;
	}
	words.value = txt;
}

/*****************************************************************************************
 * Function Name : AmountFormat
 * Description   : Formats the given towards three decimal places and rounds it
 * Usage         : onblur,onchange
 * Parameters    :
                   amt		- number to be formatted
				   objamt	- number object
 *****************************************************************************************/

function AmountFormat(amt,objamt)
{
	var num = amt;
	var deci;
	var whole;
	if(num.indexOf('.')> -1) 
	{ 
		whole=num.substring(0,num.indexOf('.'));
		deci=num.substring(num.indexOf('.')+1,num.length);
		deci = deci.replace( /[^0-9]/g, '' );
		var addzero="";
		var check = "";
		for(i=0;i<3;i++)
		{
			if(deci.charAt(i)=="")
			{
				addzero += '0';
			}
		}
		deci=deci+addzero;
		decidum = deci % 10;

		zerpad = "";
		if(deci.substring(0,1) == 0)
			zerpad = "0";
		if(decidum >5)
		{
			deci = parseFloat(deci) + parseFloat(10-decidum);
			if(deci > 999)
			{
				whole = parseFloat(whole) + 1;
				deci = "000";
			}
		}
		else if(decidum < 5)
		{
			deci = parseFloat(deci)+ parseFloat(decidum);
			if (deci == "00")
			{
				deci = "000";
			}
		}
		else if(decidum  = 5)
		{
			zerpad = "";
		}
		check = zerpad + deci;
		if(check.length > 3)
			check = deci;
		objamt.value = whole+"."+check;
	}
	else
	{
		if(num > 0)
		{
			objamt.value=num+".000";
		}
		else if (num < 0)
		{
			objamt.value=num+".000";
		}
		else if (num = 0)
		{
			objamt.value="0.000";
		}

	}
	return;
}
/*
function AmountFormat(amt,objamt)
{
	var num = amt;
	var deci;
	var whole;
	if(num.indexOf('.')> -1) 
	{ 
		whole=num.substring(0,num.indexOf('.'));
		deci=num.substring(num.indexOf('.')+1,num.length);
		deci = deci.replace( /[^0-9]/g, '' );
		var addzero="";
		for(i=0;i<3;i++)
		{
			if(deci.charAt(i)=="")
			{
				addzero += '0';
			}
		}
		deci=deci+addzero;
		total = whole+"."+deci;
		decidum = deci % 5;
//		alert('decidum :'+decidum);
		if(deci.substring(2) >5)
		{
			deci = parseInt(deci) + parseInt(5-decidum);
			if(deci > 999)
			{
				whole = parseFloat(whole) + 1;
				deci = "000";
			}
		}
		else
		{
			deci = parseInt(deci) - parseInt(decidum);
		}
		objamt.value = whole+"."+deci;
		
	}
	else
	{
		if(num > 0)
		{
			objamt.value=num+".000";
		}
	}
	return;
}
*/

/*****************************************************************************************
 * Function Name : isLeapYear
 * Description   : Checks Whether the given year is a Leap year
 * Usage         : onchange and other functions
 * Parameters    : year	- year to be validated
 *****************************************************************************************/

function isLeapYear(year)
{
	if(((year % 400) == 0) || ( ((year % 4) == 0) && ((year % 100) != 0)))
		return true;
	else
		return false;
}

/*****************************************************************************************
 * Function Name : addMonths
 * Description   : Adds the months to the date
 * Usage         : onchange and other functions
 * Parameters    : 
				   months	- number of months to be added
  				   IDate	- date to be added
				   Eg : 12 Months and with Date 27-06-2005 will return 27-05-2006
 *****************************************************************************************/

function addMonths(months,IDate,ToDateObj)
{
	var varMonths	= parseInt(months.value)-1;
	var	stdate		= IDate.value;
	if(stdate == '')
		return;

	tempYear		= 0;

	var daysInMonth = new Array(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;  
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

	var separator ="-";
	var fromDateArray	= new Array ();
	fromDateArray		= stdate.split(separator);

	totMon  =  parseFloat(varMonths) + parseFloat(fromDateArray[1]);
	divMon  =  parseInt(totMon / 12);
	modMon  =  parseInt(totMon) % 12;

	modDate = fromDateArray[0];
	
	if(modMon == 0)
	{
		modMon = 12;
		tempYear = -1;
	}
	resyear = parseFloat(fromDateArray[2]) + parseFloat(divMon) + parseFloat(tempYear);

	if(modDate == 31 && (modMon == 4 || modMon == 6 || modMon == 9 || modMon == 11))
	{
		modDate = 30;
	}
	if(modDate >= 28 &&  (modMon == 2))
	{
		if(isLeapYear(resyear) &&  modDate > 28)
			modDate = 29;
		else
			modDate = 28;
	}
	var resdate = modDate + "-" + modMon +"-"+ resyear;
	ToDateObj.value = resdate;
	return;
}


/*****************************************************************************************
 * Function Name : addMonthsInterval
 * Description   : Adds the specified noumber of months to the date
 * Usage         : onchange and other functions
 * Parameters    : 
				   months	- number of months to be added
  				   IDate	- date to be added
 *****************************************************************************************/
function addMonthsInterval(months,IDate,ToDateObj,interval)
{
	var varMonths	= (parseInt(months.value)-1)*parseInt(interval);
	var	stdate		= IDate.value;
	if(stdate == '')
		return;
  
	tempYear		= 0;

	var daysInMonth = new Array(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;  
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

	var separator ="-";
	var fromDateArray	= new Array ();
	fromDateArray		= stdate.split(separator);

	totMon  =  parseFloat(varMonths) + parseFloat(fromDateArray[1]);
	divMon  =  parseInt(totMon / 12);
	modMon  =  parseInt(totMon) % 12;

	modDate = fromDateArray[0];
	
	if(modMon == 0)
	{
		modMon = 12;
		tempYear = -1;
	}
	resyear = parseFloat(fromDateArray[2]) + parseFloat(divMon) + parseFloat(tempYear);

	if(modDate == 31 && (modMon == 4 || modMon == 6 || modMon == 9 || modMon == 11))
	{
		modDate = 30;
	}
	if(modDate >= 28 &&  (modMon == 2))
	{
		if(isLeapYear(resyear) &&  modDate > 28)
			modDate = 29;
		else
			modDate = 28;
	}
	var resdate = modDate + "-" + modMon +"-"+ resyear;
	ToDateObj.value = resdate;
	return;
}

/*****************************************************************************************
 * Function Name : checkUpperCase
 * Description   : Changes the object value to UpperCase
 * Usage         : onchange and onblur
 * Parameters    : obj - Form Object Variable to be Changed
				   
 *****************************************************************************************/

function checkUpperCase(obj)
{
	obj.value = (obj.value).toUpperCase();
	return;
}

/*****************************************************************************************
 * Function Name : roundOffHundred
 * Description   : Rounds of the Decimal Places to Nearest Hundred
 * Usage         : onchange and onblur
 * Parameters    : objamt - Form Object Variable to be Changed
				   amt - Form Object Value to be Changed	
				   
 *****************************************************************************************/

function roundOffHundred(amt,objamt)
{
	var num = amt;
	var deci;
	var whole;
	var zerpad = "";
	var addzero="";
	var check = "";

	if(num.indexOf('.')> -1) 
	{ 
		whole=num.substring(0,num.indexOf('.'));
		deci=num.substring(num.indexOf('.')+1,num.length);
		deci = deci.replace( /[^0-9]/g, '' );
		for(i=0;i<3;i++)
		{
			if(deci.charAt(i)=="")
			{
				addzero += '0';
			}
		}
		deci=deci+addzero;
		decidum = deci % 100;

		if(decidum >= 50)
		{
			deci = parseFloat(deci) + parseFloat(100-decidum);
			if(deci > 999)
			{
				whole = parseFloat(whole) + 1;
				deci = "000";
			}
		}
		else if(decidum < 50)
		{
			deci = parseFloat(deci) - parseFloat(decidum);
		}
		check = zerpad + deci;
		if(check.length > 3)
			check = deci;
		objamt.value = whole+"."+check;
	}
	else
	{
		if(num > 0)
		{
			objamt.value=num+".000";
		}
	}
	return;
}

/*****************************************************************************************
 * Function Name : clearZero
 * Description   : Clears the Zero onfocussing the the text box
 * Usage         : onfocus
 * Parameters    : n - Form Object Variable to be Changed	
				   
 *****************************************************************************************/

function clearZero(n)
{	
	if(n.value==0 || n.value==0.0)
		n.value='';
	return;
}

/*****************************************************************************************
 * Function Name : giveZero
 * Description   : Replaces the Empty text to Zero
 * Usage         : onblur
 * Parameters    : obj - Form Object Variable to be Changed	
				   
 *****************************************************************************************/
function giveZero(obj)
{
	if(obj.value == "" )
		obj.value = 0.0;
	return;
}
/*****************************************************************************************
 * Function Name : giveZero
 * Description   : Replaces the Empty text to Zero
 * Usage         : onblur
 * Parameters    : obj - Form Object Variable to be Changed	
				   
 *****************************************************************************************/
function giveZero3d(obj)
{
	if(obj.value == "" )
		obj.value = "0.000";
	return;
}
/*****************************************************************************************
 * Function Name : checkTelePhoneNum
 * Description   : Validates the Min Length of Telephone Number
 * Usage         : onblur,onchange
 * Parameters    : telObj - Form Object Variable to be Validated	
				   
 *****************************************************************************************/
function checkTelePhoneNum(telObj)
{
	var val = telObj.value;
	if(val == '')
		return;
	if(val.length < 8)
	{
		alert(teleMessage);
//		telObj.focus();		
	}
	return;
}

/*****************************************************************************************
 * Function Name : checkAutoDialTeleNum
 * Description   : Validates the Min Length of Telephone Number
 * Usage         : onblur,onchange
 * Parameters    : telObj - Form Object Variable to be Validated	
				   
 *****************************************************************************************/
function checkAutoDialTeleNum(telObj)
{
	var val = telObj.value;
	if(val == '')
		return false;
	if(val.length < 8)
		return false;
}

/*****************************************************************************************
 * Function Name : cutOffDecimalPlaces
 * Description   : Trims of the Decimal Places 
 * Usage         : onblur,onchange
 * Parameters    : numObj - Form Object Variable to be Rounded	
				   
 *****************************************************************************************/

function cutOffDecimalPlaces(numObj,decimalPlace) 
{
	objWholeNum = 0;
	objDeciNum  = 0;
	objReturnVal = 0;
	var numberVal = numObj.value;
	if(numberVal.indexOf('.')> -1) 
	{ 
		objWholeNum = numberVal.substring(0,numberVal.indexOf('.'));
		if(decimalPlace > 0)
		{
			objDeciNum  = numberVal.substring(numberVal.indexOf('.')+1,numberVal.length);
			numObj.value = objWholeNum + "." + objDeciNum.substring(0,decimalPlace)
		}
		else
			numObj.value = objWholeNum;			
	}
	else
	{
		numObj.value = numberVal;
	}

	return;
}


/*****************************************************************************************
 * Function Name : roundOffDecimalPlaces
 * Description   : Rounds of the Decimal Places to 
 * Usage         : onblur,onchange
 * Parameters    : numObj - Form Object Variable to be Rounded	
				   
 *****************************************************************************************/

function roundOffDecimalPlaces(numObj) 
{
	var numberVal = numObj.value;
    var result1 = numberVal * Math.pow(10, decimalPlace);
    var result2 = Math.round(result1);
    var result3 = result2 / Math.pow(10, decimalPlace);
    numObj.value = padZeros(result3, decimalPlace);
	return;
}

/*****************************************************************************************
 * Function Name : roundOffDecimalPlaces
 * Description   : Rounds of the Decimal Places to 
 * Usage         : onblur,onchange
 * Parameters    : numObj - Form Object Variable to be Rounded	
				   
 *****************************************************************************************/

function roundOffDecimalPostion(numObj,decimalPlace) 
{
	var numberVal = numObj.value;
    var result1 = numberVal * Math.pow(10, decimalPlace);
    var result2 = Math.round(result1);
    var result3 = result2 / Math.pow(10, decimalPlace);
    numObj.value = padZeros(result3, decimalPlace);
	return;
}

/*****************************************************************************************
 * Function Name : padZeros
 * Description   : Zero Padding to the decimal places
 * Usage         : From other Function
 * Parameters    : roundedValue - Rounded Value
				   decimalPlaces - Number of Decimal Places
 *****************************************************************************************/

function padZeros(roundedValue, decimalPlaces) 
{
    var valString		= roundedValue.toString()
    var decimalPosition = valString.indexOf(".")

    if (decimalPosition == -1)
	{        
        decimalLen = 0;
		// If decimalPlaces is greater than zero, tack on a decimal point
        valString += decimalPlaces > 0 ? "." : ""
    }
    else
	{
        // If yes, then only the extra decimal places will be padded with 0s
        decimalLen = valString.length - decimalPosition - 1;
    }
    
    var zeroPad = decimalPlaces - decimalLen;    
    if (zeroPad > 0) 
	{        
		for (var counter = 1; counter <= zeroPad; counter++) 
			valString += "0";
    }
	return valString;
}

/*****************************************************************************************
 * Function Name : openPopupWindow
 * Description   : Opens a New Window
 * Usage         : From other Function,onsubmit,onclick
 * Parameters    : url - Link of the popup
                   windowName - window name
				   height - Height of the window 
                   width  - Width of the window
				   params - Features of the Window
 *****************************************************************************************/

function openPopupWindow(url, windowName, height, width,params)
{
	var features = 'height=' + height + ',width=' + width + ','+params;	
	var winObj = window.open(url, windowName, features);	
	winObj.focus();
//	winObj.resizeBy(655,450);

}
/*****************************************************************************************
 * Function Name : calcAge
 * Description   : Calcuates the Age based on the Date of Birth
 * Usage         : From other Function,onsubmit
 * Parameters    : dbDate - Date of Birth or Date to be Calculated
 *****************************************************************************************/

function calcAge(dbDateObj,sysDateObj)
{
	if(dbDateObj.value == '')
		return;

	var fromdt	= dbDateObj.value;
	var todt	= sysDateObj.value;

	var lastslash	= fromdt.lastIndexOf("-")
	var yearfrom	= fromdt.substr(lastslash+1)

	lastslash	= todt.lastIndexOf("-")
	var yearto	= todt.substr(lastslash+1)	
	
	var diff = yearto - yearfrom;
	if(diff < varMinAge)
	{
		return false;
		}
	return true;
}

/*****************************************************************************************
 * Function Name : checkAge
 * Description   : Calcuates the Age based on the Date of Birth
 * Usage         : From other Function,onblur,onchange
 * Parameters    : ageObj - Form Object
 *****************************************************************************************/

function checkAge(ageObj)
{
	var diff = ageObj.value;
	if(diff == '')
		return;
	if((diff < varMinAge || diff > varMaxAge))
	{
		alert("Applicant Age should be between "+ varMinAge +" to "+varMaxAge);
		ageObj.focus();
		return;
	}
	return;
}

/*****************************************************************************************
 * Function Name : 11/22/2006
 * Description   : Hides the Images whenever needed
 * Usage         : From other Function and javascript methods
 * Parameters    : Object Id / DIV Id
 *****************************************************************************************/

function hideImages(obj)
{
	if(navigator.appName == 'Netscape')
	{
		document.getElementById(obj).style.visibility="hidden" 
	}
	else
	{
		document.getElementById(obj).style.visibility="hidden"; 
//		document.all[obj].style.visibility = 'hidden';
	}
}

/*****************************************************************************************
 * Function Name : showImages
 * Description   : Show the Images whenever needed
 * Usage         : From other Function and javascript methods
 * Parameters    : Object Id / DIV Id
 *****************************************************************************************/

function showImages(obj)
{
	if(navigator.appName == 'Netscape')
	{
		document.getElementById(obj).style.visibility='visible';
	}
	else
	{
		document.getElementById(obj).style.visibility='visible';
	}
}

function failsafeImg()
{
	var badImg = new Image();
	badImg.src = '/AOFS/img/V.gif';
//	alert(document.images.length);
	for(var i=0;i<document.images.length;i++)
	{
		var cpyImg = new Image();
		cpyImg.src = document.images[i].src;
//		alert('cpyImg.src'+cpyImg.src);
//		alert('cpyImg.width'+cpyImg.width);
		if(!cpyImg.width)
		{
			document.images[i].src = document.images[i].src;
//			document.images[i].src =  badImg.src;
		}
	}
}

/*************************************************************************
 * Function Name : checkZero
 * Description   : Validates Zero
 * Usage         : onSubmit

 * Parameters    : s - field 
 *************************************************************************/

function checkZero(objNum) 
{
	var ObjNumVal = objNum.value;
	if(parseInt(ObjNumVal) == 0)
	{
		return true;
	}
	else 
		return false;
}

/*************************************************************************
 * Function Name : checkFloatZero
 * Description   : Validates Zero
 * Usage         : onSubmit

 * Parameters    : s - field 
 *************************************************************************/

function checkFloatZero(objNum) 
{
	var ObjNumVal = objNum.value;
	if(parseFloat(ObjNumVal) <= 0)
	{
		return true;
	}
	else 
		return false;
}


function dateDifference(dateObj1,dateObj2)
{
	var sep             = '-';	
	var fromDateArray 	= new Array ();
	var toDateArray		= new Array ();
	var fromdate        = dateObj1.value;
	var todate          = dateObj2.value;

	fromDateArray		= fromdate.split(sep);
	toDateArray			= todate.split(sep);

	var sdate			= new Date(fromDateArray[2],fromDateArray[1],fromDateArray[0]);
	var tdate			= new Date(toDateArray[2],toDateArray[1],toDateArray[0]);

	var difference		= tdate - sdate; //unit is milliseconds

	formatdifference	= Math.round(difference/1000/60/60/24); //now unit is days

	return formatdifference;
}

function callTimer()
{
	if (timer == 1)
		window.close();
	else
	{ 
		timer -= 1;
		var curmin=Math.floor(timer/60);
		var cursec = (timer%60);
		setTimeout("callTimer()",1000)
	}
}

/*****************************************************************************************
 * Function Name : printWindow
 * Description   : Prints the Current Page
 * Usage         : onclick
 *****************************************************************************************/

function printWindow()
{
	if(printFlag == true)
	{
		window.print();
//		callTimer();
//		document.location.reload();
	}
	else
	{
		alert("Print Option has been disabled");
//		callTimer();
//		document.location.reload();
		return;
	}
}
/*****************************************************************************************
 * Function Name : AmountFormat
 * Description   : Formats the given towards three decimal places and rounds it
 * Usage         : onblur,onchange
 * Parameters    :
                   amt		- number to be formatted
				   objamt	- number object
 *****************************************************************************************/

function AmountFormat2d(amt,objamt)
{
	var num = amt;
	var deci;
	var decimal;
	var whole;
	if(num.indexOf('.')> -1) 
	{ 
		whole=num.substring(0,num.indexOf('.'));
		deci=num.substring(num.indexOf('.')+1,num.length);
		decimal=deci.substring(0,2);
		if (deci.charAt(3)>5)
		{
			decimal = parseInt(decimal)+1;
		}
        
		if (decimal > 99)
		{
		whole=parseInt(whole)+1;	 
         objamt.value = whole+".00";
		}
		else
        {
		objamt.value = whole+"."+decimal;
		}
		objamt.value = whole+"."+decimal;
	}
	else
	{
		if(num > 0)
		{
			objamt.value=num+".00";
		}
		else if (num == 0)
		{
			objamt.value="0.00";
		}
       else if (num < 0)
       {
			objamt.value=num+".00";
       }

	}
	return;
}

/*************************************************************************
 * Function Name : checkPasswordChars
 * Description   : Validates Password Characters based on Password Flag
 * Usage         : onSubmit
 * Parameters    : param - object
                   
*************************************************************************/
  
function checkPasswordChars(param)
{
	var numflag = false;
	var charflag = false;
	var val=param.value;


	for(var i=0;i<val.length;i++)
	{
		var pos1 = i;
		var pos2 = i+1;
		var element = val.substring(parseInt(pos1),parseInt(pos2));

		if(isNaN(element))
		{
			charflag = true;
		}
		else
		{
			numflag = true;
		}
	}
	if((!numflag || charflag) && passwordflag == "N")
	{
		alert('Password should contain only Numbers');
		return  true;
	}
	else if((!charflag || numflag) && passwordflag == "C")
	{
		alert('Password should contain only Characters');
		return true;
	}
	else if((!numflag || !charflag) &&  passwordflag == "A")
	{
		alert('Password should contain Characters and Numbers');
		return true;
	}
}

function hideButton(objLayer1,objLayer2)
{
	document.getElementById(objLayer1).style.display = 'none';
	document.getElementById(objLayer2).style.display = 'inline';
	return;
}

function processWait(dlid) 
{
	document.getElementById(dlid).innerHTML = '<span class="serverConnect">Please Wait Your Request Being Processed....</span>';
	return(1);
}
/*************************************************************************
 * Function Name : checkTextArea
 * Description   : To Validate Text Area with the Count(Characters)
 * Usage         : onSubmit
 * Parameters    : param - object
                   
*************************************************************************/
function checkTextArea(obj,cnt)
{
	var tempVal=obj.value;
	if(tempVal != '')
	{
		if(tempVal.length > cnt)
		{
			alert("Please Enter the number of Characters less than "+cnt);
			obj.focus();
		}
	}

}
/*************************************************************************
 * Function Name : searchSelectData
 * Description   : Searching and Highlighting an Entry
 * Usage         : onchange
 * Parameters    : param - object
                   
*************************************************************************/
/*function searchSelectData(objParam) 
{
    var found = false;
    if (objParam.value.length > -1) 
	{
        for (var i=0; (i < objParam.length) && !found; i++) 
		{
			if (objParam.options[i].text.toUpperCase().indexOf(objParam.value.toUpperCase()) == 0) 
			{
                found = true;
                objParam.options[i].selected = true;
            }
            else if (objParam.options[i].text.toUpperCase() > objParam.value.toUpperCase()) 
			{
                found = true;
                objParam.options[i].selected = true;
            }
        }
        if (!found)
			objParam.options[objParam.length - 1].selected = true;
    }
}*/



/*************************************************************************
 * Function Name		: Numval2
 * Description			: Validates the given Amount for different currencies;
 * Called From (with arguments):on blur event of the amount  fields 
 * Calls (with Parameters): form name
 * Parameters             : param1 - amount field
			    param2 - no.of.decimals	
 *************************************************************************/

function Numval2(param1,param2)
{  
	var curedit = param2;
	var num = param1.value; 
	if(isWhitespace (num)) 
	{
		param1.value='';
		num = param1.value; 
	}
	var i=0 ;
	var j=0 ;
	for(i=0;i<num.length;i++)
	{ 
		if(num.charAt(i)==' ')
			j++;
		else 
			break;
	} 
	num =num.substring(j,num.length);
	var k=0
	if(num.charAt(num.length-1)==' ')
	{ 
		for(i=num.length-1;i>=0;i--)
		{ 
			if(num.charAt(i)==' ')
			{
				k++;
			}
			else
			{
				break 
			}
		}  
	}
	num =num.substring(0,num.length-k);
	var numlen = num.length;
	if(numlen==0) 
	{
		param1.value=''; 
		return true;
	}
	var num = param1.value; 
	var to = num.indexOf('.',0);
	if(isNaN(param1.value))
	{
		alert('Please Enter a Valid Amount');
		param1.value ='';
		param1.focus();
		return false;
	}
	for(i=0;i<=num.length;i++)
	{ 
		if(num.charAt(i)=='-')
		{
			alert('Please Enter a Valid Amount');
			param1.value ='';
			param1.focus();
			return false;
		}
	}
	if(num.indexOf('.') > -1) 
	{
		var v4 = num.substring(num.indexOf('.')+1);
		if(v4.length>parseInt(curedit))
		{
			if(curedit == 0)
				alert('Decimal digits not allowed for the selected currency');
			else
				alert('Maximum Decimal digits allowed for the selected currency is '+curedit);
			param1.value ='';
			param1.focus();
			return false;
		}
	}		
	return true;
}

/*************************************************************************
 * Function Name		: setAllOption
 * Description			: sets ALL option in drop down object
 * Called From (with arguments):on blur event of the amount  fields 
 * Parameters             : form object
 *************************************************************************/

function setAllOption(frmObj)
{
	var objField = document.getElementById(frmObj);
	objField.options[0].text = "ALL";
	objField.options[0].value = "ALL";
}


/*************************************************************************
 * Function Name : populateCombozero
 * Description   : populates the javascript array for dependencies combo boxes dynamically(zeroth Index)
 * Parameters    : 
                   array1 - Values of the  first combo
				   array2 - Values of the  Second combo
				   array3 - Text Values of the Second Combo
				   obj    -  First Combo object
				   val    -   Second Combo object
                   
*************************************************************************/

function populateCombozero(array1,array2,array3,obj,val)
{
//	alert('Value :'+val);
//	alert('Object :'+obj.value);
	var j=0,entry=0;
	var dumarray1 = new Array();
	var dumarray2 = new Array();
	var nullarray = new Array();
	comboRemover(val);
	
	for(i=0;i<array1.length;i++)
	{  
//		alert('Array :'+array1[i]);
		if(array1[i]==obj.value)
		{  
			dumarray1[j] = array2[i];
			dumarray2[j] = array3[i];
			j++;
			entry=1;
		}
		else
		{
			nullarray[j] = "";
		}
	}
	if(entry==1)
	{
		Optpopulate0(dumarray1,dumarray2,val);
	}
	else
	{
		Optpopulate(nullarray,val);
	}
}

function GetTagValues_Ajax(b,elename)
{
	alert('b :'+b);	
    var obj			= b.getElementsByTagName(elename);
	alert('obj :'+obj);
	var arrValues=new Array();
	for (var i=0; i < obj.length; i++) 
	{ 
		arrValues[i] = obj.item(i).firstChild.nodeValue; 
	}	
	return arrValues;
}

function GetTagValue_Ajax(b,elename)
{
	var obj		= null;
    obj			= b.getElementsByTagName(elename); 

	var strValue='';

	
	//alert('len'+obj.length)

	if(obj!=null)
	{
		if(obj.length >0)
		{
			if((obj.item(0).childNodes.length) <=0)
			{
				strValue = '';
			}
			else
			{
				strValue = obj.item(0).firstChild.nodeValue; 
			}
		}
		else
		{
			strValue = '';
		}
	}
	//alert('strValue'+strValue);

	return strValue;
}

/*************************************************************************
 * Function Name : getDateArray
 * Description   : Validates the Date and changes to Specified Format
 * Usage         : onSubmit
 * Parameters    : 
                   dateformat - desired format
				   dateField  - Date Field value
 *************************************************************************/

function getDateArray(dateVal)
{
	if(!(dateVal=="" || dateVal==null))
	{
		var inDate = dateVal;
		if (inDate.indexOf('-') > 0 )
			sep = '-';
		if (inDate.indexOf('.') > 0 ) 
			sep = '.';
		if (inDate.indexOf('/') > 0 ) 
			sep = '/';

		inDay = inDate.substring( 0, inDate.indexOf( sep ) );
		inMonth = inDate.substring( inDate.indexOf( sep ) + 1, inDate.lastIndexOf( sep ) );
		inYear  = inDate.substring( inDate.lastIndexOf( sep ) + 1, inDate.length );

		if (inDay.length > 0 && inDay.length <= 2) 
			inDay = parseInt(inDay, 10);

		if (inMonth.length > 0 && inMonth.length <= 2)
			inMonth = parseInt(inMonth, 10);

		if (!(inYear.length < 1 || inYear.length > 4 || inYear.length == 3))
			inYear = parseInt(inYear, 10);

		dateArray = new Array();
		dateArray[0] = inDay;
		dateArray[1] = inMonth;
		dateArray[2] = inYear;
		return dateArray;
	}
}

function validateNumber(param)
{
	var curedit = 3;
	var num = param.value; 
	if(isWhitespace (num)) 
	{
		param.value='';
		num = param.value; 
	}
	var i=0 ;
	var j=0 ;
	for(i=0;i<num.length;i++)
	{ 
		if(num.charAt(i)==' ')
			j++;
		else 
			break;
	} 
	num =num.substring(j,num.length);
	var k=0
	if(num.charAt(num.length-1)==' ')
	{ 
		for(i=num.length-1;i>=0;i--)
		{ 
			if(num.charAt(i)==' ')
			{
				k++;
			}
			else
			{
				break; 
			}
		}  
	}
	num =num.substring(0,num.length-k);
	var numlen = num.length;
	if(numlen==0) 
	{
		param.value=''; 
		return true;
	}
	var num = param.value; 
	var to = num.indexOf('.',0);
	if(isNaN(param.value))
	{
		return false;
	}

	for(i=0;i<=num.length;i++)
	{ 
		if(num.charAt(i)=='-')
		{
			return false;
		}
	}
	if(num.indexOf('.') > -1) 
	{
		var v4 = num.substring(num.indexOf('.')+1);
		if(v4.length > parseInt(curedit))
		{
			return false;
		}
	}		
	return true;
}

/*************************************************************************
 * Function Name : getMonth
 * Description   : Returns the Number of Days in a Month
 * Usage         : 
 * Parameters    : 
                   month
 *************************************************************************/

function getMonth(inMonth)
{
	if( inMonth > 1 || inMonth < 12 )
		return montharray[inMonth];
	else
		return 0;
}


/** CHECK AMOUNT FORMAT***/


	function checkDollarFormat(val) 
	{	  
	
	  // makes sure that if there's a decimal point, it's followed by two digits
	  
	  dot=val.indexOf('.')
	  lastdot=val.lastIndexOf('.')	  
	 
	  if((dot!=-1) && ((dot!=(val.length-3)) || (dot!=lastdot))) 
	  {	   
	    return false;
	  }
	
	  // Makes sure that only numbers or '.' or ',' are present.
	  for (idol = 0; idol < val.length; idol++) 
	  {	   
	    ch = val.substring(idol, idol + 1)
	    
		if(!isDollar(ch)){	   
	      return false;
		} 
		
		else 
		{
		  if(ch==",")
		  {		  
		    // Makes sure that if there's a comma, it only occurs to divide groups of 1000s
			// (i.e. 1,000 or 10,000 or 100,000 or 1,000,000 but NOT 10,00,00)
			if((!isDigit(val.substring(idol-1,idol))) || (!isDigit(val.substring(idol+1,idol+2))) ||(!isDigit(val.substring(idol+2,idol+3))) ||(!isDigit(val.substring(idol+3,idol+4)))) {
	         			
			   return false;
	        }
		  }
		}
		
		
	  }	 
	  return true;
	}
	
	// Expects any single character, and returns true if it's a number and false if not.
	function isDigit(n){
	  if( (n < "0") || ("9" < n) ){
	    return false
	  } else {
	    return true
	  }
	}
	
	// Expects any single character, and returns true if it's valid input
	// for a dollar amount and false if not.
	function isDollar(n){
	  if( ((n < "0") || ("9" < n)) && (n!=".") && (n!=",") ) {
	    return false
	  } else {
	    return true
	  }
	}
	
	
	
	// Expects an object identifier for a form field that contains a dollar amount.
	// Removes the dollar sign and any commas.

	function getAmount(val) 
	 {
	  var amt='';
	 
	  for (iamt = 0; iamt < val.length; iamt++)
	   {
	    ch = val.substring(iamt, iamt + 1);
	    
	    if ((ch == ",")) 
	    {
	     val= val.substring(0,iamt)+val.substring(iamt+1,val.length)
	      iamt=iamt-1
		}
		
	  } 
	 
	  if(!(val.indexOf('.')=='-1'))
	  {		 
	  val =val.substring(0,val.indexOf('.'));	 
	  }	
	  amt=val;	  
	  return amt; 
	   
	}

	/*************************************************************************
	 * Function Name : formatCurrency
	 * Description   : Returns the amount in US format
	 * Usage         : 
	 * Parameters    : 
	                   num
	 *************************************************************************/
	
	 function formatCurrency(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		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 Name : textCounter
	 * Description   : Returns the number of characters in text area
	 * Usage         :  Returns the number of characters in text area and display the number of remaining characters 
	 * Parameters    : 
	                 
	 *************************************************************************/ 
	 function textCounter(textAreaField, labelFiled,hiddenField,maxlimit) 
	 {	 
		if (textAreaField.value.length > maxlimit) 
		{
			textAreaField.value = textAreaField.value.substring(0, maxlimit);
			document.getElementById(labelFiled).innerHTML = '0 characters left';
			hiddenField.value = '0 characters left';
		}
		else 
		{
		document.getElementById(labelFiled).innerHTML = maxlimit - textAreaField.value.length+' characters left';
		hiddenField.value = maxlimit - textAreaField.value.length+' characters left';
		}		
	}
	
	/*************************************************************************
	 * Function Name : validatePhoneNumber
	 * Description   : validate the phone number.
	 * Usage         : return true or false depending on the validation
	 * Parameters    : 
	                 
	 *************************************************************************/ 
	
	function validatePhoneNumber(varPhoneNumber) {
		// phone number - numbers, open paranthesis, close paranthesis, hyphen, space
		var re = new RegExp("^[0-9+()\\-\\s]+$");
		if (varPhoneNumber.match(re)) {
			return true;
		}
		else {
			return false;
		}
	}
	
	/*************************************************************************
	 * Function Name : validateZipcode
	 * Description   : validate the zip code.
	 * Usage         : return true or false depending on the validation
	 * Parameters    : 
	                 
	 *************************************************************************/ 
	
	function validateZipcode(varZipcode) {
		//zip code - small letters, capital letters, numbers
		var re = new RegExp("^[a-zA-Z0-9\\s]+$");
		if (varZipcode.match(re)) {
			return true;
		}
		else {
			return false;
		}
	}
	
	/*************************************************************************
	 * Function Name : validateString
	 * Description   : validates the input string.
	 * Usage         : return true or false depending on the validation
	 * Parameters    : input string, regex pattern
	                 
	 *************************************************************************/ 
	 
	function validateString (varInputString, varRegex) {
		var re = new RegExp(varRegex);
		if (varInputString.match(re)) { // match the regex against the input string
			return true;
		}
		else {
			return false;
		}
	}

	/*************************************************************************

 * Function Name : optionRemover
 * Description   : Remove the Option Id
 * Parameters    : lovName - form object
                                  lovValue - value of the option to be removed
 *************************************************************************/

function optionRemover(lovName,lovValue)
{
                var i ;
                for(i=0;i<lovName.options.length;i++)
                {                  
                                if(lovName.options[i].value == lovValue)
                                {
                                                lovName.options[i].text  = "";
                                                lovName.options[i].value = "";
                                                lovName.remove(i);
                                }                             
                }
}