// (c) 1999-2005 Bright Interactive Limited. All rights reserved.
// http://www.bright-interactive.com | info@bright-interactive.com
// Tel: 0870 240 6520

// Last modified: $Date: 2006/11/22 15:20:15 $
// Release $Name:  $
// Revision $Revision: 1.3 $

// History:
// Revision 1.14  2006/07/28 10:20:55  james
// Fixed hide/show region select to only get triggered on homepage
//
// Revision 1.13  2006/06/06 10:20:55  james
// Fixed region select showing over about us menu
// 
// $Log: nav.js,v $
// Revision 1.3  2006/11/22 15:20:15  jamesd
// changes
//
// Revision 1.2  2006/11/16 17:16:35  jamesd
// changes
//
// Revision 1.1.1.1  2006/10/27 15:53:05  jamesd
// initial import
//
// Revision 1.1.1.1  2006/10/12 16:27:04  jamesd
// initial import
//
// Revision 1.12  2005/07/20 14:31:44  eric
// Fixed highlighting for indented subnavs
//
// Revision 1.11  2005/07/11 15:34:18  tamora
// Changes
//
// Revision 1.10  2005/05/16 14:39:54  eric
// Changes for release 8 & 9
//
// Revision 1.9  2005/05/03 11:14:39  eric
// Don't clear app form fields when checkbox unticked
//
// 


function popupmenu(menuid) {
	div = document.getElementById( 'div_' + menuid );
	m = document.getElementById( 'menu_' + menuid );
	if (div.style.visibility != 'visible' ) {
		div.style.visibility = 'visible';
		if (m && m.className != "sel") {
			m.className = "sel";
		}
	}
	
	var mItem = m.firstChild.nodeValue;
	if (document.getElementById('regionSelect')){;
		if (mItem == "About Us"){
			hideRegionSelect();
		}
	}
}



function hidemenu(menuid) {
	div = document.getElementById( 'div_' + menuid );
	m = document.getElementById( 'menu_' + menuid );
	if (div.style.visibility != 'hidden' ) {
		div.style.visibility = 'hidden';
		if (m) {
			m.className = null;
		}
	}
	
	var mItem = m.firstChild.nodeValue;
	if (document.getElementById('regionSelect')){;
		if (mItem == "About Us"){
			showRegionSelect();
		}
	}
	
}


function highlight(linkid) {
	// Highlight the linkset link for this page
	li = document.getElementById( 'link_' + linkid );

	// Check that li exists
	if (li) {
		li.className = 'current';
	}
}



