//functions used by registration section
function focusColor (myElement) {myElement.style.backgroundColor='#ccdded';}
function blurColor (myElement) 	{myElement.style.backgroundColor='';}

function showId (myId) 		{document.getElementById(myId).style.display='block';}
function hideId (myId) 		{document.getElementById(myId).style.display='none';}


function toggle_visibility(show,hide1,hide2) {
	var a = document.getElementById(show);
	var b = document.getElementById(hide1);
	
	// if hide2 is passed then hide it...
	if(hide2.length > 0)
	{
		var c = document.getElementById(hide2);
	}	

	if(a.style.display == 'none')	{
		a.style.display = 'block';
		b.style.display = 'none';
		
		// if hide2 is passed
		if(hide2.length > 0)
		{
			c.style.display = 'none';
		}
	}
	else	{
		a.style.display = 'none';
		b.style.display = 'block';
		
		// if hide2 is passed
		if(hide2.length > 0)
		{
			c.style.display = 'block';
		}
	}
}

// show div passed
function showDiv(show) {
	var a = document.getElementById(show);

	a.style.display = 'block';
}

// hide div passed
function hideDiv(hide) {
	var a = document.getElementById(hide);

	a.style.display = 'none';	
}

function showhideDiv(showhide) {
	var a = document.getElementById(showhide);

	if(a.style.display == 'none')	{
		a.style.display = 'block';
	}
	else	{
		a.style.display = 'none';		
	}
}

// reset start date for american express
function selectCC(payment) {				
	var opt = document.getElementById('cctype').value;

	if (opt == 'AMEX') {		
		// change inline text next to security number field
		document.getElementById('secNumber').innerHTML = '<p class="twolines">Please enter your <br />4 digit security code.</p>';		
		}
	else {
		// change inline text next to security number field
		document.getElementById('secNumber').innerHTML = '<p class="twolines">Please enter your <br />3 digit security code.</p>';
	}
}

// this will populate fields from other fields
function passValues(field1,field2,fieldToPopulate1,fieldToPopulate2) {
	var a = document.getElementById(field1).value;
	var b = document.getElementById(field2).value;
	var c = document.getElementById(fieldToPopulate1);
	var d = document.getElementById(fieldToPopulate2);
	
	c.value = a;
	d.value = b;	
}	

// this will uncover the password forget form and populate the emailPassword field thats been uncovered with anything thats been typed in the email field
function forgot_password(divToUncover,fieldValueToPass,fieldToPopulate) {
	var a = document.getElementById(divToUncover);
	var b = document.getElementById(fieldValueToPass).value;
	var c = document.getElementById(fieldToPopulate);
	
	// make sure the emailPassword field is populated with the value from the email field
	c.value = b;
	
	//this will hide/unhide the password forget form
	if (a.style.display == 'none') {
		a.style.display = 'block';				
		document.getElementById('forgotPass').style.color='#777';
	}
	else {
		a.style.display = 'none';
		document.getElementById('forgotPass').style.color='blue';
	}
}			

function newUser(divToUncover,divToCover,linkColor) {
	var a = document.getElementById(divToUncover);
	var b = document.getElementById(fieldValueToPass).value;
	var c = document.getElementById(fieldToPopulate);
	
	// make sure the emailPassword field is populated with the value from the email field
	c.value = b;
	
	//this will hide/unhide the password forget form
	if (a.style.display == 'none') {
		a.style.display = 'block';				
		document.getElementById('newUser').style.color='#777';
	}
	else {
		a.style.display = 'none';
		a.style.display = 'none';
		document.getElementById('newUser').style.color='blue';
	}
}		
				
// stop submit button from being submitted twice
function DisableButton(b) {
	b.disabled = true;
	b.value = 'Submitting';
	b.form.submit();
}


// Code for the _international.cfm page
//////////////////////////////////////////////////////////
// the year affects the last sunday of each month
var int_now_date = new Date();
var int_last_sunday_march = new Date(int_now_date.getFullYear(), 3, 1, 1, 0, 0);
var int_last_sunday_october = new Date(int_now_date.getFullYear(), 10, 1, 2, 0, 0);
var int_output_text;
var int_diff_date;
var int_one_day=1000*60*60*24;

