function refresh(link)
{
	if(link == null || link == '') location = location;
	else location = link;
}

function dateTime(id) 
{
	/*var now = new Date();*/
	now.setSeconds(now.getSeconds()+1);

	var time = '';
	time += (now.getHours() < 10 ? '0' : '') + now.getHours() + ':';
	time += (now.getMinutes()<10 ? '0' : '') + now.getMinutes()+':';
	time += (now.getSeconds()<10 ? '0' : '') + now.getSeconds();
   
	var date = ' ' + now.getYear(); 
	date  = '200' + date.substr(date.length-1) + '-'; 
	date += ((now.getMonth()+1)<10 ? '0' : '') + (now.getMonth()+1) + '-';
	date += (now.getDate() <10 ? '0' : '') + now.getDate();
	
	var day = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	
	document.getElementById(id).innerHTML = date + ' | ' + time + ' | ' + day[now.getDay()];
	setTimeout("dateTime('"+id+"')", 1000);
}

function updateTime() 
{
	now.setSeconds(now.getSeconds()+1);

	var time = '';
	time += (now.getHours() < 10 ? '0' : '') + now.getHours() + ':';
	time += (now.getMinutes()<10 ? '0' : '') + now.getMinutes()+':';
	time += (now.getSeconds()<10 ? '0' : '') + now.getSeconds();
   
	var date = '';
	date += now.getFullYear() + '-'; 
	date += ((now.getMonth()+1)<10 ? '0' : '') + (now.getMonth()+1) + '-';
	date += (now.getDate() <10 ? '0' : '') + now.getDate();

	var day = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

	$('#date').html(date);
	$('#time').html(time);
	$('#day').html(day[now.getDay()]);
}

function selectAll(name,state)
{
	for(var n=0;n<document.forms.length;n++)
	{
		for(var i=0;i<document.forms[n].elements.length;i++)
		{
			if(document.forms[n].elements[i].name == name) document.forms[n].elements[i].checked = state;
		}
	}
}

