function validate_termite_threat_form() {
	var message = "";
	var blank_fields = "";

	// the method of using the id doesn't work in this case because the RedBox feature
	//   makes a copy of the existing form making the inputs no longer have a unique id

	var blank_required_fields = new Array("first_name",
										"last_name",
										"zip",
										"phone");

	// make sure a value is entered for each of the required fields
	var fields = document.getElementsByTagName("input");
	var state_fields = document.getElementsByTagName("select");
	var comments_fields = document.getElementsByTagName("textarea");

	num_blank_required_fields = blank_required_fields.length;

	num_fields = fields.length;
	for (i = 0; i < num_fields; i++) {
		if (fields[i].value) {
			// remove field from blank required fields
			for (j = 0; j < num_blank_required_fields; j++) {
				if (blank_required_fields[j] == fields[i].name) {
					blank_required_fields[j] = "";
					break;
				}
			}
		}
	}

	num_state_fields = state_fields.length;
	for (i = 0; i < num_state_fields; i++) {
		if (state_fields[i].value) {
			// remove field from blank required fields
			for (j = 0; j < num_blank_required_fields; j++) {
				if (blank_required_fields[j] == state_fields[i].name) {
					blank_required_fields[j] = "";
					break;
				}
			}
		}
	}

	num_comments_fields = comments_fields.length;
	for (i = 0; i < num_comments_fields; i++) {
		if (comments_fields[i].value) {
			// remove field from blank required fields
			for (j = 0; j < num_blank_required_fields; j++) {
				if (blank_required_fields[j] == comments_fields[i].name) {
					blank_required_fields[j] = "";
					break;
				}
			}
		}
	}


	blank_fields = "";
	
	for (i = 0; i < num_blank_required_fields; i++) {
		if (blank_required_fields[i]) {
			var field_name = blank_required_fields[i];
			var display_name = "";

			switch (field_name) {
				case "first_name":
					display_name = "First Name";
					break;
				case "last_name":
					display_name = "Last Name";
					break;
				case "address1":
					display_name = "Address";
					break;
				case "city":
					display_name = "City";
					break;
				case "state":
					display_name = "State";
					break;
				case "zip":
					display_name = "Zip Code";
					break;
				case "phone":
					display_name = "Phone";
					break;
				case "email":
					display_name = "Email";
					break;
				case "comments":
					display_name = "Comments";
					break;
			}

			blank_fields += display_name + "\n";
		}
	}

	if (blank_fields) {
		message = "The following required fields were left blank:\n" + blank_fields;
		alert(message);
		return false;
	}
	else {
		return true;
	}
}


function validate_contact_form() {
	var message = "";
	var blank_fields = "";

	// the method of using the id doesn't work in this case because the RedBox feature
	//   makes a copy of the existing form making the inputs no longer have a unique id

	var required_fields = new Array("contact_first_name",
										"contact_last_name",
										"contact_email",
										"contact_phone",
										"contact_email",
										"contact_zip",
										"contact_comments");

	var num_required_fields = required_fields.length;
	for (i = 0; i < num_required_fields; i++) {
		var field = document.getElementById(required_fields[i]);



		if (field.value == "") {

			alert(required_fields[i] + " " + field.value);

			var field_name = required_fields[i];
			var display_name = "";

			switch (field_name) {
				case "first_name":
					display_name = "First Name";
					break;
				case "last_name":
					display_name = "Last Name";
					break;
				case "phone":
					display_name = "Phone";
					break;
				case "email":
					display_name = "Email";
					break;
				case "comments":
					display_name = "Comments";
					break;
			}

			blank_fields += display_name + "\n";
		}
	}

	if (blank_fields) {
		message = "The following required fields were left blank:\n" + blank_fields;
		alert(message);
		return false;
	}
	else {
		return true;
	}
}


var agent = navigator.userAgent.toLowerCase();
var is_ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));

function boxes_to_down_position() {
	document.boxes.SetVariable('send_command_text', 'boxes down');
}

function open_url(box_clicked) {
	//alert(box_clicked);
	switch (box_clicked) {
		case "schedule_service":
			window.location = "/customer_service/schedule_service.php";
//			RedBox.showInline('schedule_service', true);
			break;
			case "schedule_service_fl":
			window.location = "/customer_service/schedule_service.php";
//			RedBox.showInline('schedule_service_fl', true);
			break;
		case "customer_service":
			window.location = "/customer_service/customer_service.php";
			break;
		case "termite_control":
			window.location = "/termite_control/termite_control.php";
			break;
		case "pest_control":
			window.location = "/pest_control/pest_control.php";
			break;
		case "preventive_buzz":
			window.location = "/buzz/";
			break;
	}
}


