﻿
/***********************************************
               Common Scripts
***********************************************/

function fnOpenURLNewWin(url)
{    
    winRef = window.open(url);
    winRef.focus();
}    
 
function fnIsAlphaNumericKey()
{
    var exp = String.fromCharCode(window.event.keyCode)
    var r = new RegExp("[a-zA-Z0-9]", "g");
    if (exp.match(r) == null)
        window.event.keyCode = 0;    			
} 

//Author: Chintan Sheth 29/04/2009
function fnRound2Decimal(txt)
{
    
    var rawAmount=parseFloat(txt.value);
    var result=Math.round(rawAmount*100)/100;
    txt.value=result;
    if(isNaN(result))
    {
     txt.value="";
    }
    else
    {
        txt.value=result;
    }
}

//Added By Chintan Sheth
//Date: 03/06/2009
//As per Requirement there is a need, to allow user to enter comma into the currenct textbox.
//Allows numbers with one decimal point and commas. Works for all browsers.
//PARAMETERS :
//source - Takes the event that invoked this function
//argumetns - Takes a reference of the control that invoked this function
function fnIsCurrencyKeyWithComma(source,arguments)
{
         var charCode = (source.which) ? source.which : event.keyCode;
         if ((charCode >= 48) && (charCode <= 57) || charCode <= 31|| charCode == 44 )
         {
            return true;
         }
         else if ( charCode == 46 )
         {
            if ( (arguments.value) && (arguments.value.indexOf('.') >= 0) )
                return false;
            else
                return true;
         }
         return false;
}  

//function fnIsAlphaNumericKey(evt)
//{
//    var exp = String.fromCharCode(evt.keyCode);
//    var r = new RegExp("[a-zA-Z0-9]", "g");
//    if (exp.match(r) == null)
//    {
//        return false;
//    }
//    return true;
//} 
  function fnGetScrollY() 
  {
          var scrOfY = 0;
          if( document.documentElement && document.documentElement.scrollTop ) 
          {
            //IE standards compliant mode
            scrOfY = document.documentElement.scrollTop;
          }  
          else if( typeof( window.pageYOffset ) == 'number' ) 
          {
            //Netscape compliant
            scrOfY = window.pageYOffset;
          } 
          else if( document.body && document.body.scrollTop ) 
          {
            //DOM compliant
            scrOfY = document.body.scrollTop;
          } 
          return scrOfY;
  }
  function fnIsAlphaNumericKey(evt)
  {
    var charCode = (evt.which) ? evt.which : event.keyCode;         
     if (charCode > 31 && (charCode < 65 || charCode>90) && (charCode < 48 || charCode > 57) && (charCode < 97 || charCode>122))
     {
        return false;            
     }
     return true;
  }
  
// added by Veena 
// key filter script allows for alphanumeric, - and spaces
function fnIsAlphanumericHyphenSpace(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;    
     if (charCode > 31 && charCode!=32 &&charCode!=45 && (charCode < 65 || charCode>90) && (charCode < 48 || charCode > 57) && (charCode < 97 || charCode>122))
     {
        return false;            
     }
     return true;
}

//function fnIsmoney(evt)
//{
//    var exp = String.fromCharCode(event.keyCode);
//    var r = new RegExp("^\d+(\.\d\d)?$", "g");
//    if (exp.match(r) == null)
//    {
//        return false;
//    }
//    return true;
//} 


function fnIsAlphaKey(evt)
{

    var exp = String.fromCharCode(event.keyCode);
    var r = new RegExp("[a-zA-Z]", "g");
    if (exp.match(r) == null)
    {
        return false;
    }
    return true;
} 

function fnIsNumberKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;         
     if (charCode > 31 && (charCode < 48 || charCode > 57))
     {
        return false;            
     }
     return true;
}
function fnIsNumberKeyWithComma(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;         
     if ((charCode >= 48) && (charCode <= 57) || charCode <= 31|| charCode == 44 )
     {
        return true;
     }
     
     return false;
}

//Key Filter Script: To validate for characters that are not allowed to enter for filenames(ie., in InsuredName)
//Karthik 04/05/2009
//PARAMETERS :
//Evt - event that invoked this function

function fnIsSpecialCharacterKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;  

     if (charCode == 92 || charCode == 47 || charCode == 58 || charCode == 42 || charCode == 63 || charCode == 34 || charCode == 60 || charCode == 62 || charCode == 124 )
     {
        return false;            
     }
     return true;
}
//Key Filter Script: To validate for enter key in save quote/application
//Karthik 04/05/2009
//PARAMETERS :
//Evt - event that invoked this function

function fnRestrictEnterKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode;  
    if(charCode == 13)
    {
        evt.cancel=true;
        evt.returnValue=false;
    }
}

function fnCheckAlphaNumeric(source,arguments)
{
    var txt = document.getElementById(source.controltovalidate);         
    var r = new RegExp("[a-zA-Z0-9]", "g");
    
     for (iCounter = 0; iCounter < txt.value.length; iCounter++)
     {                 
        if (txt.value.charAt(iCounter).match(r) == null)
        {
             arguments.IsValid = false;
             return;
        }
        else
        {
             arguments.IsValid = true;
        }
    }  
}

function fnCheckNumeric(source,arguments)
{
    var txt = document.getElementById(source.controltovalidate);         
    var r = new RegExp("[0-9]", "g");
    
     for (iCounter=0; iCounter<txt.value.length; iCounter++)
     {                 
        if (txt.value.charAt(iCounter).match(r) == null)
        {
             arguments.IsValid = false;
             return;
        }
        else
        {
             arguments.IsValid = true;
        }
    }  
}  

function FaxMailSummary(TargetPageName, RequestedPageName,MsgDivId)
{ 
    var win = window.open(TargetPageName + '?RequestedPageName='+RequestedPageName,'','width='+ parent.window.screen.width + ',height='+ parent.window.screen.height +',location=0,status=0,resizable=1,scrollbars=1,menubar=1');        
    if(win!=null)
    {
        win.moveTo(0,0);
        return true;
        
    }
   else
   {
    toggleAlert(MsgDivId,1);
    return false;
   
      
   }
}

function fnIsEnterKeyPress()
{
     if (event.keyCode == 13) 
     {
        event.keyCode =9;
     } 
}

function fnIsNumberCommaKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;    
     if (charCode > 31 && charCode!=44 && (charCode < 48 || charCode > 57) )
     {
        return false;            
     }
     return true;
}

function fnIsDateKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;  

     if (charCode > 31 && (charCode!=47 )&& (charCode < 48 || charCode > 57) )
     {
        return false;            
     }
     return true;
}
//Allows numbers and only one decimal point. The arg passed must be a reference to the control which is calling this script.
//Works only in IE fails in Other browsers. JOTHI 21/3/2009
function fnIsAmountKey(elementRef)
{
     var charCode = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
     if ((charCode >= 48) && (charCode <= 57) || charCode <= 31 )
     {
        return true;
     }
     else if ( charCode == 46 )
     {
        if ( (elementRef.value) && (elementRef.value.indexOf('.') >= 0) )
            return false;
        else
            return true;
     }
     return false;
}

//Allows numbers and only one decimal point. Works for all browsers. JOTHI 21/3/2009
//PARAMETERS :
//source - Takes the event that invoked this function
//argumetns - Takes a reference of the control that invoked this function
function fnIsCurrencyKey(source,arguments)
{
         var charCode = (source.which) ? source.which : event.keyCode;
         if ((charCode >= 48) && (charCode <= 57) || charCode <= 31 )
         {
            return true;
         }
         else if ( charCode == 46 )
         {
            if ( (arguments.value) && (arguments.value.indexOf('.') >= 0) )
                return false;
            else
                return true;
         }
         return false;
}    
 
   function fnAlphaSpChar(evt)
    {
     var charCode = (evt.which) ? evt.which : event.keyCode;  
        
        if((charCode>=97 && charCode<=122)||(charCode>=65 && charCode<=90)||(charCode==42)||(charCode==64)||(charCode==35)||(charCode==38)||(charCode==46)||(charCode==39)||(charCode==32)||(charCode==45)||(charCode==58)||(charCode==8))
          return true;
          else
          return false;
    }
    
    
