﻿function popRedirect(text, url) {
    alert(text);
    if (url.length > 0) {
        window.location = url;
    }
}
function platHoover(control, color, border, borderType) {    
    control.style.borderTop = border[0] + 'px ' + borderType + ' ' + color;
    control.style.borderBottom = border[1] + 'px ' + borderType + ' ' + color;
    control.style.borderRight = border[2] + 'px ' + borderType + ' ' + color;
    control.style.borderLeft = border[3] + 'px ' + borderType + ' ' + color;
    
    //control.style.backgroundColor = (border[1] == 2) ? "#efefef" : "#ffffff";
}
function maskPostNr(element) {
    $(element).setMask({
        mask: '99999'
    });
}
function maskMobileNr(element) {
    $(element).setMask({
        mask: '999-9999999',
        type: 'infinite'
    });
}
function maskOrgNr(element) {
    var val = $(element).val();
    if (val.length == 4 && val.substring(0, 2).toLowerCase() != 'se') {        
        $(element).setMask({
            mask: '999999-9999',
            type: 'infinite'
        });
    }
    if (val.length < 4) {
        $(element).unsetMask();
    }
}
function maskPhoneNr(element) {
    var subThree = $(element).val().substring(0, 3);
    var val = $(element).val();
    if($(element).val().length == 4) {
        if ($(element).val().substring(0, 2) == '08') {
            $(element).setMask({
               mask: '99-999999',
               type: 'infinite'
            });
        }
        else if (subThree == '031' || subThree == '018' || subThree == '021'
                || subThree == '016' || subThree == '018' || subThree == '019'
                || subThree == '011' || subThree == '033' || subThree == '013'
                || subThree == '023' || subThree == '026' || subThree == '033'
                || subThree == '035' || subThree == '036' || subThree == '040'
                || subThree == '042' || subThree == '044' || subThree == '033'
                || subThree == '046' || subThree == '054' || subThree == '060'
                || subThree == '063' || subThree == '090' || subThree == '033'
                || subThree == '020')  {                
                $(element).setMask({
                   mask: '999-999999',
                   type: 'infinite'
                });
        }
        else {
            $(element).setMask({
               mask: '9999-999999',
               type: 'infinite'
            });
        }
    }
    else if ($(element).val().length < 4) {
        $(element).unsetMask();
    }
}
function redirectToStartPage() {
    window.location.href = "Default.aspx";
}
function hooverAdd(id, mouseOver) {
    var values = id.split("_");
    var topIndex = parseInt(values[1]) - 1;
    var topItem = $("#" + values[0] + "_" + topIndex);
    var thisItem = $("#" + id);
    
    if (mouseOver) {
        topItem.css("border-bottom", "2px solid #f6cc08");
        thisItem.css("border-bottom", "2px solid #f6cc08");        
        topItem.css("margin-bottom", "4px");
        thisItem.css("margin-bottom", "4px");
    }
    else {
        topItem.css("border-bottom", "1px solid #c0c0c0");
        thisItem.css("border-bottom", "1px solid #c0c0c0")        
        topItem.css("margin-bottom", "5px");
        thisItem.css("margin-bottom", "5px");
    }
    
}
function search(path) {
    var what = $("#ctl00_txtSearchWhat").val();
    var where = $("#ctl00_txtSearchWhere").val();
    
    if (what.length > 0 && where.length > 0)
        window.location.href = path + "?q=" + what + "&w=" + where;
    else if (what.length > 0 && where.length < 1)
        window.location.href = path + "?q=" + what + "&w=";
    else if (what.length < 1 && where.length > 0)
        window.location.href = path + "?q=&w=" + where;   
}
function captureReturn(event, path)
{
    $(window).keypress(function(event) {
        if (!(event.which == 13)) return true;
        search(path);
        event.preventDefault();
        return false;
    });
}
function masterLoad() {
    jQuery("#ctl00_txtSearchWhat").focus();
}
