var btn_home, btn_about, btn_products, btn_treat, btn_faq, btn_news, btn_contact, d; // for nav bars
var ind_button, food_button, ocean_button, soil_button, bio_button, productpage; // for product buttons
var name, company, phonenum, emailadr, allfields; // for form fields
var faqs, spill, biorem, homepage; // home arrays for bottom 3

faqs   = new Array();
spill  = new Array();
biorem = new Array();

faqs[0] = ["IS BIOREMEDIATION APPROVED BY THE EPA- U.S. ENVIRONMENTAL PROTECTION AGENCY?","According to EPA Publication 640/k-93/002: \"The United States is the world leader in field implementation of bioremediation, an attractive alternative to conventional methods of cleaning up persistent hazardous wastes in the..."];
faqs[1] = ["WHY ARE Environmental Solution, INC. BIOREMEDIATION PRODUCTS THE BEST ON THE MARKET?","The microbes utilized in our products are in an active preparation, ready to be used. Unlike other remediation products, our products require no special solutions, no special mixing and no waiting period before application..."];
faqs[2] = ["WHAT ARE THE ADVANTAGES OF BIOREMEDIATION?","Bioremediation is an attractive option for the remediation of hydrocarbon contaminants. The following are a few of the advantages & reasons why you should consider this innovative process and the related EnviroLogic Products..."];

//take out
//take out spill[0] = ["images/products/fleetkleen.jpg", "Industrial Strength Cleaner"];
//take out spill[1] = ["images/products/spillawayplus.jpg", "Fast Acting Hydrocarbon"];
//take out spill[2] = ["images/products/partswasher.jpg", "Aqueous Based Bio-remedial"];

// take out
// take out biorem[0] = ["images/products/navelkleen.jpg", "Waste Minimization"];
//take out  biorem[1] = ["images/products/navalkleen-liquid.jpg", "Unique, specially developed"];
//  take out biorem[2] = ["images/products/biow.jpg", "Fast Acting Hydrocarbon"];

d = window.document; // global window.document
function init(){
	// grab all nav buttons they check if they are there.
	btn_home      = d.getElementById("btn_home");
	btn_about     = d.getElementById("btn_about");
	btn_products  = d.getElementById("btn_products");
	btn_treat     = d.getElementById("btn_treat");
	btn_faq   	  = d.getElementById("btn_faq");
	btn_news	  = d.getElementById("btn_news");
	btn_contact	  = d.getElementById("btn_contact");
	productpage	  = d.getElementById("ind"); // check if on products page
	homepage	  = d.getElementById("home_faq"); // check if on home page
	
	if(btn_home)
	{
	btn_home.onmouseover 	 = function(){mouseOn(this, 'home');}
	btn_home.onmouseout  	 = function(){mouseOff(this, 'home');}
	btn_home.onclick  	     = function(){location.href = 'index.php';}
	}
	
	if(btn_about)
	{
	btn_about.onmouseover = function(){mouseOn(this, 'about');}
	btn_about.onmouseout  = function(){mouseOff(this, 'about');}
	btn_about.onclick  	  = function(){location.href = 'about.php';}
	}
	
	if(btn_products)
	{
	btn_products.onmouseover 	 = function(){mouseOn(this, 'products');}
	btn_products.onmouseout  	 = function(){mouseOff(this, 'products');}
	btn_products.onclick  		 = function(){location.href = 'products.php';}
	}
	
	if(btn_treat)
	{
	btn_treat.onmouseover 	 = function(){mouseOn(this, 'treat');}
	btn_treat.onmouseout  	 = function(){mouseOff(this, 'treat');}
	btn_treat.onclick  	 	 = function(){location.href = 'treat.php';}
	}
	
	if(btn_faq)
	{
	btn_faq.onmouseover 	 = function(){mouseOn(this, 'faq');}
	btn_faq.onmouseout  	 = function(){mouseOff(this, 'faq');}
	btn_faq.onclick  	 	 = function(){location.href = 'faq.php';}
	}
	
	if(btn_news)
	{
	btn_news.onmouseover 	 = function(){mouseOn(this, 'news');}
	btn_news.onmouseout  	 = function(){mouseOff(this, 'news');}
	btn_news.onclick  	 	 = function(){location.href = 'news.php';}
	}
	
	if(btn_contact)
	{
	btn_contact.onmouseover 	 = function(){mouseOn(this, 'contact');}
	btn_contact.onmouseout  	 = function(){mouseOff(this, 'contact');}
	btn_contact.onclick  	 	 = function(){location.href = 'contact.php';}
	}
	
	if(productpage){
		setProductButtons(); // set the product buttons - below
	}
	
	if(homepage){
		//alert("hey now");
		var num1 = Math.round(Math.random()*2);
		var num2 = Math.round(Math.random()*2);
		var num3 = Math.round(Math.random()*2);
// faq
		d.getElementById("home_faq").innerHTML = "<span style='display:block; position:relative; top:35px; left:10px; width:245px; cursor:pointer'><strong>"+faqs[num1][0]+"</strong><br><br>"+ faqs[num1][1] +"<br><br><strong>read more...</strong></span>";
		d.getElementById("home_faq").onclick = function(){location.href = 'faq.php';}

// bioremedia
		d.getElementById("home_spill").innerHTML = "<span style='display:block; position:relative; top:35px; left:10px; width:245px; cursor:pointer'><div align='center'><img src='"+spill[num2][0]+"' /></div>"+ spill[num2][1] +"<br><strong>find out more...</strong></span>";
		d.getElementById("home_spill").onclick = function(){location.href = 'products.php';}
		
// spill control
		d.getElementById("home_bio").innerHTML = "<span style='display:block; position:relative; top:35px; left:10px; width:245px; cursor:pointer'><div align='center'><img src='"+biorem[num3][0]+"' /></div>"+ biorem[num3][1] +"<br><strong>find out more...</strong></span>";
		d.getElementById("home_bio").onclick = function(){location.href = 'products.php';}
		
	}
}

