function delay(){
    setTimeout('afterFiveSeconds()',5000)
}

function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}


// Declaro los selects que componen el documento HTML. Su atributo ID debe figurar aqui.
var combosFormRemeras=new Array();
combosFormRemeras[0]="categoria";
combosFormRemeras[1]="remera";
combosFormRemeras[2]="talle";
combosFormRemeras[3]="material";
combosFormRemeras[4]="color";
combosFormRemeras[5]="color_estampa";

var combosFormPines=new Array();
combosFormPines[0]="categoria";
combosFormPines[1]="remera";
var hay_remeras_agregadas=false;

var path;

function AgregarRemera()
{
//---------------------Ajax para Agregar Remera.------------------------
//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax
		var combo=document.getElementById('remera');
        var id_modelos=combo.options[combo.selectedIndex].value;

		var combo2=document.getElementById('categoria');
        var categoria=combo2.options[combo2.selectedIndex].value;

		var combo3=document.getElementById('talle');
        var talle=combo3.options[combo3.selectedIndex].value;

		var combo4=document.getElementById('material');
        var material=combo4.options[combo4.selectedIndex].value;
		//alert(material);
		var combo5=document.getElementById('color');
        var color=combo5.options[combo5.selectedIndex].value;

		var combo6=document.getElementById('color_estampa');
        var color_estampa=combo6.options[combo6.selectedIndex].value;

       // alert ('id_modelos'+id_modelos+'categoria'+categoria+'talle'+talle+'material'+material+'color'+color+'color_estampa'+color_estampa);
		var id_pedidos=document.forms[0].id_pedidos.value;

		var div_top_detalle=document.getElementById('top_detalle'); 	
	
		//Busco el Div de la imagen para cargarla.
        var div_detalle_pedido=document.getElementById('div_detalle_pedido'); 
		var ajax=nuevoAjax();
		var agregar_remera = true;
      //  alert('agregar remera');  

		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
		ajax.open("GET", "abm_remera_ajax.php?agregar_remera="+agregar_remera+"&id_pedidos="+id_pedidos+"&id_modelos="+id_modelos+"&categoria="+categoria+"&talle="+talle+"&material="+material+"&color="+color+"&color_estampa="+color_estampa, true);
		
		ajax.onreadystatechange=function() 
		{ 
			
            if (ajax.readyState==1)
            {
                // Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
            
                div_top_detalle.innerHTML='COMPLETANDO LA OPERACION...';
            }
            if (ajax.readyState==4)
            {
            //	alert(ajax.responseText);
				div_top_detalle.innerHTML=ajax.responseText;
				CargarDetalle();
            }
		}
		ajax.send(null);
		return true;
		

}
function AgregarPin(categoria,id_modelos,path_pines,txt_cant)
{
//---------------------Ajax para AgregarPin .------------------------
//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax

        path=path_pines;
       // alert ('id_modelos'+id_modelos+'categoria'+categoria+'talle'+talle+'material'+material+'color'+color+'color_estampa'+color_estampa);
        var id_pedidos=document.forms[0].id_pedidos.value;
		//var txt_cant=document.forms[0].txt_cant.value;
        if (txt_cant==null) {txt_cant=1};
        
        var div_carrito_pines=document.getElementById('carrito_pines');     
    
        //Busco el Div de la imagen para cargarla.

        var ajax=nuevoAjax();
        var agregar_pin = true;

        // alert(path+"abm_remera_ajax.php?agregar_pin="+agregar_pin+"&txt_cant="+txt_cant+"&id_pedidos="+id_pedidos+"&id_modelos="+id_modelos+"&categoria="+categoria);
        //var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
        ajax.open("GET", path+"abm_remera_ajax.php?agregar_pin="+agregar_pin+"&txt_cant="+txt_cant+"&id_pedidos="+id_pedidos+"&id_modelos="+id_modelos+"&categoria="+categoria, true);
        
        ajax.onreadystatechange=function() 
        { 
              //  alert(ajax.responseText);
               // div_carrito_pines.innerHTML=ajax.responseText;
               
               if (!(path=="")) {CargarDetallePines(path);}
                else {
                    CargarDetalle(); 
                    //alert('carganod detalle, path:'+path); 
                }
                
        }
        ajax.send(null);
        return true;
        

}
function CargarDetallePines(path)
{
        //Busco el Div de la imagen para cargarla.
		var div_preview_compra=document.getElementById('preview_compra'); 
        var div_carrito_pines=document.getElementById('carrito_pines'); 
        var div_texto_pines=document.getElementById('div_texto_pines'); 
        var id_pedidos=document.forms[0].elements['id_pedidos'].value;

      //  div_preview_compra.style.display="none";  
		div_carrito_pines.style.display="";  
		
        var ajax=nuevoAjax();    
           //el path
        ajax.open("GET", path+"cargar_detalle_pines_ajax.php?id_pedidos="+id_pedidos, true);

        ajax.onreadystatechange=function() 
        { 

            if (ajax.readyState==4)
            {
                
                div_carrito_pines.innerHTML=ajax.responseText;
               // alert(div_carrito_pines.innerHTML);
                var str = ajax.responseText;
                str = str.replace(/^\s*|\s*$/g,""); 

                hay_pines_agregados=(str!='');
                if (hay_pines_agregados)
                { div_carrito_pines.style.display="";  
                 div_texto_pines.style.display="none";  
                     
                }else
                {div_carrito_pines.style.display="none";  
                 div_texto_pines.style.display="";   }
            } 
        }
        ajax.send(null);
        return true;

}
function CargarPreviewPines(categoria,id_pines,path)
{
        //Busco el Div de la imagen para cargarla.
		var div_preview_compra=document.getElementById('preview_compra'); 
        var div_carrito_pines=document.getElementById('carrito_pines'); 
        var div_texto_pines=document.getElementById('div_texto_pines'); 
		div_preview_compra.style.display="";  
      
        var ajax=nuevoAjax();    
                
		//alert(id_pines);

		ajax.open("GET", path+"cargar_preview_pines_ajax.php?id_pines="+id_pines+"&categoria="+categoria, true);

        ajax.onreadystatechange=function() 
        { 

            if (ajax.readyState==4)
            {
                
                div_preview_compra.innerHTML=ajax.responseText;
               // alert(ajax.responseText);
                var str = ajax.responseText;
                str = str.replace(/^\s*|\s*$/g,""); 

                hay_pines_agregados=(str!='');
                if (hay_pines_agregados)
                { div_carrito_pines.style.display="";  
                 div_texto_pines.style.display="none";  
                     
                }else
                {div_carrito_pines.style.display="none";  
                 div_texto_pines.style.display="";   }
            } 
        }
        ajax.send(null);
        return true;

}
function CargarDetalle()
{
		//Busco el Div de la imagen para cargarla.
        var div_detalle_pedido=document.getElementById('div_detalle_pedido'); 

		
		var id_pedidos=document.forms[0].elements['id_pedidos'].value;
		var div_top_detalle=document.getElementById('top_detalle'); 
		var ajax=nuevoAjax();	
		
		ajax.open("GET", "cargar_detalle_ajax.php?id_pedidos="+id_pedidos, true);

		ajax.onreadystatechange=function() 
		{ 

			if (ajax.readyState==4)
			{
				div_top_detalle.innerHTML="&nbsp;";
				div_detalle_pedido.innerHTML=ajax.responseText;
				//alert(ajax.responseText);
				
				var str = ajax.responseText;
				str = str.replace(/^\s*|\s*$/g,""); 

				hay_remeras_agregadas=(str!='');
			} 
		}
		ajax.send(null);
		return true;

}
function MostrarPaso2()
{

 //hay_remeras_agregadas=true;
 
	if (hay_remeras_agregadas==true)
	{
     // alert('hayremeras');

		//Busco el Div de la imagen para cargarla.
        var div_datospers=document.getElementById('div_datospers'); 
        var div_combos=document.getElementById('div_combos');  
        if (div_datospers==null) alert('div datospers nulo');
         div_datospers.style.display="";  

        // document.forms[0].id_pedidos.value;

		var btncargopaso2=document.forms[0].btncargopaso2; 
        var divImagen=document.getElementById('divimagen'); 

		//var campo_id_pedidos=document.forms[0].elements['id_pedidos'];
		//document.forms[0].id_pedidos.value="4356";
		var id_pedidos=document.forms[0].id_pedidos.value;
		var div_top_detalle=document.getElementById('top_detalle'); 
		var div_btnpaso2=document.getElementById('div_btnpaso2'); 
		var div_btnpaso1=document.getElementById('div_btnpaso1'); 
		var divtxtimagen=document.getElementById('divtxtimagen'); 
		var divtxtimagen2=document.getElementById('divtxtimagen2'); 
		var div_titulo_2paso=document.getElementById('div_titulo_2paso'); 
		var div_titulo_1paso=document.getElementById('div_titulo_1paso'); 
		

				div_combos.style.display="none";
                
				div_btnpaso2.style.display="none";
                div_btnpaso1.style.display="";
				divImagen.style.display="none";
				divtxtimagen.style.display="none";
				divtxtimagen2.style.display="";
				div_titulo_1paso.style.display="none";
				div_titulo_2paso.style.display="";
			
//alert('btncargopaso2'+btncargopaso2.value);

        if (btncargopaso2.value=="")
        {
         
		var ajax=nuevoAjax();		
		ajax.open("GET", "cargar_datospers_ajax.php?id_pedidos="+id_pedidos, true);
		ajax.onreadystatechange=function() 
		{ 


			if (ajax.readyState==4)
			{
				//div_top_detalle.innerHTML="&nbsp;";


				div_datospers.innerHTML=ajax.responseText;
				btncargopaso2.value="SI";
				
			} 
		}
		ajax.send(null);
		
		}
	}else{alert('Agregar remeras al pedido para continuar.');}
				
		return true;

}
function MostrarPaso1()
{
		//Busco el Div de la imagen para cargarla.
        var div_datospers=document.getElementById('div_datospers'); 
        var div_combos=document.getElementById('div_combos'); 
		var div_btnpaso1=document.getElementById('div_btnpaso1'); 
        var div_btnpaso2=document.getElementById('div_btnpaso2'); 
		var divtxtimagen=document.getElementById('divtxtimagen'); 
		var divtxtimagen2=document.getElementById('divtxtimagen2'); 
		var div_titulo_2paso=document.getElementById('div_titulo_2paso'); 
		var div_titulo_1paso=document.getElementById('div_titulo_1paso'); 

		div_titulo_2paso

        div_combos.style.display="";
        div_datospers.style.display="none";
				div_btnpaso2.style.display="";
                div_btnpaso1.style.display="none";
				divtxtimagen.style.display="";
				divtxtimagen2.style.display="none";
				div_titulo_1paso.style.display="";
				div_titulo_2paso.style.display="none";
		return true;
}

