﻿function ValidarTextBox(TextBox,Campo)
{
	if(TextBox.value == '')
	{
		alert(Campo);
		TextBox.focus();
		return false;
	}
}

function showtitle (ele, text){
   if(!$('_tooltip')){
    var divs = "<div class='Tooltip' id='_tooltip' ></div>";
    new Insertion.Top(document.body, divs)
   }
  var div = $('_tooltip');
  Event.observe(ele, 'mouseout', function(){ 
  div.style.visibility = 'hidden';
  });
  div.innerHTML = text;
//  div.style.pixelLeft = event.clientX + document.body.scrollLeft + 5;
//  div.style.pixelTop = event.clientY + document.body.scrollTop + 5;
 div.style.pixelLeft = 154 + document.body.scrollLeft + 5;
  div.style.pixelTop = 230 + document.body.scrollTop + 5;
  div.style.visibility = 'visible';
}





//Permite ingresar en las cajas de texto solo numeros.
function SoloNumeroEnteros(){ //Solo permite ingresar numero en los textbox, fuciona solo en IE
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}

function SoloNumeros(e) { //Permite ingresar solo numero en las cajas de texto, funciona en firefox y IE.
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true; //Tecla de retroceso (para poder borrar)
    patron = /\d/; //ver nota
    //patron = /d/; //ver nota
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 

/*=====================VALIDAR EL INGRESO DE NUMERO DECIMALES====================================================*/

 function validarnumero(obj,evt){        
    
    var key=evt.keyCode; 
    var valor=obj.value;
    var nombre=obj.name;
                
    //46 ES EL PUNTO DECIMAL
    //DEL 48 AL 57 SON NUMEROS
        if (dec(valor)==false){
            return key==0;
        }else{
            if(npuntos(valor) == true ) {
                //
                //if (nmax(valor)==true){
                        return (key ==46 || (key >= 48 && key <= 57));                     
                    //}else{
                        //return key==0;
                        //alert("borre");
                    //}
            } else {
                //
                //if (nmax(valor)==true ){                
                        return (key >= 48 && key <= 57);                     
                    //}else{
                        //return key==0;
                        //alert("borre");
                    //}
            }
        }//end if
    }//end function

    function npuntos(q) {
        var c=0;
        for ( i = 0; i < q.length; i++ ) {
            if ( q.charAt(i) == "." ) {
            c++;                        
            }
        }
        if(c==0){
            return true;
        }else{
            return false;
        }
    }
  
    function dec(q) {
        var decallowed = 1;
        if (q.indexOf('.') == -1) q += ".";
            var dectext = q.substring(q.indexOf('.')+1, q.length);
                if (dectext.length > decallowed)
                {
                    return false;
                }else{
                    return true;
                }
    }  
    
    function nmax(obj){
        if (obj.value > 10  ){
            obj.value="";            
            alert("La nota máxima es 10.00");
            obj.focus;
        }
    }
////////////////////////////////////////////////////////


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 validateInteger(ele) {
   var sCheckStr;
   if (typeof ele == "object") sCheckStr = String( ele.value || "" );
   else sCheckStr = String( ele );
   
	var sDigitSymbols = "1234567890";
	var sSignSymbols = "+-";
	var nCurrentPosition = 0;
	var res = true;

	if ( isCharInString( sCheckStr.charAt( nCurrentPosition ), sSignSymbols ) )
		nCurrentPosition++;

	for ( ; nCurrentPosition < sCheckStr.length; nCurrentPosition++ )
		if ( !isCharInString( sCheckStr.charAt( nCurrentPosition), sDigitSymbols ) )
			break;

	if ( ( nCurrentPosition != sCheckStr.length ) )
		res = false;

	return res;
}

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 validateDate( ele ) {
    var value;
    if (typeof ele == "string") value = ele;
    else if (typeof ele == "object") value = ele.value;
    else return false;
    
//    if (isEmpty(value)) return true;
    value = value.split(/[\/\-.]/);
    if (value.length == 3) {
	    var day = value[0] * 1;
	    var month = value[1] * 1;
	    var year = value[2] * 1;
	    if (!isNaN(month) && !isNaN(day) && !isNaN(year)) {
            if (year < 1000) {
                if (year < 50) year += 2000;
                else if (year < 100) year += 1900;
                else year += 1000;
            }
		    if (month >=1 && month <=12) {
		        if (day >=1 && day <= getDaysInMonth(month, year)) {
		            if (typeof ele == "object") {
		                  // mostrar la fecha formateada
                        ele.value = (day<10?"0" + day: "" + day) + "/" +
                                   (month<10?"0" + month: "" + month) + "/" +
                                   (year);
                        // establecer la fecha como tipo Date
                        ele.date = new Date(year, month-1, day);
		            }
		            return true;
		        }
		    }
	    }
    }
    
    if (typeof ele == "object") {
        ele.value = "";
        ele.date ? ele.date = null : null;
    }
    return false;
}

function getDaysInMonth(month, year) {
	var days;
	if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)  days=31;
	else if (month==4 || month==6 || month==9 || month==11) days=30;
	else if (month==2) {
		if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)) 
		    days=29;
		else 
		    days=28;
		}
	return (days);
}




