/* Change Visibility of an element */
function changeVis(vID){
	oVis = document.getElementById(vID);
	if (oVis.style.visibility=="hidden" || (oVis.className && oVis.className.indexOf('hidden') != -1) ){
		if(oVis.className && oVis.className.indexOf('hidden') != -1){
			oVis.className = oVis.className.replace('hidden', '');
		}
		oVis.style.visibility="visible";
		oVis.style.display = "";
	} else {
		oVis.style.visibility="hidden";
		oVis.style.display="none";
	}
}

function addFav(){
	if(document.all && !window.opera){ 
		window.external.AddFavorite(location.href, document.title); 
	}else{ 
		this.title = document.title; 
	}
	return false; 	
}

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); }

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];}}
}


/* 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+"');");
}

/* 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 expandinglist(obj, count){
	lists = obj.getElementsByTagName('ul');
	for(i=0;i<lists.length;i++){
		lists[i].id = 'list' + i;
		lists[i].style.display = 'none';
		lists[i].style.visibility = 'hidden';

		linkNode = document.createElement('a');
		linkNode.setAttribute('href', 'javascript:changeVis(\'list' + i +'\');');
		textNode = document.createTextNode( lists[i].parentNode.childNodes[0].nodeValue );
		linkNode.appendChild(textNode);
		lists[i].parentNode.insertBefore(linkNode, lists[i].parentNode.childNodes[0]);
		lists[i].parentNode.childNodes[1].nodeValue = '';
	}
}

function setHover(obj, id ){
	document.getElementById(id).className = document.getElementById(id).className + ' hov';
}
function removeHover(obj, id){
	document.getElementById(id).className = document.getElementById(id).className.replace('hov','');
}
function is_ie6(){
     return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}
if(is_ie6()){
	//alert('Sorry, but we don\'t support Internet Explorer 6.0 or below. Please upgrade to Internet Explorer 7+ or Firefox.');
}

