
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }


function setPageLayoutImage(strLayout, strImgSrc, PageID) {

    try {
        if (window.top.document.getElementById('pg_tblLeftPanel')) {
            window.top.document.getElementById('pg_tblLeftPanel').className = 'mcont';
            window.top.document.getElementById('pg_tblRightPanel').className = 'mcont';
            window.top.document.getElementById('pg_tblLeftRightPanel').className = 'mcont';
            window.top.document.getElementById('pg_tblOnlyCenterPanel').className = 'mcont';

            if (strLayout == 'LEFT')
                window.top.document.getElementById('pg_tblLeftPanel').className = 'hmcont';
            else if (strLayout == 'RIGHT')
                window.top.document.getElementById('pg_tblRightPanel').className = 'hmcont';
            else if (strLayout == 'LEFTRIGHT')
                window.top.document.getElementById('pg_tblLeftRightPanel').className = 'hmcont';
            else if (strLayout == 'CENTER')
                window.top.document.getElementById('pg_tblOnlyCenterPanel').className = 'hmcont';

            window.top.document.getElementById('pg_imgSiteLayout').src = strImgSrc;

            window.top.document.getElementById('pg_hidPageID').value = PageID;
        }
    }
    catch (ex) { }

}

function toggleClick(str) {
    if (str == "SYS") {
        document.getElementById('liSys').style.display = "none";
        document.getElementById("liCP").style.display = "";

        document.getElementById("buttlayout").style.display = "none";
        document.getElementById("buttsitemap").style.display = "none";
    }
    else {
        document.getElementById("liSys").style.display = ""
        document.getElementById("liCP").style.display = "none";

        document.getElementById("buttlayout").style.display = "";
        document.getElementById("buttsitemap").style.display = "";
    }
    return true;
}

function getQval(name) {

    try {
        var m, Q = window.parent.location.search.substring(1);
        if ('' != Q) {
            var re = new RegExp(escape(name) + '=([^&$]+)');
            if (m = Q.match(re))
                return m[1];
            else return '';
        }
        return '';
    }
    catch (obj) { }

}

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}


function transferToIndexPage() {

    if (getQval('url') == '') {
        window.location.href = "/index.aspx?url=" + URLEncode(window.location.href + '');
    }
}


function transferToIndexPage2() {

    if (!window.top.frames["iAdmin"]) {
        window.location.href = "/index.aspx?url=" + URLEncode(window.location.href + '');
    }
}



function Newshowpopup(url, width, height, winname, otitle) {

    try {
        window.top.NewShowpopup2(url, width, height, winname, otitle);
        return false;
    }
    catch (obj) { }

}

function NewShowpopup2(url, width, height, winname, otitle) {
    try {
        var wndHandle = $find('dialogMain');
        wndHandle.setUrl(url);
        wndHandle.SetTitle(otitle);
        wndHandle.show();
        return false;
    }
    catch (obj) { }
}






function fixActiveX() {

    try {
        objects = document.getElementsByTagName("object");
        for (var i = 0; i < objects.length; i++) {
            objects[i].outerHTML = objects[i].outerHTML;
        }
    }
    catch (obj2) {
    }
    return true;
}

function Redirect(url) {
    location.href = url;
}

/*function imagePreLoader()
//{
//    /*var imgs=new Array()
//    imgs[0]="~/Skins/Default/Window/close.gif"
//    imgs[1]="~/Skins/Default/Window/CommandSprites.gif"
//    imgs[2]="~/Skins/Default/Window/Default.gif"
//    imgs[3]="~/Skins/Default/Window/FooterSprites.gif"
//    imgs[4]="~/Skins/Default/Window/Icon.gif"
//    imgs[5]="~/Skins/Default/Window/Loading.gif"
//    imgs[6]="~/Skins/Default/Window/StatusBarSprites.gif"
//    imgs[7]="~/Skins/Default/Window/WindowCornerSprites.gif"
//    imgs[8]="~/Skins/Default/Window/WindowResizeHandle.gif"
//    imgs[9]="~/Skins/Default/Window/WindowSprites.gif"
//    imgs[10]="~/Skins/Default/Window/WindowVerticalSprites.gif"
// 
//    //preload
//    var img = new Image();
//	for(i=0;i<imgs.length;i++)
//    {
//		img.src = imgs[i];
//    }
//    
/}*/