// JScript File
function GetBacktoServer()
{
    str = window.location.pathname;
    index = str.lastIndexOf('/')
    page = str.substr(index+1,str.length-index);
    data = readCookie('history');
    if(data.toLowerCase() != page.toLowerCase())
        window.location.reload()
}

 function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	
	return null;
}
function CallDownloadMasterPolicy(programID,DateTime)
{
 window.open('DownloadMasterPolicy.aspx?programID='+programID + '&CurrentDate=' + DateTime,'_parent','width='+ parent.window.screen.width + ',height='+parent.window.screen.height +',location=0,status=0,resizable=1,scrollbars=1,top=90,left=90');
}
/*Author : Ramachandran K
Function : Opens certificate download page
Date : 06/3/2009 */
function DownloadCertificate(certificateId)
{
 window.open('DownloadCertificate.aspx?certificateId='+certificateId,'_parent','width='+ parent.window.screen.width + ',height='+ parent.window.screen.height +',location=0,status=0,resizable=1,scrollbars=1');
} 
/*
function PreviewCertificate()
{
 window.open('PreviewCertificate.aspx','Preview','width=600,height=800,location=0,status=0,resizable=1,scrollbars=1');
}
*/
/*
Added by Syam for Preview Certificate
*/
function PreviewCertificate(previewpagename)
{
if(previewpagename == null || previewpagename=="undefined")
{
	previewpagename = "PreviewCertificate.aspx"
}
    window.open(previewpagename,'Preview','width=600,height=800,location=0,status=0,resizable=1,scrollbars=1');
}
/*Author : Veena Vijayakumar
Function : Added for AABC and other phase 2 sites
Date : 11/5/2009 */
function CallDownloadCertificate(certificateId,DateTime)
{
 window.open('DownloadCertificate.aspx?certificateId='+certificateId + '&CurrentDate=' + DateTime,'_parent','width='+ parent.window.screen.width + ',height='+parent.window.screen.height +',location=0,status=0,resizable=1,scrollbars=1,top=90,left=90');
}
function CallDownloadFinalSummary(QuoteId,DateTime)
{
  window.open('DownloadFinalSummary.aspx?QuoteID='+QuoteId + '&CurrentDate=' + DateTime,'_parent','width='+ parent.window.screen.width+',height='+parent.window.screen.height+',location=0,status=0,resizable=1,scrollbars=1,top=90,left=90');
}  

/*
Author : Karthikeyan K.S
Function : Coding for date validation
Date : 03/16/2009 */
/*Start Date Validation*/
// Declaring valid date character
var dtCh= "/";

