function retFalse()
{
 try
 {
  // VISTA IE 7
  window.event.returnValue = false;
 } catch (error)
 {
  // ALL OTHER (MOZILLA, OPERA, SAFARI, IE 6 & 7 ON XP)
  return false;
 }
}

$(document).ready(
   function()
   {

   	/**
   	* Count price
   	*/
   	function countPrice(element)
   	{
   		var price = parseInt(element.attr("value"));
 			var plan_id = parseInt(element.attr("name"));
 			var current_price = parseInt($("td.total_"+plan_id).text());
 			if(element.attr("checked"))
 			{
   			var new_price = current_price + price;
 			}
 			else
 			{
   			var new_price = current_price - price;
 			}
 			new_price = parseFloat(new_price);
 			$("td.total_"+plan_id).text(new_price);
   	}
   	
   	$(".form_button_margin_offer").click(
   		function()
   		{
   			$("#data_plan").attr("value", $("#selected_plan").text());
   			$("#data_services").attr("value", $("#selected_services").text());
   		}
   	);

   	if($("#data_plan").attr("value") != "")
   	{
   		$("#selected_plan").text($("#data_plan").attr("value"));
   	}

   	if($("#data_services").attr("value") != "")
   	{
   		$("#selected_services").text($("#data_services").attr("value"));
   	}

   	if($("#data_service_ids").attr("value") != "")
   	{
   		if($("#status").attr("value") != 1)
   		{
   			var str_value = $("#data_service_ids").attr("value");
	   		if(str_value != "")
	   		{
		   		try
			   	{
			   		var arr_services = str_value.split(",");
			   		for(i = 0; i < arr_services.length; i++)
			   		{
			   			if($(":checkbox[@id="+ arr_services[i] +"]"))
			   			{
			   				$(":checkbox[@id="+ arr_services[i] +"]").attr("checked", "checked");
			   				countPrice($(":checkbox[@id="+ arr_services[i] +"]"));
			   			}
						}
		   		}
		   		catch(e)
		   		{
		   			
		   		}
	   		}
   		}
   	}

   	if($("#status").attr("value") == 0)
   	{
   		$(".form_container").hide("fast");
   	}

    if($("#status").attr("value") == 2)
   	{
   		document.getElementById("bottom").focus();
   	}

   	if($("#status").attr("value") == 1)
   	{
   		document.getElementById("bottom").focus();
   	}

   	$(":submit[@name='plan']").click(
	   	function()
	   	{
	   		var plain_id = $(this).attr("id");
	   		var services = "";
	   		var service_ids = "";
	   		$(":checkbox[@name='"+plain_id+"']").each(
		   		function()
		   		{
		   			if($(this).attr("checked"))
		   			{
			   			services = services + $(this).attr("lang") + ", ";
			   			service_ids = service_ids + $(this).attr("id") + ", ";
		   			}
		   		}
	   		);
	   		$("#selected_plan").html($("td[@id='"+plain_id+"']").text());
	   		services = services.substring(0, services.length-2);
	   		if(services == '')
	   		{
	   			$("#add_text").hide();
	   		}
	   		else
	   		{
	   			$("#add_text").show();
	   		}
	   		$("#selected_services").html(services);
	   		$("#data_service_ids").attr("value", service_ids);
	   		$(".form_container").show("fast");
	   	}
   	);
   	
   	$(":checkbox.counter").click(
   		function()
   		{
   			countPrice($(this));
   		}

   	);

   	$(".tooltip_q").tooltip(
   	{
	    track: true,
	    showBody: " - ",
	    showURL: false
   	}
    );
   	if($("#offset").attr("value") != 2)
   	{
   		$("#news_prev").hide("slow");
   	}

   	$("#news_next").click(
   		function()
   		{
   			var current = parseInt($("#offset").attr("value"));
   			var offset = current + 2;
   			$("#news_prev").show("slow");
   			$("#offset").attr("value", offset);

   			$.getJSON(
   				"http://" + document.domain + "/index.php/,ajaxrequest.true,offset." + offset,
   				{},
   				function(json)
   				{
   					if(json == null)
   					{
   						$("#news_wrapper").html($("#news_wrapper").html());
   						$("#news_next").hide("slow");
   						offset = offset - 2;
   						$("#offset").attr("value", offset);
   					}
   					else
   					{
	   					var html = "";
	   					$.each(json.list, function(i,item)
	   					{
	   						html = html + "<div class='footer_block_content_text'> <div class='headline'>" + item.date + "</div>" + item.summary + " </div>";
	   					});
	   					$("#news_wrapper").html(html);
	   					if(json.count < 2)
	   					{
	   					  $("#news_next").hide("slow");
	   					}
   					}
   				}
   			);
   		}
   	);

   	$("#news_prev").click(
   		function()
   		{
   			var current = parseInt($("#offset").attr("value"));
   			var offset = current - 2;
   			if(offset < 0)
   			{
   				offset = 0;
   			}
   			$("#news_next").show("slow");
   			$("#offset").attr("value", offset);
   			$.getJSON(
   				"http://" + document.domain + "/index.php/,ajaxrequest.true,offset."+offset,
   				{},
   				function(json)
   				{
   					$("#news_wrapper").html("");
   					var html = "";
   					$.each(json.list, function(i,item)
   					{
   						html = html + "<div class='footer_block_content_text'> <div class='headline'>" + item.date + "</div>" + item.summary + " </div>";
   					});
   					$("#news_wrapper").html(html);
		   			if(offset == 0)
		   			{
		   				$("#news_prev").hide("slow");
		   			}
   				}

   			);
   		}
   	);


   	$("#flash").cycle({
		    fx:     'scrollLeft',
		    speed:   1000,
		    timeout: 10000,
		    pager:  '#buttons ul',
		    pagerAnchorBuilder: function(idx, slide)
		    {
		    	var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
		    	if(ie6)
		    	{
		    		// Added style here because of IE6 ir does not applies classes
		    		return '<li style="height:24px;width:24px;background:url(images/flash_button_1.gif) no-repeat left;float:left;margin:0px 3px 0px 3px;cursor:pointer;"><div class="button_num" style="color:#666768;font-size:12px;padding:4px 0px 0px 8px;">'+(idx+1)+'</div></li>';
		    	}
		    	else
		    	{
		    		return '<li><div class="button_num">'+(idx+1)+'</div></li>';
		    	}
        }

		});

   }
);