function onError(error) {
    error = error.unescapeHTML();
    if ((p = error.indexOf(".")) >= 0)
        error = error.substring(0, p+1);
        
    alert(error);
}

///************************************************************** ////////


/*--------------------------------------------------------------------------------*/
/****************************  PUBLICACION.ASPX  ************************************/
/*--------------------------------------------------------------------------------*/
function ValidarForms(){
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txtFecha,"La fecha de publicacíon del Formulario es Requerido")==false) return false;
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txtTitulo,"El Titulo del Formulario es Requerido")==false) return false;
    var oEditorEsp = FCKeditorAPI.GetInstance('ctl00_c_txtDescripcion') ;		            		            
    var textoEsp = oEditorEsp.EditorDocument.body.innerHTML;
//debugger;
//    var textoEsp = "";
//    var objtexto = oEditorEsp.EditorDocument.body.firstChild
//    if(objtexto) textoEsp = oEditorEsp.EditorDocument.body.firstChild.nodeValue;
    if (textoEsp.length == 0)
    {
        alert("La Descripción del Formulario es Requerido");
        return false;
    }
}

function ValidarFormsEliminar(){
    if (confirm("Usted está a punto de eliminar el registro \n Esta seguro que desea eliminar...?"))                
    {
        return true;
    }else{                   
        return false;
    }				
}

function NuevoForms(){
    document.aspnetForm.ctl00$c$txt_NomForms.value=""
    document.aspnetForm.ctl00$c$txt_DesForms.value=""
    document.aspnetForm.ctl00$c$txt_PosicionForms.value=""
    document.aspnetForm.ctl00$c$txt_IconoForms.value=""
    document.aspnetForm.ctl00$c$bt_Agregar.disabled=false;
    document.aspnetForm.ctl00$c$bt_Actualizar.disabled=true;
    document.aspnetForm.ctl00$c$bt_Eliminar.disabled=true;
    return false;
}

/*--------------------------------------------------------------------------------*/
/****************************  ADM_MODULOS.ASPX  ************************************/
/*--------------------------------------------------------------------------------*/
function ValidarModulos(){
	if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_NomModulo,"El nombre del modulo es Requerido")==false) return false;	
}

function NuevoModulos(){
    document.aspnetForm.ctl00$c$txt_NomModulo.value=""
    document.aspnetForm.ctl00$c$bt_Agregar.disabled=false;
    document.aspnetForm.ctl00$c$bt_Actualizar.disabled=true;
    return false;
}

/*--------------------------------------------------------------------------------*/
/****************************  ADM_ROLES.ASPX  ************************************/
/*--------------------------------------------------------------------------------*/
function ValidarRoles(){
	if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_NuevoRol,"El nombre del rol es Requerido")==false) return false;	
}

