

//
function IsNumeric(sText)
{
	if(isNaN(sText))
		return(false) ; 
	else
		return(true) ;   
}
//*****************************************************************************
//This function finds "find" into "expression" and replaces with "replacement"
function Replace(expression,find,replacement)
{
var intPos;
    do 
    {
	    expression = expression.replace(find,replacement);
	    intPos = expression.search(find);
    }
    while (intPos > -1)
    return(expression);
}
//*****************************************************************************

function validateInteger( strValue ) 
{

  var objRegExp  = /(^-?\d\d*$)/;

  
  return objRegExp.test(strValue);
}


//*****************************************************************************
//This function disables keypress event in HTML tag from it has been called
//
function fnDisableKeyPress()
{
	var intKey = window.event.keyCode;
    if (intKey != 0)
		{		 
		 window.event.keyCode = 0;
		}
}
//*****************************************************************************

//*****************************************************************************
// This Function calls Calender control 
// Parameters :
//	strFormName		: Form name of the HTML tag
//	strFieldName	: Textbox name where calnder control will insert selected date.
//	intDateType		: Format of date value
//					1 : mm/dd/yyyy
//					2 : dd/mm/yyyy
//					3 : mon dd yyyy
//					4 : dd mon yyyy
//					5 : month dd yyyy
//					6 : dd mon yy
//					7 : dd month 
  
function fnCallCalender(strFormName, strFieldName, intDateType)
{
	var frmDtCall = new x999cal(true,self,my_date_selected,strFormName,strFieldName, intDateType, 400, 10);
 	frmDtCall.date_fld = strFieldName;
	frmDtCall.popup_cal();
}

function fnCallCalendar(strFormName, strFieldName, intDateType)
{	
	var topplace = eval('document.'+strFormName+'.'+strFieldName+'.screenX');	
	var leftplace = eval('document.'+strFormName+'.'+strFieldName+'.left');	
	if(!eval('document.'+strFormName+'.'+strFieldName+'.disabled'))
	{
		var frmDtCall = new x999cal(true,self,my_date_selected,strFormName,strFieldName, intDateType,topplace,leftplace);
 		frmDtCall.date_fld = strFieldName;
		frmDtCall.popup_cal();
		//alert(eval('document.'+strFormName+'.'+strFieldName+'.topMargin'));
	}
}

//*****************************************************************************

//*****************************************************************************
// This function works in support with function "fnCallCalender". 
// It appends date selected by calender control with comma(,) saperator.
// Parameters :
//	strFormName		: Form name of the HTML tag
//	strFieldName	: Textbox name where calnder control will insert selected date.

function fnAddDate(strFormName, strFieldName)
{
	var strMain = "document." + strFormName + "." + strFieldName;
	var strHidden = "document." + strFormName + "." + strFieldName + "_Hidden" ;
	if (eval(strMain).value != "" )
		eval(strMain).value = eval(strMain).value + ", " + eval(strHidden).value;
	else
		eval(strMain).value = eval(strHidden).value;
}
//*****************************************************************************

//*****************************************************************************
// This function moves list item from Right side list box to Left side list box.
// Paramenters:
//	strFormName		: Form name of the HTML tag
//	strListLeft		: Name of Left side List box
//	strListRight	: Name of Right side List box

function fnMoveLeft(strFormName, strListLeft, strListRight)
{
	var strLeft, strRight;
	strLeft = "document." + strFormName + "." + strListLeft;
	strRight = "document." + strFormName + "." + strListRight;
	
	if(eval(strRight).selectedIndex >= 0 )
	{
		var strNewOption = new Option(eval(strRight).options[eval(strRight).selectedIndex].text, eval(strRight).options[eval(strRight).selectedIndex].value);
		eval(strLeft).options[eval(strLeft).length]= strNewOption;
		eval(strRight).options[eval(strRight).selectedIndex] = null;
	}
}
//*****************************************************************************

