function $(objname)
{
if (document.getElementById) return document.getElementById(objname);if (document.all) return document.all[objname];if (document.layers) return document.layers[objname];
}
function refineSearch (fieldname,val)
{
		$(fieldname).value=val;
		$('refinesearch').submit();
}
function priceRange (lo,hi)
{
		$('plo').value=lo;
		$('phi').value=hi;
		$('refinesearch').submit();
}
function setType (val)
{
		$('type').value=val;
		$('refinesearch').submit();
}
function setGender (val)
{
		$('gender').value=val;
		$('refinesearch').submit();
}
function setStyle (val)
{
		$('style').value=val;
		$('refinesearch').submit();
}
function setOtherStyle (val)
{
		$('otherstyle').value=val;
		$('refinesearch').submit();
}
function setBridge (val)
{
		$('bridge').value=val;
		$('refinesearch').submit();
}
function setEyesize (val)
{
		$('eyesize').value=val;
		$('refinesearch').submit();
}
function setNColour (val)
{
		$('ncolour').value=val;
		$('refinesearch').submit();
}
function setUBColour (val)
{
		$('ubcolour').value=val;
		$('refinesearch').submit();
}
function setMaterial (val)
{
		$('material').value=val;
		$('refinesearch').submit();
}
function setSideMaterial (val)
{
		$('sidematerial').value=val;
		$('refinesearch').submit();
}
var currentImage;
function swapProdImage (id,name)
{
	if (!currentImage) currentImage=$(id).src;
	$(id).src='/csp/glass/wantg/products/450x200/'+name;
}
function swapOutProdImage (id)
{
	$(id).src=currentImage;
}
function setProdImage (id)
{
	currentImage=$(id).src;
}



function setColName (val)
{
	$('colname').innerHTML=val;
}
function setColour (val)
{
	var i=0;
	while ($('coldropdown').options[i])
	{
		if ($('coldropdown').options[i].value==val)
		{
			$('coldropdown').selectedIndex=i;
		}
		i++;
	}

}
function chkPrice ()
{
	var validsize=0;
	if ($('sizeopt').tagName=="INPUT")
	{
		validsize=$('sizeopt').value;
	} else {
		if ($('sizeopt').selectedIndex>0) validsize=$('sizeopt').options[$('sizeopt').selectedIndex].value;
	}
	
	var validcolour=$('coldropdown').options[$('coldropdown').selectedIndex].value;
	if (validcolour>0&validsize>0)
	{
		$('ourprice').innerHTML='Price ';		
		$('totalprice').innerHTML='Price ';		
		$('pricedisplay').innerHTML="&pound;"+pricearray[validcolour][validsize];		
		$('pricedisplay2').innerHTML="&pound;"+pricearray[validcolour][validsize];
		currentImage='/csp/glass/wantg/products/450x200/'+imagearray[validcolour].split("~")[0];
		if (imagearray[validcolour].split("~")[1]>0)
		{
				$('viewLarge').style.display	=	'block';
		} else {
				$('viewLarge').style.display	=	'none';
		}
		$('productimage').src=currentImage;
	} else {
		$('ourprice').innerHTML='Our Price ';		
		$('totalprice').innerHTML='Total Price ';		
		$('pricedisplay').innerHTML=defaultprice;		
		$('pricedisplay2').innerHTML=defaultprice;		
	}
}









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);  }
		if($('menu_'+i+'_content').innerHTML=="") {$('menu_'+i+'_content').style.border = "none";}
		i++;
	}
}
function displayMenu(obj)
{	
	clearTimeout(menuTimer);
	var i=1;
	while ($('menu_'+i+'_content'))
	{
		$('menu_'+i+'_content').style.display='none';
		removeElementByID('iFrameBack');
		i++;
	}
	var id=obj.id.split('_')[1];
	$('menu_'+id+'_content').style.display='block';
	$('menu_'+id+'_content').style.top='133px';



	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';
	}
	makeIFrame($('menu_'+id+'_content').offsetTop, $('menu_'+id+'_content').offsetLeft, $('menu_'+id+'_content').offsetHeight, $('menu_'+id+'_content').offsetWidth)
}
function makeIFrame(top, left, height, width)
{
//	return false;
//	alert(top+" - "+left+" - "+height+" - "+width)
/*	Don't forget you need css for this as well
		position absolute;
		border: none;
		z-index: 100;	//	This needs to be above the document(select boxes) but below what it is you are showing
*/
	iFrameBack	=	document.createElement('iframe');
	iFrameBack.id	=	'iFrameBack';
	iFrameBack.style.top	=	top+'px';
	iFrameBack.style.left	=	left+'px';
	iFrameBack.style.height	=	height+'px';
	iFrameBack.style.width	=	width+'px';
	try
	{
		$('header').appendChild(iFrameBack);
	}
	catch(e){}
}

