﻿var usedemails = null;
var pageLoaded = null;

function clientInitMaster() {
    hideLoadingDiv();
    if (getId("m_hfSessionID") != null)
        getId("lblSessionID").innerHTML = getId("m_hfSessionID").value;
}
function getRandomInt() {
    return parseInt(Math.random() * 10000000);
}
function getId(id) {
    return document.getElementById(id);
}
function getSessionID() {
    return getId("m_hfSessionID").value;
}
function isMember(value, arr) {
    if (!arr)
        return false;
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == value)
            return true;
    }
    return false;
}
function formatAsMoney(mnt) {
    if (mnt == "confirm") {     
            return ScriptStrings[5];        
    }
    else {
        var amountStr = parseFloat(mnt).toFixed(2).toString().replace(".", ",");
        if (amountStr.indexOf(",") == -1)
            amountStr += ",00";
        else {
            if (amountStr.substring(amountStr.indexOf(",")).length == 1)
                amountStr += "0";
        }
        return "€ " + pointsOnThousands(amountStr);
    }
}
function pointsOnThousands(mnt) {

    if (mnt.indexOf(".")!=-1)
        return mnt;
    var split = mnt.split(',');
    if (split[0].length < 4)
        return mnt;
     
    var th = split[0].substring(0, split[0].length - 3) + "." + split[0].substring(split[0].length - 3);
    if (split.length > 1)
        th += "," + split[1];
    return th;
}

function formatComma(mnt) {
    if (mnt.toString().indexOf(".") != -1)
        return mnt.toString().replace(".", ",");
    else return mnt;
    
}


function parseCommaFloat(val) {
    var valstr = val.toString();
    return parseFloat(valstr.replace(",", "."));
}
function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
function preloadPic(location) {
    var pic = new Image(100,100);
    pic.src = location;
}

function readEmailsCookie() {
    var emails = readCookie("usedemails");
    if (emails) {
        //  alert("returned " + emails);
        return emails.split("/");
    }
}
function saveEmailAsCookie(email) {
    var emailstring = readCookie("usedemails");    
    if (emailstring) {
        if (emailstring.indexOf(email) == -1) {            
            emailstring += email + "/";
        }
    }
    else
        emailstring = email + "/";
    //alert("creating cookie named usedemails with value: " + emailstring); 
    setCookie("usedemails", emailstring, 100, "/", "authentic.be", "");
}

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 setCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
            ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
            ((path) ? ";path=" + path : "") +
            ((domain) ? ";domain=" + domain : "") +
            ((secure) ? ";secure" : "");
}
function fitName(name, pos) {
    if (name.length > pos)
        return name.substr(0, pos) + "...";
    else
        return name;
}
function arrayContains(arr,val) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == val)
            return true;
    }
    return false;
}
function weightFor(opp, weight) {
    return opp * weight;
}




function insideBrusselsAgglo(postcode) {    
    if (("1070 1000 1020 1120 1130 1040 1050 1050 1040 1140 1083 1090 1081 1160 1030 1082 1060 1080 1210 1200 1150 1180 1190 1170").indexOf(trim(postcode)) != -1)
        return true
    else return false;
}
function trim(s) {
    s = s.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");
    return s;
}

function showImage(src) {
    getId("divShowImage").style.display = "block";
    getId("imgShowImage").src = src;
}


function removeItem(arr, itemToRemove) {    
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == itemToRemove) {
            arr.splice(i, 1);
        }
    }
}

function getScrollX() {
    var s = window.pageXOffset;
    if (s == null)
        s = document.documentElement.scrollLeft;
    return s;
}
function getScrollY() {
    var s = window.pageYOffset;
    if (s == null)
        s = document.documentElement.scrollTop;
    return s;
}

function checkFlashOrSilverlight()
{
    if (DetectFlashVer(8, 0, 0) == true || isSilverlightInstalled() == true)
        getId("m_ContentPlaceHolder1_hfFlashOrSilverlight").value = "true";
    else
        getId("m_ContentPlaceHolder1_hfFlashOrSilverlight").value = "false";
}

function hideInstallPlugin() {
    getId("divInstallPlugin").style.display = "none";
    getId("pageDimmerFormsClient").style.display = "none";
}
function waitPluginInstall() {
    getId("choosePlugin").style.display = "none";
    getId("waitPlugin").style.display = "block";
}
 
/*
function getReducedDimensionsFor(width, height, maxSize)
{
    var newDim = new Array();
    newDim.push(0);
    newDim.push(1);
    if (width > height)
    {
        newDim[0] = maxSize;
        newDim[1] = parseInt(parseFloat(height)/parseFloat(width) * maxSize);
    }
    else
    {
        newDim[0] = parseInt(parseFloat(width) / parseFloat(height) * maxSize);
        newDim[1] = maxSize;
    }
    return newDim;
}
*/
function toStep1() {
    window.location = "http://www.authentic.be/OnlineBestellen/Diasec/HttpUpload.aspx?s=" + getSessionID();
}

function toStep2() {
    window.location = "http://www.authentic.be/OnlineBestellen/Diasec/ImagePreferences.aspx?s=" + getSessionID();
}

function toHttpUpload() {
    window.location = "http://www.authentic.be/OnlineBestellen/Diasec/HttpUpload.aspx?s=" + getSessionID() + "&ignorePreset=true";
}

function highLightcat() {    
    getId("cat_" + getId('inputProduct').value + "_td1").className = "productmenu-btn-l-HL";
    var td2 = getId("cat_" + getId('inputProduct').value + "_td2");
    td2.className = "productmenu-btn-c-HL";
    //td2.getElementsByTagName("a")[0].className = "largeDarkBlueLabel";    
    getId("cat_" + getId('inputProduct').value + "_td3").className = "productmenu-btn-r-HL";

        
    cat.style.borderBottom = '3px dotted red';
    cat.style.color = '#F70000';
}
