function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) curtop += obj.offsetTop;
	}
	return curtop;
}


function stf_win(url) {

	var newDiv = getById('stfdiv');
	newDiv.style.display = "block";
	newDiv.style.backgroundColor = "#f3f3f3";
	newDiv.style.border = "solid 1px #808080";
	newDiv.style.height = "300px";
	newDiv.style.width = "400px";
	newDiv.style.padding = "10px";
	newDiv.style.overflow = "auto";

	ajaxGet("stf&url="+escape(url));
}

function stf_close() {
	var newDiv = document.getElementById("stfdiv");
	newDiv.parentNode.removeChild(newDiv);
}

function stf_send() {
	remail = document.getElementById("recip_addy").value;
	sname = document.getElementById("sender_name").value;
	semail = document.getElementById("sender_addy").value;
	mssg = document.getElementById("mssg").value;
	url = document.getElementById("url").value;
	info = 'remail~~~'+remail+'|||';
	info += 'sname~~~'+sname+'|||';
	info += 'semail~~~'+semail+'|||';
	info += 'mssg~~~'+mssg+'|||';
	info += 'url~~~'+url;
	ajaxPost('send',info);
}

var MS_httpreq = new Array("Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
function createAjaxObject() {
	var httpRequest = null;
	if (window.XMLHttpRequest != null) {
		httpRequest = new window.XMLHttpRequest();
	} else if (window.ActiveXObject != null) {
		var success = false;
		for (var i = 0; i < MS_httpreq.length && !success; i++) {
			try {
				httpRequest = new ActiveXObject(MS_httpreq[i]);
				success = true;
			}
		catch (ex) {}
		}
	}
	if (httpRequest == null)  alert("Error in HttpRequest():\n\n" + "Cannot create an AJAX object.");
	return httpRequest;
}
var ajax = createAjaxObject();

function ajaxGet(action) {
	ajax.open('get', '../ajax/stf.php?action='+action, true);
	ajax.onreadystatechange = handleResponse;
	ajax.send(null);
}

function ajaxPost(action,info) {
	ajax.open('post', '../ajax/stf.php?action='+action, true);
	ajax.setRequestHeader("Content-type", "");
	ajax.setRequestHeader("Content-length", info.length);
	ajax.setRequestHeader("Connection", "close");
	ajax.send(info);
	ajax.onreadystatechange = handleResponse;
}

function handleResponse() {
	if(ajax.readyState == 4){
		if (ajax.status == 200) {
		
			var response = ajax.responseText;

			var update = new Array();
			if(response.indexOf('||') != -1) {
				update = response.split('||');
				if (update.length > 0) {
					for (n=0; n<update.length; n++) {
						if (document.getElementById(update[n])) document.getElementById(update[n]).innerHTML = unescape((update[n+1]));
						n++;
					}
				}
			}
		} else alert("AJAX Request Failed: Error "+ajax.status);
	}
}