var current_page = null;
function highlight_selected_link() {
	var selected_link = document.getElementById(current_page);
	if (selected_link)
		selected_link.className = "nav_link_selected";

	var selected_cell = document.getElementById(current_page + "_cell");
	if (selected_cell)
		selected_cell.className = "sub_nav_cell_selected";

	var selected_cellBackground = document.getElementById (current_page + "_Background");
	if (selected_cellBackground)
		selected_cellBackground.className = "nav_link_selected";
}

var all_elements = new Array();
var element_state = new Array();
var elements = new Array();
var elements_loaded = false;
var timeOut = new Array();
var last_selected = null;

var timeOutExtended = new Array();


var debug = false;

function init_highlight_elements(){
	for(i=0; i<all_elements.length; i++){
		elements[i] = document.getElementById(all_elements[i]+"Background");
		element_state[i] = "faded";
	}
}

var clear_highlight_delay = 500;

var debug_message;

function highlight_hovered_link(element_id){
	if (element_state[element_id] == "highlighted")
		return false;

	element_state[element_id] = "highlighted";

	// clear all others
	var num_elements = element_state.length;
	for (i = 0; i < num_elements; i++) {
		if (i != element_id) {
			element_state[i] = "need_to_clear";

			if (!timeOutExtended[i])
				timeOutExtended[i] = new Array();


			if (i == 0)
				//timeOut[i] = setTimeout("clear_highlight(0, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(0, false);", clear_highlight_delay));
			else if (i == 1)
				//timeOut[i] = setTimeout("clear_highlight(1, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(1, false);", clear_highlight_delay));
			else if (i == 2) {
				//timeOut[i] = setTimeout("clear_highlight(2, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(2, false);", clear_highlight_delay));
				//if (debug)
					//alert("hide " + timeOut[i]);
			}
			else if (i == 3)
				//timeOut[i] = setTimeout("clear_highlight(3, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(3, false);", clear_highlight_delay));
			else if (i == 4)
				//timeOut[i] = setTimeout("clear_highlight(4, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(4, false);", clear_highlight_delay));
			else if (i == 5)
				//timeOut[i] = setTimeout("clear_highlight(5, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(5, false);", clear_highlight_delay));
			else if (i == 6)
				//timeOut[i] = setTimeout("clear_highlight(6, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(6, false);", clear_highlight_delay));
			else if (i == 7)
				//timeOut[i] = setTimeout("clear_highlight(7, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(7, false);", clear_highlight_delay));
			else if (i == 8)
				//timeOut[i] = setTimeout("clear_highlight(8, false);", clear_highlight_delay);
				timeOutExtended[i].push(setTimeout("clear_highlight(8, false);", clear_highlight_delay));


			//if (element_state[i] == "highlighted") {

			//}
		}
	}

	if (debug) {
		//alert("element_id " + element_id);
		//if (element_id == 2)
			//alert("show " + timeOut[2]);
		//debug_message += "clearing timeout for " + element_id + "\n";
	}

	if (timeOutExtended[element_id])
		num_timeouts = timeOutExtended[element_id].length;
	else
		num_timeouts = 0;

	for (i = 0; i < num_timeouts; i++) {
		//if (debug)
			//alert(timeOutExtended[element_id][i]);

		clearTimeout(timeOutExtended[element_id][i]);
		timeOutExtended[element_id][i] = null;
	}

	clearTimeout(timeOut[element_id]);
	Effect.Appear(all_elements[element_id]+"Background",{duration:0.2});
	highlight_index = element_id;
	elements[element_id].style.top = findPosY(all_elements[element_id]) + "px";

	last_selected = element_id;
}

function clear_highlight(element_id, wait_to_clear){
	if (wait_to_clear){
		if (!timeOutExtended[element_id])
			timeOutExtended[element_id] = new Array();

		element_state[element_id] = "need_to_clear";
		//timeOut[element_id] = setTimeout("clear_highlight("+element_id+", false)",200);
		timeOutExtended[element_id].push(setTimeout("clear_highlight("+element_id+", false)",200));
	}
	else{
		if (element_state[element_id] == "need_to_clear"){
			//timeOut[element_id] = setTimeout("Effect.Fade(elements["+element_id+"],{duration:0.2})", 250);
			Effect.Fade(elements[element_id],{duration:0.2});
			//Effect.Fade(elements[element_id],{duration:0.2});
		}
	}
}

function clear_timeouts(element_id) {
	if (timeOutExtended[element_id])
		num_timeouts = timeOutExtended[element_id].length;
	else
		num_timeouts = 0;

	for (i = 0; i < num_timeouts; i++) {
		clearTimeout(timeOutExtended[element_id][i]);
		timeOutExtended[element_id][i] = null;
	}
}

