/***************************************
*	Global Site Wide JQuery Functions
**/

function basketPopup() {
	
	if($("#flashBasket").length>0) {
		if(window.location.href.match("added=1")!==null){
			$("#addToBasketWindow").show();
		}
	}
}

$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

$(function() {
	//ie6 top nav menu
	if ($.browser.version<7 && $.browser.msie) {
		$("#nav li").each( function() {
			$(this).bind("mouseover", function() {
				$(this).addClass("sfhover");							   
			}).bind("mouseout", function() {
				$(this).removeClass("sfhover");							   
			});
		});
	}
});

$(function(){
	
	$("#siteSearch, #emailInput").search();
	$("#addToBasketWindow .continue a,.close").bind("click", function() { 
		$("#addToBasketWindow").fadeOut("slow");
	});
	//search form brand/cat jumper
	$("#sBrands,#sCategory").bind("change", function() {
		window.location = '/'+this.value;									 
	});
	
	$("#editDelCon > input, #editDelCon > select").bind("keypress", function(e) {
		if (e.keyCode == 13) {
			var x = processEditDelivery();
			if(x == true) {
				return false;	
			}
		}
	});
	
	$('#editDelCon > #btnUpdate').bind('click', function() {
		var x = processEditDelivery();
		if(x == true) {
			return false;	
		}
	});
	
});

function processEditDelivery() {
	var is_errors = false;
	$('#editDelCon input').css('border','none');
	
	if(	$.trim($('#editDelCon #title').attr('value')).length == 0 ) {
		$('#editDelCon #title').css({'border':'1px solid #9F0000','padding':'5px 2px 2px 5px'});
		is_errors=true;
	}
	if(	$.trim($('#editDelCon #firstName').attr('value')).length == 0 ) {
		$('#editDelCon #firstName').css({'border':'1px solid #9F0000','padding':'5px 2px 2px 5px'});
		is_errors=true;
	}
	if(	$.trim($('#editDelCon #lastName').attr('value')).length == 0 ) {
		$('#editDelCon #lastName').css({'border':'1px solid #9F0000','padding':'5px 2px 2px 5px'});
		is_errors=true;
	}
	if(	$.trim($('#editDelCon #add_1').attr('value')).length == 0 ) {
		$('#editDelCon #add_1').css({'border':'1px solid #9F0000','padding':'5px 2px 2px 5px'});
		is_errors=true;
	}
	if(	$.trim($('#editDelCon #town').attr('value')).length == 0 ) {
		$('#editDelCon #town').css({'border':'1px solid #9F0000','padding':'5px 2px 2px 5px'});
		is_errors=true;
	}
	return is_errors;
}


function incBasket(elm, basket) {

	if($(elm)) {
		$(elm).val(parseInt($(elm).val())+1);
		if(basket==true) {
			submitDoc('cart');
		}
	}
}
function decBasket(elm, basket, limit) {

	if($(elm)) {
		if(parseInt($(elm).val())>limit) {
			$(elm).val(parseInt($(elm).val())-1);
		}
		if(basket==true) {
			submitDoc('cart');
		}
	}
}


// prod detail/cart tabs
$(function() {
	
	$(".also a").bind("click", function() {
		showTab1();
	});
	
	$(".related a").bind("click", function() {
		showTab2();
	});

	if($("#tab div").length>1) {
		//if we have customers also bought products ... 
		showTab1();
	} else if ($("#tab2 div").length>1) {
		//else if we have related products ...
		showTab2();
	}
	
});

function showTab1() {
	$(".also").addClass("active");
	$(".related").removeClass("active");
	$("#tab2").hide();
	$("#tab").show();
}

function showTab2() {
	$(".related").addClass("active");
	$(".also").removeClass("active");
	$("#tab").hide();
	$("#tab2").show();
}




