var jscte_MaxFileSize = 1048576;
// Cantidad de 'unidades de latitud/longitud' que se permiten alejadas de las coordenadas del destino para que se considere correcta
var jscte_LatDelta = 1;
var jscte_LongDelta = 1;

//-----------------------------------
// Navegación del Destino (BUSCADOR)
//-----------------------------------

//var hidIdiomaId = $F('hidIdiomaId')
//new Suggest.AutoComplete("txtDestinoNombre", function()
//{
//    return jscteGbl_Path_SiteNET + "AUTOC_Destinos.aspx?IdiomaId="+hidIdiomaId+"&FieldId=hidDestinoNombre&Typing=" + this.text.value  + "&Motivo=AgregarFotosDeGaleria";
//});

//new Suggest.AutoComplete("txtCalifDestinoPorActividad", function()
//{
//    return jscteGbl_Path_SiteNET + "AUTOC_Destinos.aspx?IdiomaId="+hidIdiomaId+"&FieldId=hidDestinoNombre&Typing=" + this.text.value  + "&Motivo=CalifDestinoPorActividad";
//});

//new Suggest.AutoComplete("txtAgregarFotosDeGaleria", function()
//{
//    return jscteGbl_Path_SiteNET + "AUTOC_Destinos.aspx?IdiomaId="+hidIdiomaId+"&FieldId=hidAgregarFotos&Typing=" + this.text.value   + "&Motivo=AgregarFotosDeGaleria";
//});

//new Suggest.AutoComplete("txtAgregarFotos", function()
//{
//    return jscteGbl_Path_SiteNET + "AUTOC_Destinos.aspx?IdiomaId="+hidIdiomaId+"&FieldId=hidAgregarFotos&Typing=" + this.text.value   + "&Motivo=AgregarFotos";
//});

//-------------------------------
// Preview Image
//-------------------------------
function jsPreviewImage()
{
    var varImagen = $('txtImagen')
    var imgImagen = $('previewImagen')
    imgImagen.src = varImagen.value;
    imgImagen.style.display = 'block';
}
//-------------------------------

//-------------------------------
// Insert Form
//-------------------------------
//function jsSubmitInsertForm(pstrType)
function jsSubmitFormNew(idBtn, idForm, pstrType)
{
    oForm = document.forms[idForm];
    oBtn = document.getElementsByName(idBtn);  
    oStrType = pstrType;     
    
    DownForm();

    //tinyMCE.triggerSave();
    //var oForm = document.forms['frmMain'];
    var oElem = Form.findFirstElement(oForm);
    //--- Verifica si está habilitado el formulario
    if (oElem==undefined)
    {
        ClearForm();   
        jsGbl_MsgBox("Ya se ha realizado el alta de la Foto","Mensaje",jscteGbl_Icon_Exclamation);
        return;
    }
    //
    //--- Valida el Formulario
    if (!jsValidateInsertForm(pstrType))
    {
        ClearForm();
        return;
    }
    //
    //--- Setea el tipo de Usuario que ingres
    oForm["hidUserType"].value = pstrType;
    
    //--- Envía el Formulario
    var ifrmResponse = $('ifrmResponse');
    jsGbl_addEvent(ifrmResponse,'load',jsSubmitInsertForm_OnLoadCallback);
    
    //--- Realiza 'encode' del Título por si tiene acentos, etc.
    var varTitulo = $('txtTitulo');
    varTitulo.value = encodeURIComponent(varTitulo.value);
    
    //--- Realiza 'encode' del Título por si tiene acentos, etc.
    var varTexto = $('txtTexto');
    varTexto.value = encodeURIComponent(varTexto.value);
    
        
    oForm.submit();
    if (document.getElementById("processOk"))
    {
        document.getElementById("processOk").value = '1';
    } 
}
function jsSubmitInsertForm_OnLoadCallback()
{
        //--- Realiza 'decode' del Título para dejarlo como lo ingresó
        
    var varTitulo = $('txtTitulo');
    varTitulo.value = decodeURIComponent(varTitulo.value);
    
    var varTexto = $('txtTexto');
    varTexto.value = decodeURIComponent(varTexto.value);
    
    var ifrmResponse = $('ifrmResponse');
    jsGbl_removeEvent(ifrmResponse,'load',jsSubmitInsertForm_OnLoadCallback);
    //
    //MLM(10/12/2007)
    //var wstrContent = ifrmResponse.contentWindow.document.body.innerText;
    var wstrContent;
    if (navigator.appName == "Microsoft Internet Explorer")
	    wstrContent = ifrmResponse.contentWindow.document.body.innerText;
    else
	    wstrContent = ifrmResponse.contentDocument.body.textContent;
	
	 wstrContent = wstrContent.replace(/-/g,"");
    wstrContent = wstrContent.replace(/^ /, "");
    wstrContent = wstrContent.replace(/^ /, "");
 
    var divID = 'iframemodal';
    var thanksID = 'fThanks';
    var responseText = 'hidResponseText';
    document.getElementById(divID).style.top = document.body.scrollTop;
    document.getElementById(responseText).value = jsGetResponseText(jsGbl_Text2XML(wstrContent));
    if (document.getElementById(responseText).value != "")
    {	      
         document.getElementById(divID).style.display = "block";
	      if (document.getElementById(responseText).value != "ANTIFLOOD")
	      {
	         document.getElementById(thanksID).src = "/gracias2.html?fotos";
	      }
	      else
	         document.getElementById(thanksID).src = "/Captcha.html";
    }	
    else
    {
         ClearForm();
         ClosePopUp();
	      jsGbl_Text_HandleResponseForOneSubmit(wstrContent,true,oForm.id)
    }
        scroll(0,0);
    //if (jsGbl_AJAX_ExecuteOK)
    //{
        //--- Deshabilita el Editor
//        tinyMCE.execCommand('mceRemoveControl', true, 'txtTexto');
//        var varTexto = $('txtTexto');
//        var lblTexto = $('lblTexto');
//        
//        if (lblTexto != null)
//        {
//            //--- Muestra el contenido como HTML
//            lblTexto.innerHTML = varTexto.value;
//        }
//        var divImagen = $('divImagen');
//        if (divImagen != null)
//        {
//            divImagen.innerHTML = jsGbl_AJAX_Body_Content();
//        }
    //}
}
function jsValidateInsertForm(pstrType) {

    var oBoton = document.getElementById("divButtonFlash");
    oBoton.style.visibility = "hidden";
    
    var varMsgs = new jsGbl_MsgSummary();
    varMsgs.AddMsgTitle("Por favor, ingrese el/los siguiente/s datos:");

    for (var i = 1; i < cImg + 1; i++) {
        var varTitulo = $('txtTitulo' + i);
        var varImagen = $('txtImage' + i);

        if (jsGbl_IsEmpty(varTitulo.value))
            varMsgs.AddMsg("Título de la Foto.");
        if (jsGbl_IsEmpty(varImagen.value))
            varMsgs.AddMsg("Imagen correspondiente a la Foto.");
    }
    
    jsGbl_ValidateUserInfo(pstrType,varMsgs);
    if (!varMsgs.IsEmpty())
    {
        varMsgs.ShowSummary();
        return false;
    }
        
    return true;
}
//-------------------------------

