﻿function findPos() {

    var obj = document.getElementById("ctl00_UCLeftFrame1_leftFrame");
    var obj2 = document.getElementById("ctl00_UCRightFrame1_rightFrame");
   
    
    var divLeft = document.getElementById("ctl00_UCLeftFrame1_leftFrame");
    var divRight = document.getElementById("ctl00_UCRightFrame1_rightFrame");



    if (divLeft != null) {
        var widthLeftFrame = divLeft.style.maxWidth.replace("px", "");
        var paddingLeftFrame = divLeft.style.paddingLeft.replace("px", "");
    }
    if (divRight != null) {
        var widthRightFrame = divRight.style.maxWidth.replace("px", "");
        var paddingRightFrame = divRight.style.paddingRight.replace("px", "");
    }




    var generalOffset = 5;
    var generalOffsetRight = 80;
    var generalOffsertRightDiv = 21;
    var offsetForLeft = 28;
    var offsetForRight = 8;
    var offsetRightFrameLeft = 5;
    var offsetRightFrameRight = 280;
    if (document.getElementById("mainTable") != null) {
        var table_width = document.getElementById("mainTable").width;
    }
    if (obj != null) {

        
        var posX = obj.offsetLeft;
        var posY = obj.offsetTop;
        
        
        var clientWidth = window.document.body.clientWidth;
        while (obj.offsetParent) {
           posX = posX + obj.offsetParent.offsetLeft;
           posY = posY + obj.offsetParent.offsetTop;
           if (obj == document.getElementsByTagName('html')[0]) { break }
            else { obj = obj.offsetParent; }
        }
        if (document.getElementById("scrollerLeft") != null) {
            document.getElementById("scrollerLeft").style.position = "absolute";
            //document.getElementById("scrollerLeft").style.left = posX + offsetForLeft + parseInt(paddingLeftFrame);
            document.getElementById("scrollerLeft").style.left = parseInt(posX-generalOffset);
        }
        if (document.getElementById("scrollerRight") != null) {
            document.getElementById("scrollerRight").style.position = "absolute";
            //document.getElementById("scrollerRight").style.left = parseInt(posX + parseInt(widthLeftFrame) - offsetForRight);
            var paddingLeftFrameRight = "0";
            if (document.getElementById("lftTD") != null) {
                paddingLeftFrameRight = document.getElementById("lftTD").style.paddingRight;
            }
            var leftSizeLeft;
            leftSizeLeft = parseInt((posX + parseInt(widthLeftFrame))) - parseInt("10");
            document.getElementById("scrollerRight").style.left = parseInt(leftSizeLeft-generalOffset);
        }

        //var divREDWIDTH = parseInt(posX + parseInt(widthLeftFrame) - offsetForRight) - posX + offsetForLeft + parseInt(paddingLeftFrame);
        var divREDWIDTH = parseInt(widthLeftFrame); 

          if (document.getElementById("sp1") != null) {
             document.getElementById("sp1").style.position = "absolute";
             document.getElementById("sp1").style.width = divREDWIDTH - 18;
             document.getElementById("sp1").style.left = parseInt(parseInt(posX) - generalOffset + 10);
             document.getElementById("sp1").style.height = "15";
        }
    }else {
                if (document.getElementById("scrollerLeft") != null) {
                     document.getElementById("scrollerLeft").style.display = "none";
                }
                if (document.getElementById("scrollerRight") != null) {
                     document.getElementById("scrollerRight").style.display = "none";
                 }
                 if (document.getElementById("sp1") != null) {
                     document.getElementById("sp1").style.display = "none";
                 }
    }

    if (obj2 != null) {
        var posXRightFrame = obj2.offsetLeft;
        while (obj2.offsetParent) {

            posXRightFrame = posXRightFrame + obj2.offsetParent.offsetLeft;
            if (obj2 == document.getElementsByTagName('html')[0]) { break }
            else { obj2 = obj2.offsetParent; }
        }
        if (document.getElementById("scroller3") != null) {
            document.getElementById("scroller3").style.position = "absolute";
            var leftSizeRightFrame = parseInt(posXRightFrame);
            document.getElementById("scroller3").style.left = leftSizeRightFrame;
        };

        if (document.getElementById("scroller4") != null) {
            var rightPaddigTD = 0;
            if (document.getElementById("rightTD") != null)
            {
                rightPaddigTD  = document.getElementById("rightTD").style.paddingLeft.replace("px","");
            }
            
            document.getElementById("scroller4").style.position = "absolute";
            var rightSizeRightFrame = parseInt(posXRightFrame) + parseInt(widthRightFrame);
            document.getElementById("scroller4").style.left = parseInt(rightSizeRightFrame - paddingRightFrame) - 20;
        };

        var divREDWIDTHRIGHT = parseInt(parseInt(widthRightFrame) - parseInt(paddingRightFrame));
        if (document.getElementById("sp2") != null) {
            document.getElementById("sp2").style.position = "relative";
            
            
            if (obj != null) {
                document.getElementById("sp2").style.left = "380px";
            } else {
                document.getElementById("sp2").style.left = "377px";
            }
            if (document.getElementById("ctl00_UCRightFrame1_contentDetailsARight") != null) {
                if (document.getElementById("ctl00_UCRightFrame1_contentDetailsARight").innerHTML != "") {
                    document.getElementById("sp2").style.height = "15";
                    document.getElementById("sp2").style.maxWidth = parseInt(widthRightFrame);
                    document.getElementById("sp2").innerHTML = "TESTTESTTESTTTTT";
                    document.getElementById("sp2").width = parseInt(rightSizeRightFrame);
                }
                else {
                    document.getElementById("sp2").style.color = "white";
                    document.getElementById("sp2").style.backgroundColor = "white";
                }
            }
            
            
        }
    } else {
                if (document.getElementById("scroller3") != null) {
                     document.getElementById("scroller3").style.display = "none";
                }
                if (document.getElementById("scroller4") != null) {
                     document.getElementById("scroller4").style.display = "none";
                 }
                 if (document.getElementById("sp2") != null) {
                     document.getElementById("sp2").style.color = "white";
                     document.getElementById("sp2").style.backgroundColor = "white";
                 }
    }
}
function PostValueForEdit(pgKey, frmVal) {
    document.getElementById("ctl00_ContentPlaceHolder1_ctl09_UCManagePages1_pgKey").value = pgKey;
    document.getElementById("ctl00_ContentPlaceHolder1_ctl09_UCManagePages1_frameValue").value = frmVal;
    __doPostBack('ctl00$ContentPlaceHolder1$ctl09$UCManagePages1$goToEditor', '');
}



