///<reference name="MicrosoftAjax.js" />

var dlg;
var popUpDlg;
var popUpDlgMdl;
var popUpIFrame;
var retun4Moz = false;

function DoWaterMarkOnFocus(txt, text) {
    if (txt.value == text) {
        txt.value = "";
    }
}


function GAtrackEvent(category) {
    // make sure GA is loaded before calling
    if (typeof _gaq !== 'undefined') {
        _gaq.push(['_trackEvent', category, 'Clicked']);
    }

    return true;
}

function DoWaterMarkOnBlur(txt, text) {
    if (txt.value == "") {
        txt.value = text;
    }
}


function confirmAffliateLogoff() {
    if (confirm("Are you sure you want to log out?"))
        location.href = "/security/logout.aspx?affliate=SONY";
}

function show_dialog2(hdr, val) {

    if (dlg) {

        return;

    }

    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    var outerDiv = document.createElement('div');
    outerDiv.style.display = 'block';
    outerDiv.style.position = 'absolute';
    outerDiv.style.top = ScrollTop + 200 + 'px';
    outerDiv.style.left = '43%';
    outerDiv.style.width = '400px';
    outerDiv.style.border = 'solid 1px #333399';
    //outerDiv.style.backgroundColor = '#fff3cf';
    outerDiv.style.backgroundImage = 'url(/images/BlueAddedToCartWithRedX.gif)';
    outerDiv.style.color = '#333399';
    outerDiv.style.fontWeight = 'bold';
    outerDiv.style.textAlign = 'center';
    outerDiv.style.verticalAlign = "middle";
    outerDiv.style.fontSize = '10';
    outerDiv.style.overflow = 'hidden';
    outerDiv.onclick = function() { hideDialog(); };


    var hdrP = document.createElement('p');
    hdrP.style.paddingLeft = '10px';

    var hdrText = document.createTextNode(hdr);

    hdrP.appendChild(hdrText);

    outerDiv.appendChild(hdrP);

    var innerDiv = document.createElement('div');
    innerDiv.style.width = '100%';
    //innerDiv.style.backgroundColor = '#fff3cf';
    innerDiv.style.backgroundImage = 'url(/images/YellowAddedToCart.gif)';
    innerDiv.style.color = 'black';
    innerDiv.style.textAlign = 'center';
    innerDiv.style.marginTop = '-15px';
    innerDiv.style.fontSize = '10';
    innerDiv.style.padding = '7px';
    innerDiv.onclick = function() { hideDialog(); };

    var txtP = document.createElement('p');

    var imgNode = document.createElement('img');

    imgNode.style.border = 'none';
    imgNode.setAttribute('src', '/images/ltBlueCheckGrad.gif');
    imgNode.setAttribute('border', '0');
    imgNode.setAttribute('style', 'float: left;');

    txtP.appendChild(imgNode);

    var hdrText = document.createTextNode(val);
    txtP.appendChild(hdrText);

    innerDiv.appendChild(txtP);

    outerDiv.appendChild(innerDiv);

    dlg = outerDiv;
    document.body.appendChild(outerDiv);

    setTimeout('flashBorder( \"#ffc211\")', 200);
    setTimeout('flashBorder( \"#333399\")', 400);
    setTimeout('flashBorder( \"#ffc211\")', 600);
    setTimeout('flashBorder( \"#333399\")', 800);
    setTimeout('flashBorder( \"#ffc211\")', 1000);
    setTimeout('flashBorder( \"#333399\")', 1200);

    setTimeout('hideDialog()', 2500);
}

