var base = (window.opener&&window.opener.base)?window.opener.base:(window.opener?window.opener:window);

function checkQuestionLength(if_ok_func, db_site_id) {
	var question = document.forms['form'].elements['question'].value;
	if(question=="" || question=="<?=$defaultValue?>")
		if_ok_func.call();
	else {
		question = question.split(' ');
		if(question.length<40 && db_site_id!=1) {
			_gaq.push(['_trackPageview', '/confirm.html']);
			confirm('We find our clients are more likely to receive the answer they\'re looking for when they enter more detailed questions.', function() {
				if_ok_func.call();
			}, function() {
				_gaq.push(['_trackPageview', '/more.html']);
			});
		}
		else {
			if_ok_func.call();
		}
	}
}

function focusFormField(f, e) {
	if(document.forms[f] && document.forms[f].elements[e]) {
		document.forms[f].elements[e].focus();
		document.forms[f].elements[e].click();
	}
}

function silentSubmit(f) {
	f.elements['silent'].value = 1;
	f.submit();
}

function createTableRow(f, _, c) {
	var tr = document.createElement('TR');
	if(c)
		tr.className = c;
	for(var i=0;i<_.length;i++) {
		var td = document.createElement('TD');
		if(_[i][0]=='text') {
			td.style.fontWeight = 'bold';
			td.innerHTML = _[i][1];
			if(_[i][2])
				td.colspan = _[i][2];
			if(_[i+1] && _[i+1][0]=='textarea')
				td.style.verticalAlign = 'top';
		}
		else if(_[i][0]=='input') {
			var input = document.createElement('INPUT');
			input.type = 'text';
			input.name = _[i][1];
			input.style.width = _[i][2];
			td.appendChild(input);
		}
		else if(_[i][0]=='textarea') {
			var input = document.createElement('TEXTAREA');
			input.name = _[i][1];
			input.style.width = _[i][2];
			input.style.height = _[i][3];
			td.appendChild(input);
		}
		else if(_[i][0]=='select') {
			var input = document.createElement('SELECT');
			input.name = _[i][1];
			input.style.width = _[i][2];
			var opts = f.elements[_[i][3]].value.split(',');
			for(var j=0;j<opts.length;j++) {
				var option = document.createElement('OPTION');
				option.value = opts[j];
				option.text = opts[j];
				input.options[input.options.length] = option;
			}
			td.appendChild(input);
		}
		tr.appendChild(td);
	}
	return tr;
}

function owningTableRow(e) {
	return owningElement(e, 'TR');
}

function owningTableBody(e) {
	return owningElement(e, 'TBODY');
}

function owningElement(e, t) {
	return e.tagName==t?e:owningElement(e.parentNode, t);
}

function toClip(str) {
	if(window && window.clipboardData && window.clipboardData.setData)
	    window.clipboardData.setData('Text', str);
	else {
		var s = document.getElementById('displayClipData');
		if(str) {
			s.style.borderStyle = 'dashed';
			s.style.borderWidth = '1px';
			s.style.borderColor = '#c0c0c0';
			s.style.marginRight = '3px';
			s.style.padding = '2px';
		}
		else
			s.style.borderWidth = '0px';
		s.innerHTML = str;
	}
}

function openWindow(a, width, height, noscroll, noresize, address) {
	var r;
	if(base!=window)
		r = base.openWindow(a, width, height, noscroll, noresize, address);
	else {
		var w = 0;
		var wtyycemc = document.cookie.split(';');
		for(var i=0;wtyycemc[i];i++) {
			if(typeof wtyycemc[i]=='string') {
				var c = wtyycemc[i].split('=');
				if(trim(c[0])=='open_windows')
					w = c[1];
			}
		}
		r = window.open((typeof a)=='string'?a:a.href, 'Window'+(w++), (width?'width='+width+',':'')+(height?'height='+height+',':'')+'location='+(address?'yes,toolbar=yes':'no')+',status=yes,scrollbars='+(noscroll?'no':'yes')+',resizable='+(noresize?'no':'yes'));
		document.cookie = 'open_windows='+w+'; path=/';
	}
	return r;
}

function reloadBase() {
	if(base!=window)
		base.reloadBase();
	else
		window.location.href = window.location.href;
}

function trim(_) {
	return _.replace(/^\s*|\s*$/g, '');
}

function elementPos(o) {
	var r = {x:o.offsetLeft,y:o.offsetTop};
	if(o.offsetParent) {
		var t = elementPos(o.offsetParent);
		r.x+=t.x;
		r.y+=t.y;
	}
	return r;
}



/************TESTING CODE FOR SLIDE EFFECT*********************/

var slideSpeed = 2;	// Higher value = faster
var slideTimer = 20;	// Lower value = faster
var activeId = '';
var slidingHeight=75;
var slideInProgress=false;

function slideDivId(id)
{
	slideDiv(document.getElementById(id));
}

function slideDiv(div)
{
	if(slideInProgress)return;
	slideInProgress = true;

	if ((activeId) && (activeId==div.id)){
		activeId=false;
		slideContent(div.id,slideSpeed);
	}else{
		activeId=div.id;
		slideContent(div.id,(slideSpeed*-1));
	}
}

function slideContent(inputId,direction)
{
	var num_top=0;
	var obj =document.getElementById(inputId);
	var top = obj.style.top;
	top = top.substring(0,top.indexOf('p'));

	num_top=top;
	top = eval((top*1) + (direction*1));
	rerunFunction = true;

	if(direction<0)
	{
		if(top<=-slidingHeight){
			top = -slidingHeight;
			rerunFunction = false;
		}
	}

	if(direction>0)
	{
		if(top>=0){
			top = 0;
			rerunFunction = false;
		}
	}

	obj.style.top = top+ 'px';

	if(rerunFunction){
		setTimeout('slideContent("'+ inputId + '",' + direction + ')',slideTimer);
	}else{
		if(activeId)
			activeId=inputId;
		slideInProgress = false;
	}
}

