//點擊切換顯示對像或者隱藏對像
function displayObj(MenuObj){
	MenuObj=document.getElementById(MenuObj);
	if(MenuObj.style.display==''){
		MenuObj.style.display='none';
	}else{
		MenuObj.style.display='';
	}
}

//全選
function CheckAll(form){
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.name != 'chkAll'&&e.disabled==false)
        e.checked = form.chkAll.checked;
    }
}

function CheckListAll(form,operation){
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.name != 'chkAll')
		if(operation==0){
			e.checked = false;
		}else if(operation==2){
			e.checked = !e.checked;
		}else{
			e.checked = true;
		}		
    }
}
//刪除
function confirmsubmit(confirminfo,theform,actionurl){
	if(confirm(confirminfo)){
		if(actionurl!=''){ theform.action=actionurl; }
		theform.submit();
	}else{
		return false;
	}
}


//刪除
function del_submit(theform){
	if(confirm('提醒：你確定要刪除這些數據嗎？')){
		theform.action='del.asp';
		theform.submit();
		theform.action='';
	}else{
		return false;
	}
}

function DelTrue(operform,reurl){
  operform.action=reurl;
  operform.submit();
}

function setcookie(name,value)
{
  var exp=new Date();
  exp.setYear(exp.getYear()+1);
  //編碼：escape();unescape 解碼
  document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
}



function reloadImgSize(imgD,FitWidth,FitHeight){
var image1=new Image();  
image1.onload = function () 
{ 
    if(this.width>0 && this.height>0)  
    {  
        if(this.width/this.height>= FitWidth/FitHeight)  
        {  
            if(this.width>FitWidth)  
            {  
                imgD.width=FitWidth;  
                imgD.height=(this.height*FitWidth)/this.width;  
            }  
            else  
            {  
                imgD.width=this.width;  
                imgD.height=this.height;  
            }  
        }  
        else  
        {  
            if(this.height>FitHeight)  
            {  
                imgD.height=FitHeight;  
                imgD.width=(this.width*FitHeight)/this.height;  
            }  
            else  
            {  
                imgD.width=this.width;  
                imgD.height=this.height;  
            }  
        }  
    } 
    image1 = null; 
} 
image1.src=imgD.src;  
imgD.style.cursor = 'hand';
}


function GetData(OpenUrl,theResultTable){
 var XmlHttp;

 createXmlHttpRequest();
 // 加隨機數防止緩存
 if (OpenUrl.indexOf("?") > 0){
    OpenUrl += "&randnum=" + Math.random();
 }else{
    OpenUrl += "?randnum=" + Math.random();
 }
    XmlHttp.onreadystatechange=function(){
        if(XmlHttp.readyState==4){
            if(XmlHttp.status==200)
            {
              document.getElementById(theResultTable).innerHTML = bytes2BSTR(XmlHttp.responsebody);
            }
		//以下這3行代碼重要,而且位置一定要在這里,釋放內存主要就靠它了,注:這3行代碼的位置一定要在if (4==xmlhttp.readyState){}里,否則無效或效果不好.
		delete XmlHttp ; 
		XmlHttp=null;
		CollectGarbage;
		///////////////////////////////////
        }
    }
    XmlHttp.open("post",OpenUrl,true);
    XmlHttp.send();

function createXmlHttpRequest(){
  if(window.ActiveXObject){
   XmlHttp = new ActiveXObject("Microsoft.XmlHttp");
  }else{
   XmlHttp = new XmlHttpRequest();
  }
} 
}


function readclassselector(clspathSelected,clsdeep,urlfix,selectorfix,selectorobj){
		var geturl='';
		if(clspathSelected==''){
			geturl = "../BBR_AjaxSelector.asp?dt="+selectorobj+"&id=0&df=";
		}else{
			var arrpath = clspathSelected.split('|');
			if(clsdeep==1){
				geturl = "../BBR_AjaxSelector.asp?dt="+selectorobj+"&id=0&df="+arrpath[clsdeep-1];
			}else{
				geturl = "../BBR_AjaxSelector.asp?dt="+selectorobj+"&id="+ arrpath[clsdeep-2] +"&df="+arrpath[clsdeep-1];
			}
		}
		geturl=urlfix+geturl+'&'+Math.random();
		//alert(geturl);
		$.ajax({
			type: "get",
			url: geturl,
			beforeSend: function(XMLHttpRequest){
				//ShowLoading();
			},
			success: function(returndata, textStatus){
				$("#"+selectorobj+"_classselector select:gt("+(clsdeep-2)+")").remove();
				if(returndata!=''){
					$("#"+selectorobj+"_classselector").append('<select name="'+ selectorfix+clsdeep +'"><option value="">請選擇</option>'+ returndata +'</select>');
					$("#"+selectorobj+"_classselector select").eq(clsdeep-1).change(function(){
						var selectedfix='';
						var selectedclsid='';
						for(var j=1;j<clsdeep;j++){
							selectedfix+='|';
						}
						selectedclsid=$(this).val();
						if(selectedclsid==''){
							$("#"+selectorobj+"_classselector select:gt("+(clsdeep-1)+")").remove();
						}else{
							readclassselector(selectedfix+selectedclsid,clsdeep+1,urlfix,selectorfix,selectorobj); 
						}
					});
					if(clspathSelected!=''){ readclassselector(clspathSelected,clsdeep+1,urlfix,selectorfix,selectorobj); }
				}else if(clsdeep==1){
					$("#"+selectorobj+"_classselector").append('<select id="'+ selectorfix+clsdeep +'" name="'+ selectorfix+clsdeep +'"><option value="">請選擇</option></select>');
				}
			},
			complete: function(XMLHttpRequest, textStatus){
				//HideLoading();
			},
			error: function(){
				//ShowError();
			}
		});
	}