/*======================================
通用js处理代码，create by lightman,2006-9
========================================*/

var imageObject;
//显示图片时重新调整图片高宽函数，调用如<img src="file" onload="ResizeImage(this,200,160)">
function ResizeImage(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if(state!='complete') {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
		if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW; b=dH/MaxH;
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}
//取得url参数
function GetRequest()
{
 var url = location.search; //获取url中"?"符后的字串
 var theRequest = new Object();
 if(url.indexOf("?") != -1)
 { 
  var str = url.substr(1);
  strs = str.split("&");
  for(var i = 0; i < strs.length; i ++)
  { 
   theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
  }
 }
return theRequest;
}
//取得字节长度
function GetByteLength(str) {
	if (str == null) return 0;
	var l = str.length;
	var blen = 0;
	for(i=0; i<l; i++) {
		if ((str.charCodeAt(i) & 0xff00) != 0) {
			blen ++;
		}
		blen ++;
	}
	return blen;
}
//弹出居中显示窗口函数，列:<a href="javascript:" onclick="popUpWin('http://www.houyi.com',300,200,'')">弹出后翼</a>
function popUpWin (url, win, width, height, options) {
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	//var aa = window.open("about:blank",win,options);
	//alert(aa);
	//aa.location.replace(url);
	//aa.focus();
	return window.open(url, win, options);
	//return window.open(url, win, options);
}
//正则表达式检测值的格式是否符合要求
function regExCheck(patn,o,errid,errmsg){
	var showmsg="",ret=1;
	var obj;
	if(!patn.test(o.value)){
		 showmsg=errmsg;
		 ret=0;
		}
	try{
		obj=document.getElementById(errid);
		if(obj){
			obj.innerHTML=showmsg;
		}
		else alert(showmsg);
	}catch(e){}
	return ret;
}
//显示隐藏内容处理
var shm;
function showhidemenu(id,me,icoopen,icoclose){
 var menu=document.getElementById(id)
// if(isNaN(menu.dheight)){ modify by 2006-10-26
	 if(menu.style.display=="none"){
	 menu.style.display="";
	 menu.dheight=menu.scrollHeight;
	 menu.style.height="0px";
	 menu.style.display="none";}
	 else
	 	menu.dheight=menu.scrollHeight;
// }
 if(menu.style.height.match("\\S")==null) menu.style.height=menu.dheight+"px";
 if(shm)return;
 showhidespeed=6;
 if(menu.style.display=="none"){
	menu.style.display="";
	if(me)if(icoopen.indexOf(".")>=0) document.getElementById(me).src=icoopen;else document.getElementById(me).innerHTML=icoopen;
	shm=setInterval("scrollsh('"+id+"',1)",20);
 }
 else{
	if(me)if(icoclose.indexOf(".")>=0) document.getElementById(me).src=icoclose;else document.getElementById(me).innerHTML=icoclose;
	shm=setInterval("scrollsh('"+id+"',0)",20);
 }
}

function scrollsh(id,n){
  var menu=document.getElementById(id);
	var h;
	h=parseInt(menu.style.height);
	if(n==1){
	 h+=showhidespeed+=6;
	 h=h>menu.dheight?menu.dheight:h;
	 menu.style.height=h+"px";
	 if(h>=menu.dheight){menu.style.height="";clearInterval(shm);shm=false;try{showscroll();}catch(e){}}
	}else{
	 h-=showhidespeed+=6;
	 h=h<0?0:h;
	 menu.style.height=h+"px";
	 if(h<=0){menu.style.display="none";clearInterval(shm);shm=false;try{showscroll();}catch(e){}}
	}
}
/*================================
函数名: Question
功  能：询问是否执得指定命令
参  数: str 询问文字符串 cmd命令字符串
返回值: 无
===================================*/
function Question(str,cmd){
 if (confirm(str)){
  if(cmd)eval(cmd);
  return true;
 }
 return false;
}

function timegotourl(i,target,url){
if (i<=0) eval(target).location.href=url;
else{ setTimeout("timegotourl("+(--i)+",'"+target+"','"+url+"')",1000);try{document.getElementById("showtime").innerHTML=i;}catch(e){}}
}

function AjaxgetContent(url,callbak){
      var xmlhttp=CreateXMLHttpRequest();
	  xmlhttp.onreadystatechange=function getok(){
	   if(xmlhttp.readyState==4){
		   window.AjaxContent=xmlhttp.responseText;
		   eval(callbak+"()");
	   }
	  }
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	  xmlhttp.send(true);
	}
/*==========================
类名：CreateXMLHttpRequest
功能：创建一个xmlhttp对象
===========================*/
function CreateXMLHttpRequest() {
	var xmlhttp=false;
	if (window.ActiveXObject) { //IE浏览器创建xmlhttp对象
		for(var i=5;i;i--)	{
			try{
				if (i==2) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				else if(i==1) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				else xmlhttp = new ActiveXObject("MSXML2.XMLHTTP."+i+".0");
				break;
			}
			catch(e){
				xmlhttp = false;
			}
		}
	}else if (window.XMLHttpRequest){ //Mozella系列浏览器建立xmlhttp对象
		try{
		xmlhttp = new XMLHttpRequest();
		}catch(e) {xmlhttp = false;}
	}
	return xmlhttp;
}
function getXMLdocument(){
	var xDoc=null;
	if(document.implementation&&document.implementation.createDocument){
		xDoc=document.implementation.createDocument("","",null);
	}
	else if(typeof ActiveXObject != "undefined"){
		try{
			xDoc=new ActiveXObject("Msxml2.DOMDocument");
			}catch(e){
			xDoc=new ActiveXObject("Msxml.DOMDocument");
		}
	}
	if(xDoc==null||typeof xDoc.load=="undefined") xDoc=null;
	return xDoc;
}
/*==========================
类名：FormToRequestString
功能：返回表单值到请求字符串
===========================*/
function FormToRequestString(form_obj){
	var query_string="";
	var and="";
	var e,element_value="";
	for (i=0;i<form_obj.length;i++ )
	{
		e=form_obj[i];
		element_value="";
		if (e.name!=''){
			if (e.type=='select-one'){
				element_value=e.options[e.selectedIndex].value;
			}
			else if (e.type=='checkbox' || e.type=='radio')
			{
				if (e.checked==false) continue;
				element_value=e.value;
			}
			else element_value=e.value;
		}
		query_string+=and+e.name+'='+qswhEncodeURI(element_value);
		and="&";
	}
	return query_string;
}
function qswhEncodeURI(str){
/************(qiushuiwuhen 2002-6-19)***************/
	var m="",sp="!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
	for(var i=0;i<str.length;i++){
		if(sp.indexOf(str.charAt(i))!=-1){
			m+=str.charAt(i)	
		}else{
			var n=str.charCodeAt(i)
			var t="0"+n.toString(8)
			if(n>0x7ff)
				m+=("%"+(224+parseInt(t.slice(-6,-4),8)).toString(16)+"%"+(128+parseInt(t.slice(-4,-2),8)).toString(16)+"%"+(128+parseInt(t.slice(-2),8)).toString(16)).toUpperCase()
			else if(n>0x7f)
				m+=("%"+(192+parseInt(t.slice(-4,-2),8)).toString(16)+"%"+(128+parseInt(t.slice(-2),8)).toString(16)).toUpperCase()
			else
				m+=("%"+("0"+n.toString(16)).slice(-2)).toUpperCase()
		}
	}
	return m;
}

//复选表单全选事件 form：表单名
function CheckAll(me,formn)  {
	for (var i=0;i<me.form.elements.length;i++)
	{
		var e = me.form.elements[i];
		if (e.name == formn&&e.type=="checkbox")
		{
			e.checked = me.checked;
		}
	}
}

//文本编辑框大小调整
function arearesize(id,type,size,smin,smax){
	try{
		var area=document.getElementById(id);
		if(type==0){
			if(!smin&&!smax)area.cols+=size;
			else if(smin&&smax){if(area.cols+size>smin&&area.cols+size<smax)area.cols+=size}
			else if(smin){if(area.cols+size>smin)area.cols+=size;}
			else if(smax){if(area.cols+size<smax)area.cols+=size;}}
		else{
			if(!smin&&!smax)area.rows+=size;
			else if(smin&&smax){if(area.rows+size>smin&&area.rows+size<smax)area.rows+=size}
			else if(smin){if(area.rows+size>smin)area.rows+=size;}
			else if(smax){if(area.row+size<smax)area.row+=size;}}
	}catch(e){}
}
//设置id的内容
function setinner(id,v){
  try{
	  document.getElementById(id).innerHTML=v;
	  }catch(e){}
}
//显示样试控制函数
function set_fontsize(id,size){
	try{
		document.getElementById(id).style.fontSize=size+"px";
		}catch(e){}
	}

/*以下是jquery相关的代码*/

//kuomart.com 菜单显示
function showd(num){
	if($("#direct_2").attr("num")!=num){
		$("#direct_2").children().hide();
		$("#d2_"+num).show();
		$("#d1_"+$("#direct_2").attr("num")).removeClass();
		$("#d1_"+num).addClass("mouseover");
		$("#direct_2").attr("num", num);
	}
}
//非IE浏览器禁止粘贴
function fncKeyStop(evt)
{
    if(!window.event)
    {
        var keycode = evt.keyCode; 
        var key = String.fromCharCode(keycode).toLowerCase();
        if(evt.ctrlKey && key == "v")
        {
          evt.preventDefault(); 
          evt.stopPropagation();
        }
    }
}

function gotourl(url){
	location.href=url;
}

function WB_CloseItemWindow() {
	window.close();
};

function BK_OpenWindow(url,name,attr){
	if(name&&attr){
		window.open(url,name,attr);
	}else if(name){
		window.open(url,name);
	}else if(attr){
		window.open(url,'',attr);	
	}else{
		window.open(url);	
	}
}

function BK_Click(achor){
	var d=document,edita=d.getElementById(achor);
	if(document.all){
		edita.click();
	}else{
		var evt = document.createEvent("MouseEvents"); 
		evt.initEvent("click",true,true);  
		edita.dispatchEvent(evt);  
	}
}
//交换显示
function swapshowId(id,id1){
	if($("#"+id).css('display')=='none'){
		$("#"+id).show();$("#"+id1).hide();
	}else{
		$("#"+id).hide();$("#"+id1).show();
	}		
}