function popup(mylink, windowname, width, height, scroll)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	href=mylink;
	else
	href=mylink.href;
	if (scroll==1)
	window.open(href, windowname, 'scrollbars=yes,status=no,width='+width+',height='+height);
	else
	window.open(href, windowname, 'scrollbars=no,status=no,width='+width+',height='+height);
	return false;
	} 
	
	
function textCounter(fieldlength, countfield, maxlimit)
{
	if (fieldlength > maxlimit) // if too long...trim it!
	countfield.value='Too long'
	else 
	countfield.value = maxlimit - fieldlength;
}




function bUpdate()
{
	document.basket.action.value='update';
	document.basket.submit();
}
function bEmpty()
{
	document.basket.action.value='empty';
	document.basket.submit();
}
function bDelete( sID )
{
	eval( 'document.basket.qty_' + sID ).value='0';
	document.basket.action.value='update';
	document.basket.submit();
}
	
	
function changeSize(siz){

	//document.basket_submit.size.value=document.basket_submit.size_id.selectedIndex.value;
	document.basket_submit.size.value=document.basket_submit.size_id.options[document.basket_submit.size_id.selectedIndex].text
}

function changeColour(mylink){
	
	
	
	//window.location=url;
	
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	//window.open(href, 'windowname', 'scrollbars=no,status=no,width=35,height=35');
	window.location=mylink
	return false;
	
}


function product_popUp(mylink, windowname, width, height )
{
	
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'scrollbars=no,status=no,width='+width+',height='+height);
	return false;
} 


function size_popUp(mylink, windowname, width, height )
{
	
	
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'scrollbars=no,status=no,width='+width+',height='+height);
	return false;
}


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_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_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];}
}
function checkSize(){
	if (document.basket_submit.size_id.value!="0") {
		if (document.basket_submit.quantity.value>0){
			document.basket_submit.submit();
		}else{
			alert("Please enter numbers only for quantity.")
			document.basket_submit.quantity.focus();
		}
	}else{
		alert("Please select a size.")
		document.basket_submit.size_id.focus();
	}
}





 

    function validatePostCode(myAction, myanchor)
    {    
        if (document.checkout.quickPostcode.value.length > 5)
        {
            document.forms.checkout.serveraction.value = myAction;
            document.forms.checkout.action= "/checkout/index.asp?#billingpostcode"			
            document.checkout.submit();
        }
        else
        {
            alert("Please enter a 7 character post code");
        }
    }
    

    function validateAlternatePostCode(myAction)
    {    
        if (document.checkout.quickAlternatePostcode.value.length > 5)
        {
            document.forms.checkout.serveraction.value = myAction;
            document.forms.checkout.action= "/checkout/index.asp?#alternatepostcode"			
            document.checkout.submit();
        }
        else
        {
            alert("Please enter a 7 character post code");
        }
    }

    function getaddress(myanchor)
    {
		if (myanchor==1)
	        document.forms.checkout.action= "/checkout/index.asp?#billingpostcode"
		else
	        document.forms.checkout.action= "/checkout/index.asp?#alternatepostcode"


        document.checkout.submit();        
    }

	function funAlternateAddress(objCheck)
	{
		if (objCheck.checked == true)
		{
			document.all.item('divAlternateAddress').style.display = 'inline';
		}
		else
		{
			document.all.item('divAlternateAddress').style.display = 'none';
		}
	}
	
	
		function SetPriceOrder(sOrder)
		{
			document.forms.searchform.search_price.value = sOrder;
			document.forms.searchform.submit();			
		}
		function SetSearchPage(sPage)
		{
			document.forms.searchform.page.value = sPage;
			
			//change the action
			//thepage
			//theviewall
			
			//alert(document.forms.searchform.action)
			
			
			
			
			document.forms.searchform.submit();			
		}
		function SetViewAllPage(sViewAll)
		{
			document.forms.searchform.viewall.value = sViewAll;
			document.forms.searchform.submit();			
		}
	
	
