//##########################################################################################
//                                                                                         #
//  powerDHTML(tm) 1.6                                                                     #
//                                                                                         #
//  Copyright (C) 2006 Reza Akhavan, Exodus Web, Inc.                                      #
//  Website: www.powerDHTML.com                                                            #
//                                                                                         #
//  This program is free software; you can redistribute it and/or modify it under the      #
//  terms of the GNU General Public License as published by the Free Software              #
//  Foundation; either version 2 of the License, or (at your option) any later version.    #
//                                                                                         #
//  This program is distributed in the hope that it will be useful, but WITHOUT ANY        #
//  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A        #
//  PARTICULAR PURPOSE. See the GNU General Public License for more details.               #
//                                                                                         #
//  You should have received a copy of the GNU General Public License along with this      #
//  program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,         #
//  Suite 330, Boston, MA 02111-1307 USA                                                   #
//                                                                                         #
//##########################################################################################
//  NOTES / UPDATES / MISC                                                                 #
//##########################################################################################
//                                                                                         #
//   Created: April 2006                                                                   #
//   Last Updated: June 2007                                                               #
//   Author: Reza Akhavan - Exodus Web, Inc.                                               #
//   Email: reza@exodusweb.com                                                             #
//                                                                                         #
//   -----------------------------------------------------------------------------------   #
//   CHANGE LOG ------------------------------------------------------------------------   #
//   -----------------------------------------------------------------------------------   #
//   v1.6 - 2007-06-10                                                                     #
//    > Added cookie read,write,delete support.                                            #
//                                                                                         #
//   v1.5 - 2007-06-10                                                                     #
//    > Found error in queryString parser. Had to remove the question mark.                #
//                                                                                         #
//   v1.4 - 2006-09-06                                                                     #
//    > Added querystring parsing script. That acts like IIS's Request.QueryString         #
//      If you don't pass an argument it will return the raw query string. If you          #
//      want a specific value from the query simply pass the name as the argument.         #
//      Usage: document.querystring(['name'])                                              #
//                                                                                         #
//   v1.3 - 2006-09-06                                                                     #
//    > Added the viewport scripts from QuirksMode.org.                                    #
//      URL: http://www.quirksmode.org/viewport/compatibility.html                         #
//                                                                                         #
//   v1.2 - 2006-08-22                                                                     #
//    > Big changes. We now include our helpful methods by simply overriding the           #
//      document object.                                                                   #
//                                                                                         #
//   v1.1 - 2006-07-19                                                                     #
//    > Changed global variable pdocument to pdocument.                                    #
//                                                                                         #
//##########################################################################################
	
	//make a getElementById shortcut
	document.$ = function(key) {
		return document.getElementById(key);
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this is our request.querystring model
	var arrQueryString = (window.location.search).replace("?","").split("&");
	document.queryString = function(name) {
		if(name == undefined) {
			return window.location.search;
		}
		else {
			//parse it out
			for(var i = 0 ; i < arrQueryString.length ; i++){
				var arrNameValue = arrQueryString[i].split("=");
				if(name == arrNameValue[0]) {
					return arrNameValue[1];
				}
			}
		}
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the canvas width (in pixels) for the browser or frame
	document.getWindowWidth = function() {
		if(self.innerWidth) {
			//in firefox we want to remove the scrollbar
			//from this measurement if it exists
			if(document.getDocumentHeight() > self.innerHeight) {
				return self.innerWidth - 19;
			}
			return self.innerWidth;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			return document.documentElement.clientWidth;
		}
		else if(document.body) {
			return document.body.clientWidth;
		}
		else return 0;
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the canvas height (in pixels) for the browser or frame
	document.getWindowHeight = function() {
		if(self.innerHeight) {
			//in firefox we want to remove the scrollbar
			//from this measurement if it exists
			if(document.getDocumentWidth() > self.innerWidth) {
				return self.innerHeight - 19;
			}
			return self.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		}
		else if(document.body) {
			return document.body.clientHeight;
		}
		else return 0;
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//get document height
	document.getDocumentHeight = function() {
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		//all but Explorer Mac
		if (test1 > test2) {
			return document.body.scrollHeight;
		//Explorer Mac
		//would also work in Explorer 6 Strict, Mozilla and Safari
		} else {
			return document.body.offsetHeight;
		}
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//get document width
	document.getDocumentWidth = function() {
		var test1 = document.body.scrollWidth;
		var test2 = document.body.offsetWidth;
		//all but Explorer Mac
		if (test1 > test2) {
			return document.body.scrollWidth;
		//Explorer Mac
		//would also work in Explorer 6 Strict, Mozilla and Safari
		} else {
			return document.body.offsetWidth;
		}
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the X offset (horizontal scroll amount)
	document.getScrolledX = function() {
		//all except IE
		if(self.pageXOffset) {
			return self.pageXOffset;
		}
		//IE 6 strict
		else if(document.documentElement && document.documentElement.scrollLeft) {
			return document.documentElement.scrollLeft;
		}
		//all others
		else if(document.body) {
			return document.body.scrollLeft;
		}
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the Y offset (vertical scroll amount)
	document.getScrolledY = function() {
		//all except IE
		if(self.pageYOffset) {
			return self.pageYOffset;
		}
		//IE 6 strict
		else if(document.documentElement && document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		}
		//all others
		else if(document.body) {
			return document.body.scrollTop;
		}
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the height of a rendered element
	document.getElementHeight = function(element) {
		var elementHeight = 0;
		if(element.offsetHeight) {
			elementHeight = element.offsetHeight;
		}
		else if(element.clip && element.clip.height) {
			elementHeight = element.clip.height;
		}
		else if(element.style && element.style.pixelHeight) {
			elementHeight = element.style.pixelHeight;
		}
		return parseInt(elementHeight);
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the width of a rendered element
	document.getElementWidth = function(element) {
		var elementWidth = 0;
		if(element.offsetWidth) {
			elementWidth = element.offsetWidth;
		}
		else if(element.clip && element.clip.width) {
			elementWidth = element.clip.width;
		}
		else if(element.style && element.style.pixelWidth) {
			elementWidth = element.style.pixelWidth;
		}
		return parseInt(elementWidth);
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the top coordinate for an element
	document.getElementTop = function(element) {
		var elementTop = 0;
		elementTop = element.offsetTop;
		var ParentElement = element.offsetParent;
		while(ParentElement != null) {
  			elementTop += ParentElement.offsetTop;
	  		ParentElement = ParentElement.offsetParent;
  		}
		return elementTop;
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method returns the left coordinate for an element
	document.getElementLeft = function(element) {
		var elementLeft = 0;
		elementLeft = element.offsetLeft;
		var ParentElement = element.offsetParent;
		while(ParentElement != null) {
  			elementLeft += ParentElement.offsetLeft;
	  		ParentElement = ParentElement.offsetParent;
  		}
		return elementLeft;
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method creates a cookie for the user
	document.createCookie = function(name, value, days, path, domain) {
		var expires = "";
		
		//should we add the expiration date?
		if(days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			expires = "; expires="+ date.toGMTString();
		}
		
		//should we add the path?
		if(path) {
			path = "; path="+ path;
		}
		
		//should we add the domain?
		if(domain) {
			domain = "; domain="+ domain;
		}
		
		//create the cookie
		document.cookie = name +"="+ value + expires + path + domain +";";
	}
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method reads a cookie
	document.readCookie = function(name) {
		var cookieName = name + "=";
		var cookieArray = document.cookie.split(';');
		
		//loop over the cookies
		for(var i = 0 ; i < cookieArray.length ; i++) {
			var thisCookie = cookieArray[i];
			
			//ready past the white space
			while(thisCookie.charAt(0) == ' ') {
				thisCookie = thisCookie.substring(1, thisCookie.length);
			}
			
			//did we find thie cookie?
			if(thisCookie.indexOf(cookieName) == 0) {
				return thisCookie.substring(cookieName.length, thisCookie.length);
			}
		}
		
		//otherwise we didn't find it
		return undefined;
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//
	
	//this method deletes (over-writes) a cookie
	document.deleteCookie = function(name) {
		document.createCookie(name, "", -1);
	};
	
	//- - - - - - - - - - - - - - - - - - - - - - -//

//##########################################################################################
//                                                                                         #
//  powerDHTML(tm) 1.6                                                                     #
//  Copyright (C) 2006 Reza Akhavan, Exodus Web, Inc.                                      #
//  Website: www.powerDHTML.com                                                            #
//                                                                                         #
//##########################################################################################