// JavaScript Document
function f_center_form(){
	//set the variables that will position and set the new div's width
	var browser_width = document.body.offsetWidth;
	var content_div = document.getElementById('content_div'); 
	var content_width = content_div.scrollWidth;
	var content_height = content_div.offsetHeight;
	var margin_width = (browser_width/2)-(content_width/2);
	content_div.style.position = "absolute";
	content_div.style.top = 15 + "px";
	content_div.style.left = margin_width + "px";
}

/////////////////////////////////////////////
//Functions for attaching event listeners///
///////////////////////////////////////////

function attachEventListener(target, eventType, functionRef, capture){
	if(typeof target.addEventListener != "undefined")
	{
		target.addEventListener(eventType, functionRef, capture);
	}
	else if(typeof target.attachEvent != "undefined")
	{
		target.attachEvent("on"+eventType, functionRef);
	}
	else
	{
		eventType = "on" + eventType;
		if(typeof target[eventType] == "function")
		{
			var oldListener = target[eventType];
			
			target[eventType] = function()
			{
				oldListener();
				return functionRef();
			};
		}
		else
		{
			target[eventType] = functionRef;
		}
	}
}

function detachEventListener(target, eventType, functionRef, capture){
	if(typeof target.removeEventListener != "undefined"){
		target.removeEventListener(eventType, functionRef, capture);
	}else if(typeof target.detachEvent != "undefined"){
		target.detachEvent("on"+eventType, functionRef);
	}else{
		target["on" + eventType] = null;
	}
}

function f_update_license(){
	var elements = document.forms['seminarForm'].elements;
	var url = "/PHP/process/ext_form/p_schedule_seminar.php";
	var sendVars = "";
	for(var x = 0; x < elements.length; x++){
		var fieldType = elements[x].type;
		if(fieldType != undefined){
			var my_encode = Url.encode(elements[x].value);
			sendVars += elements[x].id+"="+my_encode+"&";
		}
	}
	
	url += '?'+sendVars;
	window.location = url;
}

//function for making the pay now options disappear
function f_paynow_clicked(){
	var checkbox = document.getElementById("pay_now");
	var div = document.getElementById("pay_now_div");
	var html = "";
	if(checkbox.checked){
		if(!electric){
			html = '<input type="radio" name="paypal_option" value="BM" />&nbsp;($150) Business Law Test Preparation<br /><input type="radio" name="paypal_option" value="Trade" />&nbsp;($250) Trade Test Preparation<br /><input type="radio" name="paypal_option" value="Both" checked />&nbsp;($400) Combo BL and Trade Test Preparation<br />';
		}else{
			html = '<input type="radio" name="paypal_option" value="BM" />&nbsp;($150) Business Law Test Preparation<br /><input type="radio" name="paypal_option" value="Trade" />&nbsp;($350) Trade Test Preparation<br /><input type="radio" name="paypal_option" value="Both" checked />&nbsp;($500) Combo BL and Trade Test Preparation<br />';
		}
	}
	div.innerHTML = html;
}

//submit a form
function f_submit_schedule_seminar(){
	var elements = document.forms["seminarForm"].elements;
	var pass = f_validate_form(elements);
	if(pass){
		var form = document.getElementById("seminarForm");
		form.submit();
	}
}

//function for submitting the paypal form
function f_submit_paypal(){
	var form = document.getElementById("paypal_form");
	form.submit;
}

/*
///////////////////////////////////////////////////////////////////////////
//////Functions for menu interaction//////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

function showToolTip(btnTitle, column){
	if(column == null){
		column = 'menuColumn';
	}
	var menuDiv = document.getElementById(column);
	tipText = btnTitle;
	attachEventListener(menuDiv, 'mousemove', showToolTipDiv, false);
}

function hideToolTip(column){
	if(column == null){
		column = 'menuColumn';
	}
	var menuDiv = document.getElementById(column);
	detachEventListener(menuDiv, 'mousemove', showToolTipDiv, false);
	
	var myDivs = document.getElementsByTagName("div");
	for(var i=0; i < myDivs.length; i++){
		var curDiv = myDivs[i];
		var relAttr = curDiv.className;
		if(relAttr == "toolTip"){
			var parentNode = curDiv.parentNode;
			parentNode.removeChild(curDiv);	
		}
	}
}

function showToolTipDiv(event){
	if(!document.getElementById('toolTip')){
		var tip = document.createElement("div");
		tip.setAttribute("id", "toolTip");
		tip.className = "toolTip";
		tip.innerHTML = "<span class='contentText'>"+tipText+"</span>";
		
		var scrollingPosition = getScrollingPosition();
	
		var cursorPosition = [0, 0];
		if(typeof event.pageX != "undefined" && typeof event.x != "undefined"){
			cursorPosition[0] = event.pageX;
			cursorPosition[1] = event.pageY;
		}else{
			cursorPosition[0] = event.clientX + scrollingPosition[0];
			cursorPosition[1] = event.clientY + scrollingPosition[1];
		}
		
		tip.style.position = "absolute";
		tip.style.left = cursorPosition[0] + 10 + "px";
		tip.style.top =  cursorPosition[1] + 10 + "px";
		document.getElementsByTagName("body")[0].appendChild(tip);
	}else{
		hideToolTip();
		var tip = document.createElement("div");
		tip.setAttribute("id", "toolTip");
		tip.className = "toolTip";
		tip.innerHTML = "<span class='contentText'>"+tipText+"</span>";
		
		var scrollingPosition = getScrollingPosition();
	
		var cursorPosition = [0, 0];
		if(typeof event.pageX != "undefined" && typeof event.x != "undefined"){
			cursorPosition[0] = event.pageX;
			cursorPosition[1] = event.pageY;
		}else{
			cursorPosition[0] = event.clientX + scrollingPosition[0];
			cursorPosition[1] = event.clientY + scrollingPosition[1];
		}
		
		tip.style.position = "absolute";
		tip.style.left = cursorPosition[0] + 10 + "px";
		tip.style.top =  cursorPosition[1] + 10 + "px";
		document.getElementsByTagName("body")[0].appendChild(tip);
	}
}

function getScrollingPosition(){
	var position = [0, 0];
	
	if(typeof window.pageYOffset != 'undefined'){
		position = [window.pageXOffset,
					window.pageYOffset];
	}else if(typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0 || document.documentElement.scrollLeft > 0){
		position = [
					document.documentElement.scrollLeft,
					document.documentElement.scrollTop
					];
	}else if(typeof document.body.scrollTop != 'undefined'){
		position = [
					document.body.scrollLeft,
					document.body.scrollTop
					];
	}
	
	return position;
}
*/