function Mostrar(opcionenvio)
{	

		
		//Busco el Div de la imagen para cargarla.
        var div_horario_retiro=document.getElementById('div_horario_retiro'); 
        //var div_horario_entrega=document.getElementById('div_horario_entrega'); 
        
		var div_destinatario_correo=document.getElementById('div_destinatario_correo'); 
		var div_formapago=document.getElementById('div_formapago'); 
		var div_direccion_completa=document.getElementById('div_direccion_completa'); 
		var div_contraentrega=document.getElementById('div_contraentrega'); 

		//var campo_id_pedidos=document.forms[0].elements['id_pedidos'];
		//document.forms[0].id_pedidos.value="4356";

        if (opcionenvio=="1")
        {div_horario_retiro.style.display="";
      //  div_horario_entrega.style.display="none";
        div_destinatario_correo.style.display="none";
        div_formapago.style.display="none";
        div_direccion_completa.style.display="none";
        div_opciones_correo.style.display="none"; 
        }	

        if (opcionenvio=="2")
        {div_horario_retiro.style.display="none";
      //  div_horario_entrega.style.display="none";
        div_destinatario_correo.style.display="none";
        div_opciones_correo.style.display="none";  
        div_formapago.style.display="";
        div_direccion_completa.style.display="";
        div_contraentrega.style.display="";
        }	

        if (opcionenvio=="3")
        {
        div_opciones_correo.style.display="";  
        div_horario_retiro.style.display="none";
       // div_horario_entrega.style.display="";  
        div_destinatario_correo.style.display="";
        div_formapago.style.display="";
        div_direccion_completa.style.display="";
        div_contraentrega.style.display="none";
        }	


		return true;

}
function CancelarRemera()
{
		//Busco el Div de la imagen para cargarla.
        var div_detalle_pedido=document.getElementById('div_detalle_pedido'); 
		//var campo_id_pedidos=document.forms[0].elements['id_pedidos'];
		//document.forms[0].id_pedidos.value="4356";
		var id_pedidos=document.forms[0].id_pedidos.value;
		var div_top_detalle=document.getElementById('top_detalle'); 	

		
		var id_det_pedidos=document.forms[0].id_det_pedidos.value;
      
	
        //id_pedidos = '4356';
        var cancelar_remera = true;
		

		var ajax=nuevoAjax();		
		ajax.open("GET", "abm_remera_ajax.php?cancelar_remera="+cancelar_remera+"&id_pedidos="+id_pedidos+"&id_det_pedidos="+id_det_pedidos, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				div_top_detalle.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
		return true;
  }
  
function CancelarPin(id_det_pedidos,path)
{
        //Busco el Div de la imagen para cargarla.
      //  var div_detalle_pedido=document.getElementById('div_detalle_pedido'); 
        //var campo_id_pedidos=document.forms[0].elements['id_pedidos'];
        //document.forms[0].id_pedidos.value="4356";
        var id_pedidos=document.forms[0].id_pedidos.value;
     //   var div_top_detalle=document.getElementById('top_detalle');     

        
      
    
        //id_pedidos = '4356';
        var cancelar_remera = true;

        var ajax=nuevoAjax();        
        ajax.open("GET", path+"abm_remera_ajax.php?cancelar_remera="+cancelar_remera+"&id_pedidos="+id_pedidos+"&id_det_pedidos="+id_det_pedidos, true);
        ajax.onreadystatechange=function() 
        { 
                //div_top_detalle.innerHTML=ajax.responseText;
                CargarDetallePines(path); 
        }
        ajax.send(null);
        return true;
  }
  
  function RegistrarBusqueda(producto)
{
        //Busco el Div de la imagen para cargarla.
       // var txt_busqueda=document.getElementById(id); 
        //var campo_id_pedidos=document.forms[0].elements['id_pedidos'];
        //document.forms[0].id_pedidos.value="4356";
       var busqueda=document.forms[0].txt_buscar.value;   
      // alert(busqueda);
       // var busqueda=document.forms[0].txt_busqueda.value;
     //   var div_top_detalle=document.getElementById('top_detalle');     

        var ajax=nuevoAjax();        
        ajax.open("GET", "/catalogo/registrar_busqueda.php?busqueda="+encodeURIComponent(busqueda)+"&producto="+producto, true);
        ajax.onreadystatechange=function() 
        { 
             //   alert(ajax.responseText);
             //div_top_detalle.innerHTML=ajax.responseText;
               // CargarDetallePines(path); 
        }
        ajax.send(null);
        return true;
  }

function CombosVacios()
{
	//AgregarRemera(); 
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra
	var x=0;
	var faltandatos=false;
	
	while(combosFormRemeras[x])
	{
		var combo=document.getElementById(combosFormRemeras[x]);
		var opcionSeleccionada=combo.options[combo.selectedIndex].value;
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	    if(opcionSeleccionada=='0') 
			{ 
			 faltandatos = true;
             if (combosFormRemeras[x]=='color_estampa') {msg='Seleccionar un color de estamapado';}
             if (combosFormRemeras[x]=='color') {msg='Seleccionar un color de remera';} 
             if (combosFormRemeras[x]=='categoria') {msg='Seleccionar una categoria';} 
			 if (combosFormRemeras[x]=='remera') {msg='Seleccionar un modelo';} 
			 if (combosFormRemeras[x]=='talle') {msg='Seleccionar un talle de remera';} 
			 if (combosFormRemeras[x]=='material') {msg='Seleccionar un material de estampado';} 
			 alert(msg); 
			 }
		x++;
	}
	if (!faltandatos) {
	AgregarRemera();   }
return true;

}
function CombosPinesVacios()
{
	//AgregarRemera(); 
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra
    var combo=document.getElementById('remera');
        var id_modelos=combo.options[combo.selectedIndex].value;

    var combo2=document.getElementById('categoria');
        var categoria=combo2.options[combo2.selectedIndex].value;
        
	var x=0;
	var faltandatos=false;
	
	while(combosFormPines[x])
	{
		var combo=document.getElementById(combosFormPines[x]);
		var opcionSeleccionada=combo.options[combo.selectedIndex].value;
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	    if(opcionSeleccionada=='0') 
			{ 
			 faltandatos = true;
             if (combosFormPines[x]=='categoria') {msg='Seleccionar una categoria';} 
			 if (combosFormPines[x]=='remera') {msg='Seleccionar un modelo';} 
			 alert(msg); 
			 }
		x++;
	}
   // alert('en funcion combos pines vacios');
	if (!faltandatos) {
                              
	AgregarPin(categoria,id_modelos,'','1');   }
return true;

}
function ProcesarBajaNovedades()
{
	var faltandatos=false;
     var tabla_body=document.getElementById('tabla_body'); 
	var email=document.forms[0].txt_email_baja.value;
	var comentarios=document.forms[0].comentarios.value;  
	var motivo_baja=document.forms[0].motivo_baja;   
 
	var  motivo_baja_value = "";
	//alert('llego');
	
if (!(email==''))
	{
       for ( var i = 0; i < motivo_baja.length; i++ ) 
		{if ( motivo_baja[i].checked ) 
		     {motivo_baja_value=motivo_baja[i].value;}
	    }
		if (motivo_baja_value=='')	
	    {faltandatos=true; alert('Seleccione un motivo de baja antes de finalizar.'); 
	     }

	    
	 }else{faltandatos=true; alert('Ingrese su e-mail antes de finalizar.'); }
     
     if (!faltandatos) 
 	{
		//alert('procesa baja');
	 	var ajax=nuevoAjax();		
		ajax.open("GET", "procesar_baja_novedades_ajax.php?email="+encodeURIComponent(email)+"&motivo_baja="+encodeURIComponent(motivo_baja_value)+"&comentarios="+encodeURIComponent(comentarios), true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
                
				//div_top_detalle.innerHTML=ajax.responseText;      
				tabla_body.innerHTML=ajax.responseText;
				//alert(ajax.responseText);

				
			} 				
				
				
		}
		ajax.send(null);
	}


}

