//Global variables for the HTTP request
var req = false;
var isIE = false;


/**
 * This function is used to submit the main form
 * which links the pages on this website.
 */
function goToPage(url){
	document.getElementById("MainForm").page.value = url;

	for(var i=1; i<=10; i++){
		if(arguments[i]){
			document.getElementById("id"+i).value = arguments[i];
		}
		else{
			i = 100;
		}
	}
	
	document.getElementById("MainForm").submit();
}

/**
 * This function is used to submit the main form
 * which links the pages on this website.
 */
function goToAdminPage(page, id){
	//alert(page);
	location.href= "/admin/?page="+page+"&id="+id;
}

/**
 * This function is used to submit the main form
 * which links the pages on external websites
 */
function openWindow(url){
	var d = new Date();
	
	var newWindowName = "externallinks"+d.getMilliseconds();
	
	var newWindow = window.open("", newWindowName, "toolbars=no, resizable=yes, scrollbars=yes");
	document.getElementById("MainForm").page.value = "externallinks";
	document.getElementById("MainForm").target = newWindowName;
	document.getElementById("id1").value = url;
	
	document.getElementById("MainForm").submit();
	
	document.getElementById("id1").value = "";
	document.getElementById("MainForm").target = "";
}

/**
 * HTTP Request function that can be used
 * throughout this website.
 */
function doXmlHttpRequest(get_url, call_back_function, submit_method, message)
{	
	if (submit_method == "" || submit_method == undefined){
		submit_method = "GET";
	}
	
	if (message == "" || message == undefined){
		message = null;
	}
	
	//alert ("Message in XML: "+ message + "Method: "+ submit_method);
	// Object for Mozilla / Safari / Opera
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = call_back_function;
			
		if (submit_method == "POST"){
			//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}

		req.open(submit_method, get_url, true);
		req.send(null);
    	
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			//alert(call_back_function);
			req.onreadystatechange = call_back_function;
			req.open(submit_method, get_url, true);
            
            // for ie compatability
   		    //req.setRequestHeader('Content-Type','text/html');
			if (submit_method == "POST"){
				//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   		    }
			req.send();
		}
	}
}