var format = "xml";

var asxmlhttp = function()
{
	this.getXMLHttpRequest = function()
	{
		try
		{
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				return new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					return new XMLHttpRequest();
				}
				catch (e)
				{
					top.document.location.href = "/";
				}
			}
		}

		return null;
	}

	this.go = function(callerObj, actionURL, sendmethod, datatosend)
	{
	    datatosend = datatosend + "&___t___=" + (new Date()).getTime();
		try
		{
			var xmlhttp = this.getXMLHttpRequest();

			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					callerObj.doready(xmlhttp);
				}
			}

			if (sendmethod.toUpperCase() == "POST")
			{
				xmlhttp.open("POST", actionURL, true); // false = wait // true = don't wait
				xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			}
			else
			{
				xmlhttp.open("GET", actionURL, true); // false = wait // true = don't wait
			}

			xmlhttp.send(datatosend);
			return true;
		}
		catch (e)
		{
			return false;
		}
	}
}


var Updater = function()
{
	var action = "";

	this.trim = function(s)
	{
		if (s.length>0)
		{
			while ((s.charAt(0) == ' ') || (s.charAt(0) == '\n') || (s.charAt(0) == '\r') || (s.charAt(0) == '\t'))
			{
				s = s.substring(1);
			}

			while ((s.charAt(s.length-1) == ' ') || (s.charAt(s.length-1) == '\n') || (s.charAt(s.length-1) == '\r') || (s.charAt(s.length-1) == '\t'))
			{
				s = s.substring(0,s.length-1);
			}
		}
		return s;
	}
	
	this.type_of = function (obj)
	{
		var t = typeof(obj);
		return t.toUpperCase();
	}
	
	this.get_real_id = function (obj_or_id)
	{
		var t = this.type_of(obj_or_id);
		var id = '';
		var default_id = 'server_message';

		if (t == 'STRING' && obj_or_id.length > 0 && document.getElementById(obj_or_id))
		{
			id = obj_or_id;
		}
		else if (t == 'STRING' && obj_or_id == 'lightbox')
		{
			id = 'lightbox';
		}
		else if (((t == 'STRING' && obj_or_id.length == 0) || (!obj_or_id) || obj_or_id=='') && document.getElementById(default_id))
		{
			id = default_id;
		}
		else if (t=='OBJECT' && obj_or_id)
		{
			id = obj_or_id.getAttribute('id');
			if (id != 'UNDEFINED' && this.type_of(id) == 'STRING')
			{
				;
			}
			else
			{
				var p = '';
				sChrs = 'abcdefghijklmnopqrstuvwxyz_';
				id = '';
				for (var i=0; i< 10; i++)
				{
					p = Math.floor(Math.random() * sChrs.length);
					id += sChrs.substring(p, p+1);
				}
				
				obj_or_id.setAttribute('id', id);
			}
		}
		else
		{
			id = default_id;
		}

		return id;
	}
	
	this.send = function(obj, receiver_element_id)
	{
		
		receiver_element_id = this.get_real_id(receiver_element_id);

		var postdata = "using_ajax=1&receiver_element_id=" + escape(receiver_element_id);
		var postdatalink = "using_ajax-1-receiver_element_id-" + escape(receiver_element_id);
		var sendmethod = '';
		var urltosendto = '';

		try
	    {
			if (this.type_of(obj) == 'STRING')
			{
				urltosendto = obj;
				sendmethod = 'get';
			}
			else if (obj.method)
			{
				sendmethod = obj.method;

				if (obj.getAttribute('action') != '')
				{
					urltosendto = obj.action;
				}
				else
				{
					urltosendto = document.location.href;
				}

				for (i = 0; i<obj.length; i++)
				{
					var v = obj[i];
					postdata += "&"+v.name+"=" + escape(v.value);
				}
			}
			else if (obj.getAttribute('href') != '')
			{
				sendmethod = 'get';
				urltosendto = obj.getAttribute('href');
			}
			
			urltosendto = urltosendto.replace('.html', '-' + postdatalink + '.html');
			
			return !httpupdater.go(this, urltosendto, sendmethod, postdata);
	    }
	    catch (e)
	    {
	        return true;
	    }
	}
	
	
	this.doready = function(xmlhttpresponse)
	{
	    try
	    {
	        eval(xmlhttpresponse.responseText);
	    }
	    catch (e)
	    {
	        ;//alert(e);
	        //alert(xmlhttpresponse.responseText);
	    }
	    
	    return;
	    
	    
		try
		{
			if (format == "js")
			{
				eval(xmlhttpresponse.responseText);
			}
			else
			{
				var xmlDoc= xmlhttpresponse.responseXML;
				var xlist = xmlDoc.getElementsByTagName("list");

				for (var i=0; i < xlist.length; i++)
				{
					var action = getXMLElement(xlist[i], 'action');
					
					if (action == "abc")
					{
						var xuser = xlist[i].getElementsByTagName('user')[0];
						var userid = xuser.getElementsByTagName('id')[0].firstChild.nodeValue;
						var ssessionid = xuser.getElementsByTagName('sessionid')[0].firstChild.nodeValue;
						var sname = xuser.getElementsByTagName('name')[0].firstChild.nodeValue;
						var stime = xuser.getElementsByTagName('time')[0].firstChild.nodeValue;
					}
					else if (action == "ab")
					{
						var scode = getXMLElement(xlist[i], 'code');
						document.getElementById("ab").innerHTML = scode;
					}
				}
			}
		}
		catch (e)
		{
			;//alert(e);
		}
	}
	
	this.lightbox = function(stitle, scontent, surl)
	{
		if (!stitle) stitle = '';
		if (!scontent) scontent = '';
		if (!surl) surl = '';
		
		if (surl != '')
		{
			return this.send(surl, 'lightbox');
		}

		var b = '';
	
		b += '<div style="position:absolute; top:0px; left:0px; z-index: 100000;">';
		b += '    <div style="height:100%; width:100%; position: fixed; z-index:10000000; opacity:0.7; filter:alpha(opacity=70); background-color:#000000;" align="center"></div>';
			
		b += '    <div style="height:100%; width:100%; position: fixed; z-index:10000000; vertical-align:bottom; padding-top:100px;" align="center" onclick="if (!lightbox_is_inside_click || lightbox_is_close) {document.body.removeChild(this.parentNode.parentNode);} lightbox_is_inside_click = false; lightbox_is_close = false;">';

		b += '<div style="background-image: url(/templates_v2/images/lightboxtop.png); height: 16px; width: 541px;"></div>';
		b += '       <div style="width:509px; padding:16px; padding-top: 0px; padding-bottom: 0px; background-image: url(/templates_v2/images/lightbox_middle.png);" align="left" onclick="lightbox_is_inside_click = true;">';
		//b += '            <div style="height: 12px; padding: 5px;" align="left">'+stitle+'</div>';
		b += '            <div style="min-height:200px;" align="left">';
		b += scontent;
		b += '			</div>';
		b += '        </div>';
		b += '<div style="background-image: url(/templates_v2/images/lightboxbottom.png); height: 16px; width: 541px;"></div>';
		
		b += '    </div>';
		b += '</div>';

		var newElm = document.createElement('DIV');
		newElm.innerHTML = b;
		
		document.body.insertBefore(newElm, document.body.childNodes[0])
	}
}

