// CHECK CLIENT BROWSER & PLATFORM
// original code from http://developer.apple.com/internet/_javascript/
//
// USAGE:	browserNaming();
// NOTES:	call it from within an external JS document
// RESULT:	browserNew = true/false
//			browserName = IE/NS/Opera
//			browserNameLong = IE5/etc
//			Macintosh = true/false
// WORKS:	everything

	var its;
	var browserName;
	var browserNameLong;
	var browserNew;
	var preloadFlag = false;
	var Macintosh = navigator.userAgent.indexOf('Mac')>0;

	function its() {
		var n = navigator;
		var ua = ' ' + n.userAgent.toLowerCase();
		var pl = n.platform.toLowerCase();
		var an = n.appName.toLowerCase();

		// browser version
		this.version = n.appVersion;
		this.nn = ua.indexOf('mozilla') > 0;

		// 'compatible' versions of mozilla aren't navigator
		if(ua.indexOf('compatible') > 0) {
			this.nn = false;
		}
		
		this.opera = ua.indexOf('opera') > 0;
		this.ie = ua.indexOf('msie') > 0;
		this.major = parseInt( this.version );
		this.minor = parseFloat( this.version );

		// platform
		this.mac = ua.indexOf('mac') > 0;
		this.win = ua.indexOf('win') > 0;

		// workaround for IE5 which reports itself as version 4.0
		if(this.ie) {
			if(ua.indexOf("msie 5") > 1) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
			}
		}

		return this;
	}

	function browserNaming() {
		its = new its();
		
		// is it a DOM-enabled browser?
		if (!document.getElementById) {
			browserNew = false;
		}
		else {
			browserNew = true;
		}

		// need the name, too
		if (its.opera) {
			browserName = "Opera";
		}
		else if (its.ie) {
			browserName = "IE";
		}
		else {
			browserName = "NS";
		}

		// and the number
		browserNameLong = browserName + its.major;
	
	}

	document.getElementsByTagName('html')[0].className += (document.getElementsByTagName('html')[0].className=='')?'hasjs':' hasjs';

// DOM / GET STYLE PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), return the given property of that id.
// WORKS:	ie5+, ns6+, opera5+

	function getIdStyleProperty(id,property) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
				if (styleObject[property]) {
					return styleObject[ property ];
				}
			}
		return (styleObject != null) ?
		styleObject[property] :
		null;
	}

// DOM / SET STYLE PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), set the given property of that id to the value provided.
// WORKS:	ie5+, ns6+, opera5+

	function setIdStyleProperty(id,property,value) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
			styleObject[ property ] = value;
		}
	}

// DOM / GET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), return the given property of that id.
// WORKS:	ie5+, ns6+, opera5+

	function getIdProperty(id,property) {
		var propObj = document.getElementById( id );
		if (propObj != null) {
//			propObj = propObj.style;
				if (propObj[property]) {
					return propObj[ property ];
				}
			}
		return (propObj != null) ?
		propObj[property] :
		null;
	}

// DOM / SET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), set the given property of that id to the value provided.
// WORKS:	ie5+, ns6+, opera5+

	function setIdProperty(id,property,value) {
		var propObj = document.getElementById( id );
		if (propObj != null) {
//			propObj = propObj.style;
			propObj[ property ] = value;
		}
	}

// GOTO
// 
// NOTES:	takes the browser window to a given href

	function gonow(anhref) {
		document.location.href = anhref;
	}

// Add an eventListener to browsers that can do it somehow.
// Originally by the amazing Scott Andrew.
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
	obj.addEventListener(evType, fn, true);
	return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
  } else {
	return false;
  }
}

openWin = function (href,windowname,features) {
  window.open(href,windowname,features);
}

writeHidePostalLink = function (link_text) {
	document.write("<p class=\"no_print\"><span onclick=\"hidePostal();\" "
		+ "class=\"button\">" 
		+ link_text
		+ "</span></p>");
}

writeShowPostalLink = function (link_text, confirm) {
	if (confirm) {
		css_class = "class=\"hide\"";
	} else {
		css_class = "";
	}
	document.write("<div id=\"show_postal\" "
		+ css_class
		+ "><p class=\"no_print\"><span onclick=\"showPostal();\" "
		+ "class=\"button\">" 
		+ link_text
		+ "</span></p></div>");
}

hidePostal = function () {
	setIdStyleProperty('postal','display','none');
	setIdStyleProperty('show_postal','display','block');
}

showPostal = function () {
	setIdStyleProperty('postal','display','block');
	setIdStyleProperty('show_postal','display','none');
}