﻿function preloadImages()
{
	// Establezco las imágenes
	$("#divQuienesSomos").css("background-image","url(images/quienesSomos.jpg)");
	$("#divQuienesSomosMemorias").css("background-image","url(images/quienesSomosMemorias.jpg)");
	$("#divServicios").css("background-image","url(images/servicios.jpg)");
	//$("#divSituacion").css("background-image","url(images/situacion.jpg)");
	$("#divContacta").css("background-image","url(images/contacta.jpg)");

	$("#divPortfolioAirbusContent").css("background-image","url(images/portfolioAirbus.jpg)");
	$("#divPortfolioAXAContent").css("background-image","url(images/portfolioAXA.jpg)");
	$("#divPortfolioBostonContent").css("background-image","url(images/portfolioBoston.jpg)");
	$("#divPortfolioCorteInglesContent").css("background-image","url(images/portfolioCorteIngles.jpg)");
	$("#divPortfolioCuatreCasasContent").css("background-image","url(images/portfolioCuatreCasas.jpg)");
	$("#divPortfolioGlaxoContent").css("background-image","url(images/portfolioGlaxo.jpg)");
	$("#divPortfolioWaterHouseContent").css("background-image","url(images/portfolioWaterHouse.jpg)");
	$("#divPortfolioSolgarContent").css("background-image","url(images/portfolioSolgar.jpg)");
	$("#divPortfolioTelecorContent").css("background-image","url(images/portfolioTelecor.jpg)");
	$("#divPortfolioNovoNordiskContent").css("background-image","url(images/portfolioNordisk.jpg)");
	$("#divPortfolioLineaDirectaContent").css("background-image","url(images/portfolioLineaDirecta.jpg)");
//	$("#divPortfolioFundacionContent").css("background-image","url(images/portfolioFundacion.jpg)");


	// Hago un preload de ellas
	var preload_image_object = new Image();

	image_url = new Array();
	image_url.push("images/portfolioAXA.jpg");
	image_url.push("images/portfolioAXA.jpg");
	image_url.push("images/portfolioBoston.jpg");
	image_url.push("images/portfolioCorteIngles.jpg");
	image_url.push("images/portfolioCuatreCasas.jpg");
	image_url.push("images/portfolioGlaxo.jpg");
	image_url.push("images/portfolioWaterHouse.jpg");
	image_url.push("images/portfolioSolgar.jpg");
	image_url.push("images/portfolioTelecor.jpg");
	image_url.push("images/portfolioLineaDirecta.jpg");
	image_url.push("images/portfolioNordisk.jpg");
//	image_url.push("images/portfolioFundacion.jpg");
	
	image_url.push("images/quienesSomos.jpg");
	image_url.push("images/quienesSomosMemorias.jpg");
	image_url.push("images/servicios.jpg");
	image_url.push("images/situacion.jpg");
	image_url.push("images/contacta.jpg");

	image_url.push("images/busy.gif");

	var i = 0;
	for(i=0 ; i < image_url.length ; i++)
	{
		preload_image_object.src = image_url[i];
	}
	//$('img[@src$=.png]').ifixpng();
}


