
/************************************************
	Filename:	validate.js
	Author:	Stephen Bush

Thank you to Chris Campell from Particle Tree
for the original version of this script!
************************************************/

/************************************************
***** GLOBAL VARIABLES **************************
************************************************/
var do_toggle = false;
var do_switch = false;

/***************************************************
		ATTACH_SWITCH_HANDLERS
	input:	none
	output:	none
	function:	attaches dynamic validation to 
		form elements, including the form itself.
***************************************************/
function attach_tab_handlers() {
	if(document.getElementsByTagName) {								// VERIFY we have a capable browser
		var obj = document.getElementsByTagName('a');					// GRAB all possible tags
		for (var icount=0; icount < obj.length; icount++) {				// LOOP through all tags
			if(obj[icount].className == "switch") {
				obj[icount].onclick = function(){ 
					return tab_switch(this); }	// --ATTACH our dynamic validation to each tag
				document.getElementById(obj[icount].id+"_tab").style.display = "none";
				do_switch = true;
			} else if(obj[icount].className == "toggle") {
				obj[icount].onclick = function(){ 
					return tab_toggle(this); }	// --ATTACH our dynamic validation to each tag
				document.getElementById(obj[icount].id+"_tab").style.display = "none";
				do_toggle = true;
			} // END if className
		} // END for length
	} // END if getElements
} // END attach_form_handlers

/***************************************************
		TABS_SWITCH
	input:	none
	output:	none
	function:	attaches dynamic validation to 
		form elements, including the form itself.
***************************************************/
var old_link = null;
var old_tab = null;
function tab_switch(obj) {
	var new_link = obj.id;
	var new_tab = new_link+"_tab";
	
	if(new_link == old_link) { return true; }	// same tab -- don't do a thing
	
	// change new tab elements
	document.getElementById(new_tab).style.display = "block";
	document.getElementById(new_link).style.fontStyle = "italic"; // italic
	document.getElementById(new_link).style.color = "#ccc";	// gray
	
	if(old_link != null) {
		document.getElementById(old_tab).style.display = "none";
		document.getElementById(old_link).style.fontStyle = "normal"; // italic
		document.getElementById(old_link).style.color = "#000"; }	// gray
	
	old_link = new_link;
	old_tab = new_tab;
	
} // END switch_tabs

/***************************************************
		TABS_TOGGLE
	input:	none
	output:	none
	function:	attaches dynamic validation to 
		form elements, including the form itself.
***************************************************/
function tab_toggle(obj) {
	var tab_id = obj.id+"_tab";
	var tab = document.getElementById(tab_id);
	if(tab.style.display == "none") { tab.style.display = "block"; }
	else if(tab.style.display == "block") { tab.style.display = "none"; }
	else {}
} // END switch_tabs

/**/
