var loaded = false;
function trapint(form_name,formField) {
	frm = document.forms[form_name];
	var field = frm.elements[formField];
	if (field.value.length == 0) {
		if (event.keyCode==45 || (event.keyCode>46 && event.keyCode<58)) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	} else {
		if (event.keyCode>46 && event.keyCode<58) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	}
}
function trapintmax(event,field,max_pages,this_page){
	if(!document.all){
		thisEvent=event.which;
		if(thisEvent==0){
			return false;
		}
		if(thisEvent==8){
			return false;
		}
		if (thisEvent==46) {
			return false;
		}
	}else{
		thisEvent=event.keyCode;
	}

	if (field.value.length == 0) {
		if (thisEvent==45 || (thisEvent>46 && thisEvent<58)) {

		} else {
			event.returnValue = false;
			if(event.preventDefault){
				event.preventDefault();
				event.stopPropagation();
			}
			return false;
		}
	} else {
		if (thisEvent>46 && thisEvent<58) {

		} else {
			event.returnValue = false;
			if(event.preventDefault){
				event.preventDefault();
				event.stopPropagation();
			}
			return false;
		}
	}

	var val = field.value;
    var charCode = (event.charCode) ? event.charCode : event.keyCode;
	var char = String.fromCharCode(charCode);
	var val = parseInt(val+char);
	var max = parseInt(max_pages);

	if (val>max){
		event.returnValue = false;
		if(event.preventDefault){
			event.preventDefault();
			event.stopPropagation();
		}
		alert('There are only '+max_pages+' pages!');
		field.value = '';
		return false;
	}else{
		return true;
	}
}
function trapmax(field,max_pages){
	var val = parseInt(field.value);
	var max = parseInt(max_pages);
	if (val>max){
		field.value = max_pages;
		alert('There are only '+max_pages+' pages!');
		return false;
	}else{
		return true;
	}
}
function trapfloat() {
	if (event.keyCode==13 || event.keyCode==8 || (event.keyCode>45 && event.keyCode<58)) {
		return true;
	} else {
		event.returnValue = false;
		return false;
	}
}
var str = "left=0,screenX=0,top=0,screenY=0";

if (window.screen) {
  var ah = 500;
  var aw = 650;
  str += ",height=" + ah;
  str += ",innerHeight=" + ah;
  str += ",width=" + aw;
  str += ",innerWidth=" + aw;
  str += ",scrollbars=yes";
  str += ",status=yes";
  str += ",resizable";
} else {
  str += ",resizable"; // so the user can resize the window manually
}

function launch(newURL, newName, newFeatures, orgName) {
	var PopWin = window.open(newURL, newName, newFeatures);
	if ((!PopWin) || (PopWin.opener == null)) {
		alert('Warning, a popup was blocked.  Please disable popup blocking for full functionality on this website.')
		PopWin.opener = window;
		PopWin.opener.name = orgName;
	}
	return PopWin;
}

function launchPop(url) {
	if (!window.myPop || window.myPop.closed) {
		myPop = launch(url, "Popchild", str, "PopParent");
		myPop.focus();
	} else {
		myPop.location.href = url;
		myPop.focus();
	}
}

function save_maybes(){
	opener.location.href='index.html?action=login&save_maybes=true';
	self.close();
}