function posicionarCapas()
  {
  	var left = document.getElementById("container").offsetLeft;
	var newLeft = eval(left + 8) + "px";
	var newTop = "75px";

	document.getElementById("Home").style.left = newLeft;
	document.getElementById("Home").style.top = newTop;

	document.getElementById("QuienesSomos").style.left = newLeft;
	document.getElementById("QuienesSomos").style.top = newTop;

	document.getElementById("QuienesSomosMemorias").style.left = newLeft;
	document.getElementById("QuienesSomosMemorias").style.top = newTop;

	document.getElementById("Servicios").style.left = newLeft;
	document.getElementById("Servicios").style.top = newTop;

	document.getElementById("Portfolio").style.left = newLeft;
	document.getElementById("Portfolio").style.top = newTop;

	document.getElementById("portfolioDivs").style.left = newLeft;
	document.getElementById("portfolioDivs").style.top = newTop;
	
	document.getElementById("ONGDivs").style.left = newLeft;
	document.getElementById("ONGDivs").style.top = newTop;

	document.getElementById("AreaClientes").style.left = newLeft;
	document.getElementById("AreaClientes").style.top = newTop;

	document.getElementById("Presupuesto").style.left = newLeft;
	document.getElementById("Presupuesto").style.top = newTop;

	document.getElementById("Situacion").style.left = newLeft;
	document.getElementById("Situacion").style.top = newTop;

	document.getElementById("Contacta").style.left = newLeft;
	document.getElementById("Contacta").style.top = newTop;
  }

  function Show(panel)
  {
    $(".initialHidden").hide();
    $(".portfolioHidden").hide();
	
    if (lastPanel != panel)
    {
      $('#' + lastPanel).fadeOut(1000);
      if (lastPanel == "QuienesSomosMemorias")
	  	$('#aMenuQuienesSomos').removeClass('selected');
	  else
	    $('#aMenu' + lastPanel).removeClass('selected');
    }

    $('#' + panel).fadeIn(1000);

	if (panel == "QuienesSomosMemorias")
		$('#aMenuQuienesSomos').addClass('selected');
	else
	    $('#aMenu' + panel).addClass('selected');

    lastPanel = panel;

	if (panel == "Situacion")
		$('#imgAccionSocial').show();
	else
		$('#imgAccionSocial').hide();
	
	if ((panel = "AreaClientes") && (!iframeLoaded))
	{
		document.getElementById("iframeAreaClientes").src = "clientes.php";
		iframeLoaded = true;
	}

    return false;
  }

  function ShowPortfolioPanel(panel)
  {
    //$(".portfolioHidden").hide();

    $('#' + lastPortfolioPanel).hide();
    $('#' + panel).show();

//    $('#' + lastPortfolioPanel).fadeOut(1000);
//    $('#' + panel).fadeIn(1000);

    lastPortfolioPanel = panel;
  }
  
  function ShowONGPanel(panel)
  {
	$('#imgAccionSocial').hide();
    $('#' + lastONGPanel).hide();
    $('#' + panel).show();

    lastONGPanel = panel;
  }
  
  

  function windowOnLoad()
  {
    preloadImages();
  }

  function windowOnReload()
  {
    posicionarCapas();
  }


function formPresupuestoAcabadoChange(value)
{
	var e = document.getElementById("formAcabadoOtros");
	if (value == "Otros")
	{
		e.style.visibility = 'visible';
	}
	else
	{
		e.style.visibility = 'hidden';
		e.value = '';
	}
}

function sendContacto()
{
	$.blockUI( '<h1 class="block"><img src="images/busy.gif" /> Enviando...</h1>' );

	if ((document.getElementById("formContactoEmail").value == "") && (document.getElementById("formContactoTelefono").value == ""))
	{
		$.blockUI('<div id="alertFormERROR" style="cursor: default"><h1 class="alert">Debe indicar un tel&#233;fono o un EMail para que podamos contactar con usted</h1><input type="button" id="aceptarAlertBtn" onclick="$.unblockUI()" value="Aceptar" style="margin-bottom: 10px;" /></div>');
		return;
	}
	if (document.getElementById("formContactoConsulta").value == "")
	{
		$.blockUI('<div id="alertFormERROR" style="cursor: default"><h1 class="alert">Por favor, indiquenos su consulta</h1><input type="button" id="aceptarAlertBtn" onclick="$.unblockUI()" value="Aceptar" style="margin-bottom: 10px;" /></div>');
		return;
	}

	var sendData = "action=sendContacto";

	sendData = sendData + "&formContactoNombre=" + document.getElementById("formContactoNombre").value;
	sendData = sendData + "&formContactoEmail=" + document.getElementById("formContactoEmail").value;
	sendData = sendData + "&formContactoTelefono=" + document.getElementById("formContactoTelefono").value;
	sendData = sendData + "&formContactoConsulta=" + document.getElementById("formContactoConsulta").value;

	$.ajax({
		url: "sendPresupuesto.php",
	   	type: "POST",
	   	data: sendData,
	   	success: sendContacto_CB
	});
}

function sendContacto_CB(responseText,textStatus, XMLHttpRequest)
{
	$.unblockUI();
	if (responseText == 'OK')
	{
		alert("Enviado");
	}
    else
    {
    	alert("Ha ocurrido un error");
	}
}


