/*************************************************************************************
*                               DHTML API Wrapper v2.1                               *
*   Page Title:   DHTML Abstraction                                                  *
*   Page Version: 2.1                                                                *
*   Author:       Revised by Tyler Klein, based on some book... can't remember which *
*   Date:         6/18/2006                                                          *
*************************************************************************************/

// --- Include Functions ---//
var INC_DHTMLAPI = true;

// --- Object Functions: --- //
// getRawObject( obj )
// getObject( obj )

// --- Positioning Functions --- //
// getObjectHeight( obj ) 
// getObjectWidth( obj )

// shiftTo( obj, x, y )
// shiftBy( obj, dX, dY )

// center( obj )

// findPosX( obj )
// findPosY( obj )
// getObjectTop( obj )
// getObjectLeft( obj )

// --- Visibility Functions --- //
// show( obj )
// hide( obj )
// alpha( obj, a )
// getAlpha( obj )

//Global variables for browser type testing
var isCSS, isW3C, isIE4, isNN4, isIE6CSS

//Initialize document types
function initDHTML(){
	if(document.images){
		isCSS=(document.body && document.body.style)?true:false;
		isW3C=(isCSS && document.getElementById)?true:false;
		isIE4=(isCSS && document.all)?true:false;
		isNN4=(document.layers)?true:false;
		isIE6CSS=(document.compatMode && document.compatMode.indexOf("CSS1")>=0)?true:false;
	}
}

//Returns an object reference from a string
function getRawObject(obj){
	if (typeof obj=="string"){
		if( isW3C )      return( document.getElementById(obj) );
		else if( isIE4 ) return( document.all(obj) );
		else if( isNN4 ) return( document.layers[obj] );
	}
	else return( obj );
}

//Returns a reference to the style property of an object from a string
function getObject(obj){
	var theObj=getRawObject(obj);
	if( theObj && isCSS ){
		theObj=theObj.style
	}
	return theObj;
}

//Returns object's height in pixels
function getObjectHeight(obj){
	var o = getRawObject(obj);
	var r=0;

	if( o.offsetHeight )                      r=o.offsetHeight;
	else if( o.clip && o.clip.height )        r=o.clip.height;
	else if( o.style && o.style.pixelHeight ) r=o.style.pixelHeight;
	return parseInt(r);
}

//Returns object's width in pixels
function getObjectWidth(obj){
	var o=getRawObject(obj);
	var r=0;
	if (o.offsetWidth){
		if( o.scrollWidth && (o.offSetWidth!=o.scrollWidth) ) r=o.scrollWidth;
		else r=o.offsetWidth;
	}
	else if( o.clip && o.clip.width ) r=o.clip.width;
	else if( o.style && o.style.pixelWidth ) r=o.style.pixelWidth;
	return parseInt(r);
}			

function getObjectVisibleWidth(obj){
	var o=getRawObject(obj);
	var r=0;
	if (o.offsetWidth){
		r=o.offsetWidth;
	}
	else if( o.clip && o.clip.width ) r=o.clip.width;
	else if( o.style && o.style.pixelWidth ) r=o.style.pixelWidth;
	return parseInt(r);
}			

//Position obj at x, y
function shiftTo(obj,x,y){
	var o = getObject(obj);
	if( !o ) return;
	if( isCSS ){
		var u = (typeof o.left=="string")?"px":0;
		o.left=x+u;
		o.top=y+u;
	}
	else if( isNN4 ) theObj.moveTo(x,y);
}

//Move obj by dX, dY
function shiftBy(obj,dX,dY){
	var o=getObject(obj);
	if( !o ) return;
	if( isCSS ){
		var u=(typeof o.left=="string")?"px":0;
		o.left=getObjectLeft(obj)+dX+u;
		o.top=getObjectTop(obj)+dY+u;
	}else if(isNN4) theObj.moveBy(dX,dY);
}

//Centers object on screen
var fudgeFactor={top:-1,left:-1}; //Correction for IE/MAC

function center(layerName){
	var obj=getRawObject(layerName);
	
	//set fudgeFactor values first time through
	if (fudgeFactor.top==-1){
		if((typeof obj.offsetTop=="number")&&obj.offsetTop>0){
			fudgeFactor.top=obj.offsetTop;
			fudgeFactor.left=obj.offsetLeft;
		}else{
			fudgeFactor.top=0;
			fudgeFactor.left=0;
		}
		if (obj.offsetWidth && obj.scrollWidth){
			if (obj.offsetWidth!=obj.scrollWidth){
				obj.style.width=obj.scrollWidth;
			}
		}
	}
	
	var x=Math.round((getInsideWindowWidth()/2)-(getObjectWidth(obj)/2));
	var y=Math.round((getInsideWindowHeight()/2)-(getObjectHeight(obj)/2));
	shiftTo(obj,x-fudgeFactor.left,y-fudgeFactor.top);
	show(obj);
}

//NN4 Redraw bug
function handleResize(){
	if( isNN4 ) location.reload();
	else centerIt("banner");
}

//D.1 Window Width
function getInsideWindowWidth(){
	if (window.innerWidth) 
		return window.innerWidth;
	else if(isIE6CSS) 
		return document.body.parentElement.clientWidth;
	else if (document.body&&document.body.clientWidth) 
		return document.body.clientWidth;

	return 0;
}

//D.2 Window Height
function getInsideWindowHeight(){
	if (window.innerHeight)
		return window.innerHeight;
	else if(isIE6CSS)
		return document.body.parentElement.clientHeight;
	else if (document.body&&document.body.clientHeight)
		return document.body.clientHeight;
	return 0;
}