String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this;
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year < 1753){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

/*End Date Validation*/

/* M1009144 : Implementation for Whats This Popups :CR*/

document.write("<div id='WhatsThisDiv' style='display: none;' runat='server'><table id='Table1' class='ErrMessagePopup' cellpadding='0' cellspacing='0'><tr id='Tr1' class='ErrMessageHeader' height='20%'><td align='left' valign='top' width='5%'><img id='imgInfoHeader' src='/_layouts/KKCommon/Images/info_icon.gif'></img></td><td align='left' valign='middle'><span id='WhatsThisCaption' font-bold='true' font-size='10' font-names='Verdana'></span></td></tr><tr valign='top' align='center' height='60%'><td colspan='2'><table border='0' width='100%'><tr><td align='left'><span id='WhatsThisBody'></span></td></tr></table></td></tr><tr height='20%'><td align='center' colspan='2'><input id='btnWhatsThisClose' type='button' value='Close' onclick='toggleAlert(\"WhatsThisDiv\",0);' /></td></tr></table></div>");
document.write("<div id='WhatsThisWithScrollDiv' style='display:none;' runat='server'><table id='Table1' class='ErrMessagePopup' cellpadding='0' cellspacing='0'><tr id='Tr1' class='ErrMessageHeader' height='20%'><td align='left' valign='top' width='5%'><img id='imgInfoHeader' src='/_layouts/KKCommon/Images/info_icon.gif'></img></td><td align='left' valign='middle'><span id='WhatsThisWithScrollCaption' font-bold='true' font-size='10' font-names='Verdana'></span></td></tr><tr valign='top' height='60%' align='center'><td colspan='2'><table><tr align='center' style='text-align: justify'><td><div style='overflow: auto; height: 180px;'><table width='95%'><tr><td><span id='WhatsThisWithScrollBody'></span></td></tr></table></div></td></tr><tr align='center'><td><input id='btnWhatsThisWithScrollClose' type='button' value='Close' onclick='toggleAlert(\"WhatsThisWithScrollDiv\",0);' /></td></tr></table></td></tr></table></div>")

function WhatsThis(fErrorHeader,fErrorMessage,fErrorHeight,fErrorWidth,obj,event)
{    
    //fixedtooltip("<table border=0 width=38% cellspacing=0 cellpadding=0><tr><td valign=bottom><img border=0 src='../_layouts/KKSports/Images/BubTopLft.gif' width=17 height=17></td><td width=90% style=background:url('../_layouts/KKSports/Images/Bub1pxTopLine.gif') repeat-x; valign=bottom>&nbsp;</td><td width=2% valign=bottom height=17><img border=0 src='../_layouts/KKSports/Images/BubTopRight.gif' width=17 height=17></td></tr><tr><td background='../_layouts/KKSports/Images/Bub1pxleft.gif'></td><td width=90% style=font-size:14px background='../_layouts/KKSports/Images/Bub1pxCntr.gif'>"+fErrorHeader+"<table width="+fErrorWidth+"px height="+fErrorHeight+" border=0><tr><td style=font-size:11px;>"+fErrorMessage+"</td></tr><tr><td align=right><input id='btnClose' type='button' value='Close' onclick='delayhidetip()';/></td></tr></table></td><td width=2% background='../_layouts/KKSports/Images/Bub1pxRgt.gif'>&nbsp;</td></tr><tr><td width=2%><img border=0 src='../_layouts/KKSports/Images/BubBtmLft.gif' width=17 height=18></td><td width=90% background='../_layouts/KKSports/Images/Bub1pxBtm.gif'>&nbsp;</td><td width=2%><img border=0 src='../_layouts/KKSports/Images/BubBtmRgt.gif' width=17 height=18></td></tr></table>", obj, event, "");
    document.getElementById("WhatsThisCaption").innerHTML=fErrorHeader;
    document.getElementById("WhatsThisBody").innerHTML=fErrorMessage;
    toggleAlert("WhatsThisDiv",1);
} 

function WhatsThisWithScroll(fErrorHeader,fErrorMessage,fErrorHeight,fErrorWidth,obj,event)
{
    //fixedtooltip("<table border=0 width=38% cellspacing=0 cellpadding=0><tr><td valign=bottom><img border=0 src='../_layouts/KKSports/Images/BubTopLft.gif' width=17 height=17></td><td width=90% style=background:url('../_layouts/KKSports/Images/Bub1pxTopLine.gif') repeat-x; valign=bottom>&nbsp;</td><td width=2% valign=bottom height=17><img border=0 src='../_layouts/KKSports/Images/BubTopRight.gif' width=17 height=17></td></tr><tr><td background='../_layouts/KKSports/Images/Bub1pxleft.gif'></td><td width=90% style=font-size:14px; background='../_layouts/KKSports/Images/Bub1pxCntr.gif'>"+fErrorHeader+"<table width="+fErrorWidth+"px height="+fErrorHeight+" border=0><tr><td style=font-size:11px;>"+"<div style=overflow:auto;height:"+fErrorHeight+"px;><table width='97%'><tr><td>"+fErrorMessage+"</td></tr></table></div>"+"</td></tr><tr><td align=right><input id='btnClose' type='button' value='Close' onclick='delayhidetip()';/></td></tr></table></td><td width=2% background='../_layouts/KKSports/Images/Bub1pxRgt.gif'>&nbsp;</td></tr><tr><td width=2%><img border=0 src='../_layouts/KKSports/Images/BubBtmLft.gif' width=17 height=18></td><td width=90% background='../_layouts/KKSports/Images/Bub1pxBtm.gif'>&nbsp;</td><td width=2%><img border=0 src='../_layouts/KKSports/Images/BubBtmRgt.gif' width=17 height=18></td></tr></table>", obj, event, "");
    document.getElementById("WhatsThisWithScrollCaption").innerHTML=fErrorHeader;
    document.getElementById("WhatsThisWithScrollBody").innerHTML=fErrorMessage;
    toggleAlert("WhatsThisWithScrollDiv",1);
}
/*End of WhatsThis Popup implementation*/

// Funtion to allow only alphabets to be entered 
function fnIsCityKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;         
     if (charCode >= 48 && charCode <= 57)
     {
        return false;            
     }
     return true;
}


