//---- Dreamweaver ----
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//---------------------
//---- left menu -----
function is_empty(chk_string){
	if (chk_string==null) return true;
	re = / /gi;
	if (chk_string.replace(re,"")=="") return true;
	return false;
}
function msover(btn_name){
    document.images[btn_name].src=document.images[btn_name].src.substring(0, document.images[btn_name].src.length-6) + "on.gif"
}

function msout(btn_name){
    document.images[btn_name].src=document.images[btn_name].src.substring(0, document.images[btn_name].src.length-6) + "of.gif"
}


function PrintHref(URL, name){
  return ("<a href=" + URL + " target=mainFrame>" + name + "</a>")
}


function SaveMenuStatus(Tree){
	GetOpenStatus(Tree,'QueryForm','ProgramNo');
	popup_small("SaveMenu.asp?program="+QueryForm.ProgramNo.value)
}
//--------------------

function mover(src,color){
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'hand'; 
		src.bgColor = color; 
	} 
	
} 
function mout(src,color){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.bgColor = color; 
	} 
}
function popup_small(url) {	
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=400,height=250");
}

function popup(url) {	
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=600,height=330,top=0");
}

function popup_big(url) {
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=yes,scrollbars=yes,resizable=yes,menubar=no,width=750,height=700,top=0");
}

function popup_size(url, w, h) {
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()
	feature="toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width="+w+",height="+h+",top=0,left=10"
	window.open(url,winname,feature);
}

function DoPopUp(formname,fld,href) {	
	var f = eval("document."+formname);
	var n = fld=="" ? null : eval("document."+formname+"."+fld);	
	var id;
	if(n!=null) {		
		id = n.value;
		href=href + "?" + fld + "=" + id;
		if(id =="" && n != null ){
		  	alert("請至少選取一筆資料!!");
		  	return;
		}
	}
	popup_big(href);
}

function ReloadOpenerAndClose(){
	window.opener.location.reload();
	self.close();
}

function ReloadHistory(ref_url){
	window.location = ref_url
	//self.close();
}

function isWhitespace(dstring){
	re = / /gi;
	if (dstring==null||dstring=="undefined") return true;
	if (dstring.replace(re,"")=="") return true;
	return false;	
}

function popup1(paramFile){
	window.open(paramFile,"","height=270,width=300,resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no");
}

function popup_upload(form,fic,ft,path) {
	window.open("/admin/file_upload/index.asp?form="+form+"&file_item_control="+fic+"&file_type="+ft+"&file_path="+path,"FileUploadWindow","width=320,height=140");
}

function popup_delete(form,fic,ft,path,col,table,sn_col,sn) {
	window.open("/admin/file_upload/delete.asp?form="+form+"&file_item_control="+fic+"&fn="+ft+"&file_path="+path+"&col="+col+"&table="+table+"&sn="+sn+"&sn_col="+sn_col,"FileUploadWindow","width=320,height=140");
}

function field_submit(xform, queryfield) {
	MyObj = eval(xform);

	if (queryfield==MyObj.queryfield.value) {
        	if (MyObj.desc.value=="desc"){
        		MyObj.desc.value="";
        	} else {
        		MyObj.desc.value="desc";
        	}
    	} else { 
    		MyObj.desc.value=""; 
    	}
    
    	MyObj.queryfield.value = queryfield;
    	MyObj.submit();
}

function KeywordSearchResultvalid(xform){
	MyObj = eval(xform);
	if (!checkString(MyObj.keyword,"keyword"))return false;
	else if (!CheckData1(MyObj.keyword))	{
		MyObj.keyword.focus();
		return false;
	}
	else return true; 
}

function KeywordSearchResult(xform){
	MyObj = eval(xform);
    	if (MyObj.keyword.value=="") {
       		MyObj.submit();
    	}
    	else { 
    	if (KeywordSearchResultvalid(xform))	{
        	MyObj.submit();
	}else{
	}
    }
} 

function ChangePage(xform,page)	{
	MyObj = eval(xform);
  	MyObj.page.value = page;
  	MyObj.submit();
}
  
function getall(xform){
    	MyObj = eval(xform);
    	if( MyObj.list_all.value == "1" ){
		MyObj.list_all.value = "0";
	}else{
		MyObj.list_all.value = "1";
	}
    	MyObj.submit();
}

var defaultEmptyOK = false

function checkString (theField, s, emptyOK){
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    	// in equality comparison below.
    	if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    	if (isWhitespace(theField.value)) return warnEmpty (theField, s);
    	else return true;
}

function CheckData1(text2){
	if(text2.value.indexOf("'") != "-1"){
    		alert('輸入值不能有單引號,請重新輸入!!');
    		return false ;
    	}else{
    		return true ;
    	}
}

function SetCheck(xform,allbox,txtbox){
	var txtvalue="" ;
	var txt_box ;
	
	for (var i=0;i<xform.elements.length;i++){
        	var e = xform.elements[i];
          	if ((e.name != allbox) && (e.type=='checkbox') && e.checked ){
          		if (txtvalue != "")
          	  	txtvalue = txtvalue + ";";
			txtvalue = txtvalue + e.value;
          	}
	}
	txt_box=eval("xform."+txtbox);
	txt_box.value=txtvalue;
}

function CheckCheckAll(xform,allbox,txtbox){
	var OnOff ;
	OnOff = eval("xform."+allbox+".checked");

	for (var i=0;i<xform.elements.length;i++)
	{     
          var e = xform.elements[i];

		  if ((e.name != allbox) && (e.type=='checkbox'))
          {
		e.checked = OnOff;
          }
	}
	SetCheck(xform,allbox,txtbox)
}

function SetPageSize(xform){
    MyObj = eval(xform);
    MyObj.PageSize.value = MyObj.OPPageSize.options[MyObj.OPPageSize.selectedIndex].value
    MyObj.submit();
}
function openx(idx){
	if(document.all[idx].style.display == ""){
		document.all[idx].style.display = "none";
	}else{
		document.all[idx].style.display = "";
	}
}
function openy(idx,x){
	if(document.all[idx].style.display == ""){
		for(k=1;k<=x;k++){
			var s = "vio_" + k;
			if(idx == s){
				document.all[s].style.display = "none";
			}else{
				document.all["a_" + k].style.display = "";
				document.all["b_" + k].style.display = "";
			}
		}
	}else{
		for(k=1;k<=x;k++){
			var s = "vio_" + k;
			if(idx == s){
				document.all[s].style.display = "";
			}else{
				document.all["a_" + k].style.display = "none";
				document.all["b_" + k].style.display = "none";
			}
		}
	}
}
