/**
 * @author daniel
 */
	var error_msg = "";
	var focus_set = 0;
	var stop = 0;

function setScreen() {
	//var container = document.getElementById('container');
	var content = document.getElementById('content');
	var newHeight = windowHeight() - 170;
	content.style.minHeight = newHeight + "px";
	//alert (windowHeight());
	//alert (content.clientHeight);

	if (!(typeof( window.innerHeight ) == 'number')) { //if it's not a non-ie browser
		if (content.clientHeight < newHeight) {
			content.style.height = (newHeight - 50) + "px";
		}  
	} 
	
	if ((gup('page') == "home") || (gup('page') == "") ) {
		document.getElementById('we_work_for').style.visibility = "visible";}

}

function windowHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && (document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }

  return myHeight;
}

function SubmitContactForm() {
	
	f_name = document.getElementById('f_name');
	l_name = document.getElementById('l_name');
	b_name = document.getElementById('b_name');
	email = document.getElementById('email');
	phone = document.getElementById('phone');
	fax = document.getElementById('fax');
	address = document.getElementById('address');
	city = document.getElementById('city');
	state = document.getElementById('state');
	zip = document.getElementById('zip');
	heard_how = document.getElementById('heard_how');
	heard_how_other = document.getElementById('heard_how_other');
	contact_time = document.getElementById('contact_time');
	contact_time_other = document.getElementById('contact_time_other');
	comments = document.getElementById('comments');
	msg = document.getElementById('message');
	msg2 = document.getElementById('message2');
	emergency = document.getElementById('emergency');

	// Reset variables
	error_msg = "";
	focus_set = 0;
	stop = 0;

	//Reset any backgrounds for the following fields
	var fields = ['f_name','l_name','phone','fax','email','heard_how_other','contact_time_other'];
	clear_backgrounds(fields);
	
	// Check for required fields
	if (f_name.value == "") {field_error(f_name,"Please enter a first name.");}
	if (l_name.value == "") {field_error(l_name,"Please enter a last name.");}	
	if (phone.value == "") {field_error(phone,"Please enter a phone number.");}

	//Verify Phone Number
	var phone_num = stripAlphaChars(phone.value);
	if ((phone_num.length != 10) & (phone_num.length != 11)) {field_error(phone,"Enter a valid phone number");}

	//Verify fax Number only if something is entered
	if (fax.value != "") {
		var fax_num = stripAlphaChars(fax.value);
		if ((fax_num.length != 10) & (fax_num.length != 11)) {
			field_error(fax, "Enter a valid fax number");
		}
	}

	//Verify zip code only if something is entered
	if (zip.value != "") {
		var zip_code = stripAlphaChars(zip.value);
		if (zip_code.length != 5) {
			field_error(zip, "Please enter a valid 5 digit zip code.");
		}
	}
	
	//If other is selected, make sure somethign was entered
		//heard how other
		if (heard_how.value == "Other") {
			if (heard_how_other.value == "") {field_error(heard_how_other,"Please tell us how you heard about us.");}
		}

		//contact method other
		if (contact_time.value == "Other") {
			if (contact_time_other.value == "") {field_error(contact_time_other,"Please tell us when we can contact you.");}
		}


	if (stop == 0) { //If everything checks ok, submit the form
	 	AjaxRequest.post({
		'url': 'actions.php',
		'contact_form': "yes",
		'f_name': f_name.value,
		'l_name': l_name.value,
		'b_name': b_name.value,
		'phone': phone.value,
		'fax': fax.value,
		'email': email.value,
		'address': address.value,
		'city': city.value,
		'state': state.value,
		'zip': zip.value,
		'heard_how': heard_how.value,
		'heard_how_other': heard_how_other.value,
		'contact_time': contact_time.value,
		'contact_time_other': contact_time_other.value,
		'comments': comments.value,
		'emergency': emergency.checked,
		'onSuccess': function(req){
			var contact_us = document.getElementById('contact_us');
			contact_us.innerHTML = req.responseText;
			}
		});
	}
	else if (stop == 1) { //There is some error, display the messages
		msg.innerHTML = error_msg;
		msg2.innerHTML = error_msg;
	}
 }


function clear_backgrounds(ids) { 
//Clears the element background style for every element ID in the arrary ids
	
	for (i=0; i<ids.length; i++) {
		var id = document.getElementById(ids[i]);
		id.style.background = "";
	}	
}

function field_error(field_id,msg) {
//This adds the specified error message to the error string and sets the background for the element to a shade of red
		error_msg = error_msg + msg + "<br />";
		field_id.style.background = "#fa5b5b";
		if (focus_set == 0) {
			field_id.focus();
			focus_set = 1;
			}
		stop = 1;
}

function stripAlphaChars(pstrSource) 
{ 
var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 
    return m_strOut; 
}
 
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function ShowElement(photoid)
{
	//Go through and make sure the rest of these are hidden first
	for(i=1; i<=10; i++) { 
		var div_id = document.getElementById('large' + i);
		div_id.style.visibility = "hidden";
	}

	//Now show the one we want to see
	var div_id = document.getElementById(photoid);
	div_id.style.visibility = "visible";
}

function HideElement(photoid) {
	
	var div_id = document.getElementById(photoid);
	div_id.style.visibility = "hidden";
}

function ToggleOtherBox(select_id,other_id) {
	//alert("*" + select_id + "* *" + other_id + "*");

	var select_id = document.getElementById(select_id);
	var other_id = document.getElementById(other_id);
	
	//alert(select_id.value);
	
	if (select_id.value == "Other") 
		{ other_id.style.visibility="Visible"; }
	else
		{ other_id.style.visibility="Hidden"; }
}

function ToggleJobPosting(select_id) {

	var select_id = document.getElementById(select_id);

	if (select_id.style.visibility == "hidden" || select_id.style.visibility == "") 
		{ select_id.style.visibility="visible";
		  select_id.style.display = "block"; }
	else
		{ select_id.style.visibility="hidden";
		select_id.style.display = "none"; }
}



