
/**
 *	Variables que son comunes al proceso de Envío de Postal
 *
**/ 
var ANCHO_FIJO_COLUMNA2 	= 270;
var ANCHO_MARGEN			= 10;
var ALTO_FIJO_FILA_LAST		= 22;
var	ALTO_MARGEN				= 3;
var ANCHO_MARGEN_NS		= 2;
var ALTO_MINIMO_VENTANA	= 220


var ALTO_DESCRIPCION_FOTO	= 20
var ALTO_DATO_AUTOR				= 20

var winAyuda 			= null;


var NAVEGADOR_IE = "IE";
var NAVEGADOR_NS = "NS";

// Leemos el navegador.
var navegador = NAVEGADOR_IE;
if (navigator.appName.indexOf('Netscape') != -1)
        navegador = NAVEGADOR_NS;
    



/**
 *	Abre la ventana de ayuda para el envío de postales
**/ 
function abrirVentanaAyuda( pantalla) {
			
	// Dirección URL 
	var mypage = "../../../ayuda/ayudaPostal.html";
	
	if ( pantalla != "Pantalla1")
		mypage = "../../../ayuda/ayudaPostal.html";
		
	var myname	= 'Ayuda';
	var w			= 750;
	var h			= 400;

	var settings = 'height='+h + ',width='+w+',top=50,left=50,scrollbars=yes, resizable=no';		
	winAyuda = window.open ( mypage, myname, settings);
	openWinAyuda = true;
	
	// Mandamos el foco
	winAyuda.focus();
}



/**
 *	Función que define la etiqueta con la foto a representar.
**/ 
function dibujarFoto ( Formulario) {

     var nombreFoto;        
     var _altFoto;

	if ( Trim( Formulario.nameFoto.value).length != 0)	{
		nombreFoto = "gr/" + Formulario.nameFoto.value;
		_altFoto = Formulario.AltFoto.value;
		
		if ( Trim (_altFoto).length > 0)	
           	document.write ( "<img src='" + nombreFoto + "' width='" + Formulario.sizeWidth.value + "' alt='"+ _altFoto + "'>"); 
           else
           	document.write ( "<img src='" + nombreFoto + "' width='" + Formulario.sizeWidth.value + "'>"); 
           	
           escribirDatosFoto( Formulario);
	}
}


/**
 *	Función que escribe los campos ocultos, tipo HIDDEN.
 *
**/ 
function escribeHiddens ()
{
	document.write ( "<input type='hidden' name='idFoto' value='"+ m_idFoto + "'>");
	document.write ( "<input type='hidden' name='nameFoto' value='"+ m_nameFoto + "'>");
	document.write ( "<input type='hidden' name='sizeWidth' value='"+ m_sizeWidth + "'>");
	document.write ( "<input type='hidden' name='sizeHeight' value='"+ m_sizeHeight + "'>");
	document.write ( "<input type='hidden' name='altoTabla' value='"+ m_altoTabla + "'>");
	document.write ( "<input type='hidden' name='anchoTabla' value='"+ m_anchoTabla + "'>");
	document.write ( "<input type='hidden' name='ocultoemailDestinatario' value='"+ m_ocultoemailDestinatario + "'>");
	document.write ( "<input type='hidden' name='ocultonombreRemitente' value='"+ m_ocultonombreRemitente + "'>");
	document.write ( "<input type='hidden' name='ocultotexto' value='"+ m_ocultotexto + "'>");
	document.write ( "<input type='hidden' name='AltFoto' value='"+ m_AltFoto + "'>");
	document.write ( "<input type='hidden' name='DescripcionFoto' value='"+ m_DescripcionFoto + "'>");
	document.write ( "<input type='hidden' name='NombreAutor' value='"+ m_NombreAutor + "'>");
	document.write ( "<input type='hidden' name='CorreoEAutor' value='"+ m_CorreoEAutor + "'>");	
	document.write ( "<input type='hidden' name='IDTIPO' value='"+ m_IDTIPO + "'>");
	
}