function EnviarPedido()
{
	//AgregarRemera(); 
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra

	var faltandatos=false;
    var nombre=document.forms[0].nombre.value;
	var email=document.forms[0].email.value;
	var tel=document.forms[0].tel.value;
	var opcionenvio=document.forms[0].opcionenvio; 
	var  opcionenvio_value = "";
    var serviciocorreo=document.forms[0].serviciocorreo; 
    var  serviciocorreo_value = "";
	var formapago=document.forms[0].formapago; 
	var  formapago_value = "";	
    var comentarios=document.forms[0].comentarios.value; 
	var news=document.forms[0].news.value; 



    var id_pedidos_temp=document.forms[0].elements['id_pedidos'].value;
    var div_body=document.getElementById('div_body');

	var horario_retiro=document.forms[0].horario_retiro.value;
 //   var horario_entrega=document.forms[0].horario_entrega.value; 
	var destinatario_correo=document.forms[0].destinatario_correo.value;
	var direccion=document.forms[0].direccion.value;

//var hay_remeras_agregadas=true; //borrar linea!!
if (hay_remeras_agregadas==true)
	{
    if (nombre=='')	{faltandatos=true; alert('Ingrese su nombre');}
    if (email=='')	{faltandatos=true; alert('Ingrese su email');}
	if (tel=='')	{faltandatos=true; alert('Ingrese su tel');}
	
    
    for ( var i = 0; i < opcionenvio.length; i++ ) 
		{if ( opcionenvio[i].checked ) 
		     {opcionenvio_value=opcionenvio[i].value;}
	    }
    for ( var i = 0; i < serviciocorreo.length; i++ ) 
        {if ( serviciocorreo[i].checked ) 
             {serviciocorreo_value=opcionenvio[i].value;}
        }
     for ( var i = 0; i < formapago.length; i++ ) 
		{if ( formapago[i].checked ) 
		     {formapago_value=formapago[i].value;}
	    }


	if (opcionenvio_value=='')	
	{faltandatos=true; alert('Seleccione una opcion de envio');
	}
	else
	{if (opcionenvio_value=='1')	
		{if (horario_retiro=='Escribe aqu&iacute; cuando queres pasar (Lu a Vie de 9 a 18hs)')	
		    {faltandatos=true; alert('Ingrese su preferencia horaria');}
		}
     if (opcionenvio_value=='2')	
		{if (direccion=='(Direccion/Codigo Postal/Localidad/Provincia)')	
		    {faltandatos=true; alert('Ingrese su Direccion Completa');}
	 if (formapago_value=='')	
		    {faltandatos=true; alert('Seleccione una forma de pago.');}
		}
	if (opcionenvio_value=='3')	
		{  if (serviciocorreo_value=='')    
            {faltandatos=true; alert('Seleccione el servicio de envio por correo: Standard o Premium.');}
            if (direccion=='(Direccion/Codigo Postal/Localidad/Provincia)')	
		    {faltandatos=true; alert('Ingrese su Direccion Completa');}
	     if (destinatario_correo=='')	
		    {faltandatos=true; alert('Ingrese el destinatario de correo');}       
        /* if (horario_entrega=='Escribe aqu&iacute; el rango horario para recibir el correo')    
            {faltandatos=true; alert('Ingrese el rango horario que desea para recibir el correo.');} */   
		 if (formapago_value=='')	
		    {faltandatos=true; alert('Seleccione una forma de pago.');}
         
		}
	}     
   
             
	//faltandatos=false;	
	if (!faltandatos) 
		
	{
		//alert('Fin del pedido');
	 	var ajax=nuevoAjax();		
		ajax.open("GET", "confirmar_pedido_ajax.php?id_pedidos_temp="+id_pedidos_temp+"&nombre="+encodeURIComponent(nombre)+"&email="+email+"&tel="+encodeURIComponent(tel)+"&opcionenvio_value="+encodeURIComponent(opcionenvio_value)+"&serviciocorreo_value="+encodeURIComponent(serviciocorreo_value)+"&formapago_value="+encodeURIComponent(formapago_value)+"&horario_retiro="+encodeURIComponent(horario_retiro)+"&destinatario_correo="+destinatario_correo+"&direccion="+encodeURIComponent(direccion)+"&comentarios="+encodeURIComponent(comentarios)+"&news="+news, true);
        ajax.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
                //alert("confirmar_pedido_ajax.php?id_pedidos_temp="+id_pedidos_temp+"nombre="+nombre+"email="+email+"tel="+tel+"opcionenvio_value="+opcionenvio_value+"formapago_value="+formapago_value+"horario_retiro="+horario_retiro+"destinatario_correo="+destinatario_correo+"direccion="+direccion+"comentarios="+comentarios);
				//alert(ajax.responseText);
				//div_top_detalle.innerHTML=ajax.responseText;    
				div_body.innerHTML=ajax.responseText;
			//	alert(ajax.responseText);

				
			} 				
				
				
		}
		ajax.send(null);
	}
		
	
	}else{alert('Agregar remeras al pedido para continuar.');}
    return true;

}

