function changePage(newLoc) {
	nextPage = newLoc.options[newLoc.selectedIndex].value
	if (nextPage != "") {
		document.location.href = nextPage
	}
}

function confirmDelete(delUrl) {
	if (confirm("Are you sure you want to delete")) {
		document.location.href = delUrl;
	}
}

function showdiv(name,focus){ 
var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	if (obj.style.display=="none"){ 
		obj.style.display=""; 
	}else{
		obj.style.display="none"; 
	} 
}

function categoryDropShowHide(setId){
    if(document.getElementById('dv'+setId).style.display == 'none')
    {
	document.getElementById('ind'+setId).innerHTML = '[-]';	
	document.getElementById('dv'+setId).style.display = 'block';
    }
    else
    {
	document.getElementById('ind'+setId).innerHTML = '[+]';	
	document.getElementById('dv'+setId).style.display = 'none';
    }
}

function toggleLayer(id)
{
	if($(id).style.display == 'block') $(id).style.display = 'none';
	else $(id).style.display = 'block';
}

function displayRecord(id){
	if(document.getElementById('AL'+id).style.display == 'none')
	{
		document.getElementById('AL'+id).style.display = '';
		document.getElementById('ALo'+id).style.display = '';
		document.getElementById('ALc'+id).style.display = 'none';
	}
	else
	{
		document.getElementById('AL'+id).style.display = 'none';
		document.getElementById('ALo'+id).style.display = 'none';
		document.getElementById('ALc'+id).style.display = '';
	}
}

function rollUpDown(whichDiv) {
	if(document.getElementById(whichDiv).style.display == "none")
		new Effect.BlindDown(document.getElementById(whichDiv));
	else
		new Effect.BlindUp(document.getElementById(whichDiv));
}

function searchShowHideCategories(whichDiv_a,whichDiv_b) {
	if(document.getElementById(whichDiv_a).style.display == "none")
	{
		new Effect.BlindDown(document.getElementById(whichDiv_a));
		new Effect.BlindUp(document.getElementById(whichDiv_b));
	}
	else
	{
		new Effect.BlindUp(document.getElementById(whichDiv_a));
		new Effect.BlindDown(document.getElementById(whichDiv_b));
	}
}


function getViewportHeight()
{
	var viewportheight;	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportheight = window.innerHeight
	 }	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
	          && typeof document.documentElement.clientWidth !=
	          'undefined' && document.documentElement.clientWidth != 0
	         )
	 {
	       viewportheight = document.documentElement.clientHeight
	 }	 
	 // older versions of IE
	 else
	 {
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	 
	 return viewportheight;
}

function getViewportWidth()
{
	var viewportwidth;
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth;
	 }	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
	          && typeof document.documentElement.clientWidth !=
	          'undefined' && document.documentElement.clientWidth != 0
	         )
	 {
	       viewportwidth = document.documentElement.clientWidth;
	 }	 
	 // older versions of IE
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	 }
	 
	 return viewportwidth;
}


function getScreenCenterY() 
{  
	var y = 0;  	  
	y = getScrollOffset()+(getInnerHeight()/2);  
	return(y);  
}  
  
function getScreenCenterX() 
{  
	return(document.body.clientWidth/2);  
}  


function getInnerHeight() 
{  
	var y;  
	if (self.innerHeight) // all except Explorer  
	{  
		y = self.innerHeight;  
	}  
	else if (document.documentElement &&  
	         document.documentElement.clientHeight
	        )
	// Explorer 6 Strict Mode  
	{  
		y = document.documentElement.clientHeight;  
	}  
	else if (document.body) // other Explorers  
	{  
		y = document.body.clientHeight;  
	}  
	return(y);  
}  
  
function getScrollOffset() 
{  
	var y;  
	if (self.pageYOffset) // all except Explorer  
	{  
		y = self.pageYOffset;  
	}  
	else if (document.documentElement &&
			 document.documentElement.scrollTop
			)
	// Explorer 6 Strict  
	{  
		y = document.documentElement.scrollTop;  
	}  
	else if (document.body) // all other Explorers  
	{  
		y = document.body.scrollTop;  
	}  
	return(y);  
}  



function clearPriceListAdjustment(gid)
{
	$('cc'+gid).value='1';
	$('aj'+gid).value='';
	$('ajd'+gid).value='';
	$('aa'+gid).value='';
	$('at'+gid).value='p';
}

function clearAllPriceListAdjustments()
{
	for (i = 0; i < document.plform.cx.length; i++)
	{
		gid = document.plform.cx[i].value;
		clearPriceListAdjustment(gid);
	}
}

function priceListAdjustment(gid)
{
	var CatalogPrice = document.getElementById('cp'+gid).value;
	var PriceType = document.getElementById('pt'+gid).value;
	var AdjustmentType = document.getElementById('at'+gid).value;
	var AdjustmentAmount = document.getElementById('aa'+gid).value;

	$('fc').value='1'; 
	
	//if(parseFloat($('aa'+gid).value) == $('aa'+gid).value )
	if(!isNaN($('aa'+gid).value))
	{		
		$('cc'+gid).value = '1';
		
		if(AdjustmentType=='d')
		{
			$('aj'+gid).value=FormatCurrency(parseFloat(CatalogPrice)+parseFloat(AdjustmentAmount));
			$('ajd'+gid).value = $('aj'+gid).value;
		}
		else if(AdjustmentType=='p')
		{
			$('aj'+gid).value=FormatCurrency(parseFloat(CatalogPrice)+(parseFloat(CatalogPrice)*(parseFloat(AdjustmentAmount)/100)));
			$('ajd'+gid).value = $('aj'+gid).value;
		}
		else
		{
			$('aj'+gid).value=FormatCurrency($('aa'+gid).value);
			$('ajd'+gid).value = $('aj'+gid).value;
		}
	}
	else
	{
		$('aa'+gid).value='';
		$('aj'+gid).value='';
		$('ajd'+gid).value = $('aj'+gid).value;
	}
	
	if($('aj'+gid).value<=0)
	{
		$('aa'+gid).value='';
		$('aj'+gid).value='';	
		$('ajd'+gid).value = $('aj'+gid).value;
	}
}

function FormatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));
		/*num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));*/
	return (((sign)?'':'-') + num + '.' + cents);
}

function checkAll(field)
{
	for (i = 0; i < field.length; i++) field[i].checked = true ;
}

function uncheckAll(field)
{
	for (i = 0; i < field.length; i++) field[i].checked = false ;
}

function bulkPriceListAdjust()
{
	$('ba').value = FormatCurrency($('ba').value);
	for (i = 0; i < document.plform.cx.length; i++)
	{
		if(document.plform.cx[i].checked == true)
		{
			gid = document.plform.cx[i].value;
			$('aa'+gid).value=$('ba').value;
			$('at'+gid).value=$('bt').value;
			priceListAdjustment(gid);
		}
	}
}

function clearListBox(lb)
{
	lbObj=$(lb);

	for(var count = lbObj.options.length - 1; count >= 0; count--)
	{
		lbObj.options[count].selected = false;
	}
}


