
// ================== DROP DOWN =========================
		//initaliseqty()




		function initaliseqty()
		{
			document.forms['attributes'].spcqty.length = 1;
			document.forms['attributes'].spcqty.options[0].text = 'quantity';
			document.forms['attributes'].spcqty.options[0].value = '0';							
		}

		
			// list product stock level in drop down
			function ddquantity(stocklevel, formname)
			{
				istocklevel = parseInt(stocklevel);
				if (istocklevel > 10) {istocklevel=10};
				if (istocklevel == 0 )
				{
					document.forms['attributes'].spcqty.length = 1;
					document.forms['attributes'].spcqty.options[0].text = 'Out of stock';
					document.forms['attributes'].spcqty.options[0].value = '0';										
					document.getElementById('sale').innerHTML = 'Sorry, out of stock';
				}
				else
				{
					istocklevel = istocklevel + 1
					document.forms['attributes'].spcqty.length = istocklevel-1;
			
					for(i=1; i<istocklevel; i++)
						{
						document.forms['attributes'].spcqty.options[i-1].text = 'Qty: ' + i;
						document.forms['attributes'].spcqty.options[i-1].value = i;								
						}
				}
			}
			
		
			
			function checkselect(formname)
			{
			//reset quantity in case out of stock
				 ddquantity(1, formname)
				//check size and/or colour
				if (document.attributes.elements[5]) 
				{
					// double dd
					var prodcode = document.forms[formname].atrb[0].options[document.forms[formname].atrb[0].selectedIndex].value;
					var length = sizes[prodcode].length;
	
				   if (document.attributes.atrb[1])
					{
						//document.forms[formname].atrb[1].options[0].value = '0';								
						document.forms[formname].atrb[1].options.length = length+1;
						document.forms[formname].atrb[1].options.selectedIndex = 0;					
						document.forms[formname].atrb[1].options[0].text = 'SELECT A SIZE';					
						
						for(i=0; i<length; i++)
						{
						document.forms[formname].atrb[1].options[i+1].text = sizes[prodcode][i].text;
						document.forms[formname].atrb[1].options[i+1].value = sizes[prodcode][i].value;						
						}

					}

				}
				else
				{
					//single dd
					var prodcode = document.forms[formname].atrb.options[document.forms[formname].atrb.selectedIndex].value;
					ddquantity(sizes[prodcode][0].stock, formname)
					document.forms[formname].price.value = formatCurrency(sizes[prodcode][0].pop);	
					document.forms[formname].spc.value = sizes[prodcode][0].poc;		
					ippop = sizes[prodcode][0].ppop;	
					ipop = sizes[prodcode][0].pop;
					spc = sizes[prodcode][0].poc;		
					if (ippop != '0') 
					{
					
					varSaving = parseInt((1-(ipop/ippop))*100)
					document.getElementById('sale').innerHTML = ""+ varSaving +'% OFF!&nbsp Was ' + formatCurrency(ippop);	
					document.getElementById('refcode').innerHTML = '&nbsp; &nbsp;REF: ' + spc + '';
				
					}
					else
					{
					sale.innerText = ''
					document.getElementById('refcode').innerHTML = '&nbsp; &nbsp;REF: ' + spc + '';
					}
				}
			}		


		// if second drop down then this popluates it from first selection
		function checkinfo(formname)
			{
				var prodcode = document.forms[formname].atrb[0].options[document.forms[formname].atrb[0].selectedIndex].value;
				var size = document.forms[formname].atrb[1].options[document.forms[formname].atrb[1].selectedIndex].value;
				//alert (size);
				var length = sizes[prodcode].length;
				
				for(i=0; i<length; i++)
				{
				if (sizes[prodcode][i].value == size)
					{
						document.forms[formname].price.value = formatCurrency(sizes[prodcode][i].pop);			
						document.forms[formname].spc.value = sizes[prodcode][i].poc;								
						ddquantity(sizes[prodcode][i].stock, formname)						
					}
				}			
			}	

			
			// check divys are selecting options
			function checkbuy(formname)
			{
				if (document.attributes.elements[5]) 
				{
					var size = document.forms[formname].atrb[1].options[document.forms[formname].atrb[1].selectedIndex].value;
					var prodcode = document.forms[formname].atrb[0].options[document.forms[formname].atrb[0].selectedIndex].value;
				}
				else
				{
					var prodcode = document.forms[formname].atrb.options[document.forms[formname].atrb.selectedIndex].value;
				}
				var qty = document.forms[formname].spcqty.options[document.forms[formname].spcqty.selectedIndex].value;
	
				missinginfo = "";
				var submitcount=0;
			
				if ((prodcode=='')||(size==''))  
				{
					missinginfo += "Please select a size or colour";
				}
				else if (qty=='0')  
				{
					missinginfo += "This item is currently out of stock";
				}
						
				if (missinginfo != "")
					 {
						missinginfo = " " +
						missinginfo + "\n";
						alert(missinginfo);
						return false;
					}
				else
				return true;
			
			}
		

			// check user is selecting size option
			function checksizesel(formname)
			{
				var prodcode = document.forms[formname].spc.options[document.forms[formname].spc.selectedIndex].value;
				
				missinginfo = "";
				var submitcount=0;
			
				if ((prodcode==''))  
				{
					missinginfo += "Please select a size/colour";
				}
				else if (qty=='0')  
				{
					missinginfo += "This item is currently out of stock";
				}
						
				if (missinginfo != "")
					 {
						missinginfo = " " +
						missinginfo + "\n";
						alert(missinginfo);
						return false;
					}
				else
				return true;
			
			}


		
		function formatCurrency(num) 
		{
			num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			pence = num%100;
			num = Math.floor(num/100).toString();
			if(pence<10)
			pence = "0" + pence;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '£' + num + '.' + pence);
		}		
		

	ggate=0;
	mimg=0;
	
	function init()
	{
	 //reset drop down
	// if (document.prods.colour) { document.prods.colour.selectedIndex=0; }
	   if (document.prods.psize) { document.prods.psize.selectedIndex=0; }
	 //display imagery
	 if (maximgs > -1)
	 {
	  s('medium','mimg0');
	  ggate=1;
	 }
	}


xtrapos=1;
ggate = 1;


var largeView;
function largerimage(spc) {
   var url, h
   if (largeView==null || largeView.closed) {
       h = (screen.availHeight<800)?570:780;
       url = '/store/images.asp?spc=' + spc + '&pos=' + document.formpos.pos.value;
       largeView = window.open(url, "LargerView", "left=5,top=5,height="+h+",width=670,status=yes,scrollbars=yes,resizable");
   }
   else {
   	   largeView.focus();
       largeView.init(document.formpos.pos.value);
   }
}


	maximgs=2;
	function swap(imgpos)
	{
	ggate = 1
	 if (ggate==1 && maximgs > 0)
	 {
	  eval("swapit('img"+imgpos+"','simg"+mimg+"');");
	  eval("swapit('medium','mimg"+pos[imgpos]+"');");
	  hold=pos[imgpos];
	  pos[imgpos]=mimg;
	  mimg=hold;
	  document.formpos.pos.value = mimg;

	 }
	}
	
	prodf = '-1';
	
	function swapit(o,f) {	 
		 eval ("document."+o+".src= "+f+".src;");
	 }
		xtrapos = 0;
		
		
		function moremimages()
		{
		 if (ggate==1)
		 {
		  xtrapos++;
		  if (xtrapos==imgTotal+1) xtrapos=0;
		  eval("swapit('medium','mimg"+pos[xtrapos]+"');");
		  document.formpos.pos.value = pos[xtrapos];
		 }
		}
	
	
	
	
	