function openZoom(page, options, windowName) {
    if (windowName == null) windowName = 'zoom';
    var pageURL = page;
    window.open(pageURL, windowName, 'scrollbars=yes,resizable=yes,height=650').focus();
}
function openZoom1(page, options, windowName) {
    if (windowName == null) windowName = 'zoom';

    if (options == null) options = "";
    window.open('Popup/' + page + options, windowName, 'scrollbars=yes,resizable=yes,height=650').focus();
}

/* CRM Functions */
function onRecordSelect(arrSelectedRecord) {
    form1.submit();
}

function openCRMZoom(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../../Popup/' + page + options, 'zoom', 'scrollbars=yes,width=800,height=650' + resizeString).focus();
}

function openCRMProviderProductsZoom(page, options, resizable) {
    //debugger;
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../Datatables/' + page + options, 'zoom', 'scrollbars=no,width=810,height=750' + resizeString).focus();
}

function openCRMSrchProviderProductsZoom(page, options, resizable) {
    //debugger;
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../Datatables/' + page + options, 'zoom', 'scrollbars=yes,width=810,height=700' + resizeString).focus();
}

function openCRMZoomDim(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../../Popup/' + page + options, 'zoom', 'scrollbars=yes,width=800,height=500' + resizeString).focus();
}

function openCaseManagerZoom(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../../CaseManager/' + page + options, 'zoom', 'scrollbars=yes,width=1000,height=750' + resizeString).focus();
}


function openCRMZoomCase(page, options, resizable) {

    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../Popup/' + page + options, 'zoom1', 'scrollbars=yes,width=800,height=500' + resizeString).focus();
}

function openCRMZoomCampaign(page, options, resizable) {

    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open(page + options, 'zoom1', 'scrollbars=yes,width=800,height=500' + resizeString).focus();
}

