﻿
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    DOM Operation Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function $get(id){
	return document.getElementById(id);	
}

function windowHeight(){
    var a = 0;
    if (typeof window.innerHeight == "number")
        a = window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        a = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight)
        a = document.body.clientHeight;
    if (!a || a < 100)
        a = 100;
    return a
}

function windowWidth(){
    var a = 0;
    if (typeof window.innerWidth == "number")
        a = window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
        a = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth)
        a = document.body.clientWidth;
    if (!a || a < 100)
        a = 100;
    return a
}

function scrollbarWidth(){
    if (navigator.userAgent.indexOf("IE") >= 0){
        var a = document.createElement("div"), b = null;
        a.style.visible = "hidden";
        a.style.overflowY = "scroll";
        a.style.position = "absolute";
        a.style.width = 0;
        document.body.insertAdjacentElement("afterBegin", a);
        b = a.offsetWidth;
        a.parentNode.removeChild(a);
        if (!b)
            b = 16;
        scrollbarWidth = b;
        return b
    }
    else
        return 0
}

function clearAllOptions(elem){
    while(elem.options.length >0)
        elem.options[0] = null;
}

function getAbsolutePosition(e){ 
    if(!e) 
        return null; 
    var t = e.offsetTop; 
    var l = e.offsetLeft; 
    var w = e.offsetWidth; 
    var h = e.offsetHeight;     
    while( e = e.offsetParent){ 
        t += e.offsetTop; 
        l += e.offsetLeft; 
    } 
    return { t: t,  l: l, w: w, h: h }; 
} 

function createFlashObject(ur,w,h){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'"> ');
	document.write('<param name="movie" value="' + ur + '">');
	document.write('<param name="quality" value="high"> ');
	document.write('<param name="wmode" value="transparent"> ');
	document.write('<param name="menu" value="false"> ');
	document.write('<embed src="' + ur + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed> ');
	document.write('</object> ');
}

function createShadow(color, alphaTo){	
	var shield = document.getElementById("shield");
	if(!shield){
		shield = document.createElement("DIV");
		shield.id = "shield";
		document.body.appendChild(shield);
	}
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = 	document.documentElement.clientHeight > document.documentElement.scrollHeight ?
							document.documentElement.clientHeight:
							document.documentElement.scrollHeight;
	shield.style.background = color;
	shield.style.textAlign = "center";
	shield.style.zIndex = 0;
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;		
	
	this.setOpacity = function(obj,opacity){
		if(opacity>=1)opacity=opacity/100;
		try{
			obj.style.opacity=opacity; 									
		}catch(e){}
		try{ 
			if(obj.filters.length>0&&obj.filters("alpha"))		
				obj.filters("alpha").opacity=opacity*100;				
			else
				obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
		}catch(e){}
	}	
	var c = 0;	
	this.doAlpha = function(){	
		c += 2;
		if (c > alphaTo){clearInterval(ad);return 0;}
		setOpacity(shield,c);
	}	
	var ad = setInterval("doAlpha()",1);
}	


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    String Helper Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
String.prototype.trim = function(){
	return this.replace(/^\s*|\s*$/g,"");
}
String.prototype.realLength = function(){
    return this.replace(/[^\x00-\xff]/g,"**").length;
}
String.prototype.left = function(n){
	if (this.length > n)
		return this.substr(0, n) + '...';
	else
		return this;
}
String.prototype.right = function(n){
	if (this.length > n)
		return this.substr(n, this.length);
	else
		return this;
}

function cutStr(s, n){
    s = s || "";
    n = n || 9;
    if(s.length > n)
        s = s.substring(0,n) + "...";
    return s;    
}

function StringBuffer(){
	this._s = new Array;
}
StringBuffer.prototype.append = function(str){
	this._s.push(str);
}
StringBuffer.prototype.toString = function(){
	return this._s.join("");
}
StringBuffer.prototype.reset= function(){
    this._s = null;
	this._s = new Array;
}

 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Language & Browser Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function isZh(){	
    if(typeof __iszh != "undefined")
        return __iszh;
    
    var lang = getParameter("lang");
    if(lang)
        return lang == "zh";
    
    lang = navigator.systemLanguage || navigator.language;
    return  lang.substr(0,2) == "zh";
}

var __dl = isZh();
var __dln = __dl? "zh" : "en";

function dicitiGetPage(p){
    var end = (p.charAt(p.length-1) == "/");
    return (__dl?"/zh-cn/":"/en/") + p + (end?"":".html");    
}


var userAgent = navigator.userAgent.toLowerCase();
var browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Utility Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var isFunction = function(fn){
	return !!fn && typeof fn != "string" && !fn.nodeName &&
		fn.constructor != Array && /^[\s[]?function/.test( fn + "" );
}

function getDateValue(){
    return +(new Date());
    //return (new Date()).valueOf();
}

function getPrefixURL(){
    var str = location.protocol + "//" + location.hostname + ":" + (location.port||80) + "/";
    return str;
}

function fixURL(u){
	if(u.charAt(0) != "/")
		u = "/" + u;
	var str = location.protocol + "//" + location.hostname + ":" + (location.port||80) + u;
	return str;
}

function checkPictureFormat(fileName){
    var rt = ["gif", "jpg", "jpeg", "png"];
    
    var n = fileName.lastIndexOf(".");
    if(n == -1)
        return false;
        
    var fileExt = fileName.substring(n + 1, fileName.length).toLowerCase();
    for(var i=0; i<rt.length; i++)
        if(fileExt == rt[i])
            return true;
    
    return false;
}

function getFileNameFromPath(filePathName){
    if(!(filePathName))
        return "";        
    var pos = filePathName.lastIndexOf("/");
    return filePathName.substring(pos + 1);
}

function getParameter(p){  
	var reg = new RegExp("(^|&)"+ p +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
	    return unescape(r[2]);
	return null;
}


function getInfoByName(obj, poiName){
	var poiRet = null;
	poiName = (poiName || "").trim();
	for(var i=0; i<obj.length; i++){
		var p = obj[i];
		if(p.name == poiName){
			poiRet = p;
			break;
		}	
	}	
	if(!poiRet){
		for(var i=0; i<obj.length; i++){
			var p = obj[i];
			if(p.name.indexOf(poiName) != -1){
				poiRet = p;
				break;
			}	
		}
	}	
	if(!poiRet){
		for(var i=0; i<obj.length; i++){
			var p = obj[i];
			if(poiName.indexOf(p.name) != -1){
				poiRet = p;
				break;
			}	
		}
	}
	return poiRet;
}


function RGB(r, g, b){
	return (r | (g<<8) | (b<<16) );
}




