﻿
/******************************* Function that displays years in business for Pristine. It will change every August 1st. */
var one_day = 1000 * 60 * 60 * 24
var one_month = 1000 * 60 * 60 * 24 * 30
var one_year = 1000 * 60 * 60 * 24 * 30 * 12

function displayprsyrs(yr, mon, day, unit, decimal, round) {
    today = new Date()
    var pastdate = new Date(yr, mon - 1, day)

    var countunit = unit
    var decimals = decimal
    var rounding = round

    finalunit = (countunit == "days") ? one_day : (countunit == "months") ? one_month : one_year
    decimals = (decimals <= 0) ? 1 : decimals * 10

    if (unit != "years") {
        if (rounding == "rounddown")
            document.write(Math.floor((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals + " " + countunit)
        else
            document.write(Math.ceil((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals + " " + countunit)
    }
    else {
        yearspast = today.getFullYear() - yr - 1
        tail = (today.getMonth() > mon - 1 || today.getMonth() == mon - 1 && today.getDate() >= day) ? 1 : 0
        pastdate.setFullYear(today.getFullYear())
        pastdate2 = new Date(today.getFullYear() - 1, mon - 1, day)
        tail = (tail == 1) ? tail + Math.floor((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals : Math.floor((today.getTime() - pastdate2.getTime()) / (finalunit) * decimals) / decimals
        document.write(yearspast + tail + " " + countunit)
    }
}

/************ to print part of page **************/
function printPartOfPage(elementId) {
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}

/************ large pop page for more info **************/
function popInfo(url, w, h) {
    var info = window.open(url, 'info', 'width=' + w + ',height=' + h + ',toolbar=0,location=1,status=0,menubar=0,scrollbars=1,resizable=1');
 
}


/************ functions for search **************/

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}
// Function for search 2
function SubmitOnEnter(myfield, e) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;
    if (keycode == 13) {
        SearchSite();
        return false;
    }
    else
        return true;
}
function SearchSite() {
    document.location.href = '/Search.aspx?cx=006949314916960143863:cezwxxjpjcc&cof=FORID%3A9&ie=UTF-8&q=' +
URLEncode(document.getElementById('q').value) + '&sa=Search';
}
