//development server names
var domain_names = new Array();
var site_root = "";
var development_server = "localhost";
var live_server = "www.vauxhall.co.uk";
var labels = Array();
//browser sniffing
var ie5;
var ie6;
var ie7;
var firefox_pc;
var firefox_mac;
var safari_mac;

//run browser check
//offsetTop values need to work differently dependant on what browser is being run (recursive and non-recursive)
browser_check();

//global variables
var site_backgrounds = 6;
var debug = (document.location.toString().indexOf("debug=true") != -1) ? true : false;
var cookie_check = ((document.domain == development_server) && (ie6 || ie5)) ? true : true;
var valid_multimap_destination_postcode;
var load_from_cookie = ((document.domain == development_server) && (ie6 || ie5)) ? false : true;
var login_alert = "Please ensure you enter your valid registration plate before logging in";

// variables for fading popups
var fade_increment = 10;
var fade_objects = new Object();
fade_objects.contact_us_popup = ({"opacity":100,"el_id":'contact_us_popup', "intervalObj":null});

var form_mandatory_contact_us = "txt_first_name_contact|txt_last_name_contact|txt_my_email_address_contact|txt_my_question_contact";

//determine whether to show the dhtml town lookup dropdowns (Multimap functionality)
//this can be used to provide a workaround for the lack of Multimap support for similar named towns/cities around the UK
var show_town_lookup = true;

//global form fields submitted (Multimap functionality)
var location_to;

//if this is set to true, it will lock the selected navigation item, so it always remains selected
//if false, it's selected state will be removed when mousing over another primary navigation element
var lock_selected_primary_navigation = true;

//preload in the background images
var image_url = new Array();

domain_names.push(new Array("origin-vauxhall-itl.e-gm.torsdc.ca","http://origin-vauxhall-itl.e-gm.torsdc.ca/vx/drivers_centre/"));
domain_names.push(new Array("origin.vauxhall.pprod.e-gm.net","http://origin.vauxhall.pprod.e-gm.net/vx/drivers_centre/"));
//domain_names.push(new Array("origin.vauxhall.prod.e-gm.net","http://origin.vauxhall.prod.e-gm.net/vx/drivers_centre/"));
//domain_names.push(new Array("www.vauxhall.co.uk","http://www.vauxhall.co.uk/vx/drivers_centre/"));
domain_names.push(new Array("vauxhall.co.uk","http://vauxhall.co.uk/vx/drivers_centre/"));
domain_names.push(new Array("www.vauxhalldriverscentre.co.uk","http://www.vauxhalldriverscentre.co.uk/"));
domain_names.push(new Array("vauxhalldriverscentre.co.uk","http://vauxhalldriverscentre.co.uk/"));
domain_names.push(new Array("vauxhall.modemmedia.com","http://vauxhall.modemmedia.com/vx/drivers_centre/"));
domain_names.push(new Array("enovauxhall50.modemmedia.com","http://enovauxhall50.modemmedia.com/vx/drivers_centre/"));
domain_names.push(new Array("www.newastravxr.co.uk","http://www.newastravxr.co.uk/vx/drivers_centre/"));
domain_names.push(new Array("staging.uk.opel-microsites.com","http://staging.uk.opel-microsites.com/drivers_centre/"));
domain_names.push(new Array("uat.uk.opel-microsites.com","http://uat.uk.opel-microsites.com/drivers_centre/"));
domain_names.push(new Array("www.newastravxr.co.uk","http://www.newastravxr.co.uk/vx/drivers_centre/"));
domain_names.push(new Array("www.vauxhall.co.uk","http://www.vauxhall.co.uk/microsite/drivers_centre/"));
domain_names.push(new Array("vauxhall.co.uk","http://vauxhall.co.uk/microsite/drivers_centre/"));

//work out the root of the server being used
for(var i=0; i<=domain_names.length-1; i++){
	if(document.domain == domain_names[i][0]){
		site_root = domain_names[i][1];
		break;
	}
}

var primary_navigation = new Array("on_the_road","vauxhall_interactive","fun_and_games","offers","v_xtra","vauxhall_events");

//login referrer redirect details
var login_referrer_redirect = site_root;

//on the road prefix
var on_the_road_prefix = "";
var on_the_road_prefix_development = domain_names[0][1];

//login referrer redirect details
var login_redirect_development = site_root;
//var login_redirect_live = "https://vauxhall.co.uk/vx/owners/myvauxhallhome.do?method=getMyvauxhallPage";
var login_redirect_live = "/vaux/auth/loadSignin.do?method=loadSignin";
var login_referrer_redirect = site_root;

var error_textbox_prefix = "Value required";
var error_checkbox_prefix = "Agreement required";
var error_select_prefix = "Value required";
var error_invalid_email_prefix = "Invalid email address supplied";

//Multi-M/IT form actions - always run in "live" mode for any server except the specified development box
var forms_live = (document.domain != development_server) ? true : false;
var live_form_url = "http://vauxhallemail.co.uk/servlet/campaignrespondent";
var live_email_form_url = "http://vauxhall-trackday.mrmpweb.co.uk/vauxhall.post/";
//var ask_your_question_form_submit = (document.domain == live_server) ? live_form_url : "confirmation_faq.html";
//var post_a_comment_form_submit = (document.domain == live_server) ? live_form_url : "confirmation_blogs.html";
//var competition_form_submit = (document.domain == live_server) ? live_form_url : "confirmation_competition.html";

var ask_your_question_form_submit = live_form_url;
var post_a_comment_form_submit = live_form_url;
var competition_form_submit = live_form_url;
var contact_us_form_submit = live_form_url;
var share_story_form_submit = live_form_url;

// Check for login
function isLoggedIn(){
	// Uncomment to bypass cookie login test. EG when testing in Muliple IEs 6 which has a cookie bug.
	 //return true;

	var noCookiesMessage = "Driver's Centre requires cookies to function.\n It appears your browser does not support cookies\n or you have cookies turned off.";
	browserSupportsCookies(noCookiesMessage);
	//if(get_cookie("vauxhall_owner") != "true"){
	if(get_cookie("vauxhall_registered") != "true"){
		return false;
	} else {
		return true;
	}
	
}

//preload background and primary navigation images
function pnav_switch(style){
	get_element("pnav_on_the_road").src = "images/global/primary_navigation/style" + style + "/on_the_road_off.jpg";
	get_element("pnav_vauxhall_interactive").src = "images/global/primary_navigation/style" + style + "/vauxhall_interactive_off.jpg";
	get_element("pnav_prize_draws").src = "images/global/primary_navigation/style" + style + "/prize_draw_off.jpg";
	get_element("pnav_offers").src = "images/global/primary_navigation/style" + style + "/offers_off.jpg";
	get_element("pnav_v_xtra").src = "images/global/primary_navigation/style" + style + "/v_xtra_off.jpg";
	get_element("pnav_astra_interactive").src = "images/global/primary_navigation/style" + style + "/astra_interactive_off.jpg";
}

//highlight a primary navigation element
function highlight_pnav(obj,mode){
	var img_to_change = "";

	for(var i=0; i<=primary_navigation.length-1; i++){
		if(!lock_selected_primary_navigation){
			if(obj.id != "pnav_" + primary_navigation[i]){
				//all these images need to be switched to their off state
				if(get_element("pnav_" + primary_navigation[i]).src.indexOf("on.jpg") != -1){
					img_to_change = get_element("pnav_" + primary_navigation[i]);
					img_to_change.src = img_to_change.src.replace("on.jpg","off.jpg");			
				}			
			}
			else{
				switch(mode){
					case "over":
						obj.src = obj.src.replace("off.jpg","on.jpg");
						break;
					case "out":
						obj.src = obj.src.replace("on.jpg","off.jpg");
						break;
				}
			}
		}
		else{
			switch(mode){
				case "over":
					obj.src = obj.src.replace("off.jpg","on.jpg");
					break;
				case "out":
					obj.src = obj.src.replace("on.jpg","off.jpg");
					break;
			}
		}
	}
}

//disable the onmouseout event for the selected primary navigation element
function lockout_navigation_item(element){
	element.onmouseout = function(){
		return;
	}
}

//return element as an object
function get_element(id){
	return document.getElementById(id);
}

//switch background (and css) to accomodate user change
function assign_style(style_id){
	//update cookie
	set_cookie("style",style_id);

	//update thumbnail picture
	get_element("skin_active").src = "images/site_backgrounds/background_skin" + get_cookie("style") + "_thumb_large.jpg";
	
	//dynamically read in the user-specified css file
	load_css(style_id);
}

