var RowColor="";
var ArrIdsDelete = [];

Dialogo = function(obj,options) {
	this.init(obj,options);
}

$.extend(Dialogo.prototype, {  
	init: function(obj,options) {
		var defaults = {  
			autoOpen: false,  
			width: 300,  
			title: 'Dialogo',
			modal: true,
			resizable: false
		};
		var optionsa = $.extend(defaults, options);
		this.form = $('#'+obj);		
		$(this.form).dialog(optionsa)
		.bind( "dialogclose", function(event) {          
			if (/MSIE (5\.5|6).*Windows/.test(navigator.userAgent)){
				//habilitar los select en IE
				$("SELECT").each(function (i,select) {
					$(select).show();
				});
			}
		});
	},
	open: function() {
		// deshabilitar los select en IE
		if(/MSIE (5\.5|6).*Windows/.test(navigator.userAgent)) {
			$("SELECT").each(function (i,select) {
				$(select).hide();
			});
		}		
		// habilitar los select que estan dentro del Dialogo
		if(/MSIE (5\.5|6).*Windows/.test(navigator.userAgent)) {
			$("#" + this.form[0].id + " SELECT").each(function (i,select) {
				$(select).show();
			});
		}		
		$(this.form).dialog('open');	
	},
	close: function() {				
		$(this.form).dialog('close');	
	},
	title: function(title) {				
		$(this.form).dialog("option", "title", title);	
	}
});



function selectGetText(select) {
    select = $("#"+select)[0];
    return select.options[select.selectedIndex].text;
}


function validateFloat( ele ) {
   var sCheckStr;
   if (typeof ele == "object") sCheckStr = String( ele.value || "" );
   else sCheckStr = String( ele );
   
	var sDigitSymbols = "1234567890";
	var sSignSymbols = "+-";
	var nFlagComa = 0;
	var nCurrentPosition = 0;
	var res = true;

	if ( isCharInString( sCheckStr.charAt( nCurrentPosition ), sSignSymbols ) )
		nCurrentPosition++;

	for ( ; nCurrentPosition < sCheckStr.length; nCurrentPosition++ )
		if ( !isCharInString( sCheckStr.charAt( nCurrentPosition ), sDigitSymbols ) )
			if ( !isCharInString( ".", sCheckStr ) )
				break;
			else
				if ( !nFlagComa )
					nFlagComa++;
				else
					break;

	if ( nCurrentPosition != sCheckStr.length )
		res = false;

	return res;
}

function isCharInString( _cChar, _sStr ) {
	return ( _sStr.indexOf( _cChar) > -1)
}


function FormatNumber(obj, numDecimales) {
    numDecimales = parseInt(numDecimales, 10);
    if (isNaN(numDecimales)) numDecimales = 2;
    
    if (typeof obj == "string") num = obj.strip();
    else if (typeof obj == "object") {
        num = obj.value.strip();
        if (num.length === 0 && !obj.hasClassName("required")) {
            obj.value = "";
            return "";
        }
    }
    else return "";
    
    num = asNumber(num);
    var d = Math.pow(10, numDecimales);
    num = "" + (Math.round(num * d) / d);
    if (numDecimales > 0) {
        pp = num.indexOf(".");
        if (pp < 0) num += ".0";
        pp = num.indexOf(".");
        completar = numDecimales - (num.length - (pp+1));
        for (i=0; i<completar; i++)
            num += "0";
    }
    if (typeof obj == "object") obj.value = num;    
    return num;
} 

function asNumber(num) {
    if (typeof num == "string") 
        num = parseFloat(num);
    if (isNaN(num)) num = 0;
    return num;
}

function toEval(Cadena){
    return eval('(' + Cadena + ')');
}



function Loading(){        
  $.blockUI({ message:"<img src='images/loading3.gif'/>",overlayCSS: { backgroundColor: '#5E5E5E' } });   
}

function DisabledBotton(contenedor,clas,boton){
  var cont=false;
  ArrIdsDelete = [];
 $('#'+contenedor +' .'+clas).each(function(i,e){
	if(e.checked){
	  cont=true;
	  ArrIdsDelete.push(e.id);
	}
 });
 $("#"+boton).attr("disabled",!cont); 
}

function CheckGrid(contenedor,clas,elemento,btn){
 var count = false;
 ArrIdsDelete = [];
 $('#'+contenedor +' .'+clas).each(function(i,e){
	if(!e.disabled){
	  e.checked = elemento.checked;
	  if(e.checked){
		  count=true;
		  ArrIdsDelete.push(e.id);
	  }
	}
 });
 /*$("#"+btn)[0].disabled = true;
 if(count>0) $("#"+btn)[0].disabled = false;*/
 $("#"+btn).attr("disabled",!count);
}

