<!--
//////////////////////////////////////////////////////////////////////
//
// 		- Modulo de funciones Script para el navegador
//
// Creado por David González 08/03/2007 | david@dagonsoft.com
//////////////////////////////////////////////////////////////////////
	var browser_name = navigator.appName;
	var browser_version = parseFloat(navigator.appVersion); 
	var tpvWindow;
	var tpvInterval;
	var refreshTime = 500;
	
	if (browser_name == "Netscape" && browser_version >= 3.0){roll = 'true';}
	if (browser_version >= 4.0){roll = 'true';}
	var isNS = (navigator.appName == "Netscape" );
	
	if (!(isNS)) {
	
	}
	else {
	
	}
//////////////////////////////////////////////////////////////////////
//
// 	Init App
//
//////////////////////////////////////////////////////////////////////	
	function init()
	{
		
		
	}
//////////////////////////////////////////////////////////////////////
//
// 	processForm
//
//////////////////////////////////////////////////////////////////////
/*	function processContents(content)
	{
		var id_obj = "div_contenidos_empresa";
		document.getElementById (id_obj).innerHTML = '<br><br><br><div align="center"><img src="images/loading.gif"></div>';
		// mostrar la informacion del contenido en el div.
		var url = "contents.php?section=" + content ;
		getRequest (url, id_obj);
	}*/
//////////////////////////////////////////////////////////////////////
//
// 	getRequest() - imprime el resultado de la consulta en una capa
//
//////////////////////////////////////////////////////////////////////	
	function getRequest (url, id_obj)
	{
		var pageRequest = false;
		if (window.XMLHttpRequest)// Mozilla, Safari etc
		{
			pageRequest = new XMLHttpRequest ();
		} 
		else if (window.ActiveXObject)// IE
		{
			try 
			{
				pageRequest = new ActiveXObject ("Msxml2.XMLHTTP");
			}
			catch (e)// old version
			{
				try
				{
					pageRequest = new ActiveXObject ("Microsoft.XMLHTTP");
				}
				catch (e)
				{
				}
			}
		} 
		else
			return false;
		pageRequest.onreadystatechange = function ()
		{
			pageLoad (pageRequest, id_obj);
		}
		url = url + "&noCache=" + Math.random();
		pageRequest.open ('GET', url, true);
		pageRequest.send (null);
	}
//////////////////////////////////////////////////////////////////////
//
// 	pageLoad() - lee el html de la consulta
//
//////////////////////////////////////////////////////////////////////		
	function pageLoad (pageRequest, id_obj)
	{
		if (pageRequest.readyState == 4 && (pageRequest.status == 200 || window.location.href.indexOf ("http") == - 1))
		{
			document.getElementById (id_obj).innerHTML = pageRequest.responseText;
			////////// esto ejecuta el js del request //////////
			js = pageRequest.responseText.split('<!--JS-->');
			if(js.length>1) eval(js[1]);
		}
	}	
//////////////////////////////////////////////////////////////////////
//
//	sendRequest() - envia una consulta y retorna el resultado
//
//////////////////////////////////////////////////////////////////////
	function sendRequest (url)
	{
		var pageRequest = false;
		if (window.XMLHttpRequest)// Mozilla, Safari etc
		{
			pageRequest = new XMLHttpRequest ();
		} 
		else if (window.ActiveXObject)// IE
		{
			try 
			{
				pageRequest = new ActiveXObject ("Msxml2.XMLHTTP");
			}
			catch (e)// old version
			{
				try
				{
					pageRequest = new ActiveXObject ("Microsoft.XMLHTTP");
				}
				catch (e)
				{
				}
			}
		} 
		else
			return false;
		pageRequest.onreadystatechange = function ()
		{
			if (pageRequest.readyState == 4 && (pageRequest.status == 200 || window.location.href.indexOf ("http") == - 1))
				return pageRequest.responseText;
		}
		url = url + "&noCache=" + Math.random();
		pageRequest.open ('GET', url, true);
		pageRequest.send (null);
	}