//dynamically read in the user-specified css file
function load_css(style){
	var style_id = parseInt(style);
	
	//if not checking for cookies, load in default state
	//if found cookie style id is not numeric (for whatever reason), load in the default style
	if((!cookie_check) || (!is_numeric(style))){
		style_id = 6;
	}
	
	var css_skin = document.createElement("link");
	css_skin.rel = "stylesheet";
	css_skin.href="css/skin_" + style_id + ".css";
	document.getElementsByTagName("head")[0].appendChild(css_skin);
	
	var pnav_on_the_road = get_element("pnav_on_the_road");
	var pnav_vauxhall_interactive = get_element("pnav_vauxhall_interactive");
	var pnav_fun_and_games = get_element("pnav_fun_and_games");
	var pnav_offers = get_element("pnav_offers");
	var pnav_v_xtra = get_element("pnav_v_xtra");
	var pnav_vauxhall_events = get_element("pnav_astra_interactive");
	
	//dynamically assign primary navigation images once the stylesheet has been identified
	pnav_on_the_road.src = "images/global/primary_navigation/style" + style_id + "/on_the_road_off.jpg";
	pnav_vauxhall_interactive.src = "images/global/primary_navigation/style" + style_id + "/vauxhall_interactive_off.jpg";
	pnav_fun_and_games.src = "images/global/primary_navigation/style" + style_id + "/prize_draw_off.jpg";
	pnav_offers.src = "images/global/primary_navigation/style" + style_id + "/offers_off.jpg";
	pnav_v_xtra.src = "images/global/primary_navigation/style" + style_id + "/v_xtra_off.jpg";
	pnav_vauxhall_events.src = "images/global/primary_navigation/style" + style_id + "/vauxhall_events_off.jpg";
}

//retrieve cookie id, as vauxhall.co.uk domain cookie has a few other keys, so can no longer get style id by substr() positioning
function get_cookie_id(){
	var style_to_use = 6;
	
	if(get_cookie("style") != ""){
		style_to_use = get_cookie("style");
	}
	
	if(debug){alert("Return style id of: " + style_to_use + " from get_cookie_id()");}	
	return style_to_use;
}

//retreive from the client cookie which background/css should be used
function select_styles(style_id){
	if(debug){alert("select_styles() has been called");}

	assign_style(style_id);
}

//show/hide tabs
function show_tab(tab_to_show,total_tabs,tab_click){
	var tab = tab_to_show;
	var current_url = document.location.toString();
	var from_tab_click = (tab_click) ? true: false;
	var ajax_array = eval(tab_ajax_calls);
	var obj_location = current_url.split("/");
	var file_path = obj_location[obj_location.length-1].split("?")[0];
					
	//only run this code if the page has been loaded for the first time
	if(!from_tab_click){
		if(current_url.indexOf("?tab=") != -1){
			tab = current_url.split("tab=")[1].substr(0,1); 

			//reload page contextual content (tab stack position)
			load_contextual_content(tab);
		}
		else{
			load_contextual_content(1);
		}		
	}
		
	//load in dynamic ajax content if requested
	if(ajax_array.length > 0){
		//special case for Vauxhall Interactive page (to auto-load most read question)
		if(current_url.indexOf("topic=") != -1){
			if(from_tab_click){
				//run default ajax command for selected tab element
				eval(ajax_array[tab-1]);
			}		
			else{				
				//only continue if the Vauxhall Interactive or Astra Interactive  page  is being currently viewed
				switch(file_path){
					case 'vauxhall_interactive.html':
						var obj_topic = obj_location[obj_location.length-1].split("?")[1].split("&");
						var selected_topic = "";
						var selected_question = 0;
					
						for(var i=0; i<=obj_topic.length-1; i++){
							//loop until both the topic and the question number have been identified
							if((selected_topic == "") || (selected_question == 0)){
								if(obj_topic[i].indexOf("topic=") != -1){
									selected_topic = obj_topic[i].split("=")[1];
								}
								else if(obj_topic[i].indexOf("question_id=") != -1){
									selected_question = obj_topic[i].split("=")[1];
								}
							}
						}
					
						//dynamically auto-load in content based on the querystring paramaters passed as part of the url
						load_via_ajax('data/ask_vauxhall/topics.txt?topic=' + selected_topic + '&question_id=' + selected_question,'ask_vauxhall_topics');
						break;
					case 'astra_interactive.html':
						var obj_topic = obj_location[obj_location.length-1].split("?")[1].split("&");
						var selected_topic = "";
						var selected_question = 0;
					
						for(var i=0; i<=obj_topic.length-1; i++){
							//loop until both the topic and the question number have been identified
							if((selected_topic == "") || (selected_question == 0)){
								if(obj_topic[i].indexOf("topic=") != -1){
									selected_topic = obj_topic[i].split("=")[1];
								}
								else if(obj_topic[i].indexOf("question_id=") != -1){
									selected_question = obj_topic[i].split("=")[1];
								}
							}
						}
						
						//dynamically auto-load in content based on the querystring paramaters passed as part of the url
						load_via_ajax('data/astranuts/most_read_stories.txt?topic=' + selected_topic + '&question_id=' + selected_question,'astranuts');
						break;
				}
			}
		}
		else{
			//run default ajax command for selected tab element
			eval(ajax_array[tab-1]);
		}
	}	

	for(i=1; i<=total_tabs; i++){
		if(i == tab){
			get_element("tab_content_" + i).style.display = "block";
			get_element("tabs").getElementsByTagName("LI")[i-1].className = "selected";
		}
		else{
			get_element("tab_content_" + i).style.display = "none";
			get_element("tabs").getElementsByTagName("LI")[i-1].className = "";
		}
	}
}

//place all elements identified by the same classname into a global array
function get_elements_by_class_name(str_class, tag, obj_element) {
	tag = tag || "*";
	obj_element = obj_element || document;
	
	var obj_collection = obj_element.getElementsByTagName(tag);
	
	if(!obj_collection.length &&  tag == "*" &&  obj_element.all) obj_collection = obj_element.all;
	
	var arr = new Array();
	var delimeter = str_class.indexOf('|') != -1  ? '|' : ' ';
	var classes = str_class.split(delimeter);
	
	for(var i=0, j=obj_collection.length; i<j; i++){
		var obj_classes = obj_collection[i].className.split(' ');
		if(delimeter == ' ' && classes.length > obj_classes.length) continue;
	
		var c = 0;
		comparisonLoop:
	
		for(var k=0, l=obj_classes.length; k<l; k++){
			for (var m=0, n=classes.length; m<n; m++){
				if(classes[m] == obj_classes[k]) c++;
				if((delimeter == '|' && c == 1) || (delimeter == ' ' && c == classes.length)){
					arr.push(obj_collection[i]);
					break comparisonLoop;
				}
			}
		}
	}
	return arr;
}

//accomodate for IE5 (Mac) lack of support for push method
Array.prototype.push = function(value){
	this[this.length] = value;
}

//resize all embedded iframe objects if running in IE5 (to cater for box-model variances in css element widths)
function resize_iframes(browser,resize_height,resize_width,iframes){
	if(browser.indexOf("MSIE 5") != -1){
		var iframes = get_element(iframes);
		
		iframes.style.height = resize_height + "px";
		iframes.style.width = resize_width + "px";
	}
}

//load page contextual content (tab stack position)
function load_contextual_content(stack_position){
	var heading_text = get_elements_by_class_name("tab_content")[stack_position-1].getElementsByTagName("H2")[0].innerHTML;
	var introduction_text = get_elements_by_class_name("tab_content")[stack_position-1].getElementsByTagName("P")[0].innerHTML;

	get_element("horizon").getElementsByTagName("H1")[0].innerHTML = heading_text;
	
	if(introduction_text != "No introduction text available"){
		get_element("horizon").getElementsByTagName("P")[0].innerHTML = introduction_text;
	}
}

