﻿function fixIE6flicker(fix) {
    try {
        document.execCommand("BackgroundImageCache", false, true);
    } catch (err) { }
}

var radioButtonGroupActiveRadioButtons = new Array;
var radioButtonGroups = new Array;

function ToggleRadioButtonChecked(radioButton) {
    var isKnownRadioButtonGroup = radioButtonGroups[radioButton.name];
    var activeRadioButton = radioButtonGroupActiveRadioButtons[radioButton.name];

    if ((!isKnownRadioButtonGroup) && activeRadioButton == null && radioButton.defaultChecked) {
        activeRadioButton = radioButton;
    }

    radioButtonGroups[radioButton.name] = true;

    if (radioButton == activeRadioButton) {
        radioButton.checked = false;
        radioButtonGroupActiveRadioButtons[radioButton.name] = null;
    }
    else {
        radioButton.checked = true;
        radioButtonGroupActiveRadioButtons[radioButton.name] = radioButton;
    }
}

function getWindowWidthHeight() {
    var resultArray = new Array(2);

    // Firefox
    if (window.innerHeight && window.scrollMaxY) {
        resultArray[0] = window.innerWidth + window.scrollMaxX;
        resultArray[1] = window.innerHeight + window.scrollMaxY;
        
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
    {
        resultArray[0] = document.body.scrollWidth;
        resultArray[1] = document.body.scrollHeight;
        resultArray[1] = resultArray[1] + 200;
        
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    {
        resultArray[0] = document.body.offsetWidth + document.body.offsetLeft;
        resultArray[1] = document.body.offsetHeight + document.body.offsetTop;
        resultArray[1] = resultArray[1] + 500; // The height isnt correct in IE7, sometimes to low....so we add 500 extra...        
    }

    return resultArray;
}

// This function is used to find the x/y position of the element parsed as argument.
function findPos(obj) {
    var resultArray = new Array(2);
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
        while (obj = obj.offsetParent);
    }

    resultArray[0] = curleft;
    resultArray[1] = curtop;

    return resultArray;
}

// Will show the background cover. The dialog heigth is used to ensure proper rendering in case the dialog is higher than the initial document
function showCover(dialogHeight) {
    var cvr = document.getElementById("cover");
    cvr.style.height = "100px";  //mozilla wants a height to get started....
    cvr.style.display = "block";

    var contentDIV = document.getElementById("content");
    var resultsArray = findPos(contentDIV);

    // Set negative margins to expand cover over its containers borders
    var resultLeft = "-" + resultsArray[0];
    var resultTop = "-" + resultsArray[1];
    cvr.style.left = resultLeft + "px";
    cvr.style.top = resultTop + "px";

    var widthHeightArray = getWindowWidthHeight();

    var winW = widthHeightArray[0];
    var winH = widthHeightArray[1];
    if (dialogHeight > winH) {
        winH = winH + dialogHeight;
    }
    cvr.style.width = winW + "px";
    cvr.style.height = winH + "px";
}

function hideCover() {
    var cvr = document.getElementById("cover");
    cvr.style.display = "none";

}
function showDialog(dialogID) {
    // Show the dialog in question
    var dlg = document.getElementById(dialogID);
    dlg.style.display = "block";
    dlg.style.visibility = "visible";

    // Show the background cover    
    showCover(dlg.clientHeight);

    /*****Start special case section*****/
    if (dialogID == "dialogshiptonew") hideDropDownsOnAddShipToAddress(); // Need to hide drop downs when adding new ship to accounts
    /*****End special case section*****/

    // Position the dialog right in regards of parent container i.e. Content DIV
    // We cant do this before the dialog is shown as offsetWidth would be 0  (there might be another width property)
    var contentDIV = document.getElementById("content");
    var widthOfContentDIV = contentDIV.offsetWidth;
    var sizeOfDialogToShow = dlg.offsetWidth;
    var calculatedLeftMargin = ((widthOfContentDIV - sizeOfDialogToShow) / 2);
    dlg.style.left = calculatedLeftMargin + "px";
}

function closeDialog(dialogID) {
    var dlg = document.getElementById(dialogID)
    
    // It's important to use visibility:hidden instead of display:none !! Otherwise the audiogram dialog won't work after that.    
    dlg.style.visibility = "hidden";

    /*****Start special case section*****/
    if (dialogID == "dialogshiptonew") showDropDownsOnAddShipToAddress();
    /*****End special case section*****/

    hideCover();

}
function showDropDownsOnAddShipToAddress() {
    var shipTo = document.getElementById("accountshiptodropdownContainer");
    var billTo = document.getElementById("accountbilltodropdownContainer");
    if (shipTo != null) {
        shipTo.style.visibility = "visible";
    }
    if (billTo != null) {
        billTo.style.visibility = "visible";
    }
}
function hideDropDownsOnAddShipToAddress() {
    var shipTo = document.getElementById("accountshiptodropdownContainer");
    var billTo = document.getElementById("accountbilltodropdownContainer");
    if (shipTo != null) {
        shipTo.style.visibility = "hidden";
    }
    if (billTo != null) {
        billTo.style.visibility = "hidden";
    }
}

function printOrder(orderId) {
    if (orderId == 0)
        window.open('OrderWriter.aspx?type=customerService&print=true', 'Print',
                'height=700, width=750, location=no, menubar=0, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no');
    else
        window.open('OrderWriter.aspx?type=customerService&print=true&orderId=' + orderId, 'Print',
                'height=700, width=750, location=no, menubar=0, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no');
}

function checkDelete(alertText) {
    var agree = confirm(alertText);

    if (agree)
        return true;
    else
        return false;
}

//function linkAction(action)
//{
//    document.getElementById("actionField").value = action;
//    document.forms[0].submit();            
//}

//function confirmOrder()
//{
//    location = "OrderComplete.aspx" + location.search;
//}

//function standardToolTip_findPosX(obj) 
//{
//  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 standardToolTip_findPosY(obj) 
//{
//    var curtop = 0;
//    if (obj.offsetParent) 
//    {
//        while (obj.offsetParent) 
//        {
//            curtop += obj.offsetTop
//            obj = obj.offsetParent;
//        }
//    }
//    else if (obj.y)
//        curtop += obj.y;
//    return curtop;
//}

////function standardToolTip_show(tooltipId, parentId, posX, posY)
//{
//    it = document.getElementById(tooltipId);
//    
//    if ((it.style.top == '' || it.style.top == 0) 
//        && (it.style.left == '' || it.style.left == 0))
//    {
//        // need to fixate default size (MSIE problem)
//        it.style.width = it.offsetWidth + 'px';
//        it.style.height = it.offsetHeight + 'px';
//        
//        img = document.getElementById(parentId); 
//    
//        // if tooltip is too wide, shift left to be within parent 
//        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
//        if (posX < 0 ) posX = 0; 
//        
//        x = standardToolTip_findPosX(img) + posX;
//        y = standardToolTip_findPosY(img) + posY;
//        
//        
//        if(parentId == "step3infoicon")
//        {
//            it.style.top = (y - 120) + 'px';
//            it.style.left = (x - 180) + 'px';
//        }
//        else{
//            it.style.top = y + 'px';
//            it.style.left = x + 'px';
//        }
//        
//    }
//    
//    it.style.visibility = 'visible';
//}

//function standardToolTip_hide(id)
//{
//    it = document.getElementById(id); 
//    it.style.visibility = 'hidden'; 
//}

//function ordermouseover(orderitem)
//{
//    //document.getElementById(orderitem).style.background = "#f2f2f2";
//}
//function ordermouseout(orderitem)
//{
//    //document.getElementById(orderitem).style.background = "transparent";
//}

//function productmouseover(orderitem)
//{
//    document.body.style.cursor = 'Hand';
//    if( document.getElementById(orderitem + "show").style.display != "block" )
//    {
//        document.getElementById(orderitem).className = "headerBoxMouseOver";    
//    }
//    
//}
//function productmouseout(orderitem)
//{    
//    document.body.style.cursor = 'Default';
//    
//    if( document.getElementById(orderitem + "show").style.display != "block" )
//    {
//        document.getElementById(orderitem).className = "headerBox"; 
//    }
//}
//function openproductmouseclick(orderitem)
//{
//    if(  document.getElementById(orderitem + "show").style.display == "none" )
//    {
//        document.getElementById(orderitem).className = "headerBoxSelected";         
//        document.getElementById(orderitem + "show").style.display = "block";
//        
//    }
//    else
//    {   
//        document.getElementById(orderitem).className = "headerBox"; 
//        document.getElementById(orderitem + "show").style.display = "none";
//    }
//}

//Menu
//window.onload = function() 
//{
//    document.getElementById("menulinetop").style.display = "block";
//    SelectedMenuHide();
//    var strurl = window.location.href;
//    var urlparts = strurl.split("/");
//    var antalsub = urlparts.length;
//    var urlpage = urlparts[antalsub-1];
//    SelectedMenu(urlpage);
//}
//function SelectedMenu(strurlpage)
//{
//    var page = strurlpage.split(".");
//    if(page[0] == "Default" || page[0] == "" || page[0] == "default" || page[0] == null)
//    {
//        SelectedMenuShow(item);
//        MenuPageSelected("item1");
//    }
//    else{
//        var intitemstart = strurlpage.toString().indexOf("item");
//        var intitemslut = strurlpage.toString().length;
//        var item = strurlpage.toString().substring(intitemstart, intitemslut);
//        SelectedMenuShow(item);
//        MenuPageSelected(item);
//    }
//}
//function SelectedMenuShow(id)
//{
//    if(id=="item2" || id=="item3" || id=="item4" || id=="item5" || id=="item6" || id=="item7" || id=="item8")
//    {
//        var i=0;
//        document.getElementById("MenuItem2").style.background = "#696e74";
//        document.getElementById("menulinetop").style.display = "none";
//        document.getElementById("changemenuline1").setAttribute("class", "leftmenulinedivopen");
//        document.getElementById("changemenuline1").setAttribute("className", "leftmenulinedivopen");
//        for(i = 0; i<6; i++)
//        {
//            document.getElementById("MenuItem"+(3+i)).style.display = "block";
//            document.getElementById("MenuItem"+(3+i)).style.background = "#696e74";
//        }
//        document.getElementById("subleftmenu1").style.display = "block";
//    }
//    else
//    {
//        document.getElementById("subleftmenu1").style.display = "none";
//        
//        document.getElementById("changemenuline1").setAttribute("class", "leftmenulinediv");
//        document.getElementById("changemenuline1").setAttribute("className", "leftmenulinediv");
//    }
//}
//function SelectedMenuHide()
//{
//    //product order---------------------------------
//    var i=0;
//    for(i = 0; i<6; i++)
//    {
//        document.getElementById("MenuItem"+(3+i)).style.display = "none";
//    }
//    //----------------------------------------------
//}
//function MenuPageSelected(choosenpage)
//{ 
//    try
//    {
//        document.getElementById("ctl00_" + choosenpage).setAttribute("class", "selected");
//        document.getElementById("ctl00_" + choosenpage).setAttribute("className", "selected");
//        
//        document.getElementById("Menu" + choosenpage).getElementsByTagName("img")[0].src = "images/byAdapt/leftmenuarrowblue.gif";
//    }
//    catch(err)
//    {
//     var fejl = 0;
//    }
//}
 

