// JavaScript for KenKode 

var alpha = "abcdefghjkmnpqrstuvwxyz";
var numeric = "23456789"
var ranc0de = alpha.charAt(ranDom(0,22)) + alpha.charAt(ranDom(0,22))+numeric.charAt(ranDom(0,7))+alpha.charAt(ranDom(0,22))

function riteRan() {
	 writeLayer("raNdcd","<strong>"+ranc0de+"</strong>");
	 document.ContactForm.rcode.value = ranc0de;  // Sets value when on the Contact Form
}

function writeLayer(layerID, txt){  // Write text to the named layer using the correct code for visitor's browser.
	  if(document.getElementById){
		    document.getElementById(layerID).innerHTML=txt;
	  }
	  else if(document.all){
	      document.all[layerID].innerHTML=txt;
	  }
	  else if(document.layers){
	      with(document.layers[layerID].document){
	         open();
	         write(txt);
	         close();
	      }
	  }
}

function ranDom(x, y) {
  var range = y - x + 1;
  return Math.floor(Math.random() * range) + x;
}

function hideAddr(part1, part2, part3, text, subject) {  // Hide email addresses from spiders
//  To include body text, add it to the end of the variable "subject" seperated by a "?" character.
    document.write('<a href=\"mailto:' + part1 + '@' + part2 + '.' + part3);
	if (subject != "") {document.write('?subject='+subject); }  // Optional subject
	document.write('\" >');   // close off 'a' tag
    if (text == "asis") { document.write(part1 + '@' + part2 + '.' + part3); }
	  else              { document.write(text); }
    document.write('</a>');  
}

function hideTxt(idx) {  // Hide various pieces of information from spiders
	switch (idx) {
		case "1":
  			document.write("Ken McNaught<br>KenKode<br>41 Muirfield Drive<br>Thornes<br>Wakefield<br>WF2 8SH");
  			break;
		case "2":
  			document.write("01924 370580");
  			break;
		case "3":
  			document.write("07969 983422");
  			break;
		case "4":
  			document.write("xxx");
  			break;
		default:
  			document.write("Unexpected index value.  idx=" + idx);
		}
}

function cryear() {
  copyright=new Date();
  yearnow=copyright.getFullYear();
  document.write(yearnow);
}


// Scripts to process the Web Price Calculator form

function CalcForm() { 
    var totl = 0;
    var Site = radio_value(document.WebPrice.Site);
	totl = totl + eval(Site);
	Site = FormatAmt(Site);
	writeLayer("SiteVal",Site);
    var Land = radio_value(document.WebPrice.Land);
	totl = totl + eval(Land);
	Land = FormatAmt(Land);
	writeLayer("LandVal",Land);
    var Xtra = radio_value(document.WebPrice.Xtra);
	totl = totl + eval(Xtra);
	Xtra = FormatAmt(Xtra);
	writeLayer("XtraVal",Xtra);
    var Tmpl = radio_value(document.WebPrice.Tmpl);
	totl = totl + eval(Tmpl);
	Tmpl = FormatAmt(Tmpl);
	writeLayer("TmplVal",Tmpl);
    var LBox = radio_value(document.WebPrice.LBox);
	totl = totl + eval(LBox);
	LBox = FormatAmt(LBox);
	writeLayer("LBoxVal",LBox);
    var PayP = radio_value(document.WebPrice.PayP);
	totl = totl + eval(PayP);
	PayP = FormatAmt(PayP);
	writeLayer("PayPVal",PayP);
    var HitC = radio_value(document.WebPrice.HitC);
	totl = totl + eval(HitC);
	HitC = FormatAmt(HitC);
	writeLayer("HitCVal",HitC);
    var Stat = radio_value(document.WebPrice.Stat);
	totl = totl + eval(Stat);
	Stat = FormatAmt(Stat);
	writeLayer("StatVal",Stat);
    var Srch = radio_value(document.WebPrice.Srch);
	totl = totl + eval(Srch);
	Srch = FormatAmt(Srch);
	writeLayer("SrchVal",Srch);
    var xFrm = radio_value(document.WebPrice.xFrm);
	totl = totl + eval(xFrm);
	xFrm = FormatAmt(xFrm);
	writeLayer("xFrmVal",xFrm);
	
	totl = FormatAmt(totl);
	writeLayer("WebTotal","<big>"+totl+"</big>"); // Put final total into the total box on the form.
}

function radio_value(button) {
	for (var i=0; i < button.length; i++) {
	   if (button[i].checked) {
		  return button[i].value;
       }
    }
}

function FormatAmt(num) {
if (num == 0) {return "&nbsp;";}
if (isNaN(num)) {num = "0";}
num = Math.floor(num*100+0.50000000001);
pence = num%100;
num = Math.floor(num/100).toString();
if (pence<10) {pence = "0" + pence;}
return ('£' + num + '.' + pence);
}