//preload all game details
function load_game_details(game_stack_position,number_of_games){
	var promo_items = get_elements_by_class_name("two_wide");
	var promos_populated = 0;
	var title = "";
	var summary = "";
	var image = "";
	var movie_src = games[game_stack_position-1][3];
	var depth = games[game_stack_position-1][4];
	var game_width = games[game_stack_position-1][5];
	var iframe = get_element("games_iframe");
	var left_gutter = 0;
	
	//check so see if game is a flash game (native path) or self-contained within an iframe
	if(games[game_stack_position-1][3].indexOf("[IFRAME]") != -1){
		//hide flash movie container div
		if(get_element("flash_tab_1").style.display == "block"){
			get_element("flash_tab_1").style.display = "none";
		}
		
		//set iframe gutter colours (if supplied)
		//also, if width is smaller than full-width, create equal left and right gutters
		if(games[game_stack_position-1][6] != null){
			get_element("iframe_container").style.backgroundColor = games[game_stack_position-1][6];
			get_element("iframe_container").style.paddingLeft = ((766-games[game_stack_position-1][5])/2).toFixed(0) + "px";
		}
		else{
			get_element("iframe_container").style.paddingLeft = "0px";
		}
		
		//change visibility state of iframe, so game can be viewed
		iframe.style.display = "block";
		iframe.height = depth;
		iframe.width = game_width;
		iframe.src = games[game_stack_position-1][3].substr(8,games[game_stack_position-1][3].length-8);
	}
	else{
		//change visibility state of iframe, so 2 games aren't shown at once
		iframe.style.display = "none";
		
		//show flash movie container div
		if(get_element("flash_tab_1").style.display == "none"){
			get_element("flash_tab_1").style.display = "block";
		}
			
		//populate tab with necessary flash movie
		//tab 1: Games
		obj_flashtab1 = new flash_object();
		
		obj_flashtab1.height = depth;
		obj_flashtab1.width = 766;
		obj_flashtab1.container = "flash_tab_1";
		obj_flashtab1.flash_required_version = 8;
		obj_flashtab1.flash_src = movie_src;
		obj_flashtab1.flash_paramaters = "";
		obj_flashtab1.wmode = 'transparent';
		obj_flashtab1.alternative_image = "";
		obj_flashtab1.alternative_url = "";
		obj_flashtab1.alternative_target = "";
		obj_flashtab1.alternative_alt_text = "";
		obj_flashtab1.alt = "Game";
		
		obj_flashtab1.render_flash();	
	}
	
	//load game details in promo panel at bottom of page
	for(i=0; i<=number_of_games-1; i++){
		if((i+1) != game_stack_position){
			title = games[i][0];
			summary = games[i][1];
			image = games[i][2];
			
			//promo panel image		
			promo_items[promos_populated].getElementsByTagName("A")[0].title = title;
			promo_items[promos_populated].getElementsByTagName("A")[0].href = "fun_and_games.html?game=" + (i+1);
			
			//promo panel heading text
			promo_items[promos_populated].getElementsByTagName("H3")[0].getElementsByTagName("A")[0].title = title;

			promo_items[promos_populated].getElementsByTagName("H3")[0].innerHTML = '<a href="fun_and_games.html?game=' + (i+1) + '" title="' + title + '"><strong>' + title + '</strong></a>';
			promo_items[promos_populated].getElementsByTagName("P")[0].innerHTML = summary;
			promo_items[promos_populated].getElementsByTagName("IMG")[0].alt = title;
			promo_items[promos_populated].getElementsByTagName("IMG")[0].src = image;
			
			promos_populated++;
		}
	}
}

function check_emailaddress(email){
	var email_pattern = /^(.+)@(.+)$/;
	var special_characters = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var valid_characters = "\[^\\s" + special_characters + "\]";
	var quoted_user = "(\"[^\"]*\")";
	var ip_domain_pattern = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=valid_characters + '+';
	var word="(" + atom + "|" + quoted_user + ")";
	var user_pattern = new RegExp("^" + word + "(\\." + word + ")*$");
	var domain_pattern = new RegExp("^" + atom + "(\\." + atom +")*$");
	var match_array = email.match(email_pattern);

	if(match_array == null){
		return false;
	}

	var user = match_array[1];
	var domain = match_array[2];

	if(user.match(user_pattern) == null){
		return false;
	}

	var ip_array = domain.match(ip_domain_pattern);

	if(ip_array != null){
		for (var i=1; i<=4; i++){
			if(ip_array[i] > 255){
				return false;
			}
		}
		return true;
	}

	var domain_array = domain.match(domain_pattern)

	if(domain_array == null){
		return false;
	}

	var atom_pattern = new RegExp(atom,"g");
	var domain_array = domain.match(atom_pattern);
	var len = domain_array.length;

	if(domain_array[domain_array.length-1].length < 2 || domain_array[domain_array.length-1].length > 4){
		return false;
	}

	if(len < 2){
		return false;
	}

	return true;
}
//validate competition form submissions
function validate_form(obj,mandatory,form_page){
	var obj_form = obj;
	var obj_mandatory = mandatory.split("|");
	var error = false;
	var error_msg = "";
	var error_msg_intro = "Please correct the following:\n";
	var current_form_element;
	var submit_override = false;
	
	for(i=0; i<=obj_mandatory.length-1; i++){
		if(obj_mandatory[i].substr(0,3) == "txt"){
			if(obj_form.elements[obj_mandatory[i]].value == ""){		
				error_msg += "\n> " + error_textbox_prefix + ": " + format_validation_error(obj_mandatory[i].substr(4,obj_mandatory[i].length-4));
				
				//change display state of error element (until updated and verified)
				update_error_label(obj_mandatory[i],"invalid");
			}
			else{
				//a value has been supplied, but if an email address, is it valid?
				if(obj_mandatory[i].indexOf("email") != -1){
					if(check_emailaddress(obj_form.elements[obj_mandatory[i]].value)){
						update_error_label(obj_mandatory[i],"valid");
					}
					else{
						update_error_label(obj_mandatory[i],"invalid");
						error_msg += "\n> " + error_invalid_email_prefix;
					}
				}
				else{
					update_error_label(obj_mandatory[i],"valid");
				}
			}				
		}
		else if(obj_mandatory[i].substr(0,3) == "chk"){
			if(obj_form.elements[obj_mandatory[i]].checked == false){
				error_msg += "\n> " + error_checkbox_prefix + ": " + format_validation_error(obj_mandatory[i].substr(4,obj_mandatory[i].length-4));
				
				//change display state of error element (until updated and verified)
				update_error_label(obj_mandatory[i],"invalid");
			}
			else{
				update_error_label(obj_mandatory[i],"valid");
			}
		}
		else if(obj_mandatory[i].substr(0,3) == "sel"){
			if(obj_form.elements[obj_mandatory[i]].options[obj_form.elements[obj_mandatory[i]].selectedIndex].value == ""){
				error_msg += "\n> " + error_select_prefix + ": " + format_validation_error(obj_mandatory[i].substr(4,obj_mandatory[i].length-4));

				//change display state of error element (until updated and verified)
				update_error_label(obj_mandatory[i],"invalid");
			}
			else{
				update_error_label(obj_mandatory[i],"valid");
			}
		}
	}

	if(error_msg != ""){
		//remove the "_blogs" and "_faqs" suffixes within the form element names for these 2 form types
		if(form_page == "post_a_comment"){
			error_msg = error_msg.replace(/ blogs/g,"");
		} else if(form_page == "new_question"){
			error_msg = error_msg.replace(/ faqs/g,"");
		} else if(form_page == "contact_us_popup"){
			error_msg = error_msg.replace(/ contact/g,"");
		} else if(form_page == "share_story"){
			error_msg = error_msg.replace(/ Pers/g,"");
			error_msg = error_msg.replace(/ stories/g,"");
		}
		
		//show error message
		alert(error_msg_intro + error_msg);
		
		//make sure the form is not submitted by returning false
		return false;
	}
	else{
		//var confirm_prompt = "Ok to continue: form type=" + form_page;
		var opener_redirect = "";
		
		switch(form_page){
			case "competition":
				opener_redirect = "confirmation_competition.html";
				
				//update hidden form fields for Multi-M/IT
				obj_form.elements["PERS_FIRST_NAMES"].value = obj_form.elements["txt_first_name"].value;
				obj_form.elements["PERS_LAST_NAME"].value = obj_form.elements["txt_last_name"].value;
				obj_form.elements["PERS_ADDRESS1"].value = obj_form.elements["txt_address_line_1"].value;
				obj_form.elements["PERS_ADDRESS2"].value = obj_form.elements["txt_address_line_2"].value;
				obj_form.elements["PERS_TOWN"].value = obj_form.elements["txt_town_city"].value;
				obj_form.elements["PERS_POSTAL_CODE"].value = obj_form.elements["txt_postcode"].value;
				obj_form.elements["PERS_EMAIL"].value = obj_form.elements["txt_email"].value;
				obj_form.elements["PERS_TEL_HOME"].value = obj_form.elements["txt_phone"].value;
				obj_form.elements["PERS_TEL_MOBILE"].value = obj_form.elements["txt_mobile"].value;
				obj_form.elements["CAR_ERD_MONTH"].value = obj_form.elements["sel_estimated_replace_date_of_my_current_vehicle_month"].options[obj_form.elements["sel_estimated_replace_date_of_my_current_vehicle_month"].selectedIndex].value;
				obj_form.elements["CAR_ERD_YEAR"].value = obj_form.elements["sel_estimated_replace_date_of_my_current_vehicle_year"].options[obj_form.elements["sel_estimated_replace_date_of_my_current_vehicle_year"].selectedIndex].value;
				obj_form.elements["OPT_IN"].value = obj_form.elements["chk_terms_and_conditions_part_1"].checked ? "Y" : "";
		
				//switch the form action and the form target depending on which server it is running from
				if(forms_live){
					obj_form.action = live_form_url;
				}
				else{
					obj_form.action = competition_form_submit;
				}
				
				obj_form.target = "_top";
								
				break;
			case "new_question":
				opener_redirect = "confirmation_add_your_question.html";
				
				//update hidden form fields for Multi-M/IT
				obj_form.elements["PERS_FIRST_NAMES"].value = obj_form.elements["txt_first_name_faqs"].value;
				obj_form.elements["PERS_LAST_NAME"].value = obj_form.elements["txt_last_name_faqs"].value;
				obj_form.elements["PERS_EMAIL"].value = obj_form.elements["txt_my_email_address_faqs"].value;
				obj_form.elements["CAR_ERD_MONTH"].value = obj_form.elements["sel_vehicle_replace_month_faqs"].options[obj_form.elements["sel_vehicle_replace_month_faqs"].selectedIndex].value;
				obj_form.elements["CAR_ERD_YEAR"].value = obj_form.elements["sel_vehicle_replace_year_faqs"].options[obj_form.elements["sel_vehicle_replace_year_faqs"].selectedIndex].value;
				obj_form.elements["EMAIL_IND"].value = (obj_form.elements["chk_vauxhall_email_opt_in_faqs"].checked) ? "Y" : "";
				obj_form.elements["ASK_VX_QUESTION"].value = obj_form.elements["txt_my_question_faqs"].value;
				obj_form.elements["TOPIC"].value = obj_form.elements["sel_topic_faqs"].options[obj_form.elements["sel_topic_faqs"].selectedIndex].value;
				
				//switch the form action and the form target depending on which server it is running from
				if(forms_live){
					obj_form.action = live_form_url;
					obj_form.target = "_top";
				}
				else{
					obj_form.action = ask_your_question_form_submit;
					obj_form.target = (document.domain == live_server) ? "_top" : "_blank";
				}
				
				break;
			case "post_a_comment":
				opener_redirect = "confirmation_add_a_comment.html";
				
				//update hidden form fields for Multi-M/IT
				obj_form.elements["PERS_FIRST_NAMES"].value = obj_form.elements["txt_first_name_blogs"].value;
				obj_form.elements["PERS_LAST_NAME"].value = obj_form.elements["txt_last_name_blogs"].value;
				obj_form.elements["PERS_EMAIL"].value = obj_form.elements["txt_my_email_address_blogs"].value;
				obj_form.elements["CAR_ERD_MONTH"].value = obj_form.elements["sel_vehicle_replace_month_blogs"].options[obj_form.elements["sel_vehicle_replace_month_blogs"].selectedIndex].value;
				obj_form.elements["CAR_ERD_YEAR"].value = obj_form.elements["sel_vehicle_replace_year_blogs"].options[obj_form.elements["sel_vehicle_replace_year_blogs"].selectedIndex].value;
				obj_form.elements["EMAIL_IND"].value = obj_form.elements["chk_vauxhall_email_opt_in_blogs"].checked ? "Y" : "";
				obj_form.elements["BLOG_RESPONSE"].value = 	obj_form.elements["txt_my_blog_response_blogs"].value;
				
				//switch the form action and the form target depending on which server it is running from
				if(forms_live){
					obj_form.action = live_form_url;
					obj_form.target = "_top";
				}
				else{
					obj_form.action = post_a_comment_form_submit;
					obj_form.target = (document.domain == live_server) ? "_top" : "_blank";
				}				
				
				break;
			case "contact_us":
				 opener_redirect = "confirmation_contact.html";
				
				//update hidden form fields for Multi-M/IT
				obj_form.elements["PERS_FIRST_NAMES"].value = obj_form.elements["txt_first_name_contact"].value;
				obj_form.elements["PERS_LAST_NAME"].value = obj_form.elements["txt_last_name_contact"].value;
				obj_form.elements["PERS_EMAIL"].value = obj_form.elements["txt_my_email_address_contact"].value;
				obj_form.elements["EMAIL_IND"].value = obj_form.elements["chk_vauxhall_email_opt_in_contact"].checked ? "Y" : "";
				obj_form.elements["ASK_VX_QUESTION"].value = obj_form.elements["txt_my_question_contact"].value;
				
				//switch the form action and the form target depending on which server it is running from
				if(forms_live){
					obj_form.action = live_form_url;
					obj_form.target = "_top";
				}
				else{
					obj_form.action = contact_us_form_submit;
					obj_form.target = (document.domain == live_server) ? "_top" : "_blank";
				}				
				
				break;
			case "share_story":
				obj_form.action = live_email_form_url;
				obj_form.target = '_top';
				
				break;
			case "login":
			    submit_override = true;
			    var plateNum = obj_form.elements["txt_registration_plate"].value;
				
				if(plateNum.length >= 3){
					obj_form.className = "busy";
					document.getElementById('btn_login').disabled = true;
					isVehicleAVauxhall(plateNum);
				} else {
					alert("Please enter at least 3 characters");
				}
				return false;
				break;
			case "route_planner":
				var clean_location = $('txt_to').value;
				
				//clean_location = clean_location.substr(0,1).toUpperCase() + clean_location.substr(1,clean_location.length-1).toLowerCase();
				location_to = clean_location;
				
				submit_override = true;
				
				callRoute();
				break;
			case "petrol_type":
				var petrolTypeSel = $("sel_petrol_type");
				var fuelType = petrolTypeSel.options[petrolTypeSel.selectedIndex].value;
				var displayText = petrolTypeSel.options[petrolTypeSel.selectedIndex].text;
				
				submit_override = true;
				
				//reset all infoboxes for locations which don't have a postcode
				no_postcode_popup(null,null);
				
				searchForFuelStations(fuelType, $("petrol_prices"), displayText);
				get_element("petrol_prices").style.display = "block";
				
				break;
		}
		
		//redirect the opener if a popup window for ie5/ie6/ie7 has been used
		if(opener_redirect != ""){
			if(window.opener){
				window.opener.location.href = opener_redirect;
			}
		}
		
		//alert(confirm_prompt);
		if(!submit_override){
			obj_form.submit();
		}
	}
}

