// Browser detection stuff
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('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;
}


function sendMail(address, subject) {

	var theMailAddress = "mailto:";
	
	var addressArray = address.split(" ");
	
	for (var i=0; i<addressArray.length; i++) {
		var addressItem = addressArray[i];
		
		if (addressItem == "[ab]") {
			theMailAddress = theMailAddress + "@";
		}
		else if (addressItem == "[pt]") {
			theMailAddress = theMailAddress + ".";
		}
		else {
			theMailAddress = theMailAddress + addressItem;
		}
	}
	
	//	add the subject if there is one
	if (subject != "") {
		theMailAddress = theMailAddress + "?subject=" + escape(subject);
	}

	//	write the link back to an unused form and submit it		
	document.forms["sender-of-mail"].action = theMailAddress;
	submitForm("sender-of-mail");

}

function submitForm(formName) {
	document.forms[formName].submit();
}


// Correctly handles PNG transparency in Win IE 5.5 or higher.
// For documentation and the latest version visit:
// http://homepage.ntlworld.com/bobosola/

function correctPNG(specificImage) {
	if (browser == "Internet Explorer") {
	for(i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		var fileName = imgName.substring(imgName.lastIndexOf('/')+1);
		if ((imgName.substring(imgName.length-3, imgName.length) == "PNG") &&
			(specificImage == "" || (fileName == specificImage.toUpperCase()))) {
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = (img.style.cssText) ? img.style.cssText + ";" : "";
			var floatOrBlock = "display:inline-block;";
			var oAttribs = img.attributes;
			for (var j=0; j<oAttribs.length; j++) {
				var oAttrib = oAttribs[j];
				if (oAttrib.nodeName == "align") {
					switch(oAttrib.nodeValue) {
						case "left"  : floatOrBlock = "float:left;"  ; break;
						case "right" : floatOrBlock = "float:right;" ; break;
					}
					break;
				}
			}
			var strNewHTML = "<span " + imgID + imgClass + imgTitle;
			strNewHTML += " style=\"" + floatOrBlock + imgStyle;
			strNewHTML += " width:" + img.width + "px; height:" + img.height + "px; ";
			strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\');\">";
			strNewHTML += "</span>"; 
			img.outerHTML = strNewHTML;
			break;
			}
		}
	}
}

function canPerformDownload() {
	var isTouch = false;
	if ((navigator.userAgent.indexOf("Safari/") >= 0) && 
			(navigator.userAgent.indexOf("Mobile/") >= 0)) {
		isTouch = true;
	}
	if (isTouch) {
		alert("Please Download this file on a Mac.");
	}
	return !isTouch;
}

function trackDownload() {
	var pageTracker = arguments[0];
	var pagePath = arguments[1];
	var eventCategory = "";
	var eventAction = "";
	var eventLabel = "";
	var isDownload = false;
	var	currentArg = 2;
	
	if (arguments.length > currentArg) {
		eventCategory = arguments[currentArg++];
		if (typeof eventCategory == "string") {
			if (arguments.length > currentArg) {
				eventAction = arguments[currentArg++];
				eventLabel = arguments.length > currentArg?arguments[currentArg++]:"";
			}
			else {
				alert("Error: No Action argument for the tracker.");
				return false;
			}
		}
		else {
			eventCategory = "";
			currentArg--;
		}
	}
	
	//	Now test whatever the currentArg is to see if it is boolean
	if ((currentArg < arguments.length) && (typeof arguments[currentArg] == "boolean")) {
		isDownload = arguments[currentArg];
	}
	
	if (!isDownload || canPerformDownload()) { 
		pageTracker._trackPageview(pagePath);
		if (eventCategory != "") { 
			pageTracker._trackEvent(eventCategory, eventAction, eventLabel);
		}
		return true;
	} 
	else {
		return false;
	}
}


