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 nav_out1(obj) {
	obj.bgColor = "#003399";
	document.getElementById('rollover').innerHTML = '&nbsp;';
}

function nav_outV(obj) {
	obj.bgColor = "#ffffff";
	obj.style.Color = '#003399';
	document.getElementById('rollover').innerHTML = '&nbsp;';
}

function nav_outV2(obj) {
	obj.bgColor = "#ffffff";
	document.getElementById('rollover').innerHTML = '&nbsp;';
}

function nav_outH(obj) {
	obj.bgColor = "#003399";
	document.getElementById('rollover').innerHTML = '&nbsp;';
}

function spacer(w,h) {
return '<img src="rc_img/x.gif" width="'+w+'" height="'+h+'" border="0">';
}

function text_spacer(text) {
textlength=text.length;
textchar=0;

while (textchar<textlength) {
if (textchar==13) {
	document.write('&Eacute;');
	} else {
	document.write(text.substr(textchar,1));
	}
	document.write(
	'<img src="rc_img/x.gif" width="3" height="1" border="0">'
	);
textchar++;	
}
}

function set_img(div_id,src,width,height) {
document.getElementById(div_id).innerHTML = '<img src="rc_img/'+src+'" width="'+width+'" height="'+height+'" border="0">';
}

function set_text(div_id,text) {
document.getElementById(div_id).innerHTML = text;
}

function set_textV(div_id,text) {
document.getElementById(div_id).innerHTML = text;
}

function set_textH(div_id,text) {
textcode='&nbsp;';
textcode='<img src="rc_img/x.gif" width="10" height="1"><img src="rc_img/wave.gif" height="6" width="20"> '+text;
document.getElementById(div_id).innerHTML = textcode;
}

function set_caption(text) {
document.getElementById('caption').innerHTML = text;
}

function region_out() {
	document.getElementById('winenotes').innerHTML = '&nbsp;';
}

function set_r(text) {
document.getElementById('r').innerHTML = text;
}

function clr_r() {
document.getElementById('r').innerHTML = '&nbsp;';
}

function newWindow(strPage,h,w)
{
	if (window.screen)
	{
		window.open(strPage,'newWin', 'resize=yes, toolbar=no, status=no, menubar=yes, scrollbars=no, height='+(h)+', width='+(w));
		
		//location.href=strPage;
	}
}

function set_colour(id,colour) {
	document.getElementById(id).style.color = colour;
}

function nav_hover(id,colour) {
	document.getElementById(('parent'+id)).style.color = colour;
	document.getElementById(('parent'+id)).style.cursor = 'pointer';
	document.getElementById(('sub'+id)).style.visibility = 'visible';
}

function subnav_hover(id,colour) {
	document.getElementById(('page'+id)).style.color = colour;
	document.getElementById(('page'+id)).style.cursor = 'pointer';
}

function nav_out(id,colour) {
	document.getElementById(('parent'+id)).style.color = colour;
}

function subnav_out(id,colour) {
	document.getElementById(('page'+id)).style.color = colour;
}

function subnav_hide(id) {
 document.getElementById(('sub'+id)).style.visibility = 'hidden';
}

