/* author: hallvs@bigpond.com */
/* Creation date: 04/03/05 */

// Detect browser (only use this for CSS issues, otherwise use object detection
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('firefox')) browser = "FireFox"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

// Is Local (ie being read at Hall Vet Surgery)?
function isLocal() {
	return (document.domain == "" || 
				document.domain == "localhost" || document.domain == "Server") ;
}

// Was the Alt-Key pressed in the last event?
function AltPressed(ev) {
	return ((ev.modifiers == "ALT_MASK") || ev.altKey ) ;
}

var navT ;

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=/; domain=hallvet.com.au";
}

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 showNavDesc(str1) {
	if (str1== "") { navT = window.setTimeout("showNavDesc('As you hover your mouse over each of the above links, a quick description will appear here')", 1000) ; return 0 ; }
	if (navT != 0) { window.clearTimeout(navT); navT = 0; } ;
	
	showDesc("navDescrip", str1) ;
}

function showToyDesc(str1) {
	showDesc("toyDescrip", str1) ;
}

function showDesc(target,str1) {
var descr = document.getElementById(target) ;
	descr.innerHTML = str1 ;
	if (str1 == "") descr.innerHTML = "As you hover your mouse over each of the above links, a quick description will appear here" ;
}

function makeHoverWorkOnTransparentAnchorImgs() {
// If a transparent img is part of an anchor - which I have set to have a background change in a:hover - the background doesn't change correctly in Mozilla-based browsers. This remedies that, basically adding "onmouseover="this.style.backgroundColor='#446054';" onmouseout="this.style.backgroundColor='transparent';"

// don't need to do this for IE, but Opera may report as IE
if (browser == "Internet Explorer") return(0) ;

var anchors = document.getElementsByTagName('A') ;
for (var i=0;i<anchors.length;i++)
	{
		anchors[i].onmouseover = setBGColor ;
		anchors[i].onmouseout = clearBGColor ;
	}
}

function setBGColor() {
	var imgs = this.getElementsByTagName('IMG') ;
	for (var i=0;i<imgs.length;i++)
		imgs[i].style.backgroundColor='#446054';
}

function clearBGColor() {
	var imgs = this.getElementsByTagName('img') ;
	for (var i=0;i<imgs.length;i++)
		imgs[i].style.backgroundColor='transparent';
}

function sourceFilename() {
	var fn = window.location.pathname.substr(1) ;	// need to trim off vestigial '/'
	var li = fn.lastIndexOf("/") ;
	if (li == -1) li = fn.lastIndexOf('\\') ;
	// if in a subdirectory, prepend subdir name
	if (fn.lastIndexOf("services") != -1) { fn = "services/" + fn; }
	if (fn.lastIndexOf("staff") != -1) { fn = "staff/" + fn; }
	if (fn.lastIndexOf("pdfs") != -1) { fn = "pdfs/" + fn; }
	if (fn.lastIndexOf("calendar") != -1) { fn = "calendar/" + fn; }
	if (fn.lastIndexOf("tour") != -1) { fn = "tour/" + fn; }
	fn = fn.substr(li+1) ;
	return fn ;
}


function insertFeedbackLink(bugref) {	
// bugref will be something like "<a href='bugs.html?"
	document.write(bugref+sourceFilename()+'" target="_blank">Click to provide feedback and corrections to Andrew</a><br>') ;
}