var counter = 0;
var activeAnimation;
function animateString(string, limit){	
	labelText = $('login').getElementsByTagName('label')[1];
	newLength = string.length - (limit - counter);
	labelText.firstChild.nodeValue = string.substring(0, newLength);
	counter ++;
	if (counter > limit){
		counter = 0;
	}
}


function isVauxhall(plateNum, vauxhallValidationSuccessFunction ,vauxhallValidationErrorFunction ){
	//function to replace the other two versions floating round. Idea here is to seperate code from presentation. Novel idea huh.
	
	var dvlaRequest = "/vaux/drivers_centre/components/DVLAServlet.do?vrm="+plateNum+"&backdoor123=1";
	var site_dom = document.domain.split('.')
    //var dvlaRequest = "http://www.vauxhallabc.co.uk/buyersguide/drivers_centre/components/DVLAServlet.do?vrm=" + plateNum + "&backdoor123=1";
    if ( site_dom[0] == "staging" || site_dom[0] == "uat"  ){
		 dvlaRequest = "http://vx-buyers-guide-app.mrmpweb.co.uk/buyersguide/drivers_centre/components/DVLAServlet.do?vrm=" + plateNum + "&backdoor123=1";
	}
	//var dvlaRequest = "scripts/test_files/dvlatest.xml";
	//var dvlaRequest = "scripts/test_files/dvlafail.xml";
	var message ="";
	if(plateNum==""){ vauxhallValidationErrorFunction('Please enter a Vauxhall Registration');return;}
	var myXhr = new XHR({method: 'get', 
	    onSuccess: function(responseXML){ 
		    if(window.ActiveXObject){
				var xmlObj = new ActiveXObject("Microsoft.XMLDOM");
				xmlObj.async = "false";
				xmlObj.loadXML(responseXML);
			} else { //code for Mozilla, Firefox, Opera, etc.
				var parser = new DOMParser();
				var xmlObj = parser.parseFromString(responseXML,"text/xml");
			}
			
			try {
				vehicleMake = xmlObj.getElementsByTagName('MAKE')[0];
				if (vehicleMake.firstChild.nodeValue == 'VAUXHALL') {
					set_cookie("style",6);
				    vauxhallValidationSuccessFunction();

				} else {
					vauxhallValidationErrorFunction(message);

				} 
			} catch(err) {
				try {
					var errorMessage = xmlObj.getElementsByTagName('MXE1')[0].getElementsByTagName('MSG')[0].firstChild.nodeValue;
					return vauxhallValidationErrorFunction(errorMessage);
				} catch (err){
					message = 'Please enter a Vauxhall Registration';
					vauxhallValidationErrorFunction(message);
				}
				
			}
		}, 
		onFailure:function(){ 
			message ='Please enter a Vauxhall Registration';
			vauxhallValidationErrorFunction(message);
		}
    });
   myXhr.send(dvlaRequest);
	
}