function show_itemdPopUp(popUpDiv, widthOfPoup) {

    if (!popUpDiv) return;

    if (retun4Moz) {
        retun4Moz = false;
        popUpClose();
    }
    if (popUpDlg) {
        if (navigator.appName == 'Netscape') {
            retun4Moz = true;
            return;
        }
        popUpClose();
    }

    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    if (popUpDiv) {
        var outerDiv = document.createElement('div');
        outerDiv.style.display = 'block';
        outerDiv.style.position = 'absolute';
        outerDiv.style.top = '0px';
        outerDiv.style.left = '0px';
        outerDiv.style.width = document.body.offsetWidth + 'px';
        outerDiv.style.height = document.body.offsetHeight + 'px';
        outerDiv.style.border = 'solid 1px #333399';
        outerDiv.style.backgroundColor = "#757575";
        //outerDiv.style.backgroundImage = 'url(/images/BlueAddedToCartWithRedX.gif)';
        //outerDiv.style.color = '#333399';
        outerDiv.style.fontWeight = 'bold';
        outerDiv.style.textAlign = 'center';
        outerDiv.style.verticalAlign = "middle";
        outerDiv.style.fontSize = '10';
        outerDiv.style.overflow = 'hidden';
        outerDiv.style.opacity = '.50';
        //outerDiv.style.-moz-opacity = '.50';
        outerDiv.style.filter = 'alpha(opacity=50)';
        outerDiv.style.zIndex = '2000';

        popUpDlg = outerDiv;
        var innerDiv = document.createElement('div');
        popUpDiv.style.display = 'block';
        innerDiv.innerHTML = popUpDiv.innerHTML;
        popUpDiv.style.display = 'none';
        innerDiv.style.display = 'block';
        innerDiv.style.position = 'absolute';
        innerDiv.style.overflow = 'hidden';
        innerDiv.style.backgroundColor = 'White';
        innerDiv.style.top = ScrollTop + 200 + 'px';
        if (widthOfPoup == null)
            widthOfPoup = '700';
        innerDiv.style.left = (document.body.offsetWidth / 2 - widthOfPoup / 2) + 'px';
        innerDiv.style.zIndex = '3001';

        popUpIFrame = document.createElement('iframe');
        popUpIFrame.style.display = 'block';
        popUpIFrame.style.position = 'absolute';
        popUpIFrame.style.top = '0px';
        popUpIFrame.style.left = '0px';
        popUpIFrame.style.width = document.body.offsetWidth + 'px';
        popUpIFrame.style.height = document.body.offsetHeight + 'px';
        popUpIFrame.style.filter = 'alpha(opacity=50)';
        popUpIFrame.style.opacity = '.50';
        popUpIFrame.style.zIndex = '1999';

        popUpDlgMdl = innerDiv;

        document.body.appendChild(popUpIFrame);
        document.body.appendChild(outerDiv);
        document.body.appendChild(innerDiv);
    }
}
function show_itemdPopUpFixed(popUpDiv, widthOfPoup) {

    if (retun4Moz) {
        retun4Moz = false;
        popUpClose();
    }
    if (popUpDlg) {
        if (navigator.appName == 'Netscape') {
            retun4Moz = true;
            return;
        }
        popUpClose();
    }



    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    var outerDiv = document.createElement('div');
    outerDiv.style.display = 'block';
    outerDiv.style.position = 'absolute';
    outerDiv.style.top = '0px';
    outerDiv.style.left = '0px';
    outerDiv.style.width = document.body.offsetWidth + 'px';
    outerDiv.style.height = document.body.offsetHeight + 'px';
    outerDiv.style.border = 'solid 1px #333399';
    outerDiv.style.backgroundColor = "#757575";
    //outerDiv.style.backgroundImage = 'url(/images/BlueAddedToCartWithRedX.gif)';
    //outerDiv.style.color = '#333399';
    outerDiv.style.fontWeight = 'bold';
    outerDiv.style.textAlign = 'center';
    outerDiv.style.verticalAlign = "middle";
    outerDiv.style.fontSize = '10';
    outerDiv.style.overflow = 'hidden';
    outerDiv.style.opacity = '.50';
    //outerDiv.style.-moz-opacity = '.50';
    outerDiv.style.filter = 'alpha(opacity=50)';
    outerDiv.style.zIndex = '2000';

    popUpDlg = outerDiv;
    var innerDiv = document.createElement('div');
    popUpDiv.style.display = 'block';
    innerDiv.innerHTML = popUpDiv.innerHTML;
    popUpDiv.style.display = 'none';
    innerDiv.style.display = 'block';
    innerDiv.style.position = 'absolute';
    innerDiv.style.overflow = 'hidden';
    innerDiv.style.backgroundColor = 'White';
    innerDiv.style.top = '20px';
    if (widthOfPoup == null)
        widthOfPoup = '700';
    innerDiv.style.left = (document.body.offsetWidth / 2 - widthOfPoup / 2) + 'px';
    innerDiv.style.zIndex = '3001';

    popUpIFrame = document.createElement('iframe');
    popUpIFrame.style.display = 'block';
    popUpIFrame.style.position = 'absolute';
    popUpIFrame.style.top = '0px';
    popUpIFrame.style.left = '0px';
    popUpIFrame.style.width = document.body.offsetWidth + 'px';
    popUpIFrame.style.height = document.body.offsetHeight + 'px';
    popUpIFrame.style.filter = 'alpha(opacity=50)';
    popUpIFrame.style.opacity = '.50';
    popUpIFrame.style.zIndex = '1999';

    popUpDlgMdl = innerDiv;

    document.body.appendChild(popUpIFrame);
    document.body.appendChild(outerDiv);
    document.body.appendChild(innerDiv);
}

