
function AsignaValor(frmName,nom,valor)
{
  obj = document.getElementById(nom);
  obj.value = valor;
  EnviarForm(frmName);
}
function Pagina(valor)
{
  ModificaCampo('Pagina',valor);
  SmartSubmit('FotoXPag');
}
function SmartSubmit(id)
{
  var frmForm = document.getElementById(id);
  var inputs=frmForm.all.tags("INPUT");
  if (inputs.length>0) 
	{
		for (var i=0; i < inputs.length; i++) 
		{
		  if((inputs[i].type != "hidden") && (inputs[i].type != "image"))
			if((inputs[i].value == inputs[i].title) || (inputs[i].value =="") )
			{
				//alert(inputs[i].name);
				alert(inputs[i].title);
				return ;
			}
		}
	}
	var areas = frmForm.all.tags("TEXTAREA");
	 if (areas.length>0) 
	{
		for (i=0; i < areas.length; i++) 
		{
			if((areas[i].value == areas[i].title) || (areas[i].value =="") )
			{
				alert(areas[i].title);
				return ;
			}
		}
	}
	var selects = frmForm.all.tags("SELECT")
	if (inputs.length>0) 
	{
		for (i=0; i < areas.length; i++)  
		{
			if(inputs[i].value == inputs[i].title)
			{
				alert(inputs[i].title);
				return ;
			}
		}
	}
	frmForm.submit();
}
function CarroPendiente(cadena)
{
  var aux= showModalDialog('Confirma.php',cadena,'dialogWidth:400px;dialogHeight:100px;status:no;resizable:yes;scroll:no');
  if(aux)
  {
	  location.href= "CerrarSesion.php";
	}
	else
		location.href= "Carrito.php";
}
function Confirmar(idForm,cadena,comando,campo)
{
  var frm = document.getElementById(idForm);
 // var campo =document.getElementById('Comando');
  var aux = showModalDialog('Confirma.php',cadena,'dialogWidth:400px;dialogHeight:150px;status:no;resizable:yes;scroll:no');
  if(aux)
  {
    campo.value=comando;
	frm.submit();
  }  	
}

function Comparar(obj,id1,idout,cadenaerror)
{
  var obj1 =document.getElementById(id1);
  if(obj.value== obj1.value)
  	document.getElementById(idout).value = obj.value;
  else
  {
	  obj.value='';
	  obj1.value='';
	  obj1.focus();
		showModalDialog('Notifica.php',cadenaerror,'dialogWidth:400px;dialogHeight:100px;status:no;resizable:yes;scroll:no');
	  document.getElementById(idout).value = '';
	
	}
}

function ValidaEMail(obj,cadenaerror) {
  var re = new RegExp("[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[A-Za-z]+");
  if (!obj.value.match(re)) {
	  obj.value='';
	  obj.focus();
		showModalDialog('Notifica.php',cadenaerror,'dialogWidth:400px;dialogHeight:100px;status:no;resizable:yes;scroll:no');
	}
}

function EnviarForm(id)
{
  var frmForm = document.getElementById(id);
  frmForm.submit();	   
}
function ModificacionEnviar()
{
  var frmForm = document.getElementById('FormRegistro');
  var cmd = document.getElementById('Comando');
  
  var inputs=frmForm.all.tags("INPUT");	
  if (inputs.length>0) 
	{
		for (var i=0; i < inputs.length; i++) 
		{
			if((inputs[i].type == "text")||(inputs[i].type == "password"))
			{
				if(inputs[i].value == "")
				{
				  if(((inputs[i].id.indexOf("Invitado"))<0 ) )
				  {
						alert('Indique '+inputs[i].title);
						return;
                    }				
				}
			}
		}
	} 
	cmd.value="Registro";
	frmForm.submit();
	return ;
}

