//pop ups
function PopUpWindow(url, name, height, width, settings)
{
	var previewWidth = width;
	var previewHeight = height;
	var left = ( screen.availWidth / 2 ) - ( previewWidth / 2 );
	var top = ( ( screen.availHeight / 2 ) - ( previewHeight / 2 ) ) - 10;
	var windowObject;

	windowObject = window.open( url, 'popup_' + name, 'width=' + previewWidth + ', height=' + previewHeight + ', left=' + left + ', top=' + top + settings);

	return(windowObject);
}

function EditContent(id)
{
	var url = admin_path  + '/admin_contenido.php?action=info_content&id=' + id;
	var height = 530;
	var width = 713;

	PopUpWindow(url, "contentedit", height, width, "");
}

function DeleteContent(id)
{
	if( confirm('Va a borrar el contenido. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_contenido.php?action=delete_content&id=' + id;

		window.location.href = url;
	}
}

function EditUserAdmin(id)
{
	var url = admin_path  + '/admin_usuario_administracion.php?action=info_user&id=' + id;
	var height = 200;
	var width = 710;

	PopUpWindow(url, "useredit", height, width, "");
}

function DeleteUserAdmin(id)
{
	if( confirm('Va a borrar el usuario. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_usuario_administracion.php?action=delete_user&id=' + id;

		window.location.href = url;
	}
}

function EditEvent(id)
{
	var url = admin_path  + '/admin_evento.php?action=info_event&id=' + id;
	var height = 635;
	var width = 710;

	PopUpWindow(url, "eventedit", height, width, ", scrollbars = 1");
}

function DeleteEvent(id)
{
	if( confirm('Va a borrar el evento. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_evento.php?action=delete_event&id=' + id;

		window.location.href = url;
	}
}

function ListEventImage(id)
{
	var url = admin_path  + '/admin_evento_imagen.php?id_event=' + id;
	var height = 635;
	var width = 710;

	PopUpWindow(url, "eventimagenlist", height, width, ", scrollbars = 1");
}

function EditEventImage(id_event)
{
	var url = admin_path  + '/admin_evento_imagen.php?action=info_event_image&id_event=' + id_event;
	var height = 235;
	var width = 710;

	PopUpWindow(url, "eventimagenedit", height, width, ", scrollbars = 1");
}

function DeleteEventImage(id)
{
	if( confirm('Va a borrar la foto. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_evento_imagen.php?action=delete_event_image&id=' + id;

		window.location.href = url;
	}
}

function EditNew(id)
{
	var url = admin_path  + '/admin_novedad.php?action=info_new&id=' + id;
	var height = 635;
	var width = 710;

	PopUpWindow(url, "newedit", height, width, ", scrollbars = 1");
}

function DeleteNew(id)
{
	if( confirm('Va a borrar la novedad. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_novedad.php?action=delete_new&id=' + id;

		window.location.href = url;
	}
}

function EditBuzon(id)
{
	var url = admin_path  + '/admin_buzon.php?action=info_buzon&id=' + id;
	var height = 635;
	var width = 710;

	PopUpWindow(url, "buzonedit", height, width, ", scrollbars = 1");
}

function DeleteBuzon(id)
{
	if( confirm('Va a borrar el buzón. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_buzon.php?action=delete_buzon&id=' + id;

		window.location.href = url;
	}
}

function EditUser(id)
{
	var url = admin_path  + '/admin_usuario.php?action=info_user&id=' + id;
	var height = 265;
	var width = 710;

	PopUpWindow(url, "useredit", height, width, "");
}

function DeleteUser(id)
{
	if( confirm('Va a borrar el usuario. ¿Está seguro?') ) {
		var url = admin_path  + '/admin_usuario.php?action=delete_user&id=' + id;

		window.location.href = url;
	}
}

function ApproveUser(id, aprobado)
{
	var url = admin_path  + '/admin_usuario.php?action=approve_user&id=' + id;
	url = url + '&aprobado=' + aprobado;

	window.location.href = url;
}

function MakeUpMonth(month)
{
	month++;

	month = TwoDigits(month);
	
	return(month);
}

function TwoDigits(number)
{
	number = number < 10 ? "0" + number : number;

	return(number);
}

function CheckAll()
{
	for( var i = 0 ; i < document.forms[0].elements.length ; i++ ) { 
		document.forms[0].elements[i].checked = true;
	}
}

function UncheckAll()
{
	for( var i = 0 ; i < document.forms[0].elements.length ; i++ ) { 
		document.forms[0].elements[i].checked = false;
	}
}

function GetLocalTime()
{
	var currentTime = new Date();

	var day = currentTime.getDate();
	if( day < 10 )
		day = "0" + day;
	var month = currentTime.getMonth() + 1;
	if( month < 10 )
		month = "0" + month;
	var year = currentTime.getFullYear();
	var hours = currentTime.getHours();
	if( hours < 10 )
		hours = "0" + hours;
	var minutes = currentTime.getMinutes();
	if( minutes < 10 )
		minutes = "0" + minutes;
	var seconds = currentTime.getSeconds();
	if( seconds < 10 )
		seconds = "0" + seconds;

	var local_time = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

	return(local_time);
}

function showHideDiv(divId)  {
	var subd = document.getElementById("sidebar").getElementsByTagName('div');
	if (subd[0].style.display=="block") {
		subd[0].style.display="none";
		document.getElementById("bulletMore").src="../images/bullet-more-off.gif";
	}
	else {
		subd[0].style.display="block";
		document.getElementById("bulletMore").src="../images/bullet-more-on.gif";
	}

}


function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {		
		  if (test.indexOf('inLength') != -1) { p=test.indexOf(':');
          min=test.substring(9,p); max=test.substring(p+1);
          if (val.length<min || max<val.length) errors+='- '+nm+' debe tener una cantidad mínima de '+min+' y máxima '+max+' caracteres.\n';
	}
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una dirección de E-Mail válida.\n';
      } else if (test!='R') { num = parseFloat(val);
        //if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es Obligatorio.\n';}
  }
  if (errors) {
	  	alert('Por favor corrija los siguientes campos:\n'+errors);
  		document.MM_returnValue = (errors == '');
  }
return document.MM_returnValue = (errors == '');
}

function checkPassword(pass1,pass2) { //v1.0
	if ((pass1.value)!=(pass2.value)) {
		errors +="password";
		alert("Los Passwords no coinciden, por favor ingreselos nuevamente.");
		document.MM_returnValue = (errors == '');
	}
return document.MM_returnValue = (errors == '');
}

function deshabilitarBusqueda() { //v1.0
	textfield=MM_findObj("busqueda");
	boton=MM_findObj("Submiter");
	textfield.value="Buscar";
	textfield.readonly=true;
	boton.disabled=true;
}

function habilitarBusqueda() { //v1.0
	textfield=MM_findObj("busqueda");
	boton=MM_findObj("Submiter");
	textfield.value="";
	textfield.readonly=false;
	boton.disabled=false;
}