﻿// <reference name="validacionesLib.js"/>

// --------------- GEE ---------------
// Septiembre 2003
// Arlette Espinosa
// Archivo de validaciones generales
// -----------------------------------
// _____________________ FUNCIONES GENERALES ____________________________
// ______________________________________________________________________
// Revisa si un campo tiene un valor, de lo contrario
 function esVacio (valor)
{
 var string1=valor;
 var temp = "";

 string = '' + string1;
 splitstring = string.split(" ");
 for(i = 0; i < splitstring.length; i++)
  temp += splitstring[i];

 if (temp.length==0)
  return true;
 else
  return false;
}
//_____________________________________________________________________________
// Funcion para convertir un texto en mayusculas
function ConvierteMay(texto)
{
 texto.value = texto.value.toUpperCase()
}
// ______________________________________________________________________
// Revisa si un campo tiene un numero

function esNumero(valor)
{
  var RefString="1234567890";
  var InString = valor.value;
  
    for(Count=0;Count < InString.length;Count++)
  {
    TempChar = InString.substring(Count,Count+1);
    if(RefString.indexOf(TempChar,0)==-1) {
	    alert("El valor: "+InString+" no es correcto, ya que debe ser numerico")
	    valor.value="";
		return false;
	}
  }
  return true;
}


function isNumber(InString)
{
  var RefString="1234567890";
  for(Count=0;Count < InString.length;Count++)
  {
    TempChar = InString.substring(Count,Count+1);
    if(RefString.indexOf(TempChar,0)==-1) {
	    alert("El valor: "+InString+" no es correcto, ya que debe ser numerico")
		return false;
	}
  }
  return true;
}

//____________________________________________________________________________
// Valida que la direccion de correo sea válida
// Realizada con área de Internet

function vemail(correoTmp,Requerido,Control)
{
//	var correoTmp;  //correo a validar
//	var Requerido = 1;  //bandera de opcional el email
	var cIncorrecto = 0;
	var nCaract;
	var Caracteres = ".@-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var CaracteresNoInicio = ".-_";
	var arrDComunes = new Array("hotmail.com");

	splitstring = correoTmp.split(";");
	for(i = 0; i < splitstring.length; i++)
	{
	  if(splitstring[i].length==0 && i>0 && splitstring.length==i+1) continue;
	 	
	 	//Valida que el correo contenga caracteres válidos
		for (j = 0; j < splitstring[i].length; j++)
		{
//		alert( splitstring[i].charAt(j) );
			if (Caracteres.indexOf(splitstring[i].charAt(j)) == -1)
				{
				cIncorrecto = 1
				}
		}
		
		if(cIncorrecto == 0)
			{
			//Cuenta el numero de @'s
			splitstringArro = splitstring[i].split("@");
			if(splitstringArro.length==2)
				{ 
				//Que contiene solo una arroba
				//Separa el correo en dos secciones
				for(j = 0; j < splitstringArro.length;j++)
				{
				  if (splitstringArro[j].length==0)
				   {
				  	  cIncorrecto = 1
					  continue;
				   }
				
				 // Valida el correo,despues de la @
				//Separa la informacionpor cada punto
					splitstringPto = splitstringArro[j].split(".");
					//Valida que haya texto despues de un punto
					for(k=0;k<splitstringPto.length;k++)
						{
						if(splitstringPto[k].length==0  || CaracteresNoInicio.indexOf(splitstringPto[k].charAt(0)) >=0 )
							cIncorrecto = 1
						else
						if(splitstringPto.length < 2 && j==1)
						cIncorrecto = 1
						}
					//Si es un correo de losdominios "comunes", valida q sea correcto
					if(cIncorrecto == 0 && j==1)
					{
						for(k=0;k<arrDComunes.length;k++)
						{
							splitstringPtoTmp = arrDComunes[k].split(".");
							if(splitstringPto[0]==splitstringPtoTmp[0])
								{
								if(splitstringArro[j] != arrDComunes[k])
								cIncorrecto = 1
								}
						}
					}
					
				}
			}else
				{
				cIncorrecto = 1
				}
		}
	}
	
	
	if( cIncorrecto == 0  ||  (correoTmp.length==0 && Requerido==0) )
	{
	return true;
	}
	else 
	{
	alert("\nError:  EMAIL  INCORRECTO\n\nVerifique que su email sea correcto.\nQue no contenga espacios, comas o acentos.\n")
	Control.value = ""
	if(Control!="") eval(Control + ".focus();" );
	return false;
	}

}

//____________________________________________________________________________
// Valida que la direccion de correo sea válida
// Realizada AEC

function isDec(str)
{
  var RefString=".0123456789";
  var point	= 0;
  for(Count=0;Count < str.length;Count++)
  {
    TempChar = str.substring(Count,Count+1);
    if(RefString.indexOf(TempChar,0)==-1)
    { return false; }
	if(TempChar==".")
		point= point+1;
	if(parseInt(point)>1)	
    { return false; }
  }
  return true;
}


// ____________________________________________________________________________
// Descripcion: Verifica que la fecha sea válida con el formato dd/mm/aaaa