function toggleLayer(whichLayer){
		
		
		if (document.getElementById)
		{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
		}
		else if (document.all)
		{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
		else if (document.layers)
		{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
}


function toggleFabric(whichLayer,whichButton){
		
		
		if (document.getElementById){
			// this is the way the standards work
			var style2 = document.getElementById(whichLayer).style;
			//style2.display = style2.display? "":"block";
			
			if (style2.display == "block"){
				style2.display = "";
				document.getElementById(whichButton).src="/common/images/buttons/fabric_open.gif";
			}else{
				style2.display = "block";
				document.getElementById(whichButton).src="/common/images/buttons/fabric_close.gif";
			}
		
		}
		else if (document.all)
		{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
		else if (document.layers)
		{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
}


function showDiscounts(cid,whichLayer){
	
	if (cid==2){
		if (document.getElementById)
		{
			
			var style2 = document.getElementById(whichLayer).style;
			style2.display = "block";
			
		}
		else if (document.all)
		{
			var style2 = document.all[whichLayer].style;
			style2.display = "block";
			
		}
		else if (document.layers)
		{
				var style2 = document.layers[whichLayer].style;
				style2.display = "block";
			
		}
	
	}else{
	
		//var style2 = document.all[whichLayer].style;
		//style2.display = "";
		if (document.getElementById)
		{
			
			var style2 = document.getElementById(whichLayer).style;
			style2.display = "";
			
		}
		else if (document.all)
		{
			var style2 = document.all[whichLayer].style;
			style2.display = "";
			
		}
		else if (document.layers)
		{
				var style2 = document.layers[whichLayer].style;
				style2.display = "";
			
		}
	}


}



function changeCard(card) {
	
	
		cardimg='/common/images/1x1.gif';
		if(card == "Mastercard"){
			cardimg='/common/images/checkout/mastercard.gif';
		}
		if((card == "Visa/Delta") || (card == "Visa")){
			cardimg='/common/images/checkout/visa.gif';
		}
		if(card == "Maestro"){
			cardimg='/common/images/checkout/maestro.gif';
		}
		if(card == "Solo"){
			cardimg='/common/images/checkout/solo.gif';
		}
		if(card == "Switch"){
			cardimg='/common/images/checkout/switch.gif';
		}
	

		
		document.getElementById("cardimg").src=cardimg;
	
}


function updateSummary(fabric,price){
	
	price=parseFloat(price);
	price=price.toFixed(2);
	
	//price=FormatNumber('3000.00',2,3);
	
	
	document.getElementById("selectedFabric").innerHTML= fabric;
	document.getElementById("selectedPrice").innerHTML=price;
	
	
	
	document.basket_submit.unit_price.value=price;
	
	
	
	
	//p=parseFloat(document.basket_submit.unit_price.value)
	//q=parseFloat(document.basket_submit.qty.value)
	//f=parseFloat(document.basket_submit.fabric_price.value)
	
	//t=(p * q) + f
	//t=t.toFixed(2)
	//document.getElementById("totalPrice").innerHTML= t
	
	document.getElementById("totalPrice").innerHTML= price;
	
}


  

 function AlertError(methodName,e)
 {
            if (e.description == null) { alert(methodName + " Exception: " + e.message); }
            else {  alert(methodName + " Exception: " + e.description); }
 }

 
 function SetDefaultFormValues()
 {
   document.getElementById('text1').value = FormatNumber(document.getElementById('text1').value,1,6);
   document.getElementById('text2').value = FormatNumber(document.getElementById('text2').value,2,1);
   document.getElementById('text3').value = FormatNumber(document.getElementById('text3').value,3,2);
   document.getElementById('text4').value = FormatNumber(document.getElementById('text4').value,1,3);
   document.getElementById('text5').value = FormatNumber(document.getElementById('text5').value,2,4);
   document.getElementById('text6').value = FormatNumber(document.getElementById('text6').value,3,5);
 }


function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)


}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
	
	
	
    } 
  }
return null
}



function updateTot(){
	
	p=parseFloat(document.basket_submit.unit_price.value)
	q=parseFloat(document.basket_submit.qty.value)
	f=parseFloat(document.basket_submit.fabric_price.value)
	
	
	t=(p * q) + f
	
	t=t.toFixed(2)
	
	document.getElementById("totalPrice").innerHTML= t
	
	
}

function goBrand(){
	//brand_name=document.frmsearch.house.options[document.frmsearch.house.selectedIndex].text ;
	
	//brand_name=brand_name.replace(/ /,"-");
	//brand_name=brand_name.replace(/ /,"-");
	
	url=document.frmbrowse.house.options[document.frmbrowse.house.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}
function goDesigner(){

	
	
	url=document.frmbrowse.designer.options[document.frmbrowse.designer.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}