var xmlHttp

function page_onload(pgid)
{
	// some stuff here
}

function doAjax(url, ele_id, type, in_string)
{
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support AJAX... please upgrade!")
		return
	}
	url = url + "&sid=" + Math.random()
	if (ele_id == "smilies") xmlHttp.onreadystatechange = stateSmiliesChanged
	if (ele_id == "birthdays") xmlHttp.onreadystatechange = stateBirthdaysChanged
	xmlHttp.open(type,url,true)
	if (type == 'GET') {
		xmlHttp.send(null)
	} else {
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", in_string.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(in_string);
	}
} 

function stateSmiliesChanged()
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
		document.getElementById("smilies").innerHTML = xmlHttp.responseText 
	} 
} 

function stateBirthdaysChanged()
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
		document.getElementById("birthdays").innerHTML = xmlHttp.responseText 
	} 
} 

function GetXmlHttpObject()
{ 
	var objXMLHttp = null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function toggle_smilies()
{
	if (document.getElementById("smilies").innerHTML != "")	{
		document.getElementById("smilies").innerHTML = ""
		document.getElementById("smilies_title").innerHTML = "show smilies"
	} else {
		document.getElementById("smilies_title").innerHTML = "hide smilies"
		doAjax('smilies/index.php?append=1', 'smilies', 'GET', '')
	}
}

function insert_smiley(smiley)
{	
	if (document.selection) {
		document.comments_form.comment.focus();
		sel = document.selection.createRange();
		sel.text += smiley;
	} else if (document.comments_form.comment.selectionStart || document.comments_form.comment.selectionStart == '0') {
		var startPos = document.comments_form.comment.selectionStart;
		var endPos = document.comments_form.comment.selectionEnd;
		document.comments_form.comment.value = document.comments_form.comment.value.substring(0, startPos) + smiley + document.comments_form.comment.value.substring(endPos, document.comments_form.comment.value.length);
	} else {
		document.comments_form.comment.value += smiley;
	}

}

function toggle_birthdays()
{
	if (document.getElementById("birthdays").innerHTML != "")	{
		document.getElementById("birthdays").innerHTML = ""
		document.getElementById("birthdays_title").innerHTML = " &gt; add yours!"
	} else {
		document.getElementById("birthdays_title").innerHTML = "add your birthday! | hide form"
		doAjax('addbirthday.php?append=1', 'birthdays', 'GET', '')
	}
}

function post_birthday(obj) 
{
	var append_colour
	append_colour = "";

	var radios = document.getElementById("colour_selection")
	var inputs = radios.getElementsByTagName("input")
	for (var i = 0; i < inputs.length; ++i) {
		if (inputs[i].type == 'radio' && inputs[i].name == 'colour' && inputs[i].checked) append_colour = inputs[i].value
	}
	
	var poststr = "name=" + encodeURI(document.getElementById("b_name").value) + "&contact=" + encodeURI(document.getElementById("b_contact").value) + "&month=" + encodeURI(document.getElementById("b_month").value) + "&day=" + encodeURI(document.getElementById("b_day").value) + "&year=" + encodeURI(document.getElementById("b_year").value) + "&colour=" + append_colour + "&birthday_submit=1"
	doAjax('addbirthday.php?append=1', 'birthdays', 'POST', poststr)
}