/* Holy Cow Play Sound */
ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape")?1:0
ns4=(ver>3  && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound() {
 if (ie4) document.all['BGSOUND_ID'].src='images/shared/cow.wav';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
  && self.document.Moo.IsReady()
 )
 {
  self.document.Moo.play()
 }
}

function stopSound() {
 if (ie4) document.all['BGSOUND_ID'].src='images/shared/	jsilence.mid';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
 )
 {
  self.document.Bach.stop()
 }
}

/* 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 checkdelitem(vUrl){
	fRet = confirm("Are you sure you wish to delete this? It is often better to hide an item 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;
		}
	} 
}

/* Menus expand/close from ID */
var keepMenuOpen=0;
var keepSubOpen=0;

function showMenu(menuID){
	keepMenuOpen= menuID;
	keepSubOpen = (menuID.substr(-2, 2) == '_s') ? menuID : 0;
	
	if(document.getElementById){
		//document.getElementById(menuID).style.backgroundColor = '#68416b';
		if( document.getElementById(menuID + '_s') ){
			document.getElementById(menuID + '_s').style.visibility="visible";
			document.getElementById(menuID + '_s').style.display="block";
		}
	} else if(document.all){
		//document.all(menuID).style.backgroundColor = '#68416b';
		if(document.all(menuID)){
			keepSubOpen= menuID;
			document.all(menuID).style.visibility = "visible";
		}
	} 
}

function closeMenu(menuID){
	//document.getElementById(menuID).style.backgroundColor = '#542a57';
	keepMenuOpen = (menuID == keepMenuOpen) ? 0 : keepMenuOpen;
	setTimeout("hideMenu('" + menuID + "');", 250);
}

function hideMenu(menuID){
  //document.menuOpen.innerHTML=keepMenuOpen;
  if ( keepMenuOpen != menuID && (keepSubOpen == 0 || menuID + '_s' != keepSubOpen) ){
	  
    if(document.getElementById){
		//document.getElementById(menuID).style.backgroundColor = '#542a57';
		if( document.getElementById(menuID + '_s') ){
			document.getElementById(menuID + '_s').style.visibility="hidden";
		}
	}
	else if(document.all){
		//document.all(menuID).style.backgroundColor = '#542a57';
		if(document.all(menuID)){
			document.all(menuID).style.visibility = "hidden";
		}
	}
  }
}

/* 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;
		}
	}
}