function subValidate() {
    var url;
    url = window.location.href;
    if (url.indexOf('http://6') > -1) {
        alert('Please click View Original Web Page from the top of the Page');
        return false;
    }
    else {

        if (typeof (ValidatorOnSubmit) == "function")
            return ValidatorOnSubmit();
    }
}

function OnClientDock(dockObj, eventArgs) {
    var resDoc = '';
    var dZones = Telerik.Web.UI.RadDockZonesGlobalArray;
    for (j = 0; j < dZones.length; j++) {
        var dZone = dZones[j];
        if (dZone.get_docks) {
            var docObjs = dZone.get_docks();
            if (docObjs) {
                for (i = 0; i < docObjs.length; i++) {
                    var lobj = docObjs[i];
                    resDoc += lobj.get_uniqueID() + ':' + dZone.get_id() + ":" + lobj._index + '|';
                }
            }
        }
    }
    $get('ajaxCommandName').value = 'reorder';
    $get('ajaxCommandArgs').value = resDoc;
    window.setTimeout(postAjaxCommandToPage, 500);
}



function postAjaxCommandToPage() {

    postBackHiddenField('hidData');

    cshowDialog();
}

function postBackHiddenField(hiddenFieldID) {
    var hiddenField = $get(hiddenFieldID);
    if (hiddenField) {
        hiddenField.value = (new Date()).getTime();
        __doPostBack(hiddenFieldID, 'ValueChanged');
    }
}


function MainPopup(url, width, height, winname, otitle) {
    showwin(url, otitle, width, height); //Using new jQuery Window
    return false;
}


function showwin(url, title,intwidth, intheight) {

    var theurl = url;
    var thetitle = title;

    if (intheight <= 0)
        intheight = 575;

    if (intwidth <= 0)
        intwidth = 800;    
    
    if (title == null)
        thetitle = "...";

    if (url.toString().indexOf("?") > -1)
        theurl = theurl //+ "&guid=" + generateGuid();
    else
        theurl = theurl //+ "?guid=" + generateGuid();

    $("#ddialog").dialog({
        modal: true,
        overlay: {
            opacity: 0.5,
            background: "white"
        },
        title: thetitle,
        width: intwidth,
        height: intheight,
        resizable: false,
        autoResize: true,
        draggable: true,
        close: closediv,
        resizableOptions: { autoResize: true, autoHide: true }
    }).show();
    $("#createPageiFrame").attr("src", theurl);
    $("#createPageiFrame").css("display", "block");

   
}


function closeparentdiv() {
    this.parent.closediv();
}



function closediv() {
    try {
        var d = $("#ddialog").dialog('destroy');
        $("#createPageiFrame").attr("src", 'blank.htm');
        $('html, body').css("overflow", "scroll");
        refreshRVPage();
    }
    catch (ob) {
    }

}



function showpopup(url, width, height, winname, otitle) {
    try {
        window.top.MainPopup(url, width, height, winname, otitle);
        return false;
    }
    catch (obj) {
    }
}



var theWidth, theHeight;

function FindParentSize() {

    if (window.innerWidth) {
        theWidth = window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        theWidth = document.documentElement.clientWidth;
    }
    else if (document.body) {
        theWidth = document.body.clientWidth;
    }
    if (window.innerHeight) {
        theHeight = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        theHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        theHeight = document.body.clientHeight;
    }
}

function MainWinShown(radWindow) {
    if (radWindow)
        radWindow.center();
}

function AjaxEndRequestHandler(sender, args) {

    var ref = $get('reqRef').value;

    if (ref == 'true')
        refreshRVPortalPage();
    window.setTimeout(hideDialog, 500);


}

function MainWinClosed(radWindow) {
    refreshRVPage();
}

function refreshRVPage() {
    if (window.frames["iAdmin"]) {
        window.frames["iAdmin"].location.href = window.frames["iAdmin"].location.href;
    }
    else
        window.location.href = window.location.href;


}

function refreshRVPageWithUrl(strUrl) {

    window.frames['iAdmin'].location.href = strUrl;

}

function refreshRVPortalPage() {

    if (window.top.frames["iAdmin"]) {
        window.top.frames["iAdmin"].location.href = window.top.frames["iAdmin"].location;
    }
    else
        window.location.href = window.location.href;
}


function ShowAlert(msg) {
    alert(msg);


}


