var pnp=1.95;
var pnp1=3.95;
var pnplim=10.00;
var pnplim1=75.00;
var ctime="";
var timob="";
var winW=0;
var winH=0;
var lpos=0;
var tpos=0;
function assignclass(cat){
	switch (cat){
	case 1: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#9ABBA4';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#9ABBA4';
		break;
	case 2: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#cb958f';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#cb958f';
		break;
	case 3: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#b398b7';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#b398b7';
		break;
	case 4: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#C8826C';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#C8826C';
		break;
	case 5: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#879EC3';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#879EC3';
		break;
	case 6: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#907ea8';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#907ea8';
		break;
	case 7: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#e9e3a5';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#e9e3a5';
		break;
	case 8: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#d3e0ae';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#d3e0ae';
		break;
	default: 
		document.getElementById('shopwindow').style.scrollbarShadowColor= '#999999';
		document.getElementById('shopwindow').style.scrollbarArrowColor= '#999999';
	}
}



function adjbasket(bcountjs){
	getTotalCost(bcountjs);
	discount(bcountjs);
}

function nondel(value,place){	
	if(isNaN(value) || parseInt(value) != value || value==0){
		alert("Please enter a valid quantity. If you wish to delete this item, please use the button on the right.");
		place.value=1;
	}
}


function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}


function discount(bcountjs){
	var disc=0;
	if(bcountjs){
			
		//if((parseFloat(document.carrier.totals.value))<=pnplim1){
		//	if(parseFloat(document.carrier.totals.value)<=pnplim){
		//		document.carrier.post.value=pnp1;
		//		}
		//		else{
		//			document.carrier.post.value=pnp;
		//			}
				
		//	document.getElementById('panp').style.display='block';
		//	}
		//	else{
		//		document.carrier.post.value=0;
		//		document.getElementById('panp').style.display='none';
		//	}
		
		//document.carrier.totals.value=formatAsMoney(parseFloat(document.carrier.totals.value)+parseFloat(document.carrier.post.value));
		
		document.valquant.forderval.value=document.carrier.totals.value;
		document.valquant.fpnp.value=formatAsMoney(document.carrier.post.value);
	}
}

function round (n) {
    	n = Math.round(n * 100) / 100;
    	n = (n + 0.001) + '';
    	return n.substring(0, n.indexOf('.') + 3);
}

function mymenu(loc){
	if(loc != 'catalogue'){
		parent.document.getElementById('main').src=loc+'.htm';
	}
	else{
		parent.document.getElementById('main').src='pages/'+loc+'.php';
	}
}

function mymenu_nw(loc){
	location=loc;
}

function mydata_nw(status,prod,cat,typename,xprod){
	document.trans.status.value=status;
	document.trans.prod.value=prod;
	document.trans.xprod.value=xprod;
	document.trans.cat.value=cat;
	document.trans.typename.value=typename;
	if(document.getElementById('shopwindow') && document.getElementById('shopwindow').scrollTop > 0){
		document.trans.vpos.value=document.getElementById('shopwindow').scrollTop;
		}
	document.trans.submit();
}

function index_mydata_nw(status,prod,cat,typename){
	document.trans.status.value=status;
	document.trans.prod.value=prod;
	document.trans.indexcat.value=cat;
	document.trans.typename.value=typename;
	document.trans.submit();
}

function index_mydata_nw_topbar(status,prod,cat,typename){
	document.trans.action='../pages/catalogue.php';
	document.trans.status.value=status;
	document.trans.prod.value=prod;
	document.trans.indexcat.value=cat;
	document.trans.typename.value=typename;
	document.trans.submit();
}

function mydata(loc){
		location=loc;
}

function basket_mydata(loc){
		document.valquant.loc.value=loc;
		document.valquant.submit();
}

function basket_mydata_nw(status,prod,cat,typename){
	document.valquant.status.value=status;
	document.valquant.prod.value=prod;
	document.valquant.cat.value=cat;
	document.valquant.typename.value=typename;
	document.valquant.action='catalogue.php';
	document.valquant.submit();
}

function move(loc,mod){
		trans.action=loc;
		trans.mode.value=mod;
		trans.submit()
}

function move1(mod,cat){
		trans.catid.value=cat;
		trans.typeid.value=0;
		trans.productid.value=0;
		trans.mode.value=mod;
		
		trans.submit()
}