var menuTimer;
function hideMenu (id)
{
	menuTimer=window.setTimeout("closeMenus()",300);
}
function closeMenus ()
{
	var i=1;
	while ($('menu_'+i+'_content'))
	{
		$('menu_'+i+'_content').style.display='none';
		i++;
	}
	removeElementByID('iFrameBack');
}

function removeElementByID(ID)
{
//	document.body.setAttribute('onmousedown','');
	Obj=ID
	if(typeof ID== 'string') Obj=document.getElementById(ID);
	if(Obj && Obj.parentNode)Obj.parentNode.removeChild(Obj);
	if(document.getElementById(ID)) {removeElementByID(ID);}
	return
}


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 lgImgAvail(status)
{
	//	value of if large image is available, whether to display view large
	if (status)
	{
		$('viewLarge').style.display	=	'block';
	} else {
		$('viewLarge').style.display	=	'none';
	}
}
var box;
function viewLarge()
{
	var imgname=$('productimage').src.split('450x200/')[1];
	var html='';
	html+='<div style="width:700px;text-align:center;"><img src="/csp/glass/wantg/products/large/'+imgname+'"></div><br /><br />';	
	html+='<br /><div align="center"><a href="javascript:void(0);" onclick="clearItem(\'img\');HideShowSelects(\'\');"><img src="/csp/glass/wantg/images/close.gif" border=0 /></a></div>';
	box=displayBox("img",html);
	updateBoxWidth();
	HideShowSelects('hide');
}
function HideShowSelects(state)
{
	tags	=	document.getElementsByTagName('select');

	for(var i=0; i < tags.length; i++)
	{
		if(state == 'hide')
		{
			tags[i].style.display	=	'none';
		}
		else
		{
			tags[i].style.display	=	'';
		}
	}
	return true
}
function viewImg(ref,img)
{

}

function bookmarkPage()
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, window.location,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( window.location, document.title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}
function removeRow(STNO)
{
	$(STNO).value	=	0;
	$('formv').submit();
}
function formPageErr(err)
{
	eval(err);
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function moreInfo(page)
{
	displayBox('moreInfo','<iframe id="ajaxIFrame" frameborder="0" src="/ajaxmsg/?msg='+page.toLowerCase()+'"></iframe>');
	box=$("box_moreInfo");
	t=setTimeout("updateBoxWidth()",200);;
}

function recieptTrack(names,values)
{
	// names and values can be passed in as a comma seperated string for each
//	names	=	names.replace(/\s/g, "");
//	values	=	values.replace(/\s/g, "");
	var name	=	new Array();
	var value	=	new Array();
	name	=	names.split(",");
	value	=	values.split(",");
	queryString	=	$("iReciept").src.substring($("iReciept").src.indexOf('?')+1, $("iReciept").src.length);
	queryString	=	"PNO="+queryString.split("PNO=")[1];
	i=0
	while(name[i] && value[i])
	{
		queryString	=	name[i]+"="+value[i]+"&"+queryString;
		if(name[i]=='clear'&&value[i]=='tint')
		{
			setTimeout("recieptTrack('clear','Photochromic')",500)
		}
		i++;
	}
	$("iReciept").src	=	baseurl+"ireciept.csp?"+queryString;
	return
}
function recieptPos() {
	if(window.pageYOffset) {
		ScrollTop = window.pageYOffset;
	} else {
		ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	if(ScrollTop>181) {
		$('iReciept').style.top	=	ScrollTop-181+'px';
//		alert(window.pageYOffset);
	}
	if(ScrollTop<=181) {
		$('iReciept').style.top	=	'0px';
	}
	if (parseFloat($('iReciept').style.top)>893) {
		$('iReciept').style.top = '893px';
	}
	return
}
function clearMsg(obj,id)
{
	if ($(id))
	{
		if (obj.value!='')
		{
			$(id).style.display	=	'none';
		} else {
			$(id).style.display	=	'';
		}
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
var expandTimer;
var expandPX	=	8;
var expandDelay	=	20;
function expandDetails(moreLink) {
	moreLink.style.display='none';
	$('expandable').style.marginBottom	=	'20px';
	expandTimer = window.setTimeout("expandDetailsRepeat()",expandDelay);
}
function expandDetailsRepeat() {
	clearTimeout(expandTimer);
	if (($('expandable').offsetHeight+expandPX)>$('checkHeight').offsetHeight) {
		$('expandable').style.height=$('checkHeight').offsetHeight+'px';
	} else {
		$('expandable').style.height	=	(parseFloat($('expandable').offsetHeight)+expandPX)+'px';
		expandTimer = window.setTimeout("expandDetailsRepeat()",expandDelay);
	}
}