/* Main CMS Page Javascript Ends here */


/* Menu Related Scripts */
var timeoutid;
function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_showHideLayers() {
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) {
            obj = obj.style;
            if (v == 'show') {
                obj.top = findPosY("img" + args[i]) + 21 + "px";

                obj.left = findPosX("img" + args[i]) + "px";

            }
            v = (v == 'show') ? 'block' : (v == 'hide') ? 'none' : v;
        }
        obj.display = v;
    }
}


function CustomShowHide(menuname) {
    var currentmenu;
    currentmenu = MM_findObj(menuname);

    if (currentmenu.style.display == "none") {
        MM_showHideLayers(menuname, '', 'show');

    }
    else {
        timeoutid = setTimeout("myTimeout('" + menuname + "');", 500);
    }

}


function myTimeout(mnu) {

    MM_showHideLayers(mnu, '', 'hide');
}


function Stickit() {
    clearTimeout(timeoutid);
}

function findPosX(imgtext) {
    var obj = window.document.getElementById(imgtext);
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;

    return curleft;


}
function findPosY(imgtext) {
    var obj = window.document.getElementById(imgtext);
    var curtop = 0;
    if (imgtext == "imgdivMenu") {
        var curtop = 20;

    }

    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;

    return curtop;
}

function MM_changeProp(objName, x, theProp, theValue) { //v6.0
    var obj = MM_findObj(objName);
    if (obj && (theProp.indexOf("style.") == -1 || obj.style)) {
        if (theValue == true || theValue == false)
            eval("obj." + theProp + "=" + theValue);
        else eval("obj." + theProp + "='" + theValue + "'");
    }
}

/* Menu Commands End Here */

/* RV Page Commands */

function ToggleShowInAllpage(mid) {

    $get('ajaxCommandName').value = 'togshowInAll';
    $get('ajaxCommandArgs').value = mid;

    window.setTimeout(postAjaxCommandToPage, 500);
}

function PubModule(mid) {

    $get('ajaxCommandName').value = 'pubModule';
    $get('ajaxCommandArgs').value = mid;

    window.setTimeout(postAjaxCommandToPage, 500);
}

function HideModule(mid) {

    $get('ajaxCommandName').value = 'hideModule';
    $get('ajaxCommandArgs').value = mid;

    window.setTimeout(postAjaxCommandToPage, 500);
}

function DelModule(mid) {
    var conf = confirm("Are you sure you want to delete this Module ?");
    if (conf) {

        $get('ajaxCommandName').value = 'delModule';
        $get('ajaxCommandArgs').value = mid;

        window.setTimeout(postAjaxCommandToPage, 500);
    }
}

function popupSSL() {

    var wndHandle = window.top.$find('dialogMain');

    wndHandle.setUrl("~/sys/SSLConfirmation.aspx?mode=direct");
    wndHandle.SetTitle("Please wait Loading...");
    wndHandle.setSize(350, 200);
    wndHandle.center();
    wndHandle.show();
    return false;
}

function popupMainWindow(url, title, width, height, callback) {
    var wndHandle = window.top.$find('dialogMain');
    wndHandle.setUrl(url);
    wndHandle.SetTitle(title);
    wndHandle.remove_close(MainWinClosed);
    if (callback)
        wndHandle.add_close(callback);
    wndHandle.setSize(width, height);
    wndHandle.center();
    wndHandle.show();
    return false;
}

/* RV Page Command Ends */


function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}

function posLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function $$(x) {
    return document.getElementById(x);
}

function scrollFix() {
    var obol = $$('ol'); 
    if(obol.style != null)
    {
        obol.style.top = posTop() + 'px';
        obol.style.left = posLeft() + 'px'
    }
}

function sizeFix() {

    var obol = $$('ol');
    if(obol.style != null)
	{
        obol.style.height = pageHeight() + 'px';
        obol.style.width = pageWidth() + 'px';
    }
}

function kp(e) {
    ky = e ? e.which : event.keyCode;
    if (ky == 88 || ky == 120) hm();
    return false
}

function inf(h) {
    tag = document.getElementsByTagName('select');
    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;
    tag = document.getElementsByTagName('iframe');
    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;
    tag = document.getElementsByTagName('object');
    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;
}

