//Global Variables
var winW = 300;
var winY = 300;

/*********************************
*  Makes Div cols equal height ***
*********************************/
//function for two columns
function fixH(one,two) {
	if (document.getElementById(one)) {
		var lh=document.getElementById(one).offsetHeight;
		var rh=document.getElementById(two).offsetHeight;
		var nh = Math.max(lh, rh); 
		document.getElementById(one).style.height=nh+"px";
		document.getElementById(two).style.height=nh+"px";
	}
}

//function for three columns (sortNum and fixH2)
function sortNum(a,b) { return b-a} 

function fixH2(one,two,three) {
	if (document.getElementById(one)) {
		var obj=new Array(3);
		var option=[one,two,three];
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height="auto";
			obj[i]=document.getElementById(option[i]).offsetHeight;
			nh=obj.sort(sortNum);
		} 
		nh1=nh.splice(1,2);
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height=nh+"px";
		}
	}
}

//Executes fixH2 function on document load.  fixH is fired in the body html tag when specified.
//This prevents conflicts between the two functions.
window.onload=function(){
	fixH2('left_nav','main','right');
}



function getScreenSize()
{
	if(window.innerWidth)
		winW = window.innerWidth;
	else if(document.body)
	{
		if(document.body.offsetWidth)
			winW = document.body.offsetWidth;
	}
	if(window.innerHeight)
		winY = window.innerHeight;
	else if(document.body)
	{
		if(document.body.offsetHeight)
			winY = document.body.offsetHeight;
	}

	if(winW < 300)
		winW = 300;
	else
		winW = winW - 50;
	
	if(winW > 1000)
		winW = 1000;

	if(winY < 300)
		winY = 300;
	else
		winY = winY - 30;
}


// Pop-up for UN Packaging category descriptions
function CategoryInfo(arg1)
{
	window.open('../category_popup.htm?type=' + arg1, 'catwin1', 'location=no,menubar=no,toolbar=no,scrollbars=yes,resizable,width=475,height=425,left=50,top=50');
}

function PDFOpen(auto_num, category)
{
	getScreenSize();
	window.open('../view_pdf.htm?id=' + auto_num + '&cat=' + category, 'pdfwin1', 'location=no,menubar=yes,toolbar=no,scrollbars=both,resizable,width=' + winW + ',height=' + winY + ',left=20,top=20');
}

// Product Detail Page Order Now Popup Javascript
/**  Click order now button, triggers popup.  Click on popup, closes popup **/
function toggle_visibility(id) {
   e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}

/** Closes popup when clicked outside of the popup **/
document.onclick=check; 

function check(e){ 
	var productElement = document.getElementById('popup_div');
	if (productElement != null)
	{
		var target = (e && e.target) || (event && event.srcElement); 
		var obj = document.getElementById('popup_div'); 
		var obj2 = document.getElementById('order_button'); 
		checkParent(target)?obj.style.display='none':null; 
		target==obj2?obj.style.display='block':null; 
	}
} 

function checkParent(t){ 
	while(t.parentNode){ 
	if(t==document.getElementById('popup_div')){ 
	return false 
	} 
	t=t.parentNode 
	} 
	return true 
} 