function move2(mod,type){
		trans.typeid.value=type;
		trans.productid.value=0;
		trans.mode.value=mod;
		
		trans.submit()
}

function move3(mod,prod){
		trans.productid.value=prod;
		trans.mode.value=mod;
		
		trans.submit()
}

function ed4(mod,code){
		trans.code.value=code;
		trans.view.value=4;
		trans.mode.value=mod;
		trans.panel.value='edpanel4';
		
		trans.submit()
}

function ed3(mod){
		trans.view.value=3;
		trans.mode.value=mod;
		trans.panel.value='edpanel3';
		trans.submit()
}

function ed2(mod){
		trans.view.value=2;
		trans.mode.value=mod;
		trans.panel.value='edpanel2';
		
		trans.submit()
}

function ed1(mod){
		trans.view.value=1;
		trans.mode.value=mod;
		trans.panel.value='edpanel1';
		
		trans.submit()
}
 
function displaypanel(panel){
	document.getElementById(panel).style.display='block';
	document.getElementById(panel+'a').style.display='block';
}

function buyit(typename,code,price,status,prod,prodname,cat,xprod){
	
	document.sale.code.value=code;
	document.sale.price.value=price;
	document.sale.typename.value=typename;
	document.sale.prodname.value=prodname;
	document.sale.prod.value=prod;
	document.sale.xprod.value=xprod;
	document.sale.status.value=status;
	document.sale.cat.value=cat;
	document.sale.vpos.value=document.getElementById('shopwindow').scrollTop;
	
	
	document.sale.submit();
}

function getTotalCost (bcountjs) {
	totalCost = 0;
	for (i = 4; i < 7*bcountjs; i += 7) {
		totalCost += parseFloat(document.valquant[i].value * document.valquant[i-1].value);
	}
	document.carrier.totals.value = round(totalCost);
	
}

function getTotalCostad (bcountjs) {
	totalCost = 0;
	for (i = 4; i < 5*bcountjs; i += 6) {
		totalCost += parseFloat(document.valquant[i].value) * parseFloat(document.valquant[i+1].value);
		alert(document.valquant[i].value+' - '+document.valquant[i+1].value)
	}
	payf.orderval.value = round(totalCost);
	valquant.orderval.value = round(totalCost);
	
}

function organicalc(){
	if(prodform.organic.value==0){
		prodform.organic.value=1;
	}
	else{
		prodform.organic.value=0;
	}
}

function newincalc(){
	if(prodform.newin.value==0){
		prodform.newin.value=1;
	}
	else{
		prodform.newin.value=0;
	}
}

function updatecalc(){
	if(prodform.updated.value==0){
		prodform.updated.value=1;
	}
	else{
		prodform.updated.value=0;
	}
}

function displayswap(one,two){
	if(document.getElementById(one).style.display=='none'){
		document.getElementById(one).style.display='block';
		document.getElementById(two).style.display='none';
	}
	else{
		document.getElementById(one).style.display='none';
		document.getElementById(two).style.display='block';
	}
}

function labeldisplayswap(one,two,three){
	document.getElementById('labelchoiceview').style.display='none';
	if(three=='C5')
	{
		if(document.getElementById(one).style.display=='none'){
			document.getElementById(one).style.display='block';
			document.getElementById('labelview1').style.display='block';
			document.getElementById('labelview2').style.display='none';
			document.getElementById(two).style.display='none';
		}
		else{
			document.getElementById(one).style.display='none';
			document.getElementById('labelview1').style.display='none';
			document.getElementById('labelview2').style.display='block';
			document.getElementById(two).style.display='block';
		}
	}else{
		if(document.getElementById(one).style.display=='none'){
			document.getElementById(one).style.display='block';
			document.getElementById('labelview2').style.display='block';
			document.getElementById('labelview1').style.display='none';
			document.getElementById(two).style.display='none';
		}
		else{
			document.getElementById(one).style.display='none';
			document.getElementById('labelview2').style.display='none';
			document.getElementById('labelview1').style.display='block';
			document.getElementById(two).style.display='block';
		}
	}
}

function orderprint(){
	
	if(fork=confirm('Print this order?')){
		print()
	}
}

function envelopeprint(){
	
	if(pork=confirm('Print this envelope?')){
		print()
	}
}

