// Copyright 2008 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.

/*
JavaScipt for handling most ORKA Page Components.
*/
dojo.require("dojo._base.xhr");

/*
--- ORKA TERMINOLOGY ---
searchMethod - The method of searching based on Owner Name, Address, PID, etc.
themeButton - Themes (searchThemes) along the left-hand side of the interface such as General, Map, etc.
searchTheme - searchTheme is either "ORKA_SEARCH" the initial search based on Owner, etc., 
or a search for a specific parcel based on the selected searchTheme.
modTheme - The searchTheme with the term "_THEME" tacked onto the end just to make it more unique.
h_pid1 - The parcel ID of the subject property regardless of how it was established.
h_pid1Input - The parcel ID that was typed in by the user.
h_pid2 - May be used if a jurisdiction has two parcel IDs.
h_pid2Input - May be used if a jurisdiction has two parcel IDs.
reloadPrevention - If there is only one input field, pressing the Enter key will cause the page to reload.  reloadPrevention is a hidden element that prevents this from happening.
searchIndex, searchCount, searchLimit - Global variables created in pageComponents.js.
searchIndex - Managed in function incrRecords. It is passed to function fetchSearchResults because Search buttons submit a searchIndex of zero to that function.
searchCount - Managed in ajax.js. It is a value returned by the Server.
searchLimit - Global varible that can only be changed below by the site administrator.
mapPids - Variable for storing many parcel IDs.  They are pipe (|) delimited.  mapPids is established either from a Map Identify or from a Comparables search.  In the case of Comparables, the multiple parcel IDs are associated with the Map Hyperlink of the Subject Property.
selectNum - The number of the selected sketch or the quantity of Parcel polygons selected on the Map.

--- CAUTION ---
Do not introduce any form elements that contains h_ as this syntax is reserved for hidden tags.
*/

////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
////////////////////////////////////////////////////////////
// hostName is not currently used...
var hostName = document.location.host;

var logLevel = 0;

var initApp = true;
var initSales = true;
var timer = 600;
var reloadTimer = 0;
var pid1Length = 11;

//var popupFile = "popupwin.jsp";
var popupFile = "popupwin.aspx";
var popupSearchFile = "SearchResultsPopup.aspx";
var popupPPSearchFile = "SearchResultsPopupPP.aspx";
var popupPPAddrSearchFile = "SearchResultsPopupPPAddr.aspx";
var popupPic = false;
var popupPRC = false;
var popupMap = false;
var popupSkt = true;
var scrWidth = screen.width;
var scrHeight = screen.height;
var w = 700;
var h = 600;

// Global variables managed by ORKA.
var searchIndex = 1;
var searchCount = 0;
var mapPids = "";
//var mapPids = "39031B06900|39031B07000|39031B07100|39031B07200|39031B07300|39031B07400|39031B07500|39031B07600|39031B07700|39031B08200|39031B08300|39031B08400|39031B08500|39031B08600|39031B08700|39031B08800|39031B08900|39031B09000|39031B09100|39031B09200|39031B09300|39031B09400|39031B09500|39031B09600|39031B10700|39031B10800|39031B10900|39031B11000|39031B11100|39031B11200|39031B11300|39031C20800|39031C20900|39031C21000|39031C21100|39031C21200|39031C21300|39031C21400|39031C21500|39031C21600|";

// searchLimit may be adjusted up or down as needed.  Recordsets start at zero, so 29 yields 30 records.
var searchLimit = 29;

var searchTheme = "ORKA_SEARCH";

var tabListener1 = null;
var tabListener3 = null;

var mouseOutClass = "buttonOut";
var mouseOverClass = "buttonOver";
var mouseDownClass = "buttonOver";

var mapOutClass = "buttonMapOut";
var mapOverClass = "buttonMapOver";
var mapDownClass = "buttonMapOver";

////////////////////////////////////////////////////////////
// Incremental Buttons.
////////////////////////////////////////////////////////////
var incrButtonIDs = new Array();
incrButtonIDs[0] = "bof";
incrButtonIDs[1] = "prev";
incrButtonIDs[2] = "next";
incrButtonIDs[3] = "eof";

var incrLabels = new Array();
incrLabels[0] = "Beginning of Recordset";
incrLabels[1] = "Previous Record";
incrLabels[2] = "Next Record";
incrLabels[3] = "End of Recordset";

