//Mouse position

function init_product_quantities(){
	if (!$('.product_quantity').length)
		return;
	
	$('.product_quantity').change(
		function(){
			if (!$('#PRICE_'+$(this).attr('ID')).length)
				return;
			if (!$('#PRICE_VALUE_'+$(this).attr('ID')).length)
				return;
			if ($('#err_div').length)
				$('#err_div').hide();
			price = $('#PRICE_VALUE_'+$(this).attr('ID')).text();
			$('#PRICE_'+$(this).attr('ID')).text(this.value>0?Number(price * this.value).toFixed(2):Number(price).toFixed(2));
		}
	);
	if (!$('FORM#add2cart').length)
		return;
	
	$('#GIFT_OPTION_SELECT').change(function(){
			$('#ENTER_GIFT_RECIPIENT').attr('disabled', (this.value=='OTHER')?false:true);
			if (this.value=='OTHER')
				$('#alternative_dest').show();
			else
				$('#alternative_dest').hide();
	});
		
	$('FORM#add2cart').submit(function() {
		allow_submit = false;
		for (i=0; i<$('.product_quantity').length; i++){
			if (Number($('.product_quantity').get(i).value).toFixed(0) > 0){
				allow_submit = true;
				break;	
			}
		}
		if (!allow_submit && $('#err_div').length){
			$('#err_div').show();
		}
		
		if (allow_submit)
			$('.gift_options').attr('value', ($('#GIFT_OPTION_SELECT').attr('value') != 'OTHER')?$('#GIFT_OPTION_SELECT').attr('value'):$('#ENTER_GIFT_RECIPIENT').attr('value'));
		return allow_submit;
	});
	
	
}

function init_search_form(){
	if(!$('#search_text').length)
		return;
	if($('#search_text').attr('value')==''){
		$('#search_text').attr('value', 'Enter search text here');
	}
	$('#search_text').focus(function(){ 
		if (this.value == 'Enter search text here') 
			this.value = ''; 
		$(this).css('color', 'black');
	});
	
	$('#top_search_form').submit(function() {
		if (($('#search_text').attr('value') =='Enter search text here') || ($('#search_text').attr('value') =='')){
			$('#search_text').attr('value', 'Enter search text here');
			$('#search_text').css('color', 'red');
			return false;
		}
	});
}

function init_search_form(){
	if(!$('#MAIL').length)
		return;
	if($('#MAIL').attr('value')==''){
		$('#MAIL').attr('value', 'your email address');
	}
	$('#MAIL').focus(function(){ 
		if (this.value == 'your email address') 
			this.value = ''; 
		$(this).css('color', 'black');
	});
	
	$('#main_interface_form_s').submit(function() {
		if (($('#MAIL').attr('value') =='your email address') || ($('#MAIL').attr('value') =='')){
			$('#MAIL').attr('value', 'your email address');
			$('#MAIL').css('color', 'red');
			return false;
		}
	});
}

		
//main jquery hook-up function 
$(document).ready(
	function() {
		//init_left_menu();	
		init_product_quantities();
		init_search_form();
		//init_suscr_form();
	}
);