function parse(str)
{
	while(str.indexOf('[B]')>=0 && str.indexOf('[/B]')>=0) {str = str.replace('[B]','<b>'); str = str.replace('[/B]','</b>');}
	while(str.indexOf('[I]')>=0 && str.indexOf('[/I]')>=0) {str = str.replace('[I]','<i>'); str = str.replace('[/I]','</i>');}
	while(str.indexOf('[U]')>=0 && str.indexOf('[/U]')>=0) {str = str.replace('[U]','<u>'); str = str.replace('[/U]','</u>');}
	while(str.indexOf('[C]')>=0 && str.indexOf('[/C]')>=0) {str = str.replace('[C]','<center>'); str = str.replace('[/C]','</center>');}

	while(str.indexOf('[b]')>=0 && str.indexOf('[/b]')>=0) {str = str.replace('[b]','<b>'); str = str.replace('[/b]','</b>');}
	while(str.indexOf('[b]')>=0 && str.indexOf('[/b]')>=0) {str = str.replace('[b]','<i>'); str = str.replace('[/b]','</i>');}
	while(str.indexOf('[b]')>=0 && str.indexOf('[/b]')>=0) {str = str.replace('[b]','<u>'); str = str.replace('[/b]','</u>');}
	while(str.indexOf('[b]')>=0 && str.indexOf('[/b]')>=0) {str = str.replace('[b]','<center>'); str = str.replace('[/b]','</center>');}

	while(str.indexOf('[IMG]')>=0 && str.indexOf('[/IMG]')>=0) {start = str.indexOf('[IMG]')+5; end = str.indexOf('[/IMG]'); src = str.substring(start,end); str = str.substr(0,start-5)+'<img src = \''+src+'\' />'+str.substr(end+6);}
	while(str.indexOf('[URL]')>=0 && str.indexOf('[/URL]')>=0) {start = str.indexOf('[URL]')+5; end = str.indexOf('[/URL]'); src = str.substring(start,end); str = str.substr(0,start-5)+'<a href = \''+src+'\' target = \'_blank\'>'+src+'</a>'+str.substr(end+6);}
	while(str.indexOf('[URL')>=0 && str.indexOf('[/URL]')>=0) {tmp = str.substr(str.indexOf('[URL')); href = tmp.substring(4,tmp.indexOf(']')); str = str.replace('[URL'+href+']','<a href = \''+href+'\'>'); str = str.replace('[/URL]','</a>');}
	while(str.indexOf('[Quote')>=0 && str.indexOf('[/Quote]')>=0) {tmp = str.substr(str.indexOf('[Quote')); auth = tmp.substring(6,tmp.indexOf(']')); str = str.replace('[Quote'+auth+']','<div class = \'quote\'><span class = \'legend\'>Quote '+auth+':</span><blockquote><p>'); str = str.replace('[/Quote]','</p></blockquote></div>');}
	while(str.indexOf('[Red]')>=0 && str.indexOf('[/Red]')>=0) {str = str.replace('[Red]','<b style = \'color: #FF0000;\'>'); str = str.replace('[/Red]','</b>');}
	while(str.indexOf('[Green]')>=0 && str.indexOf('[/Green]')>=0) {str = str.replace('[Green]','<b style = \'color: #00FF00;\'>'); str = str.replace('[/Green]','</b>');}
	while(str.indexOf('[Blue]')>=0 && str.indexOf('[/Blue]')>=0) {str = str.replace('[Blue]','<b style = \'color: #0000FF;\'>'); str = str.replace('[/Blue]','</b>');}
	while(str.indexOf('[RGB')>=0 && str.indexOf('[/RGB]')>=0) {tmp = str.substr(str.indexOf('[RGB')); clr = tmp.substring(4,tmp.indexOf(']')); str = str.replace('[RGB'+clr+']','<b style = \'color: '+clr+';\'>'); str = str.replace('[/RGB]','</b>');}

	while(str.indexOf('[img]')>=0 && str.indexOf('[/img]')>=0) {start = str.indexOf('[img]')+5; end = str.indexOf('[/img]'); src = str.substring(start,end); str = str.substr(0,start-5)+'<img src = \''+src+'\' />'+str.substr(end+6);}
	while(str.indexOf('[url]')>=0 && str.indexOf('[/url]')>=0) {start = str.indexOf('[url]')+5; end = str.indexOf('[/url]'); src = str.substring(start,end); str = str.substr(0,start-5)+'<a href = \''+src+'\' target = \'_blank\'>'+src+'</a>'+str.substr(end+6);}
	while(str.indexOf('[url')>=0 && str.indexOf('[/url]')>=0) {tmp = str.substr(str.indexOf('[url')); href = tmp.substring(4,tmp.indexOf(']')); str = str.replace('[url'+href+']','<a href = \''+href+'\'>'); str = str.replace('[/url]','</a>');}
	while(str.indexOf('[quote')>=0 && str.indexOf('[/quote]')>=0) {tmp = str.substr(str.indexOf('[quote')); auth = tmp.substring(6,tmp.indexOf(']')); str = str.replace('[quote'+auth+']','<div class = \'quote\'><span class = \'legend\'>Quote '+auth+':</span><blockquote><p>'); str = str.replace('[/quote]','</p></blockquote></div>');}
	while(str.indexOf('[red]')>=0 && str.indexOf('[/red]')>=0) {str = str.replace('[red]','<b style = \'color: #FF0000;\'>'); str = str.replace('[/red]','</b>');}
	while(str.indexOf('[green]')>=0 && str.indexOf('[/green]')>=0) {str = str.replace('[green]','<b style = \'color: #00FF00;\'>'); str = str.replace('[/green]','</b>');}
	while(str.indexOf('[blue]')>=0 && str.indexOf('[/blue]')>=0) {str = str.replace('[blue]','<b style = \'color: #0000FF;\'>'); str = str.replace('[/blue]','</b>');}
	while(str.indexOf('[rgb')>=0 && str.indexOf('[/rgb]')>=0) {tmp = str.substr(str.indexOf('[rgb')); clr = tmp.substring(4,tmp.indexOf(']')); str = str.replace('[rgb'+clr+']','<b style = \'color: '+clr+';\'>'); str = str.replace('[/rgb]','</b>');}

	while(str.indexOf("\n")>=0) str = str.replace("\n",'<br />');

	return str;
}

