﻿var telTimer = null;
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

/**
The JavaScript functions below will gradually enlarge or shrink an image
on the current page. I use this for mouseover effects, but there might be
some other interesting applications of it as well.

You can use these scripts in any way you'd like, just don't pretend like
you wrote them yourself.

version 1.0
March 17, 2005
Julian Robichaux, http://www.nsftools.com
*/

/**** adjust these two parameters to control how fast or slow
**** the images grow/shrink ****/
// how many milliseconds we should wait between resizing events
var resizeDelay = 10;
// how many pixels we should grow or shrink by each time we resize
var resizeIncrement = 20;

// this will hold information about the images we're dealing with
var imgCache = new Object();


/**
The getCacheTag function just creates a (hopefully) unique identifier for
each <img> that we resize.
*/
function getCacheTag(imgElement) {
    return imgElement.src + "~" + imgElement.offsetLeft + "~" + imgElement.offsetTop;
}


/**
We're using this as a class to hold information about the <img> elements
that we're manipulating.
*/
function cachedImg(imgElement, increment) {
    this.img = imgElement;
    this.cacheTag = getCacheTag(imgElement);
    this.originalSrc = imgElement.src;

    var h = imgElement.height;
    var w = imgElement.width;
    this.originalHeight = h;
    this.originalWidth = w;

    increment = (!increment) ? resizeIncrement : increment;
    this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
    this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}


/**
This is the function that should be called in the onMouseOver and onMouseOut
events of an <img> element. For example:

<img src='onesmaller.gif' onMouseOver='resizeImg(this, 150, "onebigger.gif")' onMouseOut='resizeImg(this)'>

The only required parameter is the first one (imgElement), which is a
reference to the <img> element itself. If you're calling from onMousexxx, 
you can just use "this" as the value.

The second parameter specifies how much larger or smaller we should resize
the image to, as a percentage of the original size. In the example above,
we want to resize it to be 150% larger. If this parameter is omitted, we'll
assume you want to resize the image to its original size (100%).

The third parameter can specify another image that should be used as the
image is being resized (it's common for "rollover images" to be similar but
slightly different or more colorful than the base images). If this parameter
is omitted, we'll just resize the existing image.
*/
function resizeImg(imgElement, percentChange, newImageURL) {
    // convert the percentage (like 150) to an percentage value we can use
    // for calculations (like 1.5)
    var pct = (percentChange) ? percentChange / 100 : 1;

    // if we've already resized this image, it will have a "cacheTag" attribute
    // that should uniquely identify it. If the attribute is missing, create a
    // cacheTag and add the attribute
    var cacheTag = imgElement.getAttribute("cacheTag");
    if (!cacheTag) {
        cacheTag = getCacheTag(imgElement);
        imgElement.setAttribute("cacheTag", cacheTag);
    }

    // look for this image in our image cache. If it's not there, create it.
    // If it is there, update the percentage value.
    var cacheVal = imgCache[cacheTag];
    if (!cacheVal) {
        imgCache[cacheTag] = new Array(new cachedImg(imgElement), pct);
    } else {
        cacheVal[1] = pct;
    }

    // if we're supposed to be using a rollover image, use it
    if (newImageURL)
        imgElement.src = newImageURL;

    // start the resizing loop. It will continue to call itself over and over
    // until the image has been resized to the proper value.
    resizeImgLoop(cacheTag);
    return true;
}


/**
This is the function that actually does all the resizing. It calls itself
repeatedly with setTimeout until the image is the right size.
*/
function resizeImgLoop(cacheTag) {
    // get information about the image element from the image cache
    var cacheVal = imgCache[cacheTag];
    if (!cacheVal)
        return false;

    var cachedImageObj = cacheVal[0];
    var imgElement = cachedImageObj.img;
    var pct = cacheVal[1];
    var plusMinus = (pct > 1) ? 1 : -1;
    var hinc = plusMinus * cachedImageObj.heightIncrement;
    var vinc = plusMinus * cachedImageObj.widthIncrement;
    var startHeight = cachedImageObj.originalHeight;
    var startWidth = cachedImageObj.originalWidth;

    var currentHeight = imgElement.height;
    var currentWidth = imgElement.width;
    var endHeight = Math.round(startHeight * pct);
    var endWidth = Math.round(startWidth * pct);

    // if the image is already the right size, we can exit
    if ((currentHeight == endHeight) || (currentWidth == endWidth))
        return true;

    // increase or decrease the height and width, making sure we don't get
    // larger or smaller than the final size we're supposed to be
    var newHeight = currentHeight + hinc;
    var newWidth = currentWidth + vinc;
    if (pct > 1) {
        if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
            newHeight = endHeight;
            newWidth = endWidth;
        }
    } else {
        if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
            newHeight = endHeight;
            newWidth = endWidth;
        }
    }

    // set the image element to the new height and width
    imgElement.height = newHeight;
    imgElement.width = newWidth;

    // if we've returned to the original image size, we can restore the
    // original image as well (because we may have been using a rollover
    // image in the original call to resizeImg)
    if ((newHeight == cachedImageObj.originalHeight) || (newWidth == cachedImageObj.originalwidth)) {
        imgElement.src = cachedImageObj.originalSrc;
    }

    // shrink or grow again in a few milliseconds
    setTimeout("resizeImgLoop('" + cacheTag + "')", resizeDelay);
}

