var gTime = new Date();

var isIE6 = false;
if (navigator.userAgent.toLowerCase().search(/msie 6/i) != -1)
    isIE6 = true;
/*
if (window.addEventListener) {    
    window.addEventListener("onload", PageRequestload, false)
}
else {
    if (window.attachEvent) {        
        window.attachEvent("onload", PageRequestload);
    }
}
function PageRequestload() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}

window.attachEvent("onload", Pageload);
*/
function Pageload() {
   
}

function navigateTo(url)
{    
    document.location.href = '/he-il' + url; //+ '?ni=' + oMenuTree.clickedNodeIndex;
}
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
                return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}
function sendlink()
{

}
function setHome()
{
   bookmarkurl="http://www.NetivotHashas.org.il/he-il/"
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(bookmarkurl);
}
function bookmark()
{
    bookmarkurl="http://www.NetivotHashas.org.il/he-il/"
    bookmarktitle="Netivot Hashas"
    if (document.all)
        window.external.AddFavorite(bookmarkurl,bookmarktitle)
    else if (window.sidebar) // firefox
        window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}

function addTraillingZero(num) {
    var str = '' + num;
    if (str.length == 1)
        return ('0' + str);
    return (str);
}
function removeTraillingZero(num) {
    var str = '' + num;
    if (str.substr(0, 1) == '0')
        str = str.substr(1);
    if (str.substr(0, 1) == '0')
        str = str.substr(1);
    return (parseInt(str));
}
function onUpdating(){
    //document.body.style.filter = "alpha(opacity=60)"
    //disableForm(true);
    
    gTime = new Date();
    //document.body.disabled = true;    
    var pnlPopup = document.getElementById('pnlPopup');
    if(pnlPopupID)  pnlPopup = $get(pnlPopupID);    
    //var myHeight = (document.body.clientHeight>1000)?400:document.body.clientHeight;    
    var x = Math.round(document.body.clientWidth/2);
    //var y = Math.round(document.body.clientHeight/2);    
    Sys.UI.DomElement.setLocation(pnlPopup, x, 300);    
    pnlPopup.style.display = '';    
}
function onUpdated() 
{    
    //ctl00_lblPageLoadTime.innerText = PLT_DisplayFormat.replace(/%%S%%/g, ((new Date() - gTime) / 1000).toFixed(2));    
    //document.body.disabled = false;    
    //document.body.style.backgroundColor = "#ffffff";
    //document.body.style.filter = "";    
    var pnlPopup = $get('pnlPopup');    
    if(pnlPopupID)  pnlPopup = $get(pnlPopupID);
    pnlPopup.style.display = 'none';

}
function disableForm(bDisabled) {
    theform = document.forms[0];
    if (document.all || document.getElementById) {
        for (i = 0; i < theform.length; i++) {
            var formElement = theform.elements[i];
            formElement.disabled = bDisabled;            
        }
    }
}

function EndRequestHandler(sender,args){   
   //if(sender._panelsToRefreshIDs[0].toString().indexOf('upMain')>-1)       
   onUpdated();
}
function SetText(elm)
{    
    var tb = $get('ctl00_tbMasechet');
    if(elm.id.indexOf('Perek')>-1)    
        tb = $get('ctl00_tbPerek');    
    tb.value = elm.innerText;    
    return false;
}
function SearchCategory(elm)
{    
    var tb = $get(elm.id.replace('lbSearchCategory','tbCategories'));
    if(tb.value == '')
    {
        alert('! אנא בחר קטגוריה לחיפוש ');
        return false;
    }
    return true;
}
function SetExtCheck(chck) {        
    var ext1 = $get(chck.id.replace('imgExtType', 'cbExtType'));
    ext1.checked = true;    
    return true;
}
function SearchText(elm) {

    var tb = $get(elm.id.replace('btnSearch', 'tbText2Search'));    
    if (tb.value == '') {
        alert('! אנא הכנס טקסט לחיפוש ');
        return false;
    }
    return true;
}

function disable(elm)
{
    
    if (Page_IsValid)
        setTimeout(function(){dis(elm)},200)
}
function dis(elm)
{
    if (!Page_IsValid)
        return;
    elm.disabled = true;    
    elm.value = 'Sending ...';
}