function show_itemdPopUpTop(popUpDiv, widthOfPoup) {

    if (retun4Moz) {
        retun4Moz = false;
        popUpClose();
    }
    if (popUpDlg) {
        if (navigator.appName == 'Netscape') {
            retun4Moz = true;
            return;
        }
        popUpClose();
    }



    var ScrollTop = 5;

    //if (ScrollTop == 0) {
    //    if (window.pageYOffset)
    //        ScrollTop = window.pageYOffset;
    //    else
    //        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    //}

    var outerDiv = document.createElement('div');
    outerDiv.style.display = 'block';
    outerDiv.style.position = 'absolute';
    outerDiv.style.top = '0px';
    outerDiv.style.left = '0px';
    outerDiv.style.width = document.body.offsetWidth + 'px';
    outerDiv.style.height = document.body.offsetHeight + 'px';
    outerDiv.style.border = 'solid 1px #333399';
    outerDiv.style.backgroundColor = "#757575";
    //outerDiv.style.backgroundImage = 'url(/images/BlueAddedToCartWithRedX.gif)';
    //outerDiv.style.color = '#333399';
    outerDiv.style.fontWeight = 'bold';
    outerDiv.style.textAlign = 'center';
    outerDiv.style.verticalAlign = "middle";
    outerDiv.style.fontSize = '10';
    outerDiv.style.overflow = 'hidden';
    outerDiv.style.opacity = '.50';
    //outerDiv.style.-moz-opacity = '.50';
    outerDiv.style.filter = 'alpha(opacity=50)';
    outerDiv.style.zIndex = '2000';

    popUpDlg = outerDiv;
    var innerDiv = document.createElement('div');
    popUpDiv.style.display = 'block';
    innerDiv.innerHTML = popUpDiv.innerHTML;
    popUpDiv.style.display = 'none';
    innerDiv.style.display = 'block';
    innerDiv.style.position = 'absolute';
    innerDiv.style.overflow = 'hidden';
    innerDiv.style.backgroundColor = 'White';
    innerDiv.style.top = ScrollTop + 200 + 'px';
    if (widthOfPoup == null)
        widthOfPoup = '700';
    innerDiv.style.left = (document.body.offsetWidth / 2 - widthOfPoup / 2) + 'px';
    innerDiv.style.zIndex = '3001';

    popUpIFrame = document.createElement('iframe');
    popUpIFrame.style.display = 'block';
    popUpIFrame.style.position = 'absolute';
    popUpIFrame.style.top = '0px';
    popUpIFrame.style.left = '0px';
    popUpIFrame.style.width = document.body.offsetWidth + 'px';
    popUpIFrame.style.height = document.body.offsetHeight + 'px';
    popUpIFrame.style.filter = 'alpha(opacity=50)';
    popUpIFrame.style.opacity = '.50';
    popUpIFrame.style.zIndex = '1999';

    popUpDlgMdl = innerDiv;

    document.body.appendChild(popUpIFrame);
    document.body.appendChild(outerDiv);
    document.body.appendChild(innerDiv);
}

