// JavaScript Document
var http_request = false;
var div_id = "";
var dataID = "";
var g_type	= "";
var handler_f = handler;
var ajax_div = "";

function ajaxDo(url, divId, type, handler_func) {
	http_request = false;
	div_id = divId;
	g_type = type;

	if (window.XMLHttpRequest){ 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType){
			http_request.overrideMimeType('text/xml');
		}
	}else if(window.ActiveXObject){ 
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
    			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	if (!http_request) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = handler;
	http_request.open('GET', url, true);
	http_request.send(null);
}

function ajaxDo2(url1, div_id) {
	http_request = false;
	ajax_div = div_id;
//	if (handler_func == '') handler_func = handler();
//	alert('handler_func = '+handler_func);
	if (window.XMLHttpRequest){ 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType){
			http_request.overrideMimeType('text/xml');
		}
	}else if(window.ActiveXObject){ 
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
    			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	if (!http_request) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = ajax_handler;
	http_request.open('GET', url1, true);
	http_request.send(null);
	
}

function ajax_handler()
{
	divId = eval("document.getElementById(ajax_div)");
	divId.innerHTML = '';
	
	if (http_request.readyState != 4) {
		divId.innerHTML = "<!--div style='position:relative;top:100;left:100;'--><img src='images/ajax_loading.gif' align='absmiddle'>Loading Data...<!--/div-->";
	}
	else
	{
		if (http_request.status == 200) {
			var response = http_request.responseText; 
			divId.innerHTML = response;
		}else{
			alert('The requested page NOT found!!!.');
		}
	}
}

function handler(){
	if (http_request.readyState != 4) {
		document.getElementById('new_menu').style.display = '';
		document.getElementById('add_new_menu').style.display = 'none';
		document.getElementById('submit_new_menu').style.display = 'none';
		document.getElementById('loading').style.display = '';
		document.getElementById('loading').innerHTML = "<td colspan='3'><div align='center' style='width:100%;padding:3px;'><img src='image/loading.gif' align='absmiddle'> Loading Data...</div></td>";
	}else{ 
		if (http_request.status == 200) {
			setTimeout("document.getElementById('loading').innerHTML = ''", 250);
			setTimeout("showEditData(http_request)", 250);
		}else{
			alert('There was a problem with the request.');
		}
	} 
} 

//-- got this from http://www.arjenkarel.nl/js/ajax.js

function show(str,div) {
	if (str.length==0) {
		document.getElementById(mydiv).innerHTML=""
		return
	}
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var url=""
	url=url+str
	url=url+"&rnd="+Math.random()
	xmlHttp.onreadystatechange=function() {stateChanged(div,xmlHttp);}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged(div,xmlHttp) {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(div).innerHTML=xmlHttp.responseText
	}
	else {
		//document.getElementById(div).innerHTML = "<img src='images/ajax_loading.gif' align='absmiddle'>Loading Data...";
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new
			ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

//-- end