function RegistroEnviar()
{
  var frmForm = document.getElementById('FormRegistro');
  var cmd = document.getElementById('Comando');
  var prom = document.getElementById('PromBienvenida');
  var inputs=frmForm.all.tags("INPUT");	
  if (inputs.length>0) 
  {
		for (var i=0; i < inputs.length; i++)
			if((inputs[i].type == "text")||(inputs[i].type == "password"))
        if(prom == null)
			  {
          if(inputs[i].value == "")
          {
            alert('Indique ' + inputs[i].title);
            return;
          }
        }
        else
          if(inputs[i].value === "")
          {
            if(((inputs[i].id.indexOf("Invitado"))<0 ) || (prom.checked))
            {
              alert('Indique '+inputs[i].title);
						  return;  
            }
          }
          else
          {
            if(((inputs[i].id.indexOf("Invitado"))>=0 ) & (!prom.checked))
            {
              alert('Haga click en la casilla final para confirmar su participación de la promoción de bienvenida');
              return;
            }
          }
	} 
	cmd.value="Registro";
	frmForm.submit();
	return ;
}

//Envía formulario de registro
function RegistroEnviar2()
{
	var objMailProm = new Array();
	var objNombreProm = new Array();
	var objApellidoProm = new Array();
	var objAuxEmail =  new Array();
	var objAuxPassword = new Array();
	var objProm = document.getElementById('PromBienvenida');
	var frmForm = document.getElementById('FormRegistro');
	var objEmail = document.getElementById('Email');
	var objPassword = document.getElementById('Password');
	var cmd = document.getElementById('ComandoReg');
	var inputs=frmForm.all.tags("INPUT");	
	var iInvitados=0;
	var bAux =false;
	
	//Verifica los campos obligatorios	
	if (inputs.length>0) 
	{
		for (var i=inputs.length-15; i >= 0; i--) 
		{
			if(inputs[i].type != "hidden")
				if(inputs[i].value == "")
				{
					alert('Indique '+inputs[i].title);
					return ;
				}
		}
	} 
	inputs = frmForm.all.tags("SELECT");
	if (inputs.length>0) 
	{
		for (var i=inputs.length-1; i >= 0; i--) 
		{
				if(inputs[i].value == "-1")
				{
					alert('Indique '+inputs[i].id);
					return ;
				}
		}
	}
	
	//verifica las direcciones de correo
	objAuxEmail[0] = document.getElementById('Email01');	
	objAuxEmail[1] = document.getElementById('Email02');
	if(objAuxEmail[0].value==objAuxEmail[1].value)
		  objEmail.value = objAuxEmail[0].value;
	else
	{
	  alert('Las direcciones de correo electrónico no coinciden');
	  return ;
	}
	
	//Valida Passwords
	objPassword = document.getElementById('Password');
	objAuxPassword[0] = document.getElementById('Password01');
	objAuxPassword[1] = document.getElementById('Password02');
	if(objAuxPassword[0].value==objAuxPassword[1].value)
		  objPassword.value = objAuxPassword[0].value;
	else
	{
	  alert('Las contraseñas no coinciden');
	  return ;
	}
	
	//Cuenta cuantos nombres ingresó 
	for(i=0;i<4;i++)
	{
		objMailProm[i]= document.getElementById('InvEmail['+i+']');
		objNombreProm[i]= document.getElementById('InvNombre['+i+']');
		objApellidoProm[i]= document.getElementById('InvApellido['+i+']');
		
		if(objEmail.value == objMailProm[i].value)
		{
		  alert('No puede ingresar su propio email como invitado');
		  return;
		}
		if(objMailProm[i].value != "")
		{
			if(objNombreProm[i].value != "")
				iInvitados++;
			else
			{
			  	alert('Ingrese el nombre para '+ objMailProm[i].value);
			  	return;
			}
			for (j=0;j<i;j++)
		  	{
		    	if(objMailProm[i].value==objMailProm[j].value)
		    	{
			  		alert('La dirección de correo '+objMailProm[i].value+' está repetida');
			  		return;	  
				}
		  	}
		}
		if(objNombreProm[i].value != "")
			if(objMailProm[i].value == "")
			{
		  		alert('Ingrese el correo electrónico de su invitado '+objNombreProm[i].value+' '+objApellidoProm[i].value);
		  		return;
			}	
	}
	
	//Si ingresó el nombre de al menos uno y no puso el check de promoción
	if(!objProm.status && (iInvitados>0) )
	{
		alert('¡Confirme si desea participar de la promoción de bienvenida a xSiempre!');
		return ;
	}
	
	//Si ingresó el check de promoción y no puso los nombres de sus amigos
	if(objProm.status && (iInvitados == 0))
	{
		alert('Ingrese los nombres, apellidos y correos electrónicos de hasta 4 amigos para que puedan hacerle ganar con nuestra Promoción');
		return;
	}
	cmd.value="Registro";
	frmForm.submit();
}



