﻿
function createStyle() {
    var all = document.forms[0].all;
    for (var i = 0; i < all.length; ++i) {
        var nm = all[i].nodeName.toLowerCase();
        //alert(all[i].nodeName);
        if (nm == 'input' || nm == 'select' || nm == 'textarea') {
            var oldColor = all[i].style.backgroundColor;
            all[i].onfocus = function() { this.style.backgroundColor = '#cee8fc'; }
            all[i].ondeactivate = function() { this.style.backgroundColor = ''; }
            if (nm != 'textarea') {
                all[i].onkeydown = function() { if (event.keyCode == 13) { event.keyCode = 9; return event.keyCode; } }
            }
        }
        else if (nm == 'img') {

            if (all[i].src.charAt(all[i].src.length - 1) == '/')
                all[i].style.display = 'none';

        }
    }
}



function PopUp(URLTarget, width, height) {
    window.open(URLTarget, 'win', "status=yes,toolbar=no,menubar=no,location=no,directories=no,width=" + width + ",height=" + height + " ,resizable=yes,left=0,top=0,scrollbars=yes");
}

function Back_WithQuery(id, pagename) {
    location.href = pagename + id;
}

function ChangeTxtDisabled() {
    document.getElementById("DDLST_TenantBlackListReason").disabled = document.getElementById("ChBx_TenantBlackListN").checked
    //if(document.getElementById("DDLST_TenantBlackListReason").disabled==true)
    //	{
    //	document.getElementById("DDLST_TenantBlackListReason").value=""
    //	}
}
function ChangeToPostChecked(RadioID) {
    document.getElementById(RadioID).checked = true;
}
function setMirrorandRotation(divId, mirrorCase, rotatorCase, act) {
    var noM;
    var noR;
    if (act == "M") {
        noM = parseInt(document.getElementById(mirrorCase).value) + 1;
        document.getElementById(mirrorCase).value = noM;
        if (document.getElementById(mirrorCase).value > 1) {
            document.getElementById(mirrorCase).value = 0;
        }
    }
    else if (act == "R") {
        noR = parseInt(document.getElementById(rotatorCase).value) + 1;
        document.getElementById(rotatorCase).value = noR;
        if (document.getElementById(rotatorCase).value > 3) {
            document.getElementById(rotatorCase).value = 0;
        }
    }
    divId.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(mirror=' + document.getElementById(mirrorCase).value + ',rotation=' + document.getElementById(rotatorCase).value + ')';
}

function IncrImage(imageID, ParentFrameID) {
    document.images[imageID].width += 25;
    document.images[imageID].height += 25;
    AdjustFrameHeight(ParentFrameID)
}

function DecrImage(imageID, ParentFrameID) {
    document.images[imageID].width -= 25;
    document.images[imageID].height -= 25;
    AdjustFrameHeight(ParentFrameID)
}

function CallPrint(strid, mirrorCase, rotatorCase) {
    var prtContent = document.getElementById(strid);
    var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write("<DIV id='divPrint' style='height:50; width:50'>" + prtContent.innerHTML + "</div><script>divPrint.style.filter='progid:DXImageTransform.Microsoft.BasicImage(mirror=" + document.getElementById(mirrorCase).value + ",rotation=" + document.getElementById(rotatorCase).value + ")'</script>");
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
}

function resetDataGridColors(firstColor, secondColor, HoverColor, Grid) {
    for (t = 1; t < document.getElementById(Grid).rows.length; t++) {
        document.getElementById(Grid).rows(t).onmouseover = function() { this.style.backgroundColor = HoverColor }
        if (t % 2 == 0) {
            document.getElementById(Grid).rows(t).style.backgroundColor = secondColor;
            document.getElementById(Grid).rows(t).onmouseout = function() { this.style.backgroundColor = secondColor; this.style.cursor = 'hand'; }
        }
        else {
            document.getElementById(Grid).rows(t).style.backgroundColor = firstColor;
            document.getElementById(Grid).rows(t).onmouseout = function() { this.style.backgroundColor = firstColor; this.style.cursor = 'hand'; }
        }
    }
}


function TurnOffValSave(btnChLang) {
    try {
        for (i = 0; i < Page_Validators.length; i++) {
            ValidatorEnable(Page_Validators[i], false);
        }
    }
    catch (err) { }
    document.getElementById(btnChLang).click();
}

function addrec(no) {
    if (document.getElementById("HiddenText").value.indexOf("-" + no + "-") > -1) {
        document.getElementById("A_SelectAll").checked = false;
        document.getElementById("HiddenText").value = document.getElementById("HiddenText").value.replace("-" + no + "-", "");
    }
    else {
        document.getElementById("HiddenText").value += "-" + no + "-";
    }
}