function show_UrlPopUp(url, widthOfPoup, heightOfPopup) {

    if (retun4Moz) {
        retun4Moz = false;
        popUpClose();
    }
    if (popUpDlg) {
        if (navigator.appName == 'Netscape') {
            retun4Moz = true;
            return;
        }
        popUpClose();
    }



    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    var outerDiv = document.createElement('div');
    outerDiv.style.display = 'block';
    outerDiv.style.position = 'absolute';
    outerDiv.style.top = '0px';
    outerDiv.style.left = '0px';  /*
    QC ID 2011, Developer Name: ARAVI, Date: 1 June 2011
    Description: Resizing the browser window to small creates a small div, which remains the same when browser window is resized - Used the original screen size instead of the browser window size to set the height and width of div.
    */
    outerDiv.style.width = (screen.availWidth - 18) + 'px'; //document.body.offsetWidth + 'px';
    outerDiv.style.height = (screen.availHeight - 20) + 'px'; //document.body.offsetHeight + 'px';
    outerDiv.style.border = 'solid 1px #333399';
    outerDiv.style.backgroundColor = "#757575";
    //outerDiv.style.backgroundImage = 'url(/images/BlueAddedToCartWithRedX.gif)';
    //outerDiv.style.color = '#333399';
    outerDiv.style.fontWeight = 'bold';
    outerDiv.style.textAlign = 'center';
    outerDiv.style.verticalAlign = "middle";
    outerDiv.style.fontSize = '10';
    outerDiv.style.overflow = 'hidden';
    outerDiv.style.opacity = '.50';
    //outerDiv.style.-moz-opacity = '.50';
    outerDiv.style.filter = 'alpha(opacity=50)';
    outerDiv.style.zIndex = '2000';

    popUpDlg = outerDiv;

    var innerDiv = document.createElement('iframe');
    innerDiv.setAttribute("src", url);
    ////    popUpDiv.style.display = 'block';
    ////    innerDiv.innerHTML = popUpDiv.innerHTML;
    ////    popUpDiv.style.display = 'none';
    innerDiv.style.display = 'block';
    innerDiv.style.position = 'absolute';
    innerDiv.style.overflow = 'hidden';
    innerDiv.style.backgroundColor = 'White';
    innerDiv.style.top = ScrollTop + 50 + 'px';

    if (heightOfPopup == null)
        heightOfPopup = '550';
    innerDiv.style.height = heightOfPopup + 'px';

    if (widthOfPoup == null)
        widthOfPoup = '700';
    innerDiv.style.width = widthOfPoup + 'px';
    /*
    QC ID 2011, Developer Name: ARAVI, Date: 1 June 2011
    Description: Resizing the browser window to small creates a small iframe, which remains the same when browser window is resized - Set the pop-up div to the mid of the whole screen instead of the current browser window size.
    */
    innerDiv.style.left = ((screen.availWidth - 20) / 2 - widthOfPoup / 2) + 'px'; //(document.body.offsetWidth / 2 - widthOfPoup / 2) + 'px';
    innerDiv.style.zIndex = '3001';

    popUpIFrame = document.createElement('iframe');
    popUpIFrame.style.display = 'block';
    popUpIFrame.style.position = 'absolute';
    popUpIFrame.style.top = '0px';
    popUpIFrame.style.left = '0px';
    /*
    QC ID 2011, Developer Name: ARAVI, Date: 1 June 2011
    Description: Resizing the browser window to small creates a small iframe, which remains the same when browser window is resized - Used the original screen size instead of the browser window size to set the height and width of iframe.
    */
    popUpIFrame.style.width = (screen.availWidth - 20) + 'px'; //document.body.offsetWidth + 'px';screen.availHeight
    popUpIFrame.style.height = (screen.availHeight - 20) + 'px'; //document.body.offsetHeight + 'px';
    popUpIFrame.style.filter = 'alpha(opacity=50)';
    popUpIFrame.style.opacity = '.50';
    popUpIFrame.style.zIndex = '1999';

    popUpDlgMdl = innerDiv;

    document.body.appendChild(popUpIFrame);
    document.body.appendChild(outerDiv);
    document.body.appendChild(innerDiv);

}

function popUpClose() {
    if (popUpDlg) {
        popUpDlg.style.display = 'none';
        popUpDlgMdl.style.display = 'none';
        popUpDlg = null;
        popUpIFrame.style.display = 'none';
    }
}

function flashBorder(ccolor) {
    if (dlg) {
        dlg.style.borderColor = ccolor;
    }
}

