var g_stainguard = 1;
function testjavascript() 
{
   rc = alert("JavaScript is working.");
}
function testcookies() 
{
   // Test cookies by writing a unique number (the time, seconds since 1970)
   // to the cookie and then trying to retrieve it.
   var now = new Date();
   var timenow = now.getTime();
   index = document.cookie.indexOf('CookieTest'); 
   document.cookie='CookieTest=' + String(timenow) + '.;';  
   countbegin=(document.cookie.indexOf(String(timenow),index)+1);
   
   if (countbegin>=1)
   {
      rc = alert('Cookies are working.');
   }
   else
   {
      rc = alert('Cookies are **NOT** working');
   }   
}
function changeSpaces(tstring) 
{
   nstring='';
   for (var i=0; i <= tstring.length; i++) 
   {
      if (tstring.charAt(i)==' ') 
      {
         nstring=nstring+'^';
      } 
      else 
      { 
         nstring=nstring+tstring.charAt(i); 
      }
   }
   return nstring;
}
function buyItem(newItem,newPrice,newStain,newCode,newFabric,newQuantity,newpage,newwarranty) 
{

   if(newPrice=="OutOfStock") 
   {
      rc = alert('This Item is currently Out Of Stock');
   }
   else if(newQuantity<=0) 
   {
      rc = alert('The quantity entered is incorrect');
   } 
   else 
   {
      switch(newFabric)
      {
         case "a" :
            if (document.form1.fabriccoloura.selectedIndex==0)
            {
               alert('Please Select Storage Option Required');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccoloura.options[document.form1.fabriccoloura.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "b" :
            if (document.form1.fabriccolourb.selectedIndex==0)
            {
               alert('Please Select Storage Option Required');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolourb.options[document.form1.fabriccolourb.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "c" :
            if (document.form1.fabriccolourc.selectedIndex==0)
            {
               alert('Please Select Storage Option Required');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolourc.options[document.form1.fabriccolourc.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "d" :
            if (document.form1.fabriccolourd.selectedIndex==0)
            {
               alert('Please Select Storage Option Required');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolourd.options[document.form1.fabriccolourd.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;   
         case "e" :
            if (document.form1.fabriccoloure.selectedIndex==0)
            {
               alert('Please Select Storage Option Required');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccoloure.options[document.form1.fabriccoloure.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;        	
         case "1" :
            if (document.form1.fabriccolour.selectedIndex==0)
            {
               alert('You must make a colour choice before ordering');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "2" :
            if (document.form1.fabriccolour2.selectedIndex==0)
            {
               alert('You must make a colour choice before ordering');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "3" :
            if (document.form1.fabriccolour3.selectedIndex==0)
            {
               alert('You must make a colour choice before ordering');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolour3.options[document.form1.fabriccolour3.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "4" :
            if (document.form1.fabriccolour4.selectedIndex==0)
            {
               alert('You must make a colour choice before ordering');
               return;
            }
            else
            {
               newFabric=document.form1.fabriccolour4.options[document.form1.fabriccolour4.selectedIndex].text;
               newItem=newItem+' ('+newFabric+')';
            }
            break;
         case "5" :
            if (document.form1.fabriccolour.selectedIndex==0)
            {
               alert('You must make a fabric colour choice before ordering');
               return;
            }
            if (document.form1.woodcolour.selectedIndex==0)
            {
               alert('You must make a wood colour choice before ordering');
               return;
            } 
            newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text+" fabric/"+document.form1.woodcolour.options[document.form1.woodcolour.selectedIndex].text+" wood";
            newItem=newItem+' ('+newFabric+')';
            break;
         case "6" :
            if (document.form1.fabriccolour.selectedIndex==0)
            {
               alert('You must make a fabric colour choice before ordering');
               return;
            }
            if (document.form1.fabriccolour2.selectedIndex==0)
            {
               alert('You must make a cushion colour choice before ordering');
               return;
            } 
            newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text+" with "+document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].text+" cushions";
            newItem=newItem+' ('+newFabric+')';  
            break;    
         case "7" :
            if (document.form1.fabriccolour.selectedIndex==0)
            {
               alert('You must make a fabric colour choice before ordering');
               return;
            }
            if (document.form1.fabriccolour2.selectedIndex==0)
            {
               alert('You must make a frame colour choice before ordering');
               return;
            } 
            newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text+" with "+document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].text+" frame";
            newItem=newItem+' ('+newFabric+')';    
            break;
         case "8" :
            if (document.form1.fabriccolour.selectedIndex==0)
            {
               alert('You must make a fabric colour choice before ordering');
               return;
            }
            if (document.form1.fabriccolour2.selectedIndex==0)
            {
               alert('You must choose a Chair Type before ordering');
               return;
            } 
            newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text+" with "+document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].text+" frame";
            newItem=newItem+' ('+newFabric+')'; 
            break;
         default :
            newFabric='';
      }
      if (confirm('Add '+newQuantity+' x '+newItem+' to basket? ')) 
      {
         index=document.cookie.indexOf('TheBasket');
         countbegin=(document.cookie.indexOf('=',index)+1);
         countend=document.cookie.indexOf(';',index);
         if(countend==-1) { countend=document.cookie.length; }
         fulllist = document.cookie.substring(countbegin,countend);
         amended = false;
         newItemList=''; itemlist=0;
         for (var i=0;i<=fulllist.length;i++) 
         {
            if (fulllist.substring(i,i+1) == '[') 
            {
               thisitem=1;
               itemstart=i+1;
               fullstart=i+1;
            } 
            else if (fulllist.substring(i,i+1) == ']') 
            {
               itemend=i;
               thequantity=fulllist.substring(itemstart,itemend);
               itemlist++;
               if (theItem==newItem ) 
               {
                  amended=true;
                  tempquantity=eval(thequantity)+eval(newQuantity);
                  newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theStain+'|'+theCode+'|'+theFabric+'|'+thepage+'|'+tempquantity+']';
               } 
               else 
               {
                  newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theStain+'|'+theCode+'|'+theFabric+'|'+thepage+'|'+thequantity+']';
               }
            } 
            else if (fulllist.substring(i,i+1)=='|') 
            {
               if (thisitem==1) theItem=fulllist.substring(itemstart,i);
               if (thisitem== 2) thePrice=fulllist.substring(itemstart,i);
               if (thisitem== 3) theStain=fulllist.substring(itemstart,i);
               if (thisitem== 4) theCode=fulllist.substring(itemstart,i);
               if (thisitem== 5) theFabric=fulllist.substring(itemstart,i);
               if (thisitem== 6) thepage=fulllist.substring(itemstart,i);              
               thisitem++;itemstart=i+1;
            }
         }
         if (amended==false) 
         {
            newItemList=newItemList+'['+newItem+'|'+newPrice+'|'+newStain+'|'+newCode+'|'+newFabric+'|'+newpage+'|'+newQuantity+']'; 
         }
         index = document.cookie.indexOf('TheBasket');
         document.cookie='TheBasket='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
         if (newwarranty==1 && g_stainguard==1)
         {
            g_stainguard = 0;
            //showwarranty();
         }
      }
   }
}

function showwarranty()
{ 
   fmwin1=window.open('regency.htm','Warranty','toolbar=no,status=no,width=520,height=330,directories=no,scrollbars=no,location=no,resizable=yes,menubar=no');

}
function pricepromise()
{ 
   fmwin2=window.open('price_promise.htm','PricePromise','toolbar=no,status=no,width=480,height=280,left=20,top=20,directories=no,scrollbars=no,location=no,resizable=no,menubar=no');
}
function freesample()
{ 
   if (document.form1.fabriccolour.selectedIndex==0)
   {
      alert('You must make a colour choice before requesting a free colour sample');
      return;
   }
   else
   {
      var newFabric=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].text;
      var newImage=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].value;
      var oldPage=new String(document.location);
      // remove the full address to leave just the page name
      var searchstr=/.*\//;
      var newPage=oldPage.replace(searchstr,"");
      fmwin1=window.open('http://www.elegantfurniture.co.uk/cgi-bin/free_sample.cgi?image='+newImage+'&fabric='+newFabric+'&page='+newPage,'FreeSample','toolbar=no,status=no,width=410,height=360,directories=no,scrollbars=no,location=no,resizable=no,menubar=no');
   }
}

function goFabric()
{ 
   document.form1.fabriccolorimg.src=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].value;
}

function goFabric2()
{ 
document.form1.fabriccolorimg2.src=document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].value;
}

function goWood()
{ 
document.form1.woodcolorimg.src=document.form1.woodcolour.options[document.form1.woodcolour.selectedIndex].value;
}

function showbigcolour()
{
   if (document.form1.fabriccolour.selectedIndex != 0)
   {
      var oldpageimg=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].value;
      // remove the _small
      var newpageimg=oldpageimg.replace("_small.jpg",".jpg");
      fmwin1=window.open(newpageimg,'FabricColour','toolbar=no,status=no,width=460,height=360,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');
   }
}

function showbigcolour2()
{ 
   if (document.form1.fabriccolour2.selectedIndex != 0)
   {
      var oldpageimg=document.form1.fabriccolour2.options[document.form1.fabriccolour2.selectedIndex].value;
      // remove the _small
      var newpageimg=oldpageimg.replace("_small.jpg",".jpg");
      fmwin2=window.open(newpageimg,'FabricColour2','toolbar=no,status=no,width=460,height=360,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');
   }
}
function showbigcolour3()
{
      var oldpageimg=document.form1.fabriccolour.options[document.form1.fabriccolour.selectedIndex].value;
      // remove the _small
      var newpageimg=oldpageimg.replace("_small.jpg",".jpg");
      fmwin4=window.open(newpageimg,'WoodColour','toolbar=no,status=no,width=460,height=360,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');

} 

function showbigwoodcolour()
{
      var oldpageimg=document.form1.woodcolour.options[document.form1.woodcolour.selectedIndex].value;
      // remove the _small**.jpg
      var searchstr=/_small\.jpg/;
      var newpageimg=oldpageimg.replace(searchstr,".jpg");
      fmwin3=window.open(newpageimg,'WoodColour','toolbar=no,status=no,width=645,height=335,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');

}          

function showhighres()
{
      var oldpageimg=document.form1.bigpicture.src;
      // remove the .jpg
      var newpageimg=oldpageimg.replace(/\.jpg/,"_big.jpg");
      swidth="780";
      sheight="520";
      if (window.screen.width == "640") {
         swidth="620";
         sheight="420";
      }
      fmwin4=window.open(newpageimg,'HighResPicture','toolbar=no,status=no,width=' + swidth + ',height=' + sheight + ', left=3, top=3, directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');

}   

function showbigpic(imagename,widthx,heighty)
{
      if (window.screen.width == "640") {
         widthx="620";
         heighty="420";
      }
      fmwin4=window.open(imagename,'HighResPicture','toolbar=no,status=no,width=' + widthx + ',height=' + heighty + ', left=3, top=3, directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');

} 

function recommend()
{ 

      var oldPage=new String(document.location);
      // remove the full address to leave just the page name
      var searchstr=/.*\//;
      var newPage=oldPage.replace(searchstr,"");
      fmwin1=window.open('recommend.htm?page='+newPage,'Recommend','toolbar=no,status=no,width=420,height=280,left=20,top=20,directories=no,scrollbars=no,location=no,resizable=no,menubar=no');

}

function showterms()
{
   fmwin1=window.open('terms.php3','Terms','toolbar=no,status=no,width=400,height=300,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no');

}

function goTolink()
	{
	location.href = document.form1.products.options[document.form1.products.selectedIndex].value;
	}

function goTolink1()
	{
	location.href = document.form1.Tables.options[document.form1.Tables.selectedIndex].value;
	}
	
function goTolink2()
	{
	location.href = document.form1.information.options[document.form1.information.selectedIndex].value;
	}

function goTolink3()
	{
	location.href = document.form1.search.options[document.form1.search.selectedIndex].value;
	}
	
function goTolinkList() 
{
   var   txt='<select name="Most Popular Ranges" onchange="goTolink();" >';
   txt = txt+'<option selected>--Most Popular Ranges--</option>';
   txt = txt+'<option value="../asbi_quebec_table.php3">Quebec Dining Set</option>';
   txt = txt+'<option value="../seconique_salvador.php3">Salvador Pine Dining Set</option>';   
   txt = txt+'<option value="../bedroom.php3">Equador Pine Dining Set</option>';
   txt = txt+'<option value="../ultrassage_beds.php3">Adjustable Beds</option>';
   txt = txt+'<option value="../bedroom_furniture.php3">Bedroom Furniture</option>';
   txt = txt+'<option value="../home_office.php3">Home Office</option>';
   txt = txt+'<option value="../lounge.php3">Lounge & Occasional</option>';
   txt = txt+'<option value="../dining_ranges.php3">Collections</option>';
   txt = txt+'<option value="../special_offer.php3">Special Offers</option>';
   txt = txt+'</select>';
   document.write(txt);
}

function goTolinkList2() 
{
   var   txt='<select name="information" onchange="goTolink2();" >';
   txt = txt+'<option selected>--Information--</option>';
   txt = txt+'<option value="../faqs.php3">FAQs</option>';
   txt = txt+'<option value="../about.php3">About us</option>';
   txt = txt+'<option value="../faqs.php3#contactus">Contact us</option>';
   txt = txt+'<option value="mailto:feedback@ivyhousefurniture.co.uk">Email us</option>';   
   txt = txt+'<option value="../faqs.php3#payingus">Payment</option>';
   txt = txt+'<option value="../delivery.php3">Delivery</option>';
   txt = txt+'<option value="../about.php3#Finance">Finance</option>';
   txt = txt+'</select>';
   document.write(txt);
}

function goTolinkList3() 
{
   var   txt='<select name="search" onchange="goTolink3();" >';
   txt = txt+'<option selected>--Quick Search--</option>';
   txt = txt+'<option value="faqs.php3">FAQs</option>';
   txt = txt+'<option value="about.php3">About us</option>';
   txt = txt+'<option value="faqs.php3#contactus">Contact us</option>';
   txt = txt+'<option value="Metal_Frame.htm">Email us</option>';   
   txt = txt+'<option value="faqs.php3#payingus">Payment</option>';
   txt = txt+'<option value="Kids_beds.htm">Delivery</option>';
   txt = txt+'<option value="about.php3#Finance">Finance</option>';
   txt = txt+'<option value="four_poster_beds.htm">How to buy</option>';
   txt = txt+'</select>';
   document.write(txt);
}

function goToTablesList() 
{
   var   txt='<select name="Tables" onchange="goTolink1();" >';
   txt = txt+'<option selected>--Quick Search Options--</option>';
   txt = txt+'<option value="furniturefast_sofas.htm">Seats up to 4 persons</option>';
   txt = txt+'<option value="furniturefast_tables.htm">Seats up to 6 persons</option>';   
   txt = txt+'<option value="furniturefast_cabinets.htm">Seats up to 8 persons</option>';
   txt = txt+'<option value="furniturefast_beds.htm">Seats up to 10 persons</option>';
   txt = txt+'<option value="furniturefast_bedroom.htm">Under £300</option>';
   txt = txt+'<option value="furniturefast_office.htm"> £500</option>';
   txt = txt+'<option value="furniturefast_occasional.htm">Under £700</option>';
   txt = txt+'<option value="furniturefast_collections.htm">Over £700</option>';    
   txt = txt+'<option value="furniturefast_specials.htm">Pine</option>';                     
   txt = txt+'<option value="furniturefast_specials.htm">Oak</option>';
   txt = txt+'<option value="furniturefast_specials.htm">Glass</option>';
   txt = txt+'<option value="furniturefast_specials.htm">Mahogany</option>';
   txt = txt+'<option value="furniturefast_specials.htm">Oval</option>';
   txt = txt+'<option value="furniturefast_specials.htm">Round</option>';
   txt = txt+'<option value="furniturefast_specials.htm">Rectangle</option>';
   txt = txt+'</select>';
   document.write(txt);
}

<!--
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) { //v3.0
  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); 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];}
}
//-->