﻿//-----------------------------------------------------------------------
//-----------------NUMBERS ONLY START------------------------------------
//-----------------------------------------------------------------------
//this function is to enable only numbers in a textbox
// to use add   onkeydown="return numbersOnly(event);"   to the text box

function numbersOnly(e) {
    var evt = (e) ? e : window.event;
    var key = (evt.keyCode) ? evt.keyCode : evt.which;

    if (key != null) {
        key = parseInt(key, 10);

        if ((key < 48 || key > 57) && (key < 96 || key > 105)) {
            if (!isUserFriendlyChar(key))
                return false;
        }
        else {
            if (evt.shiftKey)
                return false;
        }
    }

    return true;
}

function isUserFriendlyChar(val) {
    // Backspace, Tab, Enter, Insert, and Delete
    if (val == 8 || val == 9 || val == 13 || val == 45 || val == 46)
        return true;

    // Ctrl, Alt, CapsLock, Home, End, and Arrows
    if ((val > 16 && val < 21) || (val > 34 && val < 41))
        return true;

    // The rest
    return false;
}


//-----------------------------------------------------------------------
//-----------------NUMBERS ONLY END------------------------------------
//-----------------------------------------------------------------------


//-----------------------------------------------------------------------
//-----------------DATE SELECTOR START------------------------------------
//-----------------------------------------------------------------------
//this script is for date selector. fills drop downs with dates
//to use :
//add these line to the html :
//<select id="slDays"></select><select id="slMonths"></select><select id="slYears"></select>
//<script type="text/javascript">fill_select('slDays', 'slMonths', 'slYears'); year_install('slDays', 'slMonths', 'slYears',minYear,MaxYear);</script>
//                                                                                                       the minimum year and the maximum year


var date_arr = new Array;
var days_arr = new Array;

date_arr[0] = new Option("1", "31,1");
date_arr[1] = new Option("2", "28,2");
date_arr[2] = new Option("3", "31,3");
date_arr[3] = new Option("4", "30,4");
date_arr[4] = new Option("5", "31,5");
date_arr[5] = new Option("6", "30,6");
date_arr[6] = new Option("7", "31,7");
date_arr[7] = new Option("8", "31,8");
date_arr[8] = new Option("9", "30,9");
date_arr[9] = new Option("10", "31,10");
date_arr[10] = new Option("11", "30,11");
date_arr[11] = new Option("12", "31,12");

function fill_select(slDaysId, slMonthsId, slYearsId) {
    var hElmDaysSelect = document.getElementById(slDaysId);
    var hElmMonthsSelect = document.getElementById(slMonthsId);
    hElmMonthsSelect.setAttribute('onchange', 'update_days("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');

    for (x = 0; x < 12; x++) {
        var option = document.createElement('OPTION');
        option.setAttribute('value', date_arr[x].value);
        option.innerHTML = date_arr[x].text;
        hElmMonthsSelect.appendChild(option);
    }
    selection = parseDays(hElmMonthsSelect[hElmMonthsSelect.selectedIndex].value);
}

function parseDays(ValueOfMonth) {
    return parseInt(ValueOfMonth.split(",", 2)[0]);
}

function update_days(slDaysId, slMonthsId, slYearsId, postBack) {
    var hElmYearsSelect = document.getElementById(slYearsId);
    var hElmMonthsSelect = document.getElementById(slMonthsId);
    var hElmDaysSelect = document.getElementById(slDaysId);



    temp = hElmDaysSelect.selectedIndex;
    for (x = days_arr.length; x > 0; x--) {
        days_arr[x] = null;
        hElmDaysSelect.options[x] = null;
    }

    selection = parseDays(hElmMonthsSelect[hElmMonthsSelect.selectedIndex].value);
    ret_val = 0;
    if (selection == 28) {
        year = parseInt(hElmYearsSelect.options[hElmYearsSelect.selectedIndex].value);
        if (year % 4 != 0 || year % 100 == 0) ret_val = 0;
        else
            if (year % 400 == 0) ret_val = 1;
        else
            ret_val = 1;
    }
    selection = selection + ret_val;
    for (x = 1; x < selection + 1; x++) {
        days_arr[x - 1] = new Option(x);
        hElmDaysSelect.options[x - 1] = days_arr[x - 1];
    }
    if (temp == -1) hElmDaysSelect.options[0].selected = true;
    else
        hElmDaysSelect.options[temp].selected = true;


}




