var refcheck = {
	start: function() {
		var refCheck = document.getElementById('refCheck');
		var designBy = document.getElementById('designBy');
		if (refCheck)
		{
			designBy.value = refCheck.value;
		}
	}
}

function forgot(){
	var username = document.getElementById('username').value;
	window.location = '/quote/forgot.php?username='+username;
}

//window.addEvent('domready', refcheck.start);
if (window.addEventListener) window.addEventListener("load", refcheck.start, false);
else if (window.attachEvent) window.attachEvent("onload", refcheck.start);
else window.onload=refcheck.start;

function writeEmailAddress(){
	document.write('<a h'+'ref="m'+'ailt'+'o:'+'%69%6e%66%6f%40%62%6c%75%65%32%35%36%2e%63%6f%2e%75%6b">&#105;&#110;&#102;&#111;&#64;&#98;&#108;&#117;&#101;&#50;&#53;&#54;&#46;&#99;&#111;&#46;&#117;&#107;<\/a>');
}

//when page loads start standard functions
function initialize() {
	//replace external links with open in new window
	externalLinks();
}

window.onload = initialize;


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 clickrecall(inputBox,textValue){
	if (inputBox.value=='')
	{
		inputBox.value = textValue;
	}
}

function clickclear(inputBox,textValue){
	if (inputBox.value==textValue)
	{
		inputBox.value = '';
	}
}

function sendRegisterForm()
{
	var string = $("#registerForm").serialize();
	$.getJSON("/content/processregister.php?" + string + "&callback=?", function(json) { 
		if(json.result==true)
		{
			$("#registerContent").html("<br/><h2>Thank you, your message has been sent. We will be in touch shortly.</h2><br/>");
		} else {
			$("#registerContent").append("<p style=\"color:red;\">There was a problem please refresh the page and try again</p>");
		}
	}); 

	return false;
}


$(document).ready(function() { 
	var	defaultSignupText = 'enter your email address';

	$('#main-navigation-Level-1 > li').bind('mouseover', mmul_open);
	$('#main-navigation-Level-1 > li').bind('mouseout', mmul_timer);

	$("#signup_email").focus(function(){
		if ($(this).val() == defaultSignupText) {
			$(this).val("");
		}
	});

	$("#signup_email").blur(function(){
		if ($(this).val() == "") {
			$(this).val(defaultSignupText);
		}
	});

	$("#signup_link").click(function(){
		sendRegisterForm();
	});

	$('#photo0').cycle({
		fx: 'fade',
		delay: -500
	});

	$('#photo1').cycle({
		fx: 'fade',
		delay: -1000
	});

	$('#photo2').cycle({
		fx: 'fade',
		delay: -1500
	});

	$('#photo3').cycle({
		fx: 'fade',
		delay: -2000
	});
});