var arrow_t_btnArr = new Array("t_bof", "t_prev", "t_next", "t_eof");
var arrow_b_btnArr = new Array("b_bof", "b_prev", "b_next", "b_eof");
var arrowNameArr = new Array("Beginning of Recordset", "Previous Record", "Next Record", "End of Recordset");
var arrowAltArr = new Array("Beginning", "Previous", "Next", "End");
for (var i = 0; i < arrow_t_btnArr.length; i++) {
    window[arrow_t_btnArr[i] + "1"] = new Image;
    window[arrow_t_btnArr[i] + "1"].src = "orka/images/arrow_" + arrow_t_btnArr[i] + ".gif";
    window[arrow_t_btnArr[i] + "2"] = new Image;
    window[arrow_t_btnArr[i] + "2"].src = "orka/images/arrow_" + arrow_t_btnArr[i] + "roll.gif";

    window[arrow_b_btnArr[i] + "1"] = new Image;
    window[arrow_b_btnArr[i] + "1"].src = "orka/images/arrow_" + arrow_b_btnArr[i] + ".gif";
    window[arrow_b_btnArr[i] + "2"] = new Image;
    window[arrow_b_btnArr[i] + "2"].src = "orka/images/arrow_" + arrow_b_btnArr[i] + "roll.gif";
}
////////////////////////////////////////////////////////////
// END OF GLOBAL VARIABLES
////////////////////////////////////////////////////////////

function makeMapElements() {
    var mainContainer = new dijit.layout.BorderContainer({
        id: "mapContainer",
        design: "sidebar",
        gutters: "false",
        style: "height: 100%; width: 100%;"
    },
        "agsMapStructure");

    var mapPane = new dijit.layout.ContentPane({
        id: "agsMap",
        region: "center",
        style: "margin:5px 0 5px 0;"

    });

    var mapHdr = new dijit.layout.ContentPane({
        id: "mapHdr",
        region: "top",
        style: "width: 100%;"
    });

    mainContainer.addChild(mapHdr);
    mainContainer.addChild(mapPane);
    mainContainer.startup();
}

/////////////////////////////////////////////////////

function focusDelay(srchBtn) {
    console.log("This is focusDelay() : " + srchBtn);
    window.clearTimeout(reloadTimer);
    reloadTimer = window.setTimeout("focusIt('" + srchBtn + "')", timer);
}

/////////////////////////////////////////////////////
// For focusing the appropriate input field.
/////////////////////////////////////////////////////
function focusIt(srchBtn) {
    var dojoTabs = dojo.byId("searchMethodButtons");
    if (dojoTabs != null) {
        switch (srchBtn) {
            case "Owner_Name":
                dojo.byId("lastname").focus();
                break;
            case "Address":
                dojo.byId("strnum").focus();
                break;
            case "Parcel_ID":
                dojo.byId("pid1Input").focus();
                break;
            case "Legal":
                dojo.byId("section").focus();
                break;
            case "Sales":
                dojo.byId("salesFromDate").focus();
                break;
            case "Personal_Property":
                dojo.byId("ppLastName").focus();
                break;

        }
    }
    //console.log("initApp: " + initApp.toString());
}
/////////////////////////////////////////////////////

function setSalesSearchWidgets() {
    var dateStamp = new Date();
    var day = dateStamp.getDate();
    var mo = dateStamp.getMonth();
    mo += 1
    var yr = dateStamp.getFullYear();
    //alert(dateStamp +"\n"+ day +"\n"+ mo +"\n"+ yr);

    var f = document.forms[0];
    var id = "";
    var typ = "";
    var val = "";

    //alert(initSales.toString());

    for (var i = 0; i < f.elements.length; i++) {
        typ = f.elements[i].type;
        id = f.elements[i].id;

        if (initSales) {
            //alert(typ +", "+ id);
            if (id.indexOf("_sale_mo") > -1) {
                if (typ == "select-one")
                    f.elements[i].selectedIndex = mo - 1;
                else if (id.indexOf("h_") > -1)
                    f.elements[i].value = mo;
            }
            if (id.indexOf("_sale_day") > -1) {
                if (typ == "select-one")
                    f.elements[i].selectedIndex = day - 1;
                else if (id.indexOf("h_") > -1)
                    f.elements[i].value = day;
            }
            if (id.indexOf("from_sale_yr") > -1) {
                if (typ == "select-one")
                    f.elements[i].selectedIndex = 20;
                else if (id.indexOf("h_") > -1)
                    f.elements[i].value = yr - 20;
            }
            if (id.indexOf("to_sale_yr") > -1) {
                if (id.indexOf("h_") > -1)
                    f.elements[i].value = yr;
            }

        } else {
            if (id.indexOf("_sale_") > -1 && id.indexOf("h_") < 0) {
                for (var j = 0; j < f.elements.length; j++) {
                    if (f.elements[j].id == "h_" + id) {
                        if (typ == "text")
                            f.elements[i].value = f.elements[j].value;
                        if (typ == "select-one") {
                            for (var k = 0; k < f.elements[i].length; k++) {
                                if (f.elements[i][k].value == f.elements[j].value)
                                    f.elements[i].selectedIndex = k;
                            }
                        }
                        if (typ == "checkbox") {
                            if (f.elements[j].value == "false")
                                f.elements[i].checked = false;
                            else
                                f.elements[i].checked = true;
                        }
                    }
                }
            }
        }
    }
    initSales = false;
}

