/***********************************************************************
 * @filename            : inc/common.js
 * @author              : Ken Wang
 * @description         : javascript
 * @created             : 2006-02-20
 * @modified            : 2006-12-25
 * @requires            : inc/common.js
 ***********************************************************************/

/***** Detect Browser Capabilities *****/
var isDom = (document.getElementById) ? true:false;

/***** Generic Functions *****/
/* string manipulation */
function trim( String ) 
{
    if ( String == null )
    {
        return (false);
    }
    return String.replace( /(^\s+)|(\s+$)/g,"" );
}

/* Emulate CGI Vars */
var cgi = new Object();
    cgi.http_host = location.host;
    cgi.http_user_agent = navigator.userAgent;
    cgi.http_cookie = document.cookie;
    cgi.https = (location.protocol == 'https:\/\/') ? 'on' : 'off';
    cgi.path_info = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
    cgi.query_string = (location.search) ? ((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
    cgi.script_name = cgi.path_info;
    cgi.http_referer = document.referrer;

/* jsCSS : mixed */
/*
swap, add, remove, check
http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
*/
function jsCSS( action, obj, class1, class2 )
{
    switch( action )
    {
        case 'swap': // i.e. toggle
            obj.className = !jsCSS('check',obj,class1) ? 
                obj.className.replace( class2, class1 ) :
                obj.className.replace( class1, class2 );
            break;
        
        case 'add':
            if( !jsCSS('check',obj,class1) )
            { obj.className += obj.className ? ' '+class1 : class1; }
            break;
        
        case 'remove':
            var rep = obj.className.match(' '+class1) ? ' '+class1 : class1;
            obj.className = obj.className.replace( rep, '' );
            break;
        
        case 'check':
            return new RegExp('\\b'+class1+'\\b').test(obj.className);
            break;
    }   // end switch
}   // end jsCSS


/* Multiple Onloads */
/*
usage:
    addLoadEvent( nameOfSomeFunctionToRunOnPageLoad );
    addLoadEvent( function() { // more code to run on page load } );
*/
function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if ( typeof window.onload != 'function' ) 
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() 
        {
            oldonload();
            func();
        }
    }
}

/* multiple onsubmits for <form>s */
function addOnSubmitEvent(formObj, func)
{
    var oldonsubmit = formObj.onsubmit;
    if( typeof formObj.onsubmit != 'function' )
    {
        formObj.onsubmit = func;
    }
    else
    {
        form.obj.onsubmit = function()
        {
            oldonsubmit();
            func();
        }
    }
}

/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
* modified by ken on 2006-08-13
***********************************************/

var persistclose=1 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 1100//set x offset of bar in pixels
var startY = 150 //set y offset of bar in pixels
var limitAbsoluteTopY = 0 // cannot go above this position
var verticalpos="frombottom" //enter "fromtop" or "frombottom"

function iecompattest()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function staticbar()
{
    if( !document.getElementById("topFloater") ) return;
	barheight=document.getElementById("topFloater").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id)
    {
		var el=d.getElementById(id);
		//if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP = function(x,y) { 
            this.style.left=x+"px";
            // ken's limitAbsoluteTopY
            if( y < limitAbsoluteTopY ) y = limitAbsoluteTopY;
            this.style.top=y+"px"; 
        };
		el.x = startX;
		if (verticalpos=="fromtop")
		    el.y = startY;
		else
        {
            el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
            el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft = function()
    {
		if (verticalpos=="fromtop")
        {
            var pY = ns ? pageYOffset : iecompattest().scrollTop;
            ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else
        {   // frombottom
            var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
            ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topFloater");
	stayTopLeft();
}

addLoadEvent( staticbar );

// record pageviews
var pageviewImg = new Image();
pageviewImg.src = 'pageview.php?url='+escape(cgi.script_name);

function MM_openBrWindow(theURL,winName,features) { //v2.0 
  window.open(theURL,winName,features); 
} 

