// FUNCTION TO CHECK WHETHER THE VALUE IS BLANK
// RETURN TRUE IF VALUE IS BLANK
function trim(str){
	for( lspace=0 ; lspace<str.length ; lspace++ )
		if( str.charAt(lspace)!=' ' )
			break;
	str = str.substring( lspace );
	for( rspace=str.length-1 ; rspace>=0 ; rspace-- )
		if( str.charAt(rspace)!=' ' )
			break;
	str = str.substring( 0, rspace+1 );
	return str;
 }

//THIS FUNCTION WILL BE CALLED FOR ENTRY IN MASTERS, WHEN THE NAME IS /////ENTERED AND WILL ALLOW ONLY ALPHABETS WITH SPACES
function validateMasterName(event){
	var flag='n';	
	var temp=new makeArray(55);
	var i=0;
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}

	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=32;
	i++;
	temp[i]=46;

	for(x=0;x<=54;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z]');
		event.returnValue=false;
		return;
	}
	
}

//THIS FUNCTION WILL BE CALLED FOR ENTRY IN MASTERS, WHEN THE CODE IS /////ENTERED AND WILL ALLOW ONLY ALPHANMRICE WITH UNDERSCORE

function validateMasterCode(event,obj){
	if(obj.value.length==0){
		if(event.keyCode==95){
			alert('The code can not start with UnderScore Symbol');
			event.returnValue=false;
			return;
		}
	}
	var flag='n';	
	var temp=new makeArray(64);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}

	temp[i]=95;
	for(x=0;x<=64;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] and 0-9 with UnderScore');
		event.returnValue=false;
		return;
	}
}
function onlyAlphabetInt(event){
	var flag='n';	
	var temp=new makeArray(63);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	for(x=0;x<=63;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] and 0-9');
		event.returnValue=false;
		return;
	}
	
}

//THIS FUNCTION WILL CHECK FOR THE USER INPUT AND RETURNS A ALERT  MESSAGE THAT ONLY A-Z AND 0-9 ARE ALLOWED WITH HYPHEN
function onlyAlphabetIntHyphen(event){
	var flag='n';	
	var temp=new makeArray(64);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}

	temp[i]=45;
	for(x=0;x<=64;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] and 0-9 with Hyphen');
		event.returnValue=false;
		return;
	}
	
}

//FOLLOWING FUNCTION IS USED TO CHECK TIME FORMAT
//function ValidateTime(obj){
//}

//THE FOLLOWING FUNCTION WILL CHECK FOR 0-9,(,),+,-
function validatePhoneNo(event){
	var flag='n';	
	var temp=new makeArray(15);
	var i=0;

	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	
	temp[i]=40;
	i++;
	temp[i]=41;
	i++;
	temp[i]=43;
	i++;
	temp[i]=45;

	for(x=0;x<=15;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only 0-9,(,),- and +');
		event.returnValue=false;
		return;
	}
	
}

// THIS FUNCTION WILL CHECK FOR THE USER INPUT AND RETURNS A ALERT  
// MESSAGE THAT ONLY A-Z AND 0-9 ARE ALLOWED WITH SPACE
function onlyAlphabetIntSpace(event){
	var flag='n';	
	var temp=new makeArray(64);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}

	temp[i]=32;
	for(x=0;x<=64;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] and 0-9 with Space');
		event.returnValue=false;
		return;
	}
	
}
// THIS FUNCTION WILL CHECK FOR THE USER INPUT AND RETURNS A ALERT  
// MESSAGE THAT ONLY A-Z AND 0-9 ARE ALLOWED WITH SPACE and SLASH
function onlyAlphabetIntSpaceSlash(event){
	var flag='n';	
	var temp=new makeArray(65);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}

	temp[i]=32;
	i++;
	temp[i]=47;
	for(x=0;x<=64;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] and 0-9 with Space');
		event.returnValue=false;
		return;
	}
	
}

//THE FOLLOWING FUNCTION WILL CHECK FOR A-Z,.,& and space
function onlyAlphabettwochar(event){
	var flag='n';	
	var temp=new makeArray(56);
	var i=0;
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=46;
	i++;
	temp[i]=38;
	i++;
	temp[i]=32;
	for(x=0;x<=56;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z],.,&');
		event.returnValue=false;
		return;
	}
	
}


