$(function () {
	
	//show swf	
	swfobject.embedSWF('/stadium_banner.swf', 'bomasport', 760, 170, '8.0.0', false, {}, { menu: false, wmode: 'transparent' });
	
	if (document.getElementById('flashMap') != null) {
	   swfobject.embedSWF('http://www.bomasport.pl/images/stories/mapa.swf', 'flashMap', 522, 200, '8.0.0', false, {}, { menu: false });
	}
	
	//embed tooltips
	$('input, img, a').tooltip({
	   showURL: false
	});
	
});

function checkNumberFormat(object) {
    val = object.value;
    val = val.replace(/,/g, '.');
    val = val.replace(/[^0-9\.]/g, '');
    object.value = val;
} 

function showCustomPrint() {
    $('#customPrintAjaxy').hide(1, function () {
        $('#customPrint').slideDown();
    });
}

function addToBasket() {

    var stock_id = $('#productForm select[name=stock_id]').val();
    var amount   = 1;
    var topInscription    = $('#customPrintingsForm input[name=topInscription]').val();
    var number            = $('#customPrintingsForm input[name=number]').val();
    var bottomInscription = $('#customPrintingsForm input[name=bottomInscription]').val();

    if (stock_id && amount) {

        var data = {
            stock_id: stock_id,
            amount: amount
        };
        
        if (topInscription) {
            data['topInscription'] = topInscription;
        }
        if (number) {
            data['number'] = number;
        }
        if (bottomInscription) {
            data['bottomInscription'] = bottomInscription;
        }

        $.get('/basket_items/ajax_add', data, function (data, textStatus) {
            self.location.href = '/basket_items';
        }, 'text');
        
    }    
    
}

function updateAmount(id) {
    amount = $("#amountField_" + id).val();
    //alert('/basket_items/change_amount/' + id + '/' + amount);
    self.location = '/basket_items/change_amount/' + id + '/' + amount;
}

function showNip() {
    $("#nipAjaxy").hide();
    $("#nip").show();
}
function showDeliveryData() {
    $("#deliveryDataAjaxy").hide();
    $("#deliveryData").show();
}

function isSubscribed(email) {
    if (email.indexOf('@') > 0) {
        $.get('/newsletter_recipients/ajax_is_subscribed/' + email, function (data, textStatus) {
            if (data == '0') {
                $("#addToNewsletterAjaxy").show();
            } else {
                $("#addToNewsletterAjaxy").hide();
            }
        });
    }
}

// by Michael Manning 
jQuery.parseQuery=function(A,B){var C=(typeof A==="string"?A:window.location.search),E={f:function(F){return unescape(F).replace(/\+/g," ")}},B=(typeof A==="object"&&typeof B==="undefined")?A:B,E=jQuery.extend({},E,B),D={};jQuery.each(C.match(/^\??(.*)$/)[1].split("&"),function(F,G){G=G.split("=");G[1]=E.f(G[1]);D[G[0]]=D[G[0]]?((D[G[0]] instanceof Array)?(D[G[0]].push(G[1]),D[G[0]]):[D[G[0]],G[1]]):G[1]});return D};

function askSeller(productId, postData) {
    if (postData.length) {
        postDataArray = $.parseQuery(postData);
        if (postDataArray['data%5BAskSellerForm%5D%5Bproduct_id%5D'] &&
            postDataArray['data%5BAskSellerForm%5D%5Bemail%5D']   &&
            postDataArray['data%5BAskSellerForm%5D%5Bmessage%5D']) {
	        jQuery.get('/products/ask_seller/' + productId, postData, function (html) {
	            container = $('#askSellerContainer');
	            container.html(html);
	        });
        }
    } else {
	    jQuery.get('/products/ask_seller/' + productId, postData, function (html) {
	        container = $('#askSellerContainer');
	        container.html(html);
	        container.fadeIn(function () {
	            $('#AskSellerFormEmail').focus();
	            $('#AskSellerFormEmail').addClass('focus');
	            $('#AskSellerFormEmail, #AskSellerFormMessage').bind('focus', function () {
	                $(this).addClass('focus');
	            });
                $('#AskSellerFormEmail, #AskSellerFormMessage').bind('blur', function () {
                    $(this).removeClass('focus');
                });
	        });
	    });
    }
    return false;
}
