$(function() {
    $('a[rel*=external],a[rel*=license]').click( function() {
        window.open(this.href);
        return false;
    });
});

function formConteCam(campos) {
    $.each(campos, function(key, value) {
        if($("#" + value).val() == '') $("#" + value).val($("#" + value).attr('title'));
        $("#" + value).focusin(function() {
            if($("#" + value).val() == $("#" + value).attr('title')) $("#" + value).val('');
        });
        $("#" + value).focusout(function() {
            if($("#" + value).val() == '') $("#" + value).val($("#" + value).attr('title'));
        });
    });
}

function generalJs() {
    $('#cabright ul li ul').css('visibility', 'hidden');
    $('#cabright ul li').mouseover(function() {$(this).find('ul').css('visibility', 'visible');});
    $('#cabright ul li').mouseout(function() {$(this).find('ul').css('visibility', 'hidden');});
    $('#cabright ul li div').css('visibility', 'hidden');
    $('#cabright ul li').mouseover(function() {$(this).find('div').css('visibility', 'visible');});
    $('#cabright ul li').mouseout(function() {$(this).find('div').css('visibility', 'hidden');});
    var campobusc = new Array('buscar', 'uemail');
    formConteCam(campobusc);
}

function maxLonTexto(lon, campo, quedan) {
    $('#' + campo).keyup(function(){
        //get the limit from maxlength attribute
        var limit = parseInt(lon);
        //get the current text inside the textarea
        var text = $(this).val();
        //count the number of characters in the text
        var chars = text.length;

        //check if there are more characters then allowed
        if(chars > limit){
            //and if there are use substr to get the text before the limit
            var new_text = text.substr(0, limit);
            //and change the current text with the new text
            $(this).val(new_text);
        }
        $('#quedan').html('Máximo de ' + (lon - chars) + ' caracteres');
    });
}

function validateEmail(email)
{
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return email.match(re)
}


function initPopupLinks() {
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++)
  {
    if (((pageLinks[i].className != null) &&
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) &&
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig)
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}


function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

var popupLinkConfig = new Array;


/*
function altoFoto(urlfoto) {
    var imgFile = new Image();
    imgFile.src = urlfoto;
    imgFile.onload = function() {var alto = imgFile.height;}
    return alto;
}

function anchoFoto(urlfoto) {
    var imgFile = new Image();
    imgFile.src = urlfoto;
    imgFile.onload = function() {var ancho = imgFile.width;}
    return ancho;
}
*/

