// JavaScript Document
/*var transDiv = null;
var onloadCalled = false;

window.onload = doOnLoad;

function doOnLoad()
{
	onloadCalled = true;
	
	commonPageLoad();
	
	if (typeof pageShowOrLoad == 'function')
		pageShowOrLoad(false, arguments);
}

function doPageShow()
{
	if (onloadCalled)
	{
		onloadCalled = false;
		return;
	}
	
	if (typeof pageShowOrLoad == 'function')
		pageShowOrLoad(true, arguments);
}

function commonPageLoad()
{
	/*var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	
	if (sPage == "" || sPage == "step1.html")
	{
		document.form.partialPostcode.focus();
	}*/
/*}


function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
} */


/*function prepareInputsForHints() 
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) 
		{
			// the span exists! on focus, show the hint
			inputs[i].onfocus = function () 
			{
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () 
			{
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++)
	{
		if (selects[k].parentNode.getElementsByTagName("span")[0]) 
		{
			selects[k].onfocus = function () 
			{
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () 
			{
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints); 
*/

function step3Proceed(formType)
{
	var phone2 = document.getElementById('spLeadData5');
	
	if (phone2.value == "")
	{
		if(formType == 'Free')
		{
			if (confirm("Are you sure you wish to proceed without providing an ALTERNATIVE PHONE NUMBER? Our installer must be able to contact you by telephone to book your survey and an additional number such as a mobile will be useful. \n\nSelect OK to continue or CANCEL to enter another number."))
			{
				return true;
			}
			else
			{
				phone2.focus();
				return false;
			}
		}
		
		
		else if(formType == 'Paid')
		{
			return true;
		}		
		
		/* POP UP CODE
		
		else if(formType == 'Paid')
		{
			if (confirm("Are you sure you wish to proceed without providing an ALTERNATIVE PHONE NUMBER? Our installers must be able to contact you by telephone to book your surveys and an additional number such as a mobile will be useful. \n\nSelect OK to continue or CANCEL to enter another number."))
			{
				return true;
			}
			else
			{
				phone2.focus();
				return false;
			}
		}
		
		*/
		
		else
		{
			if (confirm("Are you sure you wish to proceed without providing an ALTERNATIVE TELEPHONE NUMBER? Our installers must be able to contact you by telephone to book your surveys and an additional number such as a mobile will be useful.\n\nSelect OK to continue or CANCEL to enter another number."))
			{
				return true;
			}
			else
			{
				phone2.focus();
				return false;
			}			
		}
	}
	
	return true;
}


