function slideElement(handle)
{
	$('.slidingElement').slideUp("slow");
	if ($(handle).next("div[@class^='slidingElement']").is(":hidden")) {
		$(handle).next("div[@class^='slidingElement']").slideDown("slow");
	} else {
		$(handle).next("div[@class^='slidingElement']").slideUp("slow");
	}
}

function noError(){return true;} 
//window.onerror = noError;



// centered popup window
function f_popup(Url,PopupName,dl_width,dl_height,scrollbars,resizable){if(!scrollbars){scrollbars='no';}else{scrollbars='yes';}if(!resizable){resizable='no';}else{resizable='yes';}var x=Math.round((screen.availWidth-dl_width)/2);var y=Math.round((screen.availHeight-dl_height)/2);newwin = window.open(Url,PopupName,"left="+x+",top="+y+", scrollbars="+scrollbars+",resizable="+resizable+",width="+dl_width+",height="+dl_height+",menubar=no");return false;}

function image_viewer(rec_id, img_id)
{
	f_popup('/img-browser.php?rec_id='+rec_id+'&img_id='+img_id, 'imgb' + rec_id, 700,500, true, true);
	return false;
}

// checkbox - check/uncheck all
function checkbox_check_uncheck_all(box,obj){var f=box.form.name;var o=document.forms[f].elements[obj];var b=document.forms[f].elements[box.name];if(b.value==1){var c=true;b.value=0;}else{var c=false;b.value=1;}b.checked=c;if(typeof o!='undefined'){for (var i=0;i<o.length;i++){o[i].checked=c;}}}

// radio - get checked value
function getCheckedValue(o) {
	if(!o) return "";
	var rl = o.length;
	if(rl == undefined)
	if(o.checked)
		return o.value;
	else
		return "";
	for(var i = 0; i < rl; i++) {
		if(o[i].checked) {return o[i].value;}
	}
	return "";
}




function sh(obj)
{
	if(typeof(obj) != 'object') obj = document.getElementById(obj);
	if(typeof(obj) != 'object') return false;
	obj.style.display = obj.style.display == '' ? 'none' : '';
}


function browser_showhide(obj,lyr, url)
{
	var x = new getObj(lyr);
	vis = x.style.visibility;
	if(vis == 'visible') 
	{
		x.style.visibility = 'hidden';
		frames['frmCatBrowser'].location.href = 'about:blank';
	}
	else 
	{
		x.style.visibility = 'visible';
		setLyr(obj,lyr);
		frames['frmCatBrowser'].location.href = url;
	}
}

function browser_hide(lyr)
{
	var x = new getObj(lyr);
	x.style.visibility = 'hidden';
}


function setLyr(obj,lyr)
{
	var wx = document.documentElement.offsetWidth;
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var maxX = document.documentElement.offsetWidth - 500;
	newX = newX > maxX ? maxX : newX;
	var x = new getObj(lyr);
	
	x.style.top = newY + 15 + 'px';
	x.style.left = newX + 'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent){while (obj.offsetParent){curleft += obj.offsetLeft;obj=obj.offsetParent;}}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
 }
}



function trim(s) {
  return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


//---------------
function Pager(how) {
	if (how == 'next') {
	var a = document.frm.pos.options.length; var curr = -1;
	for (ii=0; ii<a; ii++) if (document.frm.pos.options[ii].selected) curr = ii;	
	if ((a - curr) > 1) { 
		 document.frm.pos.options[curr+1].selected = true;
		 document.frm.submit();
	} else { alert("No more pages available."); }
	}

	if (how == 'rnd') { document.frm.submit();	}}

	function openMap() {
	var map = window.open("map.php", "_map", "height=627, width=981, scrollbars=0, toolbar=0, resize=0");
	map.focus();
	}
	
	function help(wha) {
	var win = window.open("help.php?wha=" + wha, "_blank", "height=300, width=200, scrollbars=0, resize=0");
	win.focus();
	}

  function evalSearchForm() {
	var okay = true;
	var sel = false;
	
	var tid = document.getElementById('search_tid');
	var amid = document.getElementById('search_amid');
	var lid = document.getElementById('search_lid');
	
	if (tid.options[tid.selectedIndex].value != "all") sel = true;
	if (lid.options[lid.selectedIndex].value != "all") sel = true;
	if (amid.options[amid.selectedIndex].value != "all") sel = true;
	
	if (lid.options[lid.selectedIndex].value == "all" && document.search.nearby.checked == true) okay = false;
	if (document.search.budget.value == "") document.search.budget.value = "no";
	
	if (!okay) { alert("Please specify a location or uncheck 'surrounding areas'"); 
		} else {
	if (sel) { document.search.submit(); } else alert("Please choose at least one option...")
	}
  }	


function qSearch() {
	location.href = '/index.php?op=2&search=' + document.frm.qsearch.value;
}