// Return x position of object
function findPosX( obj ){
	var o = getRawObject( obj );
	if( o.x ) return o.x;
	if( o.offsetParent ) return( o.offsetLeft + findPosX( o.offsetParent ) );
	else return( o.offsetLeft );
}

// Return y position of object
function findPosY( obj ){
	var o = getRawObject( obj );
	if( o.y ) return o.y;
	
	try {
		if( o.offsetParent ) return( o.offsetTop + findPosY( o.offsetParent ) );
		else return( o.offsetTop );
	} catch (e) { }
	
	return( o.offsetTop );
}

function setPos(obj, x, y){
	var o = getRawObject( obj );
	var oX = findPosX(obj.offsetParent);
	var oY = findPosY(obj.offsetParent);
	shiftTo( obj, x-oX, y-oY );
}


function stripPX( str ){
	if( (typeof( str) == 'string') && (str.substring( -2 ) == "px") )
		return( parseInt(str.substring( 0, -2 )) );
	else
		return( parseInt(str) );
}

//get left coordinate
function getObjectLeft(obj){
	var o=getRawObject(obj);
	var r=0;
	if( document.defaultView ){
		var style=document.defaultView;
		var cssDec1=style.getComputedStyle(o,"");
		r=cssDec1.getPropertyValue("left");
	}
	else if( o.currentStyle ) r=o.currentStyle.left;
	else if( elem.style )     r=o.style.left;
	else if( isNN4 )          r=o.left;
	return parseInt(r);
}

//get top coordinate
function getObjectTop(obj){
	var o=getRawObject(obj);
	var r=0;
	if( document.defaultView ){
		var style=document.defaultView;
		var cssDec1=style.getComputedStyle(o,"");
		r=cssDec1.getPropertyValue("top");
	}
	else if( o.currentStyle ) r=o.currentStyle.top;
	else if(o.style)          r=o.style.top;
	else if(isNN4)            r=o.top;
	return parseInt(r);
}

//Show object
function show(obj){
	var o=getObject(obj);
	if( o ){
		o.visibility="visible";
	}
}

//Hide Object
function hide(obj){
	var o=getObject(obj);
	if( o ){
		o.visibility="hidden";
	}
}

//Return x scroll of window
function scrollX(){
	return (document.all)?document.body.scrollLeft:window.pageXOffset; 
}

//Return y scroll of window
function scrollY(){
	return (document.all)?document.body.scrollTop:window.pageYOffset; 
}

//Return y scroll of window
function setScrollY( top ){
	if( document.all ){
		document.body.scrollTop = top;
	} else {
		window.scrollTo(0,top);
	}
}

//set alpha of an object
function alpha( obj, a ){
	var o=getObject( obj );
    o.opacity = (a / 100);
    o.MozOpacity = (a / 100);
    o.KhtmlOpacity = (a / 100);
    o.filter = "alpha(opacity="+a/2+")";
}

//get the alpha of an object
function getAlpha( obj ){
	var o = getObject( obj );
	if( o.opacity ) return( o.opacity * 100 );
	if( o.MozOpacity ) return( o.MozOpacity * 100 );
	if( o.KhtmlOpacity ) return( o.KhtmlOpacity * 100 );
	return( 100 );
}

//Gets the keyboard modifiers
function getKeyModifiers( evt ){
	if ( evt ) {
		var shft = evt.shiftKey;
		var ctrl = evt.ctrlKey;
		var alt  = evt.altKey;
	} else {
		var shft = event.shiftKey;
		var ctrl = event.ctrlKey;
		var alt  = event.altKey;
	}	
	return( {shift:shft, ctrl:ctrl, alt:alt} );
}

function getKey( evt ){
	if( evt.keyCode )
		return( evt.keyCode );
	else
		return( evt.which );
}

//Gets an event's target
function getEvtTarget( evt ){
	if( evt ) 
		return( evt.target );
	else
		return(window.event.srcElement);
}

//Gets a mouseover's from target
function mouseFrom( evt ){
	if (!evt) var evt = window.event;
	return( evt.relatedTarget || evt.fromElement );
}

//Gets a mouseout's to target
function mouseTo( evt ){
	if (!evt) var evt = window.event;
	return( evt.relatedTarget || evt.toElement );
}

//Gets an event's click location
function getEvtClick( evt ){
	if( evt )
		return( {x:evt.pageX, y:evt.pageY} );
	else
		return( {x:window.event.clientX, y:window.event.clientY} );
}

function getCSS(obj, property){
	var o = getRawObject( o );
	if (o.currentStyle)
		var p = o.currentStyle[property];
	else if (window.getComputedStyle)
		var p = document.defaultView.getComputedStyle(o,null).getPropertyValue(property);
	return p;
}

function moveToFront( o ){
	var th = o.style.zIndex;
	if( !th ){
		for( i=0; i < o.parentNode.childNodes.length; i++ )
			if( o.parentNode.childNodes[i].style ) 
				o.parentNode.childNodes[i].style.zIndex = i;
		th = o.style.zIndex;
	}
	for( i=0; i < o.parentNode.childNodes.length - 1; i++ )
		if( o.parentNode.childNodes[i].style )
			if( o.parentNode.childNodes[i].style.zIndex > th )
				o.parentNode.childNodes[i].style.zIndex--;
	o.style.zIndex = i + 1;
}

function attribute( obj, id ){
	for( var i=0; i<obj.attributes.length; i++ ){
		if( obj.attributes[i].nodeName.toLowerCase() == id.toLowerCase() ) return(obj.attributes[i].value);
	}
	return( null );
}