/*
Copyright (C) 2009-2010, Albert Filella, Gestio i Programes S.L.  All rights reserved.
<info@gestioprogrames.es>
*/

function crearSelect(b,a,c,d){var e=document.createElement("select");a&&e.setAttribute("id",a);c&&e.setAttribute("name",c);d&&e.setAttribute("style",d);for(d=0;d<b.length;d++){a=document.createElement("option");a.setAttribute("value",b[d].valor);c=document.createTextNode(b[d].nombre);a.appendChild(c);e.appendChild(a)}return e}
jQuery.fn.extend({checkToggle:function(b){var a=this.attr("id"),c;c=$("#"+b.id).attr("checked")?true:false;return $("#"+a+" input[type=checkbox]").each(function(){this.checked=c})},checkToggleMod2:function(b){var a=this.attr("id"),c;c=$("#"+b.id).attr("checked")?true:false;return $("#"+a+" tr:visible input:checkbox:enabled").each(function(){this.checked=c})},checkInvToggle:function(){return $("#"+this.attr("id")+" input[type=checkbox]").each(function(){this.checked=this.checked?false:true})},checkTodos:function(){return $("#"+
this.attr("id")+" input[type=checkbox]").each(function(){this.checked=true})},checkNinguno:function(){return $("#"+this.attr("id")+" input[type=checkbox]").each(function(){this.checked=false})},autoFocus:function(){for(var b=0;b<eval("document."+this.attr("name")+".elements.length");b++){var a=eval("document."+this.attr("name")+".elements[i]");if(a.type!="hidden"){a.focus();break}}},soloLeer:function(){this.attr("style","outline:none");this.attr("readOnly",true)},escritura:function(){this.attr("style",
"");this.attr("readOnly",false)},soloLeerToggle:function(){if(this.attr("readOnly")==true){this.attr("style","");this.attr("readOnly",false)}else{this.attr("style","outline:none");this.attr("readOnly",true)}},activa:function(){this.attr("disabled",false)},desactiva:function(){this.attr("disabled",true)},activaToggle:function(){this.attr("disabled")==true?this.attr("disabled",false):this.attr("disabled",true)},resetForm:function(){return this.each(function(){$("input,select,textarea",this).resetFields()})},
resetFields:function(){return this.each(function(){var b=this.type,a=this.tagName.toLowerCase();if(b=="text"||b=="password"||a=="textarea")this.value="";else if(b=="checkbox"||b=="radio")this.checked=false;else if(a=="select")this.selectedIndex=0})}});
