function aDosCifras(numero)
{
	return numero <= 9 ? "0" + numero : numero;
}

function verInstrucciones()
{
	with (document.getElementById("instrucciones").style)
	{
		display = (display == "block") ? "none" : "block";
		var fecha = new Date();
		fecha.setDate(fecha.getDate() + 1);
		// Fecha a formato de cookie
		var dias = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
		var meses = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
		var diaSemana = dias[fecha.getDay()];
		var dd = aDosCifras(fecha.getDate());
		var mmm = meses[fecha.getMonth()];
		var aa = aDosCifras(fecha.getFullYear() - 2000);
		var hh = aDosCifras(fecha.getUTCHours());
		var mm = aDosCifras(fecha.getUTCMinutes());
		var ss = aDosCifras(fecha.getUTCSeconds());
		var fechaExpiracion = diaSemana + ", " + dd + "-" + mmm + "-" + aa + " " + hh + ":" + mm + ":" + ss + " GMT";
		// Manda la cookie
		document.cookie = "estiloInstrucciones=" + display + ";expires=" + fechaExpiracion;
	}
}

function Responder()
{
	with (document.getElementById("leer").style)
		display = "none";
	with (document.getElementById("responder").style)
		display = "block";

	var cadena = new String();
	var mensaje = new String();
	mensaje = "\n------------------------------------------\n";
	mensaje += document.getElementById("contenido").value;
	cadena = "RW: ";
	cadena += document.getElementById("titulo").value;
	document.getElementById("titulo").value = cadena;
	document.getElementById("contenido").value = mensaje;
	document.getElementById("contenido").focus();
}

function cogerFechaVis(formatoMySQL)
{
	var fecha = new Date();
	var aaaa = fecha.getFullYear();
	var mm = fecha.getMonth() + 1;
	var dd = fecha.getDate();
	var hh = fecha.getHours();
	var nn = fecha.getMinutes();
	var ss = fecha.getSeconds();
	// La fecha a formato de MySQL
	fecha = "" + dd + "/" + mm + "/" + aaaa;
	return fecha;
}

function cogerHoraVis()
{
	var fecha = new Date();
	var hh = fecha.getHours();
	var nn = fecha.getMinutes();
	var ss = fecha.getSeconds();
	// La fecha a formato de MySQL
	fecha = "" + hh + ":" + nn + ":" + ss;
	return fecha;
}

function cogerInstanteVis()
{
	var fecha = new Date();
	var aaaa = fecha.getFullYear();
	var mm = fecha.getMonth() + 1;
	var dd = fecha.getDate();
	var hh = fecha.getHours();
	var nn = fecha.getMinutes();
	var ss = fecha.getSeconds();
	// La fecha a formato de MySQL
	fecha = "" + aaaa + "-" + mm + "-" + dd + " " + hh + ":" + nn + ":" + ss;
	return fecha;
}

function procesarCompra(form, idFormaPago)
{
	if (idFormaPago == 3)
		form.action = "https://www.2checkout.com/2co/buyer/purchase";
	else
		form.action = "../scripts/procesar_carrito_final.php";
	form.submit();
}

function abrirVentanaConversacion(archivo, accion)
{
	if (accion != "")
		archivo = archivo + "?accion=" + accion;
	window.open(archivo, "ventConversacion", "width=740,height=550,scrollbars=1");
}

function validarExtensionAdjunto(form, arch, extensiones)
{
	if (!arch)
		return null;
	while (arch.indexOf("\\") != -1)
		arch = arch.slice(arch.indexOf("\\") + 1);
	ext = arch.slice(arch.indexOf(".")).toLowerCase();
	for (var i = 0; i < extensiones.length; i++)
		if (extensiones[i] == ext)
			return true;
	return false;
}