﻿$(document).ready(function () {

    var formatedPrice = function ($price) {
        if ($price.html().indexOf('€') > -1) {
            var priceStr = '€' + $price.html().replace('€', '');
            var formatedPriceValue = priceStr;
            formatedPriceValue = formatedPriceValue.replace(' ', '');
            if (formatedPriceValue.indexOf(',') == formatedPriceValue.length - 3) {
                formatedPriceValue = priceStr.replace(',', '.');
            }
            formatedPriceValue = formatedPriceValue.replace(' ', '');
            $price.html(formatedPriceValue);
        }
    };

    $('.price span').each(function () {
        formatedPrice($(this));
    });

    $('.price-large span').each(function () {
        formatedPrice($(this));
    });

    $('.add-basket .float-left strong').each(function () {
        formatedPrice($(this));
    });

    $('.tdprice strong').each(function () {
        formatedPrice($(this));
    });

    $('.tdprice span').each(function () {
        formatedPrice($(this));
    });

    $('.donate-bg').each(function () {
        formatedPrice($(this));
    });

    $('.basket-price span').each(function () {
        formatedPrice($(this));
    });

	/*
    $('.tabsli li h2 a span').each(function () {
        formatedPrice($(this));
        if ($(this).html().indexOf('€') > -1) {
            console.log($(this).html());
            var newVal = $(this).html().replace(' €', '').replace('to', ' to ').replace('or', ' or ');
            console.log(newVal);
            $(this).html(newVal);
        }
    });
	*/

    $('a').each(function () {
        if ($(this).attr('targer') == undefined || $(this).attr('targer').val().indexOf('blank') == -1) {
            //$(this).attr('targer', '_self');
        }
    });

    $('select.ddlCountry').change(function () {
        checkCurrentCountrySelected($(this));
    });

    var hdnIrelandId = $('input[id*="hdnIrelandId"]').val();
    var hdnIrelandPostcode = $('input[id*="hdnIrelandPostcode"]').val();
    var checkCurrentCountrySelected = function ($select) {
        var $postcodeDiv = $select.parents('.panel').find('.postcodeDiv');
        var $postcodeInput = $postcodeDiv.find('input[id*="txtPostCode"]');
        var $selVal = $select.find('option:selected').val();

        if ($selVal == hdnIrelandId || $selVal == "") {
            $postcodeDiv.hide();
            $postcodeInput.val(hdnIrelandPostcode);
        }
        else {
            $postcodeDiv.show();
            if ($postcodeInput.val() == hdnIrelandPostcode) {
                $postcodeInput.val('');
            }
        }
    };

    $('select.ddlCountry').each(function () {
        checkCurrentCountrySelected($(this));
    });
});
