
function toggle_display(elem){
	document.getElementById(elem).style.display = (document.getElementById(elem).style.display=="none") ? "" : "none";
}

function input_class(elem,type){
	if(type == "focus"){
		elem.focus();
		if(elem.className == "textbox"){
			elem.className = "textboxActive";
		}
	} else if(type == "blur" && elem.className == "textboxActive"){
		elem.className = "textbox";
	}
}


// AJAX
function ajax(){
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer"){
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	return http;
}
function ajax_function(page,elem,form){
	http = ajax();
	
	// GATHER FORM FIELDS
	if(form != null && form == true){
		var form_method = document.theform.method;
		var params = "";
		var field = "";
		for(var i=0; i<document.theform.elements.length; i++){
			if(document.theform.elements[i].type.indexOf("select") >= 0){
				field = "";
				for(var j=0; j<document.theform.elements[i].options.length; j++){
					if(document.theform.elements[i].options[j].selected == true){
						if(field != ""){ field += ", "; }
						field += document.theform.elements[i].options[j].value;
					}
					if(params != ""){ params += "&"; }
					params += document.theform.elements[i].name + "=" + escape(field);
				}
						
			} else if((document.theform.elements[i].type != "checkbox" && document.theform.elements[i].type != "radio") || (document.theform.elements[i].type == "checkbox" && document.theform.elements[i].checked == true) || (document.theform.elements[i].type == "radio" && document.theform.elements[i].checked == true)){
				if(params != ""){ params += "&"; }
				params += document.theform.elements[i].name + "=" + escape(document.theform.elements[i].value);
			}
		}
		if(form_method == "get"){
			http.open("GET", page+"?"+params, true);
		} else if(form_method == "post"){
			http.open("POST", page, true);
		}
	} else {
		http.open("GET", page, true);
	}
	
	http.onreadystatechange=function() {
		if(http.readyState == 4){
			if(elem != null){
				sethtml(elem,http.responseText);
			} else {
				sethtml("body_inner",http.responseText);
			}
		}
	}
	
	// SEND POST-FORM INFO
	if(form != null && form == true && form_method == "post"){
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.send(params);
	} else {
		http.send(null);
	}
}

function sethtml(div,content){
    var search = content;
    var script;
    while( script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i)){
      search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
      if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;
      block = search.substr(0, search.indexOf(RegExp.$1));
      search = search.substring(block.length + RegExp.$1.length);
      var oScript = document.createElement('script');
      oScript.text = block;
      document.getElementsByTagName("head").item(0).appendChild(oScript);
    }
    document.getElementById(div).innerHTML=content;
}