// JavaScript Document
var peticion = false;
try {
	peticion = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		peticion = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (othermicrosoft) {
		try {
			peticion = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (failed) {
			peticion = false;
		}
	}
}
if (!peticion)
	alert('ERROR AL INICIALIZAR!');

function cargaCombo(url,capa){
	var element =  document.getElementById(capa);
	var fragment_url = url;
	element.innerHTML = "Cargando...";
	peticion.open('GET', fragment_url);
	peticion.onreadystatechange = function() {
		if (peticion.readyState == 4) {
			element.innerHTML = peticion.responseText;
		}
	}
	peticion.send(null);
}

function borrardestinatario(comentario, usuario){
	fecha= new Date();
	seg=fecha.getMilliseconds();
	if(confirm("¿Seguro que desea dar de baja en esta conversación al usuario?")){
		url="combodestinos.php?comentario="+comentario+"&usuario="+usuario+"&accion=borrar&seg="+seg;
		capa="destinatarios"+comentario;
		cargaCombo(url,capa);
	}
}
function recordarcontrasena(){
	ema=document.getElementById('email').value.replace(/^\s*|\s*$/g,"");
	if(!ema || !isMail(document.getElementById('email').value)){
		alert("Debe insertar un email valido");
		return false;
	}
	return true;

}
function anadirdestinatario(comentario, usuario){
	fecha= new Date();
	seg=fecha.getMilliseconds();
	if(confirm("¿Seguro que desea dar de alta en esta conversación al usuario?")){
		url="combodestinos.php?comentario="+comentario+"&usuario="+usuario+"&accion=anadir&seg="+seg;
		capa="destinatarios"+comentario;
		cargaCombo(url,capa);
	}
}

function abre(pagina){
window.open(pagina , '' , 'width=550,height=400,scrollbars=NO');
}
function minimiza(){
	top.window.resizeTo(565,550);

}
function minimizanewletter(){
	top.window.resizeTo(700,800);

}

function ver(capa){
	if(document.getElementById(capa).style.display=='none')
		document.getElementById(capa).style.display='block';
	else
		document.getElementById(capa).style.display='none';
}
	
function isMail(_email) {     
	var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/;    
	return emailReg.test(_email);  
}

function validacontacto(){
	nom=document.getElementById('nombre').value.replace(/^\s*|\s*$/g,"");
	ape=document.getElementById('apellidos').value.replace(/^\s*|\s*$/g,"");
	ema=document.getElementById('email').value.replace(/^\s*|\s*$/g,"");
	if(!nom){
		alert("Debe insertar su nombre");
		return false;
	}
	if(!ape ){
		alert("Debe insertar sus apellidos");
		return false;
	}
	if(!ema || !isMail(document.getElementById('email').value)){
		alert("Debe insertar un email valido");
		return false;
	}
}
function validafranquicia(){
	nom=document.getElementById('nombre').value.replace(/^\s*|\s*$/g,"");
	ciu=document.getElementById('ciudad').value.replace(/^\s*|\s*$/g,"");
	ape=document.getElementById('apellidos').value.replace(/^\s*|\s*$/g,"");
	ema=document.getElementById('email').value.replace(/^\s*|\s*$/g,"");
	if(!nom){
		alert("Debe insertar su nombre");
		return false;
	}
	if(!ape ){
		alert("Debe insertar sus apellidos");
		return false;
	}
	if(!ciu){
		alert("Debe insertar su ciudad");
		return false;
	}
	if(!ema || !isMail(document.getElementById('email').value)){
		alert("Debe insertar un email valido");
		return false;
	}
}

function isCurriculum(archivo){
	extension=(archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if(extension==".doc" || extension==".pdf" || extension==".docx")
		return true;
	else
		return false;
	
}
function validacurriculum(){
	nom=document.getElementById('nombre').value.replace(/^\s*|\s*$/g,"");
	ape=document.getElementById('apellidos').value.replace(/^\s*|\s*$/g,"");
	ema=document.getElementById('email').value.replace(/^\s*|\s*$/g,"");
	cur=document.getElementById('curriculum').value.replace(/^\s*|\s*$/g,"");
	if(!nom){
		alert("Debe insertar su nombre");
		return false;
	}
	if(!ape ){
		alert("Debe insertar sus apellidos");
		return false;
	}
	if(!ema || !isMail(document.getElementById('email').value)){
		alert("Debe insertar un email valido");
		return false;
	}
	if(!cur || !isCurriculum(cur)){
		alert("Debe insertar un documento .doc, .docx o .pdf");
		return false;
	}
	
}

function actualizafranquicia(valor){
	document.location.href="/index.php?op=franquicias&franquicia="+valor;
	}
	
function areaprivada(){
	if(document.getElementById("usuario").value==""){
		alert('Debe introducir un usuario');
		return false;
	}
	if(document.getElementById("password").value==""){
		alert('Debe introducir una contraseña');
		return false;
	}
	return true;
}
function datosusuario(){
	if(document.getElementById("usuario").value==""){
		alert('Debe introducir un usuario');
		return false;
	}
	if(document.getElementById("contrasena").value==""){
		alert('Debe introducir una contraseña');
		return false;
	}
	if(document.getElementById("email").value=="" || !isMail(document.getElementById("email").value)){
		alert('Debe introducir un email valido');
		return false;
	}
	return true;
}
function enviararchivo(){
	if(document.getElementById("titulo").value==""){
		alert('Debe introducir el titulo del archivo');
		return false;
	}
	if(document.getElementById("archivo").value==""){
		alert('Debe introducir un archivo para compartir');
		return false;
	}
	for (i=0;ele=document.formulario.elements[i];i++)
	  if (ele.type=='checkbox')
		if (ele.checked)
		  return true;
		  
	alert('Debe marcar el usuario con el que quiere compartir el archivo');
	return false;
}

function borrararchivo(valor){
	if(confirm('¿Seguro que desea borrar el archivo?'))
		document.location.href='index.php?op=areaprivada&opcion=subirarchivos&borrar='+valor;
	
}
function enviarcomentario(){
	if(document.getElementById("asunto").value==""){
		alert('Debe introducir el titulo del comentario');
		return false;
	}
	for (i=0;ele=document.formulario.elements[i];i++)
	  if (ele.type=='checkbox')
		if (ele.checked)
		  return true;
		  
	alert('Debe marcar el usuario al que quiere enviarle el comentario');
	return false;
}

function borrarcomentario(valor){
	if(confirm('¿Seguro que desea borrar el comentario?'))
		document.location.href='index.php?op=areaprivada&opcion=vercomentario&borrar='+valor;
	
}

	