function labelchoice(){
	envtype.envchoice[0].checked=false;
	envtype.envchoice[1].checked=false;
	document.getElementById('labelchoiceview').style.display='block';
}

function labelprint(){
	
	if(fork=confirm('Print this label?')){
		print()
	}
}

function getMail(){
	document.getElementById('emailhead').style.color='#333333';
	document.getElementById('emailhead').style.textAlign='left';
	document.getElementById('emailhead').style.fontWeight='400';
	displayswap('personal','emailform');
	document.getElementById('emailhead').innerText='Type a message for customer and click \'S\' button to send';
	mailbox1.value='';
	document.getElementById('sendbutton').style.display='block';
	document.getElementById('emailhead2').style.display='block';
}

function sendeMail(){
	mailf.mailbox.value=mailbox1.value;
	mailf.submit();
}

function stripCharString (InString, CharString)  {
	OutString="";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar=InString.substring (Count, Count+1);
		Strip = false;
		for (Countx = 0; Countx < CharString.length; Countx++) {
			StripThis = CharString.substring(Countx, Countx+1)
			if (TempChar == StripThis) {
				Strip = true;
				break;
			}
		}
		if (!Strip)
			OutString=OutString+TempChar;
	}
	return (OutString);
}

function unencrypt(){
	var myText="";
	mess='140122133126140089141122134122139136139128122135130124140071124136071142132';
	len=mess.length;
	inc=len/3;
	for(x=0;x<len;x+=3){
		myText=myText+"&#"+eval(mess.substring(x,x+3)-inc)+";";
		}	
	return("<a href='mailto:"+myText+"' onMouseover='window.status=\"\"; return true'>"+myText+"</a>")
}

function cartshow(){
	winsize();
	findcenter('width=425 height=50');
	
	document.getElementById('basketshow').style.left=lpos;
	document.getElementById('basketshow').style.top=tpos;
	
	document.getElementById('basketshow').style.display='block';
}

function stockshow(){
	document.getElementById('basketshow').style.display='none';
}

function winsize(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
 			}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			}
	}
}

function findcenter(sizestring){
	var myReg= new RegExp("width=(.*) height=(.*)");
	var results= sizestring.match(myReg);
	
	lpos=Math.round(parseFloat((winW-results[1])/2));
	tpos=Math.round(parseFloat((winH-results[2])/2));
}

function getbrowser(){
	alert(window.navigator.appName);
	alert(window.navigator.userAgent);
	//if(navigator.appName == "WebTV")
	//{
	 //alert("You're using the WebTV browser.")
	//}
	 //if(navigator.appName == "Netscape")
	//{
	 //alert("You're using a Netscape browser.")
	//}
	 //if(navigator.appName == "Microsoft Internet Explorer")
	//{
	// alert("You're using the Internet Explorer browser.")
	//}
}

function greyup2(a){
	a.style.color='#cccccc';
}

function greydown2(a){
	a.style.color='#666666';
}

function nav1(oldc,Obj){
	if(Obj){
		oldcolor=oldc;
		Obj.style.color='#69C2E2';
	}
}

function nav2(Obj){
	if(Obj){
		Obj.style.color=oldcolor;
		Obj.style.fontWeight=400;
	}
}

function checkouthover(){
	document.getElementById('gotocheckout').src="../images/checkout1.jpg";
}

function checkoutunhover(){
	document.getElementById('gotocheckout').src="../images/checkout.jpg";
}

function chequehover(){
	document.getElementById('cheque').src="../images/cheque1.jpg";
}

function chequeunhover(){
	document.getElementById('cheque').src="../images/cheque.jpg";
}

function cardhover(){
	document.getElementById('card').src="../images/card1.jpg";
}

function cardunhover(){
	document.getElementById('card').src="../images/card.jpg";
}

function backhover(){
	document.getElementById('back').src="../images/back1.jpg";
}

function backunhover(){
	document.getElementById('back').src="../images/back.jpg";
}

function nexthover(){
	document.getElementById('next').src="../images/next1.jpg";
}

function nextunhover(){
	document.getElementById('next').src="../images/next.jpg";
}

function back1hover(){
	document.getElementById('back1').src="../images/back1.jpg";
}

function back1unhover(){
	document.getElementById('back1').src="../images/back.jpg";
}

function next1hover(){
	document.getElementById('next1').src="../images/next1.jpg";
}

