/*********************************************************************** * @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 function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) { curleft += obj.x; } return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; } return curtop; } /* 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