// JavaScript Document

// ------------------------------------------------------------ //
// --------------    VBLE DE DESARROLLO/PRODUCCIÓN------------- //
// ------------------------------------------------------------ //
//	var MAIN_FOLDER= '/rutadekaldi'; 	// Desarrollo
	var MAIN_FOLDER= '';				// Internet


// ----------------------------------- FUNCIONES EXCLUSIVAS DE AJAX ---------------------------------
// ----------------------------------- FUNCIONES EXCLUSIVAS DE AJAX ---------------------------------
// ----------------------------------- FUNCIONES EXCLUSIVAS DE AJAX ---------------------------------
// ----------------------------------- FUNCIONES EXCLUSIVAS DE AJAX ---------------------------------



// ----------------------------------- FUNCIONES PARA EL NAVEGADOR DE MUNDO --------------------
function navegador_compatible()
	{
		var xmlHttp;
		
        try // Firefox, Opera 8.0+, Safari
        {xmlHttp=new XMLHttpRequest();}
		catch (e) // Internet Explorer
		{			
            try
            {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
            catch (e)
			{
				try
				{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
                catch (e)
				{
					alert("¡Su explorador no soporta AJAX!");
                    return false;
				}
			}
        }		
		return xmlHttp;
	}
	
	
function actualizar_listnext_items_ajax(item_type_act,items_id,str_name,div_id,item_type_next) 
{
	var xmlHttp;
		
		
		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			actualizar_listado_items_sub_ajax(xmlHttp,item_type_act,items_id,str_name,div_id,item_type_next);
		}
}
	

function actualizar_listado_items_sub_ajax(xmlHttp, item_type_act,items_id,str_name,div_id,item_type_next)
{ 
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('list_ppal_'+item_type_next).innerHTML = xmlHttp.responseText;
			
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=actualizar_listado_items&v1='+encodeURI(item_type_act)+'&v2='+encodeURI(items_id)+'&v3='+encodeURI(div_id)+'&v4='+encodeURI(item_type_next), true);
    xmlHttp.send(null);		
}	

//-----------------
function comprobar_codigo_cliente() 
{
	var xmlHttp;
	var cod_client;
	
		cod_client= document.getElementById('cod_client').value;
		//alert(cod_client);
		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			comprobar_codigo_cliente_sub_ajax(xmlHttp,cod_client);
		
		}
}
	

function comprobar_codigo_cliente_sub_ajax(xmlHttp,cod_client)
{ 
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_cod_cliente').innerHTML = xmlHttp.responseText;
				window.document.location.reload(true);
			
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=comprobar_codigo_cliente&v1='+encodeURI(cod_client), true);
    xmlHttp.send(null);		
	
	
}	


function cerrar_sesion() 
{
	var xmlHttp;
	
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			cerrar_sesion_sub_ajax(xmlHttp);
		}
}
	

function cerrar_sesion_sub_ajax(xmlHttp)
{
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_cod_cliente').innerHTML = xmlHttp.responseText;
			window.document.location.reload(true);
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=cerrar_sesion', true);
    xmlHttp.send(null);	
		
}	


function add_product_shopping_cart(seccion,id_art,nombre_art,precio) 
{
	var xmlHttp;

		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			add_product_shopping_cart_sub_ajax(xmlHttp,seccion,id_art,nombre_art,precio);
		}
}
	

function add_product_shopping_cart_sub_ajax(xmlHttp,seccion,id_art,nombre_art,precio)
{
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_shopping_cart').innerHTML = xmlHttp.responseText;
			//document.location.href = document.location.href;
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=add_product_shopping_cart&v1='+encodeURI(seccion)+'&v2='+encodeURI(id_art)+'&v3='+encodeURI(nombre_art)+'&v4='+encodeURI(precio), true);
    xmlHttp.send(null);		
}	

function delete_art_shoppingcart(seccion,id_art,cant,recargar) 
{
	var xmlHttp;

		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			delete_art_shoppingcart_sub_ajax(xmlHttp,seccion,id_art,cant,recargar,seccion);
		}
}
	

