function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();

function ajaxGet(div,action,popup,closeOnClick) {
	
	if(closeOnClick != true) {
		closeOnClick = false;
	}
	var nocache = Math.random();
	http.open('get', 'system/implement.php?'+action+'&nocache='+nocache);
	
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			if(popup) {
				makePopup(http.responseText,closeOnClick);
			} else {
				document.getElementById(div).innerHTML = http.responseText;
			}
		}
	}
	http.send(null);
	
}

function ajaxPost(form,div) {	
	  
    http.open("POST", 'system/implement.php', true);	
	var query = '';
	
	form = document.forms[form];	
	
	for(var x = 0 ; x < form.length; x ++)	{
		query = query + form[x].name + '=' + escape(form[x].value) +'&';
	}	
	http.onreadystatechange =  function() {
		if(http.readyState == 4) {
			document.getElementById(div).innerHTML = http.responseText;
			//makePopup(http.responseText);
		}
	}
	
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
    http.send(query);
	
}

function makePopup(content,closeOnClick) {
	
	var site = document.getElementById('wrapper');
	site.style.cssText = "z-index: 2; filter: alpha(opacity=38); -moz-opacity: 0.38; opacity: 0.38;";
		
	var popup = document.getElementById('popupload');
	
	if(closeOnClick) {
		popup.onclick = function() {
			closePopup();
		}
	}
	
	popup.style.cssText = "position: fixed; border: 5px solid #2A2A2A; background: #FFF; visibility: visible;";	
	
	popup.innerHTML = '<div>'+content+'</div>';

	popup.style.background =  "#FFF";
	popup.style.padding = "5px";
			
	popup.style.left = ((getClientWidth()/2)-(popup.offsetWidth/2))+"px";
	popup.style.top =  ((getClientHeight()/2)-(popup.offsetHeight/2))+"px";

}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function closePopup() {	
	var site = document.getElementById('wrapper');
	site.style.cssText = "";

	var popup = document.getElementById('popupload');
	popup.style.cssText = "visibility: hidden;";
}

