/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function include(url) {	document.write("<script src='" + url + "'></script>"); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
include("/site/js/md5.js");
include("/site/js/event.js");
include("/site/js/effect.js");
include("/site/js/lib/boxover.js");
include("/site/js/lib/validation.js");
include("/site/js/editor/editor.js");
//include("/site/js/swfobject_source.js");
include("/site/js/prototype.js");
include("/site/js/scriptaculous.js?load=effects");
include("/site/js/lightbox.js");

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
var IE = document.all ? true : false;
var selected_item = "";
var element_selected = null;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function prepare_menu() { if (selected_item) select_item(obj("menu")); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function open_menu(option) {
	if (option && option.parentNode && option.parentNode.tagName && option != $('menu') ) {
		if (option.parentNode.tagName.toUpperCase() == "DIV") { 
			option.parentNode.style.display = "block";
			if(option.parentNode.previousSibling) option.parentNode.previousSibling.className += " opened ";
		}
		open_menu(option.parentNode);
	}
	if (option.nextSibling && option.nextSibling.tagName && option != $('menu')) {
		if (option.nextSibling.tagName.toUpperCase() == "DIV") { 
			option.nextSibling.style.display = "block";
			if(option.nextSibling) option.nextSibling.className += " opened ";
		}
	}
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function select_filter(obj) {
	var options = $("filter_options");
	options.style.display =  options.style.display  == "none" ? "" : "none";
	$("filter_type").innerHTML = obj.innerHTML;	
	
	$("search_key").value = obj.id;	
	if (($("search_key").value)!= "filter_type") redirect_sell('render',$("search_key").value,'1') ;
	filter_open = true;	
	//reposition(options, 2);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function select_filter_2(obj) {
	var options = $("filter_options_2");
	options.style.display =  options.style.display  == "none" ? "" : "none";
	$("filter_type_2").innerHTML = obj.innerHTML;	
	
	$("search_key_2").value = obj.id;	
	if (($("search_key_2").value)!= "filter_type_2") redirect_public('render',$("search_key_2").value,'1') ;
	filter_open = true;	
	//reposition(options, 2);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function select_item(option) {
    if (option) {
		if (option.id == selected_item) {
			option.className += " current ";
			open_menu(option);
		} else {
			select_item(option.nextSibling);
			select_item(option.firstChild);
		}
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toggle_menu(item) {
    var element = item.nextSibling ? item.nextSibling : null;
    if (element && element.tagName.toUpperCase() == "DIV") {
        element.style.display = (element.style.display!="block") ? "block" : "none";
    }
    if (element_selected) {
        element_selected.className = element_selected.className.substr(0, element_selected.className.lastIndexOf(" "));
    }
    item.className += " selected";
    element_selected = item;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sendform(id) {
    var form = $(id);
    if (form) {
		var onsubmit = form.onsubmit;
		if (onsubmit) {
	    	if (onsubmit(form)) form.submit();
		} else {
		    form.submit();
		}
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function processform() { sendform("data") }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function $(id) { return (typeof id != "string") ? id : document.getElementById(id) }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function $F(id) { return $(id) ? $(id).value : null; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function $V(id, value) { $(id).value = value; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function key_exec(e, key, command) { if (IE ? event.keyCode==key : e.which==key) command(); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function on_key_return(command) { document.onkeypress = function(e) { key_exec(e, Event.KEY_RETURN, command); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function on_key(key, command) { document.onkeypress =  function(e) { key_exec(e, key, command); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function highlight(obj, color) { try { obj.style.content = obj.style.backgroundColor;  obj.style.backgroundColor = color ? color : "#EFFEE7"; } catch(e) {} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function restore(obj, color) { try { obj.style.backgroundColor = color ? color : obj.style.content; } catch(e) {} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function highlight_row(obj, color) { var nodes = obj.childNodes; for(i in nodes) highlight(nodes[i], color);  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function restore_row(obj, color) { var nodes = obj.childNodes; for(i in nodes) restore(nodes[i], color);  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function highlight_text(obj, color) { try { obj.style.content = obj.style.color;  obj.style.color = color ? color : "#9E9872"; } catch(e) {} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function restore_text(obj, color) { try { obj.style.color = color ? color : "7B7B7B"; } catch(e) {} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function trim(str) { return str.replace(/^\s*|\s*$/g,""); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function show(id) {	$(id).style.display = ''; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function hide(id) {	$(id).style.display = 'none'; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function toggle(id) {	$(id).style.display = $(id).style.display != 'none' ? 'none' : ''; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function get_date() {return (new Date()).toLocaleString(); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
function encrypt(field)  { if($(field)&&$F(field)) $(field).value = hex_hmac_md5($F(field), $F(field)) }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function encrypt2(field, key) { encrypt(field); if($(field)&&$F(field)&&$F(key)) $(field).value = hex_hmac_md5($F(key), $F(field)); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function redirect(url) { window.location = "dashboard.php?pid=" + url; }
function redirect_public(url, id) { window.location = "?pid=" + url +"&cid="+id; }
function redirect_template(url) { window.location = "dashboard.php?pid=page&tid=" + url; }
function redirect_language(url,language) { window.location = "?pid=" + url +"&language="+language; }
function redirect_sell(url, id, list) { window.location = "?pid=" + url +"&cid="+id+"&listado="+list; }
function redirect_gallery(url, subsection, id) { window.location = "?pid=" + url +"&subsection="+subsection +"&gid="+id; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function delete_entry(field) {
	var result = confirm("¿Está seguro que desea borrar este registro?");
	if (result) {
		$(field).value=true; 
		processform();
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var first_part = "";
var second_part = "";
var total_name = "";
function zoneName(caller) {
var space = " ";
	if (caller == "zone_first_label_name") first_part = document.getElementById(caller).value;
	if (caller == "zone_second_label_name") second_part = document.getElementById(caller).value;
	total_name = first_part + space + second_part;
	document.getElementById("zone_name").value = total_name;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////