function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

var checked = false;
var isOver = false;

function calcPrice(){
	qty = document.form1.Quantity.value * 1;
	
	if(qty < 5){
		per_pack = 100;
	}else if(qty > 4 && qty < 10){
		per_pack = 65;
	}else if(qty > 9 && qty < 25){
		per_pack = 50;
	}else if(qty > 24 && qty < 50){
		per_pack = 30;
	}else if(qty > 49 && qty < 100){
		per_pack = 25;
	}else if (qty > 99){
		per_pack = 18;
	}
	
	total_price = per_pack * qty;
	if(document.getElementById("Material").value == 'Material_Durable_Hi_Tack'){
		total_price = (total_price * 0.70).toFixed(2);
	}
	
	document.form1.secuitems.value = '[||Custom Asset Labels|'+per_pack+'.00|'+qty+'|'+total_price+'.00]';
	document.form1.transactionamount.value = total_price+'.00';
}

function start(){
	barcodeChange();
	changeColour();
}

function changeSize(size) {
	sizeLayer = document.getElementById("showLayer");
	barLayer = document.getElementById("barcodeLayer");
	heightLayer = document.getElementById("heightlayerid");
	lengthImagePic = document.getElementById("lengthImageId");
	if(size==1){	
		sizeLayer.style.width =250;
		sizeLayer.style.height =125;
		barLayer.style.width = 222;
		heightLayer.style.left = "660px";
		lengthImagePic.src = "38mm.gif";
	}else{
		sizeLayer.style.width =300;
		sizeLayer.style.height =150;
		barLayer.style.width = 262;
		heightLayer.style.left = "705px";
		lengthImagePic.src = "52mm.gif";
	}
}

function changeColour() {
	document.getElementById("showLayer").style.backgroundColor = document.all.Colour.value; 
	document.getElementById("labela").style.backgroundColor  = document.all.Colour.value;
	document.getElementById("labelb").style.backgroundColor  = document.all.Colour.value;
	document.getElementById("labelc").style.backgroundColor  = document.all.Colour.value;
	document.getElementById("labeld").style.backgroundColor  = document.all.Colour.value;
	document.getElementById("labele").style.backgroundColor  = document.all.Colour.value;
}

function capsLabel(){
	if(!checked){
		checked = true;
	}else{
		checked = false;
	}
}

function addText(val){
	if(val==0){
		document.all.labela.value = document.all.label1.value;
	}else if(val==1){
		document.all.labelb.value = document.all.label2.value;
	}else if(val==2){
		document.all.labelc.value = document.all.label3.value;
	}else if(val==3){
		document.all.labeld.value = document.all.label4.value;
	}else if(val==4){
		document.all.labele.value = document.all.label5.value;
	}
}

function barcodeChange(){
	barval = document.all.barcode.value;
	ob = document.getElementById("barcodeLayer"); 
	barbic = document.getElementById("bar");
	if(barval==1){
		ob.style.display="none";
		document.all.label4.readOnly= false;
		document.all.label5.readOnly= false;
		document.all.prefix.readOnly= true;
		document.all.starting.readOnly= true;
		document.all.suffix.readOnly= true;
	}else if(barval==2){
		ob.style.display="block";
		barbic.style.display="none";
		resetLastTwo();
	}else if(barval==3){
		ob.style.display="block";
		barbic.style.display="block";
		barbic.src = "barcode.gif";
		resetLastTwo();
	}else if(barval==4){
		ob.style.display="block";
		barbic.style.display="block";
		barbic.src = "barcode64.gif";
		resetLastTwo();
	}else if(barval==5){
		barbic.src="barcode128.gif";
		ob.style.display="block";
		barbic.style.display="block";
		resetLastTwo();
	}
}
function resetLastTwo(){
		document.all.label4.readOnly= true;
		document.all.label5.readOnly= true;
		document.all.label4.value="";
		addText(3);
		document.all.label5.value="";
		addText(4);
		document.all.prefix.readOnly= false;
		document.all.starting.readOnly= false;
		document.all.suffix.readOnly= false;
}
function addFix(){
	
	tot = document.all.prefix.value+""+document.all.starting.value+""+document.all.suffix.value;
	if(tot.length<=14){
		document.all.barcodefield1.value=tot;
		isOver = false;
	}else{
		if(!isOver){
			alert("You must enter a total of less than 14 characters");
		}
		isOver = true;
	}
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      	tota = document.all.prefix.value+""+document.all.starting.value+""+document.all.suffix.value;
		if(tota.length>14){
			errors+='- Your barcode must not be greater than 14 characters.\n';
		}
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  //calcPrice();
}