function EnviarEncuesta()
{
	
	
    var div_body=document.getElementById('div_body');

	var faltandatos=false;
    var nombre=document.forms[0].nombre.value;
	var email=document.forms[0].email.value;
	
	var id_pedidos=document.forms[0].elements['id_pedidos'].value;

	var fecha_pedido=document.forms[0].elements['fecha_pedido'].value;

	var tel=document.forms[0].elements['tel'].value;
	
	var comollegaste=document.forms[0].comollegaste; 
	var  comollegaste_value = "";
	var sistemacompra=document.forms[0].sistemacompra; 
	var  sistemacompra_value = "";	
    var sistemacompra_porque=document.forms[0].sistemacompra_porque.value;
    var volveria=document.forms[0].volveria; 
	var  volveria_value = "";
 
	var volveria_porque=document.forms[0].volveria_porque.value;
	var comentarios=document.forms[0].comentarios.value; 

	var noprocesarencuesta=document.forms[0].noprocesarencuesta.value; 



     for ( var i = 0; i < comollegaste.length; i++ ) 
		{if ( comollegaste[i].checked ) 
		     {comollegaste_value=comollegaste[i].value;}
	    }
     for ( var i = 0; i < sistemacompra.length; i++ ) 
		{if ( sistemacompra[i].checked ) 
		     {sistemacompra_value=sistemacompra[i].value;}
	    }
	for ( var i = 0; i < volveria.length; i++ ) 
		{if ( volveria[i].checked ) 
		     {volveria_value=volveria[i].value;}
	    }

    
     if (noprocesarencuesta=='true')	
		 { 
	      faltandatos=true;
		  alert ('La encuesta ya ha sido realizada previamente, solo se admite una encuesta por pedido.');

		 }else
	    {
			if (nombre=='')	{faltandatos=true; alert('No se ha encontrado un nombre correspondiente al pedido');}
			if (email=='')	{faltandatos=true; alert('No se ha encontrado un email correspondiente al pedido');}
			if (comollegaste_value=='')	{faltandatos=true; alert('Te faltó seleccionar una opción en "Como llegaste"');}
			if (sistemacompra_value=='')	{faltandatos=true; alert('Te faltó contarnos que te pareció el sistema de compras');}
			if (volveria_value=='')	{faltandatos=true; alert('Te faltó seleccionar si volverías a comprar en Ex-it');}
	     }
	
	 
		
   
		
	if (!faltandatos) 
		
	{
		
	 	var ajax=nuevoAjax();		
		ajax.open("GET", "guardar_encuesta_ajax.php?id_pedidos="+id_pedidos+"&nombre="+encodeURIComponent(nombre)+"&email="+email+"&tel="+tel+"&fecha_pedido="+fecha_pedido+"&comollegaste_value="+encodeURIComponent(comollegaste_value)+"&sistemacompra_value="+encodeURIComponent(sistemacompra_value)+"&volveria_value="+encodeURIComponent(volveria_value)+"&volveria_porque="+encodeURIComponent(volveria_porque)+"&sistemacompra_porque="+encodeURIComponent(sistemacompra_porque)+"&comentarios="+encodeURIComponent(comentarios), true);
		ajax.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');  
        ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
 
				//alert(ajax.responseText);
				div_body.innerHTML=ajax.responseText;
	
			} 				
				
				
		}
		ajax.send(null);
	}
		
	 

	
    return true;

}

