window.defaultStatus = "Welcome to Win marketing Ltd.";

// GLOBAL variables
var lsBrowser = navigator.appName;
var oldQLbg;
var crappyIE;
var FormUtil = new Object;
var EventUtil = new Object;


// *********************************************************************
// Determine the type of browser and set wether fixes have to be applied
// *********************************************************************
function getBrowserVersion() {
	var findIndex;
	var browserVersion = 0;
	var browserFix = false;
	var lsBrowser = navigator.appName;
	browserAgent = navigator.userAgent;
	if (lsBrowser.indexOf("Microsoft")>-1) { 
		findIndex = browserAgent.indexOf("MSIE") + 5;
		browserVersion = parseInt(browserAgent.substring(findIndex,findIndex+1));
		if (browserVersion<8) { browserFix = true; }
	}
	return browserFix;
}


// Page onload functions
function pageLoad() {
	crappyIE = getBrowserVersion();
	menuStyle();
	FormUtil.focusOnfirst();
}


function lightup(ql) {
	if (crappyIE) {
		oldQLbg = document.getElementById("ql").style.backgroundImage;
	} else {
		oldQLbg = document.getElementById("ql").style.backgroundImage;
	}
	switch (ql) {
		case 1:
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql1.jpg)";
			break;
		case 2:
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql2.jpg)";
			break;
		case 3:
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql3.jpg)";
			break;
		case 4:
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql4.jpg)";
			break;
	}
}

function turnoff() {
	if (crappyIE) {
		document.getElementById("ql").style.backgroundImage = oldQLbg;
	} else {
		document.getElementById("ql").style.backgroundImage = oldQLbg;
	}		
}

// Little function to tie the styling of the 2 menus together
function menuStyle() {

	if (document.getElementById("current")) 
	{ 
	// If Marketing Strategy in main menu selected ensure the associated Quick Link is highlighted
	switch(document.getElementById("current").className) { 
		case "active item7":
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql1.jpg)";
			lightup(1);
			var i, s;
			for(i=0; (s = document.getElementsByTagName("span")[i]); i++) {
				if((s.className == "qlhdg") && (s.parentNode.parentNode.parentNode.id == "ql1")) { s.style.color = 'white'; s.parentNode.style.color = 'white'; } 	
			}
			break;
		case "active item6":
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql2.jpg)";
			lightup(2);
			var i, s;
			for(i=0; (s = document.getElementsByTagName("span")[i]); i++) {
				if((s.className == "qlhdg") && (s.parentNode.parentNode.parentNode.id == "ql2")) { s.style.color = 'white'; s.parentNode.style.color = 'white';} 	
			}
			break;
		case "parent active item8":
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql3.jpg)";
			lightup(3);
			var i, s;
			for(i=0; (s = document.getElementsByTagName("span")[i]); i++) {
				if((s.className == "qlhdg") && (s.parentNode.parentNode.parentNode.id == "ql3")) { s.style.color = 'white'; s.parentNode.style.color = 'white';} 	
			}
			break;
		case "active item9":
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql4.jpg)";
			lightup(4);
			var i, s;
			for(i=0; (s = document.getElementsByTagName("span")[i]); i++) {
				if((s.className == "qlhdg") && (s.parentNode.parentNode.parentNode.id == "ql4")) { s.style.color = 'white'; s.parentNode.style.color = 'white';} 	
			}
			break;
	}		

	switch(document.getElementById("current").parentNode.parentNode.className) { 
		case "parent active item8":
			document.getElementById("ql").style.background = "url(/templates/winm/images/ql-bg-ql3.jpg)";
			lightup(3);
			var i, s;
			for(i=0; (s = document.getElementsByTagName("span")[i]); i++) {
				if((s.className == "qlhdg") && (s.parentNode.parentNode.parentNode.id == "ql3")) { s.style.color = 'white'; s.parentNode.style.color = 'white';} 	
			}
			break;
	}

	} // endif 

}

// *********************************************************************
// Function to set the focos to the first visible field on a form
// *********************************************************************
FormUtil.focusOnfirst = function() {
	if (document.forms.length > 0) {
		for (var i=0; i < document.forms[0].elements.length; i++) {
			var oField = document.forms[0].elements[i];
			if ((oField.type != "hidden") && oField.id != "mod_search_searchword" && oField.id != "limit") { oField.focus(); return; }
		}
	}
}


// ***********************************************
// Validation and submission for the feedback form
// ***********************************************
function showError(idRed,idErr) {
	document.getElementById(idRed).style.color='red';
	document.getElementById(idErr).style.display="block";
	Missing = true;
}

function clearError(idBlk,idErr) {
	document.getElementById(idBlk).style.color='black';
	document.getElementById(idErr).style.display="none";
}

function handlefeedback() {
	var Missing = false;
	var AtCount = 0;
	var AtPosition = 0;
	var Notvalid = false;
	var Email = document.getElementById("contact_email").value;

	// Reset all the error messages to be hidden
	clearError("contact_lname","errname");
	clearError("contact_lemail","erremail");
	clearError("contact_lphone","errphone");
	clearError("contact_ltext","errtext");
	clearError("contact_lsubj","errsubj");
	
	// Validate the email address entered - not blank and it looks vaguely like an address	
	if (Email != "") {
		while (AtPosition != -1) {
			AtPosition = Email.indexOf("@",AtPosition);
			if (AtPosition != -1) { AtCount++; AtPosition++; }
		}
		if (Email.indexOf("@") == 0) { Notvalid = true; }
		else if (Email.indexOf("@") == Email.length-1) { Notvalid = true; }
		if (AtCount != 1) { 	Notvalid = true; 	}
	} else { Notvalid = true; }

	// Validate the Name field - ensure something has been entered
	if (document.getElementById("contact_name").value == "") { showError("contact_lname","errname"); }
	// Validate the Phone field 
	if (document.getElementById("contact_phone").value == "") { showError("contact_lphone","errphone"); }
	// Validate the Subject field - ensure something has been entered
	if (document.getElementById("contact_subj").value == "") { showError("contact_lsubj","errsubj"); }
	// Validate the Subject field - ensure something has been entered
	if (document.getElementById("contact_text").value == "") { showError("contact_ltext","errtext"); }
	//Highlight the errors on the form for correction
	if (Notvalid) { showError("contact_lemail","erremail"); }
	// If not errors on the form send it
	if (!Missing && !Notvalid) { document.getElementById("emailForm").submit(); }
}

