var d = window.document;

//////////////////////////////////////
//  GENERIC RETURN ELEMENT FUNCTION //
//////////////////////////////////////

function getE( v ) {
  // e is for element!
  e = false;
  
  if ( d.getElementById ) {
    e = d.getElementById( v );
  }
  else if ( d.all ) {
    e = d.all[ v ];
  }

  return e;
}

/*
	AJAX BASE FUNCTIONALITY
*/

var xmlhttp = null;
var displayDiv = "";
var nextFunc = "";

////////////////////////////////
//	BASIC AJAX LOADER					//
////////////////////////////////

function getPage( url, second ) {

	if ( second != false ) nextFunc = second;
	else nextFunc = "";
	
	xmlhttp=null;

	if (window.XMLHttpRequest) {// code for all new browsers
  	xmlhttp=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {// code for IE5 and IE6
  	xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP" );
  }
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function() {
			stateChange(nextFunc)
		};
		xmlhttp.open( "GET", url, true );
		xmlhttp.send( null );
  }
}

////////////////////////////////
//	EVENT HANDLER FOR HTTP		//
//	STATE CHANGE							//
////////////////////////////////

function stateChange(nextFunc) {
	e = getE( displayDiv );
	
	if (xmlhttp.readyState==4) {// 4 = "loaded"
		if (xmlhttp.status==200) {// 200 = OK
// 			alert(xmlhttp.responseText);
			e.innerHTML = xmlhttp.responseText;
			if ( nextFunc != "" ) eval( nextFunc );
		}
	}
}


	/* ---------------------- Pre-Loader for the Galleries ------------------------- */
	
function fadeOut(id) {
// 	var id = e.getAttribute("id");
	opacity(id, 100, 0, 115);
// 	alert(id);
}

function fadeIn(id) {
// 	var container = document.getElementById("content").style;
// 	container.backgroundImage = "none";
	
// 	var id = e.getAttribute("id");
	opacity(id, 1, 100, 115);
}




function opacity(id, startAlpha, endAlpha, milliseconds) {
	var speed = Math.round(milliseconds / 100);
	var timer = 0;
	
	if (startAlpha > endAlpha) {
		for (i=startAlpha; i>=endAlpha; i--) {
			setTimeout("changeOpacity('" + i + "', '" + id + "')", (timer*speed));
			timer++;
		}
	} else if (startAlpha < endAlpha) {
		for (i=startAlpha; i<=endAlpha; i++) {
			setTimeout("changeOpacity('" + i + "', '" + id + "')", (timer*speed));
			timer++;
		}
	}
}

function changeOpacity(newOpacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (newOpacity/100);
	object.filter = "alpha(opacity="+newOpacity+")";
	
// 	if (object.opacity == 0) {
// 		var container = document.getElementById("content").style;
// 		container.backgroundImage = "url('/_img/preloader.gif')";
// 		container.backgroundRepeat = "no-repeat";
// 		container.backgroundPosition = "center center";
// 	}
}




////////////////////////////
// CHECK ( checkboxes )
///////////////////////////
var checkflag = "false";

function check(f) {
  if (checkflag == "false") {
      for (i = 0; i < f.length; i++) {
          if (f[i].name != "Undecided" ) {
              f[i].checked = true;
          }
      }
      
      checkflag = "true";
      return "Uncheck All";     }
  
  else {
      for (i = 0; i < f.length; i++) {
          if (f[i].name != "Undecided" ) {
              f[i].checked = false;             }
      }
  
      checkflag = "false";
      return "Check All";     }
}


	
	/* ----------------------------- Ask Kate Pop Question ----------------------------- */
	
function popQuestion( clickTarget, popID, totalNumber ) {
	/* ---------- Set Up the Variables (Thanks IE) -------------- */
	var divs = document.getElementsByTagName("div");
	var questions = new Array();
	var answers = new Array();
	
	for (i=0; i<divs.length; i++) {
		if (divs[i].className == "kateQuestion") {
			questions.push(divs[i]);
		}
		
		if (divs[i].className == "kateAnswer") {
			answers.push(divs[i]);
		}
	}
	
	
	/* ------- Clear all the Answer Divs -------- */
	for (i=0; i<answers.length; i++) {
		answers[i].style.display = "none";
	}
	
	/* ------- Reset the Defualt Styles for all Questions ------ */
	for (i=0; i<questions.length; i++) {
		questions[i].style.borderLeft = "none";
		questions[i].style.borderRight = "none";
		questions[i].style.borderBottom = "2px solid #B3E5E4";
	
		if (i==0) {
			questions[i].style.borderTop = "none";
		}
	}
	
	/* ----------- Show the Appropriate Answer ------------------ */
	displayDiv = document.getElementById(popID).style;
	displayDiv.display = "block";
	
	/* ----------- Set the Styles to highlight the active element ------------- */
	clickTarget.style.borderLeft = "2px solid #B3E5E4";	
	clickTarget.style.borderRight = "2px solid #B3E5E4";
	clickTarget.style.borderBottom = "none";
	
	if (clickTarget.getAttribute("id") == questions[0].getAttribute("id")) {
		clickTarget.style.borderTop = "2px solid #B3E5E4";
	}
}




	/* ----------------- Accordian Function for the Timeline ------------------ */
	
function popTimeline(clickTarget) {
	/* ----------- First Hide All of the Accordian Divs ----------------- */
	var divs = document.getElementsByTagName("div");
	var tDetails = new Array();
	
	for (i=0; i<divs.length; i++) {
		if (divs[i].className == "timelineDetails") {
			tDetails.push(divs[i]);
		}
	}
	
	for (i=0; i<tDetails.length; i++) {
		tDetails[i].style.display = "none";
	}
	
	/* ------- Get the Div we want to Show ------- */
	divToShow = clickTarget.parentNode.nextSibling;
	
	/* -------- FireFox Treats the empty carraige return as a node, so get the next one ------- */
	if (divToShow.nodeType != 1) {
		divToShow = clickTarget.parentNode.nextSibling.nextSibling;
	}
	
	/* ---------- Pop It --------------- */
	divToShow.style.display = "block";
}


	/* ---------- New Function to toggle Additional Links in the registration ------------- */
	
function toggleMoreLinks() {
	var moreLink = document.getElementById("moreLinksLink");
	var moreBoxes = document.getElementById("moreOptions");
	
	moreLink.style.display = "none";
	moreBoxes.style.display = "block";
}