function mouse_over_image(div){

	/*switch (div.id)	{
		case 'features_image_customise':
			var div_on = document.getElementById(div.id+'_off');
			div_on.style.backgroundImage='url(./images/content/boxii/customise_box_rollover.png)';
		break;
		case 'features_image_sticky':
			var div_on = document.getElementById(div.id+'_off');
			div_on.style.backgroundImage='url(./images/content/boxii/sticky_offers_box_rollover.png)';
		break;
		case 'features_image_money':
			var div_on = document.getElementById(div.id+'_off');
			div_on.style.backgroundImage='url(./images/content/boxii/money_saving_box_rollover.png)';
		break;
		default:
		break;
	}*/

	var div_on = document.getElementById(div.id+'_on');
	var div_off = document.getElementById(div.id+'_off');
	div_on.style.display='block';
	div_off.style.display='none';
}

function mouse_out_image(div){
	var div_on = document.getElementById(div.id+'_on');
	var div_off = document.getElementById(div.id+'_off');
	div_off.style.display='block';
	div_on.style.display='none';
}
/************TESTING CODE FOR SLIDE EFFECT*********************/

function validateContactUsForm() {

	var elements = new Array("name","telephone","email","message", "security_code");
	var check=false;
	var contactUsForm = document.contact_us_form;


	for(var i=0; elements[i]; i++){
		if(document.getElementById(elements[i]).value){
			document.getElementById(elements[i]).style.border = "1px solid #7f9db9";
		} else {
			document.getElementById(elements[i]).style.border = "1px solid red";
			check=true;
		}
	}

	var phones = new Array("telephone");
	for(var i=0; phones[i]; i++){
		if (!validatePhone(document.getElementById(phones[i]).value))
		{
			document.getElementById(phones[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if (!validateEmail(document.getElementById("email").value))
	{
		document.getElementById("email").style.border = "1px solid red";
		check=true;
	}

	var names = new Array("name");
	for(var i=0; names[i]; i++){
		if (!validateName(document.getElementById(names[i]).value))
		{
			document.getElementById(names[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if(check){
		document.getElementById("error1").innerHTML = "Please complete the form.";
		return false;
	} else {
		document.getElementById("error1").innerHTML = "";
		contactUsForm.submit();
		return true;
	}
} // function validateContactUsForm()

function backFirstSectionP(){
	document.getElementById('psign_up_form_1').style.display='';
	document.getElementById('psign_up_form_2').style.display='none';
}
function backSecondSectionP(){
	document.getElementById('psign_up_form_2').style.display='';
	document.getElementById('psign_up_form_3').style.display='none';
}

function showSecondSectionP(){
	validateFirstSectionP();
}
function showThirdSectionP(){
	validateSecondSectionP();
}

function validateFirstSectionP(){
	var elements = new Array("name","surname","telephone","email","password","confirm_password");
	var check=false;
	var signUpForm = document.psign_up_form;

	if ((document.getElementById("password").value!=document.getElementById("confirm_password").value))
	{
		document.getElementById("password").style.border = "1px solid red";
		document.getElementById("confirm_password").style.border = "1px solid red";
		document.getElementById("error1").innerHTML = "Passwords don't match.";
		return false;
	}

	if(signUpForm.title.value==''){
		document.getElementById('title').style.border = "1px solid red";
		check=true;
	}

	for(var i=0; elements[i]; i++){
		if(document.getElementById(elements[i]).value){
			document.getElementById(elements[i]).style.border = "1px solid #7f9db9";
		} else {
			document.getElementById(elements[i]).style.border = "1px solid red";
			check=true;
		}
	}

	var phones = new Array("telephone");
	for(var i=0; phones[i]; i++){
		if (!validatePhone(document.getElementById(phones[i]).value))
		{
			document.getElementById(phones[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if (!validateEmail(document.getElementById("email").value))
	{
		document.getElementById("email").style.border = "1px solid red";
		check=true;
	}

	var names = new Array("name","surname");
	for(var i=0; names[i]; i++){
		if (!validateName(document.getElementById(names[i]).value))
		{
			document.getElementById(names[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if(check){
		document.getElementById("error1").innerHTML = "Please complete the form.";
		return false;
	} else {
		document.getElementById("error1").innerHTML = "";
	document.getElementById('psign_up_form_2').style.display='';
	document.getElementById('psign_up_form_1').style.display='none';
		return true;
	}
}

function validateSecondSectionP(){
	var elements = new Array("company_name","city","address","postcode","website");
	var check=false;
	var signUpForm = document.psign_up_form;


	for(var i=0; elements[i]; i++){
		if(document.getElementById(elements[i]).value){
			document.getElementById(elements[i]).style.border = "1px solid #7f9db9";
		} else {
			document.getElementById(elements[i]).style.border = "1px solid red";
			check=true;
		}
	}


	var names = new Array("city");
	for(var i=0; names[i]; i++){
		if (!validateName(document.getElementById(names[i]).value))
		{
			document.getElementById(names[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if(check){
		document.getElementById("error2").innerHTML = "Please complete the form.";
		return false;
	} else {
		document.getElementById("error2").innerHTML = "";
	document.getElementById('psign_up_form_3').style.display='';
	document.getElementById('psign_up_form_2').style.display='none';
		return true;
	}
}

function validateSignUpP(){

	var elements = new Array("bank_name","account_name","account_number","sort_code","bank_address","bank_city","bank_postcode");
	var check=false;
	var signUpForm = document.psign_up_form;


	for(var i=0; elements[i]; i++){
		if(document.getElementById(elements[i]).value){
			document.getElementById(elements[i]).style.border = "1px solid #7f9db9";
		} else {
			document.getElementById(elements[i]).style.border = "1px solid red";
			check=true;
		}
	}


	if (!validateAccountNumber(document.getElementById('account_number').value))
		{
			document.getElementById('account_number').style.border = "1px solid red";
			check=true;
		}

	if (!validateSortCode(document.getElementById('sort_code').value))
		{
			document.getElementById('sort_code').style.border = "1px solid red";
			check=true;
		}


	var names = new Array("account_name");
	for(var i=0; names[i]; i++){
		if (!validateName(document.getElementById(names[i]).value))
		{
			document.getElementById(names[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if(check){
		document.getElementById("error3").innerHTML = "Please complete the form.";
		return false;
	} else {
		//document.getElementById("error3").innerHTML = "";
	signUpForm.submit();
		return true;
	}
}

function validateSignUpA(){
//validates the advertisers sign up form

var elements = new Array("company_name","name","telephone","email","city","password","confirm_password","address","postcode");
	var check=false;
	var signUpForm = document.asign_up_form;

	if ((document.getElementById("password").value!=document.getElementById("confirm_password").value))
	{
		document.getElementById("password").style.border = "1px solid red";
		document.getElementById("confirm_password").style.border = "1px solid red";
		document.getElementById("error1").innerHTML = "Passwords don't match.";
		return false;
	}


	for(var i=0; elements[i]; i++){
		if(document.getElementById(elements[i]).value){
			document.getElementById(elements[i]).style.border = "1px solid #7f9db9";
		} else {
			document.getElementById(elements[i]).style.border = "1px solid red";
			check=true;
		}
	}

	var phones = new Array("telephone");
	for(var i=0; phones[i]; i++){
		if (!validatePhone(document.getElementById(phones[i]).value))
		{
			document.getElementById(phones[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if (!validateEmail(document.getElementById("email").value))
	{
		document.getElementById("email").style.border = "1px solid red";
		check=true;
	}

	var names = new Array("name");
	for(var i=0; names[i]; i++){
		if (!validateName(document.getElementById(names[i]).value))
		{
			document.getElementById(names[i]).style.border = "1px solid red";
			check=true;
		}
	}

	if(check){
		document.getElementById("error1").innerHTML = "Please complete the form.";
		return false;
	} else {
		document.getElementById("error1").innerHTML = "";
		signUpForm.submit();
		return true;
	}
}

function validateEmail(email) {

		var at="@"
		var dot="."
		var lat=email.indexOf(at)
		var lstr=email.length
		var ldot=email.indexOf(dot)
		var str = email;
		if (email.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true
	}

function validateName(name){
	return (name.toString().search(/^[A-Za-z ]+$/) == 0);
}

function validateAccountNumber(strAccountNum){
	return (strAccountNum.toString().search(/^[0-9]{8}$/) == 0);
}

function validateSortCode(strSortCode){
	return (strSortCode.toString().search(/^[0-9]{2}(-)?[0-9]{2}(-)?[0-9]{2}$/) == 0);
}

function validatePhone(strPhone){
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	var bracket=3
	strPhone=trim(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
	var brchr=strPhone.indexOf("(")
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))&&(c != '.')) return false;
    }
    // All characters are numbers.
    return true;
}

function trim(s)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkEnter(e){
	//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
//e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//alert(document.forms[0].name);
//alert(document.forms[0].id);
		if (document.forms[0].name=='sign_up_form')
		{
			validateSignUpForm();
		}

	document.forms[0].submit() //submit the form
	return false
	}
	else{
	return true
	}
}

function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}

	return vars;
}

function checkFragment(){
	var fragment = window.location.hash;
	if(fragment && (fragment.indexOf('|') != -1)){
		// #object.function|var,var,var
		fragment = fragment.substring(1,fragment.length);
		if(fragment.indexOf('.') != -1){
			fragment = fragment.split('.');
			var obj = fragment[0];
			var func = fragment[1].split('|');
			func = func[0];
			var vars = fragment[1].split('|')[1].split(',');
			eval('xajax_' + obj + '.' + func + '(' + vars + ')');
			//alert('xajax_' + obj + '.' + func + '(' + vars + ')');
		} else {
			var fragment = fragment.split('|');
			var func = fragment[0];
			var vars = fragment[1].split(',');
			eval(func + '(' + vars + ')');
			//alert(func + '(' + vars + ')');
		}

	}
}

function updateFragment(object,func,vars){
	if(func){
		window.location.hash = '#';
		if(object){
			window.location.hash += object + '.';
		}
		vars = varsToPrint(vars);
		window.location.hash += func + '|' + vars;
	} else {
		window.location.hash = '';
	}
}

function varsToPrint(vars){
	if((typeof vars) == 'Array'){
		for(var i = 0; i < vars.length; i++){
			if((typeof vars[i]) == 'Array'){
				vars[i] = '[' + varsToPrint(vars[i]) + ']';
			} else if(vars[i]) {
				vars[i] = "'" + vars[i] + "'";
			}
		}
	} else if(vars) {
		vars = "'" + vars + "'";
	}
	return vars;
}

function domReplace(id,opts,vals){
	var doc = document.getElementById(id);
	while(doc.options[0]){
		doc.remove(0);
	}
	for(i=0;i < opts.length;i++){
		var new_opt = document.createElement('option');
		new_opt.value = vals[i];
		new_opt.text = opts[i];
		try {
			doc.add(new_opt,null);
		} catch(ex) {
			doc.add(new_opt);
		}
	}
}

function refreshSelect(id,html){
	var doc = document.getElementById(id);
	//var html = doc.innerHTML;
	var reg_string = 'value="([^"]+)"[^>]*>([^<]+)';
	var reg = new RegExp(reg_string,'gi');
	reg.lastIndex = 0;
	var m;
	var i=0;
	var opts = [];
	var vals = [];
	while(m = reg.exec(html)) {
		if(m != null){
			opts[i] = m[2];
			vals[i] = m[1];
		}
		i++;
	}
	domReplace(id,opts,vals);
}

var SUGS=239;
var autoCompleteAddress = SITE_URL + '/?_l='+SUGS;
var searchTerm = '';


/*
 * Search for all needles and replace within the given string
 *
 * In this instance - looks for matches within row tables <tr> blocks.
 * If greater functionality is required - this should be tweaked
 *
 * array needles
 * string replace
 * string haystack
 * return string
 */
function strReplace(needles,replace,haystack) {
	var exp = new RegExp("\\b("+needles.join("|")+")\\b","gi");

	haystack = haystack.replace(/<tr(.|\s)*?<\/tr>/gi,function(row) {
		if (row.match(exp)) {
			return replace;
		}
		else {
			return row;
		}
	});

	return haystack;
}

var page_requested = 0;
var page_order = 'page.title';
var page_asc = true;

function updatePageRequest(r){
	page_requested = r;
	document.getElementById('page-link-add').style.display = 'block';
}

var checkAdd = function(input,sel){
	input = sel.innerHTML;
	xajax_Basket.checkWord(input,page_requested);
}

var updateSuggestions = function(query){
	query = query.value;
	query = 'search=' + query + '&page_requested='+page_requested;
	return query;
}




//-----------------------------------------------------------------------------------------------------

/**
* Replaces the normal javascript alert window with an overlib
*
* for some reason calling nd() once will not close the window, unless
* clicked twice - so added twice here, to allow the OK to be clicked once
*/
function displayAlert(msg,clk) {
  var click=clk?clk+";":"";
  var m = '<div class="overlibAlert">\
  			<p class="alert">'+msg+'<br />\
              <br />\
              <a class="normalLink" href="javascript:void(0);" onclick="cClick();'+click+'">\
                  OK\
              </a>\
              <br />\
          </p>\
          </div>';
  var c = '<div><img src="'+SITE_URL+'/images/content/infoLogo.png" text-align width="16px" height="16px"><strong class="white"> '+SITE_NAME+'</strong></div>';
  //alert(msg);
  overlib(m,CAPTION,c,MIDX,0,MIDY,0,WIDTH,350,SHADOW,STICKY,MODAL,MODALSCROLL,MODALOPACITY,60);
}

/**
* Similar to above, but a way to collect and easily style the various help information points
*/
function showInfo(msg,w) {
	var m = '<div class="overlibInfo">'+msg+'</div>';
  overlib(m,WIDTH,w?w:250, SHADOW);
}

function hideInfo() {
  return nd();
}


/*
 * Replaces the normal javascript/xajax confirm window with an overlib
 */
function displayConfirm(msg,skip) {
	var m = '<div class="overlibAlert">\
				<p class="alert">'+msg+'<br />\
					<br />\
					<a class="normalLink" href="javascript:void(0);" onclick="cClick();return false;">Yes</a>\
					&nbsp;&nbsp;&nbsp;&nbsp;\
					<a class="normalLink" href="javascript:void(0);" onclick="cClick();skipCommands('+skip+');return false;">No</a>\
					<br />\
				</p>\
			</div>';
  var c = '<div><strong class="white">'+SITE_NAME+'</strong></div>';
  overlib(m,CAPTION,c,MIDX,0,MIDY,0,WIDTH,350,SHADOW,STICKY,MODAL,MODALSCROLL,MODALOPACITY,60);
}

function skipCommands(skip) {
	if (skip) {
		while(0 < skip){
			xajax.tools.queue.pop(xajax.response);
			--skip;
		}
	}
}

//-------------------------------------------------------------------------------------------------------

/**
 * Validates all elements of a form f except those in array x.
 * Outputs an error
 */
function checkForm(f,x,error) {
    var e = document.forms[f].elements, i, check=true, chk=cr=false;

    // object converter
    function oc(a) {
        var o={},i;
        for (i=0;i<a.length;i++) {
            o[a[i]]='';
        }
        return o;
    }

    // loop for all the forms elements
    for (i=0;i<e.length;i++) {
        // only check the elements that havent been excluded (within x)
        if (!(e[i] in oc(x))) {
            switch (e[i].type) {
                case 'radio':
                case 'checkbox':
                    // here we are looking for at least one element to be checked
                    // first make a note that the form contains a checkbox or radio button
                    cr=true;
    				if (!chk && e[i].checked) {
                        chk = true;
                    }
                    break;

                case 'text':
				case 'textarea':
				case 'password':
    				if (!e[i].value) {
                        check = false;
                    }
				    break;

			    case 'select':
                    if (!e[i].selectedIndex.value) {
                        check = false;
                    }
			        break;

			    default:
			        // dont process hidden, submit, reset, etc... elements
			        break;
            }
        }
    }

    // If there are no checked radio or checkboxes
    if (cr && !chk) {
        check=false;
    }
    // post the form if all is ok, else display the error in the provided location
	if(check){
		document.forms[f].submit();
	} else {
		document.getElementById(error).innerHTML = 'Please fill in all required fields';
	}
}

//-----------------------------------------------------------------------

function toggleVisibility(id){
	var b;
	if(b=document.getElementById(id)){
		//nout
	} else {
		b=id;
	}
	if(b.style.display=='block'){
		b.style.display = 'none';
	} else {
		b.style.display = 'block';
	}
	return;
}

//-----------------------------------------------------------------------

function changeFormLink(form,l) {
    var f = document.forms[form];
    f._l.value=l;
}

//-----------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------

function checkDateSelect(year,month,day){
	year = document.getElementById(year);
	month = document.getElementById(month);
	day = document.getElementById(day);

	var dayValue = parseInt(day.options[day.selectedIndex].value);

	var leap = false;
	if(year%4==0){
		leap = true;
	}

	var to = 0;
	switch(parseInt(month.options[month.selectedIndex].value)){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			to = 31;
			break;
		case 2:
			if(leap){
				to = 29;
			} else {
				to = 28;
			}
			break;
		default:
			to = 30;
			break;
	}

	if (dayValue>=to) {
		day.selectedIndex=to-1;
	}

	for(var i=0;i<31;i++){
		day.options[i].disabled = false;
		if(i>=to){
			day.options[i].disabled = true;
		}
	}
}

// -----------------------------------------------------------------------------------------------

/**
 * Used to hide a button once its clicked
 *
 * useful for one click events - like confirming the paypal total
 */
function hideButton(id) {
    var el = document.getElementById(id);
    el.innerHTML="";
    el.style.padding="15px 0 0 15px";
    el.innerHTML="Please wait...";
}

// -----------------------------------------------------------------------------------------------

function setSelectedValue(v) {
	selectedItem=v;
}

//Data & function(s) for ISO 3166-1 country names and codes


//Get HTML for a list of Select options of ISO 3166-1 country names and codes.
//eg "<option value="GB">United Kingdom</option>
//  <option value="US" SELECTED>United States</option>"
//Parameters: strSelectedValue is a value that will be marked as "SELECTED"
//          if it is found in the options list
function getCountryOptionsListHtml(strSelectedValue) {
 var strCountryOptionsList = '<option value="">Please select...</option>\n';
 for (var i = 0; i < countries.length; i++) {
     strCountryOptionsList += '<option value="' + countries[i].code + '"'
     if (strSelectedValue == countries[i].code) {
         strCountryOptionsList += " SELECTED"
     }
     strCountryOptionsList += ">" + countries[i].name + "</option>\n";
 }
 return strCountryOptionsList;
}


//Get the country name for a given code.
function getCountryName(strCountryCode) {
 for (var i = 0; i < countries.length; i++) {
     if (strCountryCode == countries[i].code) {
         return countries[i].name;
     }
 }
 return "";
}

//ISO 3166-1 country names and codes from http://opencountrycodes.appspot.com/javascript
countries = [
 {code: "US", name: "United States"},
 {code: "GB", name: "United Kingdom"},
 {code: "AF", name: "Afghanistan"},
 {code: "AX", name: "Aland Islands"},
 {code: "AL", name: "Albania"},
 {code: "DZ", name: "Algeria"},
 {code: "AS", name: "American Samoa"},
 {code: "AD", name: "Andorra"},
 {code: "AO", name: "Angola"},
 {code: "AI", name: "Anguilla"},
 {code: "AQ", name: "Antarctica"},
 {code: "AG", name: "Antigua and Barbuda"},
 {code: "AR", name: "Argentina"},
 {code: "AM", name: "Armenia"},
 {code: "AW", name: "Aruba"},
 {code: "AU", name: "Australia"},
 {code: "AT", name: "Austria"},
 {code: "AZ", name: "Azerbaijan"},
 {code: "BS", name: "Bahamas"},
 {code: "BH", name: "Bahrain"},
 {code: "BD", name: "Bangladesh"},
 {code: "BB", name: "Barbados"},
 {code: "BY", name: "Belarus"},
 {code: "BE", name: "Belgium"},
 {code: "BZ", name: "Belize"},
 {code: "BJ", name: "Benin"},
 {code: "BM", name: "Bermuda"},
 {code: "BT", name: "Bhutan"},
 {code: "BO", name: "Bolivia"},
 {code: "BA", name: "Bosnia and Herzegovina"},
 {code: "BW", name: "Botswana"},
 {code: "BV", name: "Bouvet Island"},
 {code: "BR", name: "Brazil"},
 {code: "IO", name: "British Indian Ocean Territory"},
 {code: "BN", name: "Brunei Darussalam"},
 {code: "BG", name: "Bulgaria"},
 {code: "BF", name: "Burkina Faso"},
 {code: "BI", name: "Burundi"},
 {code: "KH", name: "Cambodia"},
 {code: "CM", name: "Cameroon"},
 {code: "CA", name: "Canada"},
 {code: "CV", name: "Cape Verde"},
 {code: "KY", name: "Cayman Islands"},
 {code: "CF", name: "Central African Republic"},
 {code: "TD", name: "Chad"},
 {code: "CL", name: "Chile"},
 {code: "CN", name: "China"},
 {code: "CX", name: "Christmas Island"},
 {code: "CC", name: "Cocos (Keeling) Islands"},
 {code: "CO", name: "Colombia"},
 {code: "KM", name: "Comoros"},
 {code: "CG", name: "Congo"},
 {code: "CD", name: "Congo, The Democratic Republic of the"},
 {code: "CK", name: "Cook Islands"},
 {code: "CR", name: "Costa Rica"},
 {code: "CI", name: "Côte d'Ivoire"},
 {code: "HR", name: "Croatia"},
 {code: "CU", name: "Cuba"},
 {code: "CY", name: "Cyprus"},
 {code: "CZ", name: "Czech Republic"},
 {code: "DK", name: "Denmark"},
 {code: "DJ", name: "Djibouti"},
 {code: "DM", name: "Dominica"},
 {code: "DO", name: "Dominican Republic"},
 {code: "EC", name: "Ecuador"},
 {code: "EG", name: "Egypt"},
 {code: "SV", name: "El Salvador"},
 {code: "GQ", name: "Equatorial Guinea"},
 {code: "ER", name: "Eritrea"},
 {code: "EE", name: "Estonia"},
 {code: "ET", name: "Ethiopia"},
 {code: "FK", name: "Falkland Islands (Malvinas)"},
 {code: "FO", name: "Faroe Islands"},
 {code: "FJ", name: "Fiji"},
 {code: "FI", name: "Finland"},
 {code: "FR", name: "France"},
 {code: "GF", name: "French Guiana"},
 {code: "PF", name: "French Polynesia"},
 {code: "TF", name: "French Southern Territories"},
 {code: "GA", name: "Gabon"},
 {code: "GM", name: "Gambia"},
 {code: "GE", name: "Georgia"},
 {code: "DE", name: "Germany"},
 {code: "GH", name: "Ghana"},
 {code: "GI", name: "Gibraltar"},
 {code: "GR", name: "Greece"},
 {code: "GL", name: "Greenland"},
 {code: "GD", name: "Grenada"},
 {code: "GP", name: "Guadeloupe"},
 {code: "GU", name: "Guam"},
 {code: "GT", name: "Guatemala"},
 {code: "GG", name: "Guernsey"},
 {code: "GN", name: "Guinea"},
 {code: "GW", name: "Guinea-Bissau"},
 {code: "GY", name: "Guyana"},
 {code: "HT", name: "Haiti"},
 {code: "HM", name: "Heard Island and McDonald Islands"},
 {code: "VA", name: "Holy See (Vatican City State)"},
 {code: "HN", name: "Honduras"},
 {code: "HK", name: "Hong Kong"},
 {code: "HU", name: "Hungary"},
 {code: "IS", name: "Iceland"},
 {code: "IN", name: "India"},
 {code: "ID", name: "Indonesia"},
 {code: "IR", name: "Iran, Islamic Republic of"},
 {code: "IQ", name: "Iraq"},
 {code: "IE", name: "Ireland"},
 {code: "IM", name: "Isle of Man"},
 {code: "IL", name: "Israel"},
 {code: "IT", name: "Italy"},
 {code: "JM", name: "Jamaica"},
 {code: "JP", name: "Japan"},
 {code: "JE", name: "Jersey"},
 {code: "JO", name: "Jordan"},
 {code: "KZ", name: "Kazakhstan"},
 {code: "KE", name: "Kenya"},
 {code: "KI", name: "Kiribati"},
 {code: "KP", name: "Korea, Democratic People's Republic of"},
 {code: "KR", name: "Korea, Republic of"},
 {code: "KW", name: "Kuwait"},
 {code: "KG", name: "Kyrgyzstan"},
 {code: "LA", name: "Lao People's Democratic Republic"},
 {code: "LV", name: "Latvia"},
 {code: "LB", name: "Lebanon"},
 {code: "LS", name: "Lesotho"},
 {code: "LR", name: "Liberia"},
 {code: "LY", name: "Libyan Arab Jamahiriya"},
 {code: "LI", name: "Liechtenstein"},
 {code: "LT", name: "Lithuania"},
 {code: "LU", name: "Luxembourg"},
 {code: "MO", name: "Macao"},
 {code: "MK", name: "Macedonia, The Former Yugoslav Republic of"},
 {code: "MG", name: "Madagascar"},
 {code: "MW", name: "Malawi"},
 {code: "MY", name: "Malaysia"},
 {code: "MV", name: "Maldives"},
 {code: "ML", name: "Mali"},
 {code: "MT", name: "Malta"},
 {code: "MH", name: "Marshall Islands"},
 {code: "MQ", name: "Martinique"},
 {code: "MR", name: "Mauritania"},
 {code: "MU", name: "Mauritius"},
 {code: "YT", name: "Mayotte"},
 {code: "MX", name: "Mexico"},
 {code: "FM", name: "Micronesia, Federated States of"},
 {code: "MD", name: "Moldova"},
 {code: "MC", name: "Monaco"},
 {code: "MN", name: "Mongolia"},
 {code: "ME", name: "Montenegro"},
 {code: "MS", name: "Montserrat"},
 {code: "MA", name: "Morocco"},
 {code: "MZ", name: "Mozambique"},
 {code: "MM", name: "Myanmar"},
 {code: "NA", name: "Namibia"},
 {code: "NR", name: "Nauru"},
 {code: "NP", name: "Nepal"},
 {code: "NL", name: "Netherlands"},
 {code: "AN", name: "Netherlands Antilles"},
 {code: "NC", name: "New Caledonia"},
 {code: "NZ", name: "New Zealand"},
 {code: "NI", name: "Nicaragua"},
 {code: "NE", name: "Niger"},
 {code: "NG", name: "Nigeria"},
 {code: "NU", name: "Niue"},
 {code: "NF", name: "Norfolk Island"},
 {code: "MP", name: "Northern Mariana Islands"},
 {code: "NO", name: "Norway"},
 {code: "OM", name: "Oman"},
 {code: "PK", name: "Pakistan"},
 {code: "PW", name: "Palau"},
 {code: "PS", name: "Palestinian Territory, Occupied"},
 {code: "PA", name: "Panama"},
 {code: "PG", name: "Papua New Guinea"},
 {code: "PY", name: "Paraguay"},
 {code: "PE", name: "Peru"},
 {code: "PH", name: "Philippines"},
 {code: "PN", name: "Pitcairn"},
 {code: "PL", name: "Poland"},
 {code: "PT", name: "Portugal"},
 {code: "PR", name: "Puerto Rico"},
 {code: "QA", name: "Qatar"},
 {code: "RE", name: "Réunion"},
 {code: "RO", name: "Romania"},
 {code: "RU", name: "Russian Federation"},
 {code: "RW", name: "Rwanda"},
 {code: "BL", name: "Saint Barthélemy"},
 {code: "SH", name: "Saint Helena"},
 {code: "KN", name: "Saint Kitts and Nevis"},
 {code: "LC", name: "Saint Lucia"},
 {code: "MF", name: "Saint Martin"},
 {code: "PM", name: "Saint Pierre and Miquelon"},
 {code: "VC", name: "Saint Vincent and the Grenadines"},
 {code: "WS", name: "Samoa"},
 {code: "SM", name: "San Marino"},
 {code: "ST", name: "Sao Tome and Principe"},
 {code: "SA", name: "Saudi Arabia"},
 {code: "SN", name: "Senegal"},
 {code: "RS", name: "Serbia"},
 {code: "SC", name: "Seychelles"},
 {code: "SL", name: "Sierra Leone"},
 {code: "SG", name: "Singapore"},
 {code: "SK", name: "Slovakia"},
 {code: "SI", name: "Slovenia"},
 {code: "SB", name: "Solomon Islands"},
 {code: "SO", name: "Somalia"},
 {code: "ZA", name: "South Africa"},
 {code: "GS", name: "South Georgia and the South Sandwich Islands"},
 {code: "ES", name: "Spain"},
 {code: "LK", name: "Sri Lanka"},
 {code: "SD", name: "Sudan"},
 {code: "SR", name: "Suriname"},
 {code: "SJ", name: "Svalbard and Jan Mayen"},
 {code: "SZ", name: "Swaziland"},
 {code: "SE", name: "Sweden"},
 {code: "CH", name: "Switzerland"},
 {code: "SY", name: "Syrian Arab Republic"},
 {code: "TW", name: "Taiwan, Province of China"},
 {code: "TJ", name: "Tajikistan"},
 {code: "TZ", name: "Tanzania, United Republic of"},
 {code: "TH", name: "Thailand"},
 {code: "TL", name: "Timor-Leste"},
 {code: "TG", name: "Togo"},
 {code: "TK", name: "Tokelau"},
 {code: "TO", name: "Tonga"},
 {code: "TT", name: "Trinidad and Tobago"},
 {code: "TN", name: "Tunisia"},
 {code: "TR", name: "Turkey"},
 {code: "TM", name: "Turkmenistan"},
 {code: "TC", name: "Turks and Caicos Islands"},
 {code: "TV", name: "Tuvalu"},
 {code: "UG", name: "Uganda"},
 {code: "UA", name: "Ukraine"},
 {code: "AE", name: "United Arab Emirates"},
 {code: "GB", name: "United Kingdom"},
 {code: "US", name: "United States"},
 {code: "UM", name: "United States Minor Outlying Islands"},
 {code: "UY", name: "Uruguay"},
 {code: "UZ", name: "Uzbekistan"},
 {code: "VU", name: "Vanuatu"},
 {code: "VE", name: "Venezuela"},
 {code: "VN", name: "Viet Nam"},
 {code: "VG", name: "Virgin Islands, British"},
 {code: "VI", name: "Virgin Islands, U.S."},
 {code: "WF", name: "Wallis and Futuna"},
 {code: "EH", name: "Western Sahara"},
 {code: "YE", name: "Yemen"},
 {code: "ZM", name: "Zambia"},
 {code: "ZW", name: "Zimbabwe"}
];

var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

/**
 * Countdown timer for today to some time in the future
 */
function countdown(){
	// YYYY,MM,DD,HH,MnMn,SS - months is from 0, so needs to be one less than you think
	dateFuture = new Date(2010,4,15,9,0,0);
	dateNow = new Date();
	amount = dateFuture.getTime() - dateNow.getTime();
	delete dateNow;

	// launch time
	if(amount < 0){
		document.getElementById("cd1").innerHTML="L";
		document.getElementById("cd2").innerHTML="A";
		document.getElementById("cd3").innerHTML="U";
		document.getElementById("cd4").innerHTML="N";
		document.getElementById("cd5").innerHTML="C";
		document.getElementById("cd6").innerHTML="H";
	}
	else{
		var days=0;hours=0;mins=0;sec=0;outDays="";outHours="";outMins="",outSecs="";

		amount = Math.floor(amount/1000);

		days=Math.floor(amount/86400);	// days
		amount=amount%86400;

		hours=Math.floor(amount/3600);	// hours
		amount=amount%3600;

		mins=Math.floor(amount/60);		// minutes
		amount=amount%60;

		secs=Math.floor(amount);		// seconds
		amount=amount;

		outDays = pad(String(days),2,"0",STR_PAD_LEFT);
		outHours = pad(String(hours),2,"0",STR_PAD_LEFT);
		outMins = pad(String(mins),2,"0",STR_PAD_LEFT);
		outSecs = pad(String(secs),2,"0",STR_PAD_LEFT)+" Seconds";

		document.getElementById("cd1").innerHTML=outDays.substr(0,1);
		document.getElementById("cd2").innerHTML=outDays.substr(1,1);
		document.getElementById("cd3").innerHTML=outHours.substr(0,1);
		document.getElementById("cd4").innerHTML=outHours.substr(1,1);
		document.getElementById("cd5").innerHTML=outMins.substr(0,1);
		document.getElementById("cd6").innerHTML=outMins.substr(1,1);
		document.getElementById("countdown").title=outSecs;

		setTimeout("countdown()", 1000);
	}
}

/**
 * A javascript version of PHPs str_pad - used with countdown()
 */
function pad(str, len, pad, dir) {

	if (typeof(len) == "undefined") {
		var len = 0;
	}
	if (typeof(pad) == "undefined") {
		var pad = ' ';
	}
	if (typeof(dir) == "undefined") {
		var dir = STR_PAD_RIGHT;
	}

	if (len + 1 >= str.length) {

		switch (dir){

			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
				break;

			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
				break;

			default:
				str = str + Array(len + 1 - str.length).join(pad);
				break;

		}
	}

	return str;
}

/*
 * Check if an element has a classname
 *
 * object objElement
 * string strClass
 * return boolean
 */
function HasClassName(objElement, strClass) {
	// if there is a class
	if (objElement.className) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		// find all instances and remove them
		for (var i = 0; i < arrList.length; i++) {
			// if class found
			if (arrList[i].toUpperCase() == strClassUpper) {
				// we found it
				return true;
			}
		}
	}
	// if we got here then the class name is not there
	return false;
}


/*
 * Add a classname to an element
 *
 * object objElement
 * string strClass
 * boolean blnMayAlreadyExist
 */
function AddClassName(objElement, strClass, blnMayAlreadyExist) {
	// if there is a class
	if (objElement.className) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// if the new class name may already exist in list
		if (blnMayAlreadyExist) {
			// get uppercase class for comparison purposes
			var strClassUpper = strClass.toUpperCase();
			// find all instances and remove them
			for (var i = 0; i < arrList.length; i++) {
				// if class found
				if (arrList[i].toUpperCase() == strClassUpper) {
					// remove array item
					arrList.splice(i, 1);
					// decrement loop counter as we have adjusted the array's contents
					i--;
				}
			}
		}
		// add the new class to end of list
		arrList[arrList.length] = strClass;
		// add the new class to beginning of list
		//arrList.splice(0, 0, strClass);
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	}
	// if there was no class
	else {
		// assign modified class name attribute
		objElement.className = strClass;
	}
}


/*
 * Remove a classname from an element
 *
 * object objElement
 * string strClass
 */
function RemoveClassName(objElement, strClass) {
	// if there is a class
	if (objElement.className) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		// find all instances and remove them
		for (var i = 0; i < arrList.length; i++) {
			// if class found
			if (arrList[i].toUpperCase() == strClassUpper) {
				// remove array item
				arrList.splice(i, 1);
				// decrement loop counter as we have adjusted the array's contents
				i--;
			}
		}
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	}
	// if there was no class
	// there is nothing to remove
}

function showLocation(lat,lng) {
	window.open('http://maps.google.co.uk/maps?q='+lat+','+lng);
}

function toggleCheckboxes(all) {
	var inputs = document.getElementsByTagName("input");
	if (document.getElementById(all).checked) {
		for (var i=0; i<inputs.length;i++) {
			if (inputs[i].id!=all && inputs[i].type=='checkbox') {
				inputs[i].checked = true;
			}
		}
	}
	else {
		for (var i=0; i<inputs.length;i++) {
			if (inputs[i].id!=all && inputs[i].type=='checkbox') {
				inputs[i].checked = false;
			}
		}
	}
}

function createRequest() {
    var ajaxRequest;
    try {
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e1) {
        try {
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e2) {
            ajaxRequest = new XMLHttpRequest();
        }
    }
    return ajaxRequest;
}

function textCounter(el,id,max) {
	if (el.value.length > max) {
		el.value = el.value.substring(0, max);
	}
	else {
		var val = max - el.value.length;
		document.getElementById(id).innerHTML = val + " Character"+(val!=1?"s":"")+" Remaining";
	}
}

var questionLimit='';

function checkLength(ob,r,t) {
	// also remove any error messages that may be present
	if(document.getElementById('errorMesg'))
		document.getElementById('errorMesg').innerHTML='';

    var total = ob.value.getWordCount();
    var x, len = arguments.length;
    for (x=1; x<len; ++x) {
        if (arguments[x].words) {
        	total += arguments[x].words;
        }
    }

    var val = ob.value==''?t:t - total;
    val=val<0?0:val;
    document.getElementById(r).innerHTML = val + " Word"+(val!=1?"s":"")+" Remaining";

    if (total==t) {
    	questionLimit=ob.value;
    }

    if (total > t) {
    	ob.value=questionLimit;
        alert("Your question has exceeded the maximum number of words allowed.\n Please try and shorten your question to under "+t+" words.");
        return false;
    }
    return true;
}

String.prototype.getWordCount = function() {
    return this.replace(/\s+/g, " ").replace(/^\s*/, "").replace(/\s*$/, "").split(" ").length;
}

function captureEnter(myfield,e) {
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
	}
	else if (e) {
		keycode = e.which;
	}
	else {
		return true;
	}

	if (keycode == 13) {
		changeFasAction(); // need to ensure that this is the name of the function within the specific site js file
	    document.fas.submit(); // need to ensure that the form is called fas
	   	return false;
   	}
	else {
	   return true;
	}
}

function getDateSuffix(n) {
	if (n!=11&&n!=12&&n!=13){
		switch (n % 10) {
			case 1:  return n+'st';
			case 2:  return n+'nd';
			case 3:  return n+'rd';
		}
	}
	return n+'th';
}

function displayLogo(img,id) {
	var el = document.getElementById(id);
	el.innerHTML = '<img src="' + logoPath+img + '">';
}

// jquery confirm replacement
/*
 * SimpleModal Confirm Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: confirm.js 254 2010-07-23 05:14:44Z emartin24 $
 */

function displayCurrentDateTime() {
	document.getElementById("datedate").innerHTML = getCurrentDateTime("date");
	document.getElementById("timetime").innerHTML = getCurrentDateTime("time");
	t=setTimeout('displayCurrentDateTime()',500);
}

function getCurrentDateTime(type) {
	var dateNow = new Date();
	if (type=="date") {
		var dayNames = new Array(7)
		dayNames[0] = "Sunday"
		dayNames[1] = "Monday"
		dayNames[2] = "Tuesday"
		dayNames[3] = "Wednesday"
		dayNames[4] = "Thursday"
		dayNames[5] = "Friday"
		dayNames[6] = "Saturday"

		var monthNames = new Array(12)
		monthNames[0] = "January"
		monthNames[1] = "February"
		monthNames[2] = "March"
		monthNames[3] = "April"
		monthNames[4] = "May"
		monthNames[5] = "June"
		monthNames[6] = "July"
		monthNames[7] = "August"
		monthNames[8] = "September"
		monthNames[9] = "October"
		monthNames[10] = "November"
		monthNames[11] = "December"

		var day = dateNow.getDay();

		return dayNames[day]+" "+getDateSuffix(dateNow.getDate())+" "+monthNames[dateNow.getMonth()];
	}
	else {
		return dateNow.getHours()+":"+(dateNow.getMinutes()<10?"0"+dateNow.getMinutes():dateNow.getMinutes())+(dateNow.getHours()<12?" am":" pm");
	}
}

function inputNumbersOnly(e, decimal) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	}
	else if (e) {
	   	key = e.which;
	}
	else {
	   	return true;
	}
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	   	return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)) {
	   	return true;
	}
	else if (decimal && (keychar == ".")) {
	  	return true;
	}
	else {
		return false;
	}
}

function showLocation(lat,lng) {
	window.open('http://maps.google.co.uk/maps?q='+lat+','+lng);
}

function urlEncode(s) {
	return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}

$(document).ready(function() {
	$.ajaxSetup({cache:false});

	$('tr.hover_bg').hover(function() {
		$(this).addClass('hover');
		$(this).find('.hover_hidden').fadeIn('fast');
		var classes = $(this).attr('class').split(' ');
		for(var i=0;i<classes.length;i++)
			if(classes[i].substr(0, 11)=='hover_with_')
				$('tr.'+classes[i]).addClass('hover');
	}, function() {
		var classes = $(this).attr('class').split(' ');
		for(var i=0;i<classes.length;i++)
			if(classes[i].substr(0, 11)=='hover_with_')
				$('tr.'+classes[i]).removeClass('hover');
		$(this).removeClass('hover');
		$(this).find('.hover_hidden').fadeOut('fast');
	});
});
