var $ = $ || top.$;
//string wrapper
String.prototype.replaceAll = function(search, replace){
	var regex = new RegExp(search, "g");
	return this.replace(regex, replace);
};
String.prototype.trim = function() {
	return this.replace(/(^\s+)|(\s+$)/g, "");
};
//dom wrapper
function getId(id){
	return document.getElementById(id);
}
function getTag(tag, context){
	context = context || document;
	return context.getElementsByTagName(tag);
}
function domReady(func){
	if(domReady.done) return func();
	if(domReady.timer){
		domReady.ready.push(func);
	}else{
		if(window.attachEvent){
			window.attachEvent('onload', isDomReady);
		}else if(window.addEventListener){
			window.addEventListener("load", isDomReady, false);
		}
		domReady.ready=[func];
		domReady.timer=setInterval(isDomReady,13);
	}
};
function isDomReady(){
	if(domReady.done)return false;
	if ( document && document.getElementsByTagName && document.getElementById && document.body ) {
		clearInterval( domReady.timer );
		domReady.timer = null;
		for ( var i = 0; i < domReady.ready.length; i++ )
			domReady.ready[i]();
		domReady.ready = null;
		domReady.done = true;
	}
};
function hasClass(name,tag) {
	var r = [];
	var re = new RegExp("(^|\\s)" + name + "(\\s|$)");
	var e = document.getElementsByTagName(tag || "*");
	for ( var j = 0; j < e.length; j++ )
		if ( re.test(e[j].className) ) r.push( e[j] );
	return r;
}
function getX(e) {
	e = e || window.event;
	return e.pageX || e.clientX + document.body.scrollLeft;
}
function getY(e) {
	e = e || window.event;
	return e.pageY || e.clientY + document.body.scrollTop;
}
function getElementX( e ) {
	return ( e && e.layerX ) || window.event.offsetX;
}
function getElementY( e ) {
	return ( e && e.layerY ) || window.event.offsetY;
}
function getKeyCode(e){
	e = e || window.event;
	return (e.charCode || e.keyCode);
}
function stopBubble(e) {
	e = e || window.event;
	if ( e && e.stopPropagation )
		e.stopPropagation();
	else
		e.cancelBubble = true;
}
function stopDefault( e ) {
	e = e || window.event;
	if ( e && e.preventDefault )
		e.preventDefault();
	else
		e.returnValue = false;
	return false;
}
cookie = function(key, value, options){
	if(typeof value=="undefined"){
		value=null;
		if(document.cookie && document.cookie!=''){
			var arr = document.cookie.split(";");
			for(var i=0;i<arr.length;i++){
				var c = arr[i].trim();
				if (c.substring(0, key.length + 1) == (key + '=')) {
					value = decodeURIComponent(c.substring(key.length + 1));
					break;
				}
			}
		}
		return value;
	}
	options = options || {};
	if(value===null){
		value="";
		options.expires=-1;
	}
	var expires="";
	if(options.expires && (typeof options.expire=="number" || options.expires.toUTCString)){
		var date;
		if(typeof options.expire=="number"){
			date = new Date();
			date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
		}else{
			date = options.expires;
		}
		expires = "; expires=" + date.toUTCString();
	}
	var path = options.path ? '; path=' + (options.path) : '';
	var domain = options.domain ? '; domain=' + (options.domain) : '';
	var secure = options.secure ? '; secure' : '';
	document.cookie = [key, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
function DrawImage(ImgD,iwidth,iheight){
	if(ImgD==null||ImgD.src==null)
		return;
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}			
		}
	}
} 
function globeMSG_valid(targetid,msg,toshow,classname){
	if(resetValidation!=null)
		resetValidation();	
	globeMSG(targetid,msg,toshow,classname);
}
function globeMSG(targetid,msg,toshow,classname){
	try{			
		var obj=document.getElementById(targetid);
		if(classname==null)
			classname="f_red";
		else if(classname=="tishi_t"){
			obj=window.parent.document.getElementById("globe"+targetid);
		}
		if(toshow==false){
			obj.className=classname+" hide";
		}else{
			if(classname!="add_posion")
				obj.innerHTML=msg;
			obj.className=classname;
		}
	}catch(e){}
}
function getParam(key){
	var str = decodeURI(location.search.substring(1));
	if(str=="")return null;
	var arr = str.split("&");
	for(var i=0;i<arr.length;i++){
		if(arr[i].indexOf(key+"=")==0){
			return arr[i].substring(key.length+1);
		}
	}
	return null;
}
function parseDate(str, split){
	if(!str)return null;
	split = split || "-";
	var arr = str.split(split);
	if(arr.length!=3)return null;
	var d = new Date(arr[1] + "/" + arr[2] + "/" + arr[0]);
	return d;	
}
function formatDate(date){
	if(!date)return "";
	var m = date.getMonth() + 1;
	var d = date.getDate();
	if(m < 10) m = "0" + m;
	if(d < 10) d = "0" + d;
	var str = date.getFullYear() + "-" + m + "-" + d;
	return str;	
}
function formatXml(str){
	if(!str)return str;
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}