/////////////////////////////////////////////////////
// For setting hidden tag values.
/////////////////////////////////////////////////////
function setHidden(arg) {
    var id = arg.id;
    var val = arg.value;
    var typ = arg.type;
    var chk = false;

    var chkbx = typ == "checkbox";
    if (chkbx)
        chk = arg.checked;

    //console.log("id: " + id +", val: "+ val +", typ: "+ typ +", chk: "+ chk);

    // f works here because the hidden tags are nested inside the ASP Form tag.
    var f = document.forms[0];

    for (var i = 0; i < f.elements.length; i++) {
        if (f.elements[i].id == "h_" + id) {
            if (chkbx)
                f.elements[i].value = chk.toString();
            else {
                //alert(id +", "+ val +", "+ typ +", "+ chk);

                var proceed = true;

                /* THIS IS A HOLD-OVER FROM URECA 2.0.
                if (id.toUpperCase().indexOf("PID1") > -1)
                {
                if (val.length < pid1Length)
                proceed = false;
                }
                */

                if (proceed)
                    f.elements[i].value = val;
            }
        }
    }
}
/////////////////////////////////////////////////////

/////////////////////////////////////////////////////
// For clearing inputs and results.
/////////////////////////////////////////////////////
function clearIt(clearWhat) {
    console.log("clearWhat: " + clearWhat);
    var srchBtn = dojo.byId("h_searchButton").value;
    console.log("clearIt : tab : " + srchBtn);

    //console.log("clearIt : tab: " + dijit.byId("searchMethodButtons").selectedChildWidget.id);
    
    
    var f = document.forms[0];
    var id = "";
    var typ = "";

    /* clearWhat
    1 = Input Fields
    2 = Results
    3 = All
    4 = Help
    5 = Sales form
    */

    if (clearWhat == 1 || clearWhat == 3) {
        //console.log(1);
        var dojoTabs = dojo.byId("searchMethodButtons");
        if (dojoTabs != null) {
            //console.log(2);
            switch (srchBtn) {
                case "Owner_Name":
                    dojo.byId("lastname").value = "";
                    dojo.byId("firstname").value = "";
                    console.log(3);
                    break;

                case "Address":
                    //dojo.byId("strnum").innerHTML = "";
                    //dojo.byId("strprefix").selectedIndex = 0;
                    //dojo.byId("strname").innerHTML = "";
                    //dojo.byId("strsuffixLabel").selectedIndex = 0;

                    dojo.byId("strnum").value = "";
                    dojo.byId("strnumEndRange").value = "";
                    dojo.byId("strprefix").value = "";
                    dojo.byId("strname").value = "";
                    dojo.byId("strsuffix").value = "";
                    //console.log(4);
                    break;

                case "Legal":
                    dojo.byId("section").value = "";
                    dojo.byId("township").value = "";
                    dojo.byId("range").value = "";
                    //console.log(5);
                    break;

                case "Sales":
                    dojo.byId("sectionSales").value = "";
                    dojo.byId("townshipSales").value = "";
                    dojo.byId("rangeSales").value = "";
                    dojo.byId("salesFromDate").value = "";
                    dojo.byId("salesToDate").value = "";
                    dojo.byId("salesFromPrice").value = "";
                    dojo.byId("salesToPrice").value = "";
                    dojo.byId("propertyType").value = "";
                    dojo.byId("taxUnit").value = "";
                    dojo.byId("neighborhoodCode").value = "";
                    dojo.byId("zipCode").value = "";
                    //console.log(6);
                    break;

                case "Parcel_ID":
                    //dojo.byId("pid1Input").innerHTML = "";
                    dojo.byId("pid1Input").value = "";
                    console.log(6);
                    break;
                    
                case "Personal_Property":
                    dojo.byId("ppLastName").value = "";
                    dojo.byId("ppFirstName").value = "";
                    dojo.byId("ppNameID").value = "";
                    dojo.byId("ppstrnum").value = "";
                    dojo.byId("ppstrnumEndRange").value = "";
                    dojo.byId("ppstrprefix").value = "";
                    dojo.byId("ppstrname").value = "";
                    dojo.byId("ppstrsuffix").value = "";
                    console.log(3);
                    break;
            }
        }

        //console.log("Calling focusDelay() from clearIt()");
        focusDelay(dojo.byId("h_searchButton").value);
    }

    if (clearWhat == 2 || clearWhat == 3) {
        togglePage('hidden', 'hidden', '', '', '', '', '', 'hidden', 'hidden', '', '', '', 'clearIt_' + clearWhat);
    }

    // This is for Help, but isn't currently used.
    if (clearWhat == 4) {
        togglePage('hidden', '', '', '', '', '', '', '', '', '', '', '', 'clearIt_' + clearWhat);
    }

    if (clearWhat == 5) {
        for (var i = 0; i < f.elements.length; i++) {
            typ = f.elements[i].type;
            id = f.elements[i].id

            if (id.indexOf("_sale_") > -1) {
                // Loops to clear each text field.
                // We do not want to clear hidden tags for drop-down dates.
                if (typ == "text" || typ == "hidden") {
                    if (id.indexOf("chkbx") > -1)
                        f.elements[i].value = "false";
                    else if (id.indexOf("h_from") == -1 && id.indexOf("h_to") == -1)
                        f.elements[i].value = "";
                }
                if (typ == "checkbox") {
                    f.elements[i].checked = false;
                }
            }
        }
    }
}