//*****************************************************************************
// This function moves list item from Left side list box to Right side list box.
// Paramenters:
//	strFormName		: Form name of the HTML tag
//	strListLeft		: Name of Left side List box
//	strListRight	: Name of Right side List box

function fnMoveRight(strFormName, strListLeft, strListRight)
{
	var strLeft, strRight;
	strLeft = "document." + strFormName + "." + strListLeft;
	strRight = "document." + strFormName + "." + strListRight;
	for (var i=eval(strLeft).options.length-1; i >=0;i--)
	{
		
		if (eval(strLeft).options[i].selected)
		{
			var strNewOption = new Option(eval(strLeft).options[i].text, eval(strLeft).options[i].value);
			eval(strRight).options[eval(strRight).length]= strNewOption;
			eval(strLeft).options[i] = null;
		}
	}		
}
//*****************************************************************************

//*****************************************************************************
// This function Appends contents of Source textbox to destination textbox
// Paramenters:
//	strFormName			: Form name of the HTML tag
//	strSourceField		: Name of Source text box
//	strDestinationField	: Name of Destination text box
//	strSaperator		: Sapertor value

function fnAddText(strSourceField,strDestinationField,strFormName, strSaperator)
{
	var strDest = "document."+ strFormName + "." + strDestinationField;
	var strSourse = "document." + strFormName + "." + strSourceField;
	var strDest1 = strSaperator + eval(strDest).value + strSaperator ;
	var strSourse1 = strSaperator + eval(strSourse).value + "," ;
	var intPos = 0;
    //intPos = strDest1.search(strSourse1);
    intPos = strDest1.indexOf(strSourse1);
    
	if (intPos > -1)
	{
		alert("This value already exists.");
		eval(strSourse).focus();
		return false;
	}
	else
	{
		if (eval(strDest).value == "" )
			{
			eval(strDest).value = eval(strSourse).value;
			eval(strDest + "_Disp").value = eval(strSourse).value;
			}
		else
			{
			eval(strDest).value = eval(strDest).value + strSaperator + eval(strSourse).value;
			eval(strDest + "_Disp" ).value = eval(strDest + "_Disp" ).value + "\n" + eval(strSourse).value;
			}
		eval(strSourse).value = "";
	}
}
//*****************************************************************************

//*****************************************************************************
// Removes matching contents of Source textbox from destination textbox
// Paramenters:
//	strFormName			: Form name of the HTML tag
//	strSourceField		: Name of Source text box
//	strDestinationField	: Name of Destination text box
//	strSaperator		: Sapertor value

function fnRemoveText(strSourceField, strDestinationField, strFormName, strSaperator)
{
	var strDest = "document."+ strFormName + "." + strDestinationField;
	var strSourse = "document." + strFormName + "." + strSourceField;

	var strTemp = eval(strDest).value;
	var intLen ;
	var intSapratorLen = strSaperator.length;
	strTemp = Replace(strSaperator + strTemp + strSaperator, strSaperator + eval(strSourse).value + strSaperator, strSaperator) ;
	intLen = strTemp.length;
	eval(strDest).value = strTemp.slice(intSapratorLen,intLen-intSapratorLen);
	eval(strDest + "_Disp" ).value = Replace(eval(strDest).value,strSaperator,"\n")
	eval(strSourse).value = "";
}
//*****************************************************************************

//*****************************************************************************
// This function values selected in multiselect list box saperated by saperator
// Paramenters:
//	strFormName			: Form name of the HTML tag
//	strField			: Name of Multiselect box
//	strSaperator			: Sapertor value
function fnGetMultiSelect(strFormName, strListBox, strHdnField, strSeparator)
{

var objListBox;
var objHdnField;
var intLstLen;
var intSeparator;
var strTemp;
var intIndex;
objListBox = eval("document." + strFormName + "." + strListBox);
objHdnField = eval("document." + strFormName + "." + strHdnField);


intLstLen=objListBox.length;
intSeparator = strSeparator.length;
strTemp = "";

	for(intIndex=0;intIndex<intLstLen;intIndex++)
	{
		if(intIndex == 0)
			strTemp = objListBox.options[intIndex].value ;
		else
			strTemp = strTemp + strSeparator + objListBox.options[intIndex].value ;
	}

objHdnField.value = strTemp;
}
//*****************************************************************************


