$(document).ready(function() {
//--------------------------------------------------------------------------------------------------------------------------------------


	
	   
	   
	$(".ratetype:has(small)").toggle(
	function(){
		var id = $(this).attr("id");
		$('#'+id+'_expand').show('slow');
		
	}
	,
	function(){
		var id = $(this).attr("id");
		$('#'+id+'_expand').hide();	
	});


	$("#searchbox-top > form").submit(function() {
		if($(".ajax-msg").data("busy") == '1') return false; //check for active ajax 
		
			$.post("rates_searchbox.php",{inputtext:$("#inputtext").attr("value")},function(data) {
				$("#searchbox").html(data);
				$(".ajax-msg").data("busy","0");
			});
		return false;
	});
	$("#searchboxsubmit").click(function(){
		$("#searchbox-top > form").submit();
	});


	$("abbr:contains(ZRTP)").toggle(
		function() {
			
			$("#zrtp_desc").slideDown("slow");
		}
		,
		function() {
			
			$("#zrtp_desc").slideUp("slow");
		}
	);

	
	$("#nofeeFormConfirm").click(function(){
	
		var f_namesurname = $("#namesurname").text();
		var f_email = $("#email").text();
		var f_imei = $("#imei").text();
		var f_amo = $("#amo").text();
		var f_trans_id = $("#trans_id").text();
		var f_ltype = $("#ltype").text();
		
		$.post("assert_paypal_IPN.php",{	imei:f_imei,
											namesurname:f_namesurname,
											email:f_email,
											amo:f_amo,											
											trans_id:f_trans_id,
											ltype:f_ltype
											
										},
										function(data) {
											//alert('data: '+data);
											$("#formbuttons").html(data);
											
										}
		);	
	
		
	});
	
	$(".labelBold:contains(what is this?)").toggle(
		function () {
		
			$(this).parents("td").find(".f_info_box_hidden").show();
			
		}
		,
		function() {
		
			$(this).parents("td").find(".f_info_box_hidden").hide();
		
		}
	);
	
	//main menu
	//$('ul.dropdown > li > ul > li > ul').parent('li').children('a').append('&nbsp;&nbsp;&#187;');



//--------------------------------------------------------------------------------------------------------------------------------------


//AJAX handlers - - - - - - - - // Start-Send-[success,Error]-Complete-Stop
 $(".ajax-msg").ajaxStart(function(){
   $(this).html('<img src="http://localhost/tivi_Web/base/img/loading.gif" />');
   $(this).data("busy","1"); //set ajax busy, to avoid other ajax sendings
 });
 
  $(".ajax-msg").ajaxStop(function(){
   $(this).html('<!-- status:stopped --> ');
   $(this).data("busy","0"); //set ajax status free
 });
 
 $(".ajax-msg").ajaxSend(function(evt, request, settings){
   //...
 });

 $(".ajax-msg").ajaxSuccess(function(evt, request, settings){
   $(this).html('<!-- status:ok --> ');
 });

 $(".ajax-msg").ajaxError(function(event, request, settings){
   $(this).html('<a title="Error! please reload page and try again.." href="?reload"><img alt="loading error" src="http://localhost/tivi_Web/base/img/loading_err.gif" /></a>');
 }); 


	$('#bid-form input').focus(function(){
		
	});
	$('#bid-form input[type="submit"]').click(function(){
		
		$AMO = $('#bid-form input[name="amount"]').attr('value');
		$EMAIL = $('#bid-form input[name="email"]').attr('value');
		$IMEI = $('#bid-form input[name="imei"]').attr('value');
		$LTYPE = $this.find('input[name="ltype"]').attr('value');
		if($AMO > 0 && $EMAIL.length > 0 && $IMEI.length > 0 && $LTYPE) {
			$('#bid-form').hide();
			$.post("make-bid.post.php", { amount: $AMO, email: $EMAIL, ltype: $LTYPE, imei: $IMEI },
				function(data){
				   alert(data);
				  //$('#bid-form-response').html('<div style="padding:4px 10px;margin:4px;" class="err error">'+data+'</div>');
				}
			);
		}
		else alert('Your email address and IMEI/DeviceID are required to submit the offer!');
		
		return false;
	});
	
	$('.licence-bid').click(function(e){
		$('#bid-form').css({'position':'absolute','top':(e.pageY-130)+'px','left':(e.pageX-170)+'px','visibility':'visible'}).show();
		$this = $(this);
		
		$EMAIL = '';
		$IMEI = '';
		$GROUP = ($this.find('input[name="group"]').attr('value') == 'pc') ? 'PC' : 'Mobile';
		$LTYPE = $GROUP+'/'+$this.find('input[name="ltype_label"]').attr('value');
		
		$AMO = $this.find('input[name="amo"]').attr('value');
		
		
		$('#bid-form input[name="amount"]')
		.focus()
		.attr('value',$AMO);

		$('#bid-form #ltype').html('<b>'+$LTYPE+'</b>')
		
		$('#bid-info input[name="email"]').attr('value',$EMAIL);
		$('#bid-info input[name="imei"]').attr('value',$IMEI);		
	});
	
	$('#bid-form .close').click(function(){
		$('#bid-form').hide();
	});
 
	$('input[type="radio"]')
	.parent('label')
	.mouseover(function(){
		$this = $(this);
		$this = $this.find('.licence-bid');
		$this.attr('src','../../base/img/BidYourPrice2.png');
	})
	.mouseout(function(){
		$this = $(this);
		$this.find('.licence-bid').attr('src','../../base/img/BidYourPrice.png');
	});
 
	$('.tabs > a').click(function(){
		$this = $(this);
		$('.tabs > a').removeClass('active');
		$this.addClass('active');
		//hide all
		$('#mob-licences').hide();
		$('#pc-licences').hide();
		$('#free-stuff').hide();
		return false;
	});
	
	$('.show-pc-licences').click(function(){
		$('#pc-licences').show();
		return false;
	}); 
	$('.show-mob-licences').click(function(){
		$('#mob-licences').show();
		return false;
	});
	$('.show-free-stuff').click(function(){
		$('#free-stuff').show();
		return false;
	});
	
	$('.box').click(function(){
		$this = $(this);
		//alert($(this).parent('div').attr('class'));
		$method = $this.parent('div').attr('class');
		//alert($method);
		if($method == 'url') {
			top.location = $this.attr('lang');
		}
		else {
			top.location = '?step=2&ltype='+$this.attr('lang');
		}
	});
 
//--------------------------------------------------------------------------------------------------------------------------------------

	$('#s3slider').s3Slider({
		timeOut: 4000
	});
	

});