function load_app(ohaction)
{
	document.location.href = "index.php?ohaction=" + ohaction;
}

// show/hide toggle the "suggestions" div
function toggleSuggestions() {
   var suggestion = dojo.byId("suggestions");
   var hider = dojo.byId("hider");

   var display = suggestion.getAttribute('displayed');

   if (display == 'on') 
   {
     dojo.lfx.toggle.fade.hide(suggestion, 1000);
     // change the button image
     //hider.setAttribute("src","media/images/show-suggestion.gif");
	 
	 hider.innerHTML = "<img src=\"views/images/icons/arrow_down.png\" width=\"16\" height=\"16\" border=\"0\" align=\"absmiddle\"><span class=\"block\">Menu</span>";
     display = 'off';
   } 
   else 
   {
     dojo.lfx.toggle.fade.show(suggestion, 1000);
     // change the button image back
     //hider.setAttribute("src","media/images/hide-suggestion.gif");
	 hider.innerHTML = "<img src=\"views/images/icons/arrow_up.png\" width=\"16\" height=\"16\" border=\"0\" align=\"absmiddle\"><span class=\"block\">Menu</span>";
     display = 'on';
   }
   // remember the toggle state
   suggestion.setAttribute('displayed', display);
}

// dom hook and setup
function serenityInit() 
{
   var hider = dojo.byId('hider');
   // wire the event without using inline javascript, sweet!
   dojo.event.connect(hider,'onclick',toggleSuggestions);
   var suggestion = dojo.byId("suggestions");

   // si esta logueado ocultar;
   suggestion.setAttribute('displayed', 'on');
   
}	

function onLogin()
{
	sendForm('frmLogin');
}

function Eliminar()
{
	document.deleteNewsletter.submit();	
}

function ordenar(pfield_order, pfield_dir)
{
  var rExp = /&field_order=\w+/gi;
  var _url = window.location.href.replace(rExp, "");
  var rExp = /&?field_dir=\w+/gi;
  _url = _url.replace(rExp, "");
  _url += "&field_order="+pfield_order+"&field_dir="+pfield_dir;

  var rExp = /&&/gi;
  _url = _url.replace(rExp, "&");  

  window.location = _url;
}

function Aceptar()
{
	with(document.newsletter)
	{
		if (envia.value == "")
		{
			alert("El campo envia no puede ser VACIO. Ingrese un valor");
			envia.focus();
			return;
		}
		if (subject.value == "")
		{
			alert("El asunto no puede ser VACIO. Ingrese un valor");
			subject.focus();
			return;
		}
				
		/*if (taEncabezado.value == "")
		{
			alert("Ingrese un encabezado para su Boletin");
			taEncabezado.focus();
			return;
		}			
		if (taContent.value == "")
		{
			alert("Ingrese algun contenido para su Boletin");
			taContent.focus();
			return;
		}*/
		
		if (selCategories.value == "0")
		{
			alert("Ingrese una categoría para sus Dise�os");
			taContent.focus();
			return;
		}
		
		if (selTemplates.value == "0")
		{
			alert("Ingrese un diseño para su Boletin");
			taContent.focus();
			return;
		}												
		
		submit();	
	}
}

function AceptarSend()
{
	with(document.sendNews)
	{
		if (selNews.value == "0")
		{
			alert("Ingrese el Boletin que desea Enviar");
			selNews.focus();
			return;
		}
		submit();	
	}
}

function navegar(pnValue){
  var rExp = /&?curr_page=\-?\d+#?/gi;
  var _url = window.location.href.replace(rExp, "");
  _url += "&curr_page="+pnValue;

 
  window.location = _url;
}

function EliminarContacts()
{
	document.deleteCategories.submit();	
}

function nuevoGrupo()
{
	form = document.getElementById('contacts');
	form.action = "index.php?ohaction=showGrupos";
	form.submit();
}