/////////////////////////////////////////////////////
// For clearing buttons and setting a specific one.
/////////////////////////////////////////////////////
function resetSpecificButton(thm, buttonIDs) {
    // The code below is known to be necessary under the following condition:
    // 1. The Theme is Building_Sketch and multiple Building 
    //    Sketches are available for display.
    // 2. popupPic is true. 
    // 3. The user has reset the Theme to Property_Photo and is 
    //    viewing Photos in a separate window.
    // 4. If the user tries to view the next Building Sketch,
    //    the Property Photo window will simply refresh while the 
    //    Building Sketch will remain unchanged.
    // 5. Thus, the following code resets the Theme to Building_Sketch.
    clearButtons(thm, buttonIDs);
    document.getElementById("h_searchTheme").value = thm;
    highlightBtn('buttonOver', thm, 'over', 'theme', 'buttonOut');
}
/////////////////////////////////////////////////////

/////////////////////////////////////////////////////
// For clearing all buttons prior to one being selected.
/////////////////////////////////////////////////////
function clearButtons(btn, buttonIDs) {
    for (var i = 0; i < buttonIDs.length; i++) {
        if (btn != buttonIDs[i]) {
            document.getElementById(buttonIDs[i]).className = mouseOutClass;
        }
    }
}
/////////////////////////////////////////////////////

/////////////////////////////////////////////////////
// onMouseOver and onMouseOut event for Theme and SearchMethod Buttons.
// When the mouse is passed over a button, it is highlighted.  If the user
// clicks the button, it remains hightlighted and, thus, appears selected.
/////////////////////////////////////////////////////
function highlightBtn(clsname, cell, status, source, antiname) {
    //alert(clsname +"\n"+ cell +"\n"+ status +"\n"+ source +"\n"+ antiname);

    var f = document.forms[0];

    document.getElementById(cell).className = clsname;

    var hiddenValue = "";
    switch (source) {
        case "theme":
            hiddenValue = f.h_searchTheme.value;
            break;
        case "search":
            hiddenValue = f.h_searchButton.value;
            break;
        default:
            // Map
            hiddenValue = f.h_mapButton.value;
            break;
    }

    //alert(cell +"\n"+ hiddenValue);

    if (cell == hiddenValue && status == "out") {
        switch (hiddenValue) {
            case "Full_Extent":
            case "Previous_Extent":
            case "Next_Extent":
            case "Clear_Graphics":
                break;
            default:
                document.getElementById(cell).className = antiname;
                break;
        }
    }
}
/////////////////////////////////////////////////////

