var dropDowns = new Array('subNav1','subNav4','subNav5');
var disappearSet = 0;

function showDropDown(id)
{
	hideDropDown();
	if(disappearSet == 1)
	{
		clearTimeout(disappear);
	}
	document.getElementById(id).style.display = "block";
}

function hideDropDown()
{		
		for (i=0; i<dropDowns.length; ++i)
		{
			document.getElementById(dropDowns[i]).style.display = 'none';
		}
}

function stay()
{
	clearTimeout(disappear);
}

function leave()
{
	disappear = setTimeout("hideDropDown()",1500);
	disappearSet = 1;
}

function changeImage(x)
{
	document.getElementById('galleryImage').src=x;
}

//VALIDATION
function setRequiredColors(fieldName)
{
	var label = fieldName + "Label";
	
	if (document.getElementById(fieldName).value == "")
	{
		document.getElementById(label).style.color="#C00";
	}
	else
	{
		document.getElementById(label).style.color="#333";
	}
}
function checkFields() {
	var fieldsArray	= new Array();
		fieldsArray	= Array('cfName','cfAddress1');
		if(document.getElementById('cfContactType').value == "Email")
		{
			fieldsArray[2] = "cfEmail";		
		}
		else if(document.getElementById('cfContactType').value == "Home Phone")
		{
			fieldsArray[2] = "cfHomePhone";		
		}
		else if(document.getElementById('cfContactType').value == "Cell Phone")
		{
			fieldsArray[2] = "cfHomePhone";		
		}

	for (var i=0; i<fieldsArray.length; i++)
	{
		var label = fieldsArray[i] + "Label";
		
		if(document.getElementById(fieldsArray[i]).value == "")
		{
			// set form action to nothing
			document.forms.serviceForm.action= "";
			// alert the problem
			alert ("You are missing one or more required field(s).");
			// loop through all fields for text color change
			for (var j=0; j<fieldsArray.length; j++)
			{
				setRequiredColors(fieldsArray[j]);
			}
			return(false);
		}
		else
		{
			document.forms.serviceForm.action="send_service_form.php";
		}
	}
	
}

function checkFields2() {
	var fieldsArray	= new Array();
		fieldsArray	= Array('cfName','cfPhone','cfMessage');
		
	for (var i=0; i<fieldsArray.length; i++)
	{
		var label = fieldsArray[i] + "Label";
		
		if(document.getElementById(fieldsArray[i]).value == "")
		{
			// set form action to nothing
			document.forms.contactForm.action= "";
			// alert the problem
			alert ("You are missing one or more required field(s).");
			// loop through all fields for text color change
			for (var j=0; j<fieldsArray.length; j++)
			{
				setRequiredColors(fieldsArray[j]);
			}
			return(false);
		}
		else
		{
			document.forms.contactForm.action="send_contact_form.php";
		}
	}
	
}

function checkFields() {
	var fieldsArray	= new Array();
		fieldsArray	= Array('cfName','cfAddress1');
		if(document.getElementById('cfContactType').value == "Email")
		{
			fieldsArray[2] = "cfEmail";		
		}
		else if(document.getElementById('cfContactType').value == "Home Phone")
		{
			fieldsArray[2] = "cfHomePhone";		
		}
		else if(document.getElementById('cfContactType').value == "Cell Phone")
		{
			fieldsArray[2] = "cfCellPhone";		
		}

	for (var i=0; i<fieldsArray.length; i++)
	{
		var label = fieldsArray[i] + "Label";
		
		if(document.getElementById(fieldsArray[i]).value == "")
		{
			// set form action to nothing
			document.forms.serviceForm.action= "";
			// alert the problem
			alert ("You are missing one or more required field(s).");
			// loop through all fields for text color change
			for (var j=0; j<fieldsArray.length; j++)
			{
				setRequiredColors(fieldsArray[j]);
			}
			return(false);
		}
		else
		{
			document.forms.serviceForm.action="send_service_form.php";
		}
	}
	
}
function cleanUpRequired()
{
	var fieldsArray2= new Array();
		fieldsArray2	= Array('cfEmail','cfHomePhone','cfCellPhone');
	for (var i=0; i<fieldsArray2.length; i++)
	{
		var label = fieldsArray2[i] + "Label";
		document.getElementById(label).style.color="#000";
	}
}

function showHideApps(x)
{
	i = 0;
	while(i <= totalSections)
	{
		document.getElementById("sectionHide"+i).style.display = "none";
		i++;
	}
	document.getElementById("sectionHide"+x).style.display = "block";
}

function hideAllApps(x)
{
	i = 0;
	while(i <= x)
	{
		document.getElementById("sectionHide"+i).style.display = "none";
		i++;
	}
	
	totalSections = x;
}

function openWindow(URL,w,h) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width='+w+',height='+h+',left = 50,top = 50');");
}

heatingTidBits = new Array();

heatingTidBits[0] = "<p>Energy saving tip: Set your thermostat as low as is comfortable in the winter and as high as is comfortable in the summer.</p>";
heatingTidBits[1] = "<p>Clean or replace filters on furnaces once a month or as needed.</p>";
heatingTidBits[2] = "<p>Clean warm air registers, baseboard heaters, and radiators as needed; make sure they’re not blocked by furniture, rugs, or drapes.</p>";
heatingTidBits[3] = "<p>For air conditioners, look for a high Seasonal Energy Efficiency Rating (SEER).  The current minimum is 13 SEER for central air conditioners.  ENERGY STAR models are 14 SEER or more.</p>";

electricTidBits = new Array();

electricTidBits[0] = "<p>When remodeling, look for recessed down lights, or 'cans', that are rated for contact with insulation (IC Rated).</p>";
electricTidBits[1] = "<p>Dimmers save electricity when used to lower light levels.  Be sure to select products that are compatible with CFL bulbs; not all products work with CFL's (compact florescent light bulbs).</p>";
electricTidBits[2] = "<p>Look for ENERGY STAR qualified fixtures that are designed for outdoor use and come with features like automatic daylight shut off and motion sensors.</p>";

plumbingTidBits = new Array();

plumbingTidBits[0] = "<p>Disconnect outside water hoses.  If left  connected, water in the hoses can freeze and expand causing faucets, and connecting pipes inside your home to freeze and break.</p>";
plumbingTidBits[1] = "<p>Insulate pipes in unheated areas, such as garages or crawl spaces.  Apply heat tape or thermostat-controlled heat cables around pipes that are exposed and prone to freezing.</p>";
plumbingTidBits[2] = "<p>Your water heater works harder during winter months.  Flush it out and remove sediment buildup, which causes corrosion, shortens life span and reduces heating efficiency.</p>";

function selectContent(x)
{
	var total = x.length;
	var ranNum= (Math.floor(Math.random()*total-1))+1;
	document.getElementById('tidBit').innerHTML = x[ranNum];
}
