/* Open a new window */
function help_popup(desktopURL, alternateWidth, alternateHeight, noScrollbars)
{
	if ((alternateWidth && self.screen.availWidth * 0.8 < alternateWidth) || (alternateHeight && self.screen.availHeight * 0.8 < alternateHeight))
	{
		noScrollbars = false;
		alternateWidth = Math.min(alternateWidth, self.screen.availWidth * 0.8);
		alternateHeight = Math.min(alternateHeight, self.screen.availHeight * 0.8);
	}
	else
		noScrollbars = typeof(noScrollbars) != "undefined" && noScrollbars == true;

	window.open(desktopURL, 'requested_popup', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=' + (alternateWidth ? alternateWidth : 520) + ',height=' + (alternateHeight ? alternateHeight : 300) + ',resizable=yes');

	// Return false so the click won't follow the link ;).
	return false;
}

/* The following 4 functions are for the rollover buttons (mainly just the submit button in forms)  */

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];}
}

/* End of rollover functions */

/* The following functions are responsible for the pirce change on product weight change */

function selInit()
{
  var i = 1, s = document.getElementById('weight' + i);
  while (s) {
    s.weightSelNum = i;
    s.onchange = selOnChange;
    s = document.getElementById('weight' + (++i));
  }
}
function selOnChange()
{
  var e, p, s = this.options[this.selectedIndex].text;
  p = s.match(/\(\$(\d*\.?\d+)\)/);
  if (p) {
    e = document.getElementById('price' + this.weightSelNum);
    if (e) {
      p = '$' + p[1];
      if (e.firstChild && e.firstChild.nodeType == '3') { e.firstChild.nodeValue = p; }
      else { e.innerHTML = p;}
    }
  }
  else {alert('Invalid price in select: ' + this.id);}
}

/* ------------------------------------- */

function confirmSubmit(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}

/* Hide element */
function hide_element(obj){
	document.getElementById(obj).style.display='none';
}

/* Show element */
function show_element(obj){
	document.getElementById(obj).style.display='';
}

/* Hide or unhide form selection and change what's currently selected */
function show_hide_form_selection(object, change_selected, change_state){
	// If the object is hidden
	if(change_state == 'show'){
		document.getElementById(object).style.display=''; 
		if(hidden_item_selected == 'yes'){
			hidden_item_selected = '';
			document.getElementById(object).selected='selected';
		}
	}else if(change_state == 'hide'){
		document.getElementById(object).style.display='none'; 
		if(document.getElementById(object).selected){
			hidden_item_selected = 'yes';
			document.getElementById(change_selected).selected='selected';
		}
	}
}

/* ------------------------------------- */

var areAllChecked = false;
 
function toggleAllCheckBoxes()
{
   var objs = document.getElementsByName('remove[]');
 
   areAllChecked = ! areAllChecked;
 
   for(var i = 0; i < objs.length; i++)
   {
      objs[i].checked = areAllChecked;
   }
}