﻿// JScript File
    function floatValue(strValue)
    {
        if (strValue != '')
        {
            var newStr = strValue
            newStr = newStr.replace(/%/g, "")
            newStr = newStr.replace(/\$/g, "")
            newStr = newStr.replace(/,/g, "")
            return parseFloat(newStr)
        }    
        else
        {
            return 0        
        }    
    } 
    
    function numberValue(strValue)
    {
        if (strValue != '')
        {
            var newStr = strValue
            newStr = newStr.replace(/%/g, "")
            newStr = newStr.replace(/\$/g, "")
            newStr = newStr.replace(/,/g, "")  
            return Number(newStr)
        }    
        else
        {
            return 0        
        }    
    } 
    
    function getNodeValue(xmlDoc, nodeName)
    {
        var tempNode  = xmlDoc.getElementsByTagName(nodeName)
        if (tempNode.length > 0)
        {
            if (tempNode[0].childNodes.length > 0)
               return tempNode[0].firstChild.text
            else
               return ''        
        }    
        else
        {
            return ''        
        }    
    } 
   
    function formatCurrency(strValue)
    {
	    strValue = strValue.toString().replace(/\$|\,/g,'');
	    dblValue = parseFloat(strValue);

	    blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	    dblValue = Math.floor(dblValue*100+0.50000000001);
	    intCents = dblValue%100;
	    strCents = intCents.toString();
	    dblValue = Math.floor(dblValue/100).toString();
	    if(intCents<10)
		    strCents = "0" + strCents;
	    for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		    dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		    dblValue.substring(dblValue.length-(4*i+3));
	    return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
    }
    
    function formatCurrencyFlat(strValue)
    {
	    strValue = strValue.toString().replace(/\$|\,/g,'');
	    dblValue = parseFloat(strValue);

	    blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	    dblValue = Math.floor(dblValue*100+0.50000000001);
	    dblValue = Math.floor(dblValue/100).toString();
	    for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		    dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		    dblValue.substring(dblValue.length-(4*i+3));
	    return (((blnSign)?'':'-') + '$' + dblValue);
    }    

    //Generating Pop-up Print Preview page
    function getPrint(print_area)
    {
        //Creating new page
        var pp = window.open();

        //Adding HTML opening tag with <HEAD> … </HEAD> portion
        pp.document.writeln('<HTML><HEAD><title>NewDL Print Preview</title>')
        pp.document.writeln('<LINK href="../App_Themes/Default/PrintStyle.css" type="text/css" rel="stylesheet">')
        pp.document.writeln('<LINK href="../App_Themes/Default/PrintStyle.css" type="text/css" rel="stylesheet" media="print">')
        pp.document.writeln('<base target="_self"></HEAD>')

        //Adding Body Tag
        pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
        pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');

        //Adding form Tag
        pp.document.writeln('<form method="post">');
        
        //Creating two buttons Print and Close within a HTML table
        pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
        pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
        pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
        pp.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');
        pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');

        var printHTML;
        // Code to Disable Inputs. The CSS properties do not work in IE
        printHTML = document.getElementById(print_area).innerHTML;
        printHTML = printHTML.replace(/<INPUT/gi, "<INPUT disabled='disabled'");
        printHTML = printHTML.replace(/<A/gi, "<A disabled='disabled'");
        printHTML = printHTML.replace(/<SELECT/gi, "<SELECT disabled='disabled'");
        printHTML = printHTML.replace(/<TEXTAREA/gi, "<TEXTAREA disabled='disabled'");
        printHTML = printHTML.replace(/window.onload/gi, "//window.onload");
        printHTML = printHTML.replace(/PWP.css/gi, "PrintStyle.css");
        // Remove All Javascript
        var startPos = 0
        var endTagPos = 0
        var endPos = 0
        startPos = printHTML.toUpperCase().indexOf("<SCRIPT")
        endPos = printHTML.toUpperCase().indexOf("</SCRIPT>")        
        while (startPos > -1 && endPos  > -1)
        {
            //alert(printHTML.substring(startPos,endPos + 9));
            printHTML = printHTML.substring(0,startPos) + printHTML.substring(endPos + 9)
            
            startPos = printHTML.toUpperCase().indexOf("<SCRIPT")
            endPos = printHTML.toUpperCase().indexOf("</SCRIPT>")            
        }
        startPos = printHTML.toUpperCase().indexOf("<TEXTAREA");
        if (startPos > -1)
            endTagPos = printHTML.toUpperCase().indexOf(">",startPos);
        while (startPos > -1 && endTagPos > -1)
        {
            printHTML = printHTML.substring(0,startPos) + "<div style=\"text-align: left;\"><pre>" + printHTML.substring(endTagPos + 1)
            endPos = printHTML.toUpperCase().indexOf("</TEXTAREA>");
            printHTML = printHTML.substring(0,endPos) + "</pre></div>" + printHTML.substring(endPos + 11)

            startPos = printHTML.toUpperCase().indexOf("<TEXTAREA");
            if (startPos > -1)
                endTagPos = printHTML.toUpperCase().indexOf(">",startPos);
        }
 
        //Writing print area of the calling page       
        pp.document.writeln(printHTML);

        //Ending Tag of </form>, </body> and </HTML>
        pp.document.writeln('</form></body></HTML>');
    }   
    
    function sendClientEmail(toAddress)
    {
        window.open('mailto:' + toAddress,'email','height=0px,width=0px,top=0,left=0');
    }    