function delete_art_shoppingcart_sub_ajax(xmlHttp,seccion,id_art,cant,recargar)
{
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_shopping_cart').innerHTML = xmlHttp.responseText;
			//document.location.href = document.location.href;
			if ((recargar=='true')||(seccion=='carrito'))
			{
				document.location.href = document.location.href;
			}
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=delete_art_shoppingcart&v1='+encodeURI(seccion)+'&v2='+encodeURI(id_art)+'&v3='+encodeURI(cant), true);
    xmlHttp.send(null);		
	
	
}	

function reintentar() 
{
	var xmlHttp;
	
		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			reintentar_sub_ajax(xmlHttp);
		}
}
	

function reintentar_sub_ajax(xmlHttp)
{
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_cod_cliente').innerHTML = xmlHttp.responseText;
			
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=reintentar', true);
    xmlHttp.send(null);		
}	



// ---------------------------------FIN  FUNCIONES PARA EL NAVEGADOR DE MUNDO --------------------

// ---------------------------------  FUNCIONES PARA EL NAVEGADOR TAB HORIZONTAL ---------------

//Modifica el fondo del tab que se ha pinchado
//parametros:
//*item_type: tipo del item, cada item_type tiene su propio navegadro, el id de cada uno se diferenciara por el item_type al que pertenezca
//*item_act: tab que se ha pulsado

function modify_tab_class(item_type,item_act)
{
	
	var x = document.getElementById('tabnav_'+item_type);
	var y = x.getElementsByTagName('li');
	
	
		for (var i=0;i<y.length;i++)
		{
			if (y[i].className == 'activo') {y[i].className = 'inactivo'}
		}
	document.getElementById('li_tabnav_'+item_act).className='activo';
}


//Funcion que modifica el contenido de la pantalla segun la pestaña horizontal pinchada

function clicar_tab(tab, item_type, item_id, div_id)
{ 
	var xmlHttp;

	if (xmlHttp=navegador_compatible())
	{		
			// Cambiamos las áreas
			clicar_tab_sub_ajax(xmlHttp, tab, item_type, item_id, div_id);
	}
	
}	


function clicar_tab_sub_ajax(xmlHttp, tab, item_type, item_id, div_id)
{
	 modify_tab_class(item_type,tab);
		 xmlHttp.onreadystatechange=function()
        {
		    if(xmlHttp.readyState==4)
            {	
				document.getElementById(div_id).innerHTML = xmlHttp.responseText;
			
            }        
		}
       xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=clicar_tab&v1='+encodeURI(tab)+'&v2='+encodeURI(item_type)+'&v3='+encodeURI(item_id), true);
	   xmlHttp.send(null);	
	}
	

//***+  FUNCIONES PARA BORRAR UN ITEM--------------***/
//Borramos un mensaje al pulsar en el icono
function borrar_item_related(div_id,item_type,item_id)
{
	
	var xmlHttp;
	
	
	if (xmlHttp=navegador_compatible())
		{	
			// Cambiamos el valor del voto
			borrar_item_related_sub_ajax(xmlHttp,div_id,item_type,item_id);
		}
}


function borrar_item_related_sub_ajax(xmlHttp,div_id,item_type,item_id)
{
	xmlHttp.onreadystatechange=function()
        {
		    if(xmlHttp.readyState==4)
            {	
				document.getElementById(div_id).innerHTML = xmlHttp.responseText;
			
            }        
		}
       xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=borrar_item_related&v1='+encodeURI(item_type)+'&v2='+encodeURI(item_id), true);
	   xmlHttp.send(null);	
}


//********************** FUNCIONES PARA EL NAVEGADOR DEL EDITOR DE NOTICIAS*******/


//-----------------Funciones de los div navegadores de items en el editor de noticias
//dado el item_type, y un id, mostra una lista de sugerencias para añadir a nuestro navegador del editor de noticias
//*item_type: Tipo del Item que queremos actualizar
//*item_id: Id del Item por el que hay que filtrar la busqueda del item_type
//*div_suggest_id: id del div donde se listaran los datos 
//*div_content_id: id del div donde se añadira el item_seleccionado
//*item_name: nombre del item por el que filtraremos la busqueda de los datos

function act_list_box_editnews_ajax(item_type,item_id,div_suggest_id,div_content_id,item_name,item_next_type)
{
		
	var xmlHttp;
	
	if (xmlHttp=navegador_compatible())
	{			
		// Cambiamos las áreas
		act_list_box_editnews_sub_ajax(xmlHttp,item_type,item_id,div_suggest_id,item_name,div_content_id,item_next_type);
	}
	
}