function year_install(slDaysId, slMonthsId, slYearsId, minYear, maxYear) {
    var hElmYearsSelect = document.getElementById(slYearsId);
    hElmYearsSelect.setAttribute('onchange', 'update_days("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');


    for (x = minYear; x <= maxYear; x++) {
        var option = document.createElement('option');
        option.setAttribute('value', x);
        option.innerHTML = x;
        hElmYearsSelect.appendChild(option);
    }



    update_days(slDaysId, slMonthsId, slYearsId);
}
//-----------------------------------------------------------------------
//-----------------DATE SELECTOR END------------------------------------
//-----------------------------------------------------------------------


//-----------------------------------------------------------------------
//-----------------DATE SELECTOR WITH STYLISH SELECT START---------------
//-----------------------------------------------------------------------
//this script is for date selector. fills drop downs with dates
//to use :
//add these line to the html :
//<select id="slDays"></select><select id="slMonths"></select><select id="slYears"></select>
//<script type="text/javascript">fill_select('slDays', 'slMonths', 'slYears'); year_install('slDays', 'slMonths', 'slYears',minYear,MaxYear);</script>
//the minimum year and the maximum year


function fill_selectST(slDaysId, slMonthsId, slYearsId) {
    var hElmDaysSelect = document.getElementById(slDaysId);
    var hElmMonthsSelect = document.getElementById(slMonthsId);

    hElmMonthsSelect.setAttribute('onchange', 'update_daysST("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');

    for (x = 0; x < 12; x++) {
        var option = document.createElement('OPTION');
        option.setAttribute('value', date_arr[x].value);
        option.innerHTML = date_arr[x].text;
        hElmMonthsSelect.appendChild(option);
    }
    selection = parseDays(hElmMonthsSelect[hElmMonthsSelect.selectedIndex].value);

    //    var x = hElmYearsSelect.selectedIndex;
    //    alert("Years: " + hElmYearsSelect.options[x].value);
}





function update_daysST(slDaysId, slMonthsId, slYearsId) {

    var hElmYearsSelect = document.getElementById(slYearsId);
    var hElmMonthsSelect = document.getElementById(slMonthsId);
    var hElmDaysSelect = document.getElementById(slDaysId);

    var hElmDaysUl = GetULOfSelect(hElmDaysSelect);

    temp = hElmDaysSelect.selectedIndex;
    var tempLi;
    for (x = days_arr.length; x > 0; x--) {
        days_arr[x] = null;
        hElmDaysSelect.options[x] = null;

    }

    var hElmDaysUl = GetULOfSelect(hElmDaysSelect);

    selection = parseDays(hElmMonthsSelect[hElmMonthsSelect.selectedIndex].value);
    ret_val = 0;
    if (selection == 28) {
        year = parseInt(hElmYearsSelect.options[hElmYearsSelect.selectedIndex].value);
        if (year % 4 != 0 || year % 100 == 0) ret_val = 0;
        else
            if (year % 400 == 0) ret_val = 1;
        else
            ret_val = 1;
    }
    var TempLi;
    selection = selection + ret_val;
    for (x = 1; x < selection + 1; x++) {
        days_arr[x - 1] = new Option(x);
        hElmDaysSelect.options[x - 1] = days_arr[x - 1];

        TempLi = hElmDaysUl.getElementsByTagName("li")[x - 1];
        TempLi.setAttribute("style", "display:block");
    }

    if (temp == -1) hElmDaysSelect.options[0].selected = true;
    else
        hElmDaysSelect.options[temp].selected = true;

    //    
    //    
    //    var x = hElmYearsSelect.selectedIndex;
    //    alert("Years: " + hElmYearsSelect.options[x].value);
    //    

    //    x = hElmMonthsSelect.selectedIndex;
    //    alert("Months: "+hElmMonthsSelect.options[x].text);

    //    x = hElmDaysSelect.selectedIndex;
    //    alert("Days: "+ hElmDaysSelect.options[x].text);
    //    
}

