// javascript - nov_2007
// ryan yonzon <ryanyonzon@gmail.com>


//-----------------------
//	menu
//-----------------------
	navHover = function() {
		var lis = document.getElementById("navmenu-h").getElementsByTagName("LI");
		for (var i=0; i<lis.length; i++) {
			lis[i].onmouseover=function() {
				this.className+=" iehover";
			}
			lis[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", navHover);

//-----------------------
//	image hover effect
//-----------------------
	function hoverEffect(hide, show) {
		to_hide = document.getElementById(hide);
		to_show = document.getElementById(show);
		to_hide.style.display="none";
		to_show.style.display="block";
	}

//-----------------------
//	image hover effect
//-----------------------

// this array consists of the id attributes of the divs we wish to alternate between
var divs_to_fade = new Array('box1', 'box2', 'box3');		
// the starting index in the above array.
//It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var i = 0;
// the number of milliseconds between swaps.  Default is five seconds.
var wait = 10000;

	// the function that performs the fade
	function swapFade() {
		Effect.Fade(divs_to_fade[i], { duration:1, from:1.0, to:0.0 });
		i++;
		if (i == 3) i = 0;
		Effect.Appear(divs_to_fade[i], { duration:1, from:0.0, to:1.0 });
	}
	
	function doPulsate() {
		new Effect.Highlight('rightfloat');
	}

	// the onload event handler that starts the fading.
	function startPage() {
		setInterval('swapFade()',wait);
	}


//----------------------
// mailer
//----------------------

var form = "";
var error = false;
var error_message = "";
var submitted = false;

function check_mail_input(field_name, field_size, message) {

  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {

    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
  
}

function check_mail_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_mail_form(form_name) {

  form = form_name;
	
	error_message = "";
	check_mail_input("client_name", 2, "Full Name must contain a minimum of 4 characters.");
	check_mail_input("client_city", 5, "City must contain a minimum of 5 characters.");	
	check_mail_select("client_state", "", "You must select your state from the State pull down menu.");
	check_mail_input("client_phone", 5, "Phone must contain a minimum of 5 characters.");	
	check_mail_input("client_email", 5, "Email must contain a minimum of 5 characters.");	
	check_mail_input("client_message", 0, "No message inputed");	
	
  if (error == true) {
    alert(error_message);
	error = false;
    return false;
  } else {
	error = false;
    return true;
  }
  
}

function validate_mail_form() {

	var myForm = document.getElementById('mailer');
	var validation = check_mail_form(myForm);
	
	if(validation == true) {
		document.getElementById('mailer').submit();
		return true;
	} else {
		return false;		
	}

}