function openCRMZoomLetters(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../Popup/' + page + options, 'zoom', 'scrollbars=yes,width=640,height=650' + resizeString).focus();
}

function openCRMZoomMessages(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../../Datatables/' + page + options, 'zoom1', 'scrollbars=yes,width=680,height=650' + resizeString).focus();
}



function openCRMZoom2(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../Popup/' + page + options, 'zoom', 'scrollbars=yes,width=640,height=650' + resizeString).focus();
}

function openCRMZoom1(page, options, resizable) {
    var resizeString = ',resizable=yes';
    if ((resizable != null) && (!resizable))
        resizeString = ',resizable=no'

    if (options == null) options = "";
    window.open('../../Popup/' + page + options, 'zoom', 'scrollbars=yes, width=850,height=700' + resizeString).focus();
}

function openPopupCRMZoom(page, options) {
    if (options == null) options = "";
    window.open(page + options, 'zoom', 'scrollbars=yes,resizable=yes,width=640,height=650').focus();
}
function openPopupCRMBankBranchesZoom(page, options) {
    if (options == null) options = "";
    window.open(page + options, 'zoom', 'scrollbars=yes,resizable=yes,width=880,height=500').focus();
}
/*End CRM functions*/

function SetFocus(controlName) {
    var ctrl = document.getElementById(controlName);
    if (ctrl != null)
        if (ctrl.disabled == false)
        ctrl.focus();
}

function FindPosition(obj) {
    var curleft = 0;
    var curtop = 0;

    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else {
        if (obj.x) curleft += obj.x;
        if (obj.y) curtop += obj.y;
    }

    var r = { x: curleft, y: curtop };
    return r;
}

function GetValue(controlId) {
    var control = document.getElementById(controlId)

    if (control != null)
        return control.value;
    else
        return '';
}

function ClearControl(controlId) {
    var control = document.getElementById(controlId)

    if (control != null) {
        control.value = '';
    }
}

function ClearControls(controlId1, controlId2) {
    ClearControl(controlId1);
    ClearControl(controlId2);
}

function ClearControls(controlId1, controlId2, controlId3) {
    ClearControl(controlId1);
    ClearControl(controlId2);
    ClearControl(controlId3);
}

function ClearControls(controlId1, controlId2, controlId3, controlId4) {
    ClearControl(controlId1);
    ClearControl(controlId2);
    ClearControl(controlId3);
    ClearControl(controlId4);
}

function ClearControls(controlId1, controlId2, controlId3, controlId4, controlId5) {
    ClearControl(controlId1);
    ClearControl(controlId2);
    ClearControl(controlId3);
    ClearControl(controlId4);
    ClearControl(controlId5);
}

function PostBackHiddenControl(controlId) {
    var control = document.getElementById(controlId)

    if (control != null) {
        control.value = (new Date()).toString();
        __doPostBack(controlId, '');
    }
}


function RicercaOnEnter(e, controlToClick) {
    if (controlToClick != null) {
        if (!e) var e = window.event;
        var keyCode = (e.which) ? e.which : e.keyCode;

        if (keyCode == 13) {
            var ricercaControl = document.getElementById(controlToClick);
            //if (ricercaControl != null) ricercaControl.click();
            if (ricercaControl != null) __doPostBack(controlToClick, '');
        }
    }
}
function MoveCopyright() {
    //debugger;
    div = document.getElementById('divCopy');
    if (div != null) div.style.left = document.body.offsetWidth - 230;

    div = document.getElementById('divMainMenu');
    hid = document.getElementById('MainMenu1_txtMainMenuHeight');
    if ((div != null) && (hid != null)) {
        if (showSAIWebModules)
            div.style.top = document.body.offsetHeight + document.body.scrollTop - parseInt(hid.value) - 12;
        else
            div.style.left = -500;
    }
}
function ChangeWidthFromScreenSize(controlName, size) {
    var divControl = document.getElementById(controlName);

    if (divControl != null)
        divControl.style.width = document.body.offsetWidth - size;
}

function SetBgColor(obj) {
    obj.style.backgroundColor = '#FFEC65';
}
//function SetBgColor(obj, strColor){
//obj.style.backgroundColor = strColor;
//}