function ClearText(elm, txt) {
    //setTimeout("document.getElementById('" + elmId + "').value=''", 500);
    //var elm = document.getElementById(elmId);
    if (elm && elm.value == txt) {
     //   elm.value = '---';
        elm.value = '';
    }
    //setTimeout("document.getElementById('" + elmId + "').value=' '", 500);
}
function SetText(elm,txt) {
    if (elm.value == '') {
        //   elm.value = '---';
        elm.value = txt;
    }
}



function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function CheckEmail(elm) {
   //ctl00_MainPlaceHolder_MainSubjectList_rptSubjects_ctl01_rptSubjectDetails_ctl00_tbEMail
   //ctl00_MainPlaceHolder_MainSubjectList_rptSubjects_ctl01_rptSubjectDetails_ctl01_OkButton       
   var tb = $get(elm.id.replace('OkButton', 'tbEMail'));       
   if (tb.value == '') {
       alert('! אנא הכנס דואר אלקטרוני');
       return false;
   }
   disable(elm);
   return true;   
}
///////////// Bread crumbs menu ///////////////////////////////////
var openMenu = null;
function show(elm) {

    hideMenu();
    var hl = document.getElementById(elm.id.replace('DropPanel', 'hlBreakCrumb'));
    var dp = document.getElementById(elm.id.replace('hlBreakCrumb', 'DropPanel'));
    if (elm.id.indexOf('DropPanel') == -1) {
        //dp.style.left = (hl.offsetLeft + 430 + elm.offsetWidth) + 'px';  //(elm.offsetWidth) + 'px';            //'-' +
        //dp.style.right = (document.body.scrollWidth / 2) - elm.offsetLeft + elm.offsetWidth + 'px';
        dp.style.left = (getX(hl) + hl.offsetWidth) - ((isIE6) ? 130 : 0);
    }
    else
        hl.onmouseout = hideMenu;
    dp.style.width = "0";
    dp.style.display = '';
    dp.onmouseout = hideMenu;
    openMenu = dp;
}
function hide(elm) {
    if (!openMenu)
        return;
    var dp = document.getElementById(elm.id.replace('hlBreakCrumb', 'DropPanel'));
    openMenu.style.display = 'none';
}
function hideMenu() {
    if (openMenu)
        openMenu.style.display = 'none';
}
function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function ValidateChecked(source, args) {
    args.IsValid = document.getElementById(source.id.replace('CustomValidatorApprove', 'cbApprove')).checked;
}
function CheckField(source, args) {
    args.IsValid = (source.valueOf != '')
}
var accordion = function() {
    var tm = sp = 3;
    function slider(n) { this.nm = n; this.arr = [] }
    slider.prototype.init = function(t, c, k) {
        var a, h, s, l, i; a = document.getElementById(t); this.sl = k ? k : '';
        h = a.getElementsByTagName('dt'); s = a.getElementsByTagName('dd'); this.l = h.length;
        for (i = 0; i < this.l; i++) { var d = h[i]; this.arr[i] = d; d.onclick = new Function(this.nm + '.pro(this)'); if (c == i) { d.className = this.sl } }
        l = s.length;
        for (i = 0; i < l; i++) { var d = s[i]; d.mh = d.offsetHeight; if (c != i) { d.style.height = 0; d.style.display = 'none' } }
    }
    slider.prototype.pro = function(d) {
        for (var i = 0; i < this.l; i++) {
            var h = this.arr[i], s = h.nextSibling; s = s.nodeType != 1 ? s.nextSibling : s; clearInterval(s.tm);
            if (h == d && s.style.display == 'none') { s.style.display = ''; su(s, 1); h.className = this.sl }
            else if (s.style.display == '') { su(s, -1); h.className = '' }
        }
    }
    function su(c, f) { c.tm = setInterval(function() { sl(c, f) }, tm) }
    function sl(c, f) {
        var h = c.offsetHeight, m = c.mh, d = f == 1 ? m - h : h; c.style.height = h + (Math.ceil(d / sp) * f) + 'px';
        c.style.opacity = h / m; c.style.filter = 'alpha(opacity=' + h * 100 / m + ')';
        if (f == 1 && h >= m) { clearInterval(c.tm) } else if (f != 1 && h == 1) { c.style.display = 'none'; clearInterval(c.tm) }
    }
    return { slider: slider }
} ();