function grabobj(objname) // v1.0
{
	return $(objname);
}
function inputFocus(obj,defText)
{
	if (obj.value==defText) {
		obj.value="";
	}
}
function inputBlur(obj,defText)
{
	if (obj.value=="") {
		obj.value=defText;
	}
}
function $(objname)
{
	if (document.getElementById) return document.getElementById(objname);
	if (document.all) return document.all[objname];
	if (document.layers) return document.layers[objname];
}
function menuInit ()
{
	var i=1;
	while ($('menu_'+i))
	{
		alert('menuInit - whileMenu:'+i);
		$('menu_'+i).onmouseover=function(){ displayMenu(this);}
		$('menu_'+i).onmouseout=function(){ hideMenu(this);}
		i++;
	}
	i=1;
	while ($('menu_'+i+'_content'))
	{
		alert('menuInit - whileContent:'+i);
		$('menu_'+i+'_content').onmouseover=function(){ clearMenuTimer(); }
		$('menu_'+i+'_content').onmouseout=function(){ menuTimer=window.setTimeout("closeMenus()",300);  }
		i++;
	}


}
function displayMenu (obj)
{
	clearTimeout(menuTimer);
	var i=1;
	while ($('menu_'+i+'_content'))
	{
		$('menu_'+i).style.background='';
		$('menu_'+i+'_content').style.display='none';
		i++;
	}
	var id=obj.id.split('_')[1];
	$('menu_'+id+'_content').style.display='block';
	$('menu_'+id+'_content').style.top='157px';



	var popupWidth=$('menu_'+id+'_content').offsetWidth;
	var tabWidth=$('menu_'+id).offsetWidth;




	if ((findPos(obj)[0]+popupWidth)>1000)
	{
	 	var newLeft=(findPos(obj)[0]-findPos($('wrapper'))[0])-popupWidth+tabWidth;
		if (newLeft>0)
		{
			$('menu_'+id+'_content').style.left=newLeft+'px';
		} else {
			var bWidth=(findPos($('wrapper'))[0]*2)+1000;
			
			$('menu_'+id+'_content').style.left=((bWidth/2)-(popupWidth/2)-findPos($('wrapper'))[0])+'px';
		}
	} else {
		$('menu_'+id+'_content').style.left=(findPos(obj)[0]-findPos($('wrapper'))[0])+'px';
	}

	$('menu_'+id).style.background='#000000';

}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
var menuTimer;
function hideMenu (id)
{
	menuTimer=window.setTimeout("closeMenus()",300);
}
function closeMenus ()
{
	var i=1;
	while ($('menu_'+i+'_content'))
	{
		$('menu_'+i).style.background='';
		$('menu_'+i+'_content').style.display='none';
		i++;
	}

}
function clearMenuTimer ()
{
	clearTimeout(menuTimer);
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
function prodImageSwap (opt,obj)
{
  if (obj)
  {
	obj=grabobj(obj);
	if (obj)
	{
	
	 if (opt==1)
	 {
	  obj.src=obj.src.replace('/products/opt5/medium/','/products/medium/');
	  obj.src=obj.src.replace('/products/opt4/medium/','/products/medium/');
	  obj.src=obj.src.replace('/products/opt3/medium/','/products/medium/');
	  obj.src=obj.src.replace('/products/opt2/medium/','/products/medium/');
	 } else {

	  obj.src=obj.src.replace('/products/opt5/medium/','/products/opt'+opt+'/medium/');
	  obj.src=obj.src.replace('/products/opt4/medium/','/products/opt'+opt+'/medium/');
	  obj.src=obj.src.replace('/products/opt3/medium/','/products/opt'+opt+'/medium/');
	  obj.src=obj.src.replace('/products/opt2/medium/','/products/opt'+opt+'/medium/');
	  obj.src=obj.src.replace('/products/medium/','/products/opt'+opt+'/medium/');
	 }
	}

  }
}

function viewLarge(ref,opt)
{
	html="<div style=\"width:406px;\">";
	html+="<iframe src=\"/csp/aw/site/view.csp?id="+ref+"\" style=\"width:404px;height:424px;border:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";

	html+="<div align=\"center\"><input type=\"button\" style=\"font-weight:bold;font-size:13px;\" onclick=\"clearItem('bigimg');\" value=\"Close Viewport\"></div>";
	html+="</div>";
	displayBox('bigimg',html);
}

function viewLargeCustImages(ref,opt)
{
	html="<div style=\"width:406px;\">";
	html+="<iframe src=\"/csp/aw/site/viewCustImages.csp?id="+ref+"\" style=\"width:404px;height:424px;border:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";

	html+="<div align=\"center\"><input type=\"button\" style=\"font-weight:bold;font-size:13px;\" onclick=\"clearItem('bigimg');\" value=\"Close Viewport\"></div>";
	html+="</div>";
	displayBox('bigimg',html);
}

function viewPackaging(ref)
{
	html="<div style=\"width:800px;\">";
	html+="<iframe src=\"/csp/ar/site/packaging.csp?id="+ref+"\" style=\"width:800px;height:300px;border:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";

	html+="<div align=\"center\"><input type=\"button\" style=\"font-weight:bold;font-size:13px;margin-top:10px;\" onclick=\"clearItem('bigimg');\" value=\"Close Viewport\"></div>";
	html+="</div>";
	displayBox('bigimg',html);
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function getElementsByClass(node,searchClass,tag) {
  var classElements = new Array();
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}