var _GLOBAL = {
  context	: '/tvh/'
};



$(function(){
  // INI: hide conditional elements
  $('#barra_superior').hide();
 // $('#tuopinion').hide();
  // END: hide conditional elements
	
	if($('html').hasClass('ie') || $.browser.msie){
		$('#viewallvideos').css('margin-left', '-31px');
	}

	$('.contacta, .contactaTop, .btn-opcionProblema, #footer-site .contact a').click(function(){
		var width = 425;
		var height = 290;
		var left = (screen.width/2)-(width/2);
		var top = (screen.height/2)-(height/2);

		window.open(this.href,'Contacto_Legal', "toolbar=0,width="+ width +",height="+ height +",resizable=no,scrollbars=1,top="+ top +" , left="+ left +")");
		return false;
	});

  // INI: ISLOOGGED
  $.ajax({
    url		: _GLOBAL.context+'isLogged.xml',
    data	: 'nocache=' + Math.random(),
    success : function(xml)
    {
      if ( $('data userName',xml).length )
      {
        $('#logout span').text($('data userName',xml).text()+'!');
        $('#logout').show();
        
        if($('html').hasClass('ie') || $.browser.msie){
        	var w = $('#logout .user').width() + 320;  
        
        	$('#logout').css('width', w);
        }
        $('#login_wrapper').remove();
        $('.estrellas').addClass('logged');
      }
      else
      {
        $('#barra_superior').show();
        $('#logout').hide();
      }

    }
  });
  // END: ISLOOGGED

  // INI: SUBMIT OPINION
  $.ajax({
    url		: _GLOBAL.context+'opinionAllowed.xml',
    data	: 'nocache=' + Math.random()+'&opinion.origin=EVAX_PDD',
    success : function(xml)
    {
      if ( $('data opinionAllowed',xml).length )
      {
        if ($('data opinionAllowed', xml).text() == 'true') {
        	$('#tuopinion').show();
        }
        else {
			//$('#tuopinion').remove();
		}
      }
    }
  });
  // END: SUBMIT OPINION

  // INI: Javascript Hack For link with rel='external'
  if (!document.getElementsByTagName) {
    return;
  }

  var anchors = document.getElementsByTagName("a");

  for (var i=0; i<anchors.length; i++)
  {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
      anchor.target = "_blank";
    }
  }
  // END: Javascript Hack For link with rel='external'


  // INI: Preload images
  var _i = new Array();
  var i  = new Array('/media/img/common/ico_starwhite.gif',
             '/media/img/common/ico_stargreen.gif',
             '/media/img/common/ico_starblue.gif',
             '/media/img/common/ico_minus_white.gif',
             '/media/img/common/ico_plus_white.gif',
             '/media/img/common/ico_plus.gif',
             '/media/img/common/ico_minus.gif',
             '/media/img/botones/btn_enviar_over.gif',
             '/media/img/botones/btn_enviar.gif',
             '/media/img/botones/btn_haztevip_off.png',
             '/media/img/botones/btn_haztevip_on.png',
             '/media/img/botones/btn_qopinas_off.png',
             '/media/img/botones/btn_qopinas_on.png');
  for(c=0;c<13;c++)
  {
    _i[c] = document.createElement('img');
    _i[c].src = i[c];
    try {
      document.getElementById('preload').appendChild(_i[c]);
    }
    catch (e){}

  }
  // END: Preload images
});

function _REGISTERCALLBACK(u,p)
{
    $('#IDlogin').val(u);
    $('#IDpassword').val(p);
    $('#IDtodayLogin').submit();
}


function getYears(d,m,a){
    var day = parseInt(d, 10);
    var month = parseInt(m, 10);
    var year = parseInt(a, 10);

    if (isNaN(day) || isNaN(month) || isNaN(year)) {
    return true;
  }

    var today = new Date();

    var birthdate = new Date(year, month - 1, day);


    var dif = today - birthdate;
    var days = dif/86400000;

    return (days / 365);
}

_LOGINCALLBACK = _REGISTERCALLBACK;

function openWindow(url, name, w, h, x, y, _scrollbars){
	var wW = (w!=null) ? w : screen.width-50;
	var wH = (h!=null) ? h : screen.height-150;
		
	var wX = (x!=null) ? x : Math.round(screen.width/2-(wW/2));
	var wY = (y!=null) ? y : Math.round(screen.height/2-(wH/2));

	var wscroll = (_scrollbars != null) ? _scrollbars : 0;

    var name = (name != null) ? name : 'Evax_Popuop';

    var win = window.open(url, name, 'resizable=0,scrollbars='+wscroll+',status=0,location=0,toolbar=0,menubar=0,width='+wW+',height='+wH+',screenX='+wX+',screenY='+wY+',left='+wX+',top='+wY+'');

    return win;
}

$().ready(function(){
	$('#formSearch #submitSearch').bind('mouseover', function(){
		$(this).attr('src', '/media/img/botones/btn_buscador_on.gif');
		$(this).css('background-color', '#7bc911');
	})
	
	$('#formSearch #submitSearch').bind('mouseout', function(){
		$(this).attr('src', '/media/img/botones/btn_buscar.gif');
		$(this).css('background-color', '#429FE4');
	})
})