function sendToPrinter() {
    //document.domain = 'kgs.ku.edu';
    var divMyArea = document.getElementById('themeResults');
    if (divMyArea.innerHTML != '') {
        //sendPrint();
        OpenWindow = window.open("PrintPreview.aspx", "Print_Preview");
        //OpenWindow.document.domain = 'kgs.ku.edu';
        OpenWindow.document.write("<HTML>");
        OpenWindow.document.write("<HEAD>");
        OpenWindow.document.write("<TITLE>Print Preview</TITLE>");
        OpenWindow.document.write("<link rel='stylesheet' type='text/css' href='orka/print.css' />");
        OpenWindow.document.write("<SCRIPT type='text/javascript'>");
        OpenWindow.document.write("function sendToPrinter() { self.focus(); self.print(); }");
        OpenWindow.document.write("</SCRIPT>");
        OpenWindow.document.write("</HEAD>");
        OpenWindow.document.write("<BODY>");
        OpenWindow.document.write("<H2>" + countyName + " County Property Data</H2>");
        OpenWindow.document.write(divMyArea.innerHTML);
        OpenWindow.document.write("</BODY>");
        OpenWindow.document.write("</HTML>");

        OpenWindow.document.close();
    }


    //self.focus();
    //self.print();
}
function sendPopupToPrinter() {
    //document.domain = 'kgs.ku.edu';
    var divMyArea = document.getElementById('themeResults');
    if (divMyArea.innerHTML != '') {
        //sendPrint();
        OpenWindow = window.open("PrintPreview.aspx", "Print_Preview");
        //OpenWindow.document.domain = 'kgs.ku.edu';
        OpenWindow.document.write("<HTML>");
        OpenWindow.document.write("<HEAD>");
        OpenWindow.document.write("<TITLE>Print Preview</TITLE>");
        OpenWindow.document.write("<link rel='stylesheet' type='text/css' href='orka/print.css' />");
        OpenWindow.document.write("<SCRIPT type='text/javascript'>");
        OpenWindow.document.write("function sendPopupToPrinter() { self.focus(); self.print(); }");
        OpenWindow.document.write("</SCRIPT>");
        OpenWindow.document.write("</HEAD>");
        OpenWindow.document.write("<BODY>");
        OpenWindow.document.write(divMyArea.innerHTML);
        OpenWindow.document.write("</BODY>");
        OpenWindow.document.write("</HTML>");

        OpenWindow.document.close();
    }


    //self.focus();
    //self.print();
}
function sendPrint()
{
	var divMyArea = document.getElementById('themeResults');
	
	//alert('test ' + document.domain);
	/*var pdfDataHtm = {pdfData:{escape(divMyArea.innerHTML)}};*/
	var pdfDataHtm = escape(divMyArea.innerHTML);
	alert(pdfDataHtm);

	var xhrArgs = {
	    url: "maps.kgs.ku.edu/orka/getPdf.cfm",
	    content: {prHtml:'test'},
	    load: function(data) {
		alert('Sent');
	    },
	    error: function(error) {
		alert('Error');

	    }
	};
	alert('print');
		dojo.xhrPost(xhrArgs);
}	

