﻿
//cambia la imagen del título del tipo de evento al dejar de estar encima
function changeColor(titleName, imgUrl)
{
	var img=document.getElementById(titleName);
	if(img.activo!="true")
	{
		img.src=imgUrl;
	}
}

//seleciona una opción del menú: cambiar logo y título y mostrar sus opciones. 
//Además, las otras opciones del menú se han de dejar bien
// logoName: nombre de la imagen de logo (del tipo que se selecciona)
// titleName: nombre de la imagen del nombre (del tipo que se selecciona)
// divName: nombre de la lista de opciones (del tipo que se selecciona)
// rutaImages: ruta donde están las imagenes
// imgNormal: imagen normal (del tipo que se selecciona)
// imgActiva: imagen activa (del tipo que se selecciona)
function selectOption(logoName, titleName, divName, rutaImages, imgNormal, imgActiva)
{
	var logo=document.getElementById(logoName);
	var seccion=document.getElementById(titleName);
	var lista=document.getElementById(divName);
	var i, j;
	var menu;

	logo.src=rutaImages + "botonrojo.gif";
	logo.style.cursor="default";
	//nos guardamos que está activo
	seccion.activo="true";
	//nos guardamos la imagen normal
	seccion.imgNormal=rutaImages + imgNormal;
	//cambiar la presencia
	seccion.src=rutaImages + imgActiva;
	seccion.style.cursor="default";
	//mostrar sus opciones
	lista.style.display="";
	
	//recorrer los nodos (<li>) del menú
    menu=document.getElementById('menulist');
	for(i=0;i<menu.childNodes.length;i++)
	{
		//recorrer las imágenes
		if (menu.childNodes[i].nodeType == 1)  //En FF hay que mirar el tipo de nodo
		{
	        var arImgs=menu.childNodes[i].getElementsByTagName("img");
	        for(j=0;j<arImgs.length;j++)
	        {
    	        if (arImgs[j].id!=logoName && arImgs[j].id!=titleName)
    	        {
    	            if (arImgs[j].id.lastIndexOf('imgLogo')>=0)
    	            {
    	                logo=arImgs[j];
    	                logo.src=rutaImages + "logoblanco.jpg";
    	                logo.style.cursor="pointer";
    	            }
    	            if (arImgs[j].id.lastIndexOf('imgType')>=0)
    	            {
    	                seccion=arImgs[j];
    	                //nos guardamos que ya no está activo
                        seccion.activo="false";
                        //cambiar la presencia, volver a la imagen normal
                        if (seccion.imgNormal!="" && seccion.imgNormal!=undefined)
                            seccion.src=seccion.imgNormal;
                        seccion.style.cursor="pointer";
    	            }
    	        }
            }
            
		    //recorrer los divs
	        var arDivs=menu.childNodes[i].getElementsByTagName("div");
	        for(j=0;j<arDivs.length;j++)
	        {
	            if (arDivs[j].id!=divName)
    	        {
    	            if (arDivs[j].id.lastIndexOf('pnOptions')>=0)
    	            {
    	                lista=arDivs[j];
			            //ocultar las opciones
			            lista.style.display="none";
    	            }
    	        }
	        }
	    }
    }
}

/*** BuyDelivery ***/
//Formatear el formulario de los datos de entrega
function DeliveryData(locationType, locationName, CaptionLocation, contactName, CaptionContact, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName)
{
    var div=document.getElementById('DatosEntrega');
    var divlocation1=document.getElementById('location1');
    var divlocation2=document.getElementById('location2');
    var divnote=document.getElementById('note');
    var location, contact;
    
    if (locationType=="1")
    {
        //MailBoxes
        /*
        div.style.display = 'block';
        location=document.getElementById(locationName);
        contact=document.getElementById(contactName);
        location.innerText  = CaptionLocation;
        contact.innerText  = CaptionContact;
        divlocation1.style.display = 'block';
        divlocation2.style.display = 'block';
        divnote.style.display = 'none';
        //Habilitar validaciones
        SetAllValidators(true, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName);
        */
        div.style.display = 'none';
        //Deshabilitar validaciones
        SetAllValidators(false, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName);
    }
    else
    if (locationType=="2")
    {
        //Hotel
        div.style.display = 'block';
        location=document.getElementById(locationName);
        contact=document.getElementById(contactName);
        location.innerText  = CaptionLocation;
        contact.innerText  = CaptionContact;
        divlocation1.style.display = 'block';
        divlocation2.style.display = 'block';
        divnote.style.display = 'block';
        //Habilitar validaciones
        SetAllValidators(true, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName);
    }
    else
    if (locationType=="3")
    {
        //Home
        div.style.display = 'block';
        contact=document.getElementById(contactName);
        contact.innerText  = CaptionContact;
        divlocation1.style.display = 'none';
        divlocation2.style.display = 'none';
        divnote.style.display = 'none';
        //Primero habilitar validaciones
        SetAllValidators(true, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName);
        //Deshabilitar validación
        valLocation = document.getElementById(locationValName);
        ValidatorEnable(valLocation, false);  
    }
    else
    if (locationType=="0")
    {
        //Later...
        div.style.display = 'none';
        //Deshabilitar validaciones
        SetAllValidators(false, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName);
    }
}

