function displayEmail(account, server, domain) {fulllink = "<a class=\"mailto\" href='mailto:" + account + "@" + server + "." + domain + "'>" + account + "@" + server + "." + domain + "</a>"; document.writeln(fulllink);}
function displayEmail2(account, server, domain, subject, caption) { if (subject!=="" && caption!=="") { fulllink="<a class=\"mailto\" href='mailto:"+account+"@"+server+"."+domain+"?subject="+subject+"'>"+caption+"</a>"; } else { fulllink = "<a class=\"mailto\" href='mailto:"+account+"@"+server+"."+domain+"'>"+account+"@"+server+"."+domain+"</a>";} document.writeln(fulllink);}
function displayFlash(path, width, height) {document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" WIDTH="' + width + '" HEIGHT="' + height + '" id="FlashContent"><PARAM NAME="movie" VALUE="' + path + '"><PARAM NAME="quality" VALUE="high"><PARAM NAME="AllowScriptAccess" VALUE="never"><EMBED src="' + path + '" quality="high" WIDTH="' + width + '" HEIGHT="' + height + '" NAME="FlashContent" AllowScriptAccess="never" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');}
function flashFix(theText){document.write(theText);}

// Scrolls a div across the screen: declare as hidden on page, with an id, call as href="javascript:startScroll('divid');"
// use fade('otherdivid'); if > 1 div
var boxID = "";
var xpos = -300;
var ypos = -300;
var halfs = 300;
var near_top = 20;
function startScroll(zid) {
	boxID = document.getElementById(zid);	xpos = -300;	setBoxX(zid);	showBox(zid);	do_scroll(zid);
}
function startScrollY(zid) {
	boxID = document.getElementById(zid);	ypos = (screen.height)+100;	setBoxY(zid);	showBox(zid);	do_scrollY(zid);
}
function do_scroll(zid) {
	boxID = document.getElementById(zid);
	if (xpos < halfs) {
		xpos = xpos + 10;		setBoxX(zid,xpos);		timerID = setTimeout("do_scroll(\""+zid+"\");", 10);
	}
}
function do_scrollY(zid) {
	boxID = document.getElementById(zid);
	if (ypos > near_top) {
		ypos = ypos - 10;		setBoxY(zid,ypos);		timerID = setTimeout("do_scrollY(\""+zid+"\");", 10);
	}
}
function fadeBox(zid){timerID2 = setTimeout("hideBox(\""+zid+"\")", 500);}
function setBoxX(zid){boxID = document.getElementById(zid);boxID.style.left = xpos+'px';}
function setBoxY(zid){boxID = document.getElementById(zid);boxID.style.top = ypos+'px';}
function showBox(zid){boxID = document.getElementById(zid);boxID.style.display = "block";}
function hideBox(zid){boxID = document.getElementById(zid);setBoxX(zid,xpos);boxID.style.display = "none";}
function vanishBox(zid){boxID = document.getElementById(zid);boxID.style.display = "none";}
function setBoxYSize(zid,ysize) {
	boxID = document.getElementById(zid);
	if(boxID!=null){
		boxID.style.display = ysize;
	}
}

// Job centre
function toggle2(t) {
	el=document.getElementById(t);
	elim=document.getElementById("im"+t);
	if (el.style.display == "none") {
		el.style.display="block";
		elim.src="/jobs/img/minus.gif";
	} else { 
		el.style.display="none";
		elim.src="/jobs/img/plus.gif";
	}		
}

// Change floating div to correct text on mouseover
var ent;
function doText(t,dname) {
	var xp, yp, op
	xp = dname.offsetLeft;
	yp = dname.offsetTop;
	while (dname.offsetParent) {
		op = dname.offsetParent;
		xp = xp + op.offsetLeft;
		yp = yp + op.offsetTop;
		dname = dname.offsetParent;
	}
	ent = document.getElementById("ent")
	if (ent) {
		// Customise
		ent.style.color = "#000000";
		ent.style.font = "normal x-small verdana";
		ent.style.padding = "1px 1px 1px 1px";
		ent.style.background = "#eee";
		ent.style.border = "1px solid #ddd";
		// Not below
		ent.style.position = 'absolute';
		ent.style.left = (xp+10)+"px";
		ent.style.top = (yp+24)+"px";
		ent.innerHTML = t;
		ent.style.zIndex = 99;
		ent.style.display = "block";
	}
}
function doClear(dname) {
	ent = document.getElementById("ent")
	if (ent) {
		ent.style.display = "none";
	}
}

// Ajax stuff, v=/from/root.asp
var xmlHttp
var divName
var ajaxURL
function ajax(v,dn) {
	divName = document.getElementById(dn);
	divName.innerHTML = "<img src=\"/images/timer.gif\">";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		//alert ("Browser does not support HTTP Request");
		return;
	} 
	ajaxURL=v;
	ajaxURL=ajaxURL+"&dn="+dn+"&sid="+Math.random();
	
	if (ajaxURL.indexOf("/finditforme")>-1 || 
		ajaxURL.indexOf("/suppliers/supplier_clickthru.asp")>-1 || 
		ajaxURL.indexOf("/training/training_clickthru.asp")>-1 || 
		ajaxURL.indexOf("/jobs/direct-job-app.asp")>-1) 
	{
		xmlHttp.onreadystatechange=stateChangedTracking;
	} else {
		xmlHttp.onreadystatechange=stateChanged;
	}
	xmlHttp.open("GET",ajaxURL,true);
	xmlHttp.send(null);
} 
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		divName.innerHTML=xmlHttp.responseText;
	} else {
		divName.innerHTML="";
	}
} 
function stateChangedTracking() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		divName.innerHTML=xmlHttp.responseText;
		// "_trackEvent" is the pageview event, 
		pageTracker._trackPageview(ajaxURL); 
	} else {
		divName.innerHTML="";
	}
} 

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function edieSearchCheck() {
	var myForm=document.getElementById("edieSearch");
	if (myForm) {
		var myFormValue=myForm.sfilter.value;
		if (myFormValue=='All') {myForm.action = 'http://dev4.edie.net/search/search.asp';}
		if (myFormValue=='Products') {myForm.action = 'http://dev4.edie.net/products/search.asp';}
		if (myFormValue=='News') {myForm.action = 'http://dev4.edie.net/news/search_results.asp';}
		if (myFormValue=='Jobs') {myForm.action = 'http://dev4.edie.net/jobs/search.asp';}
	}
	return true;
}

