﻿var pfx = "ctl00_cphMain_";
var pfx_master = "ctl00_";

//	GET ELEMENT BY ID
//----------------------------------------------------------------
//		This custom method allows us to perform
//		tasks to ensure we get the element we are requesting
function _getElementById(sID)
{
    var obj = document.getElementById(sID);
    return(obj);
}

//	GET ELEMENTS BY CLASS NAME
//----------------------------------------------------------------
//		http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
//		This function gets an array of elements via their style sheet class name
// getElementsByClassName(document, "a", "info-links"); 
function getElementsByClassName(oElm, strTagName, strClassName){
    try {
        var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
        var arrReturnElements = new Array();
        strClassName = strClassName.replace(/\-/g, "\\-");
        var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
        var oElement;
        for(var i=0; i<arrElements.length; i++){
            oElement = arrElements[i];      
            if(oRegExp.test(oElement.className)){
                arrReturnElements.push(oElement);
            }   
        }
        return (arrReturnElements)
    } catch (err) {
        alert("getElementsByClassName",err.description);
        return;
    }
}
//----------------------------------------------------------------
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
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 posRight() 
{
    return posLeft() + pageWidth();
} 

function posBottom() 
{
    return posTop() + pageHeight();
}

function findPosY(obj)
{
    var curtop = 0;
    
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    
    return curtop;
}

function hideBusy()
{
    document.getElementById("busy").className="busy_hid";
    return;
}

function showBusy()
{
    var obj = document.getElementById("busy");
    //alert(obj);
    obj.className = "busy";
    return;
}

function positionBusy(divID)
{
    var obj = document.getElementById(divID);
    if (obj == null) return false;
    var curTop = 0;
    var curHeight = 0;
    var curWidth = 0;
    var curLeft = 0;
    
    // reposition the processing box
    obj.style.display = "";
    
    curHeight = pageHeight();
    curTop = (curHeight/2);
    curTop = (curTop-250);
    curTop = curTop + posTop();
    obj.style.top = curTop + "px";

    curWidth = pageWidth();
    curLeft = (curWidth/2);
    curLeft = (curLeft-180);
    curLeft = curLeft + posLeft();
    
    obj.style.left = curLeft + "px";
    obj.style.top = curTop + "px";
    
    //alert("left: "+curLeft);
}

function clearInput(e){ 
e.value=""; 
} 

function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

var exeEnterKey = function(idIn) {
    if (window.event && window.event.keyCode == 13) {
        //alert(idIn);
        __doPostBack(idIn,'OnClick');
    }
    return;
}

var popProcessing = function ()
{
    positionBusy("divProgressWrapper");

    //if (document.getElementById("divProgressWrapper") != null && document.getElementById("divProgressWrapper").children != null) document.getElementById("divProgressWrapper").firstChild.style.display = "";
    getElementsByClassName(document, "div", "pnlProcessing")[0].style.display = "";
    return;
}


// element manipulation
var hideElement = function(el)
{
    el.style.display = "none";
}
var showElement = function(el)
{
    el.style.display = "";
}

// popup the item details window
var popDetails = function(productNumber)
{
    var prod = "";
    prod = productNumber + "";
    prod = prod.replace(/-/g, "");
    prod = prod.replace(/\//g, "");
    prod = prod.replace(/%20/g, "");
    window.open("ItemDetail.aspx?item=" + productNumber + "#home", prod, "status=1,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=800");
}
var popEquivalents = function(productNumber, commandType)
{
    var prod = "";
    prod = productNumber + "";
    window.open("ItemDetail.aspx?cmd=" + commandType + "&item=" + prod + "#home", prod.replace(" ","").replace("-",""), "status=1,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=800");
}

// toggle item detail
var toggleDetails = function()
{
    var pfx = "ctl00_cphMain_";
    var tb = document.getElementById(pfx + "divDetails");
    var lbl = document.getElementById(pfx + "lnkToggleDetails");
    var img = document.getElementById("imgExpand");
    
    if (tb.style.display != "none")
    {
        tb.style.display = "none";
        lbl.innerHTML = "Show item details";
        img.src = "Images/Icons/expand.gif";
    }
    else
    {
        tb.style.display = "";
        lbl.innerHTML = "Hide item details";
        img.src = "Images/Icons/collapse.gif";
    }
}
