
var total_price = 0;
var total_save  = 0;

var license_count = 1;
var license_temp  = 1;

var license_type  = 0;
var license_time  = 0;
var price_license = 0;

function setparam() {
	
	var x = 0;
	var y = 0;
	var t = 0;
	var d = 0;
	
	if(license_type) {
		x = server_annual;
		y = server_unlimited;
		if(num_price == 1) { x -= dsera;     y -= dseru;     } else
		if(num_price >= 2) { x -= dsera * 2; y -= dseru * 2; }
		if(license_time)   { t = y; d = dseru; } else { t = x; d = dsera; }
	} else {
		x = single_annual;
		y = single_unlimited;
		if(num_price == 1) { x -= dsina;     y -= dsinu;     } else
		if(num_price >= 2) { x -= dsina * 2; y -= dsinu * 2; }
		if(license_time)   { t = y; d = dsinu; } else { t = x; d = dsina; }
	}
	
	if(num_price == 0) { total_save = 0;   } else 
	if(num_price == 1) { total_save = d;   } else
	if(num_price >= 2) { total_save = d*2; }
	
	total_price   = parseInt(t);
	price_license = parseInt(t);
	
	document.getElementById('_annual').innerHTML	= x;
	document.getElementById('_unlimited').innerHTML = y;
	document.getElementById('total').innerHTML 		= total_price;
	document.getElementById('save').innerHTML 		= total_save;
	document.forms.order.totalorder.value 			= total_price;

}

function add_param(name) {
	
	var x = 0;
	var y = 0;
	var t = 0;
	var d = 0;
	var n = 0;
	var s = 0;
	
	eval("document.getElementById('license_').innerHTML+='</div><div id=license_"+license_count+"><div class=license>License of Url: <span class=\"input_url\"><input name=url[] type=text value=http:// maxlength=100 class=inputform /></span> <a href=javascript:void(0); onclick=del_param("+license_count+")>Delete</a></div><div class=\"owner\">Owner of license: <input name=owner[] type=text value=\""+name+"\" maxlength=100 class=inputform_owner /></div><div class=\"liline\"><spacer height=1 width=1 type=block></spacer></div>'");

	if(license_type) {
		x = server_annual;
		y = server_unlimited;
		if(num_price > 0) { x -= dsera; y -= dseru; }
		if(license_time)  { d  = dseru; t  = y - d; } else {  d = dsera; t = x - d; }
	} else {
		x = single_annual;
		y = single_unlimited;
		
		if(num_price > 0) { x -= dsina; y -= dsinu; }
		if(license_time)  { d  = dsinu; t  = y - d; } else { d = dsina; t = x - d; }
	}
	
	if(num_price > 0) { d = d * 2; }

	s  = parseInt(total_save);
	s += parseInt(d);
	
	total_save   = parseInt(s);
	total_price += parseInt(t);
	
	document.getElementById('total').innerHTML = total_price;
	document.getElementById('save').innerHTML  = total_save;
	document.forms.order.totalorder.value 	   = total_price;

	license_count++;
	license_temp++;
	num_price++;
}
function del_param(id) {
	if (id != '') {
		
		var x = 0;
		var y = 0;
		var t = 0;
		
		eval("document.getElementById('license_"+id+"').innerHTML=''");
		
		if(license_type) {
			x = server_annual;
			y = server_unlimited;
			
			if(license_time)  {
				t = y;
				d = dseru;  
				if(num_price == 0) { total_price -= t;         } else
				if(num_price == 1) { total_price -= t - d;     total_save -= d;    num_price--; } else
					               { total_price -= t - d * 2; total_save -= d *2; num_price--; }
			} else {
				t = x;
				d = dsera;  
				if(num_price == 0) { total_price -= t;         } else
				if(num_price == 1) { total_price -= t - d;     total_save -= d;    num_price--; } else
					               { total_price -= t - d * 2; total_save -= d *2; num_price--; }
			}
		} else {
			x = single_annual;
			y = single_unlimited;
			
			if(license_time)  {
				t = y;
				d = dsinu;  
				if(num_price == 0) { total_price -= t;         } else
				if(num_price == 1) { total_price -= t - d;     total_save -= d;    num_price--; } else
					               { total_price -= t - d * 2; total_save -= d *2; num_price--; }
			} else {
				t = x;
				d = dsina;  
				if(num_price == 0) { total_price -= t;         } else
				if(num_price == 1) { total_price -= t - d;     total_save -= d;    num_price--; } else
					               { total_price -= t - d * 2; total_save -= d *2; num_price--; }
			}
		}
		
		license_temp--;

		document.getElementById('total').innerHTML = total_price;
		document.getElementById('save').innerHTML  = total_save;
		document.forms.order.totalorder.value 	   = total_price;
	}
}