//*****************************************************************************
//This function verifies passed parameter is Numeric value
//Parameter:
//	strNumberValue			: Text string to verify

function numberVerify(strNumberValue)
{
 if(isNaN(strNumberValue))
  return(false) ; 
 else
  return(true) ;
}
//*****************************************************************************

//*****************************************************************************
//This function trims left blank spaces of parameter passed
//Parameter:
//	strValue			: Text string to verify
//

function leftTrim(strValue)
{
	while(strValue.charAt(0)==' ')
		strValue = strValue.substr(1,strValue.length-1);
		
	return(strValue) ;
}
//*****************************************************************************

//*****************************************************************************
//This function trims right blank spaces of parameter passed
//Parameter:
//	strValue			: Text string to verify
//

function rightTrim(strValue)
{
	while(strValue.charAt(strValue.length-1)==' ')
		strValue = strValue.substr(0,strValue.length-1);
	
	return(strValue) ;
}
//*****************************************************************************

//*****************************************************************************
//This function trims both sides blank spaces of parameter passed
//Parameter:
//	strValue			: Text string to verify
//

function allTrim(strValue)
{
	return(rightTrim(leftTrim(strValue))) ;
}
//*****************************************************************************

//*****************************************************************************
//This function checks whether passed field contains Numeric value.
//Parameter:
//	strFieldName			: html field name
//

function fnNumericFieldOnChange(strFieldName)
{
	var intValue = "";
	var strNumField = "document.frmMain.htm" + strFieldName;
	intValue = allTrim(eval(strNumField).value);

	intValue = Replace(intValue,",","");
	
	if (numberVerify(intValue) == false )
	{
		eval(strNumField).value = "";
		alert("Please enter a valid numeric value.")
		eval(strNumField).focus();
		return false;
	}
	else
	{
//		alert(strNumField);
		eval(strNumField).value = fnFormatNumberJs(strNumField);	
	}
}
//*****************************************************************************

//*****************************************************************************
//This function checks whether passed field contains Numeric value in HH:MM format.
//Parameter:
//	strFieldName			: html field name
//

function fnTimeFieldOnChange(strFieldName)
{
	var intValue = "";
	var intHH = "";
	var intMM = "";
	var strColon = "";
	var strErrMsg = "Invalid Time Value.\nPlease enter time in HH:MM format."
	var strNumField = "document.frmMain.htm" + strFieldName;
	intValue = eval(strNumField).value;
	intHH  = intValue.slice(0,2);
	intMM  = intValue.slice(3,5);
	strColon = intValue.slice(2,3);
	if (strColon != ":")
	{
		eval(strNumField).value = "";
		alert(strErrMsg);
		eval(strNumField).focus();
		return(false);
	}
	if (numberVerify(intHH) == false)
	{
		eval(strNumField).value = "";
		alert(strErrMsg);
		eval(strNumField).focus();
		return(false);
	}
	if (numberVerify(intMM) == false)
	{
		eval(strNumField).value = "";
		alert(strErrMsg);
		eval(strNumField).focus();
		return (false);
	}
	intHH = parseInt(intHH);
	intMM = parseInt(intMM);
	if ((intHH >=0 && intHH<24) && (intMM >=0 && intMM<=59))
	{
		if (strColon == ":")
		{
			return(true);
		}
	}
	else
	{
		eval(strNumField).value = "";
		alert(strErrMsg);
		eval(strNumField).focus();
		return (false);
	}
}
//*****************************************************************************

