/*
 *	Worday CMS JavaScript code
 *		This code is property from Bab Software Applications
 *		
 *	Author: 	Bab Software Applications
 *	Product:	Worday
 *	Version:	1.0
 *	Content:	Generic functions
 */

/*
 * openPopUp
 * @param 	Url		Url a abrir
 * @param	Width	Ancho de la ventana. Si Width y Height son -1, la ventana se maximiza
 * @param	Height	Alto de la ventana. Si Width y Height son -1, la ventana se maximiza
 * @see		Ventana sin menubar, toolbar, statusbar, scrolls y no se puede modificar su tamaño
*/
function openPopUp (Url, Width, Height) {
	win = window.open(Url,'_blank','menubar=no,toolbar=no,width=' + Width + ',height=' + Height + ',resizable=no,scrollbars=no,status=no,dialog');
	win.moveTo(screen.availWidth/2-(Width/2),screen.availHeight/2-(Height/2));
	if ((Width == -1)&&(Height == -1)) {
		maximizeWindow(win);
	}
}
function openPopUp2 (Url, Width, Height) {
	// Lo mismo que openPopUp pero con scrolls
	win = window.open(Url,'_blank','menubar=no,toolbar=no,width=' + Width + ',height=' + Height + ',resizable=no,scrollbars=yes,status=no,dialog');
	win.moveTo(screen.availWidth/2-(Width/2),screen.availHeight/2-(Height/2));
	if ((Width == -1)&&(Height == -1)) {
		maximizeWindow(win);
	}
}
function openPopUp3 (Url, Width, Height) {
	// Lo mismo que openPopUp pero con scrolls y reescalable
	win = window.open(Url,'_blank','menubar=no,toolbar=no,width=' + Width + ',height=' + Height + ',resizable=yes,scrollbars=yes,status=no');
	win.moveTo(screen.availWidth/2-(Width/2),screen.availHeight/2-(Height/2));
	if ((Width == -1)&&(Height == -1)) {
		maximizeWindow(win);
	}
}

function openPhpAdsNew (Url) {
	// Lo mismo que openPopUp pero con scrolls y reescalable
	win = window.open(Url,'_blank','titlebar=no,menubar=no,toolbar=yes,width=10,height=10,resizable=no,scrollbars=yes,status=no');
	win.moveTo(0,0);
	//win.resizeTo(screen.width,screen.height);
	maximizeWindow(win);
}

function popup(nom,url) {
  window.name=nom;
  var win = window.open(url,'_blank','menubar=no,toolbar=no,width=750,height=600,resizable=yes,scrollbars=yes,status=yes');
	win.moveTo(screen.availWidth/2-(750/2),screen.availHeight/2-(600/2));

  opener=self;
}

function popup2(nom,url,Width,Height) {
  window.name=nom;
  win = window.open(url,'_blank','menubar=no,toolbar=no,width=Width,height=Height,resizable=yes,scrollbars=yes,status=yes');
	win.moveTo(screen.availWidth/2-(Width/2),screen.availHeight/2-(Height/2));

  opener=self;
  if ((Width == -1)&&(Height == -1)) {
		win.moveTo(0,0);
		win.resizeTo(screen.width,screen.height);
	}
	return win;
}

function maximizeWindow(MyWindow) {
 var offset = (navigator.userAgent.indexOf("Mac") != -1 || 
                  navigator.userAgent.indexOf("Gecko") != -1 || 
                  navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
    MyWindow.moveTo(-offset, -offset);
    MyWindow.resizeTo(screen.availWidth + (2 * offset), screen.availHeight + (2 * offset));
}

function checkDNI(num) 
{
	let = 'TRWAGMYFPDXBNJZSQVHLCKE';
	if (num.length == 9)
	{	
		numDNI = num.substr(0,8);
		letter = num.substr(8,1);
		let = let.charAt(parseInt(numDNI) % 23);
		var cond = let.toString().toUpperCase().indexOf (letter.toString().toUpperCase(), 0);
		
		if (cond != -1)
			return true;
		else
			return false;
	}
	else 
		return false;
}
function hidediv(myDiv) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(myDiv).style.visibility = 'hidden'; 
	} 
	else { 
		if (document.layers) { // Netscape 4 
			document.hideShow.visibility = 'hidden'; 
		} 
		else { // IE 4 
			document.all.hideShow.style.visibility = 'hidden'; 
		} 
	} 
}

function showdiv(myDiv) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(myDiv).style.visibility = 'visible'; 
	} 
	else { 
		if (document.layers) { // Netscape 4 
			document.hideShow.visibility = 'visible'; 
		} 
		else { // IE 4 
			document.all.hideShow.style.visibility = 'visible'; 
		} 
	} 
}

/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

// Verificamos que el campo de busqueda no este vacio
function search () {
	if (document.getElementById("txtSearch").value == "") {
		alert("El campo de busqueda no puede ser vacio.");
		return false;
	}
	else
		return true;
}

function checkSubscription () {
	var bOk = true;
	var sError = "";
	
	if (document.getElementById("subs_nombre").value == "") {
		bOk = false;
		sError += "El nombre no es válido.\n";
	}
	if (document.getElementById("subs_mail").value == "") {
		bOk = false;
		sError += "La dirección de correo electrónico no es válida.\n";
	}
	else {
		var regExpMail = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/;
		bOk2 = regExpMail.test(document.getElementById("subs_mail").value);
				
		if (bOk2 == false) {
			sError += 'La dirección de correo electrónico no es válida.\n';
			bOk = false;
		}
	}
	if (bOk == false)
		alert(sError);
	
	return bOk;
}

function checkFirma() {
	var bOk = true;
	var sError = "";
	
	if (document.getElementById("nombre2").value == "") {
		bOk = false;
		sError += "El nombre no es válido.\n";
	}
	if (document.getElementById("apellidos").value == "") {
		bOk = false;
		sError += "Los apellidos no son válidos.\n";
	}
	
	if (document.getElementById("dni").value == "") {
		bOk = false;
		sError += "El dni no es válido.\n";
	}
	else {
		bOk2 = checkDNI(document.getElementById("dni").value);
		if (bOk2 == false) {
			bOk = false;
			sError += "El dni no es válido.\n";
		}
	}
		
	if (bOk == false)
		alert(sError);
	else {
		document.getElementById("firma").submit();
		document.getElementById("nombre2").value = "";
		document.getElementById("apellidos").value = "";
		document.getElementById("dni").value = "";
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// Admin seccion /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////







////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// Gestion Noticias //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////



function getCategorias (List) {
	var sWordsKeys = "";
	for (i=0; i < document.getElementById(List).options.length; i++)
		sWordsKeys+= document.getElementById(List).options[i].value + "|";

	sWordsKeys = sWordsKeys.substring(0, sWordsKeys.length - 1);
	return sWordsKeys;
}


function vote (IDE) {
	var ido = document.getElementById("IDO" + IDE).value;
	openPopUp("popup/result_encuesta.php?IDO=" + ido,300,150);
	window.location.reload();
}

///////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// HEMEROTECA ///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

function printNotice () {
	popup("print","../../../../admin/imprimir_noticia.php?IDH=" + document.getElementById("IDH").value);
}

function send () {
	openPopUp("../../../popup/introducir_mail.php?IDH=" + document.getElementById("IDH").value,355,290);
}