function isVehicleAVauxhall(plateNum){
	//var dvlaRequest = "http://newastravxr.co.uk/drivers_centre/proxies/dvla.cfm?vrm=" + plateNum;
	//var dvlaRequest = "/vx/DVLAServlet.do?vrm=" + plateNum;
	//var dvlaRequest = "http://origin.vauxhall.itl.e-gm.net/vx/drivers_centre/proxies/dvla.cfm?vrm=" + plateNum;
	
	// var dvlaRequest = "/vaux/DVLAServlet.do?vrm=" + plateNum;
	var site_dom = document.domain.split('.')
    var dvlaRequest = "http://www.vauxhallabc.co.uk/buyersguide/drivers_centre/components/DVLAServlet.do?vrm=" + plateNum;
    if ( site_dom[0] == "staging" || site_dom[0] == "uat"  ){
		 dvlaRequest = "http://vx-buyers-guide-app.mrmpweb.co.uk/buyersguide/drivers_centre/components/DVLAServlet.do?vrm=" + plateNum;
	}
	
	
	// Local testing files - uncomment next line to disable DVLA functionality
	// var dvlaRequest = "scripts/test_files/dvlatest.xml"; // xml returned successful
	// var dvlaRequest = "scripts/test_files/dvlanotvx.xml"; // xml returned but plate does not belong to vauxhall
	// var dvlaRequest = "scripts/test_files/dvlanotfound.xml"; // xml returned but plate not found
	// var dvlaRequest = "scripts/test_files/nonexistant.xml"; // no xml returned
	
    var labelText = $('login').getElementsByTagName('label')[0];
	labelText.firstChild.nodeValue = "Verifying...";
	// fn = 'animateString("Verifying...",3)';
	// activeAnimation = setInterval(fn, 400);
	
	var myXhr = new XHR({method: 'get', 
	    onSuccess: function(responseXML){ 
		    if(window.ActiveXObject){
				var xmlObj = new ActiveXObject("Microsoft.XMLDOM");
				xmlObj.async = "false";
				xmlObj.loadXML(responseXML);
			} else { //code for Mozilla, Firefox, Opera, etc.
				var parser = new DOMParser();
				var xmlObj = parser.parseFromString(responseXML,"text/xml");
			}
			
			try {
				vehicleMake = xmlObj.getElementsByTagName('MAKE')[0];
				if (vehicleMake.firstChild.nodeValue == 'VAUXHALL') {
					set_cookie("style",6);
					set_cookie("vauxhall_owner",true);
					
					// alert('Thanks. Continue to the Vauxhall Drivers\' Centre');
					// In case of bookmarked page send user to where they came from
					 if(document.referrer.indexOf(location.host)!= -1 && document.referrer.indexOf('login.html') == -1){
						top.location.href =  document.referrer;
					 } else {
					 	top.location.href = "index.html";
					 }
				} else {
					clearInterval(activeAnimation);
					labelText.firstChild.nodeValue ='VEHICLE NOT FOUND';
					// alert('Your vehicle is not a Vauxhall according to our records.');
				} 
			} catch(err) {
				try {
					var errorMessage = xmlObj.getElementsByTagName('MXE1')[0].getElementsByTagName('MSG')[0].firstChild.nodeValue;
					clearInterval(activeAnimation);
					labelText.firstChild.nodeValue =errorMessage;
					// alert(errorMessage);
				} catch (err){
					clearInterval(activeAnimation);
					labelText.firstChild.nodeValue = 'VEHICLE NOT FOUND';
					alert('System Failure...');
				}
			}
			
			// reset controls
			document.forms['login'].className = "";
			$('txt_registration_plate').select();
			document.getElementById('btn_login').disabled = false;
		}, 
		onFailure:function(){ 
		    // alert('System Failure...');
		    // reset 
			clearInterval(activeAnimation);
			labelText.firstChild.nodeValue ='VEHICLE NOT FOUND';
			document.forms['login'].className = "";
			$('txt_registration_plate').select();
			document.getElementById('btn_login').disabled = false;
		}
    });
    myXhr.send(dvlaRequest);
}

//string cleanup function for client-side competition error handling
function format_validation_error(error_fieldname){
	var temp_array = error_fieldname.split("_");
	var temp_str = "";
	
	for(var i=0; i<=temp_array.length-1; i++){
		//uppercase the first character of only the first word
		if(i==0){
			temp_str += temp_array[0].substr(0,1).toUpperCase() + temp_array[0].substr(1,temp_array[0].length-1).toLowerCase();
		}
		else{
			temp_str += temp_array[i].substr(0,temp_array[i].length);
		}
		temp_str += " ";
	}
	
	return temp_str.substr(0,temp_str.length-1);
}

//change display state of error element (until updated and verified)
function update_error_label(label_value,mode){
	var switch_style = (mode == "invalid") ? " error" : "";
	var label_for;

	for(var i=0; i<labels.length; i++){
		labels_for = labels[0].getAttribute("for") ? "for" : "htmlFor";
		if(labels[i].getAttribute(labels_for) == label_value){
			labels[i].className = switch_style;
		}
	}
}

//function which fixes the issue whereby Firefox identifies line breaks as an objects next sibling
function get_next_sibling(start){
    end = start.nextSibling;

    while(end.nodeType!=1){
        end = end.nextSibling;
    }
    return end;
}

//toggle the display state of (comment) content blocks
function expand_news_blog(position){
	var multiple = 2;
	get_element("article_" + position).style.display = (get_element("article_" + position).style.display == "block") ? "none" : "block";
	
	var toggle_state = (get_element("article_" + position).style.display == "block") ? "minus" : "plus";	
	get_element("link_article_" + position).style.background = "url(images/global/toggle_" + toggle_state + ".gif) no-repeat left 3px";
}

//toggle the visibility of a specified answer
function show_question_answer(question_number){
	var obj_questions = get_elements_by_class_name("abstract");
	var obj_most_read_list = get_element("most_read_answers").getElementsByTagName("UL")[0].getElementsByTagName("LI");
	var list_link = "";

	for(var i=0; i<=obj_questions.length-1; i++){
		for(var x=0; x<=obj_most_read_list.length-1; x++){
			list_link = obj_most_read_list[x].getElementsByTagName("A")[0];
            
			//check to see if the preloaded question is contained within the "Most read answers" list of links
			//if it is, auto-highlight it
			if(obj_questions[i].innerHTML.indexOf(list_link.innerHTML) != -1){
				obj_most_read_list[x].className = "selected";
				break;
			}
		}
	}

	var total_questions = get_elements_by_class_name("question_details");
	var ask_vx_links = get_elements_by_class_name("ask_vx_link");
	
	for(i=0; i<=total_questions.length-1; i++){
		total_questions[i].style.display = (i==(question_number-1)) ? "block" : "none";
		ask_vx_links[i].style.display = (i==(question_number-1)) ? "none" : "inline";
	}
}

//remove all auto-highlighting styles
function reset_most_read_answers(){
	var obj_most_read_list = get_element("most_read_answers").getElementsByTagName("UL")[0].getElementsByTagName("LI"); 
	
	for(var i=0; i<=obj_most_read_list.length-1; i++){
		obj_most_read_list[i].className = "";
	}
}

function show_story(story_number){
	/*
	var obj_stories = get_elements_by_class_name("abstract");
	var obj_most_read_list = get_element("most_read_stories").getElementsByTagName("UL")[0].getElementsByTagName("LI");
	var list_link = "";

	for(var i=0; i<=obj_stories.length-1; i++){
		for(var x=0; x<=obj_most_read_list.length-1; x++){
			list_link = obj_most_read_list[x].getElementsByTagName("A")[0];
            
			//check to see if the preloaded question is contained within the "Most read answers" list of links
			//if it is, auto-highlight it
			if(obj_stories[i].innerHTML.indexOf(list_link.innerHTML) != -1){
				obj_most_read_list[x].className = "selected";
				break;
			}
		}
	}
	*/

	var stories = get_elements_by_class_name("question_details");
	var total_stories = stories.length-1;
	var ask_vx_links = get_elements_by_class_name("ask_vx_link");
	var current_story = 0;
	for(i=0; i<=total_stories; i++){
		if(stories[i].id == 'link_article_'+story_number){
			current_story = 1;
		}
		stories[i].style.display = (current_story) ? "block" : "none";
		ask_vx_links[i].style.display = (current_story) ? "none" : "inline";
		current_story = 0;
	}
}

//remove all auto-highlighting styles
function reset_most_read_story(){
	var obj_most_read_list = get_element("most_read_stories").getElementsByTagName("UL")[0].getElementsByTagName("LI"); 
	
	for(var i=0; i<=obj_most_read_list.length-1; i++){
		obj_most_read_list[i].className = "";
	}
}

//dynamically load in blog content for the specified month
function load_blog_month(yyyy_mm){
	//ensure question popup is closed when switching between FAQs topics
	void(get_element('comment').style.display="none");
	
	//switch the color of the archive month before loading the content in via an ajax call
	var obj_list_archive = get_element("blogs_archive").getElementsByTagName("UL")[0].getElementsByTagName("LI");
	
	for(var i=0; i<=obj_list_archive.length-1; i++){
		if(obj_list_archive[i].id == "blogs_archive_" + yyyy_mm){
			obj_list_archive[i].className = "selected";
		}
		else{
			obj_list_archive[i].className = "";
		}
	}
	
	var data_lookup = new ajax_request();
	
	data_lookup.load_file = "data/blogs/" + yyyy_mm + ".html";
	data_lookup.render_to = "blogs_content";
	data_lookup.generate_results();
}

