document.write('<script type="text/javascript" src="scripts/prototype-1.6m.js"></'+'script>');
document.write('<script type="text/javascript" src="scripts/cookiejar.js"></'+'script>');
document.write('<script type="text/javascript" src="scripts/posit.js"></'+'script>');

function cart(str,num){
	new Ajax.Updater('backend', 'cart.php?b='+str+(num? '&q='+num : ''), { method: 'get', evalScripts: true });
}
function go(str){
	document.location.href='dept.php?n='+str;
}
function subgo(str){
	document.location.href='section.php?n='+str;
}

function showPage(num){
	new Ajax.Updater('backend', 'findpage.php?n='+num, { method: 'get', evalScripts: true });
}

function fullCart(showIt){
	var c=$('cart');
	var x=$('extrainfo').style;
	var l=$('cartlist').style;
	if (c) {
		if (showIt){
			x.display='block';
			l.display='block';
		} else {
			x.display='none';
			l.display='none';
		}
	}
}

function switchDelivery(){
}

function showCart(){
	top.SHOWCART=true;
	new Ajax.Updater('backend', 'showcart.php' + (top.CHECKOUT ? '?c=y':(top.THANKS ? '?t=y':'')), { method: 'get', evalScripts: true });
}

function timeLeft(str) {
	str=str || 'y';
	//ie6 bugfix - added the r parameter
	if (str=='y')
		new Ajax.Updater('backend', 'timeleft.php?e='+str+'&r='+Math.random(), { method: 'get', evalScripts: true , onSuccess: function(){setTimeout('refreshTime();',100);} });
	else 
		new Ajax.Updater('backend', 'timeleft.php?e='+str+'&r='+Math.random(), { method: 'get', evalScripts: true });

}
function refreshTime(){
	var tl=$$('#cart .timeleft')[0];
	var n=$$('#backend .timeleft')[0];
	if ( !n) { return;}
	if (tl.outerHTML) 
		tl.outerHTML=n.outerHTML;
	else 
		tl.innerHTML=n.innerHTML;
}
function checkout(){
	document.location.href='checkout.php';
}

function itemMore(num, sign, qty){
	var s=top.document.getElementById("hilite");
	if (s) s.className="normal";
	sign=sign || 1;
	s = qty ? '&q='+qty : (sign>0 ? '&m=y' : '&m=n');
	new Ajax.Updater('backend', 'cart.php?b='+num+s+ (top.CHECKOUT ? '&chk=y&pnp='+$F('deliveryType') :''), { method: 'get', evalScripts: true });
}
function itemLess(num){
	itemMore(num,-1);
}

function trim(str){
	return str.replace(/^\s+|\s+$/g, '');
}

function clearFullImg(){
		var i=$('fullimg').style;
		if (i && i.display=='block') i.display='none';
	}

function isOldIe(){
	return (typeof document.body.style.maxHeight === "undefined");
}
function coltoggleimg(that,id){
	toggleimg(that,id);
}
function toggleimg(that,id){
	if (that && (!that.src || that.src.indexOf('blank.gif')>0)) return;
	var obj=$('fullimg');
	var oldIeMc=isOldIe();
	obj.className='';
	if (that) {
		that=$(that);
		obj.style.visibility='hidden';
		var img=obj.select('img')[0];
		var hi=$("hilite");
		if (hi && that != hi) 
			hi.className="normal";
		var descr=obj.select('.descr','.sdescr')[0];
		//img.src=(that.src.substr(that.src.length-9)!='blank.gif') ? that.src : that.name;
		img.src=that.src;
		descr.innerHTML=that.next('.descr') ? that.next('.descr').innerHTML : that.next('.sdescr').innerHTML;
		descr.style.height='auto';
		descr.style.visibility='hidden';
		obj.style.top=0;
		obj.style.left=0;
		obj.style.display='block';//make ie notice the new size!
		obj.orig=that;
		obj.style.width=img.width;
		//alert(document.getElementById('fullimg').clientWidth)
		$('wrapper').onmousedown=function(){toggleimg()};
		if(id)
			new Ajax.Updater('allcols', 'code.php?i='+id, { method:'get', evalScripts: true });
	}else {
		$('wrapper').onmousedown=function(){};
		obj.style.display='none';
	}
}

function showImgCode(code){

	var obj=$('fullimg');
	var descr=obj.select('.descr','.sdescr')[0];
	descr.style.width=obj.style.width;
	descr.style.display='block';//make ie notice the new size!
	if (!(descr.innerHTML.indexOf('</small>')>0))
		descr.innerHTML+='<br><small>code: '+code+'</small>';
	else return;
	var vPort=document.viewport.getDimensions();
	var that=obj.orig;
	var xy=that.cumulativeOffset();
	var t=xy[0]+((that.width-obj.clientWidth)>>1);
	obj.style.left=(t>=0 ? t : 1)+'px';
	t=xy[1] + ((that.height-obj.clientHeight-8)>>1);
	obj.style.top=(t>=0 ? t : 1)+'px';
	top.scrollTo(xy[0]-((vPort.width-that.width)>>1),xy[1]-((vPort.height-that.height)>>1));
	
	descr.style.visibility='visible';
	obj.style.visibility='visible';
}

function toPounds(i) {
	var pre='&pound;';
	i=parseFloat(''+i);
	if (i<.005) i='0.00';
	else {
		if (i.toFixed) i=''+i.toFixed(2);
		if (isNaN(i)) i='';
	}
	return pre+i;
}

function intOnly(obj,tot){
	obj.value=parseInt(obj.value);

}
function numbersOnly(event) {
	var element = event.element();
	var k= event.which ||event.charCode || event.keyCode;
	var specialk=false;
	var val=parseInt(element.value);
	if(k==Event.KEY_RETURN) element.blur();
	[Event.KEY_BACKSPACE,Event.KEY_TAB,Event.KEY_ESC,Event.KEY_LEFT,
	Event.KEY_RIGHT,Event.KEY_DELETE,Event.KEY_HOME,Event.KEY_END,
	Event.KEY_INSERT].each (function (e){ specialk=(specialk || e==k);});
	
	if ( k>47 && k<58 || specialk ) return;
	event.stop();
 
}

function qtyEvents(){
	var E=$('cartlist').getElementsBySelector('.itemqty');
	E.each( function (e){ 
		e.observe('keypress', numbersOnly);
	});
}

function doPrice(){

}
function removeI(obj,num){
	var str='this item',td=$(obj).up().next();
	if (td) {
		var tmp=td.firstChild.innerHTML;
		str= (tmp==undefined) ? td.innerHTML:tmp;
	}
	if(confirm('Remove '+str+'?'))
		itemMore(num,1,'0');
}
function saveQty(e,num){
	if (!e) return;
	itemMore(num,1,'0'+e.value+'.');
}