// JavaScript Document
var actual = "";

function wishlist(wich) {
	$('#'+wich+'_wishlist').fadeIn();
	$('#wishlist_options').hide();
}

function buyNow(product) {
	actual = $('#options').html();
	$('#options').html( '<img src="/store/images/ajax-loader.gif" />' );
    $('#options').load( '/scart/?action=addProduct&product_id=' + product );
}
function joinGroup(idevent, product) {
	actual = $('#options').html();
	$('#options_event_'+idevent).html('<img src="/store/images/ajax-loader.gif" />');
//	$('#options_event_'+idevent).load("/calendar/controller/participate?event="+idevent);
	jQuery.get("/calendar/controller/participate", {event:idevent}, function (result) {
		if (result == 'LOGIN_EXCEPTION')
			 window.open('/login/index.php?error=NOT_ALLOWED&page=/store/product/'+product, '_self');
		else
			$('#options_event_'+idevent).html(result);
	});
}
function subscribeGroup(obj, idevent) {
	if (obj.checked) {
		jQuery.get("/calendar/controller/confirm_participation.php", {event:idevent, committed:0});
	} else {
		jQuery.get("/calendar/controller/cancel", {id:idevent});
	}
}
function editGroup(idevent) {
	actual = $('#options').html();
	$('#options_event_'+idevent).html('<img src="/store/images/ajax-loader.gif" />');
	$('#options_event_'+idevent).load("/calendar/controller/participate?event="+idevent);
}
function cancelGroup(idevent, product) {
	actual = $('#options').html();
	if (confirm('Are you sure you want to cancel your group commitment?')) {
		$('#options_event_'+idevent).html('<img src="/store/images/ajax-loader.gif" />');
		jQuery.get("/calendar/controller/cancel", {id:idevent}, function (result) {
			window.open('/store/product/'+product, '_self');
		});
	}
}
function back() {
	$('#options').html(actual);
}
function closePopup() {
	$("#top_block").slideUp();
	$('#blank').load('/store/no_popup.php');
}
function showPopup() {
	$("#top_block").slideDown();
}

function priceComparison(id)
{
    var div = $('#price_comparison');
    if (!div.data('busy')) {
	    div.data('busy', true);
	    div.load('/store/price_comparison.php?id=' + id, function(){
	    	div.data('busy', false);
	    });
    }
}

function loadBuyNow(id) {
    var div = $('#buy_now');
    if (!div.data('busy')) {
	    div.data('busy', true);
	    div.load('/store/buy_now_price.php?id=' + id, function(){
	    	div.data('busy', false);
	    });
    }
}


function resize_image(img, width, height) {

	if(navigator.userAgent.toLowerCase().indexOf("msie") == -1) return;
	if(img.width>width && img.width > img.height) {
		img.style.width= width+'px';
	} else if(img.height>height) {
		img.style.height = height+'px';
	}
}
function zoom_image(src) {
	window.open('http://'+location.host+'/store/zoom.php?img='+src, 'zoom_image', 'width=600,height=600,status=no,menubar=no,resizable=no,scrollbars=no,titlebar=no');
}

function update_image(urlthumb, url) {
	$('#product_image').attr("src", urlthumb);	
	$('#product_image').click(function(){zoom_image(url)});
	$('#product_image_zoom').click(function(){zoom_image(url)});
}

function order_invoice(id) {
	window.open('/scart?action=getOrderInfo&id='+id+'&show_groups=1', 'invoice'+id, 'width=600,height=600,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no');
}

function details_purchase(id) {
	window.open('/calendar/purchase_details?id='+id, 'details'+id, 'width=400,height=400,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no');
}

function do_placeholder() {                    

			if ($.browser.safari) {
			   	// very nice
				return;
			}

			$("input[placeholder]").each(function(el) {

				// don't do the input again
			    if ($(this).attr('placeholder_done')) {
					$(this).attr('placeholder_done', true);
				} else {
					// initial value
					if ($(this).val() == "") {
						$(this).val($(this).attr("placeholder")).addClass('placeholder');
					}             

		           	// handle focus event (hide placeholder)
					$(this).focus( function() {
						if ($(this).val() == $(this).attr("placeholder")) {
							$(this).removeClass('placeholder').val("");   
						}
					});

					// handle blur event (show placeholder if empty value)
					$(this).blur( function() {
						if ($(this).val() == "") {
							$(this).addClass('placeholder').val($(this).attr("placeholder"));
						}
					});			
				}
			});

			// don't handle this form again
		    if ($(this.form).attr('placeholder_done')) {
				$(this.form).attr('placeholder_done', true);
			} else {
				$(this.form).submit( function() {
					$("input[placeholder]").each(function(el) {
						if ($(this).val() == $(this).attr("placeholder")) {
							$(this).val("");
						}
					}
				)}); 
			}  	
		}

function updateLocationSelects(Field){
	
}

		// start on page load
		$(do_placeholder);
		
		$(document).ready(function(){
		    $("#refine_boxes_tabs").tabs();
		});