// JavaScript Document

//var BASE_URL = "http://"+((document.domain.indexOf("www")>-1)?"www.":"")+"meganracing.com/";
//var BASE_URL = "http://www.meganracing.com/";
var BASE_URL_PROTOCOL_HTTPS = "https:";
var BASE_URL_PROTOCOL_HTTP = "http:";
var BASE_URL_PROTOCOL = (document.location.protocol == "https:") ? "https:" : "http:";
var BASE_URL = BASE_URL_PROTOCOL+"//"+((document.domain.indexOf("www")>-1)?"www.":"")+"meganracing.com/";
var BASE_URL_PATH = ((document.domain.indexOf("www")>-1)?"www.":"")+"meganracing.com/";
//
var USER_AGENT = navigator.userAgent.toLowerCase();
var IS_OPERA = ((USER_AGENT.indexOf("opera")>-1)?1:0);
var IS_IE = ((USER_AGENT.indexOf("msie")>-1)&&((document.all&&!IS_OPERA)));
var IS_MOZILLA = ((USER_AGENT.indexOf("gecko")>-1)?1:0);
var IS_NS = ((navigator.appName=="Netscape")?1:0);

//////////////////////////////////////////////////////////////////////////////////////////
/*  Prototype JavaScript framework,version 1.5.2_pre0
 *  (c) 2005-2007 Sam Stephenson
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details,see the Prototype web site: http://www.prototypejs.org/
 *
/*--------------------------------------------------------------------------*/
var Class = {
	create: function(){
		return function(){
			this.initialize.apply(this,arguments);
		}
	}
};
Object.extend = function(destination,source){
	for(property in source) destination[property] = source[property];
	return destination;
};
Function.prototype.bind = function(object){
	var __method = this;
	return function(){
		return __method.apply(object,arguments);
	}
};
Function.prototype.bindAsEventListener = function(object){
	var __method = this;
	return function(event){
		__method.call(object,event || window.event);
	}
};

//////////////////////////////////////////////////////////////////////////////////////////
//extend
//concat,join,pop,push,reverse,shift,slice,sort,splice,unshift
/*
Array.prototype.push = function(){
	for(var i=0;i<arguments.length;i++)
		this[this.length]=arguments[i];
	return this.length;
};
Array.prototype.pop = function(){
	lastElement = this[this.length-1];
	this.length = Math.max(this.length-1,0);
	return lastElement;
};
Array.prototype.reverse = function(){
	var ss = [];
	for(var i=0; i<this.length; i++){
		ss.push(ss[this.length-1-i]);
	}
	return ss;
};*/
Array.prototype.contain = function(value){
	for(var i=0; i<this.length; i++){
		if(this[i] == value) return true;
	}
	return false;
};
Array.prototype.contains = function(value){
	for(var i=0; i<this.length; i++){
		if(this[i] == value || value.contain(this[i])) return true;
	}
	return false;
};
Array.prototype.ins = function(value){
	for(var i=0; i<this.length; i++){
		if(value.contain(this[i]) == false) return false;
	}
	return true;
};
Array.prototype.merge = function(b){
	for(var i=0; i<b.length; i++){
		this.push(b[i]);
	}
	return this;
};
Array.prototype.pushfirst = function(value){
	this.unshift(value);
};
Array.prototype.pushfirstb = function(value){
	var ss = [];
	ss.push(value);
	for(var i=0; i<this.length; i++){
		ss.push(this[i]);
	}
	return ss;
};
Array.prototype.first = function(value){
	if(this.length == 0 ) return null;
	return this[0];
};
Array.prototype.last = function(value){
	if(this.length == 0 ) return null;
	return this[this.length-1];
};

