$(document).ready(function(){
	$("#btn_back").click(function(){
		history.go(-1);							  
	});						   
});


/*容器显示与隐藏*/
function showitem(id){
	if($("#"+id).css("display") == "block"){
		$("#"+id).slideUp('fast');
	}else{
		$("#"+id).slideDown('fast');
	}
}

/*
	功能		信息提示
	id		容器ID,如div,span
	msg		提示语
	type	提示类型:0,失败
					1,成功
					2,强调
					3,缓冲	
*/
function showmsg(id,msg,type){
	//成功
	if(type == 1){
		var imgsrc = '/public/images/right.gif';
		var fcolor = '#388130';
	}
	//强调
	else if(type == 2){
		var imgsrc = '/public/images/exclamation.gif';
		var fcolor = '#D97700';
	}
	//失败
	else if(type == 0){
		var imgsrc = '/public/images/error.gif';
		var fcolor = '#FF0000';
	}
	
	//缓冲
	else if(type == 3){
		var imgsrc = '/public/images/loading.gif';
		var fcolor = '#388130';
	}
	
	$('#'+id).html('<img src="'+imgsrc+'" /> <span style="color:'+fcolor+'">'+msg+'</span>');
	$('#'+id).slideDown('fast');
	
	if(type != 3){
		$('#'+id).fadeOut(5000);
	}
}

//选择
function selectValue(oid,value){
	var joid = "#"+oid;	
	var type = $(joid).attr('type');
	if(!type) return ;
	type = type.toLowerCase();
	switch(type){
		case "select-one":
			$(joid).children("option").each(function (n,o){
				//alert(o.value);
				if(o.value == value){
					o.selected = "selected";
				}
			});
			break;
		case "select-multiple":
			var varr = value.split(",");
			var vlength = varr.length;
			$(joid).children("option").each(function (n,o){
				for(var i=0;i<vlength;i++){
					if(o.value == varr[i])
						o.selected = "selected";
				}				
			});
			break;
		case "radio":
			var name = $(joid).attr('name');
			$("[name="+name+"]").each(function (n,o){
				if(o.value == value){
					o.checked = "checked";
				}
			});
			break;
		case "checkbox":		
			var varr = value.split(",");
			var vlength = varr.length;
			var name = $(joid).attr('name');
			$("[name="+name+"]").each(function (n,o){
				for(var i=0;i<vlength;i++){
					if(o.value == varr[i])
						o.checked = "checked";
				}	
			});
			break
		default:
			alert("对象 "+ oid + " 的 type 属性不存在!");
	}
}


function getTextByValue(id,sel){
	for(var i=0;i<document.getElementById(id).length;i++){
		if(document.getElementById(id)[i].value== sel){
			return document.getElementById(id)[i].text;
			break;
		}
	}
}

function getValueByText(id,sel){
	for(var i=0;i<document.getElementById(id).length;i++){
		if(document.getElementById(id)[i].text == sel){
			return document.getElementById(id)[i].value;
			break;
		}
	}
}


var  highlightcolor='#c1ebff';
//此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行
var  clickcolor='#51b2f6';
function changeto(){
	source=event.srcElement;
	if  (source.tagName=="TR"||source.tagName=="TABLE")
	return;
	while(source.tagName!="TD")
	source=source.parentElement;
	source=source.parentElement;
	cs  =  source.children;
	//alert(cs.length);
	if  (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
	for(i=0;i<cs.length;i++){
		cs[i].style.backgroundColor=highlightcolor;
	}
	}
	
	function  changeback(){
	if  (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
	return
	if  (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
	//source.style.backgroundColor=originalcolor
	for(i=0;i<cs.length;i++){
		cs[i].style.backgroundColor="";
	}
}

function  clickto(){
	source=event.srcElement;
	if  (source.tagName=="TR"||source.tagName=="TABLE")
	return;
	while(source.tagName!="TD")
	source=source.parentElement;
	source=source.parentElement;
	cs  =  source.children;
	//alert(cs.length);
	if  (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
	for(i=0;i<cs.length;i++){
		cs[i].style.backgroundColor=clickcolor;
	}
	else
	for(i=0;i<cs.length;i++){
		cs[i].style.backgroundColor="";
	}
}

function gb2312(key){
	var r = "";
	for(var i=0;i<key.length;i++){
    	var t = key.charCodeAt(i);
        if(t>=0x4e00 || t==0x300A || t==0x300B){
        	try{
            	execScript("ascCode=hex(asc(\""+key.charAt(i)+"\"))", "vbscript"); r += ascCode.replace(/(.{2})/g, "%$1"); 
			}
            catch(e){}
        }else{
			r += escape(key.charAt(i))
		}
    }
	return r;
}