function GetULOfSelect(hElmDaysSelect) {
    var par = hElmDaysSelect.parentNode;
    var div1 = par.getElementsByTagName('div')[0];
    var UlDiv = div1.getElementsByTagName('ul')[0];
    GetBlankUL(UlDiv);
    return UlDiv;
}

function GetBlankUL(hElmUlToBlank) {
    var i;
    var TempLi;
    for (i = 0; i < (hElmUlToBlank.getElementsByTagName("li")).length; i++) {
        TempLi = hElmUlToBlank.getElementsByTagName("li")[i];
        TempLi.setAttribute("style", "display:none");
    }
}


function year_installST(slDaysId, slMonthsId, slYearsId, minYear, maxYear) {
    var hElmYearsSelect = document.getElementById(slYearsId);

    hElmYearsSelect.setAttribute('onchange', 'update_daysST("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');

    for (x = minYear; x <= maxYear; x++) {
        option = document.createElement('option');
        option.setAttribute('value', x);
        option.innerHTML = x;
        hElmYearsSelect.appendChild(option);
    }


    update_days(slDaysId, slMonthsId, slYearsId);
}

function msgInDayDropDown(slDaysId, slMonthsId, slYearsId) {
    var hElmDaysSelect = document.getElementById(slDaysId);
    var par = hElmDaysSelect.parentNode;
    var div1 = par.getElementsByTagName('div')[0];
    var div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'יום';

    var hElmMonthsSelect = document.getElementById(slMonthsId);
    par = hElmMonthsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'חודש';

    var hElmYearsSelect = document.getElementById(slYearsId);
    par = hElmYearsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'שנה';
}


function msgInDayDropDownArb(slDaysId, slMonthsId, slYearsId) {
    var hElmDaysSelect = document.getElementById(slDaysId);
    var par = hElmDaysSelect.parentNode;
    var div1 = par.getElementsByTagName('div')[0];
    var div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'يوم';

    var hElmMonthsSelect = document.getElementById(slMonthsId);
    par = hElmMonthsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'شهر';

    var hElmYearsSelect = document.getElementById(slYearsId);
    par = hElmYearsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    div2.innerHTML = 'سنة';
}

function ValidateDate(source, args) {

    slDaysId='ctl00_ctl00_BasicMasterPage_cphWebPageContent_slDays';
    slMonthsId='ctl00_ctl00_BasicMasterPage_cphWebPageContent_slMonths';
    slYearsId = 'ctl00_ctl00_BasicMasterPage_cphWebPageContent_slYears';
    
    
    var hElmDaysSelect = document.getElementById(slDaysId);
    var par = hElmDaysSelect.parentNode;
    var div1 = par.getElementsByTagName('div')[0];
    var div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'יום') args.IsValid = false;
    
    var hElmMonthsSelect = document.getElementById(slMonthsId);
    par = hElmMonthsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'חודש') args.IsValid = false;

    var hElmYearsSelect = document.getElementById(slYearsId);
    par = hElmYearsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'שנה') args.IsValid = false;

    //return true;
}

function ValidateDateArb(source, args) {

    slDaysId = 'ctl00_ctl00_BasicMasterPage_cphWebPageContent_slDays';
    slMonthsId = 'ctl00_ctl00_BasicMasterPage_cphWebPageContent_slMonths';
    slYearsId = 'ctl00_ctl00_BasicMasterPage_cphWebPageContent_slYears';


    var hElmDaysSelect = document.getElementById(slDaysId);
    var par = hElmDaysSelect.parentNode;
    var div1 = par.getElementsByTagName('div')[0];
    var div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'يوم') args.IsValid = false;

    var hElmMonthsSelect = document.getElementById(slMonthsId);
    par = hElmMonthsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'شهر') args.IsValid = false;

    var hElmYearsSelect = document.getElementById(slYearsId);
    par = hElmYearsSelect.parentNode;
    div1 = par.getElementsByTagName('div')[0];
    div2 = div1.getElementsByTagName('div')[0];
    if (div2.innerHTML == 'سنة') args.IsValid = false;

    //return true;
}

