// JavaScript Document

/***** YKM HELPER OBJECT ******/

var YKM = {
	browserType: function() {
		// This funciton determines the type of browser engine 
		var isDOM = (document.getElementById)?true:false;
		var isOpera = (window.opera)?true:false;
		var isOpera5 = (isOpera && isDOM);
		var isOpera6 = (isOpera5 && window.print)?true:false;
		var isMSIE = isIE = (document.all && document.all.item && !isOpera);
		var isNC = (navigator.appName=="Netscape");
		var isNC4 = (isNC && !isDOM);
		var isNC6 = isMozilla = (isNC && isDOM);
		if (isDOM && isMSIE && isIE) {
			return "IE";
		} else if (isDOM && (isOpera || isOpera5 || isOpera6)) {
			return "OP";
		} else if (isDOM && (isNC || isNC4 || isNC6)) {
			return "MZ";
		} else {
			return false;
		}
	},
	getRealX: function(ofWho) {
		who = ((typeof ofWho == "string")?(document.getElementById(ofWho)):(ofWho));
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {			
			var nLeftPos = who.offsetLeft;          // initialize var to store calculations
			var eParElement = who.offsetParent;     // identify first offset parent element  
			while (eParElement != null)
			{                                            // move up through element hierarchy
				nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
				eParElement = eParElement.offsetParent;  // until no more offset parents exist
			}
			return nLeftPos;                             // return the number calculated
		}
	},
	getRealY: function(ofWho) {
		who = ((typeof ofWho == "string")?document.getElementById(ofWho):ofWho);
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {			
			var nTopPos = who.offsetTop;
			var eParElement = who.offsetParent;
			while (eParElement != null)
			{
				nTopPos += eParElement.offsetTop;
				eParElement = eParElement.offsetParent;
			}
			return nTopPos;			
		}
	},
	isChildOf: function(whois,ofwho) {
		who = ((typeof whois == "string")?document.getElementById(whois):whois);
		par = ((typeof ofwho == "string")?document.getElementById(ofwho):ofwho);
		if (typeof who == "undefined" || who == null || typeof par == "undefined" || par == null || typeof par.tagName == "undefined" || typeof who.tagName == "undefined") {
			return false;
		} else {
			if ((par.tagName.toUpperCase() == "HTML" || par.tagName.toUpperCase() == "BODY") && (who.tagName.toUpperCase() != "HTML" && who.tagName.toUpperCase() != "BODY")) {
				return true;
			} else 
			if ((par.tagName.toUpperCase() != "HTML" && par.tagName.toUpperCase() != "BODY") && (who.tagName.toUpperCase() == "HTML" || who.tagName.toUpperCase() == "BODY")) {
				return false;
			} else 
			if (who.parentNode == par || who == par) {
				return true;
			} else {
				return this.isChildOf(who.parentNode,par);
			}
		}
	},
	mX: 0,		// This variable contains the X-position of the mouse pointer when tracking is active
	mY: 0,		// This variable contains the Y-position of the mouse pointer when tracking is active
	mouseTarget: null,
	trackMouse: function(ev) {
		// This funciton is used to track the mouse movements and report the location of the cursor to the YKM object
		if (YKM.browserType() == "IE") {
			YKM.mouseX = event.x;
			YKM.mouseY = event.y;
			YKM.mouseTarget = event.srcElement;
		} else {
			YKM.mouseX = ev.pageX;
			YKM.mouseY = ev.pageY;
			YKM.mouseTarget = ev.target;
		}
	},
	startTracking: function() {
		// Initiates tracking of the mouse position
		document.onmousemove = this.trackMouse;
	},
	_HOUR: -1,
	_DAY: -2,
	_WEEK: -3,
	_MONTH: -4,
	_YEAR: -5,
	SetCookie: function(cname, cvalue, expiration, path, dom, secure) {
		// The "expires" parameter can receive:
		// - string value of the desired expiration date, in which case it is written to the cookie as is.
		// - null value meaning no expiration date
		// - preset constants (see above the function) add to the current datetime
		// - greater than 0 numeric value of milliseconds to add to the current datetime
		var cookiestr = cname+"="+cvalue;
		if (expiration != null) {
			if (typeof expiration == "string") {
				// Custom expiration date received
				cookiestr += (";expires="+expiration);
			} else if (expiration <0) {
				switch (cookiestr) {
					case -1: var addon = (1000 * 60 * 60); break;
					case -2: var addon = (1000 * 60 * 60 * 24); break;
					case -3: var addon = (1000 * 60 * 60 * 24 * 7); break;
					case -4: var addon = (1000 * 60 * 60 * 24 * 30); break;
					case -4: var addon = (1000 * 60 * 60 * 24 * 365); break;
					default: var addon = 0;
				}
				var d = new Date();
				var expdate = d.getTime() + addon;
				cookiestr += (";expires="+expdate);
			} else {
				var d = new Date();
				var expdate = d.getTime() + expiration;
				cookiestr += (";expires="+expdate);
			}
		}
		if (path && path != null) {
			cookiestr += (";path="+path);
		}
		if (dom && dom != null) {
			cookiestr += (";domain="+dom);
		}
		if (secure && secure == true) {
			cookiestr += (";secure");
			cookiestr += (";HttpOnly");
		}
		document.cookie = cookiestr;
	},
	GetCookie: function(cname) {
		// Returns the string value of the desired cookie or boolean "false" if the cookie not found
		var temparr = document.cookie.split("; ");
		for (var i=0;i<temparr.length;i++) {
			var tempitem = temparr[i].split("=");
			if (tempitem[0] == cname) {
				return tempitem[1];
			}
		}
		return false;
	},
	CookiesSupported: function() {
		// Returns true if cookie set/get cycle was succesful
		this.SetCookie("cookietest","1");
		var test = this.GetCookie("cookietest");
		if (test == "1") {
			this.SetCookie("cookietest","");
			return true;
		} else {
			return false;
		}
	},
	getDocHeight: function() {
		// Returns the true height of the document (including the scroll)
		if (this.browserType() == "IE") {
			var s1 = document.body.scrollHeight;
			var s2 = document.body.parentNode.scrollHeight;
			if (s1<s2) return s2; else return s1;
		} else {
			return document.body.scrollHeight;
		}
	},
	getViewportTop: function() {
		// Returns the top coordinate of the currently viewport
		return document.body.scrollTop;
	},
	getViewportHeight: function() {
		// Returns the height of the client visible area of the browser
		if (this.browserType() == "IE") {
			return document.body.clientHeight;
		} else {
			return document.body.clientHeight;
		}
	},
	countChars: function(sourcestr, whichchar) {
		var count = 0;
		for (var i=0;i<sourcestr.length;i++) {
			count += (sourcestr.charAt(i) == whichchar)?1:0;
		}
		return count;
	},
	Init: function(track) {
		if (track) {
			this.startTracking();
		}
	}
}

function Dummy() {
	return false;
}
