// dynamic image centering
function ic(image,fullwidth,fullheight) {
	fromleft=0; fromtop=0;
	imgwidth=image.offsetWidth; imgheight=image.offsetHeight;
	if (imgwidth<fullwidth) {fromleft=((fullwidth-imgwidth)/2).toFixed(0);}; if (imgheight<fullheight) {fromtop=((fullheight-imgheight)/2).toFixed(0);}
	image.style.cssText='position: relative; left: '+fromleft+'px; bottom: '+fromtop+'px;';
}



// large image pop up
function pop(x) {
	window.open(x,'photo','scrollbars=no,width=640,height=720');
}

function bigpicF(file,wd,ht) { // for product-detail.php
	bigI=document.getElementById('largeI');
	bigI.src='/large/'+file+'.jpg'; bigI.style.width=wd+'px'; bigI.style.height=ht+'px';
	window.scroll(0,0);
}

// cart functions
function a2cF(id) {
	document.getElementById('a2c').value=id+'-PW-'+document.getElementById('SizePrice').selectedIndex+'-PW-'+'1'+'-P-W-';
}

function emptyF() {
	if (!confirm('Do you want to remove all items from your shopping cart?')) {
		return false;
	} else {
		document.form.empty.value='empty'; document.form.submit();
	}
}

function remF(rem) {
	document.form.rem.value=rem;
	document.form.submit();
}

function checkoutF() { 
	document.form.checkout.value='yes';
	document.form.submit();
}

function statefreightF(state) {
	if (state=='') {df.state.selectedIndex=9;} // so can't choose a state then go back and choose none, default to other
	if (state=='Western Australia' || state=='Northern Territory' || state=='Tasmania' || state=='Other') {statefactor=2;} else if (state=='New South Wales') {statefactor=1;} else {statefactor=1.5;}
	df=document.ccform;
	df.Freight.value=df.topFreight.value*statefactor;
	document.getElementById('freightbox').innerHTML=parseFloat(df.Freight.value).toFixed(2);
	document.getElementById('totalbox').innerHTML=(parseFloat(df.Freight.value)+parseFloat(df.Total.value)).toFixed(2);
}

function jumpF(box) {
	box.value=box.value.replace(/\D/g,'');
	if (box.value.length==4) {
		if (box.id=='CardNumber1') {next=2;} else if (box.id=='CardNumber2') {next=3;} else {next=4;}
		document.getElementById('CardNumber'+next).focus();
	}
}

function stopF(box) {
	box.value=box.value.replace(/\D/g,'');
	if (box.value.length==5) {box.value=box.value.substr(0,4);}
}

function cvvF() {
	if (document.getElementById('cvv').style.display=='none') {document.getElementById('cvv').style.display='inline';} else {document.getElementById('cvv').style.display='none';};
}

function payF(thisform,box) {
	// val address form	
	df=thisform; gopp=true;
	if (df.first_name.value.length<2) {alert('Please enter your name.'); df.first_name.focus(); gopp=false;} else {df.first_name.value=df.first_name.value.toLowerCase().replace(/\b(\w)/g,
function (w, p1) {return p1.toUpperCase(); });}; //capitalise
	if (df.last_name.value.length<2) {alert('Please enter your surname.'); df.last_name.focus(); gopp=false;} else {df.last_name.value=df.last_name.value.toLowerCase().replace(/\b(\w)/g,
function (w, p1) {return p1.toUpperCase(); });}; //capitalise
	if (df.address1.value.length<7) {alert('Please enter your Delivery address.'); df.address1.focus(); gopp=false;} else {df.address1.value=df.address1.value.replace(/\b(\w)/g,
	function (w, p1) {return p1.toUpperCase(); });}; //capitalise
	if (df.city.value.length<3) {alert('Please enter your Delivery address suburb.'); df.city.focus(); gopp=false;} else {df.city.value=df.city.value.toUpperCase();};
	df.zip.value=df.zip.value.replace(/\D/g,'');
	if (df.zip.value.length<4) {alert('Please enter 4-digit or more Delivery address postcode.'); df.zip.focus(); gopp=false;};
	if (df.state.value=='') {alert('Please select your Delivery address state.'); df.state.focus(); gopp=false;};
	df.night_phone_b.value=df.night_phone_b.value.replace(/\D/g,'');
	if (
		(df.night_phone_b.value.length!=9 && df.night_phone_b.value.length!=10 && df.state.value=='Other') || 
		(df.night_phone_b.value.length!=10 && df.night_phone_b.value!='Other') || 
		(df.night_phone_b.value.substr(0,1)!='0' && df.night_phone_b.value.substr(0,1)!='1')
	) { // break
		alert('Please enter your Delivery phone number correctly (including area code).\n\nMobile or site phone is acceptable.'); df.night_phone_b.focus(); gopp=false;
	}
	if (df.Email.value.length<6 || df.Email.value.lastIndexOf('@')<2 || (df.Email.value.length-df.Email.value.lastIndexOf('@'))<6 || (df.Email.value.length-df.Email.value.lastIndexOf('.'))<3 || df.Email.value.lastIndexOf('.')==-1) {alert('Please enter your email address correctly.'); df.Email.focus(); gopp=false;};

	// pre val cc here
	df.CardCVV.value=df.CardCVV.value	.replace(/\D/g,'');
	if (df.CardCVV.value.length<3) {alert('Please enter your full CVV number.'); df.CardCVV.focus(); gopp=false;}
	if (df.CardHolderName.value.length<3) {alert('Please enter the full name on the card.'); df.CardHolderName.focus(); gopp=false;}
	// number and expiry are pre-val'd
	if (gopp) {
		box.style.opacity=.3; box.style.filter='alpha(opacity=30)'; document.getElementById('paynowL').innerHTML='Please wait...';
		df.CardNumber.value=''+df.CardNumber1.value+df.CardNumber2.value+df.CardNumber3.value+df.CardNumber4.value;
		df.CardExpiry.value=df.CardExpiry1.value+df.CardExpiry2.value;
		return true;
	} else {
		return false;
	}
}


