function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function check_cvc(){                                                                                                                                                             
    card = document.data.cc_code.options[document.data.cc_code.selectedIndex].value;                                                                                              
    cvc = document.data.cc_security.value + '';                                                                                                                                   
	
	exp = '^[0-9]+$';
	regexp = new RegExp(exp);
	
    if ( (array_cvc[card] != cvc.length) || regexp.exec(document.data.cc_security.value) ){                                                                                                                                         
		document.data.cc_security.value = '';                                                                                                                                     
		return 0;                                                                                                                                                                 
    }else{                                                                                                                                                                        
		return 1;                                                                                                                                                                 
    }
}                                                                                                                                                 

function step_1_valid(f) {
    var dlvycode=false;
    var qty=false;
    var section=false;
    var i;

    if( f.dlvy_code )
    {
	if( f.dlvy_code.length )
	{
	    for(i=0; i<f.dlvy_code.length; ++i)
	    {
		if(f.dlvy_code[i].checked)
		{
		    dlvycode=true;
		    break;
		}
	    }
	}
	else
	{
	    if(f.dlvy_code.checked)
	    {
	        dlvycode=true;
	    }
	}
    }
    else
    {
	dlvycode=false;
    }

    for(i=0; i<f.elements.length; ++i)
    {
	if( f.elements[i].name.indexOf("qty_")==0 )
	{
	    if(f.elements[i].selectedIndex>0)
	    {
		qty=true;
	    }
	}
	else if( f.elements[i].name.indexOf("section_")==0 )
	{
	    if((f.elements[i].selectedIndex>0) && (f.elements[i].options[f.elements[i].selectedIndex].text.indexOf('AGOTADO')==-1))
	    {
		section=true;
	    }
	}

    }

    if( ! dlvycode ) {
	alert("Debe seleccionar un tipo de envío.");
	return false;
    }

    if( ! section ) {
	alert("Debe seleccionar su ubicación.");
	return false;
    }

    if( ! qty ) {
	alert("Debe seleccionar cantidad de entradas.");
	return false;
    }

    return true;
}



function change_modo(f, m)
{
    f.modo.value = m;

    return true;
}


function only_number()
{
    if (event.keyCode < 47 || event.keyCode > 57)
	event.returnValue = false;
}

function step_2_valid(f, dlvy) {
    var error='';

    //Agregado en la modificacion, no lo saque de abajo por las
    if( (f.phone_code.value.length < 2) || (f.phone_number.value.length < 6) )
    {
        error += "\t* Teléfono.\n";
    }

    if( f.cc_code.selectedIndex <= 0 )
    {
	error += "\t* Tarjeta de crédito.\n";
    }

    if( f.cc_nombre.value.length < 4 )
    {
	error += "\t* Nombre del titular de la tarjeta de crédito.\n";
    }

    if( f.cc_apellido.value.length < 2 )
    {
	error += "\t* Apellido del titular de la tarjeta de crédito.\n";
    }
    
    if( !check_cvc() ){                                                                                                                                                                             
	error += "\t* Código de Seguridad\n";
    }
    
    if( f.cc_num.value.length < 10 )
    {
	error += "\t* Número de tarjeta de crédito.\n";
    }
  	else{
			if (  f.show_code.value == "LUISMIINTER"){
					var banco_rio =  f.cc_num.value.substr(0, 6);
					if ( banco_rio != "450995" && banco_rio != "450979" && banco_rio != "450980" &&
							 banco_rio != "493763" && banco_rio != "448459" && banco_rio != "462982" && 
							 banco_rio != "377790" && banco_rio != "377791" ) {
							 //	window.open("popup_banco_rio.asp", 'BancoRio', 'width=300,height=200,resizable=no,titlebar=no,scrollbars=no');
							 error += "\t* Ingresar solamente tarjeta de crédito emitida por el Banco Río para este evento.\n";
					}
			}
		}
		
    //if( f.cc_security.value.length < 3 )
    //{
    //	error += "\t* Código de seguridad.\n";
    //}

    if( (f.cc_month.selectedIndex <= 0) || (f.cc_year.selectedIndex <=0) )
    {
	error += "\t* Vencimiento.\n";
    }

    if( ! f.info.checked )
    {
	error += "\t* Condiciones de venta.\n";
    }
    if( dlvy )
    {

	if( f.address.value.length < 4 )
	{
	    error += "\t* Dirección.\n";
	}

	if( f.locality.value.length < 4 )
	{
	    error += "\t* Localidad.\n";
	}

	if( f.zip_code.value.length < 4 )
	{
	    error += "\t* Código postal.\n";
	}

	if( (f.phone_code.value.length < 2) || (f.phone_number.value.length < 6) )
	{
	    error += "\t* Teléfono.\n";
	}

    }

    if( f.check && f.check.value )
    {
    	var ele;

    	for(i=0; i<f.elements.length; ++i)
	{
		if(f.elements[i].name == f.check.value)
		{
			ele = f.elements[i];
			break;
		}
	}

	if(ele && (ele.value.length < 2))
	{
		error += "\t* Datos adicionales.\n";
	}

    }

    if( error ) {
	alert("Los siguientes datos faltan o son incorrectos:\n\n"+error);
	return false;
    }

    return true;
}


function ventana(url, width, height)
{
    var newwin = window.open(url, 'ventana', 'width='+width+',height='+height+',resizable=yes,titlebar=no,scrollbars=yes');

    return;
}


function abrir(url, name, op)
{
    var nw = window.open(url, name, op);
    return;
}

function addFav()
{
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)){
	if (document.all)
	{
	    window.external.AddFavorite("http://www.tuentrada.com.pe","Tu Entrada Peru");
	}
    }
    else{
	if(navigator.appName == "Netscape") {
	    alert("No se olvide de agregarnos a sus favoritos presionando CTRL+D");
	}
    }

}


function check_equal_mail(val1, val2){
	if(val1.value != val2.value){
		alert('Las direcciones de correo electronico ingresadas no coinciden.\n Por favor, vuelva a ingresarlas.\nMuchas Gracias.');
		val1.value='';
		val2.value='';
		return false;
	}else if(!validateEmail(val1.value) || !validateEmail(val2.value)){
		alert('Las direcciones de correo electronico son incorrectas .\n Por favor, vuelva a ingresarlas.\nMuchas Gracias.');
		val1.value='';
		val2.value='';
		return false;
	}
	return true;
}

function validateEmail(mail){

    var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");
    if(!rx.test(mail)){
        return false;
    }
    return true;
}

function numbersonly(myfield, e, dec){
    var key;
    var keychar;

    if (window.event)
	key = window.event.keyCode;
    else if (e)
    	key = e.which;
    else
	return true;

    keychar = String.fromCharCode(key);
    
    if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	return true;	
    else if ((("0123456789").indexOf(keychar) > -1))
	return true;
    else if (dec && (keychar == ".")){
	myfield.form.elements[dec].focus();
    return false;
    }
    else return false;
}
