// JavaScript Document
//-------------------------------------------------------//
//function $(id){ return document.getElementById(id);	}
//-------------------------------------------------------//
// Funciones Admnistativas 
//-------------------------------------------------------//
function process_login() {
	var password = $("password");
	password.value = hex_hmac_md5(password.value, password.value);
}
//-------------------------------------------------------//
function send_encrypt_pass() {
	var user_password = $("user_password");
	var user_password_confirm = $("user_password_confirm");	
	if (user_password.value != null && user_password.value != "") {
		user_password.value = hex_hmac_md5(user_password.value, user_password.value);	
		user_password_confirm.value = hex_hmac_md5(user_password_confirm.value, user_password_confirm.value);
	}
	document.data.submit();
}
//-------------------------------------------------------//
function goto_admin(page, params){
	window.location = "dashboard.php?p="+page+"&"+params;
}
//-------------------------------------------------------//
/* cambia los parametros del formulario para ejecutar una funcion */
function process_form(form, action, validate, fields){
	action = action ? action : "save";
	var validated = !validate ? true : false; 
	if(validate) validated = check_form(fields);
	if(validated){
		$("action").value = action;
		if(action == "delete"){
			if(confirm("¿Desea eliminar el registro(s)?")){
				if($(form)) $(form).submit();										
			}	
		} else {
			if($(form)) $(form).submit();	
		}
	}
}

function check_form(fields) {
	var result = true;
	var msg = "";
	if (fields) {
		for(var i=0; i<fields.length; i++) {
			var id = fields[i].id;
			var name = fields[i].name;
			if ($F(id) == "" || $F(id) == "NULL") {
				msg += "el campo " + name + " es requerido\n";
				result = false;
			}
		}
	}
	if (!result) send_error(msg);
	return result;
}
//-------------------------------------------------------//
function send_error(msg){
	if(msg) alert(msg);
}
//-------------------------------------------------------//
function updateOrder(element){
	var list = element.parentNode;
	var children = "";
	var sep = "";
	for(var i=0; i<list.childNodes.length; i++) {
		var child = list.childNodes[i];
		if (child.tagName.toUpperCase() == "LI") {
			var id = child.id;			
			children += sep + id;
			sep = ",";
		}
	}
	$("orders").value = children;
}
//-------------------------------------------------------//

//-------------------------------------------------------//
// Navegacion
//-------------------------------------------------------//
function load_page(page, params){
	if(page){
		
		//var url = "/pages/"+page+".php?"+params;
		//new Ajax.Updater("content", url);
		//new Ajax.Updater("info", url);
		
		var url = "/?p="+page+"&"+params;
		window.location.href = url;
	}	
}