function start_timer_to_reset_tabs(description){
	//wait 2 seconds before resetting the categories and tabs to their original state
	eval( description+"_timer_to_reset_tabs=setTimeout(\"reset_tabs('"+description+"')\",2000)" );
}

function reset_tabs(description){

	//Reset the select
	eval(description+"_selected_tabs=new Array()");
	
	description1=description;//"description1";
	
	if( eval( "typeof "+description1+"_originally_selected_categories!='undefined'" ) ){
		//return the categories and tabs to their original state - their original css classes
		for(a=0;a< eval(description1+"_originally_selected_categories.length") ;a++){
			document.getElementById( eval( description1+"_originally_selected_categories[a].split(';')[0]" ) ).className= eval( description1+"_originally_selected_categories[a].split(';')[1]" );
			//populate the array with the originally selected tabs (class isn't blank)
			if( eval( description1+"_originally_selected_categories[a].split(';')[0].split('_')[0]" )==description && eval( description1+"_originally_selected_categories[a].split(';')[0].split('_')[1]" ) =='tab'&& eval( description1+"_originally_selected_categories[a].split(';')[1]" ) !=''){
				//Initialize
				//description=eval ( description1+"_originally_selected_categories[a].split(';')[0].split('_')[0]" ) ;
				if( eval( "typeof "+description+"_selected_tabs=='undefined'" ) ){
					eval( description+"_selected_tabs=new Array()" );
				}
				eval( description+"_selected_tabs["+description+"_selected_tabs.length]="+description1+"_originally_selected_categories[a].split(';')[0]" );
			}
		}
	}
	
	//DEBUGGING
	//alert( "RESET "+description+" -- "+eval(description+"_selected_tabs") );
	
}

function highlight_selected_tab(id,new_class){

	description=id.split("_")[0];
	this_tab_level=id.split("_")[2];

	description1=description;//"description1";

	//halt the timer's countdown to reset the tabs
	if( eval( "typeof "+description+"_timer_to_reset_tabs!='undefined'" ) ){
		eval( "clearTimeout("+description+"_timer_to_reset_tabs)" );
	}

	//record the originally selected tabs and their associated classes
	//initialize the array to hold the selected tabs information
	if( eval( "typeof "+description+"_selected_tabs=='undefined'" ) ){
		eval( description+"_selected_tabs=new Array()" );
		//populate the array with the originally selected tabs
		for(a=0;a<document.all.length;a++){
			//if it's a tab and the class is blank
			if(document.all[a].id.split("_")[0]==description && document.all[a].id.split("_")[1]=="tab" && document.getElementById(document.all[a].id).className!=""){
				eval( description+"_selected_tabs[document.all[a].id.split('_')[2]]=document.all[a].id" );
			}
		}
		
		//DEBUGGING
		//alert( "HIGHLIGHT "+description+" -- "+eval( description+"_selected_tabs" ) );

		//also record all of the originally selected categories and tabs and their states/css classes
		eval ( description1+"_originally_selected_categories=new Array()" ) ;
		for(a=0;a<document.all.length;a++){
			if(  document.all[a].id.split("_").length>1 && ( (document.all[a].id.split("_")[1].split("/")[0]=="tab" && document.all[a].id.split("_")[0]==description) || (document.all[a].id.split("_")[0].split("/")[0]=="categories" && document.all[a].id.split("_")[0].split("/")[1]==description) ) ){
			eval ( description1+"_originally_selected_categories["+description1+"_originally_selected_categories.length]=document.all[a].id+';'+document.getElementById(document.all[a].id).className" ) ;
			}
		}
		
		//DEBUGGING
		//alert( "ORIGINALLY "+description+" -- "+eval(description1+"_originally_selected_categories") );
		
	}
	//unselect the previously selected tab if there is one and if the previously selected tab isn't the same as the currently selected tab
	if( eval( "typeof "+description+"_selected_tabs[this_tab_level]!='undefined'" ) ){
		
		//DEBUGGING
		//alert( eval(description+"_selected_tabs") );
		
		//deselect the selected tab for this level and everything below it eg. 1-3
		for(z=this_tab_level;z< eval( description+"_selected_tabs.length" ) ;z++){
			
			//DEBUGGING
			//alert(this_tab_level+" ... "+eval( description+"_selected_tabs[z]" ));
			
			document.getElementById( eval( description+"_selected_tabs[z]" ) ).className='';
		}
		//repopulate the array to match the selected tabs
		temp_array=new Array();
		for(z=0;z<=this_tab_level;z++){
		temp_array[z]=eval( description+"_selected_tabs[z]" );
		}
		eval( description+"_selected_tabs=temp_array" );
	}
	//highlight selected tab
	document.getElementById(id).className=new_class;
	eval( description+"_selected_tabs[this_tab_level]=id" );
}