//FUNCTION IS USED TO YAKE INPUT ALPHABATES WITH SPACE,HIPHEN,& AND DOT(.)
function nameWithDotHiphenAmpersendAndNum(event){
	var flag='n';	
	var temp=new makeArray(69);
	var i=0;
	for(j=48;j<=57;j++){
		temp[i]=j;
		i++;
	}
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=32;
	i++;
	temp[i]=40;
	i++;
	temp[i]=41;
	i++;
	temp[i]=45;
	i++;
	temp[i]=46;
	i++;
	temp[i]=38;
	for(x=0;x<=69;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only [A-Z],[0-9],.,& ');
		event.returnValue=false;
		return;
	}
	
}

//THE FOLLOWING FUNCTION WILL CHECK FOR A-Z,. AND SPACE
function onlyAlphabetonechar(event){
	var flag='n';	
	var temp=new makeArray(56);
	var i=0;
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=46;
	i++;
	
	temp[i]=32;
	for(x=0;x<=56;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z],.');
		event.returnValue=false;
		return;
	}
	
}


//THE FOLLOWING FUNCTION WILL CHECK FOR ALPHABETS ONLY WITH SPACE

function onlyAlphabet(event){
	var flag='n';	
	var temp=new makeArray(54);
	var i=0;
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=32;

	for(x=0;x<=54;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z]');
		event.returnValue=false;
		return;
	}
	
}

//CHECK FOR ONLY INTEGERS
function onlyInteger(event){
	var flag='n';	
	var temp=new makeArray(10);
	var i=0;
	for(j=48;j<58;j++){
		temp[i]=j;
		i++;
	}
	for(x=0;x<=10;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('Please enter only Integer');
		event.returnValue=false;
		return;
	}
}
//function is used to check time format
function timeCheck(obj){
	var hh=0;
	var mm=0;
	var len=obj.value.length;
	if(len>5){
		alert("Please specify Time in HH:MM format.");
		obj.select();
		return false;
	}
	var pos=obj.value.indexOf(":");
	if(pos>2){
		alert("Please specify Time in HH:MM format.");
		obj.select();
		return false;
	}
	else if(pos>=1){
		var hh=eval(obj.value.substring(0,pos));
		var mm=eval(obj.value.substring(pos+1,len));
	}
	else if(pos==-1){
		hh=obj.value;
		mm=0;
		if(len>0)
			obj.value=hh+":00";
	}
	if((hh>24) || (mm>59)){
		alert("Please specify Time in HH:MM format.");
		obj.select();
		return false;
	}
	if((hh>=24) && (mm>0)){
		alert("Please specify Time in HH:MM format.");
		obj.select();
		return false;
	}
}
//function is used to check time format
function checkTime(event){
	var flag='n';	
	var temp=new makeArray(11);
	var i=0;
	for(j=48;j<=58;j++){
		temp[i]=j;
		i++;
	}
	for(x=0;x<=10;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert("Please specify Time in HH:MM format.");
		event.returnValue=false;
		return;
	}
}
//check for only Amount Values
function checkAmount(event,obj){
	var len=obj.value.length;
	var flag='n';	
	var temp=new makeArray(11);
	var i=0;
	var ctr=0;
	for(j=48;j<58;j++){
		temp[i]=j;
		i++;
	}
	i++;
	temp[i]=46;
	for(x=0;x<=11;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('Please enter value in Digits.');
		event.returnValue=false;
		return;
	}
}

function checkAmountDigit(obj){
	var len=obj.value.length;
	if(obj.value=="NaN" || obj.value==""){
		obj.value="0";
		return false;
	}
	var ctr=0;
	for(i=0;i<len;i++)
		if( obj.value.charAt(i)=='.' )
			ctr++;
	if(ctr>1){
		alert('Please enter value in Digits.');
		obj.select();
		return false;
	}			
}

//THE FOLLOWING FUNCTION WILL CHECK FOR ALPHABETS ONLY WITH SLASH

function onlyAlphabetslash(event){
	var flag='n';	
	var temp=new makeArray(55);
	var i=0;
	for(j=65;j<91;j++){
		temp[i]=j;
		i++;
	}
	for(j=97;j<123;j++){
		temp[i]=j;
		i++;
	}
	temp[i]=47;
	i++;
	temp[i]=32;

	for(x=0;x<=55;x++){
		if(event.keyCode==temp[x]){
			flag='y';
			break;
		}
	}
	if(event.keyCode==13)
			flag='y';
	if(flag=='n'){
		alert('You can enter only Alphabets[A-Z] with / and Space');
		event.returnValue=false;
		return;
	}
}

