﻿/// <reference path="jquery-1.4.2.min.js" />
/// <reference path="jquery.json-1.3.min.js" />

$(document).ready(function() {
    $("#showPhoneBook").click(function() {
        $("#showPhoneBook").nyroModalManual({ bgColor: '#fefefe', css: { bg: { background: 'transparent url(/App_Themes/generic/images/transparent_bg.png) repeat scroll 0 0' } } });
        alternateColor();
        // $("#showPhoneBook").nyroModalManual();
    });
});

function setFocus() {
    if (document.getElementById("ctl00_MainContent_Login_TxtMSISDN") != null)
        document.getElementById("ctl00_MainContent_Login_TxtMSISDN").focus();
}
function switchVnovcevanjeVisibility() {
    var x;
    var ElementsToSwitch = new Array();
    ElementsToSwitch[0] = "DivVnovcevanjeIzimobil";
    ElementsToSwitch[1] = "DivVnovcevanje3dva";
    ElementsToSwitch[2] = "DivVnovcevanjeSMS";
    //ElementsToSwitch[3] = "DivVnovcevanjeMobilna";
    ElementsToSwitch[3] = "DivVnovcevanjeMobyStyle";
    ElementsToSwitch[4] = "DivSTS";
    ElementsToSwitch[5] = "DivVision";
    ElementsToSwitch[6] = "DivMCom";
    ElementsToSwitch[7] = "DivPrimo";
    ElementsToSwitch[8] = "DivSTM";
    ElementsToSwitch[9] = "DivMicroERA";
    ElementsToSwitch[10] = "DivMSPlus";
    ElementsToSwitch[11] = "DivCondorPlus";
    i = 0;
    for (x in ElementsToSwitch) {
        if (document.getElementById(ElementsToSwitch[x])) {
            if (document.getElementById(ElementsToSwitch[x]).style.display != 'none') {
                //$(document).ready(function() {  //$("#" + document.getElementById(ElementsToSwitch[x]).id + "").slideUp(2000); //});
                document.getElementById(ElementsToSwitch[x]).style.display = 'none';
                if (x == ElementsToSwitch.length - 1) {
                    //$(document).ready(function() {  //$("#" + document.getElementById(ElementsToSwitch[0]).id + "").slideDown(2000);   //}); 
                   document.getElementById(ElementsToSwitch[0]).style.display = '';
                } else {
                    //$(document).ready(function() {  //$("#" + document.getElementById(ElementsToSwitch[parseInt(x) + 1]).id + "").slideDown(2000);   //});
                    document.getElementById(ElementsToSwitch[parseInt(x) + 1]).style.display = '';
                }
                break;
            }
        }
    }
    setTimeout ( 'switchVnovcevanjeVisibility()', 6000 );
}
function SwitchImg() {
    $(document).ready(function(e) {
//        $("#divSwitchImg img").toggle(0); //function() {
//        setTimeout('SwitchImg()', 7000);
    });
}

function Count(field, count, max) {
    document.getElementById("txtCounter").value = (max - field.value.length);
    if (field.value.length >= max) {
        field.value = field.value.substring(0, max);
        document.getElementById("txtCounter").value = 0;
    }
}
function AllowedChars(str) {
    document.getElementById(ResponseMessageID).innerHTML = "";
    var re = new RegExp("[A-Z\s\n\f  abcdefghijklmnopqrstuvwxyzäöñü0123456789!\"#%&‘()*+,-./:;<=>?@£$¥èéùìòÇLFØøCRÅåßÉ]+");
    sWrongChars = '';
       
    for (i = 0; i < str.length; i++) {
        if (str[i].match(re)) { }
        else { sWrongChars += "'" + str[i] + "'  "; }
    }
    if (sWrongChars == '') {
        return true;
    }
    else {
        document.getElementById(ResponseMessageID).innerHTML = "<font style='color: red;'>Nedovoljeni znaki: " + sWrongChars + ".</font>";
        return false;
    }
}

function checkRecipients() {
    if (document.getElementById("ctl00_MainContent_txtBoxRec").value == "") {
        document.getElementById("inter").innerHTML = "<font style='color: red;'> Vnesi mobilno številko prejemnikov.</font>";
        return false;
    }
    else {
//        reg = new RegExp("^\s[0-9,]+$", "i");
//        var crke = document.getElementById("ctl00_MainContent_txtBoxRec").value.trim();
//        if (reg.test(crke) != true) {
//            document.getElementById("inter").innerHTML = "<font style='color: red;'> Preveri mobilne številke prejemnikov. </font>";
//            return false;
        // } else { return true };
        return true;
    }
}

function SelectAllCheckboxes(spanChk) {
    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
    var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];
    xState = theBox.checked;
    elm = theBox.form.elements;
    for (i = 0; i < elm.length; i++)
        if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
        //elm[i].click();
        if (elm[i].checked != xState)
            elm[i].click();
        //elm[i].checked=xState; 
    }
}
$(document).ready(function() {
    $("a").each(function() {
        if (this.href == window.location.href.split("#")[0]) {
            $(this).addClass("activeNavi");
        }
    });
});
function showModalPopupViaClient() {
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}
function hideModalPopupViaClient() {
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}
function CheckCookies() {
    if (navigator.cookieEnabled)
        return true;
    else return false;
}
function ValidateChk(oSource, args) {
    var myCheckBox = document.getElementById('ctl00_MainContent_ChkAgreeSPU');
    if (!myCheckBox.checked) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}
function addNewRow() {
    var myTable = document.getElementById("tableRef");
    var tBody = myTable.getElementsByTagName("tbody")[0];
    var newTR = document.createElement("tr");
    var newTD = document.createElement("td");
    newTD.innerHTML = "<input type='text' name='email' style='width: 190px;' /> <span style='visibility: hidden; color:red;'>*</span>&nbsp&nbsp<a href='javascript:void(null);' text='x' onclick='this.parentNode.parentNode.removeChild(this.parentNode);' >briši</a>"; //"<input type='text' name='name' onsubmit='isEmpty(this);' onblur='isEmpty(this);' style='width: 190px;' />&nbsp<span style='visibility: hidden; color:red;'>*</span>&nbsp&nbsp&nbsp<input type='text' onblur='isEmail(this.value);' name='email' style='width: 190px;' /> <span style='visibility: hidden; color:red;'>*</span>&nbsp<a href='#' text='x' onclick='this.parentNode.parentNode.removeChild(this.parentNode);' >briši</a>";
    newTR.appendChild(newTD);
    tBody.appendChild(newTR);
}
function isEmpty(jso) {
    if (jso.value.length >= 2) {
        return true;
    } else {
        alert("Vnesi ime.");
        return false;
    }
}
function isEmail(string) {
    if (string.search(/^[a-zA-Z0-9._+-]+@[a-zA-Z0-9._+-]+\.[a-zA-Z0-9]{2,4}$/) != -1) { 
        return true;
    } else { return false; }
}