//*****************************************************************************
//This function is used to interprete disabled proprty of htaml tag.
//If disabled proprty value is set to true then it will retrun the class name of
//html tag with suffix Dbl
// otherwise it will remove the suffix Dbl from class name.
// class name with suffix Dbl will display html tag with font style italics and color blue/gray
//Parameter:
//	strFieldName			: html field name
//	strValue			: 

function fnGetClassName(strField,strValue)
{
	var strClassName = eval(strField).className;
	var strNewClssName = "";
	var intLen;
	var strLeft = "";
	var strDropdown = "" ;
	strNewClssName = strClassName;
	if (strValue == true)
	{
		if (strClassName.indexOf("Dbl") == -1 )
		{
			strNewClssName = strClassName + "Dbl";
			strDropdown = strNewClssName.substr(0,8);
			if (strDropdown == "combobox")
			{
				if (eval(strField).selectedIndex == 0)
					eval(strField).selectedIndex = eval(strField).length - 1;
			}
		}	
	}
	else
	{
		if (strClassName.indexOf("Dbl") > 0 )
		{		
			intLen = strClassName.length;
			strLeft = strClassName.slice(0,intLen-3);
			strNewClssName = strLeft;
			strDropdown = strNewClssName.substr(0,8);
			if (strDropdown == "combobox")
			{
				//if (eval(strField).selectedIndex == eval(strField).length - 1)
				//	eval(strField).selectedIndex = 0;
			}
		}		
	}
	eval(strField).className = strNewClssName;
	//return(strNewClssName);
} 
//*****************************************************************************

//This function is used to Enable /disable Business Days - Calender days radio buttons
//Parameter:
//	strTextField			: Day Text Field
//	strRadioField			: Business days /Calnder days radio box 

function fnDaysOnChange(strTextField, strRadioField)
{
	var intValue = "";
	var strText = "document.frmMain.htm" + strTextField;
	intValue = allTrim(eval(strText).value);
	
	if (numberVerify(intValue) == true )
	{
		if (intValue > 0 )
		{
			fnGetClassName("document.frmMain.htm" + strRadioField + "(0)", false); 
			fnGetClassName("document.frmMain.htm" + strRadioField + "(1)", false); 
		}
		else
		{
			fnGetClassName("document.frmMain.htm" + strRadioField + "(0)", true); 
			fnGetClassName("document.frmMain.htm" + strRadioField + "(1)", true); 
			eval("document.frmMain.htm" + strRadioField + "(0)").checked = false;
			eval("document.frmMain.htm" + strRadioField + "(1)").checked = false;
		}
	}
	else
	{
		alert("Please enter a valid numeric value.");
		eval(strText).value = "";
		fnGetClassName("document.frmMain.htm" + strRadioField + "(0)", true); 
		fnGetClassName("document.frmMain.htm" + strRadioField + "(1)", true); 
		eval("document.frmMain.htm" + strRadioField + "(0)").checked = false;
		eval("document.frmMain.htm" + strRadioField + "(1)").checked = false;
	}
}
//*****************************************************************************

//*****************************************************************************
//This function is used to Enable /disable Auditor Fields in Auditor Phase1 Module 
//Parameter:
//	strField				: Field Name
//	intOptionValue			: Option Selected

function fnEnableOption(strField)
{
	var intAuditorButton = eval("document.frmMain." + strField + "Rd").length ;
	intAuditorButton = intAuditorButton - 1;
	var strTemp = '' ;
	strTemp = "document.frmMain." + strField + "Rd(" + intAuditorButton + ")";
	var strTempFld = "document.frmMain." + strField ;
	
	if (eval(strTemp).checked == true )
	{
		eval(strTempFld).disabled = false;
	}
	else
	{
		eval(strTempFld).disabled = true;
	}
}
//*****************************************************************************

