/* $DE$ */

/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

if (navigator.appVersion.indexOf("Windows CE")>0) {
	xmlHttp = false;
}

var myloc=document.location.href;

function get_search(server,searchby,maxrows,query,sortby,orderby,page,did) {
	var params='searchby='+escape(searchby)+'&maxrows='+escape(maxrows)+'&query='+escape(query)+'&SortBy='+escape(sortby)+'&orderby='+escape(orderby)+'&page='+escape(page);
	if (server.search("searchdiary") > -1) {
		params=params.concat('&DID='+escape(did));
	}
	myloc=escape(server)+"?"+params;
	if(!xmlHttp) {
		document.location.href=myloc;
	} else {
/*        xmlHttp.abort;*/
    	xmlHttp.open("POST",escape(server));
    	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp.onreadystatechange = update_search;
    	xmlHttp.send(params+'&ajax=1');
	}
}

function update_search(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200)
			document.getElementById('search_table').innerHTML = xmlHttp.responseText;
		else
			document.location.href=myloc;
	}
}

var update_comment_id=false;

function get_comment(server,did,eid,id) {
	var params='DID='+escape(did)+'&EID='+escape(eid);
	myloc=escape(server)+"?"+params;
	if(!xmlHttp) {
		document.location.href=myloc;
	} else {
/*        xmlHttp.abort;*/
		try {
			document.getElementById('comment_insert_'+update_comment_id).innerHTML = '';
		} catch (e) { }
		update_comment_id=id;
    	xmlHttp.open("POST",escape(server));
    	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp.onreadystatechange = update_comment;
    	xmlHttp.send(params+'&ajax=1');
	}
}

function get_commentreply(server,did,eid,cid,id) {
	var params='DID='+escape(did)+'&EID='+escape(eid)+'&parentid='+escape(cid);
	myloc=escape(server)+"?"+params;
	if(!xmlHttp) {
		document.location.href=myloc;
	} else {
/*        xmlHttp.abort;*/
		try {
			document.getElementById('comment_insert_'+update_comment_id).innerHTML = '';
		} catch (e) { }
		update_comment_id=id;
    	xmlHttp.open("POST",escape(server));
    	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp.onreadystatechange = update_comment;
    	xmlHttp.send(params+'&ajax=1');
	}
}

function update_comment(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200) {
	        try {
				document.getElementById('comment_insert_'+update_comment_id).innerHTML = xmlHttp.responseText;
			} catch (e) {}
			try {
				document.getElementById('ENTRY').focus();
			} catch (e) {
				try {
					document.getElementById('FORM_USER').focus();
				} catch (e2) {}
			}
		} else {
			document.location.href=myloc;
		}
	}
}
