function RedirectUrl(url) {
    location.href = url;
}

function AddToBasket(lang_key, product_id, quantity, divmsg){

    var send_data = { 'items': '' };
    
    var inputs = jQuery('.txt-units');
    for(i=0;i!=inputs.length;i++) {
        if(i!=0) { send_data['items'] = send_data['items']+'-'; }
        send_data['items'] = send_data['items']+inputs[i].id.substring(5)+'_'+inputs[i].value.replace(',', '.');
        
    }
    jQuery.get('/'+lang_key+'_b/add/'+send_data['items']+'/', function(data) {
        
        jQuery.get('/content/basket/ajax_update.php', function(update) {
            jQuery('#ajaxMiniBasket').html(update);
        });
        
        }, 'html');
    
    
    jQuery('.loader_'+product_id).fadeIn(1000);
    jQuery('#txtloadmsg').html(divmsg);

}

function WishlistRemove(category_id) {
    
    jQuery('.loader_'+category_id).fadeIn(300);
    jQuery('.favIcon_'+category_id).fadeOut(200);
    /* Executes the wishlist delete function*/
    jQuery.get('/content/wishlist/del.php?productid='+category_id, function(data) {

        /* Handles the fadeout's, new picture of checked button and new onclick function */
        jQuery('.loader_'+category_id).fadeOut(300);
        jQuery('.favIcon_'+category_id)[0].src = "/style/graphics/fav-unchecked.png";
        jQuery('.favLink_'+category_id).unbind('click');
        jQuery('#category_'+category_id).unbind('click');
        jQuery('.favLink_'+category_id).bind('click', function(runit){ AddToWishList(category_id); });
        jQuery('.favIcon_'+category_id).fadeIn(1000);
        jQuery('#category_'+category_id).fadeOut(1000);

    }, 'html');
    
}

function RemoveFromWishlist(category_id) {
    
    jQuery('.loader_'+category_id).fadeIn(300);
    jQuery('.favIcon_'+category_id).fadeOut(200);
    /* Executes the wishlist delete function*/
    jQuery.get('/content/wishlist/del.php?productid='+category_id, function(data) {

        /* Handles the fadeout's, new picture of checked button and new onclick function */
        jQuery('.loader_'+category_id).fadeOut(300);
        jQuery('.favIcon_'+category_id)[0].src = "/style/graphics/fav-unchecked.png";
        jQuery('.favLink_'+category_id).unbind('click');
        jQuery('#product_'+category_id).unbind('click');
        jQuery('.favLink_'+category_id).bind('click', function(runit){ AddToWishList(category_id); });
        jQuery('.favIcon_'+category_id).fadeIn(1000);

    }, 'html');
    
}

function AddToWishList(category_id, divmsg){

    jQuery('.loader_'+category_id).fadeIn(300);
    jQuery('.favIcon_'+category_id).fadeOut(200);
    jQuery('#txtloadmsg').html(divmsg);
    jQuery.get('/content/wishlist/add.php?categoryid='+category_id, function(data) {
        jQuery('.loader_'+category_id).fadeOut(300);
        jQuery('.favLink_'+category_id).unbind('click');
        jQuery('.favLink_'+category_id).bind('click', function(runit){ RemoveFromWishlist(category_id); });
        jQuery('.favIcon_'+category_id)[0].src = "/style/graphics/fav-checked.png";
        jQuery('.favIcon_'+category_id).fadeIn(1000);
    }, 'html');
}

function OpenWindow(link)
{
    window.open(link, 'hammerthor_press', 'resizable=1,width=450,height=450');
}

function CheckIfNull(input)
{
    var value;
    if (jQuery('#' + input)[0].value == '') {
        value = ' ';
    } else {
        value = jQuery('#' + input)[0].value;
    }
    return value;
}

function CheckAndAddAntal(){

    var BasketCount = document.getElementById('products').value;
    document.getElementById('AddToBasketButton').href += BasketCount + '/';
}


function ValidateInput(input, error_message, error_div, regex)
{

    var priceregex=regex;
    if (jQuery('#' + input)[0].value.search(priceregex)==-1)
    {
         jQuery('#' + error_div).append(error_message);
         return false;
    } else {
         jQuery('#' + error_div).value = "";
         return true;
    }
}

function SearchRedirect(input)
{
    location.href = "/search_da/" + input + "";
}

function ReplaceNSearch(string, langid, error_msg)
{

    var send_data = { 'items': '' };
    var items = new Array();
    
    newstring = new Array(string);
    newstring.join(";;");
    
    KeyWords = document.getElementById(newstring).value;
    KeyWords = KeyWords.replace(/^\s+|\s+$/g,"");

    var length = KeyWords.length;
    if (length < 3) {
        alert(error_msg);
    } else {
        KeyWords = escape(KeyWords);
        KeyWords = KeyWords.replace(/\//g, '%2F');
        location.href = "/" + langid + "_k/"+ escape(KeyWords) + '/';
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        document.getElementById("menu1").style.display="hidden";
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  document.getElementById("menu1").style.display="hidden";
});