function buscarEnArray(array, dato)
{
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra
	var x=0;
	while(array[x])
	{
		
		if(array[x]==dato) return x;
		x++;
	}
	return null;
}

function deshabilitarCombos(x)
{			selectActual=document.getElementById(combosFormRemeras[x]);
			selectActual.length=0;
			
			if (combosFormRemeras[x]=='remera')
			{var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccione el Modelo";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true; selectActual.style.border='';
			}
			if (combosFormRemeras[x]=='talle')
			{var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="(Talles...)";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true; selectActual.style.border='';
			}
			if (combosFormRemeras[x]=='material')
			{var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="(Estampado...)";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true; selectActual.style.border='';
			}
			if (combosFormRemeras[x]=='color')
			{var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="(Colores...)";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true; selectActual.style.border='';
			}
			if (combosFormRemeras[x]=='color_estampa')
			{var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="(Colores...)";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true; selectActual.style.border='';
			}

			
			

}

function cargaImagen()
{
					//---------------------Ajax para imAgen.------------------------
//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax
		var selectRemera=document.getElementById('remera');
        var id_modelos=selectRemera.options[selectRemera.selectedIndex].value;
		//alert(id_modelos);
		//Busco el Div de la imagen para cargarla.
        var divImagen=document.getElementById('divimagen'); 
		var divtxtImagen=document.getElementById('divtxtimagen'); 
		
		divtxtImagen.style.display="none";
	    divImagen.style.display="";
		var ajax=nuevoAjax();
			
		/*var ejs=document.getElementById('divimagen').innerHTML;
	    alert(ejs);*/
		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
//alert('imagen');
//alert('id modelo'+id_modelos);
		ajax.open("GET", "cargarimagen_ajax.php?modelo="+id_modelos, true);
		//alert('pasooo');	
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//alert('entro');
				var nuevoDiv=document.createElement("div");  nuevoDiv.innerHTML="Cargando...";
				divImagen.appendChild(nuevoDiv); 	
			}
			if (ajax.readyState==4)
			{
				//alert('fdsafasd');

				divImagen.innerHTML=ajax.responseText;

				
			} 
		}
		ajax.send(null);

}
function ocultarPrecio()
{		
var div_precio=document.getElementById('div_precio'); 
div_precio.innerHTML='';
}
function mostrarPrecio(productoSeleccionado)
{
					//---------------------Ajax para imAgen.------------------------
//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax

        //alert('pasooo');
       	        var combo=document.getElementById('remera');
        var id_modelos=combo.options[combo.selectedIndex].value;
		        var combo3=document.getElementById('talle');
        
		if (productoSeleccionado=='remeras')
		{
			var talle=combo3.options[combo3.selectedIndex].value;
			var combo4=document.getElementById('material');
			var material=combo4.options[combo4.selectedIndex].value;
			var div_precio=document.getElementById('div_precio'); 
   		    //alert('pasooo');
		    var ajax=nuevoAjax();

			ajax.open("GET", "mostrarprecio_ajax.php?id_modelos="+id_modelos+"&talle="+talle+"&material="+material, true);
		}else
	    { if (productoSeleccionado=='pines')
			{var div_precio=document.getElementById('div_precio'); 
   		     //alert('pasooo');
		     var ajax=nuevoAjax();
			 ajax.open("GET", "mostrarprecio_ajax.php?id_modelos="+id_modelos, true);
			}
		}
		

		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{

				
				div_precio.innerHTML=ajax.responseText;
			//	document.forms[1].div_precio.innerHTML=ajax.responseText;
				
			} 
		}
		ajax.send(null);

}

