function swap(obj, newsrc) {
	if(obj != null) {
		obj.src = newsrc;
	}
}

function preLoadImages(arr, prestr, poststr) {
	for(var i=0 ; i<arr.length ; i++) {
		img = new Image();
		img.src = prestr + arr[i] + poststr;
	}
}

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 getContentDiv() { return document.getElementById('contentTable'); }
function getMapDiv() { return document.getElementById('map'); }
function getDetailsDiv() { return document.getElementById('details'); }
function getMainDetailsDiv() { return document.getElementById('detailsMain'); }
function getPanoDiv() { return document.getElementById('pano'); }

function showFavs() {
	favsDiv = document.getElementById('favs');
	favsDiv.innerHTML = getFavsHTML(2);
	loadPopup("favsMain");
}

function hideAllDivs() {
	hideDiv(getMapDiv());
	hideDiv(getMainDetailsDiv());
	hideDiv(getPanoDiv());
}

function resetMap() {
	firstView=true;
	showMap();
}

var firstView = true;
var step1px = 1450;
var step2px = 1850;
function showMap() {
	hideAllDivs();
	tablediv = getContentDiv();
	mapdiv = getMapDiv();
	showDiv(mapdiv);
	if(firstView) {
		map.checkResize();
		firstView = false;
		
		var zoomLevel = 11;
		var size = map.getSize();
		
		if(size.width >= step1px && size.height >= step1px) zoomLevel = 11;
		if(size.width >= step2px && size.height >= step2px) zoomLevel = 12;
		
		map.setCenter(valleyCenter, zoomLevel);
	} else {
		map.checkResize();
	}
}

function hideMovieDiv() {
	hideDiv(document.getElementById("moviediv"));
	document.movie.pause();
}

function showMovieDiv() {
	showDiv(document.getElementById("moviediv"));
	document.movie.play();
}

function showMovieDivNoPlay() {
	showDiv(document.getElementById("moviediv"));
}

function showPano() {
	hideAllDivs();
	showDiv(getPanoDiv());
}

function hideDiv(div) {
	if(div != null) {
		div.style.visibility = 'hidden';
		div.style.display = 'none';
	}
}

function showDiv(div) {
	if(div != null) {
		div.style.visibility = 'visible';
		div.style.display = 'block';
	}
}

function isDivShowing(div) {
	return div.style.visibility == 'visible';
}

function clearDetailsDiv() {
	clearDiv(getDetailsDiv());
}

function clearDiv(div) {
	if(div != null) {
		div.innerHTML = "";
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function quickRound(number, dec) {
	t = Math.pow(10, dec);
	return (Math.round(number*t)/t);
}

function mysqlunescape(str) {
	return str.replace(/\\/g, "");
}

function logopenlink(vlink) {
	makeRequest("forward.php", "?l="+vlink, donothing);
	window.open(vlink, "out", "");
}

function loglink(vlink) {
	makeRequest("forward.php", "?l="+vlink, donothing);
}

function now() {
	var now = new Date();
	return now.getTime();
}

function donothing() { }

function confirmAllRanges() {
	confirmRange(document.searchForm.priceMin, document.searchForm.priceMax, priceOpts);
}

function confirmRange(minVal, maxVal, opts) {
	if(minVal == null || maxVal == null) return false;
	
	if(parseFloat(minVal.value) > parseFloat(maxVal.value)) {
		maxVal.selectedIndex = minVal.selectedIndex;
		return false;
	} else {
		return true;
	}
}

function fillInVals() {

}

function fillInValsFor(box, opts) {
	if(box == null) {
		alert('The box does not exist.');
		return;
	}
	var bOpts = box.options;
	if(bOpts != null) {
		bOpts.size = 0;
		for(var i=0 ; i<opts.length ; i++) {
			bOpts[i] = new Option(opts[i].text, opts[i].value);
		}
	} else {
		alert('There are no options for this.');
	}
}

function strip_tags(str) {
   return str.replace(/&lt;\/?[^&gt;]+&gt;/gi, "");
}

if (!Array.prototype.contains){
	Array.prototype.contains = function(obj){
		var len = this.length;
		for (var i=0 ; i<len ; i++)
			if(this[i] == obj) return true;
		return false;
	};
}

if (!Array.prototype.getCSV){
	Array.prototype.getCSV = function(){
		var len = this.length;
		var csv = "";
		for (var i=0 ; i<len ; i++) {
			if(this[i] != null && this[i] != "")
				csv += this[i]+",";
		}
			
		return csv.substr(0,csv.length-1);
	};
}

function contains(arr, val) {
	if(arr == null)
		return false;
		
	for(var i=0 ; i<arr.length ; i++) {
		if(arr[i] == val) {
			return true;
		}
	}
	
	return false;
}

function maximize() {
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);	
}

function underline(obj, on) {
	if(on==1 && obj)
		obj.style.textDecoration="underline";
	if(on==0 && obj)
		obj.style.textDecoration="none";
}

function setSelectedIndex(cbx, ind) {
	if(ind != null && cbx != null && cbx.options != null && ind >= 0 && ind < cbx.options.length) {
		cbx.options[ind].selected = true;
	}
}

function showLoading() {
	document.body.style.overflow = 'hidden';
	justShowOverlay();
	$('loading').style.top = getScroll() + (document.body.clientHeight/2) - 100;
	$('loading').show();
}
function hideLoading() {
	$('loading').hide();
	$('overlay').hide();
	document.body.style.overflow = '';
}