function Copyright(Mensaje)
{
	alert(Mensaje); 
}
function Habilita(control,valor)
{
  	var obj=document.getElementById(control);
  	obj.disabled = valor;
}

function ModificaCampo(id,valor)
{
	var obj = document.getElementById(id);
	obj.value = valor; 
}

function LimpiaCampo(obj)
{
 	if(obj.value == obj.title)
	 {
	   obj.value ="";
	} 
}





function Retorna(getparam)
{
 // var cadena = new String(window.opener.location.href);
  if(window.opener.location.search == "" )
  	window.opener.location.href = window.opener.location.href + getparam;
  else
  	window.opener.location.href = window.opener.location.pathname + getparam;
  window.self.close();
}

function Tarjeta(params)
{
  window.opener.location.href = "Tarjeta.php" + params;
  window.self.close();
}
function AjustaVentana(id)
{
	var obj = document.getElementById(id);	
	if((obj.offsetHeight + 2 * document.body.topMargin < 0.95*window.screen.availHeight ) )
	window.resizeTo(obj.offsetWidth + 2 * document.body.leftMargin + 16 ,obj.offsetHeight + 2 * document.body.topMargin );
}

function ValidaExtension(obj)
{
 var cadena = new String(obj.value);
 cadena = cadena.toUpperCase();
	if((cadena.lastIndexOf(".JPG")== -1) && (cadena.lastIndexOf(".JPEG")==-1))
	{
	 	obj.value=" ";
		alert("Sólo se permiten archivos en formato jpg o jpeg"); 
		window.location.href=window.location.href;
	}
}
function Resize(ancho,alto)
{
  var aux = ancho;
	if(window.document.scrollWidth != null)
  		aux += window.document.scrollWidth;
  	window.resizeTo(ancho+20,alto);
}

function Confirmar(idForm,cadena,comando,campo)
{
  var frm = document.getElementById(idForm);
 // var campo =document.getElementById('Comando');
  var aux = showModalDialog('Confirma.php',cadena,'dialogWidth:400px;dialogHeight:100px;status:no;resizable:yes;scroll:no');
  if(aux)
  {
    campo.value=comando;
	frm.submit();
  }  	
}

function PopUp(url,titulo,tipo,aux)
{
	var aux ="PopUp.php?Archivo="+url+"&Titulo="+titulo+ "&Tipo=" + tipo  + "&"+ aux ;
	var aux2= "status=no,toolbar=no,menubar=no,location=no";
	if( tipo=="Img" )
		aux2 += ",scrollbars=no";
	else
		aux2 += ",scrollbars=yes";
	mio = window.open(aux,null,aux2);
	mio.focus();
}

///Funciones específicas
function CambiaColorPared(sInitColor)
{
	var Pared = document.getElementById('Cuadro').parentElement;
	var varPared = document.getElementById('ColorPared');
//	var Pared = document.getElementById('Pared');
if (sInitColor == null) 
	var sColor = dlgHelper.ChooseColorDlg();
else
	var sColor = dlgHelper.ChooseColorDlg(sInitColor);

	sColor = sColor.toString(16);
	if (sColor.length < 6) 
	{
	 	var sTempString = "000000".substring(0,6-sColor.length);
	 	sColor = sTempString.concat(sColor);
	}
	Pared.style.backgroundColor=sColor;
	varPared.value=sColor;
}

function CambiaColorMarco(obj)
{
  var Cuadro = document.getElementById('Cuadro');
  if (obj.value != "") 
  {
    Cuadro.style.borderColor =obj.value ;
    }   
	
}

function CambiaColorPaspartou(Valor)
{
	var Cuadro = document.getElementById('Cuadro');
	var Pared = Cuadro.parentElement;

	if(Valor == 1)
		Cuadro.bgColor = Pared.bgColor;
	else
		Cuadro.bgColor = "#ffffff";	
}