function validaFecha(strValue)
{
//Para validar la fecha en el formato mm/dd/aaaa
//escribir en la variable strFormatoFecha = "US"

//Para validar la fecha en el formato dd/mm/aaaa
//escribir en la variable strFormatoFecha = ""
  var strFormatoFecha = "";
  var strFecha;
  var arrFecha;
  var strDia;
  var strMes;
  var strAnio;
  var intDia;
  var intMes;
  var intAnio;
  var booFound = false;
 // var cmpFecha = objFecha;
  var arrSeparador = new Array("-","/",".");
  var elementos;
  var error = 0;
  strFecha = strValue;
/////////////////////////////////////////////////
  if (strFecha.length < 8 && strFecha.length > 5)
  { 
  for (elementos = 0; elementos < arrSeparador.length; elementos++)
  {
    if (strFecha.indexOf(arrSeparador[elementos]) != -1)
    {
      arrFecha = strFecha.split(arrSeparador[elementos]);
		// Si los elementos del arreglo son diferente de 3 elementos ejemplo: 01/01/200/34/23/4
      if (arrFecha.length != 2)
      {
        error = 1;
        return false;
      }

      else
      {
        strMes = arrFecha[1];
        strAnio = arrFecha[2];
      }
      booFound = true;
    }

  }

//alert(strDia+" "+strMes+" "+strAnio)

/////////////////////////////////////////////////

  if (booFound == false)
  {
    if (strFecha.length>5)
    {
      strMes = strFecha.substr(2, 2);
      strAnio = strFecha.substr(4);
    }
  }
/////////////////////////////////////////////////
// Si el año es de 2 digitos agrega 20 ejemplo: si es 01 entonces 2001
  if (strAnio.length == 2)
  { strAnio = '20' + strAnio; }

// Si el año es 0000
  if (parseInt(strAnio) <= 1900 )
  { return false }

/////////////////////////////////////////////////

  // Formato (mm/dd/aaaa)
  if (strFormatoFecha == "US")
  {
    strDia = strMes;
    strMes = strTemp;
  }

/////////////////////////////////////////////////

  intMes = parseInt(strMes, 10);

  if (isNaN(intMes))
  {
    error = 3;
    return false;
  }


/////////////////////////////////////////////////

  intAnio = parseInt(strAnio, 10);

  if (isNaN(intAnio))
  {
    error = 4;
    return false;
  }

/////////////////////////////////////////////////

  if (intMes>12 || intMes<1)
  {
    error = 5;
    return false;
  }

/////////////////////////////////////////////////

  if ((intMes == 1 || intMes == 3 || intMes == 5 || intMes == 7 || intMes == 8 || intMes == 10 || intMes == 12) && (intDia > 31 || intDia < 1))
  {
    error = 6;
    return false;
  }

/////////////////////////////////////////////////

  if ((intMes == 4 || intMes == 6 || intMes == 9 || intMes == 11) && (intDia > 30 || intDia < 1))
  {
    error = 7;
    return false;
  }

/////////////////////////////////////////////////
return true;
}

else
{ return false }

}
/////////////////////////////////////////////////////////////////////////////
/////////////// inicioDefault() ////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
		    function inicioDefault(){
		        var MyURL,iFrame
		        var cadPC, cadOcId
		        var i,j
		        		        
                //if(window.frameElement)
                //{
                    var param = new Array();
                    var temp = new Array();
                    var temp1 = new Array();
                    var temp2 = new Array();

                MyURL=window.top.location.href;
                param = MyURL.split('?');                 
                if (param.length == 2)
                {                    
                   MyURL=window.top.location.href;
                   temp = MyURL.split('pc=');
                   
                   if (temp.length == 2)
                    {
                       for (i=0;i<=temp.length-1;i++)
                        {   
                           if (i==1)
                            {
                              temp1=temp[i].split('&ocId=');
                              if (temp1.length==2)
                              {
                                cadPC=temp1[0];
                                cadOcId=temp1[1];
                                window.frames[0].frameElement.src="selPublicacion.aspx?pc=" + cadPC + "&ocId=" + cadOcId
                                //alert("url1: inicio.aspx?pc=" + cadPC + "&ocId=" + cadOcId);
                              }
                            }
                         }
                    } else {
                         temp1 = MyURL.split('promo=');
                         cadPC="";
                         if (temp1.length == 2)
                         {
                            cadPC=temp1[1];
                            window.frames[0].frameElement.src="selPromocion.aspx?promo=" + cadPC
                            //alert("url2: inicio.aspx?promo=" + cadPC);
                         }
                         else {
                             temp2 = MyURL.split('selPublicacion=');
                             cadPC="";
                             if (temp2.length == 2)
                             {
                                cadPC=temp2[1];
                                window.frames[0].frameElement.src="selPublicacion.aspx?ocId="+ cadPC
                                //alert("url2: inicio.aspx?promo=" + cadPC);
                             }                                                     
                        }
                    }
                  }
                  //else {
                  //   window.frames[0].frameElement.src="inicio.aspx"
                  //}                  
                //}
		    }