//-------------------------------
// Ranking Form
//-------------------------------
function jsSubmitRankingForm(pstrType)
{
    var oForm = document.forms['frmMain'];
    var oElem = Form.findFirstElement(oForm);
    //--- Verifica si está habilitado el formulario
    if (oElem==undefined)
    {
        jsGbl_MsgBox("¡Muchas gracias! Ya hemos recibido su calificación sobre la Foto correctamente.","Mensaje",jscteGbl_Icon_Exclamation);
        return;
    }
    //
    //--- Valida el Formulario
    if (!jsValidateRankingForm())
        return;
    //
    //--- Envia a procesar el Ranking
    new Ajax.Request(oForm.action, { onSuccess : jsHandleRankingResponse,
                                     onFailure : jsGbl_AJAX_HandleError,
                                     parameters : Form.serialize(oForm)
                                   });
                                   
    if (document.getElementById("processOk"))
    {
        document.getElementById("processOk").value = '1';
    } 
}
function jsValidateRankingForm(pstrType) {

    var varMsgs = new jsGbl_MsgSummary();

	var wValue = null;
	var oCol = document.getElementsByName("optCalificacion");
	var wCount = oCol.length;
    for (var i = 0; i < wCount; i++)
	{
		if (oCol[i].checked)
			wValue = oCol[i].value;
	}

    if (jsGbl_IsEmpty(wValue))
        varMsgs.AddMsg("Calificación de la Foto.");
        
    if (!varMsgs.IsEmpty())
    {
        varMsgs.ShowSummary();
        return false;
    }
        
    return true;
}
function jsHandleRankingResponse(pobjResponse)
{
    //function ShowModal(divID) {
    var divID = 'iframemodal';
    var thanksID = 'fThanks';
    var responseText = 'hidResponseText';
    document.getElementById(responseText).value = jsGetResponseText(pobjResponse.responseXML);
    if (document.getElementById(responseText).value != "")
    {
	document.getElementById(divID).style.display = "block";
	document.getElementById(divID).style.top = document.body.scrollTop;
	document.getElementById(thanksID).src = "/gracias2.html?foto";
    }	
    else
    {
	jsGbl_AJAX_HandleResponseForOneSubmit(pobjResponse,true,'frmMain')
    }
    //if (jsGbl_AJAX_ExecuteOK)
    //{
        //--- Deshabilita el Editor
        //tinyMCE.execCommand('mceRemoveControl', true, 'txtTexto');
//        var varTexto = $('txtTexto')
//        var lblTexto = $('lblTexto')
//        //--- Muestra el contenido como HTML
//        lblTexto.innerHTML = varTexto.value;

    //}
}
//-------------------------------