//*****************************************************************************
//This function is used to Enable /disable Auditor Fields in Auditor Phase1 Module 
//Parameter:
//	strField				: Field Name
//	intOptionValue			: Option Selected

function fnEnableMultiselectOption(strField)
{
	var intAuditorButton = eval("document.frmMain." + strField + "Rd").length ;
	intAuditorButton = intAuditorButton - 1;
	var strTemp = '' ;
	strTemp = "document.frmMain." + strField + "Rd(" + intAuditorButton + ")";
	var strTempFld = "document.frmMain." + strField ;
	//alert(strTemp)
	if (eval(strTemp).checked == true )
	{
		eval(strTempFld + "_Left").disabled = false;
		eval(strTempFld + "_GT").disabled = false;
		eval(strTempFld + "_LT").disabled = false;
		eval(strTempFld + "_Right").disabled = false;
	}
	else
	{
		eval(strTempFld + "_Left").disabled = true;
		eval(strTempFld + "_GT").disabled = true;
		eval(strTempFld + "_LT").disabled = true;
		eval(strTempFld + "_Right").disabled = true;
	}
}
//*****************************************************************************

//*****************************************************************************
//This function is used to Enable /disable Auditor Fields in Auditor Phase1 Module 
//Parameter:
//	strField				: Field Name
//	intOptionValue			: Option Selected

function fnEnableAddRemoveTextOption(strField)
{
	var intAuditorButton = eval("document.frmMain." + strField + "Rd").length ;
	intAuditorButton = intAuditorButton - 1;
	var strTemp = '' ;
	strTemp = "document.frmMain." + strField + "Rd(" + intAuditorButton + ")";
	var strTempFld = "document.frmMain." + strField ;
	
	if (eval(strTemp).checked == true )
	{
		eval(strTempFld + "_Text").disabled = false;
		eval(strTempFld + "_Add").disabled = false;
		eval(strTempFld + "_Remove").disabled = false;
		eval(strTempFld + "_Disp").disabled = false;
	}
	else
	{
		eval(strTempFld + "_Text").disabled = true;
		eval(strTempFld + "_Add").disabled = true;
		eval(strTempFld + "_Remove").disabled = true;
		eval(strTempFld + "_Disp").disabled = true;
	}
}
//*****************************************************************************


//*****************************************************************************
//This function is used to Enable /disable Auditor Fields in Auditor Phase1 Module 
//Parameter:
//	strField				: Field Name
//	intOptionValue			: Option Selected

function fnEnableRadioComboTextOption(strField, strF1,strF2,strF3)
{
	var intAuditorButton = eval("document.frmMain." + strField + "Rd").length ;
	intAuditorButton = intAuditorButton - 1;
	var strTemp = '' ;
	strTemp = "document.frmMain." + strField + "Rd(" + intAuditorButton + ")";
	var strTempFld = "document.frmMain." + strField ;
	
	if (eval(strTemp).checked == true )
	{
		if (strF1 != '')
			eval("document.frmMain." + strF1).disabled = false;
		if (strF2 != '')
			eval("document.frmMain." + strF2).disabled = false;
		if (strF3 != '')
			eval("document.frmMain." + strF3).disabled = false;
	}
	else
	{
		if (strF1 != '')
			eval("document.frmMain." + strF1).disabled = true;
		if (strF2 != '')
			eval("document.frmMain." + strF2).disabled = true;
		if (strF3 != '')
			eval("document.frmMain." + strF3).disabled = true;
	}
}
//*****************************************************************************

//*****************************************************************************
//This function is used to Enable /disable Auditor Fields in Auditor Phase1 Module 
//Parameter:
//	strField				: Field Name
//	intOptionValue			: Option Selected

