/**
 * @author Kovacs Gabriel
 */

// Quantity spin buttons
function increase_by_one(field,fieldsplit) {
	nr = parseInt(document.getElementById(field).value);
	nr_split = parseInt(document.getElementById(fieldsplit).value);
	document.getElementById(field).value = nr + nr_split;
	return false;
}

function decrease_by_one(field,fieldsplit) {
	nr = parseInt(document.getElementById(field).value);
	nr_split = parseInt(document.getElementById(fieldsplit).value);
	if (nr > 0) {
		if( (nr - nr_split) > 0) {
			document.getElementById(field).value = nr - nr_split;
		}
	}
	return false;
}



function ajax_receive_other_emails( idSel) {
	
	var val_select = ($('#cat_product'+idSel).val());
	
	
	$.ajax({
	    type: "POST",
	    url: "ajax_receive_emails.php",
	    data: {
	       id: val_select,
	       id_sel : idSel
	    },
	    
	    success: function(data){
			$("#check"+idSel).html(data);
			
	    }
	});
	
	
}


function doShowPurchased(i) {
	
	if ($('#purchased_at'+i).attr('checked')) {
		
		$('#acq_purchased'+i).show();
	}
}


function doHidePurchased(i) {
	
	if ($('#otheri'+i).attr('checked')) {
		
		$('#acq_purchased'+i).hide();
	}
}

function doShowOther(i) {
	
	if ($('#otheri'+i).attr('checked')) {
		
		$('#acq_other'+i).show();
	}
}

function doHideOther(i) {
	
	if ($('#purchased_at'+i).attr('checked')) {
		
		$('#acq_other'+i).hide();
	}
}

function doHideBoth(i) {
	if ($('#gift'+i).attr('checked')) {
		
		$('#acq_purchased'+i).hide();
		$('#acq_other'+i).hide();
	}
	
}


$('#content-right #show-hide').hide();

// on page load complete, fire off a jQuery
$(document).ready(function() {

	var nrr = $('#nr').val();
	
	for (jj=0; jj<nrr; jj++){
		//alert(jj);
		$('#acq_purchased'+jj).hide();
		$('#acq_other'+jj).hide();
		doShowPurchased(jj);
		doShowOther(jj);
		
	}
	
	
	
	//Scrolling pages
	$('a.goToTop').click(
			function()
			{
				$('#header').ScrollTo(600, 'easein');
				return false;
			}
		);
	
	
	
	// non-clickable links
	$(".return-false").click( function() {
		return false;
	});
	$('.hide-with-js').hide(); // use this class to hide the message "please open this link in new window"
	
		
	$("#product-details-right .arrow-up").click( function() {
		increase_by_one('qty','qtysplit');
		return false;
	}
	);

	$("#product-details-right .arrow-down").click( function() {
		decrease_by_one('qty','qtysplit');
		return false;
	}
	);

	$(".listing a").tooltip({
		bodyHandler: function() {
			if ($($(this).attr("rel")).html()) {
				var contentTooltip = $($(this).attr("rel")).html();
				if (contentTooltip.length) {
					return contentTooltip;
				}
			}
		},
		track: true,
		delay: 0,
		showURL: false,
		extraClass: "tooltip"
	});

	
	// Header input fields
	/*$("#header-username").focus(function(){ 
		if ($(this).val()=="username") {
			$(this).val("");
		}
	});
	$("#header-username").blur(function(){ 
		if ($(this).val()=="") {
			$(this).val("username");
		}
	});
	
	$("#header-password").focus(function(){ 
		if ($(this).val()=="password") {
			$(this).val("");
		}
	});
	$("#header-password").blur(function(){ 
		if ($(this).val()=="") {
			$(this).val("password");
		}
	});*/
	
	$("#header-keyword").focus(function(){ 
		if ($(this).val()=="keyword") {
			$(this).val("");
		}
	});
	$("#header-keyword").blur(function(){ 
		if ($(this).val()=="") {
			$(this).val("keyword");
		}
	});
	
	
	// JUMP MENU
	$("select.jump-menu").change(function(x){
		var url = $("option:selected", this).attr("title");
		if (url.length) {
			window.location.href = url;
		}
	});
	
	$("#form-find-retailer #featured_site").change(function(x){
		var val = $("#form-find-retailer #featured_site").val();
		
			$.ajax({
				type: "POST",
				url: "ajax_change_state.php",
				data: {val : val},
				
				success: function(data){
					$("#lala").html(data);
					
				}
			});
		
		
	});
	
	
	
});




