function grabobj(objname) // v1.0
{
	return $(objname);
}

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))
	{
		$('menu_'+i).onmouseover=function(){ displayMenu(this);}
		$('menu_'+i).onmouseout=function(){ hideMenu(this);}
		i++;
	}
	i=1;
	while ($('menu_'+i+'_content'))
	{
		$('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='106px';
	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='#BBBBBB';
	hideSelects('hidden');

}


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++;
	}
	hideSelects('visible');

}
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/opt3/medium/','/products/medium/');
	  obj.src=obj.src.replace('/products/opt2/medium/','/products/medium/');
	 } else {

	  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:400px;\">";
	html+="<iframe src=\"/csp/mirror/readeroffers2/view.csp?id="+ref+"\" style=\"width:400px;height:430px;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 hideSelects(action) {
if (action!='visible'){action='hidden';}
if (navigator.appName.indexOf("MSIE")) {
for (var S = 0; S < document.forms.length; S++){
for (var R = 0; R < document.forms[S].length; R++) {
if (document.forms[S].elements[R].options) {
document.forms[S].elements[R].style.visibility = action;
}
}
}
}
}


function retrieveCmd (cmd)
{
	var xmlHttpReq;
	try { xmlHttpReq=new XMLHttpRequest(); } catch (e) {
		try { xmlHttpReq=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
			try { xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
	}	}	}
	var url='/csp/mirror/readeroffers2/ajaxCmd.csp';

	xmlHttpReq.open('POST', url, true);
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {

		if (xmlHttpReq.responseText)
		{	
	
		try
		  {
			eval(xmlHttpReq.responseText);
		  }
		catch(err)
		  {
		  }
		}
	}
	}
	xmlHttpReq.send(cmd);
}