var l_object = new Object();
function checkDefaultValue(obj, val) {
	var value = obj.value;
	if(val == undefined){
		if(value == ''){
			obj.value = l_object.value;
		}
	}else{
		if(value == val){
			obj.value = '';
		}
		l_object.value = val;
	}

}

function printr(obj){
	var desc = '';
	var num = 0;
	for(var i in obj){
		desc += i +' = '+ obj[i] +"\r\n\r\n";
		if(!(++num%10)){
			alert(desc);
			desc = '';
		}
	}
}

function swapDisplay(id, type){
	var curdisplay = document.getElementById(type+id).style.display;
	if(curdisplay == 'none' || curdisplay == undefined || curdisplay == ''){
		switch(type){
			case 'thread':
				document.getElementById(type+id).style.display = 'block';
				document.getElementById('threadlabel'+id).innerHTML = 'Hide Sub-Comments';
				break;
			case 'reply':
				document.getElementById(type+id).style.display = 'block';
				break;
		}
	}else{
		switch(type){
			case 'thread':
				document.getElementById(type+id).style.display = 'none';
				document.getElementById('threadlabel'+id).innerHTML = 'Show Sub-Comments';
				break;
			case 'reply':
				document.getElementById(type+id).style.display = 'none';
				break;
		}
	}
}


///////////////////////////
// Live Search Functions //
///////////////////////////
var tDiff = 0;
var liveSearchClosed = false;
function liveSearch(ok){
		
	var searchString = $F('s');

	if(ok && searchString.length > 3 && searchString != 'Type for a Live Search' && !liveSearchClosed){
		
		var url = '/live_search.php';
		var pars = 's='+ searchString;

		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: showLiveSearch
			});
	}else{
		UpdateTimer(true);
		
		if(searchString != '' && searchString != 'Type for a Live Search'){
			$('liveSearchResults').style.display = 'block';
			$('liveSearchResults').innerHTML = 'Searching...';
		}else{
			$('liveSearchResults').style.display = 'none';
			$('liveSearchResults').innerHTML = '';
		}
	}
	
	liveSearchClosed = false;

}

function showLiveSearch(originalRequest){
	//put returned XML in the textarea
	$('liveSearchResults').style.display = 'block';
	$('liveSearchResults').innerHTML = originalRequest.responseText;
}

function closeLiveSearch(){
	$('liveSearchResults').style.display = 'none';
	$('liveSearchResults').innerHTML = '';
	StopTimer();
	liveSearchClosed = true;
}


var timerID = 0;
var tStart  = null;

function UpdateTimer(reset) {
	if(timerID) {
		clearTimeout(timerID);
		clockID  = 0;
	}
	if(!tStart || reset){
		tStart   = new Date();
	}
	var   tDate = new Date();
	var   tDiff = tDate.getTime() - tStart.getTime();

	tDate.setTime(tDiff);

	if(tDiff > 700){
		StopTimer();
		liveSearch(true);
	}else{
		timerID = setTimeout("UpdateTimer()", 150);
	}
}

function StopTimer() {
	if(timerID) {
		clearTimeout(timerID);
		timerID  = 0;
	}
	tStart = null;
}
/////////
// End //
/////////


function calendarHidePosts(){
	if(document.getElementById("calendarSearchResults")){
		$('calendarSearchResults').style.display = 'none';
		noupdate = false;
	}
}


/*
var popUpWin=0;
function popUpWindow(URLStr, width, height){
  if(popUpWin){
    if(!popUpWin.closed) popUpWin.close();
  }
	if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var left = (aw - width) / 2;
    var top = (ah - height) / 2;
  } else {
		var left = 100;
		var top = 100;
	}
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
*/
function openCenterWin(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}