function show_subcategories(specified_element,subcategory_elements){
	specified_element_level=eval(specified_element.split("_")[1]);
	subcategory_elements=subcategory_elements.split("|");
	for(a=0;a<subcategory_elements.length;a++){
		this_element=subcategory_elements[a];
		this_element_level=eval(this_element.split("_")[1]);
		//hide the non-specified subcategories
		if(this_element_level>=specified_element_level){
			document.getElementById(this_element).className="hide";
		}
	}
	//show the selected subcategories if they exist
	if(document.getElementById(specified_element)){
		document.getElementById(specified_element).className="show";
	}
}

function toggle_visibility(id){
	
	//Check the current state
	if( document.getElementById(id).className!="hide" ){
		var action="hide";
	}else{
		var action="show";
	}
	
	//Set the state
	document.getElementById(id).className=action;
	
}

function toggle_disability(id){

	//Check the current state
	if( document.getElementById(id).disabled!=true ){
		var action=true;
	}else{
		var action=false;
	}
	
	//Set the state
	document.getElementById(id).disabled=action;

}

function change_element_value(id,type,value){
	//Make sure that the element exists
	if( document.getElementById(id)!=null ){
		eval("document.getElementById('"+id+"')."+type+"='"+value+"'");
		
		//Notify that the element does exist
		return true;
		
	}else{
		//Notify that the element doesn't exist
		return false;	
	}
}

function get_url_variable(variable_name){
	//get the entire url
	all_variables=document.location.href.split("?")[1];
	//check that there are variables
	if(typeof(all_variables)!="undefined"){
				
		all_variables=string_replace("%26","&",all_variables);
				
		//look at all of the variables
		for(e=0;e<all_variables.split("&").length;e++){
												
			if(all_variables.split("&")[e].split("=")[0]==variable_name){
				//remove the %20 characters representing a space
				return string_replace("%20"," ",all_variables.split("&")[e].split("=")[1]);
			}
			
		}
	}
	return "none";
}

//Replace a string with another string
function string_replace(findChars,replacementChars,text){
	//Replace Characters
	var newText="";
	for(var r=0;r<text.length;r++){
		//Set char string to compare
		var charString="";
		//starting at r, create charString to compare findChars with (according to number of chars)
		for(var s=r;s<r+findChars.length&&s<text.length;s++){
			charString+=text.charAt(s);
		}
		//If the charString matches findChars
		if(charString==findChars){
			//add charString to nextText
			newText+=replacementChars;
			//and move on, starting at next unchecked char
			r=r+eval(findChars.length-1);
		}
		else{
			//Add letter to nextText
			newText+=text.charAt(r);
		}
	}
	return newText;
}

function change_url_by_element( id ){

	document.location.href=document.getElementById( id ).value;

}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function valid_email_address(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

function restrict_field_length( max_length, e, field_id ){

	//If this isn't an event
	if( e==null ){
	
	     //Take the mamimum number
		document.getElementById(field_id).value=document.getElementById(field_id).value.substring( 0, max_length );
		
		//Don't add the selected value
		return false;
	
	}
	// IE
	else if(window.event){
	
	  var keynum = e.keyCode;
	  
	}
	// Netscape/Firefox/Opera
	else if(e.which){
	
	  var keynum = e.which;

	}
	
	var keychar = String.fromCharCode(keynum);
	
	//What is the new length of the field (this function is executed before the key's value is added)
	var input_length=document.getElementById(field_id).value.length;
	
	//If the current length is greater than the maximum (allow backspace and delete buttons)
	if( input_length>=max_length && keynum!=8 && typeof keynum!="undefined" ){
	
	     //Take the maximum number
		document.getElementById(field_id).value=document.getElementById(field_id).value.substring( 0, max_length );
		
		//Don't add the selected value
		return false;
	
	}

}

function show_field_length( id, field_id ){

	document.getElementById(id).innerHTML=document.getElementById(field_id).value.length;

}