function openTerms()
{
	newwin = window.open("terms.html","popup","width=400,height=350,scrollbars=yes");
}
function openPrivacy()
{
	newwin = window.open("privacy.html","popup","width=400,height=350,scrollbars=yes");
}
/* @

@ */

function navOver(imgName)
{
	var theImage = document.getElementById(imgName);
	
	if(theImage.src.indexOf("_off.gif") != -1)
	{
		theImage.src = theImage.src.replace("_off.gif","_on.gif");
	}
	
	else
	{
		theImage.src = theImage.src.replace("_on.gif","_off.gif");
	}
}

window.onload = function()
{
	// change copyright year
	var currentYear = new Date();
	document.getElementById("thisYear").innerHTML = currentYear.getFullYear();
	
	// append 'over' class for btn rollovers in IE 
	var parentId = document.getElementById('btnOurServices');
	if(parentId != null)
	{
		parentId.onmouseover=function() 
		{
			parentId.className += " over";
		}
		parentId.onmouseout=function() 
		{
			parentId.className = parentId.className.replace(" over", "");
		}
	}
}

/* start validation */
function validateForm(theForm)
{
	valid = true;
	message = "So we can deal with your enquiry:\n\n";
	
	if(theForm.elements["txtFirstName"].value == "")
	{
		message += "  Please enter your first name\n";
		valid = false;
	}

	if(theForm.elements["txtSurname"].value == "")
	{
		message += "  Please enter your surname\n";
		valid = false;
	}

	if(theForm.elements["txtContactPhoneNumber"].value == "")
	{
		message += "  Please enter your phone number\n";
		valid = false;
	}	
	
	if(theForm.elements["txtEmailAddress"].value == "")
	{
		message += "  Please enter your email address\n";
		valid = false;
	}
	
	if(theForm.elements["txtEmailAddress"].value != "")
	{
		var supEmail = theForm.elements["txtEmailAddress"].value;
		var emLen = supEmail.length;
		var posAt = supEmail.indexOf('@')
		var posDot = supEmail.lastIndexOf('.')
		if((emLen < 7) || (posAt < 1) || (posDot <= (posAt + 1)) || (posDot >= (emLen - 1)))
		{
			message += "  Please enter a valid email address\n";
			valid = false;
		}
	}

	if(theForm.elements["ddlHowDidYouHearAboutUs"].value == "")
	{
		message += "  Please tell us how you heard about us\n";
		valid = false;
	}	
	
	if(valid)
	{
		return true;
	}
	else
	{
		alert(message);
		return false;
	}
}

/* end validation */

function validateLogin(theForm)
{
	valid = true;
	message = "Required fields:\n\n";
	
	if(theForm.elements["username"].value == "")
	{
		message += "Email\n";
		valid = false;
	}	
	
	if(theForm.elements["username"].value != "")
	{
		var supEmail = theForm.elements["username"].value;
		var emLen = supEmail.length;
		var posAt = supEmail.indexOf('@')
		var posDot = supEmail.lastIndexOf('.')
		if((emLen < 7) || (posAt < 1) || (posDot <= (posAt + 1)) || (posDot >= (emLen - 1)))
		{
			message += "Valid email\n";
			valid = false;
		}
	}
	
	if(theForm.elements["password"].value == "")
	{
		message += "Password\n";
		valid = false;
	}
	
	if(valid)
	{
		return true;
	}
	else
	{
		alert(message);
		return false;
	}
	
}

var divsInArray = new Array();
var alreadyInMenu = false;
/* @ 

@ */

function displayPopUp(id)
{
	var theId = document.getElementById(id);
	
	for(var i=0;i<divsInArray.length;i++)
	{
		tempId = divsInArray[i];
		if(tempId == id)
		{
			alreadyInMenu = true;
		}
	}	
	
	if(!alreadyInMenu)
	{
		divsInArray.push(id);
	}
	
	theId.style.display = "block";
}

function hidePopUp(id)
{
	for(var i=0;i<divsInArray.length;i++)
	{
		tempId = divsInArray[i];
		if(tempId == id)
		{	
			divsInArray.splice(i,1);
			alreadyInMenu = false;
			setTimeout('removePopUp("'+id+'")',30);
		}
	}	
}

function removePopUp(id)
{
	removeThisMenu = true;
	for(var i=0;i<divsInArray.length;i++)
	{		
		tempId = divsInArray[i];
		
		if(tempId == id)
		{	
			removeThisMenu = false;
		}
	}		
	
	if(removeThisMenu)
	{
		var theId = document.getElementById(id);
		theId.style.display = "none";
	}
	
}
