/**
 * @author Ideatronic
 */
	
var SpamtitanForm = {};	
 
 
 SpamtitanForm = function()
 {
 	this.dataTab = false;
 	this.formId = false;
	
	this.selectName = false;
	this.radioName = false;
	this.radioName1 = false;													//new
	
	this.selectIndex = 0;
	this.radioIndex = 0;
	this.radioIndex1 = 0;												//new
	
	this.licencesContentId = false;
	this.subscriptionContentId = false;
	this.totalPriceContentId = false;
	this.discountContentId = false;
	this.productVersionContentId = false;										//new
	this.productVersionDescriptionId = false;									//new
 };

SpamtitanForm.prototype = 
 {
 	getElements:function()
	{
		var $this = this;
		this.licencesContent = $(this.licencesContentId);
		this.subscriptionContent = $(this.subscriptionContentId);
		this.totalPriceContent = $(this.totalPriceContentId);
		this.discountContent = $(this.discountContentId);
		this.productVersionContent = $(this.productVersionContentId);							//new
		this.productVersionDescriptionContent = $$('.productVersDescription');			//new
		this.discountFlag = false;
		
		this.submitButton = $('EnquiryFormButton_Insert');
		this.mainForm = $(this.formId);
		
		this.selectObj = eval('this.mainForm.'+this.selectName);
		this.radioObj = eval('this.mainForm.'+this.radioName);
		this.radioObj1 = eval('this.mainForm.'+this.radioName1);											//new
		
		this.radioIndex = parseInt(this.radioObj[0].value);
		this.radioIndex1 = parseInt(this.radioObj1[0].value);											//new
		this.selectIndex = parseInt(this.selectObj.options[this.selectObj.selectedIndex].value);
		
		this.lastproductVersionIndex = 0;
		
		this.list = $$('.priceinglist');															//new poprawiÄ�
		for(var j=0; j<this.list.length; j++)
		{
			this.list[j].number = j;
			this.list[j].onclick = function(){
				var iter = this.number;
				$this.updatePriveValContent(iter);
			}
		}																							//end new
		this.selectObj.onchange = function()
		{
			$this.updateURL( parseInt(this.options[this.selectedIndex].value),null);
		}
		for(var i=0; i<this.radioObj.length; i++)
		{
			if(i===0)
			{
				this.radioObj[i].onmouseup = function()
				{
					$this.discountFlag = 0;		
					$this.updateURL(null, parseInt(this.value),this.radioIndex1);						//edit	
				}
			}
			if(i==1)
			{
				this.radioObj[i].onmouseup = function()
				{
					$this.discountFlag = 2;
					$this.updateURL(null, parseInt(this.value),this.radioIndex1);						//edit
				}
			}
			if(i==2)
			{
				this.radioObj[i].onmouseup = function()
				{
					$this.discountFlag = 3;
					$this.updateURL(null, parseInt(this.value),this.radioIndex1);						//edit
				}
			}			
		}
		
		for(var i=0; i<this.radioObj1.length; i++)
		{
			if(i===0)
			{
				this.radioObj1[i].onmouseup = function()
				{	
					$this.updatePriveValContent(0);
					$this.updateURL(null,this.radioIndex, parseInt(this.value));						//edit
				}
			}
			if(i==1)
			{
				this.radioObj1[i].onmouseup = function()
				{
					$this.updatePriveValContent(1);
					$this.updateURL(null,this.radioIndex, parseInt(this.value));						//edit
				}
			}
			if(i==2)
			{
				this.radioObj1[i].onmouseup = function()
				{
					$this.updatePriveValContent(2);
					$this.updateURL(null,this.radioIndex, parseInt(this.value));						//edit
				}
			}			
		}
		
		var flag = false;
		
		
		this.radioObj[0].checked = true;	
		this.radioObj1[0].checked = true;	
		this.updateURL(null,null);
		
		
	},
	updatePriveValContent:function(obj){	
		this.productVersionDescriptionContent[this.lastproductVersionIndex].style.display = 'none'; 
		this.lastproductVersionIndex = obj;
		this.productVersionDescriptionContent[obj].style.display = 'block';									
	},
 	updateSummary:function(selectValue, radioValue, radioValue1)
	{
		var licences = this.selectObj.options[this.selectObj.selectedIndex].text;
		var subscription = this.dataTab[selectValue][radioValue][radioValue1][2];					//edit
		var totalPrice = this.dataTab[selectValue][radioValue][radioValue1][1];						//edit
		var productVersion = this.dataTab[selectValue][radioValue][radioValue1][3];					//new
		if(this.discountFlag>0)
			var discount = this.discountFlag*parseFloat((this.dataTab[selectValue][parseInt(this.radioObj[0].value)][radioValue1][1])) - parseFloat(totalPrice); //edit
		
		else 
			var discount = 0;
		this.licencesContent.innerHTML = licences;
		this.subscriptionContent.innerHTML = subscription;
		this.totalPriceContent.innerHTML = totalPrice;
		this.discountContent.innerHTML  = discount;
		this.productVersionContent.innerHTML = productVersion;										//new
	},
	updateURL:function(selectValue, radioValue, radio1Value)
	{
		if(selectValue)
			this.selectIndex = selectValue;
		if(radioValue)
			this.radioIndex = radioValue;
		if(radio1Value)																				//new
			this.radioIndex1 = radio1Value;															//new
		
		var anchor = this.dataTab[this.selectIndex][this.radioIndex][this.radioIndex1][0];			//edit
		
		this.updateSummary(this.selectIndex, this.radioIndex, this.radioIndex1);					//edit
		
		this.submitButton.onclick = function()
		{
			var fakeLink = document.createElement ("a");
		    if (typeof(fakeLink.click) == 'undefined')
		        location.href = anchor;  // sends referrer in FF, not in IE
		    else
		    {
		        fakeLink.href = anchor;
		        document.body.appendChild(fakeLink);
		        fakeLink.click();   // click() method defined in IE only
		    }
			//location.href = anchor;
		}
	}
 }
 

