﻿var MasterIe5=document.all && document.getElementById;
var MasterNs6=document.getElementById && !document.all;
var allowCommand = true;
document.oncontextmenu = hideMenu;

function toolbarMouseMove(e)
{
    e.style.border = "1px solid red";
    e.style.cursor = "pointer";
}

function toolbarMouseExit(e)
{
    e.style.border = "1px solid white";
    e.style.cursor = null;
}

function hideMenu()
{
    return false;
}

function showLogIn()
{
    document.getElementById("siteUserId").value = "";
    document.getElementById("sitePassWord").value = "";
    document.getElementById("siteLogIn").style.display = "block";
}

function hideLogIn()
{
    document.getElementById("siteLogIn").style.display = "none";
}

function showLogOut()
{
    document.getElementById("siteLogOut").style.display = "block";
}

function hideLogOut()
{
    document.getElementById("siteLogOut").style.display = "none";
}

function showGetValue(params,valueName,valueType,showWord)
{
    document.getElementById("enterValueParams").value = params;
    document.getElementById("enterValueName").value = valueName;
    document.getElementById("enterValueType").value = valueType;
    document.getElementById("enterValueText").innerHTML = " لطفا " + showWord + " مورد نظر را وارد نمائید: ";
    document.getElementById("enterValue").value = "";
    document.getElementById("siteGetValue").style.display = "block";
}

function hideGetValue()
{
    document.getElementById("siteGetValue").style.display = "none";
}

function sendDynamicCommand(e)
{
    if (allowCommand)
    {
        setDynamicCommandStyle();
        
        var url = "SiteDefaultPage.aspx?";
        
        if (e.getAttribute("command"))
            command = e.getAttribute("command");
        else
            command = null;
        if (e.getAttribute("variable"))
            variable = e.getAttribute("variable");
        else
            variable = null;
        if (e.getAttribute("params"))
            params = e.getAttribute("params");
        else
            params = null;
        if (e.getAttribute("hidden"))
            hidden = e.getAttribute("hidden");
        else
            hidden = null;
        if (e.getAttribute("hidden2"))
            hidden2 = e.getAttribute("hidden2");
        else
            hidden2 = null;

        if (command != null)
            url += "command=" + command;
        if (variable != null)
            url += "&variable=" + variable;
        if (params != null)
            url += "&" + params;
        if (hidden != null)
            document.getElementById("hiddenData").value = hidden;
        if (hidden2 != null)
            document.getElementById("hiddenData2").value = hidden2;
             
        document.getElementById("pageForm").action = url;
        document.getElementById("pageForm").submit();
    }
    else
    {
        alert("برای مشاهده این صفحه سایر صفحات فرعی را ببندید");
    }
}

function setDynamicCommandStyle()
{
    document.getElementById("waitRow").style.height = document.body.scrollHeight;
    document.getElementById("waitRow").style.width = document.body.scrollWidth;
    document.getElementById("waitRow").style.display = "block";
}

function sendStaticCommand(e)
{
    if (allowCommand)
    {
        setStaticCommandStyle();
        var url = "SiteSecondPage.aspx?";
    
        params = e.getAttribute("params");
        _width = e.getAttribute("_width");
        _height = e.getAttribute("_height");
    
        url += params;

        document.open(url, "_blank",
            "channelmode=0, location=0, status=0, top=50px, left=50px, height=" 
            + _height + "px, width=" + _width + "px", true);
        allowCommand = false;
    }
    else
    {
        alert("برای مشاهده این صفحه سایر صفحات فرعی را ببندید");
    }
}

function setStaticCommandStyle()
{
    document.getElementById("waitRow").style.height = document.body.scrollHeight;
    document.getElementById("waitRow").style.width = document.body.scrollWidth;
    document.getElementById("waitRow").style.display = "block";
    document.getElementById("waitDescriptionRow").style.display = "none";
}

function removeStaticCommandStyle()
{
    document.getElementById("waitRow").style.display = "none";
    if (MasterIe5)
        document.getElementById("waitDescriptionRow").style.display = "block";
    else
        document.getElementById("waitDescriptionRow").style.display = "table";
}

function doThis(params, variable)
{
    var temp = document.getElementById("tempData");
    if (variable != null)
        temp.setAttribute("variable", variable);
    if (params != null)
        temp.setAttribute("params", params);
    sendDynamicCommand(temp);
}

function doRefresh()
{
    var temp = document.getElementById("refreshItem");
    if (MasterIe5)
        document.getElementById("waitDescriptionRow").style.display = "block";
    else
        document.getElementById("waitDescriptionRow").style.display = "table";
    sendDynamicCommand(temp);
}

function doUp()
{
    var temp = document.getElementById("upItem");
    if (MasterIe5)
        document.getElementById("waitDescriptionRow").style.display = "block";
    else
        document.getElementById("waitDescriptionRow").style.display = "table";
    sendDynamicCommand(temp);
}

function doLogIn()
{
    var id = document.getElementById("siteUserId").value;
    var pass = document.getElementById("sitePassWord").value;
    
    if (id != "" && pass != "" && checkType(id,"int"))
    {
        var temp = document.getElementById("siteLogIn");
        temp.setAttribute("hidden", id);
        temp.setAttribute("hidden2", pass);
        sendDynamicCommand(temp);
    }
    else
    {
        alert("لطفا شماره کاربری و رمز ورود را وارد کنید");
    }
}

function doGetValue()
{
    var params = document.getElementById("enterValueParams").value;
    var name = document.getElementById("enterValueName").value;
    var type = document.getElementById("enterValueType").value;
    var value = document.getElementById("enterValue").value;
    
    if (name == "")
        name = null;
    if (type == "")
        type = null;
    if (value == "")
        value = null;
    
    if (value != null && checkType(value, type))
    {
        var temp = document.getElementById("siteGetValue");
        if (params == "")
            temp.setAttribute("params", name + "=" + value);
        else
            temp.setAttribute("params", name + "=" + value + "&" + params);
        sendDynamicCommand(temp);
    }
    else
    {
        alert("عبارت ورودی دارای فرمت صحیح نمیباشد ،لطفا مقدار دیگری وارد نمائید");
    }
}