function get_states_ajax (country, box_id, fields)
{
	$.ajax ({
		type: "POST",
		url: "/def/get_states_ajax/" + country + "/",
		success: function (msg) {
			resp = eval ('(' + msg + ')');
			if (resp['status'] == 'OK') {
				update_selectbox (resp['data'], box_id, fields);
			}
		}
	});
	return false;
}

function update_selectbox (data, box_id, fields)
{
	if (data.length > 0) {
		var sel = $('#' + box_id)[0];
		sel.options.length = 0;
		for (var i = 0; i < data.length; i ++) {
			sel.options[sel.options.length] = new Option (data[i][fields[0]], data[i][fields[1]]);
		}
	}
}

function object_size (obj)
{
	var k = 0;
	for (var i in obj) {
		k ++;
	}
	return k;
}

function urlencode (str) {
    str = (str + '').toString();
    return encodeURIComponent (str).replace (/!/g, '%21').replace (/'/g, '%27').replace (/\(/g, '%28').replace (/\)/g, '%29').replace (/\*/g, '%2A').replace (/%20/g, '+');
}

function number_format (number, decimals, dec_point, thousands_sep) {
    number = (number + '').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function in_array (needle, haystack) {
    for (key in haystack) {
		if (haystack[key] == needle) {
			return true;
		}
	}
    return false;
}

function checkdate (m, d, y) {
    return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate();
}

function ucfirst (str) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}
