function imageholderclass(){
	this.over=new Array();
	this.down=new Array();
	this.src=new Array();
	this.store=store;
	
	function store(src, down, over){
		var AL=this.src.length;
		this.src[AL]=new Image(); this.src[AL].src=src;
		this.over[AL]=new Image(); this.over[AL].src=over;
		this.down[AL]=new Image(); this.down[AL].src=down;
	}
}

var ih = new imageholderclass();
var mouseisdown=0;

function preloader(t){
	for(i=0;i<t.length;i++){
		if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
			
			storeimages(t[i]);
			var checker='';
			checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
			checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
			
			switch(checker){
			case 'A' : mouseover(t[i]);mouseout(t[i]); break;
			case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
			case 'AB' : mouseover(t[i]);mouseout(t[i]); mousedown(t[i]); mouseup(t[i]); break;
			default : return;			
			}
			
			if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
		}
	}
}
function mouseup(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");this.oldmouseup();}

	}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");}}
	t.onmouseup=newmouseup;
}

function mouseup2(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");this.oldmouseup();}
		}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");}}
	t.onmouseup = newmouseup;
}

function mousedown(t){
	var newmousedown;
	if(t.onmousedown){
		t.oldmousedown=t.onmousedown;
		newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");this.oldmousedown();}}
	}
	else{newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");}}}
	t.onmousedown=newmousedown;
}

function mouseover(t){
	var newmouseover;
	if(t.onmouseover){
		t.oldmouseover=t.onmouseover;
		newmouseover=function(){this.src=this.getAttribute("srcover");this.oldmouseover();}
	}
	else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
	t.onmouseover=newmouseover;
}

function mouseout(t){
	var newmouseout;
	if(t.onmouseout){
		t.oldmouseout=t.onmouseout;
		newmouseout=function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
	}
	else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
	t.onmouseout=newmouseout;
}

function storeimages(t){
	var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
	var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
	var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
	ih.store(s,d,o);
}

function preloadimgsrc(){
	if(!document.getElementById) return;
	var it=document.getElementsByTagName('IMG');
	var it2=document.getElementsByTagName('INPUT');
	preloader(it);
	preloader(it2);
}

if(window.addEventListener){window.addEventListener("load", preloadimgsrc, false);} 
else{
	if(window.attachEvent){window.attachEvent("onload", preloadimgsrc);}
	else{if(document.getElementById){window.onload=preloadimgsrc;}}
}

//FORM VALIDATION/////////////////////////////////////////////////////////////////////
function validate() {
  if(!document.getElementById) return;

  // get form variables
  var title = document.getElementById("title").value;
  var firstname = document.getElementById("firstname").value;
  var lastname = document.getElementById("lastname").value;
  var address1 = document.getElementById("address1").value;
  var address2 = document.getElementById("address2").value;
  var city = document.getElementById("city").value;
  var state = document.getElementById("state").value;
  var zipcode = document.getElementById("zipcode").value;
  var phone = document.getElementById("phone").value;
  var fax = document.getElementById("fax").value;
  var incorrect = new Array();
  var no = 0;
  var regExp = /[A-Za-z]{2,6}/;

  if(regExp.test(title)) {
   	title = title.charAt(0).toUpperCase() + title.substring(1,title.length).toLowerCase();
  } else {
   	incorrect[no] = "1";
   	no++;
   	title = "";
  }

  regExp = /[A-Za-z]{1,}/;
  if(regExp.test(firstname)) {
   	firstname = firstname.toUpperCase();
  } else {
   	incorrect[no] = "2";
  	 no++;
  	 firstname = "";
  }

  regExp = /[A-Za-z]{3,}-?[A-Za-z]?/;
  if(regExp.test(lastname)) {
   	lastname = lastname.charAt(0).toUpperCase() + lastname.substring(1,lastname.length).toLowerCase();
  } else {
   	incorrect[no] = "3";
  	 no++;
   	lastname = "";
  }

  if(address1.length < 5) {
   	incorrect[no] = "4";
   	no++;
   	address1 = "";
  }

  if(address2.length < 3) {
   	incorrect[no] = "5";
   	no++;
   	address2 = "";
  }
  if(city.length < 3) {
   	incorrect[no] = "6";
   	no++;
   	city = "";
  }
  if(state.length < 5) {
   	incorrect[no] = "7";
   	no++;
   	state = "";
  }

  if(zipcode.length < 5) {

   	incorrect[no] = "8";
   	no++;
   	zipcode = "";
  }

  if(phone.length < 7) {

   	incorrect[no] = "9";
   	no++;
   	phone = "";
  }
  if(fax.length < 7) {

   	incorrect[no] = "8";
   	no++;
   	fax = "";
  }

  for(i=1;i<11;i++) {
  		document.getElementById(i).style.color="#000000";
  }

  for(j=0;j<no;j++) {
  		document.getElementById(incorrect[j]).style.color="#FF0000";
  }

  if(no > 0) {
   	document.getElementById("errors").innerHTML = "<span class=\"error\">There was an error with your form submission. Please fill in the necessary fields.</span><br /><br />";
  }

  document.getElementById("title").value = title;
  document.getElementById("firstname").value = firstname;
  document.getElementById("lastname").value = lastname;
  document.getElementById("address1").value = address1;
  document.getElementById("address2").value = address2;
  document.getElementById("city").value = city;
  document.getElementById("state").value = state;
  document.getElementById("zipcode").value = zipcode;
  document.getElementById("phone").value = phone;
  document.getElementById("fax").value = fax;
}


