var isIE = (document.all) ? true : false;

var $ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};
var $$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

//********** 用来控制菜单和显示和隐藏

function ShowSub(sid)
{
	var obj = $$(sid);
	var parentUL = obj.parentNode.parentNode;
	var oldstatus = obj.style.display;
//		 trace(parentUL.childNodes[0].childNodes[0].innerHTML);
//		 trace(parentUL.childNodes[0].childNodes[1].innerHTML);
//		 trace(parentUL.childNodes[0].childNodes[2].innerHTML);
		// alert(parentUL.childNodes[0].childNodes[i].style.display = 'none');
	//return ;
	for(var i = 0; i < parentUL.childNodes.length; i ++)
	{	
		if("UL" == parentUL.childNodes[i].tagName){
			 parentUL.childNodes[i].style.display = 'none';
		}	

		for(var j = 0 ; j < parentUL.childNodes[i].childNodes.length; j ++)
		{
			//trace();
			if("UL" == parentUL.childNodes[i].childNodes[j].tagName){
				 parentUL.childNodes[i].childNodes[j].style.display = 'none';
			}
		}
			
		 //alert(parentUL.childNodes[i].childNodes[i].style.display = 'none');
		// parentUL.childNodes[i].childNodes[i].style.display = 'none';
	}
	if(oldstatus == 'none')
	{
		obj.style.display='';
	}
	else
	{
		obj.style.display='none';
	}
};


if(!isIE){
	HTMLElement.prototype.__defineGetter__("currentStyle", function () {
		return this.ownerDocument.defaultView.getComputedStyle(this, null);
	});
}

function getStyleWidth(obj)
{
	if(!obj) return;
	var w =obj.currentStyle.width? obj.currentStyle.width:null;
	w = obj.style.width ? obj.style.width : w;
	if(!w || w == 'auto'){
		w = obj.offsetWidth ? obj.offsetWidth : null;
	}
	w = parseInt(w);
	return w;
}
function getStyleHeight(obj)
{
	if(!obj) return;
	var h =obj.currentStyle.height? obj.currentStyle.height:null;
	h = obj.style.height ? obj.style.height : h;
	if(!h || h == 'auto'){
		h = obj.offsetHeight ? obj.offsetHeight : null;
	}
	w = parseInt(h);
	return h;
}
function getStyleMarginWidth(obj)
{
	if(!obj) return;
	var w =obj.currentStyle.marginLeft? obj.currentStyle.marginLeft:0;
	w = obj.style.marginLeft ? obj.style.marginLeft : w;
	w = obj.currentStyle.marginRight ? w + obj.currentStyle.marginRight : w ;
	w = obj.style.marginRight ? w + obj.style.marginRight : w ;
	w = parseInt(w);
	return w;
}
function getStyleMarginHeight(obj)
{
	if(!obj) return 0;
	var w =obj.currentStyle.marginTop ? obj.currentStyle.marginTop :0;
	w = obj.style.marginTop  ? obj.style.marginTop  : w;
	w = obj.currentStyle.marginBottom ? w + obj.currentStyle.marginBottom : w ;
	w = obj.style.marginBottom  ? w + obj.style.marginBottom  : w ;
	w = parseInt(w);
	return w;
}


function trace(str)
{
	if(! document.getElementById('DebugBox')) return;
	document.getElementById('DebugBox').value += str + '\n';	
}
/******************************************************************
* URI 管理类。
* 一个URI分成两部分：URL和QueryString，这里主要是对后者进行管理。
* 默认以?打头，但是可以修改Url变量组成完成的URI
* .Url变量：设置跳转地址。
* .Add(name,key)  添加变量
* 主要的方法是getURI()，g()是前一个方法的简洁写法，另外重写了toString()(继承自Object）
******************************************************************/
function URI(){
	var _this = this;		//防止类成员的this和类本身的this混淆，所以在类成员的代码段里有_this来引用。
	var str = '?';			//var打头，可以当作private用
	this.Url = '';			//this打头，可以当作public用
	this.Add = function(str1,str2)
	{
		if(str == '?')
		{
			str += str1 + '=' + str2;
		}
		else
		{
			str += '&' + str1 + '=' + str2;
		}
	}
	this.toString = function()
	{
		return _this.getURI();
	}
	this.getURI = function(){
		return _this.Url + str;
	}
	//------------  下面这种不行！
	//this.g = this.getURI();
	this.g = function(){ //getURI()简写作g()
		return _this.getURI();
	}
}

function ResizeImg(obj,Predict_w,Predict_h)
{
	if(!obj) return;
	//predict  预言；预告；预示；预报；预计：
	//预计的比率
	var r1 = Predict_w/Predict_h;
	var w = obj.width;
	var h = obj.height;
	//实际的比率
	var r2 = w/h;		
	//window.status = "w:" + w + " h:" + h;
	if(r2 == 1){
		if(w<Predict_w){return;}
		obj.width = Predict_w;
		if(obj.parentNode.tagName != "A")
		{
			obj.onclick=function(){window.open(obj.src,'','');};
			obj.onmouseover=function(){this.style.cursor='hand';};
			obj.alt = "点击查看大图!";
		}
		return;
	}
	if(r2>=r1){
		if(w <= Predict_w){return;}
		obj.width = Predict_w;
		obj.height = Predict_w / r2;
	}else{
		if(h <=Predict_h){return;}
		obj.height = Predict_h;
		obj.width = Predict_h * r2;
	}	
	if(obj.parentNode.tagName != "A")
	{
		obj.onclick=function(){window.open(obj.src,'','');};
		obj.onmouseover=function(){this.style.cursor='hand';};
		obj.alt = "点击查看大图!";
	}
}

function SetSelecterByHide(id)
{
	var id_hide = id+"_hide";
	if($$(id)  && $$(id_hide))
	{
		getValueFormHidden($$(id), $$(id_hide));
	}
}
function getValueFormHidden(s,s_hide)
{
	if(s_hide.value!=""){
		for(i=0;i<s.length;i++){
			if(s.options[i].value==s_hide.value){
				s.selectedIndex=i;
			}
		}
	}
}

function getRequestQueryString(key) {
    var QueryString = location.search;
    if (QueryString.indexOf("?") != -1) {
        var str = QueryString.substr(1);
        var arr = str.split("&");
        for (var i = 0; i < arr.length; i++) {
            if (key == arr[i].split("=")[0]) {
                return arr[i].split("=")[1];
            }
        }
    }
    return null;
}