/**
 *	Función que implementa la acción de MODIFICAR los datos de postal.
 *
**/ 
function modificarPostal ( Formulario)	{

	hideObj ('divImagen');

	var altoVentana 		= parseInt (Formulario.altoTabla.value);
	var anchoVentana		= parseInt (Formulario.anchoTabla.value);

	if ( navegador == NAVEGADOR_IE )	{	
			Formulario.action="writepostal.php";
			Formulario.submit();
			window.resizeTo ( parseInt(anchoVentana) + 27, parseInt(altoVentana) + 30 );	
	}
	else	{
		top.window.opener.fAbreModificarPostalNS ( anchoVentana, altoVentana);
	}
}


// esconde un objeto
function hideObj(hideObj) {

	// determino el tipo de navegador
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	if (ns4) eval("document." + hideObj + ".visibility = 'hide'");
	if (ie4) eval(hideObj + ".style.visibility = 'hidden'");
}


function enviarPostal ( Formulario)	{
	var bEsCorrecto = true;
	
	if ( Formulario.name == "Form1")	{
		// Antes de nada, validamos los campos.
		if ( fValidarDatos () )	{
			// Actualizo campos ocultos.
			Formulario.ocultoemailDestinatario.value	= Formulario.emailDestinatario.value;
			Formulario.ocultonombreRemitente.value 	= Formulario.nombreRemitente.value;
			Formulario.ocultotexto.value 					= Formulario.texto.value;			
		}
		else	{
			bEsCorrecto = false;
		}
	}
	
	if ( bEsCorrecto)	{

		hideObj( 'divImagen');
		
		if ( Formulario.name == "Form1") disableAll();
		
		//alert ("Lanzar evento de enviar postal, donde recoges los valores de:\nidFoto - " + Formulario.idFoto.value + "\nnameFoto - " + Formulario.nameFoto.value + "\nocultoemailDestinatario - " + unescape ( Formulario.ocultoemailDestinatario.value) + "\nocultonombreRemitente - " + unescape ( Formulario.ocultonombreRemitente.value) + "\nocultotexto - " + unescape ( Formulario.ocultotexto.value) + "\nAltFoto - " + unescape ( Formulario.AltFoto.value) + "\nDescripcionFoto - " + unescape ( Formulario.DescripcionFoto.value) + "\nNombreAutor - " + unescape ( Formulario.NombreAutor.value) + "\nCorreoEAutor - " + unescape ( Formulario.CorreoEAutor.value) + "\nIDTIPO - " + Formulario.IDTIPO.value);
		
		 Formulario.ocultonombreRemitente.value = unescape ( Formulario.ocultonombreRemitente.value)
		 Formulario.ocultotexto.value = unescape (Formulario.ocultotexto.value);
		 
		Formulario.method="POST";
		Formulario.action="do_postal.php";
		Formulario.submit();
	}
}



/**
 * Función que escribe el texto asociado a la foto
**/ 
function escribirDatosFoto( Formulario)	{

	var _descripcionF = Formulario.DescripcionFoto.value;
	var _nombreAutor = Formulario.NombreAutor.value;
	var _correoAutor   = Formulario.CorreoEAutor.value;

	var _hayDatos = false;

	if ( Trim( _descripcionF).length > 0 || Trim( _nombreAutor).length > 0 || Trim( _correoAutor).length > 0)	{
				
		if ( Trim( _descripcionF).length > 0 )	{
			document.write ( "<br><div align='center'><span align='center' class='datoFotoPostal'>");
			document.write ( _descripcionF);
			_hayDatos = true;
		}
		
		if ( Trim( _nombreAutor).length > 0 )	{
			if ( !_hayDatos)
				document.write ( "<br><div align='center'><span class='datoFotoPostal'>");
			else
				document.write (  "<br>");
				
			_hayDatos = true
			document.write ( "Autor:&nbsp;&nbsp;");
			
			if (  Trim( _correoAutor).length > 0 )	{
				document.write ("<A href='mailto:" + _correoAutor + "' class='correoAutorPostal'>" + _nombreAutor + "</a>");
			}
			else	{
				document.write ( _nombreAutor);	
			}
		}
		
		if ( _hayDatos)	document.write ( "</span></div>");
		
	} // Fin del if principal
}