function getFixForIE7(slDaysId, slMonthsId, slYearsId) {
    if (document.getElementsByClassName) {
        return;
    }
    else {
        var hElmMonthsSelect = document.getElementById(slMonthsId);
        var hElmYearsSelect = document.getElementById(slYearsId);

        var selectDiv = getSelectDiv(hElmMonthsSelect);
        selectDiv.setAttribute('onclick', 'update_daysST("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');

        selectDiv = getSelectDiv(hElmYearsSelect);
        selectDiv.setAttribute('onclick', 'update_daysST("' + slDaysId + '", "' + slMonthsId + '", "' + slYearsId + '")');
    }

}

function getSelectDiv(hElmSelect) {
    var AllDivs = hElmSelect.parentNode.getElementsByTagName('div');
    for (var i = 0; i < AllDivs.length; i++) {
        if (AllDivs[i].className == 'newListSelected') {
            return AllDivs[i];
        }
    }
}

//-----------------------------------------------------------------------
//-----------------DATE SELECTOR WITH STYLISH SELECT END-----------------
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
//-----------------IE6 HANDLE START--------------------------------------
//-----------------------------------------------------------------------

function showSubscribePopUp(is_show) {
    if (parseInt(is_show) == 1) {
        if ($('#subscribe-popup').css('display') == 'none') {
            ShowGlassWindow(1);
            $('#subscribe-popup').show(10);
            $('#subscribe-popup').css('z-index', '700');
        }
    }
}

function hideSubscribePopUp() {
    if ($('#subscribe-popup').css('display') == 'block') {
        ShowGlassWindow(0);
        $('#subscribe-popup').hide(10);
    }
}
function showRegisterPopUp(is_show) {
    if (parseInt(is_show) == 1) {
        if ($('#register-popup').css('display') == 'none') {
            ShowGlassWindow(1);
            $('#register-popup').show(10);
            $('#register-popup').css('z-index', '700');
        }
    }
}

function hideRegisterPopUp() {
    //    if ($('#register-popup').css('display') == 'block') {
    //        ShowGlassWindow(0);
    //        $('#register-popup').hide(10);
    //    }
    //$('#ctl00_registerpopup').hide(10);
    document.getElementById('ctl00_registerpopup').style.display = 'none';
}
var GlassWindow = null; //ссылка на "окно-экран"
var Dialog = null; //ссылка на "окно формы"
var isIE = window.navigator.userAgent.indexOf("MSIE") > -1;

function ShowGlassWindow(show) {
    if (GlassWindow == null) {
        // 
        GlassWindow = document.createElement('DIV');
        with (GlassWindow.style) {
            //
            display = 'none'; //
            position = 'absolute'; //
            height = 0; width = 0; //любые 
            zIndex = 600; // 
            if (isIE) {//
                backgroundColor = '#000000'; //'#FFFFFF'
                filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=50, Style=0)";
            }
            else //
                backgroundImage = 'url(' + siteRoot + 'images/alfa50-fon.png)';
        }
        //
        document.body.appendChild(GlassWindow);

        if (GlassWindow.addEventListener)
            GlassWindow.addEventListener("click", (function(s) { hideSubscribePopUp(); }), false);
        else if (window.attachEvent)
            GlassWindow.attachEvent("onclick", (function(s) { hideSubscribePopUp(); }));
    }

    if (show) {
        var s = getDocumentSize();
        with (GlassWindow.style) {
            // 
            left = top = 0;
            width = s[0] + 'px';
            height = s[1] + 'px';
            zIndex = 600;

        }
    }
    GlassWindow.style.display = show ? 'block' : 'none';
}
function getDocumentSize() {
    return [
      document.body.scrollWidth > document.body.offsetWidth ?
            document.body.scrollWidth : document.body.offsetWidth,
      document.body.scrollHeight > document.body.offsetHeight ?
            document.body.scrollHeight : document.body.offsetHeight
      ];
}

//-----------------------------------------------------------------------
//-----------------IE6 HANDLE END----------------------------------------
//-----------------------------------------------------------------------