function NuevoRoles(){
    document.aspnetForm.ctl00$c$txt_NuevoRol.value=""
    document.aspnetForm.ctl00$c$txt_Descripcion.value=""   
    document.aspnetForm.ctl00$c$bt_Agregar.disabled=false;
    document.aspnetForm.ctl00$c$bt_Actualizar.disabled=true;
    return false;
}


/*--------------------------------------------------------------------------------*/
/****************************  ADM_USERS.ASPX  ************************************/
/*--------------------------------------------------------------------------------*/
function ValidarUsuarioAdministrativo(){
	if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_UserName,"El nombre del usuario es Requerido")==false) return false;	
	if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Email,"El email del usuario es Requerido")==false) return false;	
	if(ValidarEmail(document.aspnetForm.ctl00$c$txt_Email,"El email del usuario no es valido, verifique ...")==false) return false;		
}

function NuevoUsers(){
    document.aspnetForm.ctl00$c$txt_UserName.value=""
    document.aspnetForm.ctl00$c$txt_Email.value=""   
   // document.aspnetForm.ctl00$c$ddl_Rol.Selected=""   
    document.aspnetForm.ctl00$c$txt_Comment.value=""     
    document.aspnetForm.ctl00$c$bt_Grabar.disabled=false;
    document.aspnetForm.ctl00$c$bt_Actualizar.disabled=true;
    return false;
}

/*--------------------------------------------------------------------------------*/
/****************************  AGREGAR_LIBRETA_DE_DIRECCIONES  ************************************/
/*--------------------------------------------------------------------------------*/
function Validar_adress_book(){
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_Nombres,"El campo nombre es Requerido")==false) return false;	
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_Apellidos,"El campo apellidos es Requerido")==false) return false;		
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_Direccion,"El campo direccion es Requerido")==false) return false;			
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_CodigoPostal,"El campo codigo postal es Requerido")==false) return false;		
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_Ciudad,"El campo nombre de la ciudad es Requerido")==false) return false;		
	if(ValidarTextBox(document.aspnetForm.ctl00$CPH$txt_Estado,"El campo estado es Requerido")==false) return false;		
}

/*--------------------------------------------------------------------------------*/
/****************************  VALIDAR MANTENIMIENTO DE LANGUAGES  ************************************/
/*--------------------------------------------------------------------------------*/
function Validar_Languages(){
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Name,"El campo nombre del lenguaje es Requerido")==false) return false;		
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Code,"El campo codigo del lenguaje es Requerido")==false) return false;		
	if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Sort_Order,"El campo orden es Requerido")==false) return false;		
}

function NuevoLanguages(){
    document.aspnetForm.ctl00$c$txt_Name.value=""
    document.aspnetForm.ctl00$c$txt_Code.value=""   
    document.aspnetForm.ctl00$c$txt_Image.value=""  
    document.aspnetForm.ctl00$c$txt_Directory.value=""  
    document.aspnetForm.ctl00$c$txt_Sort_Order.value=""          
    document.aspnetForm.ctl00$c$bt_Agregar.disabled=false;
    document.aspnetForm.ctl00$c$bt_Actualizar.disabled=true;
    return false;
}

/*--------------------------------------------------------------------------------*/
/****************************   VALIDAR FORMULARIO DE CATEGORIES  ************************************/
/*--------------------------------------------------------------------------------*/
function ValidarCategories(){
    var frm = document.forms[0];
    var txtName=""; 
    
    for (i=0; i<frm.length; i++) 
	{   if (frm.elements[i].type == "text")
	    {
		    if (frm.elements[i].value =="")
			    {
			    txtName=frm.elements[i].name;			    
                alert("[ " + txtName.toUpperCase() + " ]" + "\n El campo categoria es requerido" ); 
                frm.elements[i].focus();
                return false;			       
			    break;			    
				}
		}
	}								
 }
 
 
 