// Funtion to round  to 2 decimal places


function fnRound2Decimal()
{
    var ctrlid=$get("<%= txtReplacementCost.ClientID %>");
    if(ctrlid!=null)
    {
    var rawAmount=parseFloat(ctrlid.value);
    var result=Math.round(rawAmount*100)/100;
    
   
    if(isNaN(result))
    {
     result="";
    }  
     ctrlid.value=result;
    }
}


///// set of function to formate number and Date field
// Author : Ramasamy
// Format function for date and number
function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.truncate = (tr != null && tr); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{	
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); 
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');	
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}

////// Function to remove comma's on focus.
function RemoveCommas(obj,maxlenth){
    if(obj.value.length<1) 
    {
    obj.maxLength=maxlenth;
    return false;
    }
    var objVal =obj.value;
   
    while (objVal.indexOf(",") > 0)
	{
		objVal	=	objVal.replace(",","");
    }
    obj.value=objVal;
	obj.maxLength=maxlenth;
	SetEnd (obj);
}
/////////Function to set focus on the last character in the textbox
function SetEnd (TB)
{
if (TB.createTextRange)
{
var FieldRange = TB.createTextRange();
FieldRange.moveStart('character', TB.value.length);
FieldRange.collapse();
FieldRange.select();
}
}
///////// Function to format number and remove negative numbers if any
function FormatNumber(obj,dec,curency){
    if(obj.value.length<1) return false;
    var objVal =obj.value;
    while (objVal.indexOf(",") > 0)
	{
		objVal	=	objVal.replace(",","");
	}
	
    if(isNaN(objVal)||((objVal.indexOf(".")>-1)&&(!dec)))
    {
    obj.value='';
    return false;
    }
    if(objVal<1)
	{
		 obj.value='0';
            return false;
	}	
    var num = new NumberFormat();
    num.setNumber(obj.value); 
    num.setInputDecimal('.');
    if(dec){
    num.setPlaces('2', true);
    }
    else
    {
    num.setPlaces('0', false);
    }

    if(curency){
    num.setCurrencyValue('$');
    num.setCurrency(true);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    }
    //Change made on 8th July
//    num.setNegativeFormat(num.PARENTHESIS);
//    num.setNegativeRed(true);
    num.setSeparators(true, ',', ',');
    if(num.toFormatted().length>obj.maxLength)
    {
    obj.maxLength=num.toFormatted().length;
    }
    obj.value = num.toFormatted();
    return true;
}



// function to format date
function formatDate(obj) {

	var objVal = obj.value;
	var year;
	var month;
	var day;
	if (objVal == "")
	{
		return false;
	}
	// Remove the Blank to confirm the validity of the date entered.
	while (objVal.indexOf(" ") > 0)
	{
		objVal	=	objVal.replace(" ","");
	}	
	var arrDate1;
	arrDate1 = objVal.split("/");
	if(!(typeof(arrDate1.length)=='undefined'||arrDate1.length!=3)) 
	{
	   month=arrDate1[0]
	   day=arrDate1[1]
	    if(arrDate1[0].length==1)
	    {
	    month="0"+arrDate1[0]
	    }
	    if(arrDate1[1].length==1)
	    {
	    day="0"+arrDate1[1]
	    }
	    objVal=month+day+arrDate1[2]
	}
	while (objVal.indexOf("/") > 0)
	{
		objVal	=	objVal.replace("/","");
	}	
	year = objVal.substring(4,8);
	if (objVal.substring(4,8).length==2)
	{
		year="20"+objVal.substring(4,8);
	}
	day=objVal.substring(2,4);
	month=objVal.substring(0,2);
	var	formatedDate	= month + "/" + day + "/" + year
	eval("obj.value = formatedDate");
	return true;
}

/////End  - function to formate number and Date field

//Added by Veena for phone fields.
function fnIsNumberHyphenKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode;    
     if (charCode > 31 && charCode!=45 && (charCode < 48 || charCode > 57) )
     {
        return false;            
     }
     return true;
}