/**
 * Este script forma parte de
 * ZULKY Framework para Desarrollo Empresarial
 * Copyright (c) 2009 Ignacio Casinelli Esviza
 */
var tiempoEfectos = 0.25;
waitBoxAndando = false;
String.prototype.trim=function(){return this.replace('/^\s+|\s+$/g',"");}
String.prototype.pad=function(l,s,t){return s||(s=" "),(l-=this.length)>0?(s=new Array(Math.ceil(l/s.length)+1).join(s)).substr(0,t=!t?l:t==1?0:Math.ceil(l/2))+this+s.substr(0,l-t):this;}
function zSubmit(f){if($('usoBotones').value=="0"){return false;}return true;}
function zAtras(){history.back(1);}
function zGet(m,a,o){cargando();o=(o==null?"":o);document.location="?m="+m+"&a="+a+"&usoBotones=1&"+o;}
function zValidarRequerido(e,l){var o=document.getElementById(e);var k=true;if(o.value.trim().length==0){alert('Debe proporcionar un valor para '+l);o.focus();k=false;}return k;}
function zSetAccion(m,a){$('m').setValue(m);$('a').setValue(a);}
function zLimpiarAccion(){$('m').setValue("");$('a').setValue("");}
function zPost(m,a,t){if(t!=null){if(!confirm(t))return;}cargando();zSetAccion(m,a);$('usoBotones').value="1";document.form.submit();}
function zPostBack(e){$('postBack').value=(e==null?"1":$(e).id);cargando();$('usoBotones').value="1";document.form.submit();}
function zPostUrl(u){$('form').action=u;document.form.submit();}
function borrar(u){zConfirm("Confirma que desea eliminar el elemento?",u);}
function zConfirm(m,u){if(!confirm(m)){return false;}document.location=u;}
function isdefined(v){return(typeof(window[v])=="undefined")?false:true;}
function alternar(e){var o=document.getElementById(e);o.style.display=o.style.display=="none"?"":"none";return o.style.display;}
function zOcultar(e){$(e).hide();}
function zMostrar(e){$(e).show();}
function mover(d,h){d=$(d);h=$(h);if(d.length==0){alert("No hay elementos que mover.");return false;}if(d.selectedIndex==-1){alert("Debe marcar un elemento para mover.");return false;}for(var i=0;i<d.length;i++){if(d.options[i].selected){var x=document.createElement("option");x.value=d.options[i].value;x.text=d.options[i].text;h.add(x);}}for(i=d.length-1;i>=0;i--){if(d.options[i].selected){d.remove(i);}}}
function alternarIcono(i,o,m,n){i=$(i);o=$(o);i.src=o.style.display=="none"?m:n;}
function stringValoresSelect(d){d=$(d);var s="";for(var i=0;i<d.length;i++){s=(s==""?"":s+",")+d.options[i].value;}return s;}
function implode(t,d){d=$(d);var s="";for(var i=0;i<d.length;i++){if(s!="")s=s+t;s=s+d.options[i].value;}return s;}
function vacio(e){e=$(e);if(e.value==""){e.focus();}}
function zFiltrar(m,a){document.form.usarFiltro.value="1";document.form.usoBotones.value="1";zPost(m,a);}
function zDespachar(m,a){zPost(m,a);}
function zGetConAjax(e,m,a,x,r,v,b){cargando();if(x==null){x=$('form').serialize();}
	new Ajax.Updater(e,"?",{
		parameters:x+"&m="+m+"&a="+a+"&conAjax=true",
		evalScripts:true,
		method:"get",
		encoding:"utf-8",
		contentType:"application/x-www-form-urlencoded; charset=utf-8",
		onComplete:function(){new Effect.Highlight($(e),{duration:tiempoEfectos,queue:'end'});if(r!=null)new Element.scrollTo($(r));if(waitBoxAndando)chauModalBox();chauCargando();if(v!=null)$(v).show();if(b!=null)b();}});
}
function zPostConAjax(e,m,a,x,r,v,b){cargando();if(x==null){zSetAccion(m,a);x=$('form').serialize();}else{x=x+"&m="+m+"&a="+a;}
	new Ajax.Updater(e,"?",{
		parameters:x+"&conAjax=true",
		evalScripts:true,
		method:"post",
		encoding:"utf-8",
		contentType:"application/x-www-form-urlencoded; charset=utf-8",
		onComplete:function(){new Effect.Highlight($(e),{duration:tiempoEfectos,queue:'end'});if(r!=null)new Element.scrollTo($(r));if(waitBoxAndando)chauModalBox();chauCargando();if(v!=null)$(v).show();if(b!=null)b();}});
}
function zRequerir(e){if($(e).value.blank()){$(e).focus();alert("Debe proporcionar un valor para "+zGetLabelFor(e));return false;}return true;}
function zGetLabelFor(e){var l=document.getElementById(e).parentNode.getElementsByTagName('LABEL');for(var i=0;i<l.length;i++){if(l[i].htmlFor==e){return l[i].innerHTML;}}return "";}
function getKeynum(e){var k;if(window.event){k=e.keyCode;}else if(e.which){k=e.which;}return k;}
function getKeyChar(e){return String.fromCharCode(getKeynum(e));}
function zfxDesplegar(e,r){e=$(e);if(!e.visible()){new Effect.BlindDown(e,{duration:tiempoEfectos,queue:'end'});}if(r!=null)new Element.scrollTo(e);}
function zfxContraer(e){e=$(e);if(e.visible()){new Effect.BlindUp(e,{duration:tiempoEfectos,queue:'end'});}}
function zfxAlternar(e,s){o=$(e);if(o.visible()){zfxContraer(o);}else{zfxDesplegar(o,s);}}
zPintarFilas=function(o){var f=o.rows;var i=1;for(j=1;j<f.length;j++){if(i==1){f[j].addClassName("impar");i=0;}else{f[j].addClassName("par");i=1;}}}
zAlternarFila=function(e){if($(e).hasClassName("seleccionFila")){$(e).removeClassName('seleccionFila');}else{$(e).addClassName("seleccionFila");}}
combo_change=function(e){var id=$(e).id.substr(0,$(e).id.length-2)+"nombre";if($(e).value==-1){$(id).show();$(id).focus();}else{$(id).hide();}}
comboFecha_change=function(id){$(id).value=$(id+'Dia').value.pad(2,"0",2)+"/"+$(id+'Mes').value.pad(2,"0",2)+"/"+$(id+"Anio").value;}
clipCopy=function(d){clipboardData.setData('text',d);}
zHtmlWrite=function(x,y){$(x).innerHTML=y;};
format = function(x,d){var s=""+Math.round(eval(x)*Math.pow(10,d));while(s.length<=d){s="0"+s;}var p=s.length-d;return s.substring(0,p)+"."+s.substring(p,s.length);}
editorHtmlFull = function(){
	tinyMCE.init({
		mode : "textareas",
		editor_selector: "mce_editable",
		theme : "advanced",
		plugins : "style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,pagebreak,imagemanager,filemanager",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,iespell,media,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,spellchecker,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		content_css : "/example_data/example_full.css",
	    plugin_insertdate_dateFormat : "%Y-%m-%d",
	    plugin_insertdate_timeFormat : "%H:%M:%S",
		external_link_list_url : "example_data/example_link_list.js",
		external_image_list_url : "example_data/example_image_list.js",
		flash_external_list_url : "example_data/example_flash_list.js",
		template_external_list_url : "example_data/example_template_list.js",
		theme_advanced_resize_horizontal : true,
		theme_advanced_resizing : true,
		apply_source_formatting : true,
		spellchecker_languages : "+Spanish=es,English=en"
	});
}
quitarSeleccionado=function(e){if(e.length==0){alert("No hay elementos que quitar.");return false;}if(e.selectedIndex==-1){alert("Debe marcar un elemento para quitar.");return false;}for(var i=e.length-1;i>=0;i--){if(e.options[i].selected){e.remove(i);}}}
tieneElementoText=function(o,t){var x=false;for(var j=0;j<o.length;j++){if(o.options[j].text==t){x=true;break;}}return x;}
zDiasEntre=function(d,h){return Math.floor(Math.abs(h.getTime()-d.getTime())/(1000*60*60*24))+1;}
tomarFechaDeCombo=function(e){return new Date($(e+"Anio").value,$(e+"Mes").value,$(e+"Dia").value);}
actualizaMasMenos=function(e,i,d,m,n){var o=$(e);var a=parseFloat(o.value);d=isNaN(d)?0:d;a=isNaN(a)?0:a;if(i>0){if(m!=null){a=a+i>m?a:a+i;}else{a+=i;}}if(i<0){if(n!=null){a=a+i<n?a:a+i;}else{a+=i;}}o.value=d==0?a:format(a,d);}
waitBox=function(){msgBoxReset();$('txtMsgBox').update('Procesando...<div id="divMsgBoxSpinner"></div>');$('divMsgBoxSpinner').show();waitBoxAndando=true;Modalbox.show($('divMsgBox'),{overlayClose:false,closable:false,title:'Procesando...',width:400});}
msgBoxReset=function(){$('txtMsgBox').update('');$('divMsgBoxAceptar').hide();$('divMsgBoxSiNo').hide();chauCargando();}
msgBox=function(t,b){msgBoxReset();$('txtMsgBox').update(t);$('divMsgBoxAceptar').show();Modalbox.show($('divMsgBox'),{title:'Atenci&oacute;n',width:400});}
msgBoxSiNo=function(t,b){msgBoxReset();$('txtMsgBox').update(t);$('divMsgBoxSiNo').show();Modalbox.show($('divMsgBox'),{title:'Atenci&oacute;n',width: 400});btnMsgBoxSi_click=b;}
stripHTML=function(s){return s.replace(/<&#91;^>&#93;*>/g,"");}
zEnter=function(e,f){if(((document.all)?e.keyCode:e.which)==13)f();}
cargando=function(){if (!waitBoxAndando && $('divCargando')) $('divCargando').show();}
dtos=function(d){return (d.getFullYear()*10000)+(d.getMonth()*100)+d.getDay();}
chauModalbox=function(){Modalbox.hide();waitBoxAndando=false;}
chauCargando=function(){if ($('divCargando')) $('divCargando').hide();}
