function iw_open_window(link, window_name, width, height, resizable) {
    caller = window.open(link, window_name,'toolbar=no,location=no,status=no,menubar=0,scrollbars=no,resizable='+resizable+',height='+height+',width='+width+',top='+(screen.height-height)/2+',left='+(screen.width-width)/2+',copyhistory=no');
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i>a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Search Box Selection
function searchBox(checkbox){
    var form=document.forms.search_form;
    var searchproducts=false;
    var searchtools=false;
    var searchcorpsupport=false;
    
    if (form.searchproducts!==undefined) {
        searchproducts=true;
    }
    if (form.searchtools!==undefined) {
        searchtools=true;
    }
    if (form.searchcorpsupport!==undefined) {
        searchcorpsupport=true;
    }

    if (checkbox=="default") {
        if (
            (!searchproducts || (searchproducts && form.searchproducts.checked==false)) && 
            (!searchtools || (searchtools && form.searchtools.checked==false)) &&
            (!searchcorpsupport || (searchcorpsupport && form.searchcorpsupport.checked==false))
        ) {
            if (searchproducts) {
                searchBox('searchproducts');
            } else if (searchtools) {
                searchBox('searchtools');
            } else if (searchcorpsupport) {
                searchBox('searchcorpsupport');
            }
        }
    }
    if(checkbox=="searchproducts"){
        if (searchproducts) {
            form.searchproducts.checked=true;
        }
        if (searchtools) {
            form.searchtools.checked=false;
        }
        if (searchcorpsupport) {
            form.searchcorpsupport.checked=false;
        }
        form.action = bpath_site_root + '/search/results_products.php';
    }
    if(checkbox=="searchtools"){
        if (searchproducts) {
            form.searchproducts.checked=false;
        }
        if (searchtools) {
            form.searchtools.checked=true;
        }
        if (searchcorpsupport) {
            form.searchcorpsupport.checked=false;
        }
        form.action = bpath_site_root + '/search/results_tools.php';
    }
    if(checkbox=="searchcorpsupport"){
        if (searchproducts) {
            form.searchproducts.checked=false;
        }
        if (searchtools) {
            form.searchtools.checked=false;
        }
        if (searchcorpsupport) {
            form.searchcorpsupport.checked=true;
        }
        form.action = bpath_site_root + '/search/results_corporate.php';
    }
}


//Power Search Page Selection
function searchPowerPage(checkbox){
    if(checkbox=="productsAll"){
        document.forms.products_search_powerform.productsAll.checked=true;
        document.forms.products_search_powerform.productsPrintprod.checked=false;
        document.forms.products_search_powerform.productsGrapharts.checked=false;
        document.forms.products_search_powerform.productsPackaging.checked=false;
        document.forms.products_search_powerform.productsFacsup.checked=false;
    }
    if(checkbox=="productsPrintprod" || checkbox=="productsGrapharts" || checkbox=="productsPackaging" || checkbox=="productsFacsup"){
        document.forms.products_search_powerform.productsAll.checked=false;
    }

    if(checkbox=="toolsAll"){
        document.forms.tools_search_powerform.toolsAll.checked=true;
        document.forms.tools_search_powerform.toolsProMatRef.checked=false;
        document.forms.tools_search_powerform.toolsMatSafDataS.checked=false;
        document.forms.tools_search_powerform.toolsCalc.checked=false;
        document.forms.tools_search_powerform.toolsGloss.checked=false;
        document.forms.tools_search_powerform.toolsForms.checked=false;
        document.forms.tools_search_powerform.toolsManuLinks.checked=false;
    }
    if(checkbox=="toolsProMatRef" || checkbox=="toolsMatSafDataS" || checkbox=="toolsCalc" || checkbox=="toolsGloss"|| checkbox=="toolsForms"|| checkbox=="toolsManuLinks"){
        document.forms.tools_search_powerform.toolsAll.checked=false;
    }

    if(checkbox=="corpSupAll"){
        document.forms.corp_search_powerform.corpSupAll.checked=true;
        document.forms.corp_search_powerform.corpSupFAQ.checked=false;
        document.forms.corp_search_powerform.corpSupNews.checked=false;
        document.forms.corp_search_powerform.corpSupCareers.checked=false;
    }
    if(checkbox=="corpSupFAQ" || checkbox=="corpSupNews" || checkbox=="corpSupCareers"){
        document.forms.corp_search_powerform.corpSupAll.checked=false;
    }

}


/**
 * This code block will let us submit forms when the user hits Enter.
 * Just add an onKeyPress="checkEnter(this, event) handler to the form to use it.
 */
NS4 = (document.layers) ? true : false;

function checkEnter(form, event)
{   
    var code = 0;
    
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    if (code==13)
        return true;
    else
        return false;
}

// validate language checkboxes (must be at least one checked)

function check_lang(which, section)
{
    if (!which.checked) {
        if (which.name == section +'_searchEnglish') {
            otherWhich = document.getElementById(section +'_searchFrench');
        } else if (which.name == section +'_searchFrench') {
            otherWhich = document.getElementById(section +'_searchEnglish');
        }

        if (!otherWhich.checked) {
            which.checked = true;
        }
    }
}
function getRealLeft(imgElem) {
    xPos = eval(imgElem).offsetLeft;
    tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}
function getRealTop(imgElem) {
    yPos = eval(imgElem).offsetTop;
    tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

var includedMsgs = false;

function IsNumeric(strString) {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

// Centers a layer in the browser window
function centerAlign(div) {
    if (typeof div=='string') {
        var top; var left; var w; var h;
        if (window.pageXOffset) {   // Netscape
            top  = window.pageYOffset;
            left = window.pageXOffset;
        } else {
            top  = document.body.scrollTop; 
            left = document.body.scrollLeft;
        }

        if (window.innerWidth) {    // Netscape
            w = window.innerWidth;
            h = window.innerHeight;
        } else {
            w = document.body.offsetWidth;
            h = document.body.offsetHeight;
        }
        var div = document.getElementById(div);
        div.style.left=(w-div.offsetWidth)/2;
        div.style.top=(h-div.offsetHeight)/2;
    }
}


function centerAlign2(div) {
    if (typeof div=='string') {
        var top; var left; var w; var h;
        if (window.pageXOffset) {   // Netscape
            top  = window.pageYOffset;
            left = window.pageXOffset;
        } else {
            top  = document.body.scrollTop; 
            left = document.body.scrollLeft;
        }

        if (window.innerWidth) {    // Netscape
            w = window.innerWidth;
            h = window.innerHeight;
        } else {
            w = document.body.offsetWidth;
            h = document.body.offsetHeight;
        }
        
        var div = document.getElementById(div);
        
        div.style.left = left + (w-parseInt(div.style.width))/2;
        div.style.top = top + (h-parseInt(div.style.height))/2;
    }
}

function focus_QuickAdd()
{
    if (!location.hash) {
        location.hash='quickadd_row';
    }
    if (document.getElementById && document.getElementById('quick_pid')) {
        setTimeout('document.getElementById("quick_pid").focus()', 300);
    }
}

/**
 * Anchors the user's browser window to the specified field.
 *
 * @param name the name of the field to which the user will be
 *			   redirected. 
 */
function reanchor(name) {
	window.location.hash = name;
}

function ProjectPopup(URL) {
    window.open(URL, 'project', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=680,height=520');
}

function SetProductSearchType(type) {
    if (parent.parent.document.images['nav_'+type+'_off']) {
        parent.parent.SetVar('nav_'+ type + '_');
        parent.parent.document.images['nav_'+type+'_off'].src= bpath_media_lang_root + "/nav_"  + type + '_on.gif';
    }
}