function sendPresupuesto()
{
	$.blockUI( '<h1 class="block"><img src="images/busy.gif" /> Enviando...</h1>' );

	if ((document.getElementById("formTelefono").value == "") && (document.getElementById("formEMail").value == ""))
	{
		$.blockUI('<div id="alertFormERROR" style="cursor: default"><h1 class="alert">Debe indicar un tel&#233;fono o un EMail</h1><input type="button" id="aceptarAlertBtn" onclick="$.unblockUI()" value="Aceptar" style="margin-bottom: 10px;" /></div>');
		return;
	}
	if (document.getElementById("formContacto").value == "")
	{
		$.blockUI('<div id="alertFormERROR" style="cursor: default"><h1 class="alert">Debe indicar una persona de contacto</h1><input type="button" id="aceptarAlertBtn" onclick="$.unblockUI()" value="Aceptar" style="margin-bottom: 10px;" /></div>');
		return;
	}

	var sendData = "action=sendMail";

	sendData = sendData + "&formEmpresa=" + document.getElementById("formEmpresa").value;
	sendData = sendData + "&formDireccion=" + document.getElementById("formDireccion").value;
	sendData = sendData + "&formTelefono=" + document.getElementById("formTelefono").value;
	sendData = sendData + "&formEMail=" + document.getElementById("formEMail").value;
	sendData = sendData + "&formContacto=" + document.getElementById("formContacto").value;

	sendData = sendData + "&formCantidades=" + document.getElementById("formCantidades").value;
	sendData = sendData + "&formFormatoAbierto=" + document.getElementById("formFormatoAbierto").value;
	sendData = sendData + "&formFormatoCerrado=" + document.getElementById("formFormatoCerrado").value;
	sendData = sendData + "&formInteriorNumPaginas=" + document.getElementById("formInteriorNumPaginas").value;
	sendData = sendData + "&formInteriorPapel=" + document.getElementById("formInteriorPapel").value;
	sendData = sendData + "&formInteriorImpresion=" + document.getElementById("formInteriorImpresion").value;
	sendData = sendData + "&formExteriorNumPaginas=" + document.getElementById("formExteriorNumPaginas").value;
	sendData = sendData + "&formExteriorPapel=" + document.getElementById("formExteriorPapel").value;
	sendData = sendData + "&formExteriorImpresion=" + document.getElementById("formExteriorImpresion").value;
	sendData = sendData + "&formAcabado=" + document.getElementById("formAcabado").value;
	sendData = sendData + "&formAcabadoOtros=" + document.getElementById("formAcabadoOtros").value;
	sendData = sendData + "&formEncuadernacion=" + document.getElementById("formEncuadernacion").value;

	$.ajax({
		url: "sendPresupuesto.php",
	   	type: "POST",
	   	data: sendData,
	   	success: sendPresupuesto_CB
	});
	//document.getElementById("presupuestoForm").submit();
}


function sendPresupuesto_CB(responseText,textStatus, XMLHttpRequest)
{
	$.unblockUI();
//	$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: 'transparent' });
	if (responseText == 'OK')
	{
		alert("Presupuesto enviado");
//        $.blockUI('<div id=\"alertFormERROR\" style=\"cursor: default\"><h1 class=\"alert\">El presupuesto se ha enviado correctamente, nos pondremos en contacto contigo tan pronto nos sea posible</h1><input type=\"button\" id=\"aceptarAlertBtn\" onclick=\"$.unblockUI()\" value=\"Aceptar\" style=\"margin-bottom: 10px;\" /></div>');
	}
    else
    {
    	alert("Ha ocurrido un error");
//        $.blockUI('<div id=\"alertFormERROR\" style=\"cursor: default\"><h1 class=\"alert\">Se ha producido un error, por favor vuelve a intentarlo</h1><input type=\"button\" id=\"aceptarAlertBtn\" onclick=\"$.unblockUI()\" value=\"Aceptar\" style=\"margin-bottom: 10px;\" /></div>');
	}
}



function alejarMapa()
  {
    if (actualZoom == "zoom2")
    {
      $('#zoom2').fadeOut(1000);
      $('#zoom1').fadeIn(1000);
      actualZoom = "zoom1";
    }
    else if (actualZoom == "zoom3")
    {
      $('#zoom3').fadeOut(1000);
      $('#zoom2').fadeIn(1000);
      actualZoom = "zoom2";
    }
    else if (actualZoom == "zoom4")
    {
      $('#zoom4').fadeOut(1000);
      $('#zoom3').fadeIn(1000);
      actualZoom = "zoom3";
    }
	
	$('#imgZoomIn').fadeIn(1);
	$('#imgZoomOut').fadeIn(1);
  }

  function acercarMapa()
  {
    if (actualZoom == "zoom1")
    {
      $('#zoom1').fadeOut(1000);
      $('#zoom2').fadeIn(1000);
      actualZoom = "zoom2";
    }
    else if (actualZoom == "zoom2")
    {
      $('#zoom2').fadeOut(1000);
      $('#zoom3').fadeIn(1000);
      actualZoom = "zoom3";
    }
    else if (actualZoom == "zoom3")
    {
      $('#zoom3').fadeOut(1000);
      $('#zoom4').fadeIn(1000);
      actualZoom = "zoom4";
    }
	
	$('#imgZoomIn').fadeIn(1);
	$('#imgZoomOut').fadeIn(1);
  }


  function muestra(capa)
  {
  	document.getElementById(capa).style.display = 'inline';
  }

  function oculta(capa)
  {
  	document.getElementById(capa).style.display = 'none';
  }