function AceptarContact()
{
	with(document.contacts)
	{
		if (firstName.value == "")
		{
			alert("Ingrese su Nombre");
			firstName.focus();
			return;
		}
		if (lastName.value == "")
		{
			alert("Ingrese su Apellido");
			lastName.focus();
			return;
		}
		if (email.value == "")
		{
			alert("Ingrese su E-mail");
			email.focus();
			return;
		}
// 		if (caractPhone.value == "")
// 		{
// 			alert("Ingrese su caracter�stica Telef�nica");
// 			caractPhone.focus();
// 			return;
// 		}
// 		if (numberPhone.value == "")
// 		{
// 			alert("Ingrese su N�mero Telef�nica");
// 			numberPhone.focus();
// 			return;
// 		}			
		submit();	
	}
}

function EliminarGroups()
{
	document.deleteGroups.submit();	
}

function AceptarGroups()
{
	with(document.updateGroups)
	{
		if (name.value == "")
		{
			alert("Ingrese su Nombre");
			name.focus();
			return;
		}
		if (description.value == "")
		{
			alert("Ingrese una Descripcion");
			description.focus();
			return;
		}
		submit();	
	}
	
}
function Cancelar(flag)
{
	if(flag == 1)
	{
		document.getElementById('updateGroups').action = 'index.php?ohaction=editContact';
		document.getElementById('updateGroups').submit();
	}
	else
	{
		document.location.href = "index.php?ohaction=dspGrupos";
	}
}

function EliminarTemplates()
{
	document.deleteTemplates.submit();	
}

function AceptarTemplates()
{
	with(document.templates)
	{
		if (name.value == "")
		{
			alert("Ingrese su Nombre");
			name.focus();
			return;
		}
		/*if (my_field1.value == "")
		{
			alert("Ingrese su ImagesEncabezado");
			my_field1.focus();
			return;
		}
		
		if (my_field2.value == "")
		{
			alert("Ingrese su ImagesFooter");
			my_field[2].focus();
			return;
		}*/
		submit();	
	}
}

function nuevaCategoria()
{
	form = document.getElementById('templates');
	form.action = "index.php?ohaction=editCategorias";
	form.submit();	
}

function AceptarCategories()
{
	with(document.updateCategories)
	{
		if (name.value == "")
		{
			alert("Ingrese su Nombre");
			name.focus();
			return;
		}
		if (description.value == "")
		{
			alert("Ingrese una Descripción");
			description.focus();
			return;
		}			
		submit();	
	}
}

function CancelarCategories(flag)
{

	if(flag == 1)
	{
		document.getElementById('updateCategories').action = 'index.php?ohaction=addTemplate';
		document.getElementById('updateCategories').submit();
	}
	else
	{
		document.location.href = "index.php?ohaction=dspCategorias";
	}
}

function EliminarTemplates()
{
	document.deleteTemplates.submit();	
}

function EliminarCategories()
{
	document.deleteCategories.submit();	
}


function AceptarSendFriends()
{
	with(document.sendFriends)
	{
		if (name.value == "")
		{
			alert("Ingrese su Nombre");
			name.focus();
			return;
		}
		
		if (name.value == "")
		{
			alert("Ingrese el nombre de su Amigo");
			nameFriend.focus();
			return;
		}
		
		if (email.value == "")
		{
			alert("Ingrese el E-mail de su amigo");
			email.focus();
			return;
		}

		submit();	
	}
	
}

// enviar prueba de boletin a un correo
function promptSendOnePreview(id)
{
	var txt = 'Enviar preview al e-mail:<br /><br /><input id="email" size="30" value="">';
	
	jQuery.prompt(txt, {
	      callback: sendOnePreview,
	      buttons: { Enviar: id, Cancel: null }
	});	
}

function sendOnePreview(v,m) {
	
	// if the response message is not null
    if (v != null) {
    	
		jQuery.ajax({
	  		type: "POST",
	  		url: "index.php?ohaction=sendOnePreview",
	  		data: "id=" + v + "&email=" + m.children('#email').val(),
	  		success: function (msg) {
				jQuery.prompt("Preview enviado");
			} 
		});
	}      
}