function cargaContenido(idSelectOrigen)
{
	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	var posicionSelectDestino=buscarEnArray(combosFormRemeras, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);

	 selectOrigen.style.border='';
     var btnagregar=document.getElementById('btnagregar');
	/* if (idSelectOrigen=='color_estampa')
		{ //alert('color_estampa');
		   
          btnagregar.style.backgroundColor='#FFCC00'; 
		}else
			{btnagregar.style.border=' border:"border-width:thick"  border-style: double";'; 
		     btnagregar.style.backgroundColor='';
			 }*/

	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	//alert(opcionSeleccionada);
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	if(opcionSeleccionada=='0')
	{
		var x=posicionSelectDestino, selectActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(combosFormRemeras[x])
		{
            deshabilitarCombos(x);
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena
	else if(idSelectOrigen!=combosFormRemeras[combosFormRemeras.length-1])
	{

		var x=posicionSelectDestino+1, selectActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(combosFormRemeras[x])
		{
            deshabilitarCombos(x);
			x++;
		}
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=combosFormRemeras[posicionSelectDestino];
	    var selectDestino=document.getElementById(idSelectDestino);
		//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax
		var selectRemera=document.getElementById('remera');
        var id_modelos=selectRemera.options[selectRemera.selectedIndex].value;
		//Selecciono el select Material y tomo el material seleccionado para pasarlo por ajax
		var selectMaterial=document.getElementById('material');
        var material_=selectMaterial.options[selectMaterial.selectedIndex].value;
		var selectTalle=document.getElementById('talle');
        var talle_=selectTalle.options[selectTalle.selectedIndex].value;


		var viene_novedades=document.forms[0].viene_novedades.value;
  
  // Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		
		//alert('viene_a llenar combos');
		//---------------------Ajax para combos.------------------------
		var ajax=nuevoAjax();
		//alert(id_modelos)		;
		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
		ajax.open("GET", "procesarcombos_ajax.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada+"&talle="+talle_+"&modelo="+id_modelos+"&material="+material_+"&viene_novedades="+viene_novedades, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				selectDestino.length=0;
				//var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				//selectOrigen.appendChild(nuevaOpcion); selectDestino.disabled=true;	
				viene_novedades=false;
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
				
			} 
		}
		ajax.send(null);

				
	

     
	}
}
function cargaContenidoCombosPines(idSelectOrigen)
{
	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	//var posicionSelectDestino=buscarEnArray(combosFormRemeras, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);

	 selectOrigen.style.border='';
     var btnagregar=document.getElementById('btnagregar');
	

	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	//alert(opcionSeleccionada);
	
	    var selectDestino=document.getElementById('remera');
		//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax
		var selectRemera=document.getElementById('remera');
        var id_modelos=selectRemera.options[selectRemera.selectedIndex].value;


		//var viene_novedades=document.forms[0].viene_novedades.value;

		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen		
		//alert('viene_a llenar combos');
		//---------------------Ajax para combos.------------------------
		var ajax=nuevoAjax();
				
		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
		ajax.open("GET", "procesarcombos_pines_ajax.php?opcion="+opcionSeleccionada+"&modelo="+id_modelos, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); selectDestino.disabled=true;	
				viene_novedades=false;
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
				
			} 
		}
		ajax.send(null);

}