/*--------------------------------------------------------------------------------*/
/****************************  VALIDAR REGISTRO DE UN NUEVO CLIENTE  ************************************/
/*--------------------------------------------------------------------------------*/
function Validar_Registro_ZonesRangos(){       
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txtPesoMin,"El campo peso minimo es Requerido")==false) return false;	
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txtPesoMax,"El campo peso maximo es Requerido")==false) return false;		    
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txtPrecio,"El campo precio es Requerido")==false) return false;		                  
}

/*--------------------------------------------------------------------------------*/
/****************************  VALIDAR REGISTRO DE UN NUEVO CLIENTE  ***/
/*--------------------------------------------------------------------------------*/
function Validar_BuscarOrdenes(){  
var opt1=document.aspnetForm.ctl00$c$OptionSearch[0].checked    
var opt2=document.aspnetForm.ctl00$c$OptionSearch[1].checked
var opt3=document.aspnetForm.ctl00$c$OptionSearch[2].checked   

if ((! opt1)  && (! opt2) && (! opt3)){
    alert("Seleccione una opcion");
   return false; 
}
//="checked"
  if(document.aspnetForm.ctl00$c$OptionSearch[2].checked ){
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_FechaDel,"Ingrese la fecha Inicial")==false) return false;	
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_FechaAl,"Ingrese la fecha final")==false) return false;	
 }   
}


/*--------------------------------------------------------------------------------*/
/****************************  SCRIPT DE POPUP PARA LA SECCION DE BANNERS  ***/
/*--------------------------------------------------------------------------------*/	
function AbrirPopup(par1,par2){
var ruta;
if (par1=="1"){//Flash
    ruta="view_flash.aspx?p1="+par1+"&p2="+par2;
}else{
    ruta="view_image.aspx?p1="+par1+"&p2="+par2;
}
var OTop = (screen.height - 800)/2;	
var OLeft = (screen.width - 800)/2;
var win = new Window({className: "alphacube",top:OTop, left:OLeft, width:800, height:500, maximizable:false,minimizable:false,
					opacity:1,draggable:false,url: ruta, showEffectOptions: {duration:1.0}})
win.show();		
}



function ValidarIngresoMovimiento(){
      if (document.aspnetForm.ctl00$c$ddl_TipoMovimiento[0].selected==true)
    {    //ctl00_c_ddl_Pais
        alert("Seleccione el tipo de movimiento.");
        document.aspnetForm.ctl00$c$ddl_TipoMovimiento.focus();
        return false;
    }
    
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Concepto,"El campo concepto del movimiento es Requerido")==false) return false;	
    if(ValidarTextBox(document.aspnetForm.ctl00$c$txt_Cantidad,"El campo cantidad del movimiento es Requerido")==false) return false;	   
}

//
function ValidarBusquedaMovimiento(){

    var Cod=document.aspnetForm.ctl00$c$txt_codigo.value;
    var Des=document.aspnetForm.ctl00$c$txt_Descripcion.value;
    var Del=document.aspnetForm.ctl00$c$txt_Del.value;
    var Al=document.aspnetForm.ctl00$c$txt_Al.value;
    
   if(Cod =="" && Des =="" && Del =="" && Al =="") {
       alert("Ingrese el/los criterio(s) para realizar la busqueda.");
       document.aspnetForm.ctl00$c$txt_codigo.focus();
       return false 
   }
   if(Del !="" && Al ==""){
        alert("Ingrese un rango de fecha valido.");
        document.aspnetForm.ctl00$c$txt_Al.focus(); 
        return false; 
   }else{
    if  (Del =="" && Al !=""){
        alert("Ingrese un rango de fecha valido.");
        document.aspnetForm.ctl00$c$txt_Del.focus(); 
        return false;          
    }
   }
}


function AbrirPopupPersonalizado(ruta,ancho,alto){
//alert(ruta);
var OTop = (screen.height - ancho)/2;	
var OLeft = (screen.width - ancho)/2;
var win = new Window({className: "alphacube",top:OTop, left:OLeft, width:ancho, height:alto, maximizable:false,minimizable:false,
					opacity:1,draggable:true,url: ruta, showEffectOptions: {duration:1.0}})
win.show();		
}