function popup(text,w,h)
{
	//var str = parse(text);	
	var str = text;
	Pre = window.open('','Popup','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+'');
	Pre.window.document.write('<html><head><title>Popup</title><link id = \'theme\' href = \''+document.getElementById('theme').href+'\' rel = \'stylesheet\' type = \'text/css\' /></head><body><div><div id = \'preview\'>\n<!-- Start -->\n'+str+'\n<!-- End -->\n</div></div></body></html>');
	Pre.document.close();
	
	/*var str = escape(text);
	var theme = escape(document.getElementById('theme').href);
	Pre = window.open('query.php?query=popup&text='+str+'&theme='+theme,'Popup','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+'');*/
}

function preview_field(field,w,h,emoticons,type)
{	
	//var str = sparse(field.value,emoticons);
	var str = field.value;
	var opt = "text="+escape(str)+"&emoticons="+emoticons;
	
	Pre = window.open('','Preview','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+'');
	Pre.window.document.write('<html><head><title>Preview</title><link id = \'theme\' href = \''+document.getElementById('theme').href+'\' rel = \'stylesheet\' type = \'text/css\' /></head><body><div></div><div id = \'preview\'>\n<!-- Start -->\n<p id = \'loading\'></p>\n<!-- End -->\n</div></div></body></html>');
	Pre.document.close();
	
	$.ajax
	({
		url: 		'query.php?query='+type,
		data: 		opt,
		type: 		'POST',
		success: 	function(data) 
		{
			str = data;
			Pre.window.document.write('<html><head><title>Preview</title><link id = \'theme\' href = \''+document.getElementById('theme').href+'\' rel = \'stylesheet\' type = \'text/css\' /></head><body><div><div id = \'preview\'>\n<!-- Start -->\n'+str+'\n<!-- End -->\n</div></div></body></html>');
			Pre.document.close();
		}
	});

	/*var str = escape(field.value);
	var theme = escape(document.getElementById('theme').href);
	Pre = window.open('query.php?query=preview&text='+str+'&theme='+theme+'&emoticons='+emoticons,'Preview','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+'');*/
}

/*
function initSlide(name, id, shiftBy, interval)
{
    this.name = name;
    this.id = id;
    this.shiftBy = shiftBy ? shiftBy : 1;
    this.interval = interval ? interval : 0;
    this.runId	= null;
    this.div = document.getElementById(id);
    var node = this.div.firstChild;
    var next;
    while(node) 
    {
        next = node.nextSibling;
        if(node.nodeType == 3) this.div.removeChild(node);
        node = next;
    }
    this.left = 0;
    this.shiftLeftAt = this.div.firstChild.offsetWidth;
    this.div.style.height = this.div.firstChild.offsetHeight;
    this.div.style.width = 2 * screen.availWidth;
}

function startSlide()
{
    this.stop();
    this.left -= this.shiftBy;
    if(this.left <= -this.shiftLeftAt)
    {
        this.left = 250;
        this.div.appendChild(this.div.firstChild);
        this.shiftLeftAt = this.div.firstChild.offsetWidth;
    }
    this.div.style.left = (this.left + 'px');
    this.runId = setTimeout(this.name + '.start()', this.interval);
}

function stopSlide()
{
    if (this.runId) clearTimeout(this.runId);
    this.runId = null;
}

initSlide.prototype.start = startSlide;
initSlide.prototype.stop = stopSlide;
*/