function PaginarValidar(evento,text,funcion){
  var accion;
  if(evento.keyCode)
    accion = evento.keyCode;
  else if(evento.which)
    accion = evento.which; 

  var MaxValue = parseInt($(text).attr("MaxValue"),10);
  var Value = parseInt($.trim(text.value),10);
  var OldValue = parseInt($(text).attr("OldValue"),10);
  if(accion === 13){	
	if(OldValue == Value) return;	
	if(Value>MaxValue || Value<1 || isNaN(Value)){
	  //var msg = isNaN(Value)?"Es requerido ingresar el número de página":"La página número "+ Value +" no esta permitido.";
	  //alert(msg);
	  text.value = OldValue;
	  return;
	}	
	if (typeof funcion == "function") funcion(text.value);	
  }else if(isNaN(Value)){
	text.value = OldValue;  
  }
}

function ValidFono(_Elemento,adicional){
 if(typeof adicional == "undefined") adicional = "";
 var _completo = "1234567890 -()." + adicional;
 var contador = 0;
 var _retorno = "";
   for (var i=0; i < _Elemento.value.length; i++) {
     ubicacion = _Elemento.value.substring(i, i + 1);      
     if ((_completo.indexOf(ubicacion) != -1)) {  
       contador++;
       _retorno += ubicacion;
     } else {
       _Elemento.value = _retorno; 
       return false;  
     }  
   }
   return true;
}
//"abcdefghijklmnopqrstuvwxyzñáéíóú ABCDEFGHIJKLMNOPQRSTUVWXYÑZÁÉÍÓÚ"
function ValidTexto(_Elemento, adicional){
 if(typeof adicional == "undefined") adicional = "";
  var _completo = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" + adicional;
 var contador = 0;
 var _retorno = "";
   for (var i=0; i < _Elemento.value.length; i++) {
     ubicacion = _Elemento.value.substring(i, i + 1);      
     if ((_completo.indexOf(ubicacion) != -1)) {  
       contador++;
       _retorno += ubicacion;
     } else {
       _Elemento.value = _retorno; 
       return false;  
     }  
   }
   return true;
}

function ValidTextoNumero(_Elemento,adicional){
if(typeof adicional == "undefined") adicional = "";
 var _completo = "abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ" + adicional;
 var contador = 0;
 var _retorno = "";
   for (var i=0; i < _Elemento.value.length; i++) {
     ubicacion = _Elemento.value.substring(i, i + 1);      
     if ((_completo.indexOf(ubicacion) != -1)) {  
       contador++;
       _retorno += ubicacion;
     } else {
       _Elemento.value = _retorno; 
       return false;  
     }  
   }
   return true;
}

function ValidEntero(_Elemento,adicional){
 if(typeof adicional == "undefined") adicional = "";
 var _completo = "1234567890" + adicional;
 var contador = 0;
 var _retorno = "";
   for (var i=0; i < _Elemento.value.length; i++) {
     ubicacion = _Elemento.value.substring(i, i + 1);      
     if ((_completo.indexOf(ubicacion) != -1)) {  
       contador++;
       _retorno += ubicacion;
     } else {
       _Elemento.value = _retorno; 
       return false;  
     }  
   }
   return true;
}

function ValidarEmail(email,msj) {      
    var patron=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (patron.test(email.value)==false){ 
        alert(msj);
        email.focus();
        return false;
    }
}

function CantidadLetras(objota,limite) {
 var nnn=objota.value.length;
	if (nnn>=limite) {
		objota.form.contador.value=limite;
		objota.value=objota.value.substr(0,limite);
		window.event.keyCode=0;
		return false;
	}
 objota.form.contador.value=nnn;
 return true;
}
//onfocus="CantidadLetras(this,2048);" onchange="CantidadLetras(this,2048);" onkeypress="CantidadLetras(this,2048);" onkeyup="CantidadLetras(this,2048);" onblur="CantidadLetras(this,2048);"
function CantidadLetras(e,limite) {
	if ($(e)[0].value.length>=limite) {
		$(e)[0].value=$(e)[0].value.substr(0,limite);
		window.event.keyCode=0;
		return false;
	}
 return true;
}

jQuery(function($) {
$.datepicker.regional['es'] = 
  {
    clearText: 'Borra',
    clearStatus: 'Borra fecha actual',
    closeText: 'Cerrar',
    closeStatus: 'Cerrar sin guardar',
    prevText: '<Anterior',
    prevBigText: '<<',
    prevStatus: 'Mostrar mes anterior',
    prevBigStatus: 'Mostrar a&ntilde;o anterior',
    nextText: 'Siguiente>',
    nextBigText: '>>',
    nextStatus: 'Mostrar mes siguiente',
    nextBigStatus: 'Mostrar a&ntilde;o siguiente',
    currentText: 'Hoy',
    currentStatus: 'Mostrar mes actual',
    monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
    monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
    monthStatus: 'Seleccionar otro mes',
    yearStatus: 'Seleccionar otro a&ntilde;o',
    weekHeader: 'Sm',
    weekStatus: 'Semana del a&ntilde;o',
    dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;bado'],
    dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mi&eacute;', 'Jue', 'Vie', 'S&aacute;b'],
    dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'S&aacute;'],
    dayStatus: 'Set DD as first week day',
    dateStatus: 'Select D, M d',
    dateFormat: 'dd/mm/yy',
    firstDay: 1,
    initStatus: 'Seleccionar fecha',
    isRTL: false
  };
  
  $.datepicker.setDefaults($.datepicker.regional['es']);
});





