//File Information:
//Version: $Revision: 974 $
//Last Changed By: $Author: cfrommann $ on $Date: 2007-06-04 17:58:26 -0400 (Mon, 04 Jun 2007) $

// lib/shared.js
//  Basic JS library

/* iWebPress - A Newspaper Administration tool
 * http://www.iwebpress.com
 * Copyright (C) 2002-2007 Christopher Frommann, iWebPress, Inc., et al except where otherwise noted
 *
 * This program is protected by copyright.  Redistribution 
 * is prohibited without express written consent of the
 * authors.  You can find contact information on iwebpress.com.
 *
 * 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.
 */

var bugRiddenCrashPronePieceOfJunk = (
	navigator.userAgent.indexOf('MSIE 5') != -1
	&&
	navigator.userAgent.indexOf('Mac') != -1
);

var ua = navigator.userAgent.toLowerCase();

var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && document.getElementsByTagName && document.createElement);

Array.prototype.exists = function (x) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == x) {
			return true;
		}
    }
    return false;
}

String.prototype.toCamelCase = function() {
	var s = this;
	for(var exp = /-([a-z])/; 
		exp.test(s); s = s.replace(exp, RegExp.$1.toUpperCase()) );
	return s;	
}

getStyle = function(node,style) {
	var value = node.style[style];
    if(!value)
        if(document.defaultView) { //DOM
            value = document.defaultView.getComputedStyle(node, "").getPropertyValue(style);
        } else if(node.currentStyle) { //IE
            value = node.currentStyle[style.toCamelCase()];
            if(value == 'auto')
            	if(style == 'height')
            		value = node.offsetHeight; //this should subtract padding, margin, border, but
            									//there's no way we could possibly anticipate which
            									//properties we need to look at
            	else if(style == 'width')
            		value = node.offsetWidth; //see above
            		
        }
    return value;
}

defineAttribute = function(obj,attribute,value) {
	//F*** IE a thousand times
	if(document.all) {
		var eventhandlers = new Array ("onclick","onmouseover","onmouseout");
		if(eventhandlers.exists(attribute)) {
			eval("obj." + attribute + " = function () { " + value + " }");		
		} else {
			eval("obj." + attribute + ' = "' + value + '"');
		}
	} else if(document.getElementById) {
		eval("obj.setAttribute(attribute,value)");
	} else {
		return false;
	}
	return true;
}