//-----------> Mensajes generales para eliminar registros
function confirmar(url){
	var x=window.confirm("Are you sure you want to delete this registry?");
	if (x){
		//window.location = "index.php?page="+page+"&action=Delete&id="+id+"&token="+token;
		window.location = "index.php?"+url;		
	}
}//fin confirm

//-----------> Mensaje para cambiar nivel al usuario (users.php)
function level(siteid, cont, userid){
	var nivel = document.getElementById('level'+cont).value;
	var x=window.confirm("Are you sure that you want to assign this level to this site?");
	if (x){
		window.location = "index.php?page=users&action=apply&mode=assignlevels&sitio="+siteid+"&level="+nivel+"&id="+userid+"";
	}else{
		return(false);
	}
}
//-----------> Mensaje para aplicar todos los esquemas de seguridad de sitios a un usuario (users.php)
function applyall(userid){
	var x=window.confirm("This action save all security changes. Are you sure that you want to do this?");
	if (x){
		/*window.location = "index.php?page=users&action=assignlevels&mode=applyall&id="+userid+"";*/
		document.fr_security.submit();
	}else{
		return(false);
	}
}

//-----------> ESTE BLOQUE ES PARA MULTITEMPLATES.PHP
var win = null;
MM_reloadPage(true);

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}


function apply(id){
	var x=window.confirm("Are you sure you want to apply this template?\n\nAll contents, blocks and areas having this templateid will be evaluated again");
	if (x){
		window.location = "index.php?page=multitemplates&token=<?=$token?>&action=apply&id="+id;
	}
}

function bulk(){
	var x=window.confirm("Are you sure that you want continue? - This action will begin a bulk process [some menu options will be locked]");
	if (x){
		document.edit.submit();
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//-----------> FIN BLOQUE ES PARA MULTITEMPLATES.PHP

//-----------> ESTE BLOQUE ES PARA FTP.PHP

function bulk(){
	var x=window.confirm("Are you sure that you want continue? - This action will begin a bulk process [some menu options will be locked]");
	if (x){
		document.edit.submit();
	}
}//fin bulk

function doTestConnection(){
	var host	=document.edit.hostftp.value;
	var user	=document.edit.userftp.value;
	var encoded	=document.edit.encodedpass.value;
	var pass	=document.edit.passftpone.value;
	var passver	=document.edit.passftp.value;
   //For each radio button if it is checked get the value and break.
   for (var i = 0; i < document.edit.type.length; i++){
	  if (document.edit.type[i].checked){
		 var datype = document.edit.type[i].value;
		 break;
	  }
   }

	var remote	=document.edit.remote.value;
	
	if(pass!=passver){
		alert('Typed passwords do not match');
		return(false);
	}else{
		if(pass.length==0){
			if(encoded.length==0){
				alert('Password is empty');
				return(false);
			//}else{
				//pass=encoded;
			}
		}
	}
	
	/*
	alert('Host: '+host+', \n'+
	'User: '+user+', \n'+
	'Pass: '+pass+', \n'+
	'Encoded: '+encoded+', \n'+
	'Type: '+datype+', \n'+
	'Remote: '+remote+'. \n'
	);
	*/
	var url='includes/popups/connection_test.php?host='+host+'&user='+user+'&pass='+pass+'&type='+datype+'&remote='+remote+'&encoded='+encoded+'';
	alert('URL > '+url);
	var popup = window.open(url,'','scrollbars=no,menubar=no,height=200,width=400,resizable=no,toolbar=no,location=no,status=yes');
	
	return(true);
}

//-----------> FIN BLOQUE FTP.PHP

//-----------> onresize for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css){
	  lyr.css.visibility = "visible";
	  lyr.css.display = "block";
  }
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css){
	  lyr.css.visibility = "hidden";	  
	  lyr.css.display = "none";
	  
  }
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function show_component(theURL,winName,features) { //v2.0
	window.open(theURL, winName, features + "toolbar=no,location=no,directories=no,status=no,menubar=no,personalbar=no");
}
/*
function mueveReloj(){
	momentoActual = new Date();
	hora = momentoActual.getHours();
	minuto = momentoActual.getMinutes();
	segundo = momentoActual.getSeconds();
	
	dia =  momentoActual.getDay();
	mes =  momentoActual.getMonth();
	anno = momentoActual.getYear();
	
	str_segundo = new String (segundo);
	if (str_segundo.length == 1){segundo = "0" + segundo;}
	
	str_minuto = new String (minuto);
	if (str_minuto.length == 1){minuto = "0" + minuto;}
	
	str_hora = new String (hora);
	if (str_hora.length == 1){hora = "0" + hora;}
	
	horaImprimible = dia + "/" + mes + "/" + anno + " " + hora + " : " + minuto + " : " + segundo;
		

	objeto=document.getElementById('reloj');
	objeto.value = horaImprimible;
	//window.document.forms[0].elements[0].value = horaImprimible;
	setTimeout("mueveReloj()",1000);
}
*/
function mueveReloj(){
	momentoActual = new Date();
	hora = momentoActual.getHours();
	minuto = momentoActual.getMinutes();
	segundo = momentoActual.getSeconds();
	
	str_segundo = new String (segundo);
	if (str_segundo.length == 1){segundo = "0" + segundo;}
	
	str_minuto = new String (minuto);
	if (str_minuto.length == 1){minuto = "0" + minuto;}
	
	str_hora = new String (hora);
	if (str_hora.length == 1){hora = "0" + hora;}
	
	horaImprimible = hora + " : " + minuto + " : " + segundo;

	objeto=document.getElementById('reloj');
	objeto.value = horaImprimible;
	//window.document.forms[0].elements[0].value = horaImprimible;
	setTimeout("mueveReloj()",1000);
}


