// JavaScript for New Hudson Motorcycles

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 hideInfo(item) {
	switch(item) {
    case "1":
       	 document.write("01325 721463");
       	 break;
    case "2":
       	 document.write("&nbsp; +44 1325 721463");
       	 break;
    default:
       	 document.write(" ");
       	 break;
	}
}

// Generate random "Form Validation Code" and enter it into the form on the contact.html page

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.nhmForm.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 cryear() {
  copyright=new Date();
  yearnow=copyright.getFullYear();
  document.write(yearnow);
}

function checkExtension() {
	var attFile = document.nhmForm.photo.value;
//	alert(attFile);
	if(attFile == "") {return true;}
	else {
		var position = attFile.lastIndexOf("\\"); // IE will give full path and file name.  Check for "/" in name.
		if (position > 0) {position += 1; attFile = attFile.substring(position); } // Extract just the filename
//	alert(attFile);
		var position = attFile.lastIndexOf(".");
		var ext = attFile.substring(position);
		ext = ext.toLowerCase(ext); // Force to lowercase for camparison
		if (ext == ".jpg" || ext == ".gif") {
//			nhmForm.photo.value = attFile;
//	alert(document.nhmForm.photo.value);
			return true;
		}
		else {alert("Sorry, I can only accept 'jpg' or 'gif' file types.");
				nhmForm.photo.value = "";
//	alert(document.nhmForm.photo.value);
				return false;
			 }
	}
}
