var title = 0;
var name = "";
var email = "";
var errorTitle = "Please select your title.";
var errorName = "Please enter your surname.";
var erroremail = "Please enter your e-mail address.";
var invalidAddress = "Please enter a valid e-mail address.\nAddress must be in the format user@domain.com";


$(document).ready(function() { //to fix the issue of menu nit displaying over the engine drop downs 
	$("#navmenu").hover(function(){
		$("#navIframe").show();
	},function(){
		$("#navIframe").hide();
	});
});


function setTitleIndex(selectElement) {
	title = selectElement.selectedIndex;
}

function checkAddress()	{
	var atIndex = email.indexOf("@");
	var dotIndex = email.lastIndexOf(".");
	var atIndexPlus = atIndex + 2;
	var emailLength = email.length - 1;
	if (atIndex < 1) { // @ cannot be at the start of the string
		return false;
	}
	if (dotIndex < atIndexPlus) { // . cannot be immediatly after @
		return false;
	}
	if (dotIndex == emailLength)	{
		return false;
	} else {
		return true;
	}
}

function checkSignup() {
	name = document.sendmail.surname.value;
	email = document.sendmail.email.value;
	if (title == 0)	{
		alert(errorTitle);
		return false;
	}
	if (name.length == 0)	{
		alert(errorName);
		document.sendmail.surname.focus();
		return false;
	} else if (email.length == 0) {
		alert(erroremail);
		document.sendmail.email.focus();
		return false;
	} else if (!checkAddress())	{
		alert(invalidAddress);
		return false;
	} else {
		document.sendmail.submit();
	}
}

function enterSubmit() {
	if(window.event && window.event.keyCode == 13) {
		checkSignup();
		return !(window.event && window.event.keyCode == 13);
	} else {
		return true;
	}
}

function openwin(url) {
	window.open(url,'mywindow','width=770,height=300, scrollbars=yes');
}

// png fix
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	//document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}