function fnEnableTextRadioOption(strField)
{
	var intAuditorButton = eval("document.frmMain." + strField + "Rd").length ;
	intAuditorButton = intAuditorButton - 1;
	var strTemp = '' ;
	strTemp = "document.frmMain." + strField + "Rd(" + intAuditorButton + ")";
	var strTempFld = "document.frmMain." + strField ;
	
	if (eval(strTemp).checked == true )
	{
		eval(strTempFld).disabled = false;
		eval(strTempFld + 'Days(0)').disabled = false;
		eval(strTempFld + 'Days(1)').disabled = false;
	}
	else
	{
		eval(strTempFld).disabled = true;
		eval(strTempFld + 'Days(0)').disabled = true;
		eval(strTempFld + 'Days(1)').disabled = true;
	}
}
//*****************************************************************************


//*****************************************************************************
//This function formats numeric value with comma saperator.
//Parameter:
//	strNumField			: html field name
//
function fnFormatNumberJs(strNumField) 
{
	var intNumber = eval(strNumField).value;
	intNumber = Replace(intNumber,",","");
	if (numberVerify(intNumber) == false )
	{
		eval(strNumField).value = "";
		alert("Please enter a valid numeric value.")
		eval(strNumField).focus();
		return false;
	}
	if (intNumber == '')
	{
		return('');
	}
	else
	{
		return fnFormatIntegerPart(Math.floor(intNumber-0) + '') + fnFormatFractionalPart(intNumber); 
	}
}

function fnFormatIntegerPart(intNumber) 
{
    if (intNumber.length <= 3)
        return (intNumber == '' ? '' : intNumber);
    else {
        var intMod = intNumber.length%3;
        var intOutput = (intMod == 0 ? '' : (intNumber.substring(0,intMod)));
        for (i=0 ; i < Math.floor(intNumber.length/3) ; i++) {
            if ((intMod ==0) && (i ==0))
                intOutput += intNumber.substring(intMod+3*i,intMod+3*i+3);
            else
                intOutput += ',' + intNumber.substring(intMod+3*i,intMod+3*i+3);
        }
        return (intOutput);
    }
}

function fnFormatFractionalPart(intNumber) 
{
    var strNumber = intNumber.toString()
    var intDecimalPtPos = strNumber.indexOf(".");
	if (intDecimalPtPos > -1)
	{
		return('.' + strNumber.slice(intDecimalPtPos + 1, strNumber.length));
	}	
	else
	{
		return ('');
	}
}



//added by : Prashant Deshmane
//added date : 3 oct 2006
//function to check email
function checkemail(textval,message)
{
  message="Please enter valid email";
if (textval.value == "")
 {
  alert("Please Enter Your Email Address.");
  textval.focus();
  return false;
 }

// check for spaces
/*
----- check for spaces which are invalid -----
*/
var sp = textval.value.indexOf(" ");
if (sp != -1) {
    alert("Invalid email address, can't use spaces!");

    textval.focus();
    return false;
   }

/*
----- is there a @ ?-----
*/
var str = textval.value.indexOf("@");
var c = str+1;
if (str == -1)
 {
    alert("Invalid email address, no @!");
    textval.focus();
    return false;
   }
/*
----- is there a period? -----
*/
var pr = textval.value.indexOf(".",str);
if (pr == -1) {
    alert("Invalid email address, no period, '.', or period before the @")
    textval.focus();
    return false
   }
/*
----- are there at least 2 characters between the @ and . -----
*/

if (pr - str - 1 < 1)
 {
	alert("There must be at least 1 characters between the '@' and '.'");
	return false;
}

/*
----- are there at least 2 characters after the period? -----
*/
var x = textval.value.length - pr -1;
for (var i = pr; i < textval.value.length; i++) 
	{
		var ch = textval.value.substring(i, i + 1);				
		if(((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))&&
		(ch < "0" || "9" < ch) && 
					(ch != '_') && 
					(ch != '-') &&
					//(ch != '@') && 
					(ch != '.') ) 
		{
			alert('Wild characters found in  \n '+message);
			textval.select();
			return false;
		}
	}


if ( x < 2 )
{
  alert("There must be at least 2 characters after the period!");
  return false;
}
return true;
}
	
	
	
	
	
	
	
	
	/*
	{
		var str="";
		var atrate=0;
		var str = textval.value;
		
		if (str=="")
		{
			alert(message)
			textval.select()
			return false;
		}
		else 
		{
			for (var i = 0; i < str.length; i++) 
			{
				var ch = str.substring(i, i + 1);
			if ( 
					((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && 
					(ch < "0" || "9" < ch) && 
					(ch != '_') && 
					(ch != '-') &&
					(ch != '@') && 
					(ch != '.') 
				) 
				{
					alert('Wild characters found \n '+message)
					textval.select()
					return false;
				}
			}

			if ((str.indexOf ('@') == -1) || (str.indexOf ('.') == -1) || (str.indexOf (' ') > 0))
			{
				alert(message)
				textval.select()
				return false
			}
			for (var i = 0; i < str.length; i++) 
			{
				var ch = str.substring(i, i + 1);
				if ( ch=='@')
				atrate=atrate+1;
			}
			if (atrate > 1 )
			{
				alert('Only 1 ( @ ) symbol allowed \n  '+message)
				textval.select()
				return false
			}
		}
	return true
	}*/
