/* Change Visibility of an element */
function changeVis(vID){
	oVis = document.getElementById(vID);
	if (oVis.style.visibility=="hidden"){
		oVis.style.visibility="visible";
		oVis.style.display = "";
	} else {
		oVis.style.visibility="hidden";
		oVis.style.display="none";
	}
}
function switchReveal(obj1, obj2, val){
	elm1 = (obj1.className.indexOf('hidden') == -1) ? obj1 : obj2;
	elm2 = (obj1.className.indexOf('hidden') == -1) ? obj2 : obj1;
	val = (!val) ? 1 : val;
	elm1.setStyle('overflow','hidden');
	elm1.set('tween', { duration:1500,transition:'expo:out', onComplete: function(e){
		e.addClass('hidden');
		elm2.set('tween', { duration:1500,transition:'expo:out', onComplete: function(e){
			//Do Nothing
		}});
		elm2.setStyle('height', 0);
		elm2.removeClass('hidden');
		val = (parseInt(val) == 1 && parseInt(elm2.restoreHeight) > 0) ? parseInt(elm2.restoreHeight) : parseInt(val);
		elm2.tween('height',val);
	}});
	if(!elm1.restoreHeight){
		elm1.restoreHeight = elm1.offsetHeight;
	}
	elm1.tween('height',0);
}

function fLoc(vID,vX,vY){
	getFlashMovieObject('Neighbourhood').fGoZoom(vX,vY,100);
	
}
function fSetMenuStyle(vID, vStyle, vSetStyle){
		if(document.getElementById(vID) != null){
			document.getElementById(vID).style[vStyle] = vSetStyle;
		}
}
function pageTop(vLink) {
	window.location.href="#"+vLink;
}
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function checkdelitem(vUrl){
	fRet = confirm("Are you sure you wish to delete this? It is often better to hide an item or set it's date to some time in the past rather than completely delete it."); 
	if(fRet == 1){
		location.replace(vUrl);
	}	
}

/* Swap an image from it's name */
function swapImage(vImage, vFile){
	document.images[vImage].src=vFile;
}

function checkNewDrop(vDD, vOB){
	vDDVal = document.getElementById(vDD).options[document.getElementById(vDD).selectedIndex].value;
	vOBVis = document.getElementById(vOB).style.visibility;
	if( (vDDVal == 'n3w' && vOBVis == "hidden") || (vDDVal != 'n3w' && vOBVis == "visible") ){
		changeVis(vOB);
	}
}

/* Preload any images */
function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=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];}}
}

/* Change Background Color */
function bgChange(menuID, col){
	if(document.getElementById){
		if( document.getElementById(menuID) ){
			document.getElementById(menuID).style.backgroundColor = col;
		}
	} else if(document.all){
		if(document.all(menuID)){
			document.all(menuID).style.backgroundColor = col;
		}
	} 
}

sfHover = function(){
 var sfEls = document.getElementById('menusan').getElementsByTagName("li");
 for (var j=0;j<sfEls.length;j++){
  sfEls[j].onmouseover=function(){
   this.className += " sfhover";
  }
  sfEls[j].onmouseout=function(){
   this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
  }
 } 
}

if (window.attachEvent){ window.attachEvent("onload", sfHover); }

/* Create a popup */
function fPopUp(vURL, vW, vH){
	vDay = new Date();
	vId = vDay.getTime();
	eval("page" + vId + " = window.open(vURL, '" + vId + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+vW+",height="+vH+"');");
}
/* Create a popup */
function popup(n){
	window.open( n , 'popup', 'width=934,height=680,scrollbars=yes,toolbar=no,location=no;directories=no,status=no,resizable=yes,');
	return 1;
}

/* Check action before carrying out */
function fCheckAct(vMessage, vUrl){
	vCheck = confirm(vMessage); 
	if(vCheck == 1){
		location.replace(vUrl);
	}
}

/* Send Username to parent window - p_find_user.php */
function fSendName (vName){
	vOW = window.opener.document.getElementById('username');
	vOW.value = vName;
	window.close();
}

/* Change the the opening pages URL */
function fChangeOpener (vURL){
	window.opener.document.location = vURL;
}

/* Update Cordinates ??? */
function fUpdateLoc (vX, vY){
	document.getElementById('xcord').value = vX;
	document.getElementById('ycord').value = vY;
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	this.set=Querystring_set
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
    s1 = 0;
	s2 = 0;
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
		s1 = (name = 's1') ? 1 : s1;
		s2 = (name = 's2') ? 1 : s2;
	}
	if(!s1){
		name = s1;
		value = 0;
		this.params[name] = value
	}
	if(!s2){
		name = s2;
		value = 0;
		this.params[name] = value
	}

}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function Querystring_set(key, value) {
	this.params[key] = value
}

function fChangeCompare(vLink){	
	var qs = new Querystring();
	if(parseInt( qs.get('s1') ) > 0){
		if( parseInt(qs.get('s1')) == parseInt(vLink) ){
			qs.set( 's1', qs.get('s2') );
			qs.set('s2', '0');
		}else if( parseInt(qs.get('s2')) == parseInt(vLink) ){
			qs.set('s2', '0');
		}else{
			qs.set('s2', vLink);
		}
	}else{
		qs.set('s1', vLink);
	}
	
	document.location = 'index.php?p=' + qs.get('p') + '&s=' + qs.get('s') + '&sprocedures=' + qs.get('sprocedures', 0) + '&scounty=' + qs.get('scounty', 0) + '&search=Search&s1=' + qs.get('s1', 0) + '&s2=' + qs.get('s2', 0) + '&start=' + qs.get('start', 0);
	
}

function fBodyList(vID){
	document.bodyForm.ba.value = vID;
	document.bodyForm.submit();
}

function fChangeSRDrop(vNum){
	vDrop = document.searchForm['searcht[region_id]'];
	for(i=0;i<vDrop.options.length;i++){
		if(vDrop.options[i].value==vNum){
			vDrop.options[i].selected = true;
		}
	}
}

function showText(let, num){
	if( $('default' + let) ){
		$('default' + let).addClass('hidden');
	}
	for(k=0;k<10;k++){
		if( $( ('linkLink' + let) + k) ){
			$( ('linkLink' + let) + k).removeClass('current');
		}
		if( $( ('linkText' + let) + k) ){
			$( ('linkText' + let) + k).addClass('hidden');
		}
	}
	if( $( ('linkLink' + let) + num) ){
		$( ('linkLink' + let) + num).addClass('current');
	}
	if( $( ('linkText' + let) + num) ){
		$( ('linkText' + let) + num).removeClass('hidden');
	}
}