function highlight_subnav() {
	// Highlight the right subnav item by comparing the URL with
	// the href of each <a> elt in the <div id="subnav">, or by
	// using the hint if supplied as arguments[0]. The hint
	// specifies a part of the URL, useful for actions with
	// lots of paramters
	
	var this_page = document.location.href;
	
	// Remove anchor if there is one -- anything following #, including #
	this_page = this_page.replace( /\#.*/, '' );
	
	var hint = "";
	if (arguments[0]) {
		hint = arguments[0];
	}
	
	
	// Try both subnav and subnavIndent for our item to highlight
	
	var divs = [ "subnav", "subnavIndent" ];
	for (var d = 0; d < divs.length; d++) {
	
		if (document.getElementById(divs[d])) {
			var subnav_elts = document.getElementById(divs[d]);
			var aTags = subnav_elts.getElementsByTagName("A");
			
		 
			
			var i = 0;
			for (i = 0; i < aTags.length; i++) {
				// Is this a link?
				var elt = aTags[i]
 					if (elt.parentNode.nodeName != "H2" && elt.href == this_page || (hint && elt.href.indexOf(hint) != -1) ) {
						elt.className = elt.className + " current";
						var par = elt.parentNode.parentNode.parentNode;
						if (par.nodeName == "LI"){
							par.className = "currentsub";
							par.firstChild.className += " section";
							document.getElementById("subnav").getElementsByTagName("H2")[0].className = "reset";
						}else{
							elt.parentNode.className = elt.parentNode.className + " currentsub";
 						}
						
						
					}
 			}
		}
	}
		

}


function list_value(l) {
	return l.options[l.selectedIndex].value;
}


function clear_hint(field) {
	// Remove the [search] or other hint from the input field
	// but check that the user hasn't typed something in (which
	// we wouldn't want to clear)
	
	if (field.value.match(/\[.*\]/)) {
		// string of the form [hint] is present so clear it
		field.value = "";
	}

}


function set_next_prev_page() {
	// Set next and previous links, based on page variables
	// next_url & prev_url, which should be defined before calling
	// this method.
	
	var next_link = document.getElementById("nextPageBaseLink");
	if (next_link) {
		next_link.href = next_url;	
	}
	
	next_link = document.getElementById("nextPageHeadLink");
	if (next_link) {
		next_link.href = next_url;	
	}
	
	var prev_link = document.getElementById("prevPageBaseLink");
	if (prev_link) {
		prev_link.href = prev_url;
	}

	prev_link = document.getElementById("prevPageHeadLink");
	if (prev_link) {
		prev_link.href = prev_url;
	}

}


function popup_help(id) {
	switch (id) {
		case 'nextday_intl':
			window.open( '/ijb/help_intl/','popupHelp','width=720,height=474,left=20,top=20,scrollbars=yes' );
			return false;
		break
		default:
			window.open( '/ijb/help/','popupHelp','width=720,height=564,left=20,top=20,scrollbars=yes' );
			return false;
		break
	}
}


function popup(id) {
	switch (id) {
		case 'tandcs':
			window.open( '/popup/tandcs.html','popup','width=720,height=475,left=20,top=20,scrollbars=yes' );
			return false;
		break
		case 'dataprotection':
			window.open( '/popup/dataprotection.html','popup','width=720,height=475,left=20,top=20,scrollbars=yes' );
			return false;
		break
		default:
			return;
		break
	}
}


function switch_apply_button () {
	// Check that the user has checked the right tick boxes
	// if they have, enable the button, otherwise disable it
	
	var agree = document.getElementById( 'agreeCheckbox' ).checked;

	var applyButton = document.getElementById( 'applyButton' );

	if (agree) {
		applyButton.disabled = false;
	}
	else {
		applyButton.disabled = true;
	}
}

function switch_requirements () {
	
	var nextday = document.getElementById( 'nextdayCheckbox' ).checked;
	var intl = document.getElementById( 'intlCheckbox' ).checked;
	
	if (nextday || intl) {
		set_required( ['intl_nextday_email'] );
		document.getElementById('intl_nextday_email_req').style.display = 'inline';
		
		if (intl) {
			set_required( ['intl_nextday_vat_no'] );
			document.getElementById('intl_nextday_vat_req').style.display = 'inline';
		}
		else {
			unset_required( ['intl_nextday_vat_no'] );
			document.getElementById('intl_nextday_vat_req').style.display = 'none';
		}
	}
	else {
		unset_required( ['intl_nextday_email','intl_nextday_vat_no'] );
		document.getElementById('intl_nextday_email_req').style.display = 'none';
		document.getElementById('intl_nextday_vat_req').style.display = 'none';
	}
}

function use_details (section) {
	
	var checked = document.getElementById( section +'_checkbox').checked;
	
	switch (section) {
	
		case 'invoice':
		case 'pickup':
			
			var address1 = '', address2 = '', town = '', postcode = '', tel = '', fax = ''; 
			
			if (checked) {
				address1 = document.getElementById('trading_address1').value;
				address2 = document.getElementById('trading_address2').value;
				town = document.getElementById('trading_town').value;
				postcode = document.getElementById('trading_postcode').value;
				tel = document.getElementById('trading_tel').value;
				fax = document.getElementById('trading_fax').value;		
			}
			
			// Now set form fields. If checkbox not checked this will
			// cause fields to be blanked
			document.getElementById( section + '_address1').value = address1;
			document.getElementById( section + '_address2').value = address2;
			document.getElementById( section + '_town').value = town;
			document.getElementById( section + '_postcode').value = postcode;
			
			if (document.getElementById( section + '_tel')) {
				document.getElementById( section + '_tel').value = tel;
				document.getElementById( section + '_fax').value = fax;
			}
			

		break;
		
		case 'payments_contact':
			
			var	name = '', email = '', tel = '', fax = '';
			
			if (checked) {
				name = document.getElementById('contact_name').value;
				email = document.getElementById('contact_email').value;
				tel = document.getElementById('contact_tel').value;
				fax = document.getElementById('contact_fax').value;
			}

			// Now set form fields. If checkbox not checked this will
			// cause fields to be blanked
			document.getElementById( section + '_name').value = name;
			document.getElementById( section + '_email').value = email;
			document.getElementById( section + '_tel').value = tel;
			document.getElementById( section + '_fax').value = fax;
			
			
		break;
		
		default:
		break;	
	}
}