function checkbox_checkall(thisfield,field){
 var tocheck = true;
 tocheck = thisfield.checked;
 var x = 1;
 while(document.getElementById(field+x)!=null){
   document.getElementById(field+x).checked = tocheck;
   x++;
 }
}

function is_checked(field){
var is_checked_bool = false;
var x = 1;
 while(document.getElementById(field+x)!=null){
	 if(document.getElementById(field+x).checked){
	  is_checked_bool = document.getElementById(field+x).checked  
	  break;
	 }
   x++;
 }
 return is_checked_bool;
}

function confirm_delete(flag,field){
 if(flag==1){
  if(is_checked(field)){
	 return true;}
  else {
	   alert('請選擇項目。');
	   return false;}
 }
 
 if(!confirm('確定刪除?'))
	 return false;
 return true;
}


function is_validdate(y,m,d){   

 var date = new Date(y,m-1,d);   
 var convertedDate =  ""+date.getFullYear() + (date.getMonth()+1) + date.getDate();   
 var givenDate = "" + y + m + d;   
 
 return ( givenDate == convertedDate);   
}  



 function showElement(id){

	 document.getElementById(id).style.display = '';
 
 }
 
 function hideElement(id){

	 document.getElementById(id).style.display = 'none';
 
 }
 

 function changeClass(id,classname){
	 	 document.getElementById(id).className = classname;  
 }


function addOption(id,optionid,optiontext){
 document.getElementById(id).options[document.getElementById(id).length] = new Option(optiontext,optionid);
}

function removeOption(id,optionid){
  for (var x=0;x<document.getElementById(id).length;x++) {  
	  if(optionid == document.getElementById(id)[x].id)
         document.getElementById(id).options[x] = null;
  }
}




  function add_rows(id){	 

      var mytable=document.getElementById(id); 

	//  var tnum=document.getElementById(id+'tnum').value;
	  var rowsNum=mytable.rows.length;


	 // var x=parseInt(document.getElementById(id+'total_item').value)+1;
	  var newrow=mytable.insertRow(rowsNum) //add new row to end of table
      newrow.setAttribute("vAlign","top");
      newrow.setAttribute('id',id+rowsNum)
      for (var x=1;x<arguments.length;x++) {
	 
       var newcell=newrow.insertCell(x-1);
       newcell.innerHTML=arguments[x];
	   if(x==1) {
		   
		   newcell.className="fieldname";


	   }
	   else  newcell.className="field";
   	}

    //   document.getElementById(id+'total_item').value=x;

  }


  
  
   function popup_window(url,width,height,title) {

 	msgWindow=window.open(url,'msgWIn','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+width+',height='+height);
	msgWindow.opener = self;
	msgWindow.focus();

}



  function checkTodayDate(fullday){


       var full_day_ar = Array();

	   var year_r = 2009;

   	   var month_r = 1;

	   var day_r = 1;

       if(fullday!='') {

		   full_day_ar = fullday.split("-");

           year_r=  full_day_ar[0];

           month_r = full_day_ar[1];

           day_r = full_day_ar[2];


	   }
	   else {
	   
	   
           year_r=   arguments[1];

           month_r =  arguments[2];

           day_r =  arguments[3];
	   }

		   
	   var myDate=new Date();

	   var today = new Date();

	   myDate.setDate(day_r);

	   myDate.setMonth(parseInt(month_r)-1); // January = 0

	   myDate.setFullYear(year_r); 
  
       var is_today = false;

 

     if( year_r == today.getYear() &&
          month_r == today.getMonth() &&
     	   day_r == today.getDate() )
	  {
	 
	   is_today = true;
	 
	 }


	    if(myDate<today && !is_today) {
		
		//	alert("請選擇今天或以後的日期。");

	        return false;
		}
		else return true;

  }


  function in_array(needle, haystack, argStrict) {
 
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}

 function removeZero(str)
    {
        var i = 0;

 

        while(str.substr(0,1)  == "0" &&  i++ < 100)
            str = str.substr(1) ;

	        return  str;
    } 