function hideDialog() {
    //alert('here!');
    if (dlg) {
        dlg.style.display = 'none';
        dlg = null;
    }
}

function show_hide_box(an, width, height, borderStyle, href) {

    var boxdiv = document.getElementById(href);

    if (boxdiv != null) {
        if (boxdiv.style.display == 'none') {
            move_box(an, boxdiv);
            boxdiv.style.display = 'block';
        } else
            boxdiv.style.display = 'none';
        return false;
    }

    boxdiv = document.createElement('div');
    boxdiv.setAttribute('id', href);
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.backgroundColor = '#fff';

    var contents = document.createElement('iframe');
    contents.scrolling = 'no';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = height + 'px';
    contents.src = href;

    boxdiv.appendChild(contents);
    document.body.appendChild(boxdiv);
    move_box(an, boxdiv);

    return false;
}

function move_box(an, box) {
    var cleft = 33;
    var ctop = -15;
    var obj = an;

    while (obj.offsetParent) {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';
    ctop += an.offsetHeight + 10;

    if (document.body.currentStyle && document.body.currentStyle['marginTop']) {
        ctop += parseInt(document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

// call FlipVisibility passing in an ElementId, it will flip it's visibility status
function FlipVisibility(d) {
    if (document.getElementById(d)) {
        if (document.getElementById(d).style.display == "none") {
            document.getElementById(d).style.display = "block";
        }
        else {
            document.getElementById(d).style.display = "none";
        }
    }
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;

    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    if (isNaN(key)) return true;

    keychar = String.fromCharCode(key);

    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl) {
        return true;
    }

    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

    return isFirstN || isFirstD || reg.test(keychar);
}

//The below method displays the address book in modal popup
function OpenAddressBookWindow() {

    var WinSettings = "center:yes;resizable:no;dialogHeight:600px;dialogWidth:1000px";
    // ALTER BELOW LINE - supply correct URL for Child Form
    var MyArgs = window.showModalDialog("../../TDSKUSelector.aspx?isDirectAccess=true&isFromToolsMenu=false", null, WinSettings);

    if (MyArgs == null) {
    }
    else {
        if (MyArgs[0].toString() == 'Ok') {
            //Use the below if just want to reload the page
            window.location.reload(true);
            //window.location.href = window.location.href
        }
        else if (MyArgs[0].toString() == 'Cancel') {
            //alert('Cancel');
        }

    }
}


// MOVED FROM GLOBAL.JS

function confirmLogoff() {
    if (confirm("Are you sure you want to log out?"))
        location.href = "/security/logout.aspx";
}

function ShowPopup(hoveritem) {
    hp = document.getElementById("HoverCart");

    if (hp) {
        mcancelclosetime();
        hp.style.visibility = 'hidden';

        ddmenuitem = hp;
        var cleft = 0;
        var ctop = 0;
        var obj = hoveritem;
        while (obj.offsetParent) {
            cleft += obj.offsetLeft;
            ctop += obj.offsetTop;
            obj = obj.offsetParent;
        }
        hp.style.left = (cleft - 55) + 'px';
        ctop += hoveritem.offsetHeight; // + 10;
        if (document.body.currentStyle && document.body.currentStyle['marginTop']) {
            ctop += parseInt(document.body.currentStyle['marginTop']);
        }
        hp.style.top = ctop + 'px';

        hp.style.visibility = "Visible";
        hp.style.zIndex = 999;
    }
}


function ShowFrame() {
    if (document.getElementById("frmSurvey").height > '1')
        document.getElementById("frmSurvey").height = '1';
    else {
        document.getElementById("frmSurvey").src = '/reseller/PageRateNew.aspx?URL=' + location.href;
        document.getElementById("frmSurvey").height = '100';
    }
    document.location.hash = "bottom";
}


function DoWaterMarkOnFocus(txt, text) {
    if (txt.value == text) {
        txt.value = "";
    }
}

function DoWaterMarkOnBlur(txt, text) {
    if (txt.value == "") {
        txt.value = text;
    }
}

function GetHelp(strPage) {
    var strURL = "/reseller/help/Help" + strPage;
    window.open(strURL, "HELP", "height=450,width=330,status=1,toolbar=1,resizable,scrollbars=yes");
}
