// change according to your settings
jQuery(document).ready(function(){
	if(jQuery('#cf_field_8').attr('name')) {
		jQuery.get('../wp-content/plugins/easy-estimator/easy-estimator-session.php', function(data,status) {jQuery('#cf_field_8').val(data);});
	}
});

// on checkbox clicked
jQuery(document).ready(function(){
	jQuery('#easy_estimator input').filter(':checkbox').click(function(){
		if(jQuery(this).attr('checked') == true)
			jQuery('#easy_estimator_price').text(number_format(parseInt(number_format_reverse(jQuery('#easy_estimator_price').text()))+parseInt(jQuery(this).val())));
		else
			jQuery('#easy_estimator_price').text(number_format(parseInt(number_format_reverse(jQuery('#easy_estimator_price').text()))-parseInt(jQuery(this).val())));
	}).end();
});

// checkbox initialization
jQuery(document).ready(function(){
	jQuery('#easy_estimator input').filter(':checkbox').attr('checked',false).end();
});

// radio clicked
jQuery(document).ready(function(){
	jQuery('#easy_estimator input').filter(':radio').click(function(){
		jQuery('#easy_estimator #'+jQuery(this).attr('name')+'_name').val(jQuery('#easy_estimator #'+jQuery(this).attr('id')+'_name').val());
	});
});

// presets
function checkMarkEasyEstimator(ids) {
	jQuery('#easy_estimator_price').text('0');
	jQuery('#easy_estimator input').filter(':checkbox').attr('checked',false).end();
	jQuery.each(ids,function(){
		jQuery('#easy_estimator #'+this).attr('checked',true);	
		jQuery('#easy_estimator_price').text(number_format(parseInt(number_format_reverse(jQuery('#easy_estimator_price').text()))+parseInt(jQuery('#easy_estimator #'+this).val())));
	});
	return false;	
}

function number_format(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}
function number_format_reverse(str) {
	return new String(str).replace(/,/g,"");
}