//Activa o desactiva todos los validadores
function SetAllValidators(validate, locationValName, contactValName, addressValName, cityValName, zipValName, countryValName)
{
    var valLocation, valContact, valAddress, valCity, valZIPCode, valCountry;
    
    valLocation = document.getElementById(locationValName);
    ValidatorEnable(valLocation, validate);
    valContact = document.getElementById(contactValName);
    ValidatorEnable(valContact, validate);
    valAddress = document.getElementById(addressValName);
    ValidatorEnable(valAddress, validate);
    valCity = document.getElementById(cityValName);
    ValidatorEnable(valCity, validate);
    valZIPCode = document.getElementById(zipValName);
    ValidatorEnable(valZIPCode, validate);
    valCountry = document.getElementById(countryValName);
    ValidatorEnable(valCountry, validate);
}

//Establecer datos en el formulario de los datos de entrega
function SetDeliveryData(txtLocationName, txtContactName, txtAddressName, txtCityName, txtZIPCodeName, ddlCountryName, txtCommentsName, location, contact, address, city, zipcode, country, comments, divDeliveryCostName, idIdiom)
{
    var txtLocation, txtContact, txtAddress, txtCity, txtZIPCode, ddlCountry, txtComments;
    
    txtLocation=document.getElementById(txtLocationName);
    txtContact=document.getElementById(txtContactName);
    txtAddress=document.getElementById(txtAddressName);
    txtCity=document.getElementById(txtCityName);
    txtZIPCode=document.getElementById(txtZIPCodeName);
    ddlCountry=document.getElementById(ddlCountryName);
    txtComments=document.getElementById(txtCommentsName);
    
    txtLocation.value=location;
    txtContact.value=contact;
    txtAddress.value=address;
    txtCity.value=city;
    txtZIPCode.value=zipcode;
    ddlCountry.value=country;
    txtComments.value=comments;
    
    //Si se selecciona un país por defecto, mostrar su gastos de envío
    if (country!='')
        GetDeliveryCost(ddlCountryName, divDeliveryCostName, idIdiom);
}

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

//Validación de la cantidad introducida en la cesta
function ValidateQuantityCart(idCart, txtQuantityName, divMessagesName, idIdiom) 
{
    var quantity = $get(txtQuantityName).value;

    //El último parámetro es el nombre del control donde mostrar la información
    PageMethods.ValidateQuantity(idCart, quantity, idIdiom, OnCompleteValidateQuantity, OnErrorValidateQuantity, divMessagesName);
}

function OnCompleteValidateQuantity(result, userContext, methodName)
{
    if (result=="")
        $get(userContext).className='hideMessage';
    else
    {
        $get(userContext).className='showMessage';
        $get(userContext).innerHTML=result;
    }
}

function OnErrorValidateQuantity(objError, userContext, methodName)
{
    // Display the error message. 
    $get(userContext).className='showMessage';
    $get(userContext).innerHTML=objError.get_message();
} 


//Obtener el gasto de entrega
function GetDeliveryCost (ddlCountryName, divDeliveryCostName, idIdiom)
{
    var combo = $get(ddlCountryName);
    var idcountry = combo.options[combo.selectedIndex].value;
    
    //El último parámetro es el nombre del control donde mostrar la información
    PageMethods.GetDeliveryCost(idcountry, idIdiom, OnCompleteGetDeliveryCost, OnErrorGetDeliveryCost, divDeliveryCostName);
}

function OnCompleteGetDeliveryCost(result, userContext, methodName)
{
    if (result=="")
        $get(userContext).className='hideDeliveryCost';
    else
    {
        $get(userContext).className='showDeliveryCost';
        $get(userContext).innerHTML=result;
    }
}

function OnErrorGetDeliveryCost(objError, userContext, methodName)
{
    // Display the error message. 
    $get(userContext).className='showDeliveryCost';
    $get(userContext).innerHTML=objError.get_message();
}