function setTelefonoTitle() {

    var lvTelefono = document.getElementById('ctl00_MainContent_SearchBoxId_Telefono');
    if (lvTelefono != null){
        lvTelefono.title = 'Digita el Teléfono';
    }
    
    
}
function setCiudadTitle() {
    var lvCity = document.getElementById('ctl00_MainContent_SearchBoxId_ciudadTxt');
    if (lvCity != null) {
        lvCity.title = 'Digita el nombre de la ciudad que deseas buscar';
    }
}
function displayPhone(secuencia, nombreTabla, cust_id, telefono, direccion, class_code, ciudad, name_id, anuncio,saveClick) {
    document.getElementById("div_" + secuencia).style.display = 'block';
    document.getElementById("hdSecuencia").value = secuencia;
    document.getElementById("hdTabla").value = nombreTabla;

    //Si se va a guardar el click inmediatamente
    if (saveClick == true) {
        saveTelClick(secuencia, nombreTabla, cust_id, telefono, direccion, class_code, ciudad, name_id, anuncio, saveClick);
    } else {
        //El click se va a guardar en 3 segundos
        telTimer = setTimeout(
            function() {
                saveTelClick(secuencia, nombreTabla, cust_id, telefono, direccion, class_code, ciudad, name_id, anuncio, saveClick);
            }, 4000);
    }
    
   // document.getElementById("hdSecuencia").value = "";
  //  document.getElementById("hdTabla").value = "";
    document.getElementById("anchor" + secuencia).style.visibility = "hidden";
    document.getElementById("anchor" + secuencia).style.display = "none";

}

function saveTelClick(secuencia, nombreTabla, cust_id, telefono, direccion, class_code, ciudad, name_id, anuncio, saveClick) {

 //   alert(document.getElementById("div_" + secuencia).style.display);
    //Solo guardar si es un click directo o si todavía está encima
    var hdTelefono = document.getElementById('hdIsTelSave_' + secuencia);
    
    
    if ((saveClick == true || document.getElementById("div_" + secuencia).style.display == 'block') && !(hdTelefono != null && hdTelefono.value != '0')) {
       // alert(hdTelefono.value);
        var f = document.getElementById('FrameSetPhone');
        f.src = "http://www.paginasamarillas.com.do/CodeBehind.aspx?metodo=GuardarClicksTelefonos&secuencia=" + secuencia + "&tabla=" + nombreTabla + "&cust_id=" + cust_id + "&telefono=" + telefono + "&direccion=" + direccion.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g, "") + "&clasificado=" + class_code.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g, "") + "&ciudad=" + ciudad + "&name_id=" + name_id + "&anuncio=" + anuncio;
        hdTelefono.value = '1';
    }
    

}

function hidePhone(secuencia, nombreTabla, cust_id, telefono, direccion, class_code, ciudad, name_id, anuncio) {
    //  alert("div_" + secuencia);

    if (telTimer != null) {
        clearTimeout(telTimer);
        telTimer = null;
    }


    var hdTelefono = document.getElementById('hdIsTelSave_' + secuencia);
    
    // Si ya guardo el click en el teléfono entonces esconderlo de nuevo
    if (hdTelefono.value == '0') {
     
        //document.getElementById("div_" + secuencia).style.visibility = 'hidden';
        document.getElementById("div_" + secuencia).style.display = "none";

        //alert('hide');
        
        document.getElementById("hdSecuencia").value = '';
        document.getElementById("hdTabla").value = '';
        
        document.getElementById("anchor" + secuencia).style.visibility = "";
        document.getElementById("anchor" + secuencia).style.display = "block";


    }

}

