//--------------------------------
//Functions used on Public sites
//--------------------------------

//Required function for photo gallery image switcher
function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('placeholder').src = whichpic.href;
  if (whichpic.title) {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
  } else {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
  }
  return false;
 } else {
  return true;
 }
}

// Clear standard search box of default text
function clearsearch(){
if (document.searchForm.searchQuery.value == "Search...")
	document.searchForm.searchQuery.value = "";
}
	
// Clear standard email subscribe box of default text
function clearemail(){
if (document.maillist.email.value == "Your email address")
	document.maillist.email.value = "";
}
	
// Process a subscribe request
function doAction(action)
{
	form = document.maillist;
	if (form.email.value == "") 
	{
		alert("Please enter an email address.")
	}
	else if (form.email.value == "Your email address") 
	{
		alert("Please enter a valid email address.")
	}
	else
	{
		if (action == "subscribe") {
			alert('Thank you for subscribing. Your email address will be added to our mailing list.');
		}
		if (action == "unsubscribe") {
			alert('Thank you for unsubscribing. Your email address will be removed from our mailing list.');
		}
		form.action.value = action;
		form.submit();
	}	
}
	
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=400,left = 490,top = 287');");
}
	
// Photo rotation JS
if (document.images)
{
    logo1 = new Image(226, 78);
    logo1.src = "/layout/rotateimage/trane.jpg";
    
    logo2 = new Image(226, 78);
    logo2.src = "/layout/rotateimage/rinnai.jpg";
    
    logo3 = new Image(226, 78);
    logo3.src = "/layout/rotateimage/avalon.jpg";
    
    logo4 = new Image(226, 78);
    logo4.src = "/layout/rotateimage/heatglo.jpg";
    
    logo5 = new Image(226, 78);
    logo5.src = "/layout/rotateimage/lifebreath.jpg";
    
    logo6 = new Image(226, 78);
    logo6.src = "/layout/rotateimage/roth.jpg";
    
    logo7 = new Image(226, 78);
    logo7.src = "/layout/rotateimage/lopi.jpg";
    
    logo8 = new Image(226, 78);
    logo8.src = "/layout/rotateimage/vermont.jpg";
}

var currentPhoto = 0;
var secondPhoto = 1;
	
var currentOpacity = new Array();
var imageArray = new Array(logo1.src, logo2.src, logo3.src, logo4.src, logo5.src, logo6.src, logo7.src, logo8.src);
	
var FADE_STEP = 2;
var FADE_INTERVAL = 10;
var pause = false;
	
function init() {
	currentOpacity[0]=99;
	for(i=1;i<imageArray.length;i++)currentOpacity[i]=0;
	mHTML="";
	for(i=0;i<imageArray.length;i++)mHTML+="<div id=\"logo\" name=\"logo\" class=\"mPhoto\"><img src=\"" + imageArray[i]  +"\"></div>";
	document.getElementById("logos").innerHTML = mHTML;
	
	if(document.all) {
		document.getElementsByName("logo")[currentPhoto].style.filter="alpha(opacity=100)";
	} else {
		document.getElementsByName("logo")[currentPhoto].style.MozOpacity = .99;
	}
	mInterval = setInterval("crossFade()",FADE_INTERVAL);
}
	
function crossFade() {
	if(pause)return;
	
	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;
	
	if(document.all) {
		document.getElementsByName("logo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		document.getElementsByName("logo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
	} else {
		document.getElementsByName("logo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
		document.getElementsByName("logo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
	}
	
	if(currentOpacity[secondPhoto]/100>=.98) {
		currentPhoto = secondPhoto;
		secondPhoto++;
		if(secondPhoto == imageArray.length)secondPhoto=0;
		pause = true;
		xInterval = setTimeout("pause=false",4000);
	}
}
	
function doPause()  {
	if(pause) {
		pause = false;
		document.getElementById("pauseBtn").value = "pause";
	} else {
		pause = true;
		document.getElementById("pauseBtn").value = "play";
	}
}
	
// Standard function for creating an xmlhttprequest object
function createXMLHttpRequest() {
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
  try { return new XMLHttpRequest(); } catch(e) {}
  alert("XMLHttpRequest not supported");
 	return null;
}