// specials star glow
function glowF() {
	if (direction=='down') { // minus jump
		val=val-jump;
	} else if (direction=='up') { // plus jump
		val=val+jump;
	} else { // pause set
		val=val;
	}
	document.getElementById('specI').style.filter='alpha(opacity='+val+')';
	document.getElementById('specI').style.opacity=val/100;
	cyc++; 
	if (cyc==(cycles-1) && direction=='pause') { // extra long pause
		cyc=1; direction='pause2';
	}
	if (cyc>cycles) { // end of set
		cyc=0; 
		if (direction=='down') { // hit bottom, go back up
			direction='up';
		} else if (direction=='up') { // hit top, pause for a set
			direction='pause';
		} else { // finished pause, go back down again
			direction='down';
		}
	} // end of set
	if (document.getElementById('debug')) {dbg='val: '+val+'. Cyc: '+cyc+'. Dir: '+direction+'<br />'; document.getElementById('debug').innerHTML+=dbg;};
} // glowF

cycles=8; // means distance combined with jump
jump=4; // 1 to 100
cyclespeed=45; // miliseconds
direction='down'; // down or up to start (oscillates, with pause?)
val=100; // starting opacity (IE)


// my menu system for product flyouts

/*
omv products link = show 00
omt products div = nomenu in 300, if not in a menudiv

omv any menu div and any link = cancel a no menu

omv sub link = hide all post col, show correct col

just need to fix - now that it slides out - check that has finished sliding (4 moves?) before getting new one, without cancelling new one!
*/
nomenuT=false; // so that it doesn't spit error msg when clearing
function menu(col,which,e) { // includes event capture for moz
	susmenu(); // cancel the hide, but pick them off specifically
	//soundManager.play('linksound','/1.mp3'); removed sound
	x=col; while (x<3) { // from current col to highest col number
		y=0; while (document.getElementById('menu'+x+y)) { // all possible subs(col1) or products(col2)
			document.getElementById('menu'+x+y).style.visibility='hidden'; // make everything after col hidden
			y++;
		}
		x++;
	}
	if (document.getElementById('menu'+col+which)) {
		thisMenu=document.getElementById('menu'+col+which); 
		thisMenu.style.left=(parseInt(thisMenu.offsetLeft)-220)+'px'; // put the nom menu behind it's left edge
		// thisMenu.style.top=(parseInt(tempY)-20)+'px'; // put the nom men at the height of the mouse minus the padding */ // old mouse height code
		if (false) { // col<2
			thisMenu.style.top=((which*36)+50)+'px'; // prev=which;
		} else {
			// thisMenu.style.top=((prev*45)+130)+'px';
			if (document.all) {
				tempY=event.clientY + document.body.scrollTop;
			} else {
				tempY=e.pageY;
			}
			thisMenu.style.top=(parseInt(((parseInt(tempY)-50)/36))*36)-110+'px'; // mouse location minus header + number of divlinks... + header again
			// alert('pity-50: '+(parseInt(tempY)-50)+' - then divide by 36, round, times 36, round, plus 50');
		}
		thisMenu.style.visibility='visible'; // make the nominated menu visible
		slx=0; goslides(col);
	} // end if menu exists (put in coz pulled out third level of menus - individual products)
}

function goslides(col) {
	if (slx<4) { // four moves, 55px each = 220px wide menu
		slx++; setTimeout("slidemenu("+col+");",34);
		// alert(thisMenu.offsetLeft);
	} else if (slx==4) { // run has just finished. confirm menus in correct spot!
		if (col==1) {thisMenu.style.left='178px';} else if (col==2) {thisMenu.style.left='401px';};
	} // else {alert(slx);};
}
function slidemenu(col) {
	thisMenu.style.left=(parseInt(thisMenu.offsetLeft)+55)+'px'; goslides(col); // alert(thisMenu.offsetLeft);
}
function nomenu() {
	nomenuT=setTimeout('clearmenus();',300); // wait until i've really moved off the div, then run hide all
}
function susmenu() {
	if (nomenuT) {
		clearTimeout(nomenuT); // cancel the existing 'hide all menus' command
	}
}

function clearmenus() {
	no=2; while (no>-1) { // 3 menu columns
		z=0; while (document.getElementById('menu'+no+z)) { // max 20 subs or products in each column
			document.getElementById('menu'+no+z).style.visibility='hidden'; // hide all menus
			// document.getElementById('menu'+no+z).style.left=; // put them back under the left edge, abs pos of 140, 300, 460, (160 wide each)
			z++;
		}
		no--;
	}
}

/* image expander/detracter, thanks to prlog.org. */
// use with onmouseover="sli(this)" onmouseout="ssi(this);" class="inl" 
// that is: .inl{display:inline;position:absolute;z-index:99;left:203} and include width/height attributes about .59(?) the size
var lwd=341,lht=199,swd=200,sht=117; // these were php'd in i'd say, but we could put calcs in!
var i,d,j=1,n=20,t=40;
function sli(ii){i=ii;d=1;rs();}
function ssi(ii){d=-1;rs();}
function xy(x1,x2,j){return (x2-x1)*j/n+x1;}
function rs(){
	i.style.width=xy(swd,lwd,j);i.style.height=xy(sht,lht,j);
	if(d>0 && n>j) {
		j++;setTimeout('rs()',t);
	} else if (0>d && j>0){
		j--;setTimeout('rs()',t);
	}
}