function step4Proceed(formType)
{
	if(formType == 'Free')
	{
		if (confirm("By submitting this form, I understand that I cannot claim Feed in Tariff payments, I have the required roof space for the panels and I am agreeing to have a no-obligation survey from an EnergyLink approved installer. Select OK to continue or CANCEL to stay on this page."))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	else if(formType == 'Paid')
	{
		if (confirm("By submitting this form: 1) I understand that a typical Solar PV system costs £6,000 to £8,000. 2) I am aware that I will receive a Feed in Tariff rate of 21p per kWh. 3) I agree to have up to three surveys from EnergyLink approved installers. Select OK to continue or CANCEL to stay on this page."))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	return true;
}


/*function popitup(url)
{
	newwindow = window.open(url,'Help','height=500,width=400,resizable=no,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function step2_loftChange(dropdown)
{
	// Check for valid selection
	var loftDropdown = document.getElementById('loft_dropdown');
	var wallDropdown = document.getElementById('wall_dropdown');
	var loftValue = loftDropdown.options[loftDropdown.selectedIndex].value;
	var loftIcon = document.getElementById('loft_icon');
	var wallValue = wallDropdown.options[wallDropdown.selectedIndex].value;
	var wallIcon = document.getElementById('wall_icon');
	var loftMessage = document.getElementById('loft_message');
	var wallMessage = document.getElementById('wall_message');
	var topError = document.getElementById('top_message');
	
	loftIcon.style.visibility = "hidden";
	wallIcon.style.visibility = "hidden";
	
	if (loftValue == 'Floor of Loft')
	{
		loftIcon.src = "/form/templates/images/applytick.gif";
		loftIcon.style.visibility = "visible";
		loftMessage.className = "step2notesgreen";
		loftMessage.innerHTML = "This is covered under the grant scheme.<br />Click NEXT STEP to proceed.";
		loftMessage.style.visibility = "visible";
	}
	else if (loftValue != '' && loftValue != 'Not Applicable')
	{
		loftIcon.src = "/form/templates/images/applycross.gif";
		loftIcon.style.visibility = "visible";
		loftMessage.className = "step2notesred";
		loftMessage.innerHTML = "This is NOT covered under the grant scheme.<br />(You may still qualify for Wall Insulation)";
		loftMessage.style.visibility = "visible";
	}
	else
	{
		loftIcon.style.visibility = "hidden";
		loftMessage.style.visibility = "hidden";
	}
	
	if (wallValue == 'Cavity Walls')
	{
		wallIcon.src = "/form/templates/images/applytick.gif";
		wallIcon.style.visibility = "visible";
		wallMessage.className = "step2notesgreen";
		wallMessage.innerHTML = "This is covered under the grant scheme.<br />Click NEXT STEP to proceed.";
		wallMessage.style.visibility = "visible";
	}
	else if (wallValue != '' && wallValue != 'Not Applicable')
	{
		wallIcon.src = "/form/templates/images/applycross.gif";
		wallIcon.style.visibility = "visible";
		wallMessage.className = "step2notesred";
		wallMessage.innerHTML = "This is NOT covered under the grant scheme.<br />(You may still qualify for Loft Insulation)";
		wallMessage.style.visibility = "visible";
	}
	else
	{
		wallIcon.style.visibility = "hidden";
		wallMessage.style.visibility = "hidden";
	}
	
	if (loftValue == 'Not Applicable' && wallValue == 'Not Applicable')
	{
		topError.className = "msg_error";
		topError.innerHTML = "Error: You must choose at least one insulation type.";
		loftIcon.src = "/form/templates/images/icon_error.png";
		loftIcon.style.visibility = "visible";
		wallIcon.src = "/form/templates/images/icon_error.png";
		wallIcon.style.visibility = "visible";
	}
}

function step2_wallChange(dropdown)
{
	step2_loftChange(dropdown);
}

function confirmStep3()
{
	var selected = document.form.over70.options[document.form.over70.selectedIndex].value;
	if (selected == 'Yes')
		return confirm("Someone must be aged 70 or over AND be a permanent resident in the property at the time of this enquiry. If they are not yet 70 or they do not live at the property, please select Over 70 = No or apply again when this is the case. N.B. There must be 60mm or less existing insulation to qualify free on the Over 70s scheme.\n\nSelect OK to continue, or Cancel to go back.");
}

function copyPostcodeAnywhere()
{
	var sourceDiv = document.getElementById('postcode_anywhere_source');
	var destDiv = document.getElementById('postcode_anywhere');
	destDiv.innerHTML = sourceDiv.innerHTML;
}*/

// START: Aaron Williams – 08/11/2010 – Login on Enter Error

/*function enterSubmit(myfield, e)
{
	var keycode;
	
	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (e) 
	{
		keycode = e.which;
	}
	else
	{
		return true;
	}
	
	if (keycode == 13)
	{
		myfield.form.submit();
		return false;
	}
	else
	{
		return true;
	}
}*/

// END: Aaron Williams – 08/11/2010 – Login on Enter Error

function capturePageValues()
{
	// Find forms
	var forms = document.forms;
	
	if (forms.length > 0)
	{
		for (var f = 0; f < forms.length; f++)
		{
			var form = forms[f];
			
			if (form.name == 'form')
			{
				var el = form.elements['capture_values'];
				
				if (el != undefined)
				{
					el.value = "yes";
					form.submit();
					return false;
				}
			}
		}
	}
	
	return true;
}
