/***
 *
 */
var RRP = {
	get:function(){
		this.form = document.form_calcvenetianmm;
		if(typeof(sale) == 'undefined' || sale.sale == 0){
			selected_slat = this.get_selected_stat();
			var post = {'width':this.form.custom_width.value,'drop':this.form.custom_drop.value,'table':this.get_price_table(), 'price':this.form.price.value, 'sample_id':this.get_by_query_params(),'sample_table':st};
			new Ajax.Request('http://www.blindsuk.net/inc/rrp.php', {
			  parameters:post,
			  onComplete: function(transport){
				  response = transport.responseText;
				  //alert(response);
				  if(response == 'false'){
					  $('rrp').value            = 'N/A';
					  $('saveprice2').value     = 'N/A';
					  $('save_value').innerHTML = '';
					  $('rrp').setStyle({textDecoration:'none'});
				  }
				  
				  if(response.evalJSON()){
					  __price = parseFloat(document.form_calcvenetianmm.price.value);
					  var rrp = transport.responseText.evalJSON();
					  $('rrp').value = parseFloat(__price) < parseFloat(rrp.rrp) ? rrp.rrp : 'N/A';
					  
					  if(__price < rrp.rrp ){
						$('rrp').setStyle({textDecoration:'line-through'});
					  }else{
						$('rrp').setStyle({textDecoration:'none'});
					  }
					  
					  $('saveprice2').value     = parseFloat(__price) < parseFloat(rrp.rrp) ? rrp.save_price : 'N/A';
					  $('save_value').innerHTML = parseFloat(__price) < parseFloat(rrp.rrp) ? rrp.save_precent+'%' : 'N/A';
				  }
			  }
			});
		}else{
			//-----------------------------------------------------------------------------
			if(typeof(this.form.nextday) != 'undefined')
				nextday = nextdayPrice();
			else 
				nextday = 0;
				
			discount = getDiscount();
			raw_price = formatDecimal(
									  GetPrice(venetianmm_arr[findSlat()][7], this.form.custom_width.value, this.form.custom_drop.value) * (1 - discount) , true, 2
									  );
			
			
			$('rrp').value = formatDecimal(parseFloat(raw_price) + (parseFloat(nextday) + parseFloat(bracketPrice())) * (1 - discount), true, 2);
			
			sale_price = formatDecimal(raw_price - (raw_price * sale.sale / 100), true, 2);
			$('saveprice2').value = (raw_price - sale_price).toFixed(2);
			
			sale_price = parseFloat(sale_price) + (parseFloat(bracketPrice()) + parseFloat(nextday)) * (1 - discount);
			this.form.price.value = formatDecimal(sale_price, true, 2);
			$('save_value').innerHTML = round_10(sale.sale)+'%';
			
			//-----------------------------------------------------------------------------
			/*
			 $('rrp').value = this.form.price.value;
			  if(typeof(this.form.nextday) != 'undefined')
			 	nextday = this.form.nextday.value;
			 else 
			 	nextday = 0;
			 this.form.price.value = (this.form.price.value - ( (this.form.price.value - nextday) * sale.sale / 100)).toFixed(2);
			 $('saveprice2').value = ($('rrp').value - this.form.price.value).toFixed(2);
			 $('save_value').innerHTML = round_10(sale.sale)+'%';
			 */
		}
	},
	/**
	* Get selected slat
	*/
	get_selected_stat:function(){
		for(i = 0; i < this.form.slat.length; i++){
			if(this.form.slat[i].checked === true && this.form.slat[i].value !== ''){
					//alert(this.form.slat[i].value);
				return this.form.slat[i].value;
			}
		}
		return false;
	},
	
	get_by_query_params:function(){
	href = document.form_calcvenetianmm.action;
	params = href.toQueryParams();
	return params.venetianmm_sample;
	},

	/**
	* Set save precent
	*/
	set_precent:function(){
		save_price = $('saveprice2').value;
		rrp = $('rrp').value;
		if(save_price > 0 && rrp > 0)
			$('save_value').innerHTML = Math.round(save_price / rrp * 100/10)*10+'%';
		else
		$('save_value').innerHTML = '';
	},
	/**
	* Find price table
	*/
	price_type:function(){
		type = null;
		price_type = {'mm':price};
		Object.keys(price_type).each(function(index){
		  if(price_type[index] != 0 && type == null){
			type = index;
		  }
		});
		//return type;
		return 'mm';
	},
	get_price_table:function(){
		type = this.price_type();
		table_object = eval('pt_'+type);
		slat = this.get_selected_stat();
		//alert(table_object[slat]);
		return table_object[slat];
	}
}