function getXMLElement(xmlobj, tagname)
{
	try
	{
		return xmlobj.getElementsByTagName(tagname)[0].firstChild.nodeValue;
	}
	catch(e)
	{
		return "";
	}
}
/*
function getvalue(list_of_values, variablename)
{
	var ret = "";
	try
	{
		var agt = browser.getUserAgent();
		
		if (((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)))
		{
			ret = list_of_values.getElementsByTagName(variablename)[0].textContent;
		}
		else if (browser.isIE()) // IE
		{
			ret = list_of_values.getElementsByTagName(variablename)[0].text;
		}
		else
		{
			ret = list_of_values.getElementsByTagName(variablename)[0].firstChild.nodeValue;
		}
	}
	catch(e)
	{
		;
	}
	
	return ret;
}
*/


var lightbox_is_inside_click = false;
var lightbox_is_close = false;



var httpupdater = new asxmlhttp();

var ajx = new Updater();


function random_online_images()
{
	var imgs = document.getElementsByTagName('IMG');

	for( var i = 0; i < imgs.length; i++)
	{
		if (imgs[i].src.indexOf('images/online.gif') > -1)
		{
			randomnumber = 1 + Math.floor(Math.random() * 3);
			imgs[i].src='/images/images/online'+randomnumber+'.gif';
		}
	}

}

function openwebcampop(link)
{
	window.open('webcam_pop.html?url='+link, 'showwindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=850,height=700');
}

