// JavaScript Document
var NORECORD_DELETE = "Hãy chọn bản ghi để xóa!.";
var SURE = "Bạn đã chắc chắn?";

function toggleSelect(state,relCheckName) {
	//alert(relCheckName);
	//var a = document.getElementById(relCheckName);
	//alert(a);
	//alert('manhtl');
	var test =  getObj(relCheckName);
	//alert(test.length);
	if (test) {
		//alert(getObj(relCheckName).length);
		if (typeof(test.length)=="undefined") {
			test.checked=state;
		} else {
			//alert(test);
			for (var i=0;i<test.length;i++)
				test[i].checked=state;
		}
	}
}

function toggleSelectAll(relCheckName,selectAllName) {
	//alert(relCheckName);
	if (typeof(getObj(relCheckName).length)=="undefined") {
		getObj(selectAllName).checked=getObj(relCheckName).checked
	} else {
		var atleastOneFalse=false;
		for (var i=0;i<getObj(relCheckName).length;i++) {
			if (getObj(relCheckName)[i].checked==false) {
				atleastOneFalse=true
				break;
			}
		}
		getObj(selectAllName).checked=!atleastOneFalse
	}
}

function getObj(n,d) {

  var p,i,x; 
  if(!d)

      d=document;

   
   if(n != undefined)
   {
	   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){
		//alert('1');
      x=d.all[n];
  }
 

  for(i=0;!x&&i<d.forms.length;i++){
	  
	//alert('2');
      x=d.forms[i][n];

  }

  for(i=0;!x&&d.layers&&i<d.layers.length;i++){
	//alert('3');
      x=getObj(n,d.layers[i].document);

  }

  if(!x && d.getElementById){
	//alert('4');
      x=d.getElementById(n);
  }


  return x;

}

function massDelete(module, page)
{
    x = document.list.check_id.length;
    idstring = "";
    if ( x == undefined)
    {
        if (document.list.check_id.checked)
        {
            idstring=document.list.check_id.value;
        }
        else
        {
            alert(""+NORECORD_DELETE);
            return false;
        }
    }
    else
    {
        
        xx = 0;
        for(i = 0; i < x ; i++)
        {
            if(document.list.check_id[i].checked)
            {
                  //alert(document.list.check_id[i].value);
				  if(idstring=="")
				  	idstring = document.list.check_id[i].value;
				  else
				  	idstring = document.list.check_id[i].value +","+idstring;
                  xx++;
            }
        }
        if (xx == 0)
        {
            alert(""+NORECORD_DELETE);
            return false;
        }
    }
   if (confirm(""+SURE))
    {
        //alert("authenticate/login/module/"+module+"/action/del?page="+page+"&idList="+idstring);
		//alert(module);
		document.location.href=module+"/page/"+page+"/idList/"+idstring;
    }
    else
    {
        return false;
      
    }
}

function deleteOne(module, page, id) {
	if (confirm(""+SURE))
    {
		document.location.href=module+"/page/"+page+"/idList/"+id;
    }
    else
    {
        return false;
      
    }
}
function actionSelect(url){
	document.location.href="df";
}