// JavaScript Document

function ClearText(theField) {
	if (theField.value == "USERNAME"){
		theField.value="";
	}
	else if (theField.value == "PASSWORD"){
		theField.value="";
	}	
}
function ResetIfBlank(theField){
	if (theField.id == "name_field"){
		if (theField.value == ""){
			theField.value = "USERNAME";
		}
	}
	if (theField.id == "pass_field"){
		if (theField.value == ""){
			theField.value = "PASSWORD";
		}
	}
}

function HighlightLink(id) {
		document.getElementById(id).style.color = "white";
}


var x;
var ContentDivs = new Array("core","refractory","project", "steel", "maintenance");


function SwitchContent(NewContent){
	
	for (x in ContentDivs) {
		document.getElementById(ContentDivs[x]).style.display = "none";
	}
	document.getElementById(NewContent).style.display = "inline";
	//the height change is necessary for the sake of of the sticky footer, unfortunately
	if (NewContent == 'core'){
		document.getElementById("content").style.height = "445px";
		HighlightSubLink("core_link");
		
	}
	else if (NewContent == 'project'){
		document.getElementById("content").style.height = "545px";
		HighlightSubLink("project_link");
	}
	else if (NewContent == 'steel'){
		document.getElementById("content").style.height = "480px";
		HighlightSubLink("steel_link");
		
	}
	else if (NewContent == 'maintenance'){
		document.getElementById("content").style.height = "465px";
		HighlightSubLink("maintenance_link");
	}
	else if (NewContent == 'refractory'){
		document.getElementById("content").style.height = "545px";
		HighlightSubLink("refractory_link");
	}
	
	if (NewContent == "core"){document.getElementById("bottom_image").style.display = "inline";}
	else {document.getElementById("bottom_image").style.display = "none";}	
	
}

function SwitchSubContent(NewContent, PreviousContent, NewLink, OldLink){
			document.getElementById(PreviousContent).style.display = "none";
			document.getElementById(NewContent).style.display = "inline";
			document.getElementById(OldLink).className = "red";
			document.getElementById(NewLink).className = "red_bold";
}

var CurrentSublink = "core_link";
function HighlightSubLink(id) {
	if (CurrentSublink == id){}
	else {
		if (id == "core_link"){
			document.getElementById(CurrentSublink).style.color = "#cccccc";
			CurrentSublink = id;
		}
		else{
			if (CurrentSublink == "core_link"){
				CurrentSublink = id;
				document.getElementById(CurrentSublink).style.color = "#ffffff";
				
			}
			else {
				document.getElementById(CurrentSublink).style.color = "#cccccc";
				CurrentSublink = id;
				document.getElementById(CurrentSublink).style.color = "#ffffff";
			}
		}
	}
}

var windContentDivs = new Array("intro","windServices","photos");
function SwitchWindContent(NewContent){
	
	for (x in windContentDivs) {
		document.getElementById(windContentDivs[x]).style.display = "none";
	}
	document.getElementById(NewContent).style.display = "inline";
	//the height change is necessary for the sake of of the sticky footer, unfortunately
	if (NewContent == 'intro'){
		document.getElementById("content").style.height = "575px";
		HighlightWindSubLink("intro_link");
		
	}
	else if (NewContent == 'windServices'){
		document.getElementById("content").style.height = "700px";
		HighlightWindSubLink("windServices_link");
	}
	else if (NewContent == 'photos'){
		document.getElementById("content").style.height = "545px";
		HighlightWindSubLink("photos_link");
	}
}

var CurrentWindSublink = "intro_link";
function HighlightWindSubLink(id) {
	if (CurrentWindSublink == id){}
	else {
		if (id == "core_link"){
			document.getElementById(CurrentWindSublink).style.color = "#cccccc";
			CurrentWindSublink = id;
		}
		else{
			if (CurrentWindSublink == "intro_link"){
				CurrentWindSublink = id;
				document.getElementById(CurrentWindSublink).style.color = "#ffffff";
				
			}
			else {
				document.getElementById(CurrentWindSublink).style.color = "#cccccc";
				CurrentWindSublink = id;
				document.getElementById(CurrentWindSublink).style.color = "#ffffff";
			}
		}
	}
}


var currentWindSubLink = "";
var windSubContentDivs = new Array("field_services","gearbox_services","generator_services","lubrication_services","generator_services","blade_services");
function switchWindSubContent(NewContent, newLink){
	for (x in windSubContentDivs){
			document.getElementById(windSubContentDivs[x]).style.display = "none";
	}
	document.getElementById(NewContent).style.display = "inline";
	if(currentWindSubLink==""){
		document.getElementById(newLink).className = "red_bold";
		currentWindSubLink=newLink;
	} else {
		document.getElementById(currentWindSubLink).className = "red";
		document.getElementById(newLink).className = "red_bold";
		currentWindSubLink=newLink;
	}
}


var currentWindPhotoLink = "w1Link";
var WindPhotosArray = new Array("w1","w2","w3","w4","w5");
function switchWindPhotos(newPhoto, newLink){
	for (x in WindPhotosArray){
			document.getElementById(WindPhotosArray[x]).style.display = "none";
	}
	document.getElementById(newPhoto).style.display = "inline";
	
	document.getElementById(currentWindPhotoLink).className = "red";
	document.getElementById(newLink).className = "red_bold";
	currentWindPhotoLink=newLink;
		
}

//****** handing variables through the url *******************************************

var linkfrom = "";
linkfrom = location.search.substr(1).split("?");//sets variable as whatever follows question mark in the url
function DisplayPage(){
	if (linkfrom == "") {
		//document.getElementById("loading").style.display ="none";
		//DisplayProduct("splash");
	}
	else {
		//document.getElementById("loading").style.display ="none";
		SwitchContent(linkfrom);
	}
}

//******* Email Form Validation ***************

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="")
		  {alert(alerttxt);return false}
		else {return true}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
		  {alert(alerttxt);return false}
		else {return true}
	}
}
//email form
function validate_form2(thisform) {

	with (thisform) {
		if (validate_required(name,"Please enter your name.")==false)
		  {name.focus();return false}
	}
	with (thisform) {
		if (validate_email(email,"Please enter valid e-mail address.")==false)
		  {email.focus();return false}
	}
	with (thisform) {
		if (validate_required(message,"Please enter a message.")==false)
		  {message.focus();return false}
	}
	
}