function get_element_by_id(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all[id];
	}
	else if (document.layers) {
		return document.layers[id];
	}
}

function gebi(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all[id];
	}
	else if (document.layers) {
		return document.layers[id];
	}
}

function change_style(id, element, value) {
	if (document.getElementById) {
		document.getElementById(id).style[element] = value;
	}
	else if (document.all) {
		document.all[id].style[element] = value;
	}
	else if (document.layers) {
		document.layers[id].style[element] = value;
	}
}

function get_style(id, element) {
	if (document.getElementById) {
		return document.getElementById(id).style[element];
	}
	else if (document.all) {
		return document.all[id].style[element];
	}
	else if (document.layers) {
		return document.layers[id].style[element];
	}
}

function get_scroll_height() {
	if (document.compatMode && document.compatMode != "BackCompat") {
	   return document.documentElement.scrollHeight;
	} else {
	   return document.body.scrollHeight;
	}
}

function get_scroll_width() {
	if (document.compatMode && document.compatMode != "BackCompat") {
	   return document.documentElement.scrollWidth;
	} else {
	   return document.body.scrollWidth;
	}
}

function get_body_property(property) {
	if (document.compatMode && document.compatMode != "BackCompat") {
	   return document.documentElement[property];
	} else {
	   return document.body.scrollTop[property];
	}
}

function center_floating_div(id) {
	var div = get_element_by_id(id);
	var div_width = div.offsetWidth;
	var div_height = div.offsetHeight;
	var dim = get_browser_height();
	var new_left = (dim.width - div_width) / 2;
	var new_top = (dim.height - div_height) / 2;
	change_style(id, 'left', parseInt(new_left + get_body_property('scrollLeft')) + 'px');
	change_style(id, 'top', parseInt(new_top + get_body_property('scrollTop')) + 'px');
}

function get_browser_height() {
	var intH = 0;
	var intW = 0;
	if (typeof window.innerWidth  == 'number') {
		intH = window.innerHeight;
		intW = window.innerWidth;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		intH = document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}
	return {width: parseInt(intW), height: parseInt(intH)};
}

function toggle_collapse(id) {
	if (get_style(id, 'display') == 'none') {
		change_style(id, 'display', '');
	} else {
		change_style(id, 'display', 'none');
	}
}

function fade_in(elementId) {
	change_opacity(gebi(elementId), 0);
	change_style(elementId, 'display', '');
	
	var this_obj = this;
	var fadeTimer1 = new Array(), opacity1, delay;
	for (var i = 1; i <= 100; i++) {
		opacity1 = parseInt(i);
		delay = parseInt(i*15);
		fadeTimer1[i] = setTimeout('change_opacity(gebi("' + elementId + '"), ' + opacity1 + ')', delay);
	}
	// fadeTimer1[i] = setTimeout(function(){change_style(fromId, 'display', 'none'); this_obj.mClickable=true; this_obj.Debug();}, delay + 1);
}

function change_opacity(object, opacity) {
	object = object.style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")"; 
}

var xmlHttp;

function executeAjax(file_name, state_change_func) { 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = file_name;
	
	xmlHttp.onreadystatechange = state_change_func;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {xmlHttp=new XMLHttpRequest();}
	catch (e){ 
		try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){ 
			xmlHttp=new
			ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	return xmlHttp;
}

function is_valid_email(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,10})$/;
	if(reg.test(str) == false) {
		return false;
	} else {
		return true;
	}
}

function validate_email(id) {
	var email = gebi(id).value;
	if (!is_valid_email(email)) {
		alert('The email address you have provided is invalid.');	
	}
}

function window_open(link_url, window_name, window_width, window_height, scrollbar) {
	var pref = "width=" + window_width + ",height=" + window_height + ",scrollbars=" + scrollbar;
	new_window = window.open(link_url, window_name, pref);
	if (window.focus) {
		new_window.focus();
	}
}