// extension jQuery para determinar si un objeto existe
// uso: if ($(selector).exists()) { }
jQuery.fn.exists = function(selector) {return (jQuery(selector).length > 0);}

// extension a jQuery para hacer auto-extensible el input que muestra el linkear como en documentos
// es util para usuarios y sac para cuando tienen que copiar dicho link de algun documento
jQuery.fn.autoGrowInput = function(o) {

    o = jQuery.extend({
        maxWidth: 500,
        minWidth: 0,
        comfortZone: 3
    }, o);

    // this.filter('input:text').each(function(){

		var minWidth = jQuery(this).width(),
    val = '',
    input = jQuery(this),
    testSubject = jQuery('<tester/>').css({
        position: 'absolute',
        top: -9999,
        left: -9999,
        width: 'auto',
        fontSize: input.css('fontSize'),
        fontFamily: input.css('fontFamily'),
        fontWeight: input.css('fontWeight'),
        letterSpacing: input.css('letterSpacing'),
        whiteSpace: 'nowrap'
    }),
            
		check = function() {

	     if (val === (val = input.val())) {return;}

	     // Enter new content into testSubject
	     var escaped = val.replace(/&/g, '&amp;').replace(/\s/g,' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
	     testSubject.html(escaped);

	     // Calculate new width + whether to change
	     var testerWidth = testSubject.width(),
	         newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
	         currentWidth = input.width(),
	         isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth)
	                              || (newWidth > minWidth && newWidth < o.maxWidth);

	     // Animate width
	     if (isValidWidthChange) {
	         input.width(newWidth);
	     }

     };

     testSubject.insertAfter(input);
     jQuery(this).bind('load click focus keyup keydown blur update', check);

    // });
    // return this;
};


function choose_to(anchor, uri) {
  var url = "/redirect/TO/com/" + uri
	document.location = (jQuery("#freetrial-boox").attr("name") == 'freetrial') ? anchor : uri;
}

function _url() {
	// var company = document.getElementById('company').innerHTML;
	var separator = document.getElementById('separator').innerHTML;
	var args = Array.prototype.slice.call(arguments);

	var domain = args.shift();
	var uri = args.join(separator);

	// go2('.fr', 'jurisdictions', 'FR') -> vlex.fr
  // go2('.com.mx', 'jurisdictions', 'MX'); -> vlex.com.mx
  // go2('br.', 'jurisdictions', 'BR'); -> br.vlex.com
  // go2('prensa_es', 'jurisdictions', 'ES'); -> prensa.vlex.es
  
	// return rebuild_domain(domain) + separator + uri;
	return uri;
}

function go2popup() {
	var args = Array.prototype.slice.call(arguments);
	var popup_options = args.pop();
	var popup_title = args.pop();
	var url = '/redirect/TO' + args[0] + '/' + _url.apply(this, args);
	window.open(url, popup_title, popup_options);
	return false;
}

function go2() {
	var args = Array.prototype.slice.call(arguments);
	var url = '/redirect/TO' + args[0] + '/' + _url.apply(this, args);   
	if(window.location.toString().search("embedded_freetrial") == -1){
      window.location.href = url;		
	}else{
	  top.location.href = url;
	}
}