/*
function clear_highlight_all() {
	var num_menu_items = element_state.length
	for (i = 0; i < num_menu_items; i++) {
		if (last_selected != i)
			clear_highlight(i, true);
	}
}
*/

function findPosY(element_id){
	var obj = document.getElementById(element_id);


    var curtop = document.getElementById(element_id).offsetTop;
    var tempEl = document.getElementById(element_id).offsetParent;

    while (tempEl != null) {
        curtop += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }

	if (saf) {
		// if selected
		if (obj.className.indexOf("selected") != -1)
			curtop -= 15;
		else
			curtop -= 18;
	}



	if (debug)
		alert(curtop + " " + element_id);

	return curtop;
}

/*
function getMenuY(element_id) {
    var header = document.getElementById("header");
    var navbar = document.getElementById("navbar");

    var yPos = document.getElementById(element_id).offsetTop;
    var tempEl = document.getElementById(element_id).offsetParent;

    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }

    // vertical offset for submenus
    var isSubMenu = false;
    if (element_id == "volunteer"
            || element_id == "volunteer2"
            || element_id == "programs"
            || element_id == "swap"
            || element_id == "education_exhibitions") {
        isSubMenu = true;
    }

    if (isSubMenu) {
        yPos = yPos - 5;
    }

    return yPos;
}
*/



// Pest flash links
function link_to(pest) {
	if (pest == "termites") {
		window.location = "/termite_control/termite_control.php";
		return false;
	}

	var default_pest_link = "";
	switch (pest) {
		case "rodents":
			default_pest_link = "/pest_control/pest_database/details.php?id=1&name=Deer Mice";
			break;
		case "cockroaches":
			default_pest_link = "/pest_control/pest_database/details.php?id=7&name=American Roaches";
			break;
		case "scorpions":
			default_pest_link = "/pest_control/pest_database/details.php?id=13&name=Scorpions";
			break;
		case "spiders":
			default_pest_link = "/pest_control/pest_database/details.php?id=10&name=Black Widows";
			break;
		case "wasps_and_bees":
			default_pest_link = "/pest_control/pest_database/details.php?id=14&name=Wasps";
			break;
		case "ants":
			default_pest_link = "/pest_control/pest_database/details.php?id=4&name=Carpenter Ants";
			break;
		case "termites":
		case "pigeons":
		default:
	}

	if (default_pest_link) {
		document.getElementById('pest_details').src = default_pest_link;

		document.getElementById('pest_sub_page').src = 'pest_database/' + pest;

		pest_points_plain_text(pest, true);
	}
}

// Pest Points
function pest_points(type) {
	var text;
	var index = Math.floor(Math.random()*20);

	if (type == "termites") {
		index = index % 5;
		if (index == 0)
			text = "Termites can live for 15 years.";
		else if (index == 1)
			text = "Termites will not only eat wood, they will eat anything made from wood.";
		else if (index == 2)
			text = "Termites have been known to cause over $1.5 billion worth of damage in the US each year.";
		else if (index == 3)
			text = "Termites can enter your home through a crack as thin as a piece of paper.";
		else
			text = "Termites have been around for more than 250 million years.";
	}
	if (type == "spiders") {
		index = index % 8;
		if (index == 0)
			text = "The female black widow eats the male black widow after mating.";
		else if (index == 1)
			text = "The black widow is the most poisonous spider in the United States.";
		else if (index == 2)
			text = "Webs get dirty and torn, so lots of spiders make a new one every day. They don't waste the old one, though--they roll it up into a ball and eat it.";
		else if (index == 3)
			text = "When a black widow bites a human the venom will cause muscle aches, nausea, and a paralysis of the diaphragm that can make breathing difficult.";
		else if (index == 4)
			text = "Some species of wolf spiders are able to walk on water using their feet and hairs on their body.";
		else if (index == 5)
			text = "When a wolf spiders eggs hatch the spider-lings hold on to the hairs on their stomach for about a week before they disperse";
		else if (index == 6)
			text = "Jumping spiders can jump up to forty timest heir own body length";
		else
			text = "There are more than 30,000 species of spiders in the world.";
	}

	document.write( "<p class='pest_points'>" + text + "</p>" );
}