//dynamically load in faqs for the specified topic
function load_faqs(topic){
	//ensure question popup is closed when switching between FAQs topics
	void(get_element('new_question').style.display="none");
	
	//switch the color of the topic group before loading the content in via an ajax call
	var obj_list_topics = get_element("topics").getElementsByTagName("UL")[0].getElementsByTagName("LI");
	
	for(var i=0; i<=obj_list_topics.length-1; i++){
		if(obj_list_topics[i].id == "faq_topic_" + topic){
			obj_list_topics[i].className = "selected";
		}
		else{
			obj_list_topics[i].className = "";
		}
	}

	//lookup (and retrieve) data
	var data_lookup = new ajax_request();
	
	data_lookup.load_file = "data/ask_vauxhall/" + topic + ".html";
	data_lookup.render_to = "faqs_content";
	data_lookup.generate_results();
}

function load_via_ajax(file_path,mode){
	var data_lookup = new ajax_request_file_retieve_only();
	data_lookup.load_file = file_path;
	data_lookup.mode = mode;
	data_lookup.generate_results();
}

//dynamically load in  Astra News for the specified article
function load_astra_article(article,articleType){
	//ensure question popup is closed when switching between FAQs topics
	void(get_element('share_story').style.display="none");
	var dataPath = ''
	switch(articleType){
		case 'news':
			dataPath = 'data/astra_news/';
			contentID = 'article_content';
			break;
		case 'history':
			dataPath = 'data/astra_history/';
			contentID = 'article_content';
			break;
		case 'astranuts':
			dataPath = 'data/astranuts/';
			contentID = 'astranuts_content';
			break;
	}
	if (dataPath!=''){
		//switch the color of the topic group before loading the content in via an ajax call
		/*
		var obj_list_articles = get_element("news_archive").getElementsByTagName("UL")[0].getElementsByTagName("LI");
	
		for(var i=0; i<=obj_list_articles.length-1; i++){
			if(obj_list_articles[i].id == "news_archive_" + article){
				obj_list_articles[i].className = "selected";
			}
			else{
				obj_list_articles[i].className = "";
			}
		}
		*/

		//lookup (and retrieve) data
		var data_lookup = new ajax_request();
	
		data_lookup.load_file = dataPath + article + ".html";
		data_lookup.render_to = contentID;
		data_lookup.generate_results();
		
	}
}


//functionality to enforce a user-specified filter within the Vauxhall Interactive (blogs) section
function get_rels(category_filter){
	var elements_switch = new Array("H2","DIV","P");
	var elements;
	var tag;
	var all_blogs_link = get_elements_by_class_name("show_all_blog_categories");
	var update_h2_class = false;
	var category_search = category_filter + "|";
	
	for(var i=0; i<=elements_switch.length-1; i++){
		elements = document.getElementsByTagName(elements_switch[i]);
		for(var x=0; x<=elements.length-1; x++){
			tag = elements[x];											
			//set flag to identify which element should have its className changed
			if((elements_switch[i] == "H2") && (x==0)){
				update_h2_class = true;
			}
			
			//restore visibility state for all elements with a "rel" attribute
			if(category_filter == "all"){
				if(tag.getAttribute("rel") != null){
					//ensure that the display state of the question answers isn't dynamically changed
					if(tag.id.indexOf("article_") == -1){
						tag.style.display = "block";
					}
					
					//hide all "show all categories" links
					for(var y=0; y<=all_blogs_link.length-1; y++){
						all_blogs_link[y].style.display = "none";
					}
				}
				
				//if resetting all, update all (but the first) H2 classNames
				var obj_headings = get_element("blogs_content").getElementsByTagName("H2");						
				
				for(var z=0; z<=obj_headings.length-1; z++){
					if(z==0){
						obj_headings[z].className = "first";
					}
					else{
						obj_headings[z].className = "";
					}
				}
			}
			else{
				if(tag.getAttribute("rel") != null){		
					if(tag.getAttribute("rel").indexOf(category_search) != -1){
						//ensure that the display state of the question answers isn't dynamically changed
						if(tag.id.indexOf("article_") == -1){
							tag.style.display = "block";
						}
					
						//reset the first H2, so that it always (correctly) includes the className "first"
						if((elements_switch[i] == "H2") && (update_h2_class)){
							tag.className = "first";
							update_h2_class = false;
						}
					}
					else{
							tag.style.display = "none";
					}
						
					//show all "show all categories" links
					for(var y=0; y<=all_blogs_link.length-1; y++){
						all_blogs_link[y].style.display = "inline";
					}
				}
			}
		}
	}
	//ie5 and ie6 require all <a> tags to be position:relative (when using png hack)
	//setTimeout("make_relative_elements('" + container + "')",500);
}

//ie5 and ie6 require all <a> tags to be position:relative (when using png hack)
function make_relative_elements(container){
/*
	if(ie5 || ie6){
		var obj_links = get_element(container).getElementsByTagName("A");
		if(debug){alert(obj_links.length + " a tags have been identified");}
		
		for(var i=0; i<=obj_links.length-1; i++){
			obj_links[i].style.backgroundColor = 'red';
			obj_links[i].style.position = "relative";
		}
	}
*/
}

//hide all select lists when running ie5/6
function hide_selects(over_out){
    if((navigator.appVersion.indexOf("MSIE 5") != -1) || (navigator.appVersion.indexOf("MSIE 6") != -1)){
        var mode = (over_out == "over") ? "none" : "block";

        obj_selects = document.getElementsByTagName("SELECT");

        for(i=0; i<=obj_selects.length-1; i++){
            obj_selects[i].style.display = mode;
        }
    }
}

//show terms and conditions for competition form(s)
function competition_terms_and_conditions(id){
	var obj = get_element(id);
	
	switch(obj.style.display){
		case "block":
			obj.style.display = "none";
			hide_selects("out");
			break;
		case "none":
			obj.style.display = "block";
			hide_selects("over");
			break;
	}
}

function showPopup(el){
	var elementName = el;
	if (el == 'contact_us_popup'){
		var data_lookup = new ajax_request();
		data_lookup.load_file = "contact_us_form.html";
		data_lookup.render_to = "contact_us_popup";
		data_lookup.generate_results();
	}
	
	
	
	// close any open popups
	var popups = get_elements_by_class_name("popup_form_container");
	for (var i=0; i<popups.length; i++){
		if (popups[i].style.display == 'block'){
			closePopup(popups[i].id);
			break;
		}
	}
	if (document.getElementById('flexinfo')){
		document.getElementById('flexinfo').style.display = 'none';
	}
	
	// reset fading
	clearInterval(fade_objects[el].intervalObj);
	fade_objects[el].opacity = 100;
	
	el = get_element(el);
	
	// position element in centre of the page but below header
	var scroll_top = document.body.scrollTop ? document.body.scrollTop : document.body.parentNode.scrollTop;
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    window_height = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    window_height = document.documentElement.clientHeight;
	  }
	var dist_from_top_of_viewport = (window_height - 280)/2
	el.style.top = Math.max(scroll_top + dist_from_top_of_viewport, 120) + "px";
	if(elementName =='contact_us_popup'){
	    el.style.left="250px";
	    //el.style.width="250px";
	}
	// show it
	setOpacity(el, 100);
	el.style.display = "block";	
}

//called when a question is asked within the faqs section of the website
function ask_your_question(topic){	
    //track a blog form being opened
	tc_log('/uk/en/driversCentre/vxInteractive/askQuestionForm');
	
    showPopup("new_question");
	get_element("summary_title_faqs").innerHTML = "<strong>Selected topic:</strong>&nbsp;" + topic;
	
	var obj_topics = document.forms["new_question"].elements["sel_topic_faqs"];
		
	for(var i=0; i<=obj_topics.length-1; i++){
		if(obj_topics[i].value == topic){
			obj_topics.selectedIndex = i;
			break;
		}
	}
}

//form pop-up for Astranuts
function share_story(){	
	//track a blog form being opened
	tc_log('/uk/en/driversCentre/astraInteractive/storiesForm');
	showPopup("share_story");
}

//loop until the parent wrapper has been reached, in order to find the offsetTop to the very top of the web browser screen
function recursive_offset_top(mode){
	var marker;
	
	if(mode == "blogs"){
		marker = get_element("blogs_content").getElementsByTagName("H2")[0];
	}
	else{
		marker = get_element("ask_your_question");
	}
	
	var message = "";
	var offset_top = 0;
	var marker_vertical_offset = 0;
	
    if(marker.offsetTop){
        while(marker.parentNode){
            if(marker.id == "wrapper"){
                break;
            }
            else{
                offset_top += marker.offsetTop;
                marker = marker.parentNode;
            }
        }	
		return (offset_top + marker_vertical_offset);
	}
}