//////////////////////////////////////////////////////////////////////
//
// 	processForm() - procesa los datos del formulario de registro
//
//////////////////////////////////////////////////////////////////////		
	function processForm()
	{
		// campos
		var name = document.getElementById('inputName');
		var surname = document.getElementById('inputSurname');
		var mail = document.getElementById('inputMail');
		var password = document.getElementById('inputPassword');
		var sex = document.getElementById('selectSex');
		var day = document.getElementById('selectDay');
		var mouth = document.getElementById('selectMouth');
		var year = document.getElementById('selectYear');		
		// valida datos
		var errorMsg = "";
		p = mail.value.indexOf('@');	
		if(name.value == '' || name.value == 'null')
		{
			errorMsg = "Debes proporcionar tu nombre completo.";
			name.focus();
		}
		else if(surname.value == '' || surname.value == 'null')
		{
			errorMsg = "Debes proporcionar tu nombre completo.";
			surname.focus();
		}
		else if(mail.value == '' || mail.value == 'null' || p<1 || p == (mail.value.length - 1))
		{
			errorMsg = "Por favor introduce un correo electrónico valido.";
			mail.focus();
		}
		else if(password.value == '' || password.value == 'null')
		{
			errorMsg = "Por favor, indica una contraseña.";
			password.focus();
		}
		else if(sex.value == '' || sex.value == 'null')
		{
			errorMsg = "Por favor, selecciona Hombre o Mujer.";
			sex.focus();
		}
		else if(day.value == '' || day.value == 'null')
		{
			errorMsg = "Por favor, introduce tu fecha de nacimiento completa.";
			day.focus();
		}
		else if(mouth.value == '' || mouth.value == 'null')
		{
			errorMsg = "Por favor, introduce tu fecha de nacimiento completa.";
			mouth.focus();
		}
		else if(year.value == '' || year.value == 'null')
		{
			errorMsg = "Por favor, introduce tu fecha de nacimiento completa.";	
			year.focus();
		}		
		if(errorMsg != '')// open error box
		{
			var objDiv = document.getElementById('msgErrorForm');
			objDiv.style.display = "block";
			objDiv.innerHTML = errorMsg;
		}
		else // open registerCOntrol
		{			
			var objDiv = document.getElementById('msgErrorForm');
			objDiv.style.display = "none";			
			var objDiv = document.getElementById('registerForm');
			objDiv.style.display = "none";			
			var objDiv2 = document.getElementById('registerControl');
			objDiv2.style.display = "block";			
			getImgCaptcha();
		}
	}
//////////////////////////////////////////////////////////////////////
//
// 	returnForm() - resetea las capas del formulario de alta
//
//////////////////////////////////////////////////////////////////////		
	function returnForm()
	{
		var objDiv = document.getElementById('registerControl');
		objDiv.style.display = "none";			
		var objDiv2 = document.getElementById('registerForm');
		objDiv2.style.display = "block";
	}
//////////////////////////////////////////////////////////////////////
//
// 	getImgCaptcha() - muestra la imagen de control
//
//////////////////////////////////////////////////////////////////////		
	function getImgCaptcha()
	{
		var objDiv = document.getElementById('imgCaptcha');
		var url = "imgCaptcha.php?action=getImg";
		objDiv.innerHTML = "Espera...";
		getRequest(url,'imgCaptcha');
		objDiv.style.display = "block";
		document.getElementById('msgErrorControl').style.display = "none";
	}