function getInfoDataMail(id, url) {
    jQuery.noConflict();
    jQuery('#' + id).mouseover(function() { jQuery('#' + id).attr('href', 'javascript:getData();'); });
    jQuery('#' + id).click(function() { jQuery('#' + id).attr('href', url); });

}
var isHover = 0, isHover2 = 0;
var elementId = '', elementId2 = '';
function addCategory(id, idConteiner) {
    jQuery.noConflict();
    jQuery('#' + id).mouseover(function() { elementId = idConteiner; showCategory(idConteiner); }).mouseleave(function() { setTimeout("HideAtTimeDiv();", 1000); });
    jQuery('#' + idConteiner).mouseover(function() { elementId = idConteiner; isHover = 1; }).mouseleave(function() { isHover = 0; getHideDiv(idConteiner); });
}
function addCategory2(id, idConteiner) {
    jQuery.noConflict();
    jQuery('#' + id).mouseover(function() { elementId2 = idConteiner; showCategory(idConteiner); }).mouseleave(function() { setTimeout("HideAtTimeDiv2();", 1000); });
    jQuery('#' + idConteiner).mouseover(function() { elementId2 = idConteiner; isHover2 = 1; }).mouseleave(function() { isHover2 = 0; getHideDiv2(idConteiner); });
}
function showCategory(id) {
    jQuery.noConflict();
    if (!jQuery('#' + id).is(':visible')) {
        jQuery("#" + id).slideToggle("slow");
    }
}
function getHideDiv(id) {
    jQuery.noConflict();
    if (jQuery('#' + id).is(':visible')) {
        if (isHover == 0) {
            jQuery("#" + id).hide(); //.slideToggle("slow");
            elementId = '';
        }
    }
}
function getHideDiv2(id) {
    jQuery.noConflict();
    if (jQuery('#' + id).is(':visible')) {
        if (isHover2 == 0) {
            jQuery("#" + id).hide(); //.slideToggle("slow");
            elementId2 = '';
        }
    }
}
function HideAtTimeDiv() {
    if (isHover == 0) {
        if (elementId != '') {
            jQuery.noConflict();
            if (jQuery('#' + elementId).is(':visible')) {
                jQuery("#" + elementId).hide(); //.slideToggle("slow");
                elementId = '';
            }
        }
    }
}
function HideAtTimeDiv2() {
    if (isHover2 == 0) {
        if (elementId2 != '') {
            jQuery.noConflict();
            if (jQuery('#' + elementId2).is(':visible')) {
                jQuery("#" + elementId2).hide(); //.slideToggle("slow");
                elementId2 = '';

            }
        }
    }
}

/*Para sombrear las estrellas en el ranking de la cartelera*/
function FillStarsRanking(voto, peli_id, root_url) {
    for (starIndex = 1; starIndex <= voto; starIndex++) {
        var star = document.getElementById('ImageEstrella' + peli_id + '-' + starIndex);
        star.src = root_url + 'images/NuevoLookAndFeel/cine_star_am.png';
    }
    for (starIndex = voto + 1; starIndex <= 5; starIndex++) {
        var star = document.getElementById('ImageEstrella' + peli_id + '-' + starIndex);
        star.src = root_url + 'images/NuevoLookAndFeel/cine_star_gr.png';
    }
}
/*Llamar al server method que registra los votos*/
function RegistrarVotoMenu(peli_id, puntos) {
    //call server side method?
    PageMethods.RegistrarVoto(peli_id, puntos, MostrarResultadoVotacionMenu);
}

/*Mostrara el resultado del proceso de votacion*/
function MostrarResultadoVotacionMenu(mensaje) {
    if (mensaje == 1) {
        alert("Tu voto se ha registrado");
        //__doPostBack('cartelera', '');
    }
    else { alert("Ya registraste un voto para esta opción"); }
}
/*Llamar al server method que registra los votos*/
function RegistrarVotoPelicula(peli_id, puntos) {
    //call server side method?
    PageMethods.RegistrarVoto(peli_id, puntos, MostrarResultadoVotacion);
}

/*Mostrara el resultado del proceso de votacion*/
function MostrarResultadoVotacion(mensaje) {
    if (mensaje == 1) {
        alert("Tu voto se ha registrado");
        //__doPostBack('cartelera', '');
    }
    else { alert("Ya registraste un voto para esta película"); }
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function OpenWELink(link, newLink) {
    if (newLink == 1 || newLink == "true") {

        var open_link = window.open('', '_blank');
        open_link.location = link;
    } else {
        location.href = link;
    }
}


var BusinessName = 'MicroSite_PaginasAmarillas(RD)';
function exportToPdf() {
    //convertContentToPdf(BusinessName, 'content_pdf');
    convertContentToPdf(BusinessName, 'DataContent');
}

function convertContentToPdf(p_str_BusinessName, p_str_HtmlControlID) {
    
    var xml = document.getElementById(p_str_HtmlControlID);
    var exportForm = document.getElementById("exportForm");
    exportForm.content.value = xml.innerHTML;
    //exportForm.busName.value = document.getElementById('nombrePerfil').innerText + ' - ' + p_str_BusinessName;
    //exportForm.busName.value = BusinessName + ' - ' + p_str_BusinessName;
    exportForm.busName.value = BusinessName;
    exportForm.link.value = document.location.href;
    exportForm.typeFile.value = "PDF";
    exportForm.submit();
    exportForm.content.value = "";
    //document.getElementById("DataPrueba").innerHTML = xml.innerHTML;
    //setTimeout("hideMsg()", 4000);
}
function showOverResult(a, b, class_name) {
    var c = document.getElementById("divGenResult_" + a), d = document.getElementById("sobre_" + a);
    if (c != null) b == true ? (c.className = "anunciantesover3", d.style.visibility = "visible") : (c.className = "anunciantesover", d.style.visibility = "hidden")
};