function MM_goToURL() {
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function rc_site_open() {
  window.open('rc_page.php','','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=580');
}

function rc_enter(time) {
		setTimeout("location.href='rc_page.php';document.getElementById('enter').style.visibility = 'visible'",time);
		setTimeout("document.getElementById('enter').style.visibility = 'hidden'",time*3);
}

function switch_d(div_id) {
	if (document.getElementById(div_id).style.display=="block")
		{
		document.getElementById(div_id).style.display="none";
		}
		else 
		{
		document.getElementById(div_id).style.display="block";
		}
}

function voucher_preview() {
	if (order.recipient_name.value) { document.getElementById('voucherheader').innerHTML = 'Gift Voucher for'; document.getElementById('voucherrecipient').innerHTML = '<b>'+order.recipient_name.value+'<b>'; }
	if (order.amount.value) { document.getElementById('vouchervalue').innerHTML = '<b>&pound;'+order.amount.value+'<b>'; }
	if (order.message.value) { 
		var ix=0; add=''; while (ix<order.message.value.length) { 
		if (order.message.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.message.value.substring(ix,ix+1)!='\\') { add=add+order.message.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('vouchermessage').innerHTML = add; }
	document.getElementById('vouchercard_name').innerHTML = order.card_name.value;
	if (order.card_address.value) { 
		var ix=0; add=''; while (ix<order.card_address.value.length) { 
		if (order.card_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.card_address.value.substring(ix,ix+1)!='\\') { add=add+order.card_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('voucheraddress').innerHTML = add; }
	document.getElementById('voucherpostcode').innerHTML = order.postcode.value;
	document.getElementById('vouchercountry').innerHTML = order.country.value;
	if (order.email.value==order.email_confirm.value) { document.getElementById('voucheremail').innerHTML = order.email.value; }
	document.getElementById('vouchernumber').innerHTML = order.number.value;
	document.getElementById('vouchershipping_name').innerHTML = order.shipping_name.value;
	if (order.shipping_address.value) { 
		var ix=0; add=''; while (ix<order.shipping_address.value.length) { 
		if (order.shipping_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.shipping_address.value.substring(ix,ix+1)!='\\') { add=add+order.shipping_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('vouchershipping_address').innerHTML = add; }
	if (order.card_number.value) { document.getElementById('vouchercard_number').innerHTML = 'Card number:<br>'+order.card_number.value; }
 if ((order.start_month.value) && (order.start_year.value)) { document.getElementById('voucherstart_date').innerHTML = 'Start: '+order.start_month.value+' / '+order.start_year.value; }
	if ((order.expiry_month.value) && (order.expiry_year.value)) { document.getElementById('voucherexpiry_date').innerHTML = 'Exp: '+order.expiry_month.value+' / '+order.expiry_year.value; }
	if (order.issue_number.value) { document.getElementById('voucherissue_number').innerHTML = 'Issue number: '+order.issue_number.value; }
	if (order.security_code.value) { document.getElementById('vouchersecurity_code').innerHTML = 'Security code: '+order.security_code.value; }
	document.getElementById('vouchershipping_name').innerHTML = order.shipping_name.value;
	if (order.shipping_address.value) { 
		var ix=0; add=''; while (ix<order.shipping_address.value.length) { 
		if (order.shipping_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.shipping_address.value.substring(ix,ix+1)!='\\') { add=add+order.shipping_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('vouchershipping_address').innerHTML = add; }
	document.getElementById('vouchershipping_postcode').innerHTML = order.shipping_postcode.value;
	document.getElementById('vouchershipping_country').innerHTML = order.shipping_country.value;
}

function tshirt_preview() {
	document.getElementById('ordercard_name').innerHTML = order.card_name.value;
	if (order.card_address.value) { 
		var ix=0; add=''; while (ix<order.card_address.value.length) { 
		if (order.card_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.card_address.value.substring(ix,ix+1)!='\\') { add=add+order.card_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('orderaddress').innerHTML = add; }
	document.getElementById('orderpostcode').innerHTML = order.postcode.value;
	document.getElementById('ordercountry').innerHTML = order.country.value;
	if (order.email.value==order.email_confirm.value) { document.getElementById('orderemail').innerHTML = order.email.value; }
	document.getElementById('ordernumber').innerHTML = order.number.value;
	document.getElementById('ordershipping_name').innerHTML = order.shipping_name.value;
	if (order.shipping_address.value) { 
		var ix=0; add=''; while (ix<order.shipping_address.value.length) { 
		if (order.shipping_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.shipping_address.value.substring(ix,ix+1)!='\\') { add=add+order.shipping_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('ordershipping_address').innerHTML = add; }
	if (order.card_number.value) { document.getElementById('ordercard_number').innerHTML = 'Card number:<br>'+order.card_number.value; }
 if ((order.start_month.value) && (order.start_year.value)) { document.getElementById('orderstart_date').innerHTML = 'Start: '+order.start_month.value+' / '+order.start_year.value; }
	if ((order.expiry_month.value) && (order.expiry_year.value)) { document.getElementById('orderexpiry_date').innerHTML = 'Exp: '+order.expiry_month.value+' / '+order.expiry_year.value; }
	if (order.issue_number.value) { document.getElementById('orderissue_number').innerHTML = 'Issue number: '+order.issue_number.value; }
	if (order.security_code.value) { document.getElementById('ordersecurity_code').innerHTML = 'Security code: '+order.security_code.value; }
	document.getElementById('ordershipping_name').innerHTML = order.shipping_name.value;
	if (order.shipping_address.value) { 
		var ix=0; add=''; while (ix<order.shipping_address.value.length) { 
		if (order.shipping_address.value.charCodeAt(ix)==10) { add=add+'<br>'; } 
		if (order.shipping_address.value.substring(ix,ix+1)!='\\') { add=add+order.shipping_address.value.substring(ix,ix+1); }
		ix++;
		}
	document.getElementById('ordershipping_address').innerHTML = add; }
	document.getElementById('ordershipping_postcode').innerHTML = order.shipping_postcode.value;
	document.getElementById('ordershipping_country').innerHTML = order.shipping_country.value;
	
}

function change_order_qty(qty_max,sku_n,sku,price,change) {
	qty_this=Number(document.getElementById('qty_'+sku).value);
	qty_total=0; i=0; while (i<sku_n) { i++; qty_total=Number(qty_total)+Number(document.getElementById('qty_'+i).value); }
	qty_total_new=qty_total+change;
	if ((change==-1) && (qty_total==qty_max)) { document.getElementById('qty_max_alert').style.display="none"; }
	if ((qty_this+change>=0) && (qty_this+change<=qty_max) && (qty_total_new>=0) && (qty_total_new<=qty_max)) {
		//valid change
		document.getElementById('qty_'+sku).value=qty_this+change;
		document.getElementById('qty_disp_'+sku).value=qty_this+change;
		document.getElementById('total_'+sku).value=(Number(document.getElementById('qty_'+sku).value)*price).toFixed(2);
		document.getElementById('total_disp_'+sku).value=(Number(document.getElementById('qty_'+sku).value)*price).toFixed(2);
	} else {
		if (qty_total==qty_max) {
			document.getElementById('qty_max_alert').style.display="block"; 
		}
	}
	order_total=Number(document.getElementById('ppcost').value);
	i=0; while (i<sku_n) { i++;
		order_total=order_total+Number(document.getElementById('total_'+i).value);
	}
	document.getElementById('order_total').value=order_total.toFixed(2);
	document.getElementById('order_total_disp').value=order_total.toFixed(2);
}

function set_pic(src,caption,rev) {
	document.getElementById('image_main').style.backgroundImage='url('+src+')';
	if (caption!='') {
		if (rev=='1') {
			document.getElementById('image_caption').className='piccaptionwhite';
		} else {
			document.getElementById('image_caption').className='piccaption';
		}
		document.getElementById('image_caption').innerHTML=caption;
	} else {
		document.getElementById('image_caption').innerHTML='&nbsp;';
	}
}

var row=1;

function thumb_scrollX(rows,inc) {
	if (row<(rows-3)) {
		target=row;
	} else {
		target=0;
	}
	var top=parseInt(row)*80-80;
	target=target*80;
	step=(target-top)/20;
	//alert ('row:'+row+' rows:'+rows+' inc:'+inc+' target:'+target+' top:'+top+' step:'+step);
	//move
	while (top<target) {
		top=top+step;
		document.getElementById('thumbs_grid').style.top=-top;
	}
	document.getElementById('thumbs_grid').style.top=-target;
	row++;
	if (row>rows) {
		row=1;
	}
}

function thumb_scroll(rows,inc) {
	if (row<(rows-3)) {
		target=row;
	} else {
		target=0;
	}
	var top=parseInt(row)*80-80;
	target=target*80;
	step=(target-top)/20;
	//alert ('row:'+row+' rows:'+rows+' inc:'+inc+' target:'+target+' top:'+top+' step:'+step);
	//move
	new Effect.Move(thumbs_grid, { x:0, y: -target, mode: 'absolute', duration: 0.3  });
	row++;
	if (row==(rows-3)) {
		row=0;
	}
}
