
// --------------------------------
// FUNCIÓN para escribir una Cookie
// --------------------------------
function writeCookie (name, value, hours) {
  var expire = "";
  if(hours != null) {
    expire = new Date((new Date()).getTime() + hours * 3600000);
	expire =  "01/01/2070" // NASA Para que caduque en 2070
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
// --------------------------------

// ----------------------------------------------
// FUNCIÓN para recuperar los datos de una Cookie
// ----------------------------------------------
function readCookie(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  var DatosCK_array = cookieValue.split (',');
  if (name == 'AudUsuario') {
	  if (cookieValue != "") {
		document.form1.nombre.value = DatosCK_array [0];
	  	document.form1.email.value = DatosCK_array [1];
	  	document.form1.telefono.value = DatosCK_array [2];
	  	document.form1.tipoprofesional.value = DatosCK_array [3];
	  	document.form1.lugarresidencia.value = DatosCK_array [4];
	  	if (DatosCK_array [5]==1) document.form1.minorista.checked = true;
	  	if (DatosCK_array [6]==1) document.form1.ventadistancia.checked = true;
	 }
  }
  return cookieValue;
}
// ----------------------------------------------


function muestraPopUp () {
    var muestraVentana = "";
	muestraVentana = readCookie ('AUDALIAeBayPopUp');
	if (muestraVentana == "si") {
		alert ('Los datos personales del formulario se completan con\nla información que facilitó la última vez.\nPor favor, compruebe cada vez que son los correctos.\n\nLa información relativa a la nueva consulta deberá\nintroducirse en cada ocasión.\n\nGracias.\n\n\nNota: Esta ventana no volverá a apracer si no elimina las cookies');
		writeCookie ('AUDALIAeBayPopUp', 'no')
	}
}


// ------------------------------------------------------------
// FUNCION para abrir una ventana popUp
// Las características son configurables a través de parámetros
// ------------------------------------------------------------
var popUpWin=0;
//function popUpWindow (URLStr, left, top, width, height)
function popUpWindow (URLStr, toolbar, location, directories, status, menubar, scrollbar, resizable, copyhistory, width, height, left, top)
{
  if(popUpWin) {
    if(!popUpWin.closed) popUpWin.close();
  }

  popUpWin = open(URLStr, 'popUpAudaliaebay', 'toolbar='+toolbar+',location='+location+',directories='+directories+',status='+status+',menubar='+menubar+',scrollbars='+scrollbar+',resizable='+resizable+',copyhistory='+copyhistory+',width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');;
}

function CambiaOrigenDestino (tipooperacion) {
	if (tipooperacion == '{333EA4F7-4B81-4518-81BA-587848F23FDC}'){ // Compra de bienes
		varTipoOperacion = 'Origen de la mercancía';
	} else if (tipooperacion == '{1E9DE015-C877-49C5-8EF7-C94DF3FD9A68}') { // Venta de bienes
		varTipoOperacion = 'Destino de la mercancía';
	} else if (tipooperacion == '--') { // Reset a Seleccione una opción
		varTipoOperacion = 'Origen / Destino de la mercancía';
		ResetOrigenDestino ();
	} else {
		alert ('Este tipo de operación no está prevista.\nPóngase en contacto con el administrador de la página para solucionar la incidencia');
		varTipoOperacion = 'Tipo de opración no previsto [Origen/Destino]';
	}
	return document.form1.TextoOrigenDestino.value= varTipoOperacion;
}
// ------------------------------------------------------------

function ResetOrigenDestino () {
	document.form1.origendestino.value = '--';
}


// --------------------------------
// Evitar el reenvío de formularios
var cuenta=0;
function enviado() { 
	if (cuenta == 0) {
		cuenta++;
		return true;
	} else {
		//alert("El formulario se está enviando.");
		return false;
	}
}
// --------------------------------

// -----------------------------------------------------------------
// Cambiar la propiedad "visibility" de objetos -mantiene el hueco en pantalla-
function visi(nr) {
	if (document.layers) 	{
		vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
		document.layers[nr].visibility = vista;
	} 	else if (document.all) 	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all[nr].style.visibility = vista;
	} 	else if (document.getElementById) 	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(nr).style.visibility = vista;
	}
}
// -----------------------------------------------------------------

// ----------------------------------------------------------------------------
// Cambiar la propiedad "display" de objetos -NO mantiene el hueco en pantalla-
function blocking(nr) {
	if (document.layers) 	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	} 	else if (document.all) 	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	} 	else if (document.getElementById) 	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}
// ----------------------------------------------------------------------------


// ------------------------------------------------------------
// Cambiar la propiedad "disabled" de objetos -los deshabilita-
function deshabilitaInputs (formulario, campo) {
	eval('document.' + formulario + '.' + campo + '.value=""');
	eval('document.' + formulario + '.' + campo + '.disabled=true');
	//alert ('Deshabilitado'); // DEPURANDO
}
// ------------------------------------------------------------

// ---------------------------------------------------------
// Cambiar la propiedad "disabled" de objetos -los habilita-
function habilitaInputs (formulario, campo) {
	eval('document.' + formulario + '.' + campo + '.disabled=false');
	//alert ('Habilitado'); // DEPURANDO

}
// ---------------------------------------------------------
