﻿
// layouts functions
function InbalLayout_MakeInvisibleIfEmpty()
{
	var allElements=document.getElementsByName("_invisibleIfEmpty");
	for (var curElement=0; curElement<allElements.length; curElement++)
	{
	    try
	    {
	        var oElement = allElements[curElement];
	        if (oElement.tagName == "TD")
	        {
		        if (oElement.innerHTML.toLowerCase().indexOf("</span>&nbsp;</div>")!=-1)
		        {
			        oElement.innerHTML= oElement.innerHTML.toLowerCase().replace("</span>&nbsp;</div>", "</span></div>");
		        }
		    }
		    else if (oElement.tagName == "TR")
		    {
		        if (oElement.childNodes.length == 2)
		        {
		            if (TrimWhiteSpaces(oElement.childNodes[1].innerText) == "")
		            {
		                oElement.style.display = "none";
		            }
		        }
		    }
	    }
	    catch(e)
	    {
	    }
	}
}

function HomePage_CheckEmail(lstTitle, txtField, txtEmail)
{
    var sTitle = lstTitle.options[lstTitle.selectedIndex].value;
    var sField = txtField.value;
    var sEmail = txtEmail.value;
    if (sTitle == "")
    {
        alert("נא בחר קבוצה");
        return;
    }
    if (ValidateEmail(sEmail))
    {
        var sUrl = "/_layouts/NewsLetter/Resources/NewUser.aspx?email="+escape(sEmail)+"&group="+escape(sTitle)+"&field="+escape(sField);
        var sStyle = "height=200,left=100,top=100,width=200,resizable=no,scrollbars=no,status=no,location=no,menubar=no,toolbar=no";
        window.open(sUrl, "_blank", sStyle);
    }
    else
    {
        alert("נא הזן כתובת דוא''ל חוקית");
    }
}

function ValidateEmail(sEmail)
{
	var regex = /^[a-z]([\.][a-z_\-0-9]|[a-z_\-0-9])+@[a-z_\-0-9]+(\.[a-z]{2,10}){1,4}$/i
	return regex.test(sEmail);
}

function SetHomePage()
{
    oHomePage.setHomePage("http://www.inbal.co.il");
    event.returnValue = false;
}

function PrintPage()
{
    window.open("/_layouts/InbalPortal/WebForms/wfPrintPage.aspx", null, "height=5,width=5")
}

function CheckManagerPanel()
{
	if (event.ctrlKey && event.altKey && event.keyCode == 65)
	{
		var el = document.getElementById("LoginActionBar")
		if (el.style.display == "none")
			el.style.display = ""
		else
			el.style.display = "none"
	}
}

// ItemStyle functions
function PageList_HandleRuleDescription(imgid, rowid, position)
{
    var RowElement = document.getElementById(rowid);
    var ImgElement = document.getElementById(imgid);
    if(RowElement.style.display == "none")
    {
        RowElement.style.display = "";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("Taktzir.gif", "CloseLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("Taktzir.gif", "CloseDark.gif");
    }
    else
    {
        RowElement.style.display = "none";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("CloseLight.gif", "Taktzir.gif");
        else
            ImgElement.src = ImgElement.src.replace("CloseDark.gif", "Taktzir.gif");
    }
}

function PageList_HandleArticleDescription(imgid, rowid, position)
{
    var RowElement = document.getElementById(rowid);
    var ImgElement = document.getElementById(imgid);
    if(RowElement.style.display == "none")
    {
        RowElement.style.display = "";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("Taktzir.gif", "CloseLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("Taktzir.gif", "CloseDark.gif");
    }
    else
    {
        RowElement.style.display = "none";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("CloseLight.gif", "Taktzir.gif");
        else
            ImgElement.src = ImgElement.src.replace("CloseDark.gif", "Taktzir.gif");
    }
}

function PageList_HandleLiteratureDescription(imgid, rowid, position)
{
    var RowElement = document.getElementById(rowid);
    var ImgElement = document.getElementById(imgid);
    if(RowElement.style.display == "none")
    {
        RowElement.style.display = "";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("DetailsLight.gif", "CloseLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("DetailsDark.gif", "CloseDark.gif");
    }
    else
    {
        RowElement.style.display = "none";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("CloseLight.gif", "DetailsLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("CloseDark.gif", "DetailsDark.gif");
    }
}

function PageList_HandleAnswerDescription(imgid, rowid, position)
{
    var RowElement = document.getElementById(rowid);
    var ImgElement = document.getElementById(imgid);
    if(RowElement.style.display == "none")
    {
        RowElement.style.display = "";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("Answer.gif", "CloseLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("Answer.gif", "CloseDark.gif");
    }
    else
    {
        RowElement.style.display = "none";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("CloseLight.gif", "Answer.gif");
        else
            ImgElement.src = ImgElement.src.replace("CloseDark.gif", "Answer.gif");
    }
}

function PageList_HandleEventDescription(imgid, rowid, position)
{
    var RowElement = document.getElementById(rowid);
    var ImgElement = document.getElementById(imgid);
    if(RowElement.style.display == "none")
    {
        RowElement.style.display = "";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("DetailsLight.gif", "CloseLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("DetailsDark.gif", "CloseDark.gif");
    }
    else
    {
        RowElement.style.display = "none";
        if (position % 2 == 0)
            ImgElement.src = ImgElement.src.replace("CloseLight.gif", "DetailsLight.gif");
        else
            ImgElement.src = ImgElement.src.replace("CloseDark.gif", "DetailsDark.gif");
    }
}

// aggreement section
function ManageAuthorization()
{
    if (unescape(window.location.href).indexOf("TermOfUse.aspx") != -1)
        return;
    var sCookie = document.cookie;
	
    if (unescape(sCookie).indexOf("RiskManage") == -1)
        window.location = "/Pages/TermOfUse.aspx";
}

function AcceptAgreement()
{
    var oDate = new Date("01/01/2050");
    document.cookie = "RiskManage=RiskManage; expires=" + oDate.toGMTString() + "; path=/";
    window.location = "/";
    return false;
}

// menu script override
var flyoutsAllowed=false;
function enableFlyoutsAfterDelay()
{
    setTimeout("flyoutsAllowed=true;", 25);
}
function overrideMenu_HoverStatic(item)
{
    if (!flyoutsAllowed)
    {
        setTimeout(delayMenu_HoverStatic(item), 50);
    }
    else
    {
        var node=Menu_HoverRoot(item);
        var data=Menu_GetData(item);
        if (!data) return;
        __disappearAfter=data.disappearAfter;
        Menu_Expand(node, data.horizontalOffset, data.verticalOffset);
    }
}
function delayMenu_HoverStatic(item)
{
    return (function()
    {
        overrideMenu_HoverStatic(item);
    });
}

// show map
function OpenLargeMap()
{
    var sStyle = "height=305,left=100,top=100,width=455,resizable=no,scrollbars=no,status=no,location=no,menubar=no,toolbar=no";
    window.open("/_layouts/InbalPortal/Images/General/LargeMap.gif", "_blank", sStyle)
}
