/////////////////////////////////////////////////////////////////////////
// FUNCIONES PARA EL POPUP DE CAMPAÃ‘A NO ACTIVA EN UNA CIUDAD ACTIVA/////
/////////////////////////////////////////////////////////////////////////
var popupStatus = 0;

function loadPopup() {
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7",
			"filter": "alpha(opacity = 70)",
			"z-index":"90019"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popup_box").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup() {
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popup_box").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup() {
	var windowWidth = document.documentElement.clientWidth;
	//var windowHeight = document.documentElement.clientHeight;
	//var windowHeight = $(window).scrollTop();
	var popupHeight = $("#popup_box").height();
	var popupWidth = $("#popup_box").width();
	
	//find actual position
	var wPos = $(window).scrollTop();
	var wPos2= wPos+ (wPos/2);

	//centering
	$("#popup_box").css({
		"position": "absolute",
		"top": wPos2,
		"left": windowWidth/2-popupWidth/2,
		"z-index": "90020",
		"margin-top":"200px"
	});
	//only need force for IE6
//	$("#backgroundPopup").css({
//		"height": windowHeight,
//		"background-color": "black",
//		"position": "absolute",
//		"top": "0",
//		"left": "0",
//		"z-index": "0",
//		"width": "100%",
//		"height": "200%"
//	});
	overlay_size();
	
}
function centerPopupSpecial() {
		var windowWidth = document.documentElement.clientWidth;
		//var windowHeight = document.documentElement.clientHeight;
		//var windowHeight = $(window).scrollTop();
		var popupHeight = $("#popup_box").height();
		var popupWidth = $("#popup_box").width();
		
		//find actual position
		var wPos = $(window).scrollTop();
		var wPos2= wPos+ (wPos/2);

		//centering
		$("#popup_box").css({
			"position": "absolute",
			"top": "0px",
			"margin-top":"100px",
			"left": windowWidth/2-popupWidth/2,
			"z-index": "90020"
		});
	//only need force for IE6
//	$("#backgroundPopup").css({
//		"height": windowHeight,
//		"background-color": "black",
//		"position": "absolute",
//		"top": "0",
//		"left": "0",
//		"z-index": "0",
//		"width": "100%",
//		"height": "200%"
//	});
	overlay_size();
}


function getPageScrollTop(){
    var yScrolltop;
    var xScrollleft;
    if (self.pageYOffset || self.pageXOffset) {
      yScrolltop = self.pageYOffset;
      xScrollleft = self.pageXOffset;
    } else if(document.documentElement&& document.documentElement.scrollTop
      || document.documentElement.scrollLeft ){   // Explorer 6 Strict
      yScrolltop = document.documentElement.scrollTop;
      xScrollleft = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScrolltop = document.body.scrollTop;
      xScrollleft = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScrollleft,yScrolltop);
    return arrayPageScroll;
  }


function overlay_size() {
    try {
      if(window.innerHeight && window.scrollMaxY
        || window.innerWidth && window.scrollMaxX) {
        h = window.innerHeight + window.scrollMaxY;
        w = window.innerWidth + window.scrollMaxX;
        var deff = document.documentElement;
        var wff = (deff&&deff.clientWidth)
          || document.body.clientWidth || window.innerWidth || self.innerWidth;
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight
          || window.innerHeight || self.innerHeight;
        w -= (window.innerWidth - wff);
        h -= (window.innerHeight - hff);
      } else if(document.body.scrollHeight > document.body.offsetHeight
        || document.body.scrollWidth > document.body.offsetWidth) {
          // all but Explorer Mac
        h = document.body.scrollHeight;
        w = document.body.scrollWidth;
      } else {
        // Explorer Mac.would also work in Explorer 6 Strict, Mozilla and Safari
        var left_top = getPageScrollTop();
        h = left_top[1] + settings.height;
        w = left_top[0] + settings.width;
        if( h < document.body.offsetHeight) {
          h = document.body.offsetHeight;
        }
        if( w < document.body.offsetWidth) {
          w = document.body.offsetWidth;
        }
      }
    } catch(err) {
      w = $(document.body).width();
      h = $(document.body).height();
    }
    //alert("height "+h);
   // alert("width "+w);
    w=w+200;
    $("#backgroundPopup").css({"height":h+"px", "width":w +"px", "margin-left": "-200px", "background-color": "#000000", "position": "absolute", "top": "0", "left": "0", "z-index": "-1"});
  }

var cities_status="hidden";
function toggle_cities()
{
	if(cities_status=="hidden")
	{
		show_cities();
	}
	else
		hide_cities();
}
function show_cities()
{
	slider1=$("#cities_slider");
	slider2=$("#main-menu");
	
	slider1[0].style.display="block";
	$("#arrow_anchor")[0].style.backgroundImage='url("/assets/img/select-up.gif")';
	slider1.animate({"height":45},"200","linear",function(){cities_status="shown";}).add(
	slider2.animate({"margin-top":70},200,"linear"));
}
function hide_cities()
{
	slider1=$("#cities_slider");
	slider2=$("#main-menu");
	$("#arrow_anchor")[0].style.backgroundImage='url("/assets/img/select.gif")';
	slider1.animate({"height":1},"200","linear",function(){$("#cities_slider")[0].style.display="none";cities_status="hidden";}).add(
	slider2.animate({"margin-top":30},200,"linear"));
}

$(function() {
	$(".popupContactClose").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
});
/////////////////////////////////////////////////////////////////////////
//FIN FUNCIONES PARA EL POPUP DE CAMPAÃ‘A NO ACTIVA EN UNA CIUDAD ACTIVA//
/////////////////////////////////////////////////////////////////////////


//FUNCIONES PANTALLA DE PUNTOS

function clearFriend(num)
{
	if($('#invitation' + num).val() == "<?= _('Amigo').' ' ?>" + num)
		$("#invitation" + num).val("");
}
function addFields()
{
	var n = parseInt($('#num_fields').val()) + 1;
	$('#invite_fields').append("<p class='right'><input type='text' name='invitation"+n+"' id='invitation"+n+"' value='<?= _('Amigo') ?> "+n+"' onclick='clearFriend(" + n + ")' /></p>");
	n++;
	$('#invite_fields').append("<p><input type='text' name='invitation"+n+"' id='invitation"+n+"' value='<?= _('Amigo') ?> "+n+"' onclick='clearFriend(" + n + ")' /></p>");
	$('#num_fields').val(n);
}
function sendInvitations()
{
	var data = new Object();
	data['num_fields'] = $('#num_fields').val();
	for(i = 1; i <= data['num_fields']; i++)
		data['invitation'+i] = $('#invitation'+i).val();
	$.ajax({
		url : '/purchase/json_send_invitations',
		type: 'POST',
		data: { data : data },
		success : function(response){
			$('#invitation_response').text(response.msg_response);
			for(i = 1; i <= data['num_fields']; i++){
				if(response['invitation'+i])
					$('#invitation'+i).addClass('ok');
				else
					$('#invitation'+i).removeClass('ok');
			}
		},
		error: function(){
			alert("<?= _('Ha ocurrido un error. Por favor, inténtalo de nuevo.') ?>");
		}
	});
}

// FIN FUNCIONES PANTALLA DE PUNTOS