//-----------> Toggle
function toggleT(_w,_h) {
	if (document.all) { // is IE
	if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
	if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
	} else { // is NS? 
	if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
	if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
	}
}
function toggleLayer(id) { 
	var el = document.getElementById(id).style; 
	if(el.display == "none") { 
		el.display = "block";
	} 
	else if(el.display == "block") { 
		el.display = "none"; 
	} 
}
function toggleLayer2(id) { 
	var el = document.getElementById(id).style; 
	if(el.display == "none") { 
		el.display = "table-row";
	} 
	else if(el.display == "table-row") { 
		el.display = "none"; 
	} 
}
function showDisplay(id,display) { 
	document.getElementById(id).style.display=display; 
}
function newtoggleLayer(id,img,num) { 
	var el = document.getElementById(id).style; 
	if(el.display == "none") { 
		el.display = "block";
		filter((img),'imgin'+num);
	} 
	else if(el.display == "block") { 
		el.display = "none"; 
		filter((img),'imgout'+num);	
	} 
} 
function checkDisplay(id,img,num){
	var obj = document.getElementById(id).style; 
	if(obj.display == "none") { 
		newtoggleLayer(id,img,num);
	}
}
function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=eval(objectsrc+".src");
	}
}
//-----------> END TOGGLE

//-----------> Tabdata
function tabdataInit() {
	var tables = document.getElementsByTagName('table');
	for (var t=0; t<tables.length; t++) {
		if ('alternate'==tables[t].className) {
		var rows = document.getElementsByTagName('tr');
			for (var i = 0; i < rows.length; i++) {
				rows[i].onmouseover = function() {
					this.className += ' hilite';
				}
				rows[i].onmouseout = function() {
					this.className = this.className.replace('hilite', '');
				}
			}
		}
	}
}
window.onload=tabdataInit;
//-----------> END TABDATA

//-----------> AJAX CHECKING PASSWORD
function checkoldpass(){	
	var oldPass = document.getElementById('oldPass').value  ;
	if(oldPass !== "") {       
		var url = '../includes/changepass.php?oldPass=' + oldPass;
		runXMLHttpRequest(url,'error');	
	}
}

function checknewpass(){	
    //Put the form data into a variable
	var newPass = document.getElementById('newPass').value  ;
	var cnewPass = document.getElementById('cnewPass').value  ;
	
    //If the form data is *not* blank, query the DB and return the results
	if(newPass !== "") {
		var url = '../includes/changepass.php?newPass=' + newPass + '&cnewPass=' + cnewPass;
		xmlhttp.send(null);  
		runXMLHttpRequest(url,'error');	
	}
}
//-----------> END AJAX CHECKING PASSWORD