function get_global_offset_top(el){
	var offset_top_integer = el.offsetTop;
	while (el.offsetParent){
		el = el.offsetParent;
		offset_top_integer = el.offsetTop;
	}
	return (offset_top_integer);
}

//check browser type (for offsetTop)
function browser_check(){
	ie5 = (navigator.appVersion.indexOf("MSIE 5") != -1) ? true : false;
	ie6 = (navigator.appVersion.indexOf("MSIE 6") != -1) ? true : false;
	ie7 = (navigator.appVersion.indexOf("MSIE 7") != -1) ? true : false;
	firefox_pc = ((navigator.userAgent.toLowerCase().indexOf("windows") != -1) && (navigator.userAgent.toLowerCase().indexOf("firefox") != -1)) ? true : false;
	firefox_mac = ((navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.userAgent.toLowerCase().indexOf("firefox") != -1)) ? true : false;
	safari_mac = ((navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.userAgent.toLowerCase().indexOf("safari") != -1)) ? true : false;
}

//called when a response is posted for an existing blog post
function post_a_comment(article_title,article_id,month,year){
	showPopup("comment");
		
	//track a blog form being opened
	tc_log('/uk/en/driversCentre/vxInteractive/blogCommentForm');
	

	
	var month_year = month + "_" + year;
	get_element("summary_title_blogs").innerHTML = "<strong>Selected article:</strong>&nbsp;" + article_title;
	
	var obj_form = document.forms["post_a_comment"];
		
	obj_form.elements["BLOG_TITLE"].value = article_title;
	obj_form.elements["BLOG_ARTICLE_ID"].value = article_id;
	obj_form.elements["BLOG_DATE"].value = month_year;	
	
	//send page to top, so that input form is visible
	// todo: add in some intelligence and smooth scrolling
	// scroll(0,0);
}

//function to centralise any given popup window for ie5/ie6/ie7
//onclick="popup_window(this.href, 'popup', 600, 500, 1, 1, 0, 0, 0, 1, 0);
//1 = url
//2 = width
//3 = height
//4 = scrollbars
//5 = resizable
//6 = menubar
//7 = toolbar
//8 = addressbar
//9 = statusbar
//10 = fullscreen
function popup_window(url, window_name, width, height, scrollbars, resizable, menubar, toolbar, address_bar, status_bar, full_screen){
	var window_left = (screen.width - width) / 2;
	var window_top = (screen.height - height) / 2;
	var window_properties = 'height=' + height + ',width=' + width + ',top=' + window_top + ',left=' + window_left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',toolbar=' + toolbar + ',location=' + address_bar + ',statusbar=' + status_bar + ',fullscreen=' + full_screen + '';
	var obj_window = window.open(url, window_name, window_properties)
	
	if(parseInt(navigator.appVersion) >= 4){
		obj_window.window.focus();
	}
}

//ensure that all div popup layers are non-visible
function reset_popups(section){
	switch(section){
		case "vauxhall_interactive":
			get_element("comment").style.display = "none";
			get_element("new_question").style.display = "none";
			break;
	}
}

//simple function to ensure the form is calling the correct functions when pressing the enter key to submit a form, rather than the submit "link"
function override_submit_login(){
	var obj = document.forms["login"].elements["txt_registration_plate"];
	
	//a value must be entered before being allowed to submit
	if(obj.value == ""){
		return false;
	}
	//a value of 3 (or more) characters must be entered before being allowed to submit
	else if(obj.value.length < 3){
		obj.value = "";
		validate_form(document.forms['login'],form_mandatory_login,'login');
		return false;		
	}
	else{
		validate_form(document.forms['login'],form_mandatory_login,'login');
		return false;
	}
}

//check for valid numeric strings
function is_numeric(str){
	var numeric_chars = "0123456789";
	var current_char;
	var result = true;

	for(var i=0; i<str.length && result == true; i++){
		current_char = str.charAt(i);

		if(numeric_chars.indexOf(current_char) == -1){
			result = false;
		}
	}
	return result;
}

function show_offer_details(offer_name,mode){
	var offer_details_element = document.getElementById(offer_name + '_details');
	
	switch(mode){
		case "show":
			get_element("content").className += "offer_detail_fadeout";
			offer_details_element.style.display = "block";
			// todo: make this a smooth scroll
			scroll(0, (offer_details_element.offsetTop - 20));
			break;
		default:
			get_element("content").className = get_element("content").className.replace(/offer_detail_fadeout/g,"");
			offer_details_element.style.display = "none";
			break;
	}
}

//homepage petrol tool
function submit_fuel_lookup(){
	var obj_form = document.forms["submit_fuel_lookup"];
	var fuel_location = get_element("petrol_tool_location");
	var fuel_type = get_element("petrol_tool_fuel_type");

	if((fuel_location.value == "") || (fuel_type.selectedIndex == 0)){
		alert("Please enter location and fuel type");
	}
	else{
		//run multimap.js logic
		get_petrol_prices();
	}

	return false;
}

//default actions on homepage
function load_homepage_defaults(){
	var pump_image = get_element("fuel_prices").getElementsByTagName("IMG")[0];
	
	pump_image.src = (ie6) ? "images/petrol_tool/pump.gif" : "images/petrol_tool/pump.png";
	
	//default values for petrol tool
	var default_location = get_element("petrol_tool_location");
	
	if(get_cookie("location") != null){
		default_location.value = get_cookie("location");
	}
					
	if(get_cookie('fuelType') != null){
		var default_fuel_type = get_element("petrol_tool_fuel_type");
		
		for(index = 0; index < default_fuel_type.length; index++){
			if(default_fuel_type[index].value == get_cookie('fuelType')){
				default_fuel_type.selectedIndex = index;
			}
		}
	}
}

//retrieve all url paramater
function get_url_param(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
		
	//modified return statement - 30-1-2008
	return (results == null) ? "" : results[1];
}

//build primary navigation so it is rendered at run-time, rather than on an onload
function build_pnav(style_to_use){
	document.write("<a href='on_the_road.html'><img id='pnav_on_the_road' class='first' src='images/global/primary_navigation/style" + style_to_use + "/on_the_road_off.jpg' alt='On the Road' width='125' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>");
	document.write("<a href='vauxhall_interactive.html'><img id='pnav_vauxhall_interactive' src='images/global/primary_navigation/style" + style_to_use + "/vauxhall_interactive_off.jpg' alt='Vauxhall Interactive' width='172' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>");
	document.write("<a href='prize_draws.html'><img id='pnav_prize_draws' src='images/global/primary_navigation/style" + style_to_use + "/prize_draw_off.jpg' alt='Prize Draw' width='134' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>");
	document.write("<a href='offers.html'><img id='pnav_offers' src='images/global/primary_navigation/style" + style_to_use + "/offers_off.jpg' alt='Offers' width='87' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>");
	document.write("<a href='v_xtra.html'><img id='pnav_v_xtra' src='images/global/primary_navigation/style" + style_to_use + "/v_xtra_off.jpg' alt='V Xtra' width='89' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>")
	document.write("<a href='astra_interactive.html'><img id='pnav_astra_interactive' src='images/global/primary_navigation/style" + style_to_use + "/astra_interactive_off.jpg' alt='Astra Interactive' width='149' border='0' onmouseover='highlight_pnav(this,\"over\")' onmouseout='highlight_pnav(this,\"out\")' /></a>");
}


function submitWithEnter(e, obj, mandatory, form_page){
	var keynum;
	
	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	
	if (keynum == 13){
		validate_form(obj,mandatory,form_page);
		initialiseLoading($('get_route'));
	}
}

function swapImage(me, newSrc){
	me.src = newSrc;
}

function show_dialogue(me, popup, relto, internalOffset){
	popup = $(popup);
	el = $(relto);
	leftOffset = 0;
	topOffset = 0;
    while(el.offsetParent){
		leftOffset += el.offsetLeft;
		topOffset += el.offsetTop;
		el = el.offsetParent;
	} 
	
	popup.style.left = (leftOffset + internalOffset.left) + "px";
	popup.style.top = (topOffset + internalOffset.top) + "px";
	popup.style.display= "block";
}