function jsGoDestino()
{
    var hidDestinoNombre = $F('hidDestinoNombre')
    if (hidDestinoNombre=='')
        return;
        
//    var sURL = "destinos/home-"+hidDestinoNombre+".html"
    var sURL = "fotos--"+hidDestinoNombre+".html"

    window.location.href = sURL;
}

function jsGoAgregarFotos()
{
    var hidDestinoNombre = $F('hidDestinoNombre')
    if (hidDestinoNombre=='')
        return;
        
//    var sURL = "destinos/home-"+hidDestinoNombre+".html"
    var sURL = "fotos--"+hidDestinoNombre+".html"

    window.location.href = sURL;
}
//-----------------------------------
//-------------------------------
// Funciones de Paneles
//-------------------------------
function jsViewCalifPanel(divName)
{
    var divPanel = $(divName);
    divPanel.style.display = 'block';
}
function jsCloseCalifPanel(divName)
{
    var divPanel = $(divName);
    divPanel.style.display = 'none';
}
//-------------------------------


function jsCheckNewDestino(pDIV,pIFRAME,pDIVParent,pIFRAMEParent,shadowContainer,pOcultarParent)
{
    var iframe = $(pIFRAME);
    var iframeParent = $(pIFRAMEParent);
    var div = $(pDIV);
    var divParent = $(pDIVParent);
    var divShadowContainer = $(shadowContainer);

    div.style.display = "block";
    divParent.style.display = "block";
    
    if (divShadowContainer != null)
        divShadowContainer.style.display = "block";
        
    if (Prototype.Browser.IE)
    {
        iframe.style.top= div.style.top;
        iframe.style.left = div.style.left;
        iframe.style.width = div.offsetWidth;
        iframe.style.height = div.offsetHeight;
        iframe.style.zIndex = div.style.zIndex - 1;
        iframe.style.display = "block";
        
        iframeParent.style.top= divParent.style.top+100;
        iframeParent.style.left = divParent.style.left;
        iframeParent.style.width = divParent.offsetWidth;
        iframeParent.style.height = divParent.offsetHeight;
        iframeParent.style.zIndex = divParent.style.zIndex -1;
        
        if (pOcultarParent != null)
            iframeParent.style.display = "none";
        else
            iframeParent.style.display = "block";
        
    }
}

//-----------------------------------
function jsSubmitProposeDestino(pFormName)
{
    //    jsHome_ProposeForm = pFormName;
    var oForm = document.forms[pFormName];
    //--- Valida el Formulario
    if (!jsValidateProposeDestino(oForm))
        return;
        
    new Ajax.Request(oForm.action, { onSuccess : jsHandleProposeDestino,
                                     onFailure : jsGbl_AJAX_HandleError,
                                     parameters : Form.serialize(oForm)
                                   });
}
function jsHandleProposeDestino(pobjResponse)
{
    jsGbl_AJAX_HandleResponse(pobjResponse,true);
//    jsGbl_AJAX_HandleResponseForOneSubmit(pobjResponse,true,jsHome_ProposeForm);
//    if (jsGbl_AJAX_ExecuteOK)
//    {
//    }
}

function jsValidateProposeDestino(pForm) {
    var varMsgs = new jsGbl_MsgSummary();
    
    var valDestino = pForm['txtProposeDestino'].value;
    var valEMail = pForm['txtProposeEMail'].value;
    
    if (jsGbl_IsEmpty(valDestino))
        varMsgs.AddMsg("Nombre del Destino que no encuentra.");
    if (!jsGbl_IsEmpty(valEMail) && !jsGbl_IsEMail(valEMail))
        varMsgs.AddMsg("El e-mail no es correcto. Por favor, ingrese un e-mail válido. (Ej.: jlopez@email.com)");

    if (!varMsgs.IsEmpty())
    {
        varMsgs.ShowSummary();
        return false;
    }
        
    return true;
}

function jsGoCalifDestinoPorActividad()
{
    var hidDestinoNombre = $F('hidDestinoNombre');
    if (hidDestinoNombre=='')
        return;
        
    var sURL = "/destinos/galeria-fotos/fotos--"+hidDestinoNombre+".html"
    window.location.href = sURL;
}

function jsGoAgregarFotos()
{
    var hidDestinoNombre = $F('hidAgregarFotos');
    if (hidDestinoNombre=='')
        return;
    
    var sURL = "/destinos/galeria-fotos/"+hidDestinoNombre+"-fotos-alta.html";
    window.location.href = sURL;
}