//////////////////////////////////////////////////////////////////////
//
// 	processControl() - control de insercion de frase captcha
//
//////////////////////////////////////////////////////////////////////		
	function processControl()
	{
		var textControl = document.getElementById('captchaPhrase');
		var url = "imgCaptcha.php?action=validate&captchaPhrase="+textControl.value;
		var pageRequest = false;		
		if (window.XMLHttpRequest)// Mozilla, Safari etc
		{
			pageRequest = new XMLHttpRequest ();
		}
		else if (window.ActiveXObject)// IE
		{
			try 
			{
				pageRequest = new ActiveXObject ("Msxml2.XMLHTTP");
			}
			catch (e)// old version
			{
				try
				{
					pageRequest = new ActiveXObject ("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert(e);
				}
			}
		} 
		else
			return false;
		// pedimos la confirmacion del capcha
		pageRequest.onreadystatechange = function ()
		{
			if (pageRequest.readyState == 4 && (pageRequest.status == 200 || window.location.href.indexOf ("http") == - 1))
			{
				if(pageRequest.responseText == 'true_validation')
				{
					setRegisterForm();// salvamos la informacion de registro
					//mostramos la pantalla de validacion por mail
					var url = "contents.php?option=msgRegisterValidate";
					getRequest (url, 'contents');
				}
				else
				{
					getImgCaptcha();// pedimos otra imagen					
					textControl.value= "";// limpiamos el cuado de la frase					
					var objDiv = document.getElementById('msgErrorControl');// mostramos el error
					objDiv.style.display = "block";
					objDiv.innerHTML = "La frase no es correcta, vuelve a intentarlo.";	
				}
			}
		}
		url = url + "&nocache=" + Math.random();
		pageRequest.open ('GET', url, true);
		pageRequest.send (null);
	}
//////////////////////////////////////////////////////////////////////
//
//	setRegisterForm() - envio de datos del registro
//
//////////////////////////////////////////////////////////////////////
	function setRegisterForm()
	{
		var name = document.getElementById('inputName').value;
		var surname = document.getElementById('inputSurname').value;
		var mail = document.getElementById('inputMail').value;
		var password = document.getElementById('inputPassword').value;
		var sex = document.getElementById('selectSex').value;
		var day = document.getElementById('selectDay').value;
		var mouth = document.getElementById('selectMouth').value;
		var year = document.getElementById('selectYear').value;	
		
		var params = "login.php?action=registerUser";		
		params += "&userName=" + name;
		params += "&userSurname=" + surname;
		params += "&userMail=" + mail;
		params += "&userPassword=" + password;
		params += "&userSex=" + sex;
		params += "&userDay=" + day;
		params += "&userMouth=" + mouth;
		params += "&userYear=" + year;
		
		sendRequest(params);
	}
//////////////////////////////////////////////////////////////////////
//
//	sendVideoMail() - envio del videomensaje
//
//////////////////////////////////////////////////////////////////////
	function sendVideoMail()
	{
		// campos
		var to = document.getElementById('to');
		var cc = document.getElementById('cc');
		var subject = document.getElementById('subject');
		var fileName = document.getElementById('fileName');
		var sendErrors = document.getElementById('sendErrors');
		var priority_0 = document.getElementById('priority_0');
		var priority_1 = document.getElementById('priority_1');
		var priority_2 = document.getElementById('priority_2');
		// importancia del mensaje
		var priority = 5;
		if(priority_0.checked) priority = priority_0.value;
		else if (priority_1.checked) priority = priority_1.value;
		else if (priority_2.checked) priority = priority_2.value;
		
		

		
		
		// deteccion de errores
		sendErrors.style.display = "none";
		errorMsg = '';
		p = to.value.indexOf('@');		
		if(to.value == '' || to.value == 'null' || p<1 || p == (to.value.length - 1))
		{
			errorMsg = "Por favor introduce un correo electrónico valido.";
			to.focus();
		}
		p = cc.value.indexOf('@');		
		if(cc.value != '' && (p<1 || p == (cc.value.length - 1)))
		{
			errorMsg = "Por favor introduce un correo electrónico valido.";
			cc.focus();
		}
		else if(subject.value == '' || subject.value == 'null')
		{
			errorMsg = "Por favor indica un asunto.";
			subject.focus();
		}
		
		if(errorMsg != '')// open error box
		{
			sendErrors.style.display = "block";
			sendErrors.innerHTML = errorMsg;
		}
		else
		{
			//datos del videomensaje
			var params = "contents.php?option=sendVideoMail";		
			params += "&to=" + to.value;
			params += "&cc=" + cc.value;
			params += "&subject=" + subject.value;
			params += "&id=" + fileName.value;
			params += "&priority=" + priority;
			// enviamos
			getRequest(params,'videoFlash');
		}
	}
//////////////////////////////////////////////////////////////////////
//
//	processNewMessage() - cargar pantalla nuevo videomensaje
//
//////////////////////////////////////////////////////////////////////
	function processNewMessage()
	{
		var params = "contents.php?option=newVideoMessage";
		getRequest(params,'videoFlash');		
	}
//////////////////////////////////////////////////////////////////////
//
//	processSendMessage() - cargar la pantalla de enviar videomensaje
//
//////////////////////////////////////////////////////////////////////
	function processSendMessage(idvm)
	{
		var params = "contents.php?option=sendVideoMessage&id=" + idvm;
		getRequest(params,'videoFlash');
	}	
//////////////////////////////////////////////////////////////////////
//
//	processSendMessage() - cargar la pantalla de ver videomensaje
//
//////////////////////////////////////////////////////////////////////
	function processViewMessage(idvm)
	{
		var params = "contents.php?option=viewVideoMessage&id=" + idvm;
		getRequest(params,'videoFlash');
	}	
//////////////////////////////////////////////////////////////////////
//
//	processSendMessage() - eliminar el videomensaje
//
//////////////////////////////////////////////////////////////////////
	function processDeleteMessage(idvm,name)
	{
		var msgConfirm = "¿ Estas seguro de eliminar el video mensaje\n";
		    msgConfirm+= " " + name + " ?"; 
		if(confirm(msgConfirm)) 
		{
			var params = "contents.php?option=deleteVideoMessage&id=" + idvm;
			sendRequest(params);
			setTimeout("loadVideoFiles()",refreshTime);
		}	
	}
//////////////////////////////////////////////////////////////////////
//
//	saveVideoMail() - guardar el videomensaje
//
//////////////////////////////////////////////////////////////////////
	function saveVideoMail()
	{
		var fileTitle = document.getElementById('fileTitle');		
		var fileDuration = document.getElementById('fileDuration');		
		var fileName = document.getElementById('fileName');		
		var boxErrors = document.getElementById('boxErrors');
		
		var errorMsg = "";
		boxErrors.style.display = "none";
		
		if(fileTitle.value == '' || fileTitle.value == 'null')
		{
			errorMsg = "Por favor introduce un titulo para este video mensaje.";
			fileTitle.focus();
		}		
		if(errorMsg != '')// open error box
		{
			boxErrors.style.display = "block";
			boxErrors.innerHTML = errorMsg;
		}
		else
		{
			var params = "contents.php?option=saveVideoMessage&fileName=" + fileName.value;
			params = params + "&fileTitle=" + fileTitle.value;
			params = params + "&fileDuration=" + fileDuration.value;
			getRequest(params,'videoFlash');
			setTimeout("loadVideoFiles()",refreshTime);
		}
	}
//////////////////////////////////////////////////////////////////////
//
//	loadVideoFiles() - recarga los videomensajes en el div
//
//////////////////////////////////////////////////////////////////////
	function loadVideoFiles()
	{
		var url = "contents.php?option=getVideoFiles";
		getRequest(url,'videoFiles');
	}	
//////////////////////////////////////////////////////////////////////
//
//	openSaveBox() - abre el div para guardar el videomensaje
//
//////////////////////////////////////////////////////////////////////

	function openSaveBox()
	{
		var obj = document.getElementById('saveBox');
		obj.style.display = "block";
	}
//////////////////////////////////////////////////////////////////////
//
//	closeSaveBox() - cierra el div para guardar el videomensaje
//
//////////////////////////////////////////////////////////////////////	
	function closeSaveBox()
	{
		var obj = document.getElementById('saveBox');
		obj.style.display = "none";
	}
//////////////////////////////////////////////////////////////////////
//
//	setDuration() - establece la duracion del videomensaje
//
//////////////////////////////////////////////////////////////////////		
	function setDuration(seg)
	{
		var obj = document.getElementById('fileDuration');
		obj.value = seg;
	}
//////////////////////////////////////////////////////////////////////
//
//	addCredits() - cargar pantalla de comrpa de creidtos
//
//////////////////////////////////////////////////////////////////////
	function addCredits()
	{
		var url = "contents.php?option=addCredits";
		getRequest(url,'videoFlash');
	}
//////////////////////////////////////////////////////////////////////
//
//	processBuyCredits() - abre la pantalla de compra de creditos
//
//////////////////////////////////////////////////////////////////////
	function buyCredits()
	{
		var amount = 0;
		if(document.getElementById('credits1').checked)
			amount = 300;
		else if(document.getElementById('credits2').checked)	
			amount = 500;
		else if(document.getElementById('credits3').checked)
			amount = 700;
		else if(document.getElementById('credits4').checked)
			amount = 1000;
		else if(document.getElementById('credits5').checked)
			amount = 1500;
		tpvWindow = window.open("","tpv","width=650,height=500,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no");
		var frm = document.getElementById('addCredits');
		frm.amount.value = amount;
		frm.submit();		  
		tpvWindow.focus();		
		tpvInterval = setInterval("reloadCredits()",3000);
	}
//////////////////////////////////////////////////////////////////////
//
//	reloadCredits() - recarga los creditos despuesa de la compra por TPV
//
//////////////////////////////////////////////////////////////////////
	function reloadCredits()
	{
		if( !tpvWindow || tpvWindow.closed )
		{
			clearInterval(tpvInterval);
			getUserCredits();
		}
	}
//////////////////////////////////////////////////////////////////////
//
//	getUserCredits() - carga los creditos del usuario
//
//////////////////////////////////////////////////////////////////////
	function getUserCredits()
	{
		var url = "contents.php?option=getUserCredits";
		getRequest(url,'userCredits');
		getUserMessagesSent();
	}
//////////////////////////////////////////////////////////////////////
//
//	getUserMessagesSent() - carga los mensajes enviados del usuario
//
//////////////////////////////////////////////////////////////////////
	function getUserMessagesSent()
	{
		var url = "contents.php?option=getUserMessagesSent";
		getRequest(url,'messagesSent');
		loadVideoFiles();// actualizamos los archivos
	}
//////////////////////////////////////////////////////////////////////
//
//	setMessageTitle() - carga los mensajes enviados del usuario
//
//////////////////////////////////////////////////////////////////////
	function setMessageTitle()
	{
		var fileTitle = document.getElementById('fileTitle');		
		var fileId = document.getElementById('fileId');	
		//datos del videomensaje
		var params = "contents.php?option=setTitleVideoMail";		
		params += "&title=" + fileTitle.value;
		params += "&id=" + fileId.value;
		// enviamos
		getRequest(params,'videoFlash');
		setTimeout("loadVideoFiles()",refreshTime);// actualizamos los archivos
	}
//////////////////////////////////////////////////////////////////////
//
//	editUserData() - carga la pantalla de edicion de datos de usuario
//
//////////////////////////////////////////////////////////////////////
	function editUserData()
	{
		var url = "contents.php?option=editUserData";
		getRequest(url,'videoFlash');
	}	
//////////////////////////////////////////////////////////////////////
//
//	setUserData() - envia los datos de usuario
//
//////////////////////////////////////////////////////////////////////
	function setUserData()
	{
		// campos requeridos
		var name = document.getElementById('userName');		
		var surname = document.getElementById('userSurname');	
		var password = document.getElementById('userPassword');
		var confirmPassword = document.getElementById('userConfirmPassword');
		
		var boxErrors = document.getElementById('boxErrors');
		
		var errorMsg = "";
		boxErrors.style.display = "none";
		
		if(name.value == '' || name.value == 'null')
		{
			errorMsg = "Por favor introduce nombre.";
			name.focus();
		}		
		else if(surname.value == '' || surname.value == 'null')
		{
			errorMsg = "Por favor introduce tus apellidos.";
			surname.focus();
		}
		else if(password.value != '' || confirmPassword.value != '')
		{
			if(password.value != confirmPassword.value)
			{
				errorMsg = "Por favor las contraseñas deben ser iguales.";
				password.focus();
			}
		}		
		if(errorMsg != '')// open error box
		{
			boxErrors.style.display = "block";
			boxErrors.innerHTML = errorMsg;
		}
		else
		{
			//enviamos datos del usuario
			var params = "contents.php?option=setUserData";		
			params += "&name=" + name.value;
			params += "&surname=" + surname.value;
			params += "&password=" + password.value;
			// enviamos
			getRequest(params,'videoFlash');
		}
	}		
//////////////////////////////////////////////////////////////////////
//
//	getUserData() - carga los datos del usuario
//
//////////////////////////////////////////////////////////////////////
	function getUserData()
	{
		var url = "contents.php?option=getUserName";
		getRequest(url,'userNameBox');
		//var url = "contents.php?option=getUserMail";
		//getRequest(url,'userMailBox');		
	}
//////////////////////////////////////////////////////////////////
//
//	processResetPassword - envia un email con la contraseña al usuario
//
//////////////////////////////////////////////////////////////////	
	function processResetPassword()
	{
		var params = "../contents.php?option=resetPassword";		
			params += "&e-mail=" + document.getElementById('e-mail').value;
		getRequest(params,'msgRegisterValidate');
	}
//////////////////////////////////////////////////////////////////////
//
// 	alertBox()
//
//////////////////////////////////////////////////////////////////////	
	// constants to define the title of the alert and button text.
	var ALERT_TITLE = "Alerta";
	var ALERT_BUTTON_TEXT = "Aceptar";
	
	// over-ride the alert method only if this a newer browser.
	// Older browser will see standard alerts
	if(document.getElementById) {
		window.alert = function(txt) {
			myAlertBox(txt);
		}
	}
	
	function myAlertBox(txt) {
		// shortcut reference to the document object
		d = document;
		
		// if the modalContainer object already exists in the DOM, bail out.
		if(d.getElementById("modalContainer")) return;
	
		// create the modalContainer div as a child of the BODY element
		mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
		mObj.id = "modalContainer";
		 // make sure its as tall as it needs to be to overlay all the content on the page
		mObj.style.height = document.documentElement.scrollHeight + "px";
	
		// create the DIV that will be the alert 
		alertObj = mObj.appendChild(d.createElement("div"));
		alertObj.id = "alertBox";
		// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
		if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
		// center the alert box
		alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	
		// create an H1 element as the title bar
		h1 = alertObj.appendChild(d.createElement("h1"));
		h1.appendChild(d.createTextNode(ALERT_TITLE));
	
		// create a paragraph element to contain the txt argument
		msg = alertObj.appendChild(d.createElement("p"));
		msg.innerHTML = txt;
		
		// create an anchor element to use as the confirmation button.
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "closeBtn";
		btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
		btn.href = "#";
		// set up the onclick event to remove the alert when the anchor is clicked
		btn.onclick = function() { removeCustomAlert();return false; }
	
		alertObj.style.display = "block";
	}
	
	// removes the custom alert from the DOM
	function removeCustomAlert() {
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
	}

	
	
	