function confirmation() {
    if (document.getElementById("HiddenText").value != "") {
        var answer = confirm("هل تريد حذف كل البيانات المختاره");
        if (answer) {
            document.getElementById("Delete").click();
        }
        else {
            setAllCheckboxes(Form1, false);
            document.getElementById("HiddenText").value = "";
        }
    }
}

function ChangeAllChecks(chk) {
    var all = document.forms[0].elements;
    //var aValue;
    //document.getElementById("ids").value = "";
    for (var i = 0; i < all.length; ++i) {
        if (all[i].id.indexOf('chkSelectRow') > -1 || all[i].id.indexOf('chbSelectAll') > -1) {
            all[i].checked = chk;
        }
    }
    try {
        $get('ctl00_cp_btn_Delete').disabled = !chk;
        $get('ctl00_cp_btn_Delete2').disabled = !chk;
    } catch (ex) { }
    try {
        $get('btn_Delete').disabled = !chk;
        $get('btn_Delete2').disabled = !chk;
    } catch (ex) { }
}

function changeCheck(chk) {
    var all = document.forms[0].elements;
    //var aValue;
    //document.getElementById("ids").value = "";
    if (chk) {
        try {
            $get('ctl00_cp_btn_Delete').disabled = false;
            $get('ctl00_cp_btn_Delete2').disabled = false;
        } catch (ex) { }
        try {
            $get('btn_Delete').disabled = false;
            $get('btn_Delete2').disabled = false;
        } catch (ex) { }
        return;
    }
    try {
        $get('ctl00_cp_btn_Delete').disabled = true;
        $get('ctl00_cp_btn_Delete2').disabled = true;
    } catch (ex) { }
    try {
        $get('btn_Delete').disabled = true;
        $get('btn_Delete2').disabled = true;
    } catch (ex) { }
    for (var i = 0; i < all.length; ++i) {
        if (all[i].id.indexOf('chkSelectRow') > -1) {
            if (all[i].checked) {
                try {
                    $get('ctl00_cp_btn_Delete').disabled = false;
                    $get('ctl00_cp_btn_Delete2').disabled = false;
                } catch (ex) { }
                try {
                    $get('btn_Delete').disabled = false;
                    $get('btn_Delete2').disabled = false;
                } catch (ex) { }
            }
        }
    }
    return false;
}

function AdjustFrameHeight(frameId) {
    //			     try{

    var x, y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }
    else // Explorer Mac;
    //would also work in Explorer 6 Strict, Mozilla and Safari
    {
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    } var x, y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }
    else // Explorer Mac;
    //would also work in Explorer 6 Strict, Mozilla and Safari
    {
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    }


    parent.document.all(frameId).style.height = y; //document.body.scrollHeight+30;
    //  parent.document.getElementById(frameId).height=document.body.scrollHeight+10;
    //				 }
    //				 catch(ex){}


    var sPath = window.location.href;
    //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    parent.window.location.hash = "#url=" + sPage;


    parent.window.scrollTo(0, 0);
}

function getime() {
    if (document.getElementById("lastOperation2") != null) {
        document.getElementById("lastOperation2").style.visibility = "hidden";
    }
    if (document.getElementById("lastOperation1") != null) {
        document.getElementById("lastOperation1").style.visibility = "hidden";
    }
    if (document.getElementById("lastOperation") != null) {
        document.getElementById("lastOperation").style.visibility = "hidden";
    }
}

function startp() {
    Myinterval = window.setInterval("getime()", 10000);
}

function ShowThis2(ID) {
    M = ID.id;
    M = M.substr(1);
    L = "S" + M;
    if (ID.id.substr(0, 1) == "w") {
        document.images[ID.id].style.display = "none";
        document.getElementById(L).style.display = "";
        U = "u" + M;
        document.images[U].style.display = "";
    }
    if (ID.id.substr(0, 1) == "u") {
        document.images[ID.id].style.display = "none";
        document.getElementById(L).style.display = "none";
        document.images[D].style.display = "";
    }
}

function NullTo(txt, DefaultValue) {
    //txt=the name of textbox
    //DefaultValue=the value to replace the null
    if (document.getElementById(txt).value == "") {
        document.getElementById(txt).value = DefaultValue;
        document.getElementById(txt).select();
    }
}

function hideSubPageOnError(frameId, ErrPage) {
    var sPath = window.location.pathname;
    //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    if (sPage == ErrPage) {
        parent.document.all(frameId).height = 0;
    }
}