function changeTp(n) {
	
	var x = 0;
	var y = 0;
	var t = 0;
	var d = 0;
	var c = 0;
	
	c = license_temp;
	
	if(n) {
		
		license_type = 1;
		
		x = server_annual;
		y = server_unlimited;
		
		if(default_num == 1) { x -= dsera;     y -= dseru;     } else
		if(default_num >= 2) { x -= dsera * 2; y -= dseru * 2; }
		
		if(license_time) {
			t = parseInt(y);
			d = parseInt(dseru); 
		} else {
			t = parseInt(x);
			d = parseInt(dsera);
		}
		
	} else {
		
		license_type = 0;
		
		x = single_annual;
		y = single_unlimited;
		
		if(default_num == 1) { x -= dsina;     y -= dsinu;     } else
		if(default_num >= 2) { x -= dsina * 2; y -= dsinu * 2; }
		
		if(license_time) {
			t = parseInt(y);
			d = parseInt(dsinu);
		} else {
			t = parseInt(x);
			d = parseInt(dsina);
		}
		
	}
	
	if(default_num == 1) { d = d;     } else 
	if(default_num == 2) { d = d * 2; }
	
	if(c == 1) {
		total_price = t;
	} else 
	if(c == 2) {
		total_price = t * 2 - d;
	} else
	if(c > 2) {
		if(default_num == 0) {
			total_price = t + (t - d) + ((t - d*2) * (c - 2));
		}else
		if(default_num == 1) {
			total_price = t + (t - d) + ((t - d) * (c - 2));
		}else{
			total_price = t * c;
		}
	}
	
	if(default_num == 0) {
		if(c == 1) {
			total_save = 0;
		} else
		if(c == 2) {
			total_save = d;
		} else {
			total_save = d + (d * 2* (c - 2));
		}
	} else 
	if(default_num == 1) {
		if(c == 1) {
			total_save = d;
		} else
		if(c == 2) {
			total_save = d + d * 2;
		} else {
			total_save = d + (d * 2) + (d * 2* (c - 2));
		}
	} else
	if(default_num == 2) {
			total_save = d * c;
	}
	
	document.getElementById('save').innerHTML 		= total_save;
	document.getElementById('total').innerHTML 		= total_price;
	document.getElementById('_annual').innerHTML	= x;
	document.getElementById('_unlimited').innerHTML = y;
	document.forms.order.totalorder.value 			= total_price;
}

function changeLs(n) {
	
	var x = 0;
	var y = 0;
	var t = 0;
	var d = 0;
	var c = 0;
	
	c = license_temp;
	
	if(n) {
		license_time = 1;	
	} else {
		license_time = 0;
	}
	
	if( license_type ) {
		x = server_annual;
		y = server_unlimited;
		
		if(default_num == 1) { x -= dsera;     y -= dseru;     } else
		if(default_num >= 2) { x -= dsera * 2; y -= dseru * 2; }
		
		if(license_time) {
			t = parseInt(y);
			d = parseInt(dseru); 
		} else {
			t = parseInt(x);
			d = parseInt(dsera);
		}
	} else {
		x = single_annual;
		y = single_unlimited;
		
		if(default_num == 1) { x -= dsina;     y -= dsinu;     } else
		if(default_num >= 2) { x -= dsina * 2; y -= dsinu * 2; }
		
		if(license_time) {
			t = parseInt(y);
			d = parseInt(dsinu);
		} else {
			t = parseInt(x);
			d = parseInt(dsina);
		}
	}
	
	if(default_num == 1) { d = d;     } else 
	if(default_num == 2) { d = d * 2; }
	
	if(c == 1) {
		total_price = t;
	} else 
	if(c == 2) {
		total_price = t * 2 - d;
	} else
	if(c > 2) {
		if(default_num == 0) {
			total_price = t + (t - d) + ((t - d*2) * (c - 2));
		}else
		if(default_num == 1) {
			total_price = t + (t - d) + ((t - d) * (c - 2));
		}else{
			total_price = t * c;
		}
	}
	
	if(default_num == 0) {
		if(c == 1) {
			total_save = 0;
		} else
		if(c == 2) {
			total_save = d;
		} else {
			total_save = d + (d * 2* (c - 2));
		}
	} else 
	if(default_num == 1) {
		if(c == 1) {
			total_save = d;
		} else
		if(c == 2) {
			total_save = d + d * 2;
		} else {
			total_save = d + (d * 2) + (d * 2* (c - 2));
		}
	} else
	if(default_num == 2) {
			total_save = d * c;
	}
	
	document.getElementById('total').innerHTML 		= total_price;
	document.getElementById('save').innerHTML 		= total_save;

	document.getElementById('_annual').innerHTML	= x;
	document.getElementById('_unlimited').innerHTML = y;
	document.forms.order.totalorder.value 			= total_price;
}

function install_checked() {
	
	var install = document.forms.order.install.checked;
	
	if(install == true) {
		total_price += 0;
	} else {
		total_price -= 0;	
	}
	
	document.getElementById('total').innerHTML 	= total_price;
	document.forms.order.totalorder.value		= total_price;
}

function is_checked() {
	var license = document.getElementById('agree_license').checked;
	var refund = document.getElementById('noback').checked;
	
	if (license && refund) {
		document.getElementById('purchase').disabled=false;
		
		document.getElementById('check').innerHTML = '';
	} else {
		document.getElementById('purchase').disabled=true;
	}
}