//find last Sunday in March
do {
	int_last_sunday_march.setTime(int_last_sunday_march.getTime() - int_one_day);
} while (int_last_sunday_march.getDay() != 0); // while not Sunday
int_last_sunday_march.setMinutes(int_last_sunday_march.getMinutes() - int_last_sunday_march.getTimezoneOffset());
//find last Sunday in October
do {
	int_last_sunday_october.setTime(int_last_sunday_october.getTime() - int_one_day);
} while (int_last_sunday_october.getDay() != 0); // while not Sunday
int_last_sunday_october.setMinutes(int_last_sunday_october.getMinutes() - int_last_sunday_october.getTimezoneOffset());

// END Constants, Variables and Initialisation.

//British Summer Time check
function isBST(nowTime)
{
	return ((nowTime.getTime() > int_last_sunday_march.getTime()) && (nowTime.getTime() < int_last_sunday_october.getTime()));
}

// The display update
function updateTimeString()
{
	int_now_date = new Date();
	int_now_date.setMinutes(int_now_date.getMinutes() - int_now_date.getTimezoneOffset());
	
	//if is British Summer Time, take off 1 hour
	if (isBST(int_now_date)) {
		int_now_date.setHours(int_now_date.getHours() - 1);
	}
	
	if (int_now_date.getTime() <= int_192_open_today.getTime()) {
		int_diff_date = new Date(int_192_open_today.getTime() - int_now_date.getTime());
		int_output_text = "<strong>192.com is closed</strong>, we will open in approximately " + int_diff_date.getHours() + " hour" + (int_diff_date.getHours() == 1 ? "" : "s") + (int_diff_date.getMinutes() == 0 ? "" : ", " + int_diff_date.getMinutes() + " minute" + (int_diff_date.getMinutes() == 1 ? "" : "s")) + (int_diff_date.getSeconds() == 0 ? "" : " and " + int_diff_date.getSeconds() + " second" + (int_diff_date.getSeconds() == 1 ? "" : "s")) + ".";
	} else if ((int_now_date.getTime() > int_192_open_today.getTime()) && (int_now_date.getTime() < int_192_close_today.getTime())) {
		int_diff_date = new Date(int_192_close_today.getTime() - int_now_date.getTime());
		int_output_text = "<strong>192.com is open</strong>, we will be closing in approximately " + int_diff_date.getHours() + " hour" + (int_diff_date.getHours() == 1 ? "" : "s") + (int_diff_date.getMinutes() == 0 ? "" : ", " + int_diff_date.getMinutes() + " minute" + (int_diff_date.getMinutes() == 1 ? "" : "s")) + (int_diff_date.getSeconds() == 0 ? "" : " and " + int_diff_date.getSeconds() + " second" + (int_diff_date.getSeconds() == 1 ? "" : "s")) + ".";
	} else if (int_now_date.getTime() >= int_192_close_today.getTime()) {
		int_diff_date = new Date(int_192_open_tomorrow.getTime() - int_now_date.getTime());
		int_output_text = "<strong>192.com is closed</strong> for the day, we will open tomorrow in approximately " + int_diff_date.getHours() + " hour" + (int_diff_date.getHours() == 1 ? "" : "s") + (int_diff_date.getMinutes() == 0 ? "" : ", " + int_diff_date.getMinutes() + " minute" + (int_diff_date.getMinutes() == 1 ? "" : "s")) + (int_diff_date.getSeconds() == 0 ? "" : " and " + int_diff_date.getSeconds() + " second" + (int_diff_date.getSeconds() == 1 ? "" : "s")) + ".";
	} else {
		int_output_text = "&nbsp;";
	}

	document.getElementById('span_time_till_open').innerHTML = int_output_text;
}

//Cross browser add event to arbitrary element
function XBrowserAddEvent(element,eventName,functionName) { 
	if (element.addEventListener) { 
		element.addEventListener(eventName, functionName, false);
	} else if (element.attachEvent) { 
		element.attachEvent("on" + eventName, functionName);
	} else { 
		element["on" + eventName] = functionName; 
	} 
}

//Set updateTimeString() to be called every second
function startTimeUpdate() {
	window.setInterval("updateTimeString();", 1000);
}

//Remy Becher & Jason Wright 20/11/2007 orderConfirm logic
function orderConfirm() {
	var timeoutID = window.setTimeout('orderConfirmCallBack()', 100);
}

function orderConfirmCallBack() {
	document.payment.submit();
}