/////////////////////////////////////////////////////
// Makes Increment Buttons.
// Executed many times.
/////////////////////////////////////////////////////
function makeIncrButtons(po) {
    var htmlTxt = "";

    for (var i = 0; i < incrButtonIDs.length; i++) {
        htmlTxt += '<TD width="1%" align="Center" valign="Top">';
        switch (po) {
            case "bottom":
                // Bottom buttons.
                htmlTxt += '<A href="javascript:incrRecords(\'' + incrButtonIDs[i] + '\')" ';
                htmlTxt += 'onmouseover="window.status=\'' + arrowNameArr[i] + '\'; hilightIncrBtn(\'' + arrow_b_btnArr[i] + '\',\'' + arrow_b_btnArr[i] + '2\'); return true;" ';
                htmlTxt += 'onmouseout="window.status=\' \'; hilightIncrBtn(\'' + arrow_b_btnArr[i] + '\',\'' + arrow_b_btnArr[i] + '1\'); return true;">';
                htmlTxt += '<IMG alt="' + arrowAltArr[i] + '" src="orka/images/arrow_' + arrow_b_btnArr[i] + '.gif" border="0" height="21" id="' + arrow_b_btnArr[i] + '">';
                htmlTxt += '</A>';

                break;

            default:
                // Top buttons.
                htmlTxt += '<A href="javascript:incrRecords(\'' + incrButtonIDs[i] + '\')" ';
                htmlTxt += 'onmouseover="window.status=\'' + arrowNameArr[i] + '\'; hilightIncrBtn(\'' + arrow_t_btnArr[i] + '\',\'' + arrow_t_btnArr[i] + '2\'); return true;" ';
                htmlTxt += 'onmouseout="window.status=\' \'; hilightIncrBtn(\'' + arrow_t_btnArr[i] + '\',\'' + arrow_t_btnArr[i] + '1\'); return true;">';
                htmlTxt += '<IMG alt="' + arrowAltArr[i] + '" src="orka/images/arrow_' + arrow_t_btnArr[i] + '.gif" border="0" height="21" id="' + arrow_t_btnArr[i] + '">';
                htmlTxt += '</A>';

                break;
        }

        htmlTxt += '</TD>\n';
    }

    //alert(htmlTxt);
    return htmlTxt;
}

function hilightIncrBtn(imgDocID, imgObjName) {
    var f = document.forms[0];
    if (f != null && f.h_searchTheme != null) {
        var b = f.h_searchTheme.value;
        if (b == "" || b != imgDocID)
            document.images[imgDocID].src = eval(imgObjName + ".src");
    }
}
/////////////////////////////////////////////////////

function checkForTabChange() {
    var srchBtn = dojo.byId("h_searchButton").value;
    var childId = dijit.byId("searchMethodButtons").selectedChildWidget.id
    console.log("checkForTabChange: " + childId);
    if (srchBtn != childId) {
        dojo.byId("h_searchButton").value = childId;
        //console.log("Calling focusDelay() from checkForTabChange()");
        focusDelay(childId);
    }
}

function checkForSubmit(event, btn) {
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
        /*
        if (event.which)
        alert("event.which: " + event.which.toString())
        if (event.keyCode)
        alert("event.keyCode: " + event.keyCode.toString())
        */

        dojo.byId(btn).click();

        return true;

    } else {
        return false;
    }
}

/////////////////////////////////////////////////////
// Miscellaneous functions.
/////////////////////////////////////////////////////
function getVar(inText, theVar) {
    var theTmpVar = null;
    startpos = inText.indexOf(theVar);
    if (startpos != -1) {
        var nextpos = inText.indexOf("=", startpos);
        var endpos = inText.indexOf("&", nextpos);
        if (endpos == -1) endpos = inText.length;
        //alert('nextpos: ' + nextpos +'\nendpos: '+ endpos);
        theTmpVar = inText.substr((nextpos + 1), ((endpos - 1) - nextpos));
    }
    //alert('inText: ' + inText +'\ntheVar: '+ theVar +'\ntheTmpVar: '+ theTmpVar);
    return theTmpVar;
}

function getRandom(factor) {
    // To determine the factor, divide 9.99 by slightly less
    // than the last element.  For 0-2, factor = 9.99 / 1.9

    // Selects a random number for establishing image.
    var randomNum = 0;
    randomNum = Math.random();
    var theInt = ((randomNum * 10) / Number(factor));
    var num = Math.round(theInt);

    //alert("random: "+ randomNum +"\nint: "+ theInt +"\nnum: "+ num);

    return num;
}

function replaceBlankSpace(inText) {
    var space = / /g;
    inText = inText.replace(space, "");
    return inText;
}
function replaceSpacer(inText) {
    var spacer = /%20/g;
    inText = inText.replace(spacer, " ");
    return inText;
}
function replaceWithUnderscore(inText) {
    var spacer = / /g;
    inText = inText.replace(spacer, "_");
    return inText;
}
function replaceUnderscore(inText) {
    var spacer = /_/g;
    inText = inText.replace(spacer, " ");
    return inText;
}
function getDateStamp() {
    // Note: dateStamp must not contain pluses (+).
    var dateStamp = new Date();
    dateStamp = dateStamp.toLocaleString();
    dateStamp = dateStamp.toString();
    // Eliminates comma within dateStamp.
    var r = /\,/g;
    var newDateStamp = dateStamp.replace(r, "");

    return newDateStamp;
}
/////////////////////////////////////////////////////

