function $import(src){
	var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}


// import with a random query parameter to avoid caching
function $importNoCache(src){
	var ms = new Date().getTime().toString();
	var seed = "?" + ms; 
	$import(src + seed);
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window) ": "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
//			anchor.onclick = 'javascript: pageTracker._trackPageview (\'/outgoing/'+anchor.href+'\');';
			var track = anchor.href;
			track = track.replace('http://','');
			anchor.onclick = function() { 
				pageTracker._trackPageview('/outgoing/'+track);
			}
		}
	}
}


function xmlhttpPost(Url,varString,id) {
	var xmlHttpReq = false;
	var self = this;
	var urlToSend = Url;
	
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
	self.xmlHttpReq.open('POST',urlToSend, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			display(id,self.xmlHttpReq.responseText);
		}
	}
	self.xmlHttpReq.send(varString);
	return true;
}

function display(id, str) {
	document.getElementById(id).innerHTML = str;
}


var num = 0;
function special_offer_attractions() {
	if (document.getElementById('special_offer_attraction_area'))
	{
		if (specialOfferAttractions.length>1)
		{
			setInterval('runupdate()', 5000);
		}
	}
}

function runupdate() {
	display('special_offer_attraction_area', specialOfferAttractions[num]);
	num++;
	if (num >= specialOfferAttractions.length) num = 0;
}

var attractionImageArray = Array();
var num2 = 0;
function attractionImages() {
	if (document.getElementById('picture'))
	{
		setInterval('run_attraction_image_update()', 5000);
	}
}

function run_attraction_image_update() {
	display('picture', attractionImageArray[num2]);
//	alert('picture info is:' + attractionImageArray[num]);
	num2++;
	if (num2 >= attractionImageArray.length) num2 = 0;
}


function check_valid_brochure_request()
{
	var errorList = '';

	if(document.getElementById('name').value=='') errorList += '\n - Name';
	if(document.getElementById('address1').value=='') errorList += '\n - Address Line 1';
	if(document.getElementById('town').value=='') errorList += '\n - Town';
	if(document.getElementById('county').value=='') errorList += '\n - County';
	if(document.getElementById('postcode').value=='') errorList += ' \n - Postcode';

	if (errorList!='')
	{
		errorList = 'Please complete the following information' + errorList;
		alert(errorList);
		return false;
	} else {
		return true;
	}

}

function specialOffer(url)
{
	window.open(url,'vouchers','left=20,top=20,width=270,height=350,toolbar=0,resizable=1,scrollbars=1');
}

function allSpecialOffers(url)
{
	window.open(url,'vouchers','left=20,top=20,width=800,height=640,toolbar=1,menubar=1,resizable=1,scrollbars=1');
}


/*
	OLD JAVASCRIPT BELOW
*/


function check_executive_form()
{
	var errorList = '';
	var areaSelected = false;

	if(form.first_name.value=='') errorList += '\n - First Name';
	if(form.last_name.value=='') errorList += '\n - Last Name';
	if(form.address1.value=='') errorList += '\n - Address Line 1';
	if(form.town.value=='') errorList += '\n - Town';
	if(form.county.value=='') errorList += '\n - County';
	if(form.postcode.value=='') errorList += ' \n - Postcode';
	if((form.mobile_phone.value=='') && (form.home_phone.value=='') && (form.work_phone.value=='')) errorList += '\n - A contact number';
	if(form.email.value=='') errorList += '\n - Email Address';
	if((form.mortgage_advice.checked=='') && (form.finance.checked=='') && (form.executive.checked=='') && (form.emailproperties.checked=='') && (form.textproperties.checked=='')) errorList += '\n - What services would you like information on';


	for(i=0; i<form.millsoppsareas.length; i++){
		if (form.millsoppsareas[i].checked==true)
		{
			areaSelected = true;
		}
	}

	if (areaSelected==false)  errorList += '\n - An area of interest';


	if (errorList!='')
	{
		errorList = 'Please complete the following information' + errorList;
		alert(errorList);
		return false;
	} else {
		return true;
	}
}

function updateCheckBox(checkBoxId)
{
	if (document.getElementById(checkBoxId).checked==true)
	{
		document.getElementById(checkBoxId).checked=false;
	} else {
		document.getElementById(checkBoxId).checked=true;
		document.getElementById('allareas').checked=false;
	}
	
}

function checkAllAreas(checkBoxId)
{
	if ((document.getElementById(checkBoxId).checked==true) && (document.getElementById('allareas').checked==true))
	{
		document.getElementById('allareas').checked=false;
	}
}

var num = 1;

function lastest_property() {
	setInterval("update()", 10000);
}

function update() {
	display("latestproperty_header_padded", latestProperties[num][0]);
	display("latestproperty_photo", latestProperties[num][1]);
	display("latestproperty_footer_padded", latestProperties[num][2]);
	num++;
	if (num == latestProperties.length) num = 0;
}




function getStyleObject(objectId) {
	// cross-browser function to get an object's style object given its
	if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	} else {
		return false;
	}
} // getStyleObject




/*
function getquerystring() {
	var form = document.forms['f1'];
	var word = form.word.value;
	qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
	return qstr;
}
*/

function openRegisterWindow()
{
	var currentTime = new Date()
	registerObject = window.open("/register/index.php?clean="+ currentTime.getTime(),"reqister","left=100,top=50,width=470,height=530,toolbar=0,resizable=1,menubar=0,scrollbars=1");
	registerObject.focus()
}

function closeRegisterWindow()
{
	opener.focus()
	window.close();
	return false;
}


function unblockParent()
{
	opener.$(".offer-cover").unblock();
	opener.$(".offer-cover-not-required").unblock();
	opener.$(".booklet-cover").unblock();
	opener.$(".booklet-cover-not-required").unblock();
	opener.$(".allspecialoffertemp-cover").unblock();
	opener.$(".allspecialoffertemp-cover-not-required").unblock();
	opener.$(".print-all-offers-link").css("display", "block");
}

function blockParent()
{
	opener.$(".offer-cover-not-required").block({ 
		message: "<div class=\"inner-tube\">In order to download vouchers please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "120px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 

	opener.$(".offer-cover").block({ 
		message: "<div class=\"inner-tube\">In order to download vouchers please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "120px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 

	opener.$(".booklet-cover-not-required").block({ 
		message: "<div class=\"inner-tube\">In order to view the booklet, please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "180px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 

	opener.$(".booklet-cover").block({ 
		message: "<div class=\"inner-tube\">In order to view the booklet, please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "180px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 

	$(".print-all-offers-link").css("display", "none");
}


$(document).ready(function() { 

	$("#special-offer-area").css("display", "block");
	$(".offer-cover").block({ 
		message: "<div class=\"inner-tube\">In order to download vouchers please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "120px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 

	$(".booklet-cover").block({ 
		message: "<div class=\"inner-tube\">In order to view the booklet, please <a href=\"#\" onclick=\"openRegisterWindow();\">click here to register.</a></div>", 
		css: { border: "1px solid #3DB6B6", width: "180px", backgroundColor: "#fff", fontSize: "120%" } 
	}); 


	externalLinks();

/*	
	//was being used to track visitor activity
	$("a").click( function() {
		var varString = "action=trackvisitor&url=" + $(this).attr("href");
		xmlhttpPostStats(varString);
	});
*/


});
