/* GMAttributesCalculator.js <?php
#   --------------------------------------------------------------
#   GMAttributesCalculator.js 2011-04-21 gambio
#   Gambio GmbH
#   http://www.gambio.de
#   Copyright (c) 2011 Gambio GmbH
#   Released under the GNU General Public License (Version 2)
#   [http://www.gnu.org/licenses/gpl-2.0.html]
#   --------------------------------------------------------------
?>*/
/*<?php
if($GLOBALS['coo_debugger']->is_enabled('uncompressed_js') == false)
{
?>*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(W).13(0(){$(\'.X\').z(0(){3 a=9 7();a.A($(2).6(\'u\'))});4(g($(".j").6(\'t\'))!=\'h\'||g($(".10").6(\'t\'))!=\'h\'){3 b=9 7();b.8();3 c=i;4($(".j").6(\'m\')==\'E\'){$(".j").w(0(){4(c==i){3 a=9 7();a.8()}})}x{$(".j").w(0(){4(c==i){3 a=9 7();a.8()}}).Y(0(){3 a=9 7();a.8();c=5})}}$("#Q").R(0(){3 a=9 7();a.8();U.V()})});0 7(){2.8=0(){$("#P").B({C:\'q\',v:\'n.o?p=y&l=\'+r,s:0(a){$("#Z").k(a)}});$("#P").B({C:\'q\',v:\'n.o?p=11&l=\'+r,s:0(a){$("#12").k(a)}})};2.A=0(b,c){3 d=[];3 e=i;$(\'#F\'+b+\' .S\').z(0(){4($(2).6(\'m\')==\'E\'){4($(2).6(\'T\')==5){d.G(2.H+\'=\'+I(2.u));4($(2).J(\'K-L\')){e=5}}}x{d.G(2.H+\'=\'+I(2.u));4(g($(2).M(\'N:O\'))!=\'h\'&&$(2).M(\'N:O\').J(\'K-L\')==5){e=5}}});4((e==5||(g(c)!=\'h\'&&c==5))&&(d.D(\'&\').14(/15\\[/)!=-1||g($(\'#F\'+b+\' .16\').6(\'t\'))!=\'h\')){3 f=17.18({19:d.D(\'&\')+\'&1a=\'+b,v:\'n.o?p=y&l=\'+r,m:"q",1b:5,s:0(a){$(\'#1c\'+b).k(a)}}).k}}}',62,75,'function||this|var|if|true|attr|GMAttributesCalculator|calculate|new|||||||typeof|undefined|false|gm_attr_calc_input|html|XTCsid|type|gm_ajax|php|module|POST|gm_session_id|success|class|value|url|click|else|calculate_price|each|calculate_listing|ajaxSubmit|method|join|radio|gm_add_to_cart_|push|name|escape|hasClass|has|price|find|option|selected|cart_quantity|gm_attr_calc_qty|keyup|gm_listing_form|checked|coo_dropdowns_listener|check_combi_status|document|gm_products_id|change|gm_attr_calc_price|graduated_prices_detail_row|calculate_weight|gm_calc_weight|ready|search|id|gm_graduated_prices|jQuery|ajax|data|products_id|async|gm_attr_calc_price_'.split('|'),0,{}))
/*<?php
}
else
{
?>*/
$(document).ready(function(){

		$('.gm_products_id').each(function(){
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate_listing($(this).attr('value'));
		});

		if(typeof($(".gm_attr_calc_input").attr('class')) != 'undefined' || typeof($(".graduated_prices_detail_row").attr('class')) != 'undefined')
		{
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate();

			var t_changed = false;

			if($(".gm_attr_calc_input").attr('type') == 'radio')
			{
				$(".gm_attr_calc_input").click(function()
				{
					if(t_changed == false)
					{
						var attr_calc = new GMAttributesCalculator();
						attr_calc.calculate();
					}
				});
			}
			else
			{
				$(".gm_attr_calc_input").click(function()
				{
					if(t_changed == false)
					{
						var attr_calc = new GMAttributesCalculator();
						attr_calc.calculate();
					}

				}).change(function()
				{ // change-event is needed for Safari 4
					var attr_calc = new GMAttributesCalculator();
					attr_calc.calculate();
					t_changed = true;
				});
			}
		}

		// attributes price and graduated price
		$("#gm_attr_calc_qty").keyup(function(){
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate();

			coo_dropdowns_listener.check_combi_status();
		});
	}
);


function GMAttributesCalculator(){

	this.calculate = function(){
		$("#cart_quantity").ajaxSubmit({
			method: 'POST',
			url: 'gm_ajax.php?module=calculate_price&XTCsid='+gm_session_id,
			success:  function(updated_price) {
				$("#gm_attr_calc_price").html(updated_price);
			}
		});

		$("#cart_quantity").ajaxSubmit({
			method: 'POST',
			url: 'gm_ajax.php?module=calculate_weight&XTCsid='+gm_session_id,
			success:  function(updated_price) {
				$("#gm_calc_weight").html(updated_price);
			}
		});

	}

	this.calculate_listing = function(gm_id, p_force_request){

		var inputs = [];

		var t_has_price = false;

		$('#gm_add_to_cart_' + gm_id + ' .gm_listing_form').each(function()
		{
				if($(this).attr('type') == 'radio')
				{
					if($(this).attr('checked') == true){
						inputs.push(this.name + '=' + escape(this.value));

						if($(this).hasClass('has-price'))
						{
							t_has_price = true;
						}
					}
				}
				else
				{
					inputs.push(this.name + '=' + escape(this.value));
					if(typeof($(this).find('option:selected')) != 'undefined' && $(this).find('option:selected').hasClass('has-price') == true)
					{
						t_has_price = true;
					}
				}
			}
		);

		if((t_has_price == true || (typeof(p_force_request) != 'undefined' && p_force_request == true)) && (inputs.join('&').search(/id\[/) != -1 || typeof($('#gm_add_to_cart_' + gm_id + ' .gm_graduated_prices').attr('class')) != 'undefined'))
		{
			var updated_price = jQuery.ajax({data: 		inputs.join('&') + '&products_id=' + gm_id,
											url: 		'gm_ajax.php?module=calculate_price&XTCsid='+gm_session_id,
											type: 		"POST",
											async:		true,
											success:	function(updated_price){
													$('#gm_attr_calc_price_' + gm_id).html(updated_price);
												}
											}).html;

		}
	}
}
/*<?php
}
?>*/