function next1unhover(){
	document.getElementById('next1').src="../images/next.jpg";
}

function back2hover(){
	document.getElementById('back2').src="../images/back1.jpg";
}

function back2unhover(){
	document.getElementById('back2').src="../images/back.jpg";
}

function clearhover(){
	document.getElementById('clear').src="../images/clear1.jpg";
}

function clearunhover(){
	document.getElementById('clear').src="../images/clear.jpg";
}

function clear1hover(){
	document.getElementById('clear1').src="../images/clear1.jpg";
}

function clear1unhover(){
	document.getElementById('clear1').src="../images/clear.jpg";
}

function submithover(){
	document.getElementById('submit').src="../images/submit1.jpg";
}

function submitunhover(){
	document.getElementById('submit').src="../images/submit.jpg";
}

function swapimg(code,loca){
	document.getElementById(loca).innerHTML="<img src='../images/"+code+"_m.jpg' width=200px style=\"border: 1px #666666 solid\"><br><br>Click on Colour Panel to change image";
}

function startimeradd(oBj){
	timob=oBj;
	countplus();
}

function startimersub(oBj){
	timob=oBj;
	countminus();
}

function countplus(){
	var inc=parseInt(document.getElementById(timob).value);
	if(inc<100)
	inc++;
	document.getElementById(timob).value=parseInt(inc);
	document.sale.newquant.value=parseInt(inc);
	if(inc<100){
		document.onmouseup = stopcount;
		ctime=setTimeout("countplus()",200);
		}
}

function countminus(){
	var inc=parseInt(document.getElementById(timob).value);
	if(inc>1)
	inc--;
	document.getElementById(timob).value=parseInt(inc);
	document.sale.newquant.value=parseInt(inc);
	if(inc>1){
		document.onmouseup = stopcount;
		ctime=setTimeout("countminus()",200);
		}
}

function stopcount(){
	clearTimeout(ctime);
	ctime="";
}

function showimage(){
	winsize();
	findcenter('width=300 height=200');
	document.getElementById('imagediv').style.posLeft=lpos;
	document.getElementById('imagediv').style.posTop=tpos;
	document.getElementById('imagediv').style.display='block';
}

function divgo(){
	document.getElementById('pichoose').src='../images/newimage.jpg';
	document.getElementById('imagediv').style.display='none';
}

function winsize(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
 			}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			}
	}
}

function findcenter(sizestring){
	var myReg= new RegExp("width=(.*) height=(.*)");
	var results= sizestring.match(myReg);
	
	lpos=Math.round(parseFloat((winW-results[1])/2));
	tpos=Math.round(parseFloat((winH-results[2])/2));
}

function formsub(oBj){
	var regEx = new RegExp ('[a-zA-Z_0-9 ]+\.jpg$', 'gi') ;
	var picstring = unescape(document.getElementById('pichoose').src);
	picstring=picstring.match(regEx);
	
	if(oBj.imagetitle.value=='' || oBj.imagefile.value=='' || picstring == 'newimage.jpg'){
		alert('please select image file');
	}
	else{
		oBj.submit();
	}
}

function revealpic(){
	if(picdesc=="1"){
		document.getElementById('pichoose').src=document.getElementById('imagefile').value;
		picdesc="0";
		document.getElementById('imagefile').blur();
		
	}
	else{
		picdesc="1";
	}
}

function viewimg(pic){
	var newcontent=pic;
	var finalcontent=imgtemplate.replace(/content/gi,newcontent);
	
	winsize();
	findcenter('width=300 height=200');
	document.getElementById('medimagediv').style.posLeft=lpos;
	document.getElementById('medimagediv').style.posTop=tpos;
	document.getElementById('medimagediv').innerHTML=finalcontent;
	document.getElementById('medimagediv').style.display='block';
}

function copyimg(imgfile){
	if(mark=confirm('Do you wish to copy '+imgfile+' to the Newsletter Folder?')){
		packform.copyimage.value=1;
		packform.imgfile.value=imgfile;
		packform.submit();
	}
}

function closediv(oBj){
	document.getElementById(oBj).style.display='none';
}

function delimage(imgfile){
	if(mark=confirm('Do you wish to erase '+imgfile+'?')){
		packform.delimage.value=1;
		packform.imgfile.value=imgfile;
		packform.submit();
	}
}