function RemoveBgColor(obj) {
    obj.style.backgroundColor = '';
}

function VerifyMonths(varMonths) {
    var months = document.getElementById(varMonths);
    if (months != null) {
        if (months.value > 11) {
            ClearControl(varMonths);
        }
    }
}

function VerifyDays(varDays) {

    var days = document.getElementById(varDays);
    if (days != null) {
        if (days.value > 31) {
            ClearControl(varDays);
        }
    }
}
function ChangeMenuColor(id) {

    var par = document.getElementById(id);
    var childNodes = par.getElementsByTagName("td");
    var i = 0;
    for (i = 0; i < childNodes.length; i++) {

        if (childNodes[i].className == "crnLeftInactive") {
            if (document.getElementById("leftHoverVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("leftHoverVertical").value + ")";
        }
        if (childNodes[i].className == "crnMiddleInactive") {
            if (document.getElementById("middleHoverVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("middleHoverVertical").value + ")";

            var anchorNodes = childNodes[i].getElementsByTagName("a");
            for (j = 0; j < anchorNodes.length; j++) {
                anchorNodes[j].style.color = "#000000";
            }
        }
        if (childNodes[i].className == "crnRightInactive") {
            if (document.getElementById("rightHoverVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("rightHoverVertical").value + ")";
            
        }
    }
}
function ChangeMenuColorOut(id) {

    var par = document.getElementById(id);
    var childNodes = par.getElementsByTagName("td");
    var i = 0;
    for (i = 0; i < childNodes.length; i++) {

        if (childNodes[i].className == "crnLeftInactive") {
            if (document.getElementById("leftVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("leftVertical").value + ")";
        }
        if (childNodes[i].className == "crnMiddleInactive") {
            if (document.getElementById("middleVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("middleVertical").value + ")";
            var anchorNodes = childNodes[i].getElementsByTagName("a");
            for (j = 0; j < anchorNodes.length; j++) {
                anchorNodes[j].style.color = "rgb(102,17,0)";
            }
        }
        if (childNodes[i].className == "crnRightInactive") {
            if (document.getElementById("rightVertical").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("rightVertical").value + ")";
        }

    }
}

//Horizontal
function ChangeMenuColorHorizontal(id) {

    var par = document.getElementById(id);
    var childNodes = par.getElementsByTagName("td");
    var i = 0;
    for (i = 0; i < childNodes.length; i++) {

        if (childNodes[i].className == "crnLeftInactiveHor") {
            if (document.getElementById("leftHoverHorizontal").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("leftHoverHorizontal").value + ")";
        }
        if (childNodes[i].className == "crnMiddleInactiveHor") {
            if (document.getElementById("middleHoverHorizontal").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("middleHoverHorizontal").value + ")";

            var anchorNodes = childNodes[i].getElementsByTagName("a");
            for (j = 0; j < anchorNodes.length; j++) {
                anchorNodes[j].style.color = "#000000";
            }
        }
        if (childNodes[i].className == "crnRightInactiveHor") {
            if (document.getElementById("rightHoverHorizontal").value != null)
                childNodes[i].style.background = "url('" + document.getElementById("rightHoverHorizontal").value + "')";
        }
    }
}
function ChangeMenuColorOutHorizontal(id) {

    var par = document.getElementById(id);
    var childNodes = par.getElementsByTagName("td");
    var i = 0;
    for (i = 0; i < childNodes.length; i++) {

        if (childNodes[i].className == "crnLeftInactiveHor") {
            if (document.getElementById("leftHorizontal").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("leftHorizontal").value + ")";
        }
        if (childNodes[i].className == "crnMiddleInactiveHor") {
            if (document.getElementById("middleHorizontal").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("middleHorizontal").value + ")";
            var anchorNodes = childNodes[i].getElementsByTagName("a");
            for (j = 0; j < anchorNodes.length; j++) {
                anchorNodes[j].style.color = "rgb(102,17,0)";
            }
        }
        if (childNodes[i].className == "crnRightInactiveHor") {
            if (document.getElementById("rightHorizontal").value != null)
                childNodes[i].style.background = "url(" + document.getElementById("rightHorizontal").value + ")";
        }

    }
}