function closer(){
	opener.focus();
	self.close();
}
function MakeArray(n) {
	this.length = n;
	for (var i = 1; i <= n; i++) {
		this[i] = 0;
	}
	return this;
}
function pickSelectedId(elId, elVal) {
	var el = window.opener.document.getElementById(elId);
	for (i = 0; i < el.options.length; i++) {
		if (elVal == el.options[i].value) {
			el.selectedIndex = i;
		}
	}
	window.opener.focus();
	self.close();
}
function pickSelected(form,formField,Index){
	var frm = window.opener.document.forms[form];
	var field = frm.elements[formField];
	field.selectedIndex = Index;
	window.opener.focus();
	self.close();
}
function qfRequireState(a,b,c) {
	var stateVal = b;
	stateObj = document.getElementById(c);
	if (stateObj.options.length < 2) {
		// selected country has no states
		return true;
	}
	if ('' == stateVal) {
		return false;
	}
	return true;
	
}
var loadedStates = new Array();
var stateObj;
var updateStateRunning = false;
function updateStates(stateId, countryId) {
	if (true == updateStateRunning) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',100);
		return;
	}
	if (false == window.loaded) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',10);
		return;
	}
	updateStateRunning = true;
	countryObj = document.getElementById(countryId);
	var selectedCountry = countryObj.options[countryObj.selectedIndex].value;
	stateObj = countryObj.form[stateId];
	var numOpts = stateObj.options.length;
	if (numOpts) {
		stateObj.options[0].selected = true;
		stateObj.options[0].innerHTML = 'Loading...';
		for (var i = numOpts; i > 0; i--) {
			stateObj.options[i] = null;
		}
	}
	if (loadedStates[selectedCountry]) {
		setStateOptions(selectedCountry);
	} else {
		var stateScript = document.body.appendChild(document.createElement('iframe'));
		stateScript.setAttribute('height', 0);
		stateScript.setAttribute('width', 0);
		stateScript.setAttribute('src', '/jsrpc.html?action=loadStates&countryCode='+selectedCountry+'&stateId='+stateId);
		stateScript.setAttribute('id', 'loadStates'+selectedCountry);
	}
}
function setStateOptions(selectedCountry) {
	var opt;
	var selected;
	if (loadedStates[selectedCountry]) {
		eval('selected = '+stateObj.id+';');
		for (var key in loadedStates[selectedCountry]) {
			opt = document.createElement('option');
			opt.setAttribute('value', key);
			if (key == selected) {
				opt.setAttribute('selected', true);
			}
			opt.innerHTML = loadedStates[selectedCountry][key];
			stateObj.appendChild(opt);
		}
		stateObj.options[0].innerHTML = 'Select State';
	} else {
		stateObj.options[0].innerHTML = 'No Known States for '+selectedCountry;
	}
	updateStateRunning = false;
	return false;
}
function show_calendar(id) {
	url = "/calendar.html?id=" + id;
	size = 190;
	win = window.open(url, 'calendar', 'innerHeight='+size+',width='+size+',status=no');
	win.moveTo((screen.width-size)/2, (screen.height-size)/2);
	return win;
}
function erase(p_item){
	frm = document.getElementById(p_item);
	frm.value='';
}
function strpos(haystack, needle) {
	nlen = needle.length;
	for (var i = 0; i < haystack.length; i++)
	if (haystack.substring(i, i+nlen) == needle) return i;
	return -1;
}
function checkEmail(element) {
	val = element.value;
	if (val.length) {
		fs = document.body.appendChild(document.createElement('iframe'));
		fs.setAttribute('height', 0);
		fs.setAttribute('width', 0);
		fs.setAttribute('src', '/jsrpc.html?action=checkEmail&email='+val+'&domid='+element.id);
		fs.setAttribute('id', 'checkEmail');
	}
}
function checkEmailNotifications(element){
	val = document.getElementById('qf_0_email_notification_id').value;
	fs = document.body.appendChild(document.createElement('iframe'));
	fs.setAttribute('height', 0);
	fs.setAttribute('width', 0);
	fs.setAttribute('src', '/jsrpc.html?action=checkEmailNotifications&email_notification_id='+val);
	fs.setAttribute('id', 'checkEmailNotifications');
}
function in_array(n, h) {
	for (var i=0; i<h.length; i++) { if (n == h[i]) { return true; } } return false;
}

	function photoPop(img_dir, photo, length, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/photograph.html?img_dir=" + img_dir + "&photo=" + photo + "&length=" + length;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 525;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) { popWindow.opener = self; }
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
	function screenPop(photo, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/popup.html?action=screen_grab&photo=" + photo;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 520;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) { popWindow.opener = self; }
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
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 updAddrNm(a,b,c) {
	if ((aa = document.getElementById(a)) && (bb = document.getElementById(b)) && (cc = document.getElementById(c))) aa.value=bb.value+' '+cc.value;
}
function alternateRows(tab, cls1, cls2) {
	rows = tab.getElementsByTagName('tr');
	for (j=0; j<rows.length; j++) {
		cells = rows[j].getElementsByTagName('td');
		for (k=0; k<cells.length; k++) {
			if (k%2 == 0) {
				cls = cls1;
			} else {
				cls = cls2;
			}
			cells[k].setAttribute('class', cls);
		}
	}
}	
function initPage() {
	if (bcn = document.getElementById('navLevel3')) { var hideNav3 = true; for (i=0; i<bcn.childNodes.length; i++) { if (bcn.childNodes[i].childNodes.length > 0) { hideNav3 = false; } } if (hideNav3) { bcn.style.display = 'none'; } } if (hrarh = document.getElementById('hrAboveResultsHeader')) { if (sechdr = document.getElementById('sectionHeader')) { if (sechdr.childNodes.length < 2 && !hideNav3) { hrarh.style.display = 'none'; } } }
	dbEnt = getElementsByClass('dbEntity');
	for (i=0; i<dbEnt.length; i++) {
		alternateRows(dbEnt[i], 'alt', '');
	}
	window.loaded=true;
	var waHeight = document.body.clientHeight-160;
	try{
		document.getElementById('workarea').style.minHeight = waHeight+"px";
	}catch(err){
	}
}


function perPage(value){
	if(document.location.search){
		document.location.href=document.location.href+'&per_page='+value;
	}else{
		document.location.href='?per_page='+value;
	}
}

function getElementsByClass(className) {
	var out = new Array();
	allElements = document.getElementsByTagName('*');
	j = 0;
	for (i=0; i<allElements.length; i++) {
		if (className == allElements[i].className) {
			out[j++] = allElements[i];
		}
	}
	return out;
}

function showAcres() {
	el = document.getElementById('categories');
	if(el.value == '4'){
		document.getElementById('area').style.display = 'none';
		document.getElementById('acres').style.display = 'block';
		document.getElementById('which').value = 'acres';
	}else{
		document.getElementById('area').style.display = 'block';
		document.getElementById('acres').style.display = 'none';
		document.getElementById('which').value = 'area';
	}
}

function submitForm() {
	document.getElementById('searchform').submit();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

