/*******************************
*
* DhtmlUtils.js
* 
* Element Control class
* Ver = 2 - Utilizes prototype.js library - /js/extern/prototype.js
*
* Author: John Hutcheson, control.option
* References: DHTMLapi.js by Danny Goodman (http://www.dannyg.com) Release 2.0.
*
*******************************/
// Create DhtmlUtils class using prototype.js 
var DhtmlUtils = Class.create();
// Add new methods to the DhtmlUtils class' prototype
DhtmlUtils.prototype = {
	
	/* protype.js initialize - Constructor method
	* 
	* browser test properties initialized:
	* this.isWin
	* this.isMac
	* this.isCSS
	* this.isW3C
	* this.isIE
	* this.isIE6CSS
	* this.isIE7
	*
	*/
	
	initialize: function() { 
		if (document.images) {
			this.isWin = (navigator.platform=="Win32") ? true : false;
			this.isMac = (navigator.platform=="MacPPC") ? true : false;
			this.isCSS = (document.body && document.body.style) ? true : false;
			this.isW3C = (this.isCSS && document.getElementById) ? true : false;
			this.isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
			this.isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
			this.isIE7 = (document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" && document.all) ? true : false;
		}
	},
	
	
	checkBrowser: function(element) { 
		var element = $(element);
		
		var b;
		
		if (document.images){
			b = { 
				isWin: ((navigator.platform=="Win32") ? true : false),
				isMac: ((navigator.platform=="MacPPC") ? true : false),
				isCSS: ((document.body && document.body.style) ? true : false),
				isW3C: ((this.isCSS && document.getElementById) ? true : false),
				isIE: ((navigator.appVersion.indexOf("MSIE") != -1) ? true : false),
				isIE6CSS: ((document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false),
				isIE7: ((document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" && document.all) ? true : false)
				};
		}
		
		return b; 
	},
	
	// Position an object at a specific pixel coordinate
	shiftTo: function(element, x, y) {
		var element = $(element).style;
		if (element) {
			// equalize incorrect numeric value type
			var units = (typeof element.left == "string") ? "px" : 0;
			element.left = x + units;
			element.top = y + units;
		}
	},
	
	// Move an object by x and/or y pixels
	shiftBy: function(element, deltaX, deltaY) {
		var element = $(element);
		var elStyle = element.style
		if (elStyle) {
			// equalize incorrect numeric value type
			var units = (typeof elStyle.left == "string") ? "px" : 0;
			elStyle.top = parseInt(element.getStyle('top')) + deltaY + units;
			elStyle.left = parseInt(element.getStyle('left')) + deltaX + units;
	   }
	},
	
	// Set the visibility of an object to visible
	setVisible: function(element) {
		var element = $(element).style;
		if (element) {
			element.visibility = "visible";
		}
	},
	
	// Set the visibility of an object to hidden
	setHidden: function(element) {
		var element = $(element).style;
		if (element) {
			element.visibility = "hidden";
		}
	},
	
	// Set the display of an object to none
	displayNone: function(element) {
		var element = $(element).style;
		if (element) {
			element.display = "none";
		}
	},
	
	// Set the display of an object to block
	displayBlock: function(element) {
		var element = $(element).style;
		if (element) {
			element.display = "block";
		}
	},
	
	// Set the display of an object to inline
	displayInline: function(element) {
		var element = $(element).style;
		if (element) {
			element.display = "inline";
		}
	},
	
	getObjLeft: function(element)  {
		var element = $(element);
		var elLeft = element.getStyle('left');
		
		return element.getStyle('left');
	},
	
	// Retrieve the y coordinate of a positionable object
	getObjTop: function(element)  {
		var element = $(element);
		return element.getStyle('top');
	},
	
	// Return the available content width space in browser window
	getInsideWindowWidth: function(element) {
		var element = $(element);
		if (window.innerWidth) {
			return window.innerWidth;
		} else if (element.checkBrowser().isIE6CSS) {
			// measure the html element's clientWidth
			return document.body.parentElement.clientWidth;
		} else if (document.body && document.body.clientWidth) {
			return document.body.clientWidth;
		}
		return 0;
	},
	
	// Return the available content height space in browser window
	getInsideWindowHeight: function(element) {
		var element = $(element);
		if (window.innerHeight) {
			return window.innerHeight;
		} else if (element.checkBrowser().isIE6CSS) {
			// measure the html element's clientHeight
			return document.body.parentElement.clientHeight;
		} else if (document.body && document.body.clientHeight) {
			return document.body.clientHeight;
		}
		return 0;
	},
	
	
	/*setBgPng: function(element, imgSrc, repeat) {
		var element = $(element);
		var elStyle = element.style;
		var cb = element.checkBrowser();
		if (cb.isIE && ! cb.isIE7) {
			elStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + imgSrc + ", sizingMethod='scale')";
		} else {
			elStyle.backgroundImage ="url(" + imgSrc + ")";
			if (repeat) {
				elStyle.backgroundRepeat = repeat;
			}
		}	
	},*/
	
	setBgTransPng: function(element) {
		var element = $(element);
		var cb = element.checkBrowser();
		if (cb.isIE && ! cb.isIE7) {
			var elBg = element.getStyle('background-image');
			if (elBg.indexOf('url(') != -1) {
				var bgBIG = elBg.toUpperCase();
				if (elBg.toUpperCase().indexOf('.PNG') == -1) {
					return;
				}
				
				element.setStyle({background: 'none'});
				
				var imgSrc = elBg.replace('url(', '');
				imgSrc = imgSrc.replace('.png)', '.png');
															   
				element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + imgSrc + ", sizingMethod='scale')";
				
				//alert (element + " : " + element.style.filter);
			}
		}
	}
	
	
};
