function hidead()
{
	if (document.getElementById)
	{
		document.getElementById("sblog").style.display = "none";
	}
	else if(document.all)
	{
		document.all["sblog"].style.display = "none";
	}
	else if (document.layers)
	{
		document.layers["sblog"].style.display = "none";
	}
}
function showad1()
{
	if (document.getElementById)
	{
		document.getElementById("sblog").style.display = "block";
	}
	else if(document.all)
	{
		document.all["sblog"].style.display = "block";
	}
	else if (document.layers)
	{
		document.layers["sblog"].style.display = "block";
	}
}
function fileUpload(form, action_url, div_id)
{
	clearInterval('getEntries()');
	// Create the iframe...
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id","upload_iframe");
	iframe.setAttribute("name","upload_iframe");
	iframe.setAttribute("width","0");
	iframe.setAttribute("height","0");
	iframe.setAttribute("border","0");
	iframe.setAttribute("style","width: 0; height: 0; border: none;");

	// Add to document...
	form.parentNode.appendChild(iframe);
	window.frames['upload_iframe'].name="upload_iframe";

	iframeId = document.getElementById("upload_iframe");

	// Add event...
	var eventHandler = function()  {

		if (iframeId.detachEvent)
			iframeId.detachEvent("onload", eventHandler);
		else
			iframeId.removeEventListener("load", eventHandler, false);

		// Message from server...
		if (iframeId.contentDocument) {
			content = iframeId.contentDocument.body.innerHTML;
		} else if (iframeId.contentWindow) {
			content = iframeId.contentWindow.document.body.innerHTML;
		} else if (iframeId.document) {
			content = iframeId.document.body.innerHTML;
		}

		document.getElementById(div_id).innerHTML = content;

		// Del the iframe...
		setTimeout('iframeId.parentNode.removeChild(iframeId)', 2500);
	}

	if (iframeId.addEventListener)
		iframeId.addEventListener("load", eventHandler, true);
	if (iframeId.attachEvent)
		iframeId.attachEvent("onload", eventHandler);

	// Set properties of form...
	form.setAttribute("target","upload_iframe");
	form.setAttribute("action", action_url);
	form.setAttribute("method","post");
	form.setAttribute("enctype","multipart/form-data");
	form.setAttribute("encoding","multipart/form-data");

	// Submit the form...
	form.submit();
	hidead();
	

	document.getElementById(div_id).innerHTML = "Uploading...";
	
}
function getXMLHttpRequestb(){
	try{
		req = new XMLHttpRequest();
	}
	catch(err1){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(err2){
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(err3){
				req = false;
			}
		}
	}
	return req;
}

var xmlhttpb = getXMLHttpRequestb();

function getEntries(){ 
	if(xmlhttpb){
		var cid = document.getElementById('cid').value;
		var myurl = 'scripts/clblog.php?cid=' + escape(cid) ;
		myRand = parseInt(Math.random()*999999999999999); //to avoid page caching
		var modurl = myurl + '&rand=' + myRand;
		xmlhttpb.open('GET', modurl, true);
		xmlhttpb.onreadystatechange = useHttpResponseb;
		xmlhttpb.send(null);
	}
}
function useHttpResponseb(){
	var timeoutSet = false;
	var downloadOK = false;
	if(xmlhttpb.readyState == 1){
		if(!timeoutSet){
			toolong = window.setTimeout(function(){
					   	if(!downloadOK){
						xmlhttpb.abort();
						document.getElementById('upload').innerHTML = 
						'<font color=red>Server took long to respond <b>trying again!</b></font>';
							}
						}, 35000);
			timeoutSet = true;
		}
	}
	if(xmlhttpb.readyState == 4){
		if(xmlhttpb.status == 200){
		xmloutput = xmlhttpb.responseXML;
		xmlRoot = xmloutput.documentElement;
		window.clearTimeout( toolong );
		
		if(!xmloutput || !xmlRoot){
		alert('check XML structure');
		}
		
		entryArray = xmlRoot.getElementsByTagName('entry');
		dateArray = xmlRoot.getElementsByTagName('date');
		fromArray = xmlRoot.getElementsByTagName('from')
		textArray = xmlRoot.getElementsByTagName('text');
		photoArray = xmlRoot.getElementsByTagName('photo');
		captionArray = xmlRoot.getElementsByTagName('caption');

		var cid1 = parseInt(document.getElementById('cid').value) + parseInt(entryArray.length);
		document.getElementById('cid').setAttribute('value', cid1 );	
	
		for(var i = 0; i < entryArray.length; i++){
			if(fromArray[i]){
				row1 = document.getElementById('thr').insertRow(0);
				row2 = document.getElementById('thr').insertRow(1);
				date1 = dateArray[i].firstChild.data;
				text = textArray[i].firstChild.data;
				cell11 = row1.insertCell(0);
				cell11.style.backgroundColor='#F6F6F6';
				cell21 = row1.insertCell(1);
				cell21.style.backgroundColor='#F6F6F6';
				cell12 = row2.insertCell(0);
				cell12.colSpan = '2';
				cell12.style.textAlign='left';
				cell11.style.verticalAlign ='top';
				cell21.style.verticalAlign = 'top';
				cell21.innerHTML = date1 + '&nbsp; EAT';

				from = fromArray[i].firstChild.data;
				from1 = '<img src="images/quote.gif" />';
				from = '<a href="directory.php?id='+ from +'" title="Click to see '+ from +'\'s profile" >'+ from + '</a>';
				cell11.innerHTML = from1 +' <b>'+ from +'</b>';
				t = document.createElement('table');
				t.style.width='100%';
				r = t.insertRow(0);
				c = r.insertCell(0);
				c.style.textAlign='left';
				cell12.appendChild(t);

				picDiv = document.createElement('div');
				picDiv.setAttribute('style', 'float:right;');
				picDiv.style.right='0'; 
				picDiv.style.marginTop='0'; 
				picDiv.style.marginRight='0'; 
				picDiv.style.marginBottom='5px'; 
				picDiv.style.marginLeft='5px';
				picDiv.style.width='310px';
				pd = document.createElement('div');
				pd.setAttribute('align', 'center');
				picDiv.appendChild(pd);


				if(photoArray[i]){
					photo = photoArray[i].firstChild.data;
					photo='<img src="phpThumb.php?src=/photos/blog/'+ photo 
					+'&amp;w=300&amp;h=300" style="border:1px solid #CCCCCC"/>';
					pd.innerHTML = photo;
					c.appendChild(picDiv);
					if(captionArray[i]){
						capDiv = document.createElement('div');
						picDiv.appendChild(capDiv);
						capDiv.style.textAlign='center';
						caption = captionArray[i].firstChild.data;
						capDiv.innerHTML =  caption;
					}
				}
				sp = document.createElement('span');
				sp.style.fontSize='1.2em';
				sp.innerHTML = text;
				c.appendChild(sp);
				h = document.createElement('hr');
				h.style.verticalAlign='bottom'; 
				h.style.clear='both';
				c.appendChild(h);

			}
		
		}
		document.getElementById('upload').innerHTML = ' ';
		}
	}else{
		document.getElementById('upload').innerHTML = '<font color=gray>Fetching ...</font>';
		}
}