function checkMaster(obj){	
	var  str=obj.value;
	var temp=new makeArray(27);
	temp[0]='@';
	temp[1]='~';
	temp[2]='`';
	temp[3]='#';
	temp[4]='$';
	temp[5]='%';
	temp[6]='^';
	temp[7]='&';
	temp[8]='*';
	temp[9]='=';
	temp[10]='+';
	temp[11]='|';
	temp[12]='{';
	temp[13]='}';
	temp[14]='[';
	temp[15]=']';
	temp[16]=':';
	temp[17]=';';
	temp[18]='<';
	temp[19]='>';
	temp[20]='?';
	temp[21]='"';
	temp[22]='(';
	temp[23]=')';
	temp[24]=' ';
	for(i=0;i<str.length;i++){
		for(j=0;j<=24;j++){
			if(str.charAt(i)==temp[j]){
				alert("Special Characters are not allowed");
				obj.select();
				return false;
			}
		}
	}
}

function checkSymbol(obj){	
	var  str=obj.value;
	var temp=new makeArray(29);
	temp[0]='@';
	temp[1]='~';
	temp[2]='`';
	temp[3]='#';
	temp[4]='$';
	temp[5]='%';
	temp[6]='^';
	temp[7]='&';
	temp[8]='*';
	temp[9]='_';
	temp[10]='=';
	temp[11]='+';
	temp[13]='|';
	temp[14]='{';
	temp[15]='}';
	temp[16]='[';
	temp[17]=']';
	temp[18]=':';
	temp[19]=';';
	temp[20]='<';
	temp[21]='>';
	temp[22]='?';
	temp[23]='/';
	temp[24]='"';
	temp[25]='(';
	temp[26]=')';
	temp[27]='\'';
	temp[28]='\"';
for(i=0;i<str.length;i++){
			for(j=0;j<=28;j++){				
				if(str.charAt(i)==temp[j]){
					alert("Special Characters are not allowed");
					obj.select();
					return false;
				}
			}
		}
}
function checkSymbolAnother(obj){	
	var  str=obj.value;
	var temp=new makeArray(27);
	temp[0]='@';
	temp[1]='~';
	temp[2]='`';
	temp[3]='#';
	temp[4]='$';
	temp[5]='%';
	temp[6]='^';
	temp[7]='^';
	temp[8]='*';
	temp[9]='_';
	temp[10]='=';
	temp[11]='+';
	temp[13]='|';
	temp[14]='{';
	temp[15]='}';
	temp[16]='[';
	temp[17]=']';
	temp[18]=':';
	temp[19]=';';
	temp[20]='<';
	temp[21]='>';
	temp[22]='?';
	temp[23]='/';
	temp[24]='"';
	temp[25]='(';
	temp[26]=')';
for(i=0;i<str.length;i++){
			for(j=0;j<=26;j++){				
				if(str.charAt(i)==temp[j]){
					alert("Special Characters are not allowed");
					obj.select();
					return false;
				}
			}
		}
}
function checkaddress(obj){	
	var  str=obj.value;
	var temp=new makeArray(24);
//	temp[0]='@';
	temp[1]='~';
	temp[2]='`';	
	temp[3]='$';
	temp[4]='%';
	temp[5]='^';
	temp[6]='^';
	temp[7]='*';
	temp[8]='_';
	temp[9]='=';
	temp[10]='+';
	temp[11]='|';
	temp[12]='{';
	temp[13]='}';
	temp[14]='[';
	temp[15]=']';
	temp[16]=':';
	temp[17]=';';
	temp[18]='<';
	temp[19]='>';
	temp[20]='?';	
	temp[21]='"';
	temp[22]='(';
	temp[23]=')';
for(i=0;i<str.length;i++){
			for(j=0;j<=23;j++){				
				if(str.charAt(i)==temp[j]){
					alert("The address field should contain only A-Z,0-9,&,#,\\,-,@ and ,");
					obj.select();
					return false;
				}
			}
		}
}
function checkSymbolUnderScore(obj){	
	var  str=obj.value;
	var temp=new makeArray(27);
	temp[0]='@';
	temp[1]='~';
	temp[2]='`';
	temp[3]='#';
	temp[4]='$';
	temp[5]='%';
	temp[6]='^';
	temp[7]='^';
	temp[8]='*';
	temp[9]='*';
	temp[10]='=';
	temp[11]='+';
	temp[13]='|';
	temp[14]='{';
	temp[15]='}';
	temp[16]='[';
	temp[17]=']';
	temp[18]=':';
	temp[19]=';';
	temp[20]='<';
	temp[21]='>';
	temp[22]='?';
	temp[23]='/';
	temp[24]='"';
	temp[25]='(';
	temp[26]=')';
for(i=0;i<str.length;i++){
			for(j=0;j<=26;j++){				
				if(str.charAt(i)==temp[j]){
					alert("Special Characters are not allowed");
					obj.select();
					return false;
				}
			}
		}
}
function isEmailAddr(email){
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0){
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
function isBlank(val){
	if (val == null) { return true; }
	for (var i=0; i < val.length; i++) {
		if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) { return false; }
		}
	return true;
	}