function dibujarContenidoTablaPre( Formulario)	{
	
	var ancho_tabla 	= Formulario.anchoTabla.value;		// ancho
	var alto_tabla 		= Formulario.altoTabla.value;			// alto
	var ancho_columna;
	var valor	= unescape(Formulario.ocultotexto.value);

	if ( navegador == NAVEGADOR_IE )	{
		ancho_columna = parseInt ( Formulario.anchoTabla.value ) - ANCHO_FIJO_COLUMNA2;

		document.write ( "<table cellspacing='0' cellpadding='0' class='TablaWPostal' width='" + ancho_tabla + "' height='" + alto_tabla + "'>");
		document.write ( "<tr>");		
		document.write ("<td width='" + ancho_columna + "' height='1'></td>");
		document.write ("<td width='" + ANCHO_FIJO_COLUMNA2 + "' height='1'></td>");
		document.write ( "</tr>");		
		document.write ( "<tr>");		
		document.write ( "<td valign='middle' width='" + ancho_columna + "'>");
		dibujarFoto ( Formulario);
		document.write ( "</td>");
	 	document.write ( "<td width='" + ANCHO_FIJO_COLUMNA2 + "'><span class='textoMensaje'>" + valor + "</span></td>");
    		document.write ( "</tr>");
		document.write ( "<tr>");
      	document.write ( "<td colspan='2' align='right' class='CeldaWPostal' height='22'></td>");
    		document.write ( "</tr>");
    		document.write ( "</table>");
  		document.write ( "<br>");
	}
	else	{		
		// Netscape
		ancho_columna = parseInt ( Formulario.anchoTabla.value ) - ANCHO_FIJO_COLUMNA2 - (2 * ANCHO_MARGEN_NS);
		
		document.write ( "<table cellspacing='0' cellpadding='0' width='" + ancho_tabla + "' height='" + alto_tabla + "' border=0>");
		document.write ( "<tr>");		
		document.write ("<td width='" + ANCHO_MARGEN_NS + "' height='1'></td>");		
		document.write ("<td width='" + ancho_columna + "' height='1'></td>");
		document.write ("<td width='" + ANCHO_FIJO_COLUMNA2 + "' height='1'></td>");
		document.write ("<td width='" + ANCHO_MARGEN_NS + "' height='1'></td>");				
		document.write ( "</tr>");		
		document.write ( "<tr>");		
  		document.write ( "<td colspan='4' bgcolor='#FFF7C7' valign='bottom'><img src='../imagen/transparent' width='1' height='3'></td>");
  		document.write ( "</tr>");
  		document.write ( "<tr>");
		document.write ( "<td width='" + ANCHO_MARGEN_NS + "' bgcolor='#FFF7C7' align='left'><img src='../imagen/transparent' width='2' height='1'></td>");
		document.write ("<td valign='bottom' width='" + ancho_columna + "'>");
		dibujarFoto ( Formulario);
		document.write ("</td>"); 
		document.write ( "<td align='right' width='" + ANCHO_FIJO_COLUMNA2 + "'><span class='textoMensaje'>" + valor + "</span></td>");
		document.write ( "<td width='" + ANCHO_MARGEN_NS + "' bgcolor='#FFF7C7' align='rigth'><img src='../imagen/transparent' width='2' height='1'></td>");
  		document.write ( "</tr>");
  		document.write ( "<tr>");
		document.write ( "<td colspan='4' align='right' class='CeldaWPostal' height='22'>&nbsp;</td>");  		
  		document.write ( "</tr>");  		  		
  		document.write ( "</table>");
	}
}


function cerrarWindow()	{
	window.close();	
}

