/* 
	DoubleClick DART Natural Search Tracking Code
*/

if (document.referrer){
	var ord = Math.random()*1000000000000;
	document.write('<SCRIPT language="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/N4378.N10466.nso.codesrv/B4476212;dcadv=2732908;sz=1x2;ord=' + ord + '?"><\/SCRIPT>');
}

/*
	MediaVest Tracking Library for www.qhotels.co.uk
	v1.1 2010-05-19
	(c) MediaVest Leeds 2010
*/

var mv_GAID = "";

function mv_GetCookie(strName){
	var i = document.cookie.indexOf(strName + "=");
	if (i != -1){
		i += strName.length + 1;
		var j = document.cookie.indexOf(";", i);
		if (j == -1){
			j = document.cookie.length;
		}
		return document.cookie.substring(i, j);
	}
	return "";
}

function mv_GetGAID() {
	var s = mv_GetCookie("__utma");
	var a = s.split(".");
	if (a.length >= 2) return a[1];
	return "";
}

function mv_GetParam(strElementName) {
	var e = document.getElementById(strElementName);
	if (!e) return "";
	return encodeURIComponent(e.value);
}

function mv_CreateIFrame(strURL) {
	var e = document.getElementById("mv_TargetDiv");
	if (!e) return "";
	var newIFrame=document.createElement('iframe');
	newIFrame.src=strURL;
	newIFrame.width="1";
	newIFrame.frameBorder="0";
	newIFrame.allowTransparency=true;
	newIFrame.height="1";
	e.appendChild(newIFrame);	
}

function mv_GetEventTarget(evt,tag){
	var e = evt.target || evt.srcElement;
	while (e.tagName && (e.tagName != tag)){
		e = e.parentElement || e.parentNode;
	}
	return e;
}

function mv_HookEvent(objElement, strEvent, fcnHandler){
	if ((typeof(fcnHandler) == "function") && objElement){
		if (objElement.addEventListener){
			objElement.addEventListener(strEvent, fcnHandler, true);
		}
		else if(objElement.attachEvent){
			objElement.attachEvent("on" + strEvent, fcnHandler);
		}
	}
}

function mv_LinkClick(evt) {
	var a;
	evt =  evt || (window.event || false);
	if (evt) {
		var e = mv_GetEventTarget(evt, "A");

		/* M3. Main Website - Email Click */
		if (e.protocol == "mailto:") {
			a = Math.random() * 10000000000000 + "";
			var strEmail = encodeURIComponent(e.href.substring(7));
			mv_CreateIFrame("http://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=03mai060;u11=" + strEmail + ";u12=" + mv_GAID + ";ord=" + a + "?");
		}

		/* M6. Main Website - Brochure Download	*/
		if (e.pathname.substring(e.pathname.lastIndexOf(".") + 1, e.pathname.length).toLowerCase() == "pdf") {
			a = Math.random() * 10000000000000 + "";
			var strPage = encodeURIComponent(e.pathname);
			mv_CreateIFrame("https://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=m6mai948;u10=" + strPage + ";u12=" + mv_GAID + ";ord=" + a + "?");
		}
	}
}

function mv_WindowLoad() {
	var arrLinks = document.getElementsByTagName("a");
	for (var i = 0; i < arrLinks.length; i++) {
		mv_HookEvent(arrLinks[i], "mousedown", mv_LinkClick );
	}
}

function mv_Track() {
	mv_GAID = encodeURIComponent(mv_GetGAID());
	
	var a = Math.random() * 10000000000000 + "";
	var strPage = encodeURIComponent(window.location.host + window.location.pathname);
	
	// M1. Main Website - Generic Unique
	mv_CreateIFrame("http://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=01mai497;u10=" + strPage + ";u12=" + mv_GAID + ";ord=1;num=" + a + "?");

	/* M2. Main Website - Contact Us */
	if (document.location.pathname == "/contact-us.aspx") {
		mv_CreateIFrame("http://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=02mai476;u12=" + mv_GAID + ";ord=1;num=" + a + "?");
	}

	/* M4. Main Website - Newsletter Signup */
	if (document.location.pathname == "/newsletter-thankyou.aspx") {
		mv_CreateIFrame("http://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=m4mai355;u1=;u9=;u12=" + mv_GAID + ";ord=1;num=" + a + "?");
	}
	
	/* M5. Main Website - Conference Enquiry */
	if (document.location.pathname == "/conferences/enquiry-thankyou.aspx") {
		mv_CreateIFrame("http://fls.doubleclick.net/activityi;src=2725819;type=mainw102;cat=m5mai514;u1=;ord=" + a + "?");
	}
	
	mv_HookEvent(window, "load", mv_WindowLoad);
}
