document.onmousedown = function()
{
	for (a in document.links) document.links[a].onfocus = document.links[a].blur;
}

function clearIt(oTxt){
  if (oTxt.value==oTxt.defaultValue){
    oTxt.value = "";
  }
}

function resetTxt(oTxt){
  if (oTxt.value==""){
    oTxt.value = oTxt.defaultValue;
  }
}
function submit_nwl()
{
  $('#nwl_text').load('newsletter.php?nume='+encodeURIComponent($('#nume').val())+'&email='+encodeURIComponent($('#email').val()));
  return false;
}

function is_numeric (mixed_var) {
    if (mixed_var === '') {
        return false;
    }

    return !isNaN(mixed_var * 1);
}

function serialize (mixed_value) {
    var _getType = function (inp) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            mixed_value = this.utf8_encode(mixed_value);
            val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = this.serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += this.serialize(okey) +
                        this.serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
            val = "N";
            break;
    }
    if (type != "object" && type != "array") {
        val += ";";
    }
    return val;
}

function utf8_encode ( argString ) {
    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function base64_encode (data) {
       
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

    if (!data) {
        return data;
    }

    data = this.utf8_encode(data+'');
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch (data.length % 3) {
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

function reset_mesaje()
{
  $('#mesaj_tricou_baieti').html('')
}

function adauga_tricou_baieti()
{
  $('#mesaj_baieti').html('&nbsp;');

  var bucati = $('#bucati_tricou_baieti').val();
  var marime =$('#marime_tricou_baieti').val(); 
  var culoare = $('#culoare_tricou_baieti').val();

  if (!is_numeric(bucati)||bucati<1)
  {
    if (js_lang=='ro')
      $('#mesaj_tricou_baieti').html('<span style=\"color:red;\">Cantitate gresita!</span>');
    else
      $('#mesaj_tricou_baieti').html('<span style=\"color:red;\">Wrong quantity!</span>');
    return false;
  }

  $('#buton_tricou_baieti').hide();
  $('#loader_tricou_baieti').show();
  var date=new Array();
  date['tip'] = 'tricou_baieti';
  date['marime'] = marime;
  date['culoare'] = culoare;
  date['pret'] = 35;
  date['bucati'] = bucati;
  
  $('#cart_div').load('update_cart.php?data='+base64_encode(serialize(date)));
  $('#loader_tricou_baieti').hide();
  $('#buton_tricou_baieti').show();

  if (js_lang=='ro')
    $('#mesaj_tricou_baieti').html('<span style=\"color:#64AAD2;\">Adaugat!</span>');
  else
    $('#mesaj_tricou_baieti').html('<span style=\"color:#64AAD2;\">Added!</span>');
  
  setTimeout ('reset_mesaje()', 1000);
}
