// Set event handler to initialize API
var isCSS, isW3C, isIE4, isIE6CSS, isNN4, isNN6; 
var widthWindow, heightWindow;
var heightHTML;

window.onresize = checkIBrowser;

// let all IBrowsers establish content objects
function checkIBrowser() {
	if (document.images) {
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isNN6 = (document.getElementById && !document.all) ? true : false;
		isOPE = (window.opera) ? true : false;
		
		return true;
	}
	else
		return false;
}

// Set the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isNN4) {
			theObj.bgColor = color;
		} else if (isCSS) {
			theObj.backgroundColor = color;
		}
	}
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}
	return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isW3C) {
			theObj = document.getElementById(obj);
		} else if (isIE4) {
			theObj = document.all(obj);
		} else if (isNN4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		// pass through object reference
		theObj = obj;
	}
	return theObj;
}

// Set the visibility of an object to visible - true or hidden - false
function showHideObject(obj, sw) {
    var theObj = getObject(obj);
    if (theObj) {
    	if (sw)
        	theObj.visibility = "visible";
        else
        	theObj.visibility = "hidden";
    }
}

// change cursor style
function cursorStyle(img) {
	if (isCSS) {
		if (isNN4 || isNN6)
			img.style.cursor='pointer';
		else
			img.style.cursor='hand';
	}
	return;
}

// change all select color list for IE
function chngSelectColor() {
    var arg = chngSelectColor.arguments;
    for (i = 0; i < arg.length; i++) {
        obj = getRawObject(arg[i]);
        if (obj) {
			for (j = 0; j < obj.options.length; j++) {
			    if (obj.options[j].selected == false) {
				    chngInputColor(obj.options[j], true, true);
			    }
			}
        }
    }
}

// change Input Color
function chngInputColor(what, sw, init, colorSelected, colorNotSelected) {
	// on focus
	if (sw) {
		setBGColor(what, colorSelected);
		if (!init) {
			objElement = getRawObject(what.name);
			if (objElement.options)
				for (i = 0; i < objElement.options.length; i++)
					setBGColor(objElement.options[i], colorSelected);
		}
	}
	// on blur
	else {
		setBGColor(what, colorNotSelected);
		objElement = getRawObject(what.name);
		if (objElement.options)
			setBGColor(objElement.options[objElement.selectedIndex], colorNotSelected);
	}

}