function act_list_box_editnews_sub_ajax(xmlHttp,item_type,item_id,div_suggest_id,item_name,div_content_id,item_next_type)
{ 

  xmlHttp.onreadystatechange=function()
        {
		    if(xmlHttp.readyState==4)
			{
				document.getElementById(div_suggest_id+item_next_type).innerHTML = xmlHttp.responseText;
				
            }
        }
        xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=act_list_box_editnews&v1='+encodeURI(item_type)+'&v2='+encodeURI(item_id)+'&v3='+encodeURI(item_name)+'&v4='+encodeURI(div_content_id)+'&v5='+encodeURI(item_next_type), true);
        xmlHttp.send(null);		
        	
}

//funcion que rellena la lista de sugerencias del item siguiente segun la cabecera del intem en el que nos encontramos
function construir_lista_newsedit(item_type_click,item_id_click,item_type_next,div_content_id)
{
	var xmlHttp;
	//alert(div_id_content);
	if (xmlHttp=navegador_compatible())
	{			
		// Cambiamos las áreas
		construir_lista_newsedit_sub_ajax(xmlHttp,item_type_click,item_id_click,item_type_next,div_content_id);
	}
	
}

function construir_lista_newsedit_sub_ajax(xmlHttp,item_type_click,item_id_click,item_type_next,div_content_id)
{
	
	
	 xmlHttp.onreadystatechange=function()
        {
		    if(xmlHttp.readyState==4)
            {	
				document.getElementById(div_content_id+item_type_next).innerHTML = xmlHttp.responseText;
							
            }        
		}
       xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=construir_lista_newsedit&v1='+encodeURI(item_type_click)+'&v2='+encodeURI(item_id_click)+'&v3='+encodeURI(item_type_next)+'&v4='+encodeURI(div_content_id), true);
	   xmlHttp.send(null);	
}


//funcion que rellena el contendor del navegador del editor de noticias
function change_item_nav_edit_news(item_type_click,item_id_click,div_content_id,item_name,item_type_next)
{
		
	//alert(item_type_next);
	var div_id=document.getElementById('head_linkbox_'+item_type_click);
	var texto= "<a href=\"#\" onclick=\"open_link_box_editnews("+item_type_click+",'list_headbox_suggest_"+item_type_click+"');\">"+item_name+"</a>"; 
	div_id.innerHTML=texto;  
	close_link_box_editnews(item_type_click,'list_headbox_suggest_'+item_type_click);
//	alert(item_type);
	//actualizamos la lista de items para el filtrado del navegador de cabecera
	construir_lista_newsedit(item_type_click,item_id_click,item_type_next,'list_headbox_suggest_');
	//actualizamos la lista de items para el filtrado del navegador de cabecera
	act_list_box_editnews_ajax(item_type_next,item_id_click,'content_box_suggest_','content_box_',item_name,item_type_next);
}


function open_link_box_editnews(item_type,div_id)
{
	var str='div #'+div_id;
	$(str).slideToggle('slow');
}


function add_link_nav_edit_news(item_type,div_content_id,link_name,link_str)
{
	//alert(div_content_id+item_type);
	var div_id=document.getElementById(div_content_id+item_type);
	var texto= "<a href=\"#\" onclick=\"add_link_text_edit_news('"+link_name+"','"+link_str+"') \">"+link_name+'</a><br/>'; 
	texto=div_id.innerHTML+texto;
	//alert(texto);
	div_id.innerHTML=texto;  
	close_link_box_editnews(item_type,'content_box_suggest_'+item_type);
	
}




function actualizar_content_products(pagina) 
{
	var xmlHttp;
		
		
		
		if (xmlHttp=navegador_compatible())
		{			
			// Cambiamos las áreas
			actualizar_content_products_sub_ajax(xmlHttp,pagina);
		}
}
	

function actualizar_content_products_sub_ajax(xmlHttp, pagina)
{ 
    xmlHttp.onreadystatechange=function()
    {
	    if(xmlHttp.readyState==4)
		{
			document.getElementById('div_contenedor_productos').innerHTML = xmlHttp.responseText;
			
        }
    }
    xmlHttp.open('GET', MAIN_FOLDER+'/index.php?mod=ajax&f=actualizar_content_products&v1='+encodeURI(pagina), true);
    xmlHttp.send(null);		
}	