// rollover functions
function mouseOn(dom, name){
	dom.src = 'images/' + name + '_on.gif';
	dom.style.cursor = 'pointer';
}

function mouseOff(dom, name){
	dom.src = 'images/' + name + '_off.gif';
}

//Product Buttons

function setProductButtons(){
	var e, id;
	
	ind_button   = d.getElementById("ind");
	food_button  = d.getElementById("food");
	ocean_button = d.getElementById("ocean");
	soil_button  = d.getElementById("soil");
	bio_button   = d.getElementById("bio");
	
	ind_button.onclick   = function(event){
		e = event || window.event;
		window.event ? id = e.srcElement.id	: id = e.currentTarget.id;
		openCloseTable(id);
	}
	food_button.onclick  = function(event){
		e = event || window.event;
		window.event ? id = e.srcElement.id	: id = e.currentTarget.id;
		openCloseTable(id);
	}
	ocean_button.onclick = function(event){
		e = event || window.event;
		window.event ? id = e.srcElement.id	: id = e.currentTarget.id;
		openCloseTable(id);
	}
	soil_button.onclick  = function(event){
		e = event || window.event;
		window.event ? id = e.srcElement.id	: id = e.currentTarget.id;
		openCloseTable(id);
	}
	bio_button.onclick   = function(event){
		e = event || window.event;
		window.event ? id = e.srcElement.id	: id = e.currentTarget.id;
		openCloseTable(id);
	}
}

function openCloseTable(button_id){
	if(d.getElementById(button_id + "_table").style.display == "none" || d.getElementById(button_id + "_table").style.display == ""){
		d.getElementById(button_id + "_table").style.display = "block";
		d.getElementById(button_id).src = "images/prod_"+ button_id +"_on.gif";
	}
	else{
		d.getElementById(button_id + "_table").style.display = "none";
		d.getElementById(button_id).src = "images/prod_"+ button_id +"_off.gif";
	}
}

// form checker
function formcheck(){
	//grab the required form fields if there.
	name     = d.getElementById('name');
	company  = d.getElementById('company');
	phonenum = d.getElementById('pnumber');
	emailadr = d.getElementById('email');
	question = d.getElementById('question');
	
	allfields = d.getElementsByTagName("input");
	

	if((name.value && company.value && phonenum.value && emailadr.value && question.value) == "")
	{
		alert("Please fill in all required * fields.");
		return false;
	}
	else if((isNaN(phonenum.value)) || (String(phonenum.value).length != 10)){
		alert("Please enter a correct phone number (1235551212)");
		phonenum.focus();
		return false;
	}
	else if((emailadr.value.indexOf("@") == -1) || (emailadr.value.indexOf(".") == -1)){
		alert("Please enter a correct email address (xxxxx@xxxx.xxx)");
		emailadr.focus();
		return false;
	}
	else{
		for(var i=0; i < allfields.length; i++){
			if((allfields[i].value.indexOf("<") != -1) || (allfields[i].value.indexOf("&lt;") != -1) || (question.value.indexOf("<") != -1) || (question.value.indexOf("&lt;") != -1)){
				alert("Please do not use the < character.");
				allfields[i].focus();
				return false;
			}
		}
	}
}


//window.onload = init;