//////////////////////////////////////////////////////////////////////////////////////////
//VERSION 1.0.0.1
function $(el,d){
	if(isUndefined(d)){
		d = document;
	}
	if(d.getElementById){
		return d.getElementById(el);
	} else if(d.all){
		return d.all[el];
	} else if(d.layers){
		return d.layers[el];
	} else {
		return null;
	}
}
function $A(a){
	var na = [];
	for(var i=0; i<a.length; i++){
		na.push(a[i]);	
	}
	return na;
}
function $E(el){
	if(typeof el == 'string'){
		el = document.getElementById(el);
	}
	return el;
}
function $N(name,obj){
	if(typeof(obj) == "undefined"){
		obj = document;
	}
	if(obj.getElementsByTagName(name)){
		return obj.getElementsByTagName(name);
	} else {
		return null;
	}
}
function $S(){
	if(arguments.length == 1){
		return $E(arguments[0]);	
	}
	var elements = [];
	var a = $A(arguments);
	for(var i=0; i<a.length; i++){
		elements.push($E(a[i]));	
	}
	return elements;
}
function isUndefined(variable){
	return typeof variable == 'undefined' ? true : false;
}
//////////////////////////////////////////////////////////////////////////////////////////
function str_length(string){
	return string.replace(/[^x00-\xff]/g,"**").length;
}
function str_trim(string){
	//return string.replace(new RegExp("(^[\\s]*)|([\\s]*$)","g"),"");
	return string.replace(/^\s*/,"").replace(/\s*$/,"");
}
function str_ltrim(string){
	return s.replace(/^\s*/,"");
}
function str_rtrim(string){
	return s.replace(/^\s*/,"");
}
function str_replace_space(string){
	return string.replace(/\s/g,"").replace(/\u3000/g,"");
}
function str_replace(str_search,str_replace,str_subject){
	if(str_length(str_subject)){
		return str_subject.replace(str_search,str_replace);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////
// RAND
//////////////////////////////////////////////////////////////////////////////////////////
function getRand(a,b){
	if(a){
		b = b ? b:0;
		return Math.floor(Math.random()*a + b);
	} else {
		a = new Date();
		return a.getTime();
	}
}
function getNow(){
    var d = new Date();
	if(IS_IE){
		var year = d.getYear();
	} else {
		var year = d.getFullYear();
	}
    var month = d.getMonth() + 1;
    var day = d.getDate();
	//getHours(),getMinutes(),getTime()
    if(month < 10){
		month = "0" + month;
    }
	if(day < 10){
		day="0" + day;
	}
	var separator = '-';
	var ys = "-";
	var ms = "-";
	var ds = "-";
	return year+ys+month+ms+day+ds;
}
//////////////////////////////////////////////////////////////////////////////////////////
//	COOKIE
//////////////////////////////////////////////////////////////////////////////////////////
function setCookie(name,value,path,domain,days){
	var strCookie;
	strCookie = name + "=" + value;
	
	//path
	if(!path){
		path = "/";
	}
	strCookie += "; path=" + path;
	
	//timeout
	var expires = "";
	if(days){
		var date = new Date();
		date.setTime(date.getTime() + (days*24*3600*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	strCookie += expires;
	
	//domain
	if(domain){
		strCookie += "; domain=" + domain;
	}
	
	document.cookie = strCookie;
}
function getCookie(name){
	//RegExp
	var r = new RegExp("(^|;|\\s)*"+name+"=([^;]*)(;|$)");
	var m = document.cookie.match(r);
	return (!m ? "" : m[2]);
	
	//indexOf
	var search,offset;
	search = name + "=";
	offset = document.cookie.indexOf(search);
	if(offset != -1){
		offset += search.length;
		end = document.cookie.indexOf(";",offset);
		if(end == -1){
			end = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset,end));
	} else {
		return null;
	}
	
	//Strict,Array
	var search = name + "=";
	var ca = document.cookie.split(";");
	for(var i=0; i<ca.length; i++){
		var c = ca[i];
		while( c.charAt(0) == " "){
			c = c.substring(1,c.length);
		}
		if(c.indexOf(search) == 0){
			return c.substring(search.length,c.length);
		}
	}
	return null;
}
function eraseCookie(name,path,domain){
    var strCookie = name + "=";
	
	//path
    if(!path){
		path = "/";
	}
    strCookie += "; path=" + path;
	
	//domain
	if(domain){
        strCookie += "; domain="+domain;
    }
	
	//timeout
    strCookie += "; expires=Thu,1 Jan 1970 00:00:01 UTC";
	
	//
    if(getCookie(name)){
        document.cookie = strCookie;
    }
	
	//setCookie(name,"",false,false,-1);
	//setCookie(name,"",path,domain,-1);
}
////////////////////////////////////////////////////////////////////////////////////
// 
////////////////////////////////////////////////////////////////////////////////////
function IsAscii(char){
	if(char > 0 && char <= 255){
		return true;
	} else {
		return false;
	}
}
function IsNumeric(strString){
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	for(i = 0; i<strString.length && blnResult == true; i++){
		strChar = strString.charAt(i);
		if(strValidChars.indexOf(strChar) == -1){
			blnResult = false;
		}
	}
	return blnResult;
}
function IsFloat(strString){
	//if(parseFloat(strString) == strString){
	//	return true;
	//}
	if(parseInt(strString) >= 0){
		var pattern = /^[0-9]+((\.)[0-9]+)$/;
		if(IsNumeric(strString) == true || IsDecimal(strString) == true || pattern.test(strString) == true){
			return true;
		}
	}
	return false;
}
function IsDecimal(strString){
	var strPoint = ".";
	var strValidChars = ".0123456789";
	var strChar;
	var blnResult = true;
	var pointNums = 0;
	
	//point nums
	for(i = 0; i<strString.length; i++){
		strChar = strString.charAt(i);
		if(strChar == strPoint){
			pointNums++;
		}
	}
	if(pointNums != 1){
		return false;
	}
	//first char
	if(strString.charAt(0) == strPoint){
		strString = "0" + strString;
	}
	//valid char
	for(i = 0; i<strString.length && blnResult == true; i++){
		strChar = strString.charAt(i);
		if(strValidChars.indexOf(strChar) == -1){
			blnResult = false;
		}
	}
	return blnResult;
}
function checkEmail(val){
	var emailPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if(emailPattern.test(val) == false){
		return false;
	} else {
		return true;
	}
}
function validator_form(){
	var has_error = false;
	var has_warning = false;
	var error_startobj = null;
	if(arguments.length > 0){
		var formname = arguments[0];
		if(typeof(formname) == "string" && document.forms[formname]){
			var form = document.forms[formname];
		} else {
			var form = formname;
			formname = form.name;
		}
		if(typeof(form) == "object"){
			var i;
			var en;
			var ens = Array();
			if(arguments.length == 2 && arguments[1].length > 0){
				ens.push(formname);
				for(i=0; i<arguments[1].length; i++){
					ens.push(arguments[1][i]);
				}
			} else {
				ens = arguments;
			}
			for(i=1; i<ens.length; i++){
				en = ens[i];
				if(form.elements[en] && form.elements[en].value == ""){
					if(error_startobj == null){
						error_startobj = form.elements[en];
					}
					var msg = en + "_msg";
					if($(msg)){
						$(msg).style.display = "";
						has_warning = true;
					}
					has_error = true;
				} else if(form.elements[en] && form.elements[en].value != ""){
					var msg = en + "_msg";
					if($(msg)){
						$(msg).style.display = "none";
					}
				}
			}
			if(has_error){
				if(has_warning == false){
					//alert("Please check the form error!");
					alert("The * Indicates Required Fields.\n\nPlease check the form error!");
				}
				if(error_startobj != null && error_startobj.focus){
					error_startobj.focus();
				}
				return false;
			} else {
				return true;
			}
		} else {
			return false;
		}
		
	} else {
		return true;
	}
	return true;
}
function validator_blur(el){
	if($(el).value == ""){
		var msg = el + "_msg";
		if($(msg)){
			$(msg).style.display = "";
		}
	} else {
		var msg = el + "_msg";
		if($(msg)){
			$(msg).style.display = "none";
		}
	}
}
function validator_null(el){
	if($(el) && $(el).value == ""){
		return true;
	}
	return false;
}
////////////////////////////////////////////////////////////////////////////////////
// D OPERATION
////////////////////////////////////////////////////////////////////////////////////
function dmask(percent){
	if(typeof(percent) == "undefined"){
		percent = 50;
	}
	var element = document.body;
	var objBrother = element.childNodes[0];
	var divObj = document.createElement('DIV');
	
	var ps = getPageSize();
	var width = ps[0];
	var height = ps[1];// + getScrollTop();
	var divObjInnerHTML = '<div style="text-align:center; margin-top:40px;"></div>';
	divObj.setAttribute("id","body_mask");
	divObj.style.textAlign = "center";
	divObj.style.position = "absolute";
	divObj.style.top = "0px";
	divObj.style.left = "0px";
	divObj.style.opacity = (percent / 100);
	divObj.style.MozOpacity = (percent / 100);
	divObj.style.KhtmlOpacity = (percent / 100);
	divObj.style.filter = "alpha(opacity="+percent+")";
	divObj.style.height = height + "px";
	divObj.style.width = width + "px";
	divObj.style.margin = "0px";
	divObj.style.padding = "0px";
	divObj.style.backgroundColor = "#000000";
	
	element.insertBefore(divObj,objBrother);
}
function dremove(el){
	el = $E(el);
	if(el && el.parentNode){
		el.parentNode.removeChild(el);
	}
}
function dshow(el){
	if(el = $E(el)){
		$(el).style.display = "";
	}
}
function dhide(el){
	if(el = $E(el)){
		$(el).style.display = "none";
	}
}
function dtoggle(el){
	if(el = $E(el)){
		if(el.style.display == ""){
			el.style.display = "none";
		} else {
			el.style.display = "";
		}
	}
}
function dtoggleWithImg(el){
	var element = $E(el);
	if(element){
		if(element.style.display == ""){
			element.style.display = "none";
		} else {
			element.style.display = "";
		}
	}
	if($(el+"_img")){
		if($(el+"_img").style.display == ""){
			$(el+"_img").style.display = "none";
		} else {
			$(el+"_img").style.display = "";
		}
	}
}
function dswitch(el){
	if(!$(el+'1') || !$(el+'2') || !$(el+'a')){
		return;
	}
	if($(el+'2').style.display == "none"){
		$(el+'1').style.display = "none";
		$(el+'2').style.display = "";
		$(el+'a').innerHTML = "[hide]"
	} else {
		$(el+'2').style.display = "none";
		$(el+'1').style.display = "";
		$(el+'a').innerHTML = "[...]"
	}
}
function dtabover(i,c,u){
	if($(u+i+'h')){
		if($(u+i+'h').className == "c"){
			$(u+i+'h').className = "cc";
		} else if($(u+i+'h').className == "d"){
			$(u+i+'h').className = "dd";
		}
	}
}
function dtabout(i,c,u){
	if($(u+i+'h')){
		if($(u+i+'h').className == "cc"){
			$(u+i+'h').className = "c";
		} else if($(u+i+'h').className == "dd"){
			$(u+i+'h').className = "d";
		}
	}
}
function dtabclick(i,c,u){
	for(var j=0; j<c; j++){
		if($(u+j+'h')){
			$(u+j+'h').className = "d";
		}
		if($(u+j+'c')){
			$(u+j+'c').style.display = "none";
		}
	}
	$(u+i+'h').className = "c";
	$(u+i+'c').style.display = "";
}
function dselect(obj,a,u){
	for(var k in a){
		var el = $(u+a[k]);
		if(el){
			if(a[k] == obj.options[obj.selectedIndex].value){
				el.style.display = '';
			} else {
				el.style.display = 'none';
			}
		}
	}
}
function dzoomtextarea(e,zoom){
	var zoomsize = zoom ? 10 : -10;
	var obj = $(el);
	if(obj.rows + zoomsize > 0 && obj.cols + zoomsize * 3 > 0){
		obj.rows += zoomsize;
		obj.cols += zoomsize * 3;
	}
}
function dcheckalloption(form,value){
	for(var i = 0; i<form.elements.length; i++){
		var el = form.elements[i];
		if(el.value == value && el.type == 'radio' && el.disabled != true){
			el.checked = true;
		}
	}
}
function dcheckallvalue(form,value,checkall){
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i<form.elements.length; i++){
		var el = form.elements[i];
		if(el.type == 'checkbox' && el.value == value){
			el.checked = form.elements[checkall].checked;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////
// STYLE
////////////////////////////////////////////////////////////////////////////////////
function setFocusStyle(div_id,focus_class){
	if(typeof focus_class == 'undefined'){
		focus_class = "focusElement";
	}
	$(div_id).className = focus_class;
}
function setBlurStyle(div_id,blur_class){
	if(typeof blur_class == 'undefined'){
		blur_class = "blurElement";
	}
	$(div_id).className = blur_class;
}
function setFocus(div_id,inner_html,focus_class){
	if(typeof focus_class == 'undefined'){
		focus_class = "focusElement";
	}
	$(div_id).className = focus_class;
	$(div_id).innerHTML = inner_html;
}
function setBlur(div_id ,blur_class){
	if(typeof blur_class == "undefined"){
		blur_class = "blurElement";
	}
	$(div_id).className = blur_class;
}
////////////////////////////////////////////////////////////////////////////////////
// DIV/HTML
////////////////////////////////////////////////////////////////////////////////////
function appendDIV(pObj,divId,className,innerHTML){
	var divObj = document.createElement("DIV");
	if(className) divObj.className = className;
	//divObj.appendChild(document.createTextNode(text));
	if(IS_IE){
		divObj.id = divId;
	} else {
		divObj.setAttribute("id",divId);
	}
	with(divObj.style){
		//display = 'none';
		position = 'absolute';
	}
	divObj.innerHTML = innerHTML;
	
	pObj.appendChild(divObj);
}
function appendDIVHTML(divId,innerHTML,className){
	var divObj = document.createElement('DIV');
	
	if(IS_IE){
		divObj.id = divId;
	} else {
		divObj.setAttribute("id",divId);
	}
	if(className) divObj.className = className;
	with(divObj.style){
		display = 'none';
		position = 'absolute';
	}
	divObj.innerHTML = innerHTML;
	document.body.appendChild(divObj);
}
function addTableItem(obj,nums){
	var row = obj.parentNode.parentNode;
	var table = row.parentNode;
	var rowindex = row.rowIndex;
	var row_new = table.insertRow(rowindex + 1);
	for(var i=1; i<nums; i++){
		var cell_new = row_new.insertCell(i - 1);
	}
	var cell_new = row_new.insertCell(nums - 1);
	cell_new.innerHTML = row.cells[nums - 1].innerHTML.replace(/(.*)(addTableItem)(.*)(\[)(\+)/i,"$1removeTableItem$3$4-").replace(/(<textarea.*)name="(.*)\[(.*)\]"(.*>)(.*)(<\/textarea>)/,"$1name=\"$2\[\]\"$4$6");
}
function removeTableItem(obj){
	var row = obj.parentNode.parentNode;
	var table = row.parentNode;
	var rowindex = row.rowIndex;
	table.deleteRow(rowindex);
}
function addTableItemB(obj,nums){
	var row = obj.parentNode.parentNode;
	var table = row.parentNode;
	var rowindex = row.rowIndex;
	var row_new = table.insertRow(rowindex + 1);
	for(var i=0; i<nums; i++){
		var cell_new = row_new.insertCell(i);
		if(i == 0){
			cell_new.setAttribute("valign","top");
		}
		cell_new.innerHTML = row.cells[i].innerHTML.replace(/(.*)(addTableItemB)(.*)(\[)(\+)/i,"$1removeTableItemB$3$4-").replace(/(<textarea.*)name="(.*)\[(.*)\]"(.*>)(.*)(<\/textarea>)/,"$1name=\"$2\[\]\"$4$6");
	}
}
function removeTableItemB(obj){
	var row = obj.parentNode.parentNode;
	var table = row.parentNode;
	var rowindex = row.rowIndex;
	table.deleteRow(rowindex);
}
function addOption(obj,value,text){
	var option = document.createElement("OPTION");
	option.value = value;
	option.text = text;
	obj.add(option);
}
function appendOption(obj,value,text){
	var option = document.createElement("OPTION");
	option.value = value;
	option.text = text;
	obj.appendChild(option);
}
function addOptionToDest(src,dest){
	for(var i=0; i<src.length; i++){
		var option = src.options[i];
		if(option.selected && option.value != ''){
			var option_new = option.cloneNode(true);
			option_new.className = '';
			dest.appendChild(option_new);
		}
	}
	src.selectedIndex = -1;
}
function deleteOptionFromDest(dest){
	for(var i=dest.length - 1; i>=0; i--){
		var option = dest.options[i];
		if(option.selected){
			dest.options[i] = null;
		}
	}
}
function joinOptionsToString(obj){
	var list = new Array();
	for(var i=0; i<obj.length; i++){
		list[i] = ojb.options[i].text + "=" + obj.options[i].value;
	}
	return list.join(",");
}
////////////////////////////////////////////////////////////////////////////////////
// POPUP
////////////////////////////////////////////////////////////////////////////////////
function popup(url,title,w,h,l,t){
	//if(!title ) title = 'POPUP WINDOW';
	if(!w ) w = 500;
	if(!h ) h = 500;
	if(!l ) l = 150;
	if(!t ) t = 150;
	var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,';
	f += 'width='+w+',height='+h+',screenX='+l+',screenY='+t+',top='+t+',left='+t;
	var win = window.open(url,'',f);
	//win.focus();
}
function popupWin(url,features,features_add,title){
	if(typeof features == 'undefined'){
		features = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
	}
	if(typeof features_add == 'undefined'){
		features_add = ',width=400,height=400,screenX=50,screenY=50,top=50,left=50';
	} else if(features_add != false){
		
	}
	features = features + features_add;
	if(typeof title == 'undefined'){
		title = 'popupWindow';
	}
	var win = window.open(url,title,features);
	//win.focus();
}
function popupPrintInfo(url){
	popupWin(url,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=600,screenX=50,screenY=50,top=50,left=50',false)
}
function popupWindow(url,w,h){
	if(typeof(w) == "undefined") w = 500;
	if(typeof(h) == "undefined") h = 400;
	if(w<480) w = 480;
	if(h<360) h = 360;
	if(w>600) w = 600;
	if(h>500) h = 500;
	var t = 100;
	var l = 50;
	var win = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',screenX='+l+',screenY='+t+',top='+t+',left='+l)
	//win.focus();
}
////////////////////////////////////////////////////////////////////////////////////
// SIZE
////////////////////////////////////////////////////////////////////////////////////
function isWindows(){
	if(navigator.appName.indexOf("Microsoft") != -1 ) return true;
	return false;
}
function isNetscape(){
	if(navigator.appName.indexOf("Netscape") != -1 ) return true;
	return false;
}
function getOffsetLeft(el){
	var ol = el.offsetLeft;
	while ((el = el.offsetParent) != null)
		ol += el.offsetLeft;
	return ol;
}
function getOffsetTop(el){
	var ot = el.offsetTop;
	while((el = el.offsetParent) != null)
		ot += el.offsetTop;
	return ot;
}
function getScrollX(){
	var scrOfY = 0;
	if(typeof(window.pageXOffset) == 'number'){//Netscape
		scrOfY = window.pageXOffset;
	} else if(document.body && ( document.body.scrollLeft || document.body.scrollTop )){//DOM
		scrOfY = document.body.scrollLeft;
	} else if(document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )){//IE6
		scrOfY = document.documentElement.scrollLeft;
	}
	return scrOfY;
}
function getScrollY(){
	var scrOfY = 0;
	if(typeof(window.pageYOffset) == 'number'){//Netscape
		scrOfY = window.pageYOffset;
	} else if(document.body && ( document.body.scrollLeft || document.body.scrollTop )){//DOM
		scrOfY = document.body.scrollTop;
	} else if(document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )){//IE6
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}
function getWindowSize(){
	var windowWidth,windowHeight;
	if(parseInt(navigator.appVersion) > 3){
		if(navigator.appName == "Netscape"){
			windowWidth = window.innerWidth;
			windowHeight = window.innerHeight;
		} else if(navigator.appName.indexOf("Microsoft") != -1){
			windowWidth = document.body.offsetWidth;
			windowHeight = document.body.offsetHeight;
		}
	}
	
	return new Array(windowWidth,windowHeight);
}
var pageWidth = 800;
var pageHeight = 600;
function getPageSize(){
	var windowWidth,windowHeight;
	if(window.innerHeight){// all except Explorer
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if(document.body){// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var xScroll,yScroll;
	if(window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if(document.body.scrollHeight > document.body.offsetHeight){// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {// Explorer Mac...would also work in Explorer 6 Strict,Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll<windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll<windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	//
	arrayPageSize = new Array(windowWidth,windowHeight,pageWidth,pageHeight);
	
	return arrayPageSize;
}
////////////////////////////////////////////////////////////////////////////////////
// TOOLS
////////////////////////////////////////////////////////////////////////////////////
function addFavorite(url,title){
	if(isUndefined(url) ) url = location.href;
	if(isUndefined(title) ) title = document.title;
	//window.external.addFavorite(url,title);
	if(document.all){
		window.external.addFavorite(url,title);
	} else if(window.sidebar){
		window.sidebar.addPanel(title,url,"");
	}
}
function addBookmark(url,title){  
	if(isUndefined(url) ) url = location.href;
	if(isUndefined(title) ) title = document.title;
	if(window.sidebar){   
		window.sidebar.addPanel(title,url,"");   
	} else if(document.all){  
		window.external.addFavorite( url,title);  
	} else if(window.opera && window.print){  
		return true;  
	}  
}
function copytoBoard(url,content){
	content = content ? content : 'Copy the content successfully!';
	window.clipboardData.setData('text',url);
	alert(content);
}
function h_back(){
	history.go(-1);
}
function h_go(){
	history.go(+1);
}
function goToLink(url){
	//jump to new location
	document.location.href = url;
}
////////////////////////////////////////////////////////////////////////////////////
// MENU
////////////////////////////////////////////////////////////////////////////////////
function cssJsMenu(el){
	if($(el)){
		var root = $(el);
		var a = root.getElementsByTagName("LI");
		
		for(var i=0; i<a.length; i++){
			a[i].onmouseover = function(){
				for(var j=0; j<this.getElementsByTagName("UL").length; j++){
					var elem = this.getElementsByTagName("UL")[j];
					elem.style.position = "absolute";
					elem.style.left = "0px";
					elem.style.top = "27px";
					elem.style.display = "block";
					elem.style.zIndex = "200";
				}
			};
			a[i].onmouseout = function(){
				for(var j=0; j<this.getElementsByTagName("UL").length; j++){
					dhide(this.getElementsByTagName("UL")[j]);
				}
			};
		}
	}
}
function divJsMenu(tm1, tm1s) {
	//
	var tm1 = $(tm1);
	var tm1s = $(tm1s);
	tm1s.style.display = "none";
	//
	var tm1d = document.createElement("DIV");
	tm1d.style.position = "absolute";
	tm1d.style.left = getOffsetLeft(tm1)+"px";
	tm1d.style.top = (getOffsetTop(tm1)+30)+"px";
	//tm1d.style.width = "200px";
	//tm1d.style.height = "200px";
	tm1d.innerHTML = "<ul class=hs>"+tm1s.innerHTML+"</ul>";
	tm1d.style.display = "none";
	tm1d.style.zIndex = "1000";
	tm1d.className = "tmhs";
	document.body.appendChild(tm1d);
	//
	tm1d.onmouseover = function() {
		this.style.display = "block";
	};
	tm1d.onmouseout = function() {
		this.style.display = "none";
	};
	tm1.onmouseover = function() {
		tm1d.style.display = "block";
	};
	tm1.onmouseout = function() {
		tm1d.style.display = "none";
	};
}
////////////////////////////////////////////////////////////////////////////////////
//Window Event
////////////////////////////////////////////////////////////////////////////////////
if(window.Event){
	/*IE8 bug
	window.constructor.prototype.__defineGetter__("event",function(){
			var obj = arguments.callee.caller;
			var eventx;
			while( obj != null){
				eventx = obj.arguments[0];
				if(eventx && (eventx.constructor == Event || eventx.constructor == MouseEvent)){
					return eventx;
				}
				obj = obj.caller;
			}
	   		return null;
		});
	*/
}
if(window.addEventListener){
	window.constructor.prototype.__defineGetter__("event",window_prototype_get_event);
	HTMLElement.prototype.__defineGetter__("runtimeStyle",element_prototype_get_runtimeStyle);
	Event.prototype.__defineGetter__("srcElement",event_prototype_get_srcElement);
}
function element_prototype_get_runtimeStyle(){
	return this.style;
}
function window_prototype_get_event(){
	var obj = arguments.callee.caller;
	var eventx;
	while( obj != null){
		eventx = obj.arguments[0];
		if(eventx && (eventx.constructor == Event || eventx.constructor == MouseEvent)){
			return eventx;
		}
		obj = obj.caller;
	}
	return null;
}
function event_prototype_get_srcElement(){
	return this.target;
}
//Mouse Event
if(navigator.appName == "Netscape"){
	//document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
}
function mouse_prototype_right_mischandler(){
	return false;
}
function mouse_prototype_left_mousehandler(e){
	var eventx = e ? e : event;
	//var eventx = event;
	var eventbutton;
	if(IS_NS){
		eventbutton = eventx.which;
	} else {
		eventbutton = eventx.button;
	}
	if((eventbutton == 2) || (eventbutton == 3)){
		return false;
	}
}
//document.oncontextmenu = mouse_prototype_right_mischandler;
//document.onmousedown = mouse_prototype_left_mousehandler;
//document.onmouseup = mouse_prototype_left_mousehandler;
////////////////////////////////////////////////////////////////////////////////////
// LOAD
////////////////////////////////////////////////////////////////////////////////////
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){oldonload();func();}
	}
}

