sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function chkF(field,alerttxt,reject){
	with (field) {
		if (value==null||value==""||value==reject){
			alert(alerttxt);
			return false
		} else { return true }
	}
}

function chkE(field,alerttxt){
	with (field){
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) 
			  {alert(alerttxt);return false}
		else {return true}
	}
}

function contactForm(thisForm) {
	with (thisForm){
		if (chkF(lhlName, "Please enter your name.", "asd")==false){
			lhlName.focus();
			return false
		}
		
		if (chkE(lhlEmail,"Sorry that isn't a valid Email Address")==false){
			lhlEmail.focus();
			return false
		}
		
		if (chkF(lhlContact,"Please enter your Contact Number", "asd")==false){
			lhlContact.focus();
			return false
		}
		
		if (chkF(lhlMessage, "Please enter a Message", "asd")==false){
			lhlMessage.focus();
			return false
		}
	}
}

function changeimg(img) {
	if(img.src.match("-norm")) {
		img.src = img.src.split("-norm").join("-fade");
	} else {
		img.src = img.src.split("-fade").join("-norm");
	}
}

function flash(movie, width, height, alt, id) {
	document.write('<object style="border:0;padding:0;margin:0;" id="'+id+'" type="application/x-shockwave-flash" data="'+movie+'" width="'+width+'" height="'+height+'" title="'+alt+'">\n');
	document.write('<param name="movie" value="'+movie+'" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('</object>\n');
}

function newwin(lnk) {
	window.open(lnk.href, 'newwindow','toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
	return false;
}

function areyousure(txt) {
	var q = confirm(txt);
	if (!q){ return false; }
}

var current_page = 'none';

function popup(page_var) {
	// Set the opacity filters
	document.getElementById('grey').style.opacity = 0.6;
	document.getElementById('grey').style.filter = 'alpha(opacity=45)';
	
	if(current_page == page_var) {
		// This is the current page so just hide the grey & bits
		document.getElementById('grey').style.display = 'none';
		document.getElementById('product_page').style.display = 'none';
		current_page = 'none';
		getContent('inc/app/pcgc/boxes/productloader/index.php', "product_page");
	} else {
		// There is a current page so just load the new details
		document.getElementById('grey').style.display = 'block';
		document.getElementById('product_page').style.display = 'block';
		getContent('inc/app/pcgc/boxes/productloader/index.php?a=' + page_var, "product_page");
		current_page = page_var;
	}
}

function hideall() {
	document.getElementById('grey').style.display = 'none';
	document.getElementById('product_page').style.display = 'none';
	current_page = 'none';
}

function change_image(source) {
	document.getElementById('product_image').src = source;
}

var xmlHttp
function PublishContent(content,id) {
	try {
		if (content.readyState == 4) {
			if(content.status == 200) { document.getElementById(id).innerHTML=content.responseText; }
			else { alert('\n\nContent request error, status code:\n'+content.status+' '+content.statusText); }
			}
		}
	catch(error) { /* alert('Error: '+error.name+' -- '+error.message); */ }
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try {
 		 xmlHttp = new XMLHttpRequest();   // Firefox, Opera 8.0+, Safari
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function getContent(url,id) {
	var httpRequest;
	if (window.XMLHttpRequest) {
		try { httpRequest = new XMLHttpRequest(); }
		catch(e) {}
	} 
	else if (window.ActiveXObject) {
		try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e) {
			try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 
			catch(e) {}
		}
	   }
	if(! httpRequest) {
		alert('\n\nSorry, unable to open a connection to the server.');
		return false;
	}
	httpRequest.onreadystatechange = function() { PublishContent(httpRequest,id); };
	httpRequest.open('GET',url,true);
	httpRequest.send('');
}

