var baseurl = '/';

function scroll_news_func()
{
	scroll_news = $('#scroll_news').val();
	$('a','.news_marquee').each(function(){
		if($(this).attr('ref') == scroll_news)
		{
			$(this).hide('fast');
		}
	});
	scroll_news++;
	if(scroll_news == 4)
	{
		scroll_news = 1;
	}
	$('a','.news_marquee').each(function(){
		if($(this).attr('ref') == scroll_news)
		{
			$(this).show('fast');
		}
	});
	$('#scroll_news').val(scroll_news);
}

function center_em()
{
	x = $(window).width();
	$('.centered').each(function(){ 
		if(x < $(this).width())
		{ $(this).css({left:'0px','margin-left':'10px'}); }
		else
		{ $(this).css({left:(x/2)+'px','margin-left':'-'+($(this).width()/2)+'px'}); }
	});
}

function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

function get_popup(key)
{
	switch(key)
	{
		case "trae_a_un_amigo":
			$.blockUI({
				message: $('#trae_amigo_popup'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		break;
		
		case "politica_de_privacidad":
			$.blockUI({
				message: $('#polpriv_popup'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		break;
		
		case "como_contratar":
			$.blockUI({
				message: $('#como_contratar_popup'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		break;
		
		case "mapa_del_sitio":
			$.blockUI({
				message: $('#site_map_popup'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-323px',
					'margin-top': '-61px',
					border: 0,
					background: 'none'
				}
			});
		break;
		
		case "regalos":
			$.blockUI({
				message: $('#regalos_popup'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		break;
		
		case "tua_condiciones_generales":
		{
			$.blockUI({
				message: $('#tua_condiciones_generales'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_proteccion_de_datos_personales":
		{
			$.blockUI({
				message: $('#tua_proteccion_de_datos_personales'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_apadrinamiento":
		{
			$.blockUI({
				message: $('#tua_apadrinamiento'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_informacion_productos":
		{
			$.blockUI({
				message: $('#tua_informacion_productos'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_seguridad":
		{
			$.blockUI({
				message: $('#tua_seguridad'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_formalizacion_solicitudes":
		{
			$.blockUI({
				message: $('#tua_formalizacion_solicitudes'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_cancelacion_solicitudes":
		{
			$.blockUI({
				message: $('#tua_cancelacion_solicitudes'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_propiedad_intelectual":
		{
			$.blockUI({
				message: $('#tua_propiedad_intelectual'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_acceso_y_estancia":
		{
			$.blockUI({
				message: $('#tua_acceso_y_estancia'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_nuestra_responsabilidad":
		{
			$.blockUI({
				message: $('#tua_nuestra_responsabilidad'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "tua_derechos_de_los_usuarios":
		{
			$.blockUI({
				message: $('#tua_derechos_de_los_usuarios'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
		
		case "texto_legal":
		{
			$.blockUI({
				message: $('#texto_legal'),
				css: {
					top: '50%',
					left: '50%',
					'margin-left': '-175px',
					'margin-top': '-175px',
					border: 0,
					background: 'none'
				}
			});
		}
		break;
	}
	
	
}

function news_scrollers(orientation, active_news)
{
	if($.browser.msie)
	{
		$('.subcontent','.center_top').each(function(){
			if($(this).attr('ref') == active_news)
			{
				$(this).hide();
			}			
		});
		switch(orientation)
		{
			case 'left':
				active_news--;
				if(active_news == 0)
				{
					active_news = 3;
				}
			break;
			case 'right':
				active_news++;
				if(active_news == 4)
				{
					active_news = 1;
				}
			break;
		}
		$('.subcontent','.center_top').each(function(){
			if($(this).attr('ref') == active_news)
			{
				$(this).show('fast');
			}			
		});
	}
	else
	{			
		switch(orientation)
		{
			case 'left':
				active_news--;
				if(active_news == 0)
				{
					active_news = 3;
				}
			break;
			case 'right':
				active_news++;
				if(active_news == 4)
				{
					active_news = 1;
				}
			break;
		}
		switch(active_news)
		{
			case 1: margin_left = 0; break;
			case 2: margin_left = '-576px'; break;
			case 3: margin_left = '-1152px'; break;
		}
		$('.allcontents').animate({'margin-left': margin_left},500);
	}
	return active_news;
}

function callme_submit()
{
	var tel = $('.callme_form_tel').val();
	var tsource = $('#tsource').val();
	var distribuidor = $('#distribuidor').val();
	$.ajax({
		url: baseurl + 'helper/callme/',
		type: 'POST',
		data: { telefono: tel, tsource: tsource, distribuidor: distribuidor },
		dataType: 'json',
		success: function(data)
		{
			if(data.status)
			{
				$('.callme').animate({ width: '0px'},400,function(){
					$('p','.callme_form').html('<i>Ahora nos ponemos en contacto contigo</i>');
					$('.callme_form_tel','.callme_form').hide();
					$('.submitter','.callme_form').hide();
				});
				$('.callme').animate({ width: '327px'},400);
				var url = 'http://www.cobaltskull.com/pixels/get_tracking/adslworld/' + jQuery('#distribuidor').val() + '/' + jQuery('#tsource').val() + '/callme';
				document.getElementById('tracker').contentWindow.location.href = url;
				
				var url_remark = 'http://www.cobaltskull.com/pixels/get_tracking/adslworld/' + jQuery('#distribuidor').val() + '/' + jQuery('#tsource').val() + '/remarketing';
					document.getElementById('tracker_remark').contentWindow.location.href = url_remark;	
			}
			else
			{
				alert(data.msg);
			}
		}
	});
}

function call_compdir(op)
{
	$.blockUI({
		message: $('#compdir'),
		css: {
			top: '50%',
			left: '50%',
			'margin-left': '-175px',
			'margin-top': '-200px',
			border: 0,
			background: 'none'
		}
	});
	$('.content','#compdir').removeClass('adslworld');
	$('.content','#compdir').removeClass('movistar');
	$('.content','#compdir').removeClass('jazztel');
	$('.content','#compdir').removeClass('yacom');
	$('.content','#compdir').removeClass('orange');
	$('.content','#compdir').removeClass('ono');
	$('.content','#compdir').removeClass('vodafone');
	$('.content','#compdir').addClass(op);
	$('.compdir_form','#compdir').attr('ref',op);
	$('.thx_compdir','#compdir').hide('fast');
}

function link_to_operador()
{
	$('.btn_jazztel').click(function(){
		window.location = "http://www.mijazztel.com/jazztel/index/adslworld/"+$('#distribuidor').val();
	});
	$('.btn_movistar').click(function(){
		window.location = "http://www.altas-movistar.es/mailing/duo_10mb/adslworld/"+$('#distribuidor').val();
	});
	$('.btn_ono').click(function(){
		window.location = "http://ofertaono.com/fibra/?tsource=adslworld&distribuidor="+$('#distribuidor').val();
	});
	$('.btn_orange').click(function(){
		window.location = "http://www.ofertaorange.com/inicio/index/adslworld/"+$('#distribuidor').val();
	});
	$('.btn_vodafone').click(function(){
		window.location = "http://www.oferta-vodafone.com/inicio/index/adslworld/"+$('#distribuidor').val();
	});
	$('.btn_yacom').click(function(){
		window.location = "http://www.yacom-ofertas.com/inicio/index/adslworld/"+$('#distribuidor').val();
	});
}
