function requiredDecorator(){
    $('label.required').each(function(i){
        var tmp = $(this).text();
        $(this).html(tmp + '<span class="required">*</span>');
    });
}
function sanatizeString(str){
  var toReplace = {
      '|': '-',
      '!': '-',
      '"': '-',
      '\'': '-',
      '£': '-',
      '%': '-',
      '&': '-',
      '/': '-',
      '(': '-',
      ')': '-',
      '[': '-',
      ']': '-',
      '{': '-',
      '}': '-',
      '=': '-',
      '?': '-',
      '^': '-',
      '*': '-',
      '°': '-',
      '*': '-',
      '§': '-',
      '@': '-',
      '#': '-',
      '_': '-',
      '+': '-',
      ';': '-',
      ':': '-',
      '!': '-',
      '.': '-',
      ',': '-',
      ':': '-',
      ';': '-',
      '<': '-',
      '<': '-',
      ' ': '-',
      'à': 'a',
      'è': 'e',
      'é': 'e',
      'ì': 'i',
      'ò': 'o',
      'ù': 'u',
      'ç': 'c',
  };
  var string = str.replace(/./g, function (match) {
      return toReplace[match] || match;
  });

  return string.toLowerCase().substring(0, 255);
}
function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/in_array
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}
function strip_tags (str, allowed_tags) {
    // Strips HTML and PHP tags from a string  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strip_tags
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Tomasz Wesolowski
    // *     example 1: strip_tags('<p>Kevin</p> <b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
 
    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }
 
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
  return str;
}
function showQuickLoginLoader(sel) {
  var target= $(sel);
  var loader= $('<div id="quickLoginloader"></div>');
  loader.fadeTo("fast", 0.9);
  loader.css({
    width: target.width() + 'px',
    height: target.height() + 'px'
  }).hide().appendTo(target);
  loader.show();
}
function goToProtectedPage(data){
  window.location = data.redirect; // Members Area
}
function showLoginError(msg){
  var html = '<p id="loginError">'+msg+'</p>';
  if ($('#loginError').length > 0){
     $('#loginError').remove();
  }
  
  $('#frm-quick-login').prepend(html);
}


function toIdentify(){
  $.ajax({
        type: "POST",
        timeout:3000,
        url:  $('#frm-quick-login').attr('action') ,
        dataType: 'json',
        data:$('#frm-quick-login :input') ,
        success: function(data){
            if ($('#quickLoginloader').length > 0){
                 $('#quickLoginloader').remove();
            }
            $('#submitQuickLogin').removeAttr("disabled"); 
            if (typeof data.error !== 'undefined'){
               showLoginError(data.error);
               return;
            }
            setTimeout(function(){window.location = data.redirect;}, 1000);
            //alert('ok');
            //alert(data.redirect);
            
        },
        beforeSend: function(){
            showQuickLoginLoader('#quickLogin');
            $('#submitQuickLogin').attr('disabled','disabled');
        },
        error:function(xhr, str, er){
            alert('error status');
            if ($('#quickLoginloader').length > 0){
                 $('#quickLoginloader').remove();
            }
            $('#submitQuickLogin').removeAttr("disabled"); 
            return;
        }
    }); 
}
function xhrLogin(email,password,loginCallback){
  $.ajax({
        type: "POST",
        timeout:3000,
        url:  sBasePath + '/auth/xhr' ,
        cache: false,
        dataType: 'json',
        data: {'email':email,'password':password} ,
        success: function(data){
           loginCallback(data);
        },
        error:function(xhr, str, er){
            alert('error');
            return;
        }
  }); 
}