// Open user dashboard on any page.  RC June 2011
function show_dashboard(dashurl) {
	// Check url
	if (dashurl=="home") {dashurl="/user/index.asp";}
	// Get height of page
	var pageHGT=document.getElementById('nav_section_page').scrollHeight;
	// Create transp layer for firefox etc
	t2 = document.createElement("div");
	t2.id = 'surroundingDiv';
	t2.style.height = pageHGT+"px";	t2.style.width = "100%";	t2.style.background = "black";
	t2.style.position = "absolute";	t2.style.top = "0px";	t2.style.left = "0px";
	t2.style.filter = "alpha(opacity=75)";	t2.style.opacity = "0.75";
	document.getElementById('nav_section_page').appendChild(t2);
	// Surrounding div for iframe
	t = document.createElement("div");
	t.id = 'innerIframe';
	txt = "<iframe name=\"dashBoard\" onLoad=\"reSizeIframe();\" scrolling=\"no\" id=\"dashBoard\" src=\""+dashurl+"\" frameborder=\"0\" allowtransparency=\"true\" width=\"900\"></iframe>"
	t.innerHTML = txt;
	t.style.border = "3px solid #e6e6de";	t.style.background = "white";	t.style.width = "910px";
	t.style.height = "300px";	t.style.padding = "10px 10px 10px 10px";	t.style.margin = "10px 10px 10px 10px";
	t.style.position = "absolute";	t.style.top = "24px";	t.style.left = "auto";	t.style.zIndex = "100";
	document.getElementById('nav_section_page').appendChild(t);
	// IE transp fix
	bg = document.getElementById('thePage');
	if (bg) {
	  bg.style.filter = "alpha(opacity=25)";	bg.style.opacity = "0.25";
	}
}
// Close dashboard
function close_dashboard() {
	var dashBoard=document.getElementById('dashBoard');
	var innerIFrame=document.getElementById('innerIframe');
	var surroundingDiv=document.getElementById('surroundingDiv');
	if (dashBoard) {
		dashBoard.parentNode.removeChild(dashBoard);
		innerIFrame.parentNode.removeChild(innerIFrame);
		surroundingDiv.parentNode.removeChild(surroundingDiv);
	} else {
		document.location='/';
	}
}
// Useful if you don't know if dashboard is open or not, this will either open it, or just redirect within it!
function dash_open_or_redirect(dashurl) {
	var surroundingDiv=parent.document.getElementById('surroundingDiv');
	if (surroundingDiv) {
		document.location=dashurl;
	} else {
		show_dashboard(dashurl);
	}
}
// This is called on load of new iframe page, it resizes iframe and div to right size.
// Based on several solutions on line, this is a combination that is lite and works cross-browser
function reSizeIframe() {
	var dashBoard=document.getElementById('dashBoard');
	var innerIFrame=document.getElementById('innerIframe');
	var surroundingDiv=parent.document.getElementById('surroundingDiv');
	// Make small first! This fixes resize to smaller glitch
	dashBoard.height=10;
	innerIFrame.style.height="10px";
	// Find the height newly loaded page
	var newPageHeight=document.getElementById('dashBoard').contentWindow.document.body.scrollHeight;
	// Resize iframe, surrounding div and dark layer
	dashBoard.height=newPageHeight;
	innerIFrame.style.height=(newPageHeight+10)+"px";
	// Fix for parent dark layer resize for small pages
	var pageHGT=parent.document.getElementById('nav_section_page').scrollHeight;
	if (newPageHeight>pageHGT) {
		surroundingDiv.style.height=(newPageHeight+300)+"px";
	} else {	
		surroundingDiv.style.height=pageHGT+"px";
	}
}