function sm(obl, wd, ht) {
    var h = 'hidden';
    var b = 'block';
    var p = 'px';
    var obol = $$('ol');
    if (!$$('mbd'))
        initmb();
    var obbxd = $$('mbd');
    obbxd.innerHTML = $$(obl).innerHTML;
    if (obol.style) {
        obol.style.height = pageHeight() + p;
        obol.style.width = pageWidth() + p;
        obol.style.top = posTop() + p;
        obol.style.left = posLeft() + p;
        obol.style.display = b;
     }
    var tp = posTop() + ((pageHeight() - ht) / 2) - 12;
    var lt = posLeft() + ((pageWidth() - wd) / 2) - 12;
    var obbx = $$('mbox');
    if (obbx.style) {
        obbx.style.top = (tp < 0 ? 0 : tp) + p;
        obbx.style.left = (lt < 0 ? 0 : lt) + p;
        obbx.style.width = wd + p;
        obbx.style.height = ht + p;
        inf(h);
        obbx.style.display = b;
     }
    setheightWidth(obbx);
    return false;
}

function setheightWidth(obbx) {
    var img = document.getElementById('imgProgress');
    if (img) {
        var h, w;
        h = img.height;
        w = img.width;
        if (obbx.style && parseInt(h) > 0 && parseInt(w) > 0) {
            obbx.style.height = h + 'px'
            obbx.style.width = w + 'px'
            var ww, wh;
            ww = (document.body.clientWidth / 2) - (w / 2);
            ww = parseInt(ww);
            obbx.style.left = ww + 'px';
        }
    }
}

function hm() {
    if ($$('ol')) {
        var v = 'visible'; var n = 'none';
        
        if($$('ol').style)
        {
            $$('ol').style.display = n;
        }
        
        if($$('mbox').style)
        {
            $$('mbox').style.display = n;
        }   
        inf(v);
        document.onkeypress = ''
    }
}

function initmb() {
    var ab = 'absolute'; var n = 'none';
    var obody = document.getElementsByTagName('body')[0];
    var frag = document.createDocumentFragment();
    var obol = document.createElement('div');
    obol.setAttribute('id', 'ol');
    obol.style.display = n;
    obol.style.position = ab;
    obol.style.top = 0;
    obol.style.left = 0;
    obol.style.zIndex = 998;
    obol.style.width = '100%';
    frag.appendChild(obol);
    var obbx = document.createElement('div');
    obbx.setAttribute('id', 'mbox');
    obbx.style.display = n;
    obbx.style.position = ab;
    obbx.style.zIndex = 999;
    var obl = document.createElement('span');
    obbx.appendChild(obl);
    var obbxd = document.createElement('div');
    obbxd.setAttribute('id', 'mbd');
    obl.appendChild(obbxd);
    frag.insertBefore(obbx, obol.nextSibling);
    obody.insertBefore(frag, obody.firstChild);
    window.onscroll = scrollFix; window.onresize = sizeFix;
}
window.onload = initmb;

function cshowDialog() {
    if (typeof (ValidatorOnSubmit) == "function") {
        if (Page_IsValid == true)
            sm('box', 20, 20);
        else
            return false;
    }
    else {
        sm('box', 20, 20);
        return true;
    }


}


function hookAjax() {
    try {
        if (Sys) {
            var orq = Sys.WebForms.PageRequestManager.getInstance();
            if (orq)
                orq.add_endRequest(EndRequestHandler);
        }

    }
    catch (obj) {

    }
}

function EndRequestHandler(sender, args)
{ hideDialog(); }

function hideDialog() {
    hm('box');
}
function ShowAjaxMessage() {

    try {
        var orq = Sys.WebForms.PageRequestManager.getInstance();
        if (orq)
            orq.add_pageLoading(PageLoadingHandler);


    }
    catch (obj) {

    }
}

function PageLoadingHandler(sender, args) {

    var dataItems = args.get_dataItems();
    var ID;

    if (dataItems['<%=AjaxHiddenField.ClientID%>'] != null)
        ID = '<%=AjaxHiddenField.ClientID%>'
    else
        ID = "AjaxHiddenField";

    if (dataItems[ID] != null) {
        if ($get(ID) != null) {
            $get(ID).value = dataItems[ID];

            var pem = document.getElementById(ID);
            if (pem != null && pem.value.length > 0) {

                alert(pem.value);
            }
        }
    }

}
function Trim(input) {
    return input.replace(/^\s+|\s+$/g, '');
} 