function highlight(me){
	me.select();
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeOut(objId,opacity) {
	var fn = "fadeObject('" + objId + "', -1)";
	fade_objects[objId].intervalObj = setInterval(fn , 50);
	if (document.getElementById('games_iframe')){
	 	document.getElementById('games_iframe').style.visibility = "visible";
	 }
}

function fadeObject(objId, dir){
	
	//opacity = fade_objects[objId].opacity;
	var el = document.getElementById(objId);
	
	if(dir == 1 && fade_objects[objId].opacity >= 100){
		fade_objects[objId].opacity = 100;
		clearInterval(fade_objects[objId].intervalObj);
	} else if(dir == -1 && fade_objects[objId].opacity <= 0){
		clearInterval(fade_objects[objId].intervalObj);
		el.style.display='none';
		fade_objects[objId].opacity = 0;
		setOpacity(el, fade_objects[objId].opacity);
	} else{
		fade_objects[objId].opacity += fade_increment*dir;
		setOpacity(el, fade_objects[objId].opacity);
	}
}

function closePopup(objId) {
	fadeOut(objId, 100);
	 //get_element(objId).style.display='none'
}

function hideFlash(){
	document.getElementById('games_iframe').style.visibility = "hidden";
}


///Motor Show competition survey

function validate_survey_form1() {
with (document.VDC_Motorshow) {
var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
radioOption = -1;
for (counter=0; counter<Q1.length; counter++) {
if (Q1[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your overall perception of the Vauxhall Drivers' Centre?";
	document.getElementById("Q1").style.color = "red";
}
else
{
	document.getElementById("Q1").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q2_GAMES.length; counter++) {
if (Q2_GAMES[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the games section?";
	document.getElementById("Q2_GAMES").style.color = "red";
}
else
{
	document.getElementById("Q2_GAMES").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_COMPETITIONS.length; counter++) {
if (Q2_COMPETITIONS[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the competitions section?";
	document.getElementById("Q2_COMPETITIONS").style.color = "red";
}
else
{
	document.getElementById("Q2_COMPETITIONS").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_OFFERS.length; counter++) {
if (Q2_OFFERS[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the offers section?";
	document.getElementById("Q2_OFFERS").style.color = "red";
}
else
{
	document.getElementById("Q2_OFFERS").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q2_EVENTS.length; counter++) {
if (Q2_EVENTS[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the events section?";
	document.getElementById("Q2_EVENTS").style.color = "red";
}
else
{
	document.getElementById("Q2_EVENTS").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q2_BLOG.length; counter++) {
if (Q2_BLOG[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the blog section?";
	document.getElementById("Q2_BLOG").style.color = "red";
}
else
{
	document.getElementById("Q2_BLOG").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_FUEL_PRICES.length; counter++) {
if (Q2_FUEL_PRICES[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the fuel prices section?";
	document.getElementById("Q2_FUEL_PRICES").style.color = "red";
}
else
{
	document.getElementById("Q2_FUEL_PRICES").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_TRAFFICNET.length; counter++) {
if (Q2_TRAFFICNET[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the traffic net section?";
	document.getElementById("Q2_TRAFFICNET").style.color = "red";
}
else
{
	document.getElementById("Q2_TRAFFICNET").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_JOURNEY_PLANNER.length; counter++) {
if (Q2_JOURNEY_PLANNER[counter].checked) radioOption = counter;
}

if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the journey planner section?";
	document.getElementById("Q2_JOURNEY_PLANNER").style.color = "red";
}
else
{
	document.getElementById("Q2_JOURNEY_PLANNER").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q2_ASK_VAUXHALL.length; counter++) {
if (Q2_ASK_VAUXHALL[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the ask vauxhall section?";
	document.getElementById("Q2_ASK_VAUXHALL").style.color = "red";
}
else
{
	document.getElementById("Q2_ASK_VAUXHALL").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q2_VMAGAZINE.length; counter++) {
if (Q2_VMAGAZINE[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the v magazine section?";
	document.getElementById("Q2_VMAGAZINE").style.color = "red";
}
else
{
	document.getElementById("Q2_VMAGAZINE").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q2_FOOTAGE.length; counter++) {
if (Q2_FOOTAGE[counter].checked) radioOption = counter;
}

if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the vauxhall footage section?";
	document.getElementById("Q2_FOOTAGE").style.color = "red";
}
else
{
	document.getElementById("Q2_FOOTAGE").style.color = "white";
}

radioOption = -1;
for (counter=0; counter<Q3.length; counter++) {
if (Q3[counter].checked) radioOption = counter;
}

if (radioOption == -1) {
	alertMsg += "\nWhich of our current offers appeals most to you?";
	document.getElementById("Q3").style.color = "red";
}
else
{
	document.getElementById("Q3").style.color = "white";
}

if (Q4.value == "") {
	alertMsg += "\nWhat other types of offers would you like to see in your Vauxhall Drivers' Centre?";
	document.getElementById("Q4").style.color = "red";
}
else
{
	document.getElementById("Q4").style.color = "white";
}
radioOption = -1;

for (counter=0; counter<Q5_INTERVIEWS.length; counter++) {
if (Q5_INTERVIEWS[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the interviews footage?";
	document.getElementById("Q5_INTERVIEWS").style.color = "red";
}
else
{
	document.getElementById("Q5_INTERVIEWS").style.color = "white";
}
radioOption = -1;

for (counter=0; counter<Q5_TV.length; counter++) {
if (Q5_TV[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the tv advertisements footage?";
	document.getElementById("Q5_TV").style.color = "red";
}
else
{
	document.getElementById("Q5_TV").style.color = "white";
}
radioOption = -1;

for (counter=0; counter<Q5_VIDEOS.length; counter++) {
if (Q5_VIDEOS[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the videos footage?";
	document.getElementById("Q5_VIDEOS").style.color = "red";
}
else
{
	document.getElementById("Q5_VIDEOS").style.color = "white";
}

radioOption = -1;

for (counter=0; counter<Q5_DOCUMENTARIES.length; counter++) {
if (Q5_DOCUMENTARIES[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the documentaries footage?";
	document.getElementById("Q5_DOCUMENTARIES").style.color = "red";
}
else
{
	document.getElementById("Q5_DOCUMENTARIES").style.color = "white";
}

if (Q6.value == "") {
	alertMsg += "\nWhat else would you like to see added to your Vauxhall Drivers' Centre?";
	document.getElementById("Q6").style.color = "red";
}
else
{
	document.getElementById("Q6").style.color = "white";
}

if (Q7.options[Q7.selectedIndex].value == "") {
	alertMsg += "\nHow often do you currently/intend to visit this site?";
	document.getElementById("Q7").style.color = "red";
}
else
{
	document.getElementById("Q7").style.color = "white";
}
radioOption = -1;
for (counter=0; counter<Q8.length; counter++) {
if (Q8[counter].checked) radioOption = counter;
}


for (counter=0; counter<Q8.length; counter++) {
if (Q8[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nHow did you find out about this competition?";
	document.getElementById("Q8").style.color = "red";
}
else
{
	document.getElementById("Q8").style.color = "white";
}

if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } }


function validate_survey_form2() {
with (document.VDC_Motorshow) {
var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";

if (PERS_FIRST_NAME.value == "") {
	alertMsg += "\nYour name ";
	document.getElementById("PERS_FIRST_NAME").style.color = "red";
}
else
{
	document.getElementById("PERS_FIRST_NAME").style.color = "white";
}
if (PERS_DOB_DAY.value == "") {
	alertMsg += "\nAge(DD)";
	document.getElementById("PERS_DOB_DAY").style.border = "1px red solid";
}
else
{
	document.getElementById("PERS_DOB_DAY").style.border = "none";
}

if (PERS_DOB_MONTH.value == "") {
	alertMsg += "\nAge (MM)";
	document.getElementById("PERS_DOB_MONTH").style.border = "1px red solid";
}
else
{
	document.getElementById("PERS_DOB_MONTH").style.border = "none";
}

if (PERS_DOB_YEAR.value == "") {
	alertMsg += "\nAge (YYYY)";
	document.getElementById("PERS_DOB_YEAR").style.border = "1px red solid";
}
else
{
	document.getElementById("PERS_DOB_YEAR").style.border = "none";
}


for (counter=0; counter<PERS_GENDER.length; counter++) {
if (PERS_GENDER[counter].checked) radioOption = counter;
}
if (radioOption == -1) {
	alertMsg += "\nWhat is your opinion of the documentaries footage?";
	document.getElementById("PERS_GENDER").style.color = "red";
}
else
{
	document.getElementById("PERS_GENDER").style.color = "white";
}



if (PERS_EMAIL.value == "") {
	alertMsg += "\nEmail address";
	document.getElementById("PERS_EMAIL").style.color = "red";
}
else
{
	document.getElementById("PERS_EMAIL").style.color = "white";
}


if (PERS_TEL_HOME.value == "") {
	alertMsg += "\nHome telephone number";
	document.getElementById("PERS_TEL_HOME").style.color = "red";
}
else
{
	document.getElementById("PERS_TEL_HOME").style.color = "white";
}
if (TNC_CONFIRM_YN.checked !== true) alertMsg += "\nYou must agree to our terms and conditions";
if (radioOption == -1) alertMsg += "\nHow did you find out about this competitions?";
if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } }

///used to parse out querystring variables
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
function gup(name)
{
	// Get URL parameter value
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#?]*)";
	var regex = new RegExp(regexS,'i');	
	
	var results = regex.exec(window.location.href);
	
	if(results == null) return "";
		/*return the number*/
		else return results[1];
}


function tc_log(){
	return;
}