site_address = "http://www.eaa.org.uk/"
im_path = "im/"

im1 = new Image(); im1.src = "im/wait_msg.gif"

function show_wait_msg(x)
{
  image_name = "wait_msg" + x
  document.images[image_name].src = "im/wait_msg.gif"
}

buttons1 = new Array('but_back_to_results', 'but_next', 'but_prev', 'but_more_details')
buttons2 = new Array('but_new_search', 'but_next_page', 'but_prev_page', 'but_more_details')
buttons3 = new Array('but_more_details')
buttons4 = new Array('but_back_to_news')
buttons_polla = new Array('but_vote_submit')
buttons_pollb = new Array('vote_box')

function do_load()
{
	page_loaded = 1;
	im_preload(buttons1, "gif");
	im_preload(buttons2, "gif");
	im_preload(buttons3, "gif");
	im_preload(buttons4, "gif");
//	load_popups(ddmenu_P7_arr);
//	raiseMenuButton();
}

function im_preload(arr, itype)
{
  im = new Array()
  for (n=0; n<arr.length; n++)
  {
    im[n] = new Image()
    im[n].src = im_path + arr[n] + "_f2." + itype
  }
}

function raiseMenuButton() 
{
  if (raised_button) document.images[raised_button].src = im_path + raised_button + '_f2.gif'
}

function jmover(id, page_id)
{
  if (page_id) im = id + "_" + page_id; else im = id
  document.images[im].src = im_path + id + "_f2.jpg"
}

function jmout(id, page_id)
{
  if (page_id) im = id + "_" + page_id; else im = id
  document.images[im].src = im_path + id + ".jpg"
}

function gmover(id)
{
  page_id = gmover.arguments[1]
  ext = gmover.arguments[2]
  sticky = gmover.arguments[3]
  if (page_id) im = id + "_" + page_id; else im = id
  if (!ext) ext = "_f2"
  
  if (sticky) 
  {
//		alert(document.images[im].src)
		if (document.images[im].src.indexOf("_f4") != -1) return
  }
  document.images[im].src = im_path + id + ext + ".gif"
}

function gmout(id)
{
  page_id = gmout.arguments[1]
  ext = gmout.arguments[2]
  sticky = gmout.arguments[3]
  if (!ext) ext = ""
  if (page_id) im = id + "_" + page_id; else im = id
  
  if (sticky) 
  {
//		alert(document.images[im].src)
		if (document.images[im].src.indexOf("_f4") != -1) return
  }
  document.images[im].src = im_path + id + ext + ".gif"
//  raiseMenuButton() 
}

function reset1(v)
{
	if (v.value == "your name" || v.value == "your email address") v.value = ""
}


var win1

function newWin(url,w,h) {
if (win1 && win1.open || win1 && !win1.closed){win1.close()}
win1 = window.open(url,"win1","width="+w+",height="+h+",toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=yes")
}

function readCookie(name)
{
  var cookieValue = "";
  var search1 = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search1);
    if (offset != -1)
    { 
      offset += search1.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

//poll stuff ---------------------

var provisional_selection_msg = "Provisional selection."
var provisional_selection_msg_ta = "Current response. Confirm by clicking vote button below."

function update_poll_cookie (p) //need to make it poll aware too. Do that next
{	
	//build cookie str containing question=answer|question=answer|question=answer etc
	var ck_str = "";
	var divider = "";
	for (i=0; i<poll_questions.length; i++)
	{
		question_field = poll_questions[i] //e.g. gets rb-9 or ta-12
//		pairs = question.split("-")
//		answer_field_type = pairs[0]
//		question_number = pairs[1]
		answer = document.form1.elements['pollvar[' + question_field + ']'].value
		ck_str += divider + question_field + "=" + answer
		divider = "|"
	}
	writeCookie("poll"+p, ck_str, 72)
}

function update_poll_from_cookie (p)
{
	ck = readCookie("poll"+p)
	
	pairs = ck.split("|")
	for (i=0; i<pairs.length; i++)
	{
		pair_split = pairs[i].split("=")
		question_field = pair_split[0] //question field e.g. rb-9, ta-8
		answer = pair_split[1] //answer
		
		//assign values to relevant form vars to display correctly
		if (answer)
		{
			//assign form var
			document.form1.elements['pollvar[' + question_field + ']'].value = answer
			
			//do following highlighting for rb (radiobox) style question fields only
			if (question_field.indexOf("rb-") != -1) 	highlight_poll_row (question_field, answer)
			if (question_field.indexOf("ta-") != -1) 	highlight_ta_row (question_field)
		}
	}
}

function toggleSelRow(qf, answer)
{
	var row_already_selected = 0
	//get the row
	row_elem = document.getElementById("row_" + qf + "_" + answer)
	//get the vote box
	box_elem = document.getElementById("vote_box_" + qf + "_" + answer)
	//establish if already selected
	if (box_elem.src.indexOf("vote_box_f4.gif") != -1) row_already_selected = 1
	clearSelRow(qf)
	
	if (!row_already_selected) 
	{
		document.form1.elements['pollvar[' + qf + ']'].value = answer
		highlight_poll_row (qf, answer)
	}
	
	update_poll_cookie(poll_id) //update the cookie whether just set or just cleared a value
}

function highlight_poll_row (qf, answer)
{
	document.getElementById("row_" + qf + "_" + answer).style.backgroundColor = "#FFFFCC";
	document.getElementById("vote_box_" + qf + "_" + answer).src = "im/vote_box_f4.gif"
	//show poll provisional selection div warning
	document.getElementById("ppsd_" + qf + "_" + answer).className = "ppsd_on"
	document.getElementById("ppsd_" + qf + "_" + answer).innerHTML = provisional_selection_msg
}

function toggleTA(qf, this_ta)
{
//	var ta_already_selected = 0
	//if box has text in it
	update_poll_cookie(poll_id) //update the cookie whether just set or just cleared a value

	if (this_ta.value.length > 0)
	{
		highlight_ta_row(qf)
	}
	else
	{
		document.getElementById("row_" + qf).style.backgroundColor = "#FFFFFF";
		document.getElementById("ta_box_" + qf).src = "im/ta_box.gif"
		//show poll provisional selection div warning
/*		
		document.getElementById("ppsd_" + qf).className = "ppsd"
		document.getElementById("ppsd_" + qf).innerHTML = ""
*/
	}
}

function highlight_ta_row (qf)
{
	document.getElementById("row_" + qf).style.backgroundColor = "#FFFFCC";
	document.getElementById("ta_box_" + qf).src = "im/ta_box_f4.gif"
	//show poll provisional selection div warning
/*	
	document.getElementById("ppsd_" + qf).className = "ppsd_on"
	document.getElementById("ppsd_" + qf).innerHTML = provisional_selection_msg_ta
*/
}

function clearSelRow(qf)
{
	//clear all row bgcols for this question
	for (i=0; i<document.form1.getElementsByTagName("tr").length; i++)
	{
		elem1 = document.form1.getElementsByTagName("tr")[i]
		if (elem1.id.indexOf("row_" + qf) != -1) elem1.style.backgroundColor = "#FFFFFF";
	}	
	//clear all vote boxes 
	for (i=0; i<document.form1.getElementsByTagName("img").length; i++)
	{
		elem1 = document.form1.getElementsByTagName("img")[i]
		if (elem1.id.indexOf("vote_box_" + qf) != -1) elem1.src = "im/vote_box.gif";
	}	
	//clear all ppsd divs 
	for (i=0; i<document.form1.getElementsByTagName("div").length; i++)
	{
		elem1 = document.form1.getElementsByTagName("div")[i]
		if (elem1.id.indexOf("ppsd_" + qf) != -1) elem1.className = "ppsd"
	}	
	//clear vote choice value
	document.form1.elements['pollvar[' + qf + ']'].value = "";
}

function sd(c) //show details
{
	newWin("vote_choice_details.php?c=" + c, 200, 200)	
}

// misc -------------------------------------
//CUSTOM TOOLTIP
//Copyright 2004, Sandeep Gangadharan
//For more free scripts go to http://sivamdesign.com/scripts/

(document.getElementById) ? dom = true : dom = false;

function hideIt(add) {
  if (dom) {document.getElementById('tooltip'+add).style.visibility='hidden';}
  if (document.layers) {document.layers["tooltip"+add].visibility='hide';}
 }
function showIt(add) {
 if (dom) {
  if (document.getElementById('tooltip'+add).style.visibility=='visible') { hideIt(add); }
  else {document.getElementById('tooltip'+add).style.visibility='visible'} }

 if (document.layers) {
  if (document.layers["tooltip"+add].visibility=='show') { hideIt(add); }
  else {document.layers["tooltip"+add].visibility='show'}  }
 }
 //end custom tool tip
 
//cookie check
function cookies_turned_off()
{
	ck_warning = ""
	writeCookie("test", "testvalue", 24)
	cookie_check = readCookie("test")
	if (cookie_check != "testvalue") ck_warning = "<div style=\"border:5px solid #CC0000; width:90%; padding:10px\"><p class=\"warning\">Your browser cookies must be enabled to allow you to take part in the poll. <br><font color=\"#990000\"><b>Your cookies are disabled or not working.</b></font><br>Please consult your browser help file for information on enabling cookies.</p></div>"
	writeCookie("test", "testvalue", -24)
	return ck_warning
}