///function to check whether the value is amount
function isAmount(num){
	var string="1234567890.,";
	if (string.indexOf(num) != -1){
		return true;
		}
	return false;
	}
function isPayScale(num){
	var string="1234567890.,-";
	if (string.indexOf(num) != -1){
		return true;
		}
	return false;
	}

///function to check whether the value is amount
function isDigit(num){
	var string="1234567890,";
	if (string.indexOf(num) != -1){
		return true;
		}
	return false;
	}

///function to check the whether the value is Integer
function isInteger(val,param1){
	for (var i=0; i < val.length; i++){
		if(param1=="amount"){
			if (!isAmount(val.charAt(i))){ 
				return false; 
			}
		}
		else{
			if (!isDigit(val.charAt(i))){ 
				return false; 
			}
		}
	}
	return true;
}

// function to check the value is integer
function checkInt(val,param1){
	value=val.value
	if(param1=="amount" || param1=="percent" || param1=="numeric"){
		ret=isInteger(value,"amount");
	}
	else{
		ret=isInteger(value)	;
	}
	ret1=isBlank(value);
	/////if value is left blank
	if(ret1==true){
		if(param1=="amount"){
			val.value="0.00";
		}
		if(param1=="percent"){
			val.value="0.00";
		}
		if(param1=="numeric"){
			val.value="0.00";
		}
		if(param1==null){
			val.value="0";
		}
		val.focus();
	}
	else{
		//////else show the error
		if(ret==false){
			if(param1=="amount"){			
				alert("Please enter Amount value");
				val.value="0.00";
			}
			if(param1=="percent"){			
				alert("Please enter Percentage value");
				val.value="0.00";
			}
			if(param1=="numeric"){			
				alert("Please enter Decimal value");
				val.value="0.00";
			}
			if(param1==null){	
				alert("Please enter Numeric value");
				val.value="0";	
			}
			val.focus();
		}
		else{
			if(param1=="amount"){			
				val.value=formatCurrency(val.value);
			}
			if(param1=="percent"){			
				val.value=formatCurrency(val.value);
			}
			else
				val.value=value;
		}
	}		
}
function checkIntNew(val,param1){
	value=val.value
	if(param1=="amount" || param1=="percent" || param1=="numeric"){
		ret=isInteger(value,"amount");
	}
	else{
		ret=isInteger(value)	;
	}
	ret1=isBlank(value);
	/////if value is left blank
	if(ret1==true){
		if(param1=="amount"){
			val.value="0.00";
		}
		if(param1=="percent"){
			val.value="0.00";
		}
		if(param1=="numeric"){
			val.value="0.00";
		}
		if(param1==null){
			val.value="0";
		}
		val.select();
	}
	else{
		//////else show the error
		if(ret==false){
			if(param1=="amount"){			
				alert("Please enter Amount value");
				val.value="0.00";
			}
			if(param1=="percent"){			
				alert("Please enter Percentage value");
				val.value="0.00";
			}
			if(param1=="numeric"){			
				alert("Please enter Decimal value");
				val.value="0.00";
			}
			if(param1==null){	
				alert("Please enter Numeric value");
				val.value="0";	
			}
			val.select();
		}
		else{
			if(param1=="amount")	{						
				val.value=formatCurrency(val.value);
				value=parseFloat("value");
				val.value=value.toFixed(2);
			}
			if(param1=="percent"){			
				val.value=formatCurrency(val.value);
			}
			if(param1=="numeric")
			{			
				val.value=formatCurrency(val.value);
			}
		}
	}		
}
function checkInt1(val,param1)
{
	value=val.value
	if(param1=="amount")
	{
		ret=isInteger(value,"amount");
	}
	else
	{
		ret=isInteger(value)	;
	}
	ret1=isBlank(value);
	/////if value is left blank
	if(ret1==true)
	{
		if(param1=="amount")
		{
			val.value="0.00";
		}
		else
		{	
			val.value="0";	
		}
		val.focus();
	}
	else
	{
		//////else show the error
		if(ret==false)
		{
			if(param1=="amount")
			{			
				alert("Please enter Amount value");
				val.value="0.00";
			}
			else
			{	
				alert("Please enter numeric value");
				val.value="0";	
			}
			val.focus();
		}
		if(param1=="amount")
		{			
			value=formatCurrency(value,'amount');
			val.value=value;
		}
		else
		{
			val.value=value;
		}
	}		
}
///////function to make an Array
function makeArray(IntarrSize) {

  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;

}
/////////function equivalent to explode
function customSplit(strvalue, separator, arrayName) 
{
  var n = 0;
  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}


/////FUNCTION TO FORMAT THE CURRENCY
function formatCurrency(num,param) 
{
	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));
	if(param=='amount')
	{
		return (((sign)?'':'-') + num + '.' + cents);
	}
	else
	{
		return (((sign)?'':'-') + num);
	}
}

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
function isValidDate(dateObj) {

dateStr=dateObj.value;
if(dateStr=="")
	{
	return false;
	}
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("`"+dateStr + "` is not a valid date format.")
	dateObj.select();
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
dateObj.select();
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
dateObj.select();
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
dateObj.select();
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
dateObj.select();
return false;
   }
}
return true;
}
function isValidDateNew(dateObj) {

dateStr=dateObj.value;
if(dateStr=="")
	{
	return false;
	}
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("`"+dateStr + "` is not a valid date format.")
	dateObj.select();
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
//dateObj.select();
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
//dateObj.select();
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn't have 31 days!")
//dateObj.select();
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn't have " + day + " days!");
//dateObj.select();
return false;
   }
}
return true;
}

function convertdate(first)
{
date1 = new Date();
size=customSplit(first, "/", "First") ;
date1temp = new Date(First[1]+"/"+First[0]+"/"+First[2]+" 00:00:00AM");
date1.setTime(date1temp.getTime());
return date1;

}
function dateDiff(first, second) {
date1 = new Date();
date2 = new Date();
diff  = new Date();
size=customSplit(first, "/", "First") ;
size1=customSplit(second, "/", "Second") ;
date1temp = new Date(First[1]+"/"+First[0]+"/"+First[2]+" 00:00:00AM");
date1.setTime(date1temp.getTime());

date2temp = new Date(Second[1]+"/"+Second[0]+"/"+Second[2]+" 00:00:00AM");
//date2temp = new Date("10/10/2002 00:00:00AM");
date2.setTime(date2temp.getTime());
// sets difference date to difference of first date and second date

diff.setTime(date1.getTime() - date2.getTime());
timediff = diff.getTime();

weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);

hours = Math.floor(timediff / (1000 * 60 * 60)); 
timediff -= hours * (1000 * 60 * 60);

mins = Math.floor(timediff / (1000 * 60)); 
timediff -= mins * (1000 * 60);

secs = Math.floor(timediff / 1000); 
timediff -= secs * 1000;
//dateform.difference.value = weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds";
total=eval(eval(weeks * 7) + days);
return total; // form should never submit, returns false
}

function removespecial(amount)
{
	var amt=0;
	for(var i=0;i<amount.length;i++)
	{
		if(amount.charCodeAt(i)!=44)
		{
			amt+=amount.charAt(i);
		}
	}
	return amt;
}
function roundTo2dp(amount){
	return Math.round(amount*100)/100;
}
function roundToNdp(amt, decimalPlace){
	var T = Number('1e'+decimalPlace);
	return Math.round(amt*T)/T;
}
function backForm(form,file){
	var conf=confirm("Are you sure, you want to go Back? \nYou will loss your Data.");
	if(conf)
		form.action=file;
	else
		return false;
}
function cancelForm(form,file){
	var conf=confirm("Are you sure, you want to Cancel? \nYou will loss your Data.");
	if(conf)
		form.action=(file);
	else
		return false;
}
function resetForm(form,file){
	var conf=confirm("Are you sure, you want to Reset Values?");
	if(conf)
		form.reset();
	else
		return false;
}
function closeForm(){
	var conf=confirm("Are you sure, you want to Close Window?");
	if(conf)
		window.close();
	else
		return false;
}