var core_url = '/index.php';
var create_itog = 0;
$(document).ready(function(){
	$('div.colors').find('a').click(function(){
		$(this).parent().find('a').removeClass('active');
		$(this).parent().find('input').val($(this).attr('id'));
		$(this).attr('class', 'active');
	});
	$('div.selectDop').find('.upakovka a').click(function(){
		$(this).parent().parent().find('a').removeClass('active');
		$(this).parent().parent().find('input').val($(this).attr('id'));
		$(this).attr('class', 'active');
		LoadForm('create_buket');
	});
	$('div#set_count_items').find('input').blur(function(){
		sum = $(this).val() * $(this).parent().parent().find('div span#price_item').html();
		$(this).parent().parent().find('div#price span').html(sum);
		LoadForm('create_buket')
	});
});

function LoadForm(form) {
	jQuery.ajax({
		url: core_url,
		type: "POST",
		data: jQuery('#'+form).formToArray(true),
		enctype: "multipart/form-data",
		dataType : "json",
		beforeSend: function() {
			return php.beforeSend();
		},
		success: function(data, textStatus) {
			return php.success(data, textStatus);
		},
		error: function (xmlEr, typeEr, except) {
			return php.error(xmlEr, typeEr, except);                  
		},
		complete: function (XMLHttpRequest, textStatus) {
			return php.complete(XMLHttpRequest, textStatus);
		}
	});
	return false;
}

function LoadData(op, module_name, value) {
	jQuery.ajax({
		url: core_url,
		type: "POST",
		data: "op=" + op + "&module_name=" + module_name + "&value=" + value,
		dataType : "json",
		beforeSend: function() {
			return php.beforeSend();
		},
		success: function(data, textStatus) {
			return php.success(data, textStatus);
		},
		error: function (xmlEr, typeEr, except) {
			return php.error(xmlEr, typeEr, except);                  
		},
		complete: function (XMLHttpRequest, textStatus) {
			return php.complete(XMLHttpRequest, textStatus);
		}
	});
	return false;
}

function intval (mixed_var, base) {
    var type = typeof( mixed_var );
 
    if (type === 'boolean') {        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}