function pest_points_plain_text(type, document_get_by_id) {
	var text;
	var index = Math.floor(Math.random()*20);

	if (type == "termites") {
		index = index % 5;
		if (index == 0)
			text = "Termites can live for 15 years.";
		else if (index == 1)
			text = "Termites will not only eat wood, they will eat anything made from wood.";
		else if (index == 2)
			text = "Termites have been known to cause over $1.5 billion worth of damage in the US each year.";
		else if (index == 3)
			text = "Termites can enter your home through a crack as thin as a piece of paper.";
		else
			text = "Termites have been around for more than 250 million years.";
	}
	if (type == "spiders") {
		index = index % 8;
		if (index == 0)
			text = "The female black widow eats the male black widow after mating.";
		else if (index == 1)
			text = "The black widow is the most poisonous spider in the United States.";
		else if (index == 2)
			text = "Webs get dirty and torn, so lots of spiders make a new one every day. They don't waste the old one, though--they roll it up into a ball and eat it.";
		else if (index == 3)
			text = "When a black widow bites a human the venom will cause muscle aches, nausea, and a paralysis of the diaphragm that can make breathing difficult.";
		else if (index == 4)
			text = "Some species of wolf spiders are able to walk on water using their feet and hairs on their body.";
		else if (index == 5)
			text = "When a wolf spiders eggs hatch the spider-lings hold on to the hairs on their stomach for about a week before they disperse";
		else if (index == 6)
			text = "Jumping spiders can jump up to forty timest heir own body length";
		else
			text = "There are more than 30,000 species of spiders in the world.";
	}
	if (type == "ants") {
		index = index % 4;
		if (index == 0)
			text = "Ants have the largest brain compared to other insects.";
		else if (index == 1)
			text = "Currently 325 million acres across the U.S. are infested with fire ants.";
		else if (index == 2)
			text = "The average life expectancy of an ant is 45-60 days.";
		else
			text = "Ants can carry over 20 times their weight.";
	}
	if (type == "cockroaches") {
		index = index % 4;
		if (index == 0)
			text = "Cockroaches bleed white blood.";
		else if (index == 1)
			text = "The world's largest cockroach is over 6 inches long with a wingspan of over 1 whole foot.";
		else if (index == 2)
			text = "A cockroach can live for 3-4 weeks without its head.";
		else
			text = "Cockroaches can hold their breath for 40 minutes.";
	}
	if (type == "scorpions") {
		index = index % 3;
		if (index == 0)
			text = "Scorpions become fluorescent under certain ultraviolet lights, like a black light.";
		else if (index == 1)
			text = "Scorpions that act dead and look dead - even squished - are oftentimes not dead at all, and touching said scorpion can result in another sting.";
		else
			text = "Scorpions have a dangerous venom that is more dangerous than a snake's venom.";
	}
	if (type == "wasps_and_bees") {
		index = index % 2;
		if (index == 0)
			text = "Honey bees need to consume about 20 lbs of honey to make 1 lb of beeswax.";
		else
			text = "Honey bees can fly at 15 mph.";
	}
	if (type == "rodents") {
		index = index % 2;
		if (index == 0)
			text = "You can keep mice on a table without a cage because mice are afraid to jump off high vertical drops.";
		else
			text = "Rats multiply so quickly that in 18 months, two rats could have over a million descendants.";
	}



	// not used???
	if (type == "mosquito") {
		index = index % 3;
		if (index == 0)
			text = "A mosquito beats its wing 300 to 600 times per second.";
		else if (index == 1)
			text = "Mosquitoes can smell their prey from about 75 feet away.";
		else
			text = "Adult mosquitoes can transmit West Nile Virus to humans and heartworm disease to pets.";
	}
	if (type == "tick") {
		index = index % 1;
		if (index == 0)
			text = "Certain species of Ticks are known to transmit Lyme Disease.";
	}
	if (type == "cricket") {
		index = index % 3;
		if (index == 0)
			text = "While crickets have wings, the majority of them do not fly.";
		else if (index == 1)
			text = "Tree crickets are called the poor man's thermometer because temperature directly affects their rate of activity. Count the number of chirps a cricket makes in 15 seconds, and then add 37. The sum will be very close to the outside temperature.";
		else
			text = " If left unchecked in houses, especially in large numbers, crickets will cause damage to clothing and other fabrics.";
	}
	if (type == "snail") {
		index = index % 1;
		if (index == 0)
			text = "A snail only mates once.";
	}
	if (type == "pill_bug") {
		index = index % 1;
		if (index == 0)
			text = "Pillbugs breathe through gills, in fact they live on land but their bodies are made for the water.";
	}
	if (type == "millipede") {
		index = index % 2;
		if (index == 0)
			text = "With each molt, the millipede gets a new segment and 2 pairs of legs.";
		else
			text = "Millipedes produce a odorous fluid that can cause an allergic reaction and can be harmful if it gets into the eye.";
	}
	if (type == "flea") {
		index = index % 1;
		if (index == 0)
			text = "Fleas can lay up to 1,500 eggs in a lifetime.";
	}




	if (document_get_by_id)
		document.getElementById("pest_points_copy").innerHTML = text;
	else
		document.write(text);
}