//end of function checkemail
//*****************************************************************************

//*****************************************************************************
//This function is used to get the date difference
   
   function fnSuycDateDiff(start, end, interval, rounding)
	{
      var iOut = 0;
             
      // Create 2 error messages, 1 for each argument. 
      var startMsg = "Check the Start Date and End Date\n"
      startMsg += "must be a valid date format.\n\n"
      startMsg += "Please try again." ;
         		
      var intervalMsg = "Sorry the dateAdd function only accepts\n"
      intervalMsg += "d, h, m OR s intervals.\n\n"
      intervalMsg += "Please try again." ;

      var bufferA = Date.parse( start ) ;
      var bufferB = Date.parse( end ) ;
             	
      // check that the start parameter is a valid Date. 
      if ( isNaN (bufferA) || isNaN (bufferB) ) 
      {
            alert( startMsg ) ;
            return null ;
      }
         	
     // check that an interval parameter was not numeric. 
      if ( interval.charAt == 'undefined' ) 
      {
      // the user specified an incorrect interval, handle the error. 
        // alert( intervalMsg ) ;
         return null ;
      }
             
      var number = bufferB-bufferA ;
             
      // what kind of add to do? 
      switch (interval.charAt(0))
      {
         case 'd': case 'D': 
                  iOut = parseInt(number / 86400000) ;
                  if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
                     break ;
         case 'h': case 'H':
                 iOut = parseInt(number / 3600000 ) ;
                 if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
                     break ;
         case 'm': case 'M':
                  iOut = parseInt(number / 60000 ) ;
                  if(rounding) iOut += parseInt((number % 60000)/30001) ;
                   break ;
         case 's': case 'S':
                  iOut = parseInt(number / 1000 ) ;
                  if(rounding) iOut += parseInt((number % 1000)/501) ;
                  break ;
               default:
         // If we get to here then the interval parameter
         // didn't meet the d,h,m,s criteria.  Handle
         // the error. 		
          alert(intervalMsg) ;
          return null ;
      }
      return iOut ;
   }
   // function used r=to check name fields  allow only  characters a-z & A-Z
   function checkName(strName)
   {   
		var objRegExp= /[^a-zA-Z']/;		
		return objRegExp.test(strName);     
   }   	
//*****************************************************************************
//added by : Vishal Gadhia
//added date : 28 Nov 2006
//function to check emailId

function emailCheck (emailStr) {
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.in|COM|NET|ORG|EDU|BIZ|INFO|CO.IN)$/;

/* 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

//alert("The username doesn't seem to be valid.");
alert("Invalid E-mail ID");
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;
}

// If we've gotten this far, everything's valid!
return true;
}