function cargarCombosNovedades(viene_novedades)
{
	if (viene_novedades=='1')
	{
		
	//alert('valor viene_novedades'+viene_novedades);

		var DivDestino=document.getElementById('div_combos');
		//Selecciono el select Remera y tomo el modelo seleccionado para pasarlo por ajax
		var selectRemera=document.getElementById('remera');
        var id_modelos=selectRemera.options[selectRemera.selectedIndex].value;
		//Selecciono el select Material y tomo el material seleccionado para pasarlo por ajax
		var selectMaterial=document.getElementById('material');
        var material_=selectMaterial.options[selectMaterial.selectedIndex].value;
		var selectTalle=document.getElementById('talle');
        var talle_=selectTalle.options[selectTalle.selectedIndex].value;

		


	//	alert('viene_novedades');

		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		

		//---------------------Ajax para combos.------------------------
		var ajax=nuevoAjax();
				
		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
		ajax.open("GET", "procesarcombos_novedades_ajax.php?talle="+talle_+"&modelo="+id_modelos+"&material="+material_+"&viene_novedades="+viene_novedades, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				selectRemera.disabled=true;	
				//var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				//DivDestino.appendChild(nuevaOpcion); 
				viene_novedades=false;
			}
			if (ajax.readyState==4)
			{
				DivDestino.innerHTML=ajax.responseText;
				cargaImagen();
				
			} 
		}
		ajax.send(null);

	};		
	


}


function CambiarCombosSegunProducto(producto)
{
	
		
	//alert('valor viene_novedades'+viene_novedades);


		var DivDestino=document.getElementById('div_combos');
        var divtxtimagen=document.getElementById('divtxtimagen');
        var divImagen=document.getElementById('divimagen');

        divtxtimagen.style.display="";
	    divImagen.style.display="none";

		//alert('aca');

		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		

		//---------------------Ajax para combos.------------------------
		var ajax=nuevoAjax();
				
		//var id_modelo=combosFormRemeras[1].options[remera.selectedIndex].value;
		
		if (producto=='pines')
		{
			//alert('es pines');
			ajax.open("GET", "mostrar_combos_pines.php", true);
		}else
		{if (producto=='remeras')
				{ajax.open("GET", "mostrar_combos_remeras.php", true);}
		}

     
		
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
			
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				DivDestino.appendChild(nuevaOpcion); 
				viene_novedades=false;
			}        
			if (ajax.readyState==4)
			{
				//alert(ajax.responseText);
                DivDestino.innerHTML=ajax.responseText;
                //DivDestino.innerHTML='holaaaaaaaaaaaaaa';
                
				//cargaImagen();        
				
			} 
		}
		ajax.send(null);

		
	


}

