/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var datos = "";
var funcionAceptarGeneral;
var precarga =  '<img src="images/loader.gif" border="0" align="absmiddle" />';
var urlActual = "";
var idActualEdicion = 0;

function setUrlActual(arg){
   urlActual = arg;
}

function mainmenu(){
    $("#nav ul").css({display:"none"});
    $("#nav li").hover(function(){
        $(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
    },function(){
        $(this).find('ul:first').slideUp(400);
    });
}

function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {

		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');

	//if prev is set to 0 (next item)
	} else {

		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');

	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);
	$('#mask-excerpt').scrollTo(next_excerpt, 800);

}

function initAsmSelect(){
    try{
	$("#etiquetas").asmSelect({
	addItemTarget: 'top',
	animate: true,
	highlight: true,
	sortable: true,
	removeLabel:'<img src="images/12-em-cross.png" border="0"/>'

	}).after($("").click(function() {
		$("#cities").children().attr("selected", "selected").end().change();
		return false;
	}));
    }catch(e){}
}

function reloadFrame(url){
    var frame = document.getElementById("framedownload");
    frame.src = url;
}

function initCalendario(){

    $.datepicker.regional['es'] = {
            closeText: 'Cerrar',
            prevText: '&#x3c;Ant',
            nextText: 'Sig&#x3e;',
            currentText: 'Hoy',
            monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
            'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
            monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
            'Jul','Ago','Sep','Oct','Nov','Dic'],
            dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
            dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
            dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
            weekHeader: 'Sm',
            dateFormat: 'yy-mm-dd',
            firstDay: 1,
            isRTL: false,
            showMonthAfterYear: false,
            yearSuffix: ''};
    $.datepicker.setDefaults($.datepicker.regional['es']);

    $(".datepicker").datepicker();

}

function initTinymce(){
    tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        elements : "contenido",
        plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,bullist,numlist,undo,redo,|,link,unlink,code",
        theme_advanced_buttons3 : "tablecontrols",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
        
    });
}

function loadModal(template){
    var mensaje="";
    var campo="";
    if(arguments[1] != undefined){
            mensaje = arguments[1];
    }

    if(arguments[2] != undefined){
            campo = arguments[2];
    }
 
    $.ajax({
            type: "GET",
            url: "includes/getPlantilla.php?html="+template+".html",
            success: function(datos){
                //alert(datos);
                $("#contentmodal").html(datos);
                $("#mensajemodalvalidacion").html(mensaje);
                $.colorbox.objectFocus(campo);
                $.colorbox({html:$("#contentmodal").html()});

            }
    });

}

function cerrarModal(){
    datos = "";
    funcionAceptarGeneral = "";
    try{
    $.colorbox.close();
    }catch(e){}
}


function validarContacto(){
	var mensaje = "";
        var campo = "";
        
	if($("#nombre").val() == "" && mensaje == ""){mensaje = "Por favor digite su nombre";campo = "nombre";}
	if($("#email").val() == "" && mensaje == ""){mensaje = "Por favor digite su email";campo = "email";}
        if($("#mensaje").val() == "" && mensaje == ""){mensaje = "Por favor digite su mensaje";campo = "mensaje";}

	if(mensaje != ""){
            //loadModal("validation", mensaje, campo);
            alert(mensaje);
            var tempField = document.getElementById(campo);
            tempField.focus();
            return false;
	}
        
        $("#linkContacto").css("display","none");
        $("#displayError").html("Enviando información...");

	var datos = $("#formcontacto").serialize();

       // alert(datos);
       

	$.ajax({
            type: "POST",
            url: "includes/contacto.php",
            data: datos,
            success: function(request){               
                if(request == "ok"){
                    //loadModal("validation", "Sus datos fueron enviados correctamente.");
                    alert("Sus datos fueron enviados correctamente.");
                    $("#nombre").val("");
                    $("#email").val("");
                    $("#mensaje").val("");

                }else{
                   //loadModal("validation", "Se produjo un error inesperado, vuelva a intentarlo.");
                   alert("Su mensaje no pudo ser enviado, vuelva a intentarlo...");
                }
                $("#linkContacto").css("display","block");
                $("#displayError").html("");
            }
        });
    return false;
}

function aceptarGeneral(){
   funcionAceptarGeneral();
}
