var tarif_summ = new Array();
var bonus_limit = 100;
var bonus_step = 100;
var bonus_add = 10;

function init(tarif1,tarif2,tarif3,tarif4,tarif5,tarif6){
	tarif_summ[0] = tarif1;
	tarif_summ[1] = tarif2;
	tarif_summ[2] = tarif3;
	tarif_summ[3] = tarif4;
	tarif_summ[4] = tarif5;
	tarif_summ[5] = tarif6;
}

function hostingDays(usd_curr){
	selectedSumm = document.getElementById("pay_summ").value;
	if (selectedSumm > bonus_limit){
		bonus = Math.round((selectedSumm - bonus_limit)/(bonus_add));
	}else{
		bonus = 0;
	}
	//days bonus
	for (i=0;i!=6;i++){
		document.getElementById("days_bonus_"+i).innerHTML = Math.round(((selectedSumm*1 + bonus*1) / tarif_summ[i]) * 30) + " дней";
		document.getElementById("days_"+i).innerHTML = Math.round((selectedSumm / tarif_summ[i]) * 30) + " дней";
		document.getElementById("bonus_"+i).innerHTML = bonus+" руб";
		document.getElementById("bonus_usd_"+i).innerHTML = "($ "+rndf('%8.1f',(bonus/usd_curr))+")";
		
		if (selectedSumm*1 >= 1500){
			document.getElementById("domen_second_"+i).src="/images/check_blue.gif";
			document.getElementById("search_reg_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("domen_second_"+i).src="/images/black_line_short.gif";
			document.getElementById("search_reg_"+i).src="/images/black_line_short.gif";
		}
		if (selectedSumm*1 >= 5000){
			document.getElementById("domen_second_two_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("domen_second_two_"+i).src="/images/black_line_short.gif";
		}
		if (selectedSumm*1 >= 6000){
			document.getElementById("promo_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("promo_"+i).src="/images/black_line_short.gif";
		}
	}
	
	if (document.form_2) document.form_2.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_3) document.form_3.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_4) document.form_4.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_5) document.form_5.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_6) document.form_6.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_7) document.form_7.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_8) document.form_8.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_9) document.form_9.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_10) document.form_10.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_11) document.form_11.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_12) document.form_12.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_13) document.form_13.by_summ.value = document.summ_selector.pay_summ.value;
	if (document.form_14) document.form_14.by_summ.value = document.summ_selector.pay_summ.value;
}

function hostingPeriod(usd_curr){
	selectedPeriod = document.getElementById("pay_period").value;	
	sums = new Array();
	for (i=0;i!=6;i++){
		
		/*sums[i] = (selectedPeriod/30)*tarif_summ[i];
		if (sums[i] > bonus_limit){
			bonus = (sums[i] - bonus_limit)/bonus_step*bonus_add;
		}else{
			bonus = 0;
		}*/
		document.getElementById("summ_clean_"+i).innerHTML = (selectedPeriod/30)*tarif_summ[i]+" руб";
		document.getElementById("summ_clean_usd_"+i).innerHTML = "($ "+rndf('%8.1f',(((selectedPeriod/30)*tarif_summ[i])/usd_curr))+")";
		
		if (((selectedPeriod / 30)*tarif_summ[i]) > bonus_limit){
			sums[i] = Math.round(((selectedPeriod*tarif_summ[i]*bonus_add+30*bonus_limit)/30)*1/(bonus_add+1));
			bonus = ((selectedPeriod / 30)*tarif_summ[i]) - sums[i];
		}else{
			sums[i] = (selectedPeriod / 30)*tarif_summ[i];
			bonus = 0;
		}
		document.getElementById("bonus_"+i).innerHTML = bonus+" руб";
		document.getElementById("bonus_usd_"+i).innerHTML = "($ "+rndf('%8.1f',(bonus/usd_curr))+")";
		document.getElementById("summ_"+i).innerHTML = sums[i]*1+" руб";
		document.getElementById("summ_usd_"+i).innerHTML = "($ "+rndf('%8.1f',((sums[i]*1)/usd_curr))+")";
		
		if (sums[i]*1 >= 1500){
			document.getElementById("domen_second_"+i).src="/images/check_blue.gif";
			document.getElementById("search_reg_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("domen_second_"+i).src="/images/black_line_short.gif";
			document.getElementById("search_reg_"+i).src="/images/black_line_short.gif";
		}
		if (sums[i]*1 >= 5000){
			document.getElementById("domen_second_two_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("domen_second_two_"+i).src="/images/black_line_short.gif";
		}
		if (sums[i]*1 >= 6000){
			document.getElementById("promo_"+i).src="/images/check_blue.gif";
		}else{
			document.getElementById("promo_"+i).src="/images/black_line_short.gif";
		}
		//document.getElementById("bonus_days_"+i).innerHTML = Math.round(((sums[i]*1 + bonus*1) / tarif_summ[i]) * 30) + " дней";
		//document.getElementById("bonus_days_"+i).innerHTML = selectedPeriod + " дней";
	}
	
	if (document.form_2) document.form_2.by_period.value = document.period_selector.pay_period.value;
	if (document.form_3) document.form_3.by_period.value = document.period_selector.pay_period.value;
	if (document.form_4) document.form_4.by_period.value = document.period_selector.pay_period.value;
	if (document.form_5) document.form_5.by_period.value = document.period_selector.pay_period.value;
	if (document.form_6) document.form_6.by_period.value = document.period_selector.pay_period.value;
	if (document.form_7) document.form_7.by_period.value = document.period_selector.pay_period.value;
	if (document.form_8) document.form_8.by_period.value = document.period_selector.pay_period.value;
	if (document.form_9) document.form_9.by_period.value = document.period_selector.pay_period.value;
	if (document.form_10) document.form_10.by_period.value = document.period_selector.pay_period.value;
	if (document.form_11) document.form_11.by_period.value = document.period_selector.pay_period.value;
	if (document.form_12) document.form_12.by_period.value = document.period_selector.pay_period.value;
	if (document.form_13) document.form_13.by_period.value = document.period_selector.pay_period.value;
	if (document.form_14) document.form_14.by_period.value = document.period_selector.pay_period.value;
}

function hostingPeriodOrder(usd_curr){
	selectedPeriod = document.getElementById('by_period').value;
	var bonus = 0;
	
	for (i=0;i!=document.order.tarif_plans.length;i++){
		if (document.order.tarif_plans[i].checked){
			tarif_id = document.order.tarif_plans[i].value;
		}
	}

	tarif_summ = document.getElementById("price_"+tarif_id).value;
	sums = (selectedPeriod/30)*tarif_summ;
	document.getElementById("clean_summ").innerHTML = sums+" руб" + " ($"+rndf('%8.1f',(sums/usd_curr))+")"; 		
	/*if (sums > bonus_limit){
		bonus = Math.round((sums - bonus_limit)/bonus_step*bonus_add);
	}*/
	
	if (((selectedPeriod / 30)*tarif_summ) > bonus_limit){
		sums = Math.round(((selectedPeriod*tarif_summ*bonus_add+30*bonus_limit)/30)*1/(bonus_add+1));
		bonus = ((selectedPeriod / 30)*tarif_summ) - sums;
	}else{
		sums = (selectedPeriod / 30)*tarif_summ;
		bonus = 0;
	}
	
	if (window.document.order.domain_status[0].checked){
		document.getElementById("domain_summ").innerHTML = "См. <a href='/domen/' target='_blank'>тарифы</a>";
	}else{
		document.getElementById("domain_summ").innerHTML = "Бесплатно, так как перенос";
	}
	document.getElementById("bonus").innerHTML = bonus+" руб";
	document.getElementById("bonus_usd").innerHTML = " ($"+rndf('%8.1f',(bonus/usd_curr))+")";
	document.getElementById("pay_summ").innerHTML = sums+" руб";
	document.getElementById("pay_summ_usd").innerHTML = " ($"+rndf('%8.1f',((sums)/usd_curr))+")";
	//document.getElementById("full_sum_itogo").innerHTML = sums+" руб" + " ($"+rndf('%8.1f',(sums/usd_curr))+")"; 		
}

function prodlenieOrder(usd_curr,type,tarif){
	if (type == 1) // by summ
	{
		sums = document.getElementById("by_summ").value;
		selectedSumm = sums;
		selectedPeriod = Math.round((sums/tarif)*30);
		
		var bonus = 0;
		//if (sums > bonus_limit){
		//	bonus = Math.round((sums - bonus_limit)/bonus_step*bonus_add);
		//}			
		if (sums > bonus_limit){
			bonus = (sums - bonus_limit)/(bonus_add);
		}
		bonus = rndf('%8.1f',bonus);
		document.getElementById("days").innerHTML = selectedPeriod+" дней";
		document.getElementById("bonus").innerHTML = bonus+" руб ";
		document.getElementById("bonus_usd").innerHTML = " ($"+rndf('%8.1f',(bonus/usd_curr))+")";
		document.getElementById("days_bonuszz").innerHTML = Math.round(((sums*1 + bonus*1) / tarif*1) * 30) + " дней";
		document.getElementById("full_sum_itogo").innerHTML = selectedSumm+" руб" + " ($"+rndf('%8.1f',(selectedSumm/usd_curr))+")"; 			
		
		document.getElementById("pay_summ_hidden").value = selectedSumm;
		document.getElementById("bonus_hidden").value = bonus;
		document.getElementById("days_hidden").value = selectedPeriod;
	}else if (type == 2) //by period
	{
		selectedPeriod = document.getElementById("by_period").value;
		var sums;
		sums = (selectedPeriod/30)*tarif;
		sums = rndf('%8.1f',sums);
		document.getElementById("clean_summ").innerHTML = sums+" руб" + " ($"+rndf('%8.1f',(sums/usd_curr))+")";
		var bonus = 0;
		
		/*if (sums > bonus_limit){
			bonus = Math.round((sums - bonus_limit)/bonus_step*bonus_add);
			sums = sums-bonus;
		}*/
		
		if (((selectedPeriod / 30)*tarif) > bonus_limit){
			sums = ((selectedPeriod*tarif*bonus_add+30*bonus_limit)/30)*1/(bonus_add+1);
			bonus = ((selectedPeriod / 30)*tarif) - sums;
		}else{
			sums = (selectedPeriod / 30)*tarif;
			bonus = 0;
		}
		bonus = rndf('%8.1f',bonus);
		sums = rndf('%8.1f',sums);
		
		document.getElementById("bonus").innerHTML = bonus+" руб";
		document.getElementById("bonus_usd").innerHTML = " ($"+rndf('%8.1f',(bonus/usd_curr))+")";
		document.getElementById("pay_summ").innerHTML = sums+" руб";
		document.getElementById("pay_summ_hidden").value = sums;
		document.getElementById("pay_summ_usd").innerHTML = " ($"+rndf('%8.1f',(sums/usd_curr))+")";
		
		document.getElementById("bonus_hidden").value = bonus;
		document.getElementById("days_hidden").value = selectedPeriod;
		
	}else if (type == 3) //individual
	{
		selectedPeriod = document.getElementById("by_period").value;
		sums = tarif*(selectedPeriod/30);
		sums = rndf('%8.1f',sums);
		document.getElementById("clean_summ").innerHTML = sums+" руб" + " ($"+rndf('%8.1f',(sums/usd_curr))+")";
		
		/*full_sum_bonus = (selectedPeriod / 30)*tarif;
		if (full_sum_bonus > bonus_limit){
			bonus = Math.round((full_sum_bonus - bonus_limit)/bonus_step*bonus_add);
		}else{
			bonus = 0;
		}*/
		
		if (((selectedPeriod / 30)*tarif) > bonus_limit){
			full_sum_bonus = rndf('%8.1f',((selectedPeriod*tarif*bonus_add+30*bonus_limit)/30)*1/(bonus_add+1));
			bonus = ((selectedPeriod / 30)*tarif) - full_sum_bonus;
		}else{
			full_sum_bonus = (selectedPeriod / 30)*tarif;
			bonus = 0;
		}
		
		full_sum_bonus = rndf('%8.1f',full_sum_bonus);
		document.getElementById("pay_summ_hidden").value = rndf('%8.1f',full_sum_bonus);
		document.getElementById("bonus").innerHTML = rndf('%8.1f',bonus)+" руб";
		document.getElementById("bonus_usd").innerHTML = " ($"+rndf('%8.1f',(bonus/usd_curr))+")";
		document.getElementById("pay_summ").innerHTML = full_sum_bonus+" руб";
		document.getElementById("pay_summ_usd").innerHTML = " ($"+rndf('%8.1f',(full_sum_bonus/usd_curr))+")";
		
		
		document.getElementById("bonus_hidden").value = rndf('%8.1f',bonus);
		document.getElementById("days_hidden").value = selectedPeriod;
				
	}else if (type == 4) // vip
	{
		selectedPeriod = document.getElementById("by_period").value;
		period = selectedPeriod;
		if (period >= 180 && period < 360){
			skidka = 0.04;
		}else if (period >= 360 && period < 720){
			skidka = 0.1;
		}else if (period >= 720){
			skidka = 0.18;
		}else{
			skidka=0;
		}
		summ = tarif * (selectedPeriod/30);
		summ = rndf('%8.1f',summ);
		fin_summ = rndf('%8.1f',summ - summ*skidka);
		fin_summ_usd = rndf('%8.1f',fin_summ/usd_curr);
		skidka_text = rndf('%8.1f',summ*skidka);
		skidka_text_usd = rndf('%8.1f',skidka_text/usd_curr);

		document.getElementById("clean_summ").innerHTML = summ + " руб. ($"+rndf('%8.1f',summ/usd_curr)+")";
		document.getElementById("bonus").innerHTML = skidka_text+" руб";
		document.getElementById("bonus_usd").innerHTML = " ($"+skidka_text_usd+")";
		document.getElementById("pay_summ").innerHTML = fin_summ+" руб";
		document.getElementById("pay_summ_usd").innerHTML = " ($"+fin_summ_usd+")";
		
		document.getElementById("pay_summ_hidden").value = fin_summ;
		document.getElementById("bonus_hidden").value = skidka_text;
		document.getElementById("days_hidden").value = selectedPeriod;
	}
}

function hostingPriceOrder(usd_curr){
	selectedSumm = document.getElementById('by_summ').value;
	sums = selectedSumm;
	var bonus = 0;
	
	for (i=0;i!=document.order.tarif_plans.length;i++){
		if (document.order.tarif_plans[i].checked){
			tarif_id = document.order.tarif_plans[i].value;
		}
	}

	tarif_summ = document.getElementById("price_"+tarif_id).value;
	selectedPeriod = Math.round((sums/tarif_summ)*30);
	//sums = Math.round((selectedPeriod/30)*tarif_summ);
		
	//if (sums > bonus_limit){
	//	bonus = Math.round((sums - bonus_limit)/bonus_step*bonus_add);
	//}
	if (sums > bonus_limit){
		bonus = Math.round((sums - bonus_limit)/(bonus_add));
	}

	if (window.document.order.domain_status[0].checked){
		document.getElementById("domain_summ").innerHTML = "См. <a href='/domen/' target='_blank'>тарифы</a>";
	}else{
		document.getElementById("domain_summ").innerHTML = "Бесплатно, так как перенос";
	}
	document.getElementById("days").innerHTML = selectedPeriod+" дней";
	document.getElementById("bonus").innerHTML = bonus+" руб";
	document.getElementById("bonus_usd").innerHTML = " ($"+rndf('%8.1f',(bonus/usd_curr))+")";
	document.getElementById("days_bonuszz").innerHTML = Math.round(((sums*1 + bonus) / tarif_summ) * 30) + " дней";
	//document.getElementById("pay_summ").innerHTML = sums+" руб";
	//document.getElementById("pay_summ_usd").innerHTML = "("+rndf('%8.1f',(sums/usd_curr))+" $)";	
	document.getElementById("full_sum_itogo").innerHTML = selectedSumm+" руб" + " ($"+rndf('%8.1f',(selectedSumm/usd_curr))+")"; 			
}

function hostingIndividOrder(usd_curr){
	var ftpaccount_cost=0.48000000;
	var virtualservers_cost=0.60000000;
	var parking_cost=0.08000000;
	var poddom_cost=0.04000000;
	var db_mysql_cost=0.60000000;
	var email_dif_cost=0.08000000;
	var cgi_cost=0.48000000;
	var php_cost=0.48000000;
	var ssl_cost=0.40000000;
	var ssh_cost=1.00000000;
	var spam_cost=0.32000000;
	var space_cost=0.200000000; //per 10Mb
	
	var selectedMonth = 0;
	
	selectedPeriod = document.getElementById('by_period').value;
	selectedMonth = selectedPeriod*1 / 30;
	
	disk_space = document.getElementById('disk_space').value;
	domains = document.getElementById('domains').value;
	email = document.getElementById('email').value;
	ftp = document.getElementById('ftp').value;
	perl = document.getElementById('perl').value;
	php = document.getElementById('php').value;
	mysql = document.getElementById('mysql').value;
	parking = document.getElementById('parking').value;
	subdomain = document.getElementById('subdomain').value;
	sendmail = document.getElementById('sendmail').value;
	ssl = document.getElementById('ssl').value;
	ssh = document.getElementById('ssh').value;
	spam = document.getElementById('spam').value;

	/*if (disk_space >= 200){
		space_cost = 0.24000000;
	}else if (disk_space >= 100 && disk_space < 200){
		space_cost = 0.32000000;
	}else if (disk_space > 0 && disk_space < 100){
		space_cost = 0.48000000;
	}*/
	
	sum = (disk_space/10) * space_cost;
	sum = sum + domains * virtualservers_cost;
	sum = sum + email * email_dif_cost;
	sum = sum + ftp * ftpaccount_cost;
	sum = sum + perl * cgi_cost;
	sum = sum + php * php_cost;
	sum = sum + mysql * db_mysql_cost;
	sum = sum + parking * parking_cost;
	sum = sum + subdomain * poddom_cost;
	sum = sum + ssl * ssl_cost;
	sum = sum + ssh * ssh_cost;
	sum = sum + spam * spam_cost;
	
	var sendmail_cost=1.00000000;
	if (selectedMonth < 3 || sum < 12){
		sendmail_cost = 0;
		document.getElementById("sendmail").disabled=1;
		document.getElementById("sendmail_hidden").disabled=0;
		sum = sum + sendmail_cost * sendmail;
	}else {
		document.getElementById("sendmail").disabled=0;
		document.getElementById("sendmail_hidden").disabled=1;
		sum = sum + sendmail_cost * sendmail;
	}

	sum_without_skidka = sum * selectedMonth;
	
	full_sum_usd = sum_without_skidka - (sum_without_skidka)*skidka/100;
	var full_sum = 0;
	full_sum = full_sum_usd*usd_curr;
	
	month_sum = sum_without_skidka*usd_curr / selectedMonth;
	month_sum_usd = sum_without_skidka*usd_curr / selectedMonth;

	selectedPeriod = selectedMonth * 30;
	var bonus = 0;
	/*full_sum_bonus = (selectedPeriod / 30)*month_sum;
	if (full_sum_bonus > bonus_limit){
		bonus = Math.round((full_sum_bonus - bonus_limit)/bonus_step*bonus_add);
	}else{
		bonus = 0;
	}
	full_sum_bonus = full_sum_bonus - bonus;*/
	
	if (((selectedPeriod / 30)*month_sum) > bonus_limit){
		full_sum_bonus = Math.round(((selectedPeriod*month_sum*bonus_add+30*bonus_limit)/30)*1/(bonus_add+1));
		bonus = ((selectedPeriod / 30)*month_sum) - full_sum_bonus;
	}else{
		full_sum_bonus = (selectedPeriod / 30)*month_sum;
		bonus = 0;
	}
	if (window.document.order.domain_status[0].checked){
		document.getElementById("domain_summ").innerHTML = "См. <a href='/domen/' target='_blank'>тарифы</a>";
	}else{
		document.getElementById("domain_summ").innerHTML = "Бесплатно, так как перенос";
	}
	document.getElementById("month_pay").innerHTML = rndf('%8.1f',month_sum) + " руб ($"+rndf('%8.1f',month_sum/usd_curr)+")";
	document.getElementById("skidka").innerHTML = rndf('%8.1f',bonus)+" руб ($"+rndf('%8.1f',bonus/usd_curr)+")";
	document.getElementById("clean_summ").innerHTML = rndf('%8.1f',selectedMonth*month_sum)+" руб ($"+rndf('%8.1f',(selectedMonth*month_sum)/usd_curr)+")";
	document.getElementById("full_sum").innerHTML = rndf('%8.1f',full_sum_bonus)+" руб ($"+rndf('%8.1f',full_sum_bonus/usd_curr)+")";
	//document.getElementById("full_sum_itogo").innerHTML = rndf('%8.1f',full_sum_bonus)+" руб ($"+rndf('%8.1f',full_sum_bonus/usd_curr)+")";
	
	document.getElementById("month_pay_hidden").value = rndf('%8.1f',month_sum);
	document.getElementById("skidka_hidden").value = bonus;
	document.getElementById("clean_summ_hidden").value = rndf('%8.1f',selectedMonth*month_sum);
	document.getElementById("full_sum_hidden").value = rndf('%8.1f',full_sum_bonus);
}

function checkUrFiz(){
	if (window.document.order.client_status[0].checked){
		window.document.order.pay_type[0].disabled=true;
		window.document.order.pay_type[1].disabled=false;
		window.document.order.pay_type[1].checked=true;
		window.document.order.pay_type[2].disabled=false;
		window.document.order.pay_type[3].disabled=false;
		window.document.order.pay_type[4].disabled=false;
		window.document.order.pay_type[5].disabled=false;
		window.document.order.pay_type[6].disabled=false;
		window.document.order.pay_type[7].disabled=false;
		window.document.order.pay_type[8].disabled=false;
	}else{
		window.document.order.pay_type[0].disabled=false;
		window.document.order.pay_type[0].checked=true;
		window.document.order.pay_type[1].disabled=true;
		window.document.order.pay_type[2].disabled=true;
		window.document.order.pay_type[3].disabled=true;
		window.document.order.pay_type[4].disabled=true;
		window.document.order.pay_type[5].disabled=true;
		window.document.order.pay_type[6].disabled=true;
		window.document.order.pay_type[7].disabled=true;
		window.document.order.pay_type[8].disabled=true;
	}
}

function checkUrFizDomen(){
	if ((window.document.order.client_status[0].checked && window.document.order.payer[0].checked) || window.document.order.payer[1].checked){
		window.document.order.pay_type[0].disabled=true;
		window.document.order.pay_type[1].disabled=false;
		window.document.order.pay_type[1].checked=true;
		window.document.order.pay_type[2].disabled=false;
		window.document.order.pay_type[3].disabled=false;
		window.document.order.pay_type[4].disabled=false;
		window.document.order.pay_type[5].disabled=false;
		window.document.order.pay_type[6].disabled=false;
		window.document.order.pay_type[7].disabled=false;
		window.document.order.pay_type[8].disabled=false;
	}else{
		window.document.order.pay_type[0].disabled=false;
		window.document.order.pay_type[0].checked=true;
		window.document.order.pay_type[1].disabled=true;
		window.document.order.pay_type[2].disabled=true;
		window.document.order.pay_type[3].disabled=true;
		window.document.order.pay_type[4].disabled=true;
		window.document.order.pay_type[5].disabled=true;
		window.document.order.pay_type[6].disabled=true;
		window.document.order.pay_type[7].disabled=true;
		window.document.order.pay_type[8].disabled=true;
	}
}

function checkUrFizDomenRenew(){
	if (window.document.order.payer[0].checked){
		window.document.order.pay_type[0].disabled=true;
		window.document.order.pay_type[1].disabled=false;
		window.document.order.pay_type[1].checked=true;
		window.document.order.pay_type[2].disabled=false;
		window.document.order.pay_type[3].disabled=false;
		window.document.order.pay_type[4].disabled=false;
		window.document.order.pay_type[5].disabled=false;
		window.document.order.pay_type[6].disabled=false;
		window.document.order.pay_type[7].disabled=false;
		window.document.order.pay_type[8].disabled=false;
	}else if (window.document.order.payer[1].checked){
		window.document.order.pay_type[0].disabled=false;
		window.document.order.pay_type[0].checked=true
		window.document.order.pay_type[1].disabled=true;
		window.document.order.pay_type[2].disabled=true;
		window.document.order.pay_type[3].disabled=true;
		window.document.order.pay_type[4].disabled=true;
		window.document.order.pay_type[5].disabled=true;
		window.document.order.pay_type[6].disabled=true;
		window.document.order.pay_type[7].disabled=true;
		window.document.order.pay_type[8].disabled=true;
	}
}

function vip_order(usd_curr,flag){
	var summ = document.getElementById("vip_summ").value;
	var summ_usd = document.getElementById("vip_summ_usd").value;
	var period = document.getElementById("vip_period").value;
	var skidka = 0;
	if (flag && window.document.order.vip_tarif[1].checked){
		summ_usd = rndf('%8.1f',summ/usd_curr);
		document.getElementById("vip_summ_usd").value = summ_usd;
	}else if (!flag && window.document.order.vip_tarif[1].checked){
		summ = summ_usd * usd_curr;
		document.getElementById("vip_summ").value = summ;
	}else{
		if (document.getElementById('vip_usluga').value == "vip_mail"){
			summ = 790;
			summ_usd = rndf('%8.1f',summ/usd_curr);
		}else{
			summ = 1450;
			summ_usd = rndf('%8.1f',summ/usd_curr);
		}
	}
	
	if (period >= 180 && period < 360){
		skidka = 0.04;
	}else if (period >= 360 && period < 720){
		skidka = 0.1;
	}else if (period >= 720){
		skidka = 0.18;
	}else{
		skidka=0;
	}
	
	document.getElementById("month_summ_h").value = summ;
	document.getElementById("skidka_h").value = skidka*100;
	document.getElementById("additional").value="";
	
	summ = rndf('%8.1f',summ * (period/30));
	
	fin_summ = rndf('%8.1f',summ - summ*skidka);
	fin_summ_usd = rndf('%8.1f',fin_summ/usd_curr);
	skidka_text = rndf('%8.1f',summ*skidka);
	skidka_text_usd = rndf('%8.1f',skidka_text/usd_curr);
	
	document.getElementById("skidka").innerHTML = skidka_text+" руб.";
	//document.getElementById("skidka_usd").innerHTML = " ($"+skidka_text_usd+")";
	document.getElementById("clean_summ").innerHTML = summ + " руб.";
	document.getElementById("pay_summ").innerHTML = fin_summ + " руб.";
	//document.getElementById("pay_summ_usd").innerHTML = " ($"+fin_summ_usd + ")";
	
	if (document.getElementById("vip_usluga").value == "vip_mail"){
		document.getElementById("setup").innerHTML = "500 руб.";
		document.getElementById("additional").value=500;
		document.getElementById("mail_tarif").style.display='block';
		document.getElementById("host_tarif").style.display='none';
		document.getElementById("standart_tarif_mail").disabled=0;
		document.getElementById("standart_tarif_host").disabled=1;
		document.getElementById("what_pay").innerHTML = "VIP-почту";
	}else{
		document.getElementById("setup").innerHTML = "0 руб до конца октября";
		document.getElementById("mail_tarif").style.display='none';
		document.getElementById("host_tarif").style.display='block';
		document.getElementById("standart_tarif_mail").disabled=1;
		document.getElementById("standart_tarif_host").disabled=0;
		document.getElementById("what_pay").innerHTML = "VIP-хостинг";
	}
	if (window.document.order.vip_tarif[1].checked){
		document.getElementById("standart_tarif_mail").disabled=1;
		document.getElementById("standart_tarif_host").disabled=1;
		document.getElementById("vip_summ").disabled=0;
		document.getElementById("vip_summ_usd").disabled=0;
	}else{
		document.getElementById("standart_tarif_mail").disabled=0;
		document.getElementById("standart_tarif_host").disabled=0;
		document.getElementById("vip_summ").disabled=1;
		document.getElementById("vip_summ_usd").disabled=1;
	}
	if (window.document.order.domain_status[0].checked && summ < 3000){
		document.getElementById("domain_summ").innerHTML = "См. <a href='/domen/' target='_blank'>тарифы</a>";
	}else if (summ > 3000){
		document.getElementById("domain_summ").innerHTML = "Бесплатно";
	}else{
		document.getElementById("domain_summ").innerHTML = "Бесплатно, так как перенос";
	}
}

function domain_order(usd_curr,flag){
	if (document.getElementById("without_hosting").checked == 0 || flag == false){
		window.document.order.only_domen[0].disabled=1;
		window.document.order.only_domen[1].disabled=1;
		window.document.order.client_status[0].disabled=1;
		window.document.order.client_status[1].disabled=1;
		window.document.order.payer[0].disabled=1;
		window.document.order.payer[1].disabled=1;
		window.document.order.payer[2].disabled=1;
		window.document.order.pay_type[0].disabled=1;
		window.document.order.pay_type[1].disabled=1;
		window.document.order.pay_type[2].disabled=1;
		window.document.order.pay_type[3].disabled=1;
		window.document.order.pay_type[4].disabled=1;
		window.document.order.pay_type[5].disabled=1;
		window.document.order.pay_type[6].disabled=1;
		window.document.order.pay_type[7].disabled=1;
		window.document.order.pay_type[8].disabled=1;
		document.getElementById("domen_period").disabled=1;
		document.getElementById("btn_step2").disabled=1;
	}else{
		window.document.order.only_domen[0].disabled=0;
		window.document.order.only_domen[1].disabled=0;
		window.document.order.client_status[0].disabled=0;
		window.document.order.client_status[1].disabled=0;
		window.document.order.payer[0].disabled=0;
		window.document.order.payer[1].disabled=0;
		window.document.order.payer[2].disabled=0;
		window.document.order.pay_type[0].disabled=0;
		window.document.order.pay_type[1].disabled=0;
		window.document.order.pay_type[2].disabled=0;
		window.document.order.pay_type[3].disabled=0;
		window.document.order.pay_type[4].disabled=0;
		window.document.order.pay_type[5].disabled=0;
		window.document.order.pay_type[6].disabled=0;
		window.document.order.pay_type[7].disabled=0;
		window.document.order.pay_type[8].disabled=0;
		document.getElementById("domen_period").disabled=0;
		document.getElementById("btn_step2").disabled=0;
		checkUrFiz();
	}
}

function rndf()
{
    if (!arguments || arguments.length < 1 || !RegExp)
    {
        return;
    }
    var str = arguments[0];
    var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
    var a = b = [], numSubstitutions = 0, numMatches = 0;
    while (a = re.exec(str))
    {
        var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
        var pPrecision = a[5], pType = a[6], rightPart = a[7];
        //alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
        numMatches++;
        if (pType == '%')
        {
            subst = '%';
        }
        else
        {
            numSubstitutions++;
            if (numSubstitutions >= arguments.length)
            {
                alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
            }
            var param = arguments[numSubstitutions];
            var pad = '';
                   if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
              else if (pPad) pad = pPad;
            var justifyRight = true;
                   if (pJustify && pJustify === "-") justifyRight = false;
            var minLength = -1;
                   if (pMinLength) minLength = parseInt(pMinLength);
            var precision = -1;
                   if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
            var subst = param;
                   if (pType == 'b') subst = parseInt(param).toString(2);
              else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
              else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
              else if (pType == 'u') subst = Math.abs(param);
              else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
              else if (pType == 'o') subst = parseInt(param).toString(8);
              else if (pType == 's') subst = param;
              else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
              else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
        }
        str = leftpart + subst + rightPart;
    }
    return str;
}


function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}

function setCookie (name, value, expires, path, domain, secure) {
     expires = ""; 
	 document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function setMenuArr(){
	if (getCookie("raznoe") == "show")
		document.getElementById("raznoe").style.display='block';
	else
		document.getElementById("raznoe").style.display='none';
		
	if (getCookie("drugie") == "show")
		document.getElementById("drugie").style.display='block';
	else
		document.getElementById("drugie").style.display='none';
		
	if (getCookie("hosting") == "show")
		document.getElementById("hosting").style.display='block';
	else
		document.getElementById("hosting").style.display='none';

	if (getCookie("domen") == "show")
		document.getElementById("domen").style.display='block';
	else
		document.getElementById("domen").style.display='none';
		
	if (getCookie("company") == "show")
		document.getElementById("company").style.display='block';
	else
		document.getElementById("company").style.display='none';
		
	if (getCookie("polezno") == "show")
		document.getElementById("polezno").style.display='block';
	else
		document.getElementById("polezno").style.display='none';
	
	if (getCookie("polezno") == "region")
		document.getElementById("polezno").style.display='block';
	else
		document.getElementById("polezno").style.display='none';
}

function swapPart(id){
	if (id=="show_all"){
		setCookie("showall","block","Mon, 01-Jan-2001 00:00:00 GMT");
		document.getElementById("raznoe").style.display='block';
		document.getElementById("raznoe_cell").style.background="url('/images/menu_open.gif')";
		setCookie("raznoe","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("drugie").style.display='block';
		document.getElementById("drugie_cell").style.background="url('/images/menu_open.gif')";
		setCookie("drugie","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("hosting").style.display='block';
		document.getElementById("hosting_cell").style.background="url('/images/menu_open.gif')";
		setCookie("hosting","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("domen").style.display='block';
		document.getElementById("domen_cell").style.background="url('/images/menu_open.gif')";
		setCookie("domen","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("company").style.display='block';
		document.getElementById("company_cell").style.background="url('/images/menu_open.gif')";
		setCookie("company","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("polezno").style.display='block';
		document.getElementById("polezno_cell").style.background="url('/images/menu_open.gif')";
		setCookie("polezno","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("region").style.display='block';
		document.getElementById("region_cell").style.background="url('/images/menu_open.gif')";
		setCookie("region","block","Mon, 01-Jan-2001 00:00:00 GMT","/");
		return;
	}else if (id == "hide_all"){
		setCookie("showall","none","Mon, 01-Jan-2001 00:00:00 GMT");
		document.getElementById("raznoe").style.display='none';
		document.getElementById("raznoe_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("raznoe","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("drugie").style.display='none';
		document.getElementById("drugie_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("drugie","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("hosting").style.display='none';
		document.getElementById("hosting_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("hosting","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("domen").style.display='none';
		document.getElementById("domen_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("domen","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("company").style.display='none';
		document.getElementById("company_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("company","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("polezno").style.display='none';
		document.getElementById("polezno_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("polezno","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		document.getElementById("region").style.display='none';
		document.getElementById("region_cell").style.background="url('/images/menu_normal.gif')";
		setCookie("region","none","Mon, 01-Jan-2001 00:00:00 GMT","/");
		return;
	}
	var elem = document.getElementById(id);
	if (elem.style.display=='block'){
		elem.style.display='none';
		document.getElementById(id+"_cell").style.background="url('/images/menu_normal.gif')";
		setCookie(id,"none","Mon, 01-Jan-2001 00:00:00 GMT","/");
	}else{
		elem.style.display='block';
		document.getElementById(id+"_cell").style.background="url('/images/menu_open.gif')";
		setCookie(id,"show","Mon, 01-Jan-2001 00:00:00 GMT","/");
	}
}

function chgMenu(id,elem,type){
	if (type){
		document.getElementById(id).style.cursor='pointer';
		document.getElementById(id).style.background="url('/images/menu_over.gif')";
	}else{
		if (getCookie(elem) == "show" && document.getElementById(elem).style.display == ""){
			document.getElementById(elem).style.display = "block";
		}
		if (document.getElementById(elem).style.display=='block' || getCookie(elem) == "show"){
			document.getElementById(id).style.background="url('/images/menu_open.gif')";
		}else{
			document.getElementById(id).style.background="url('/images/menu_normal.gif')";
		}
	}
}

function switchIcon(id,direct,active){
	var td1 = document.getElementById("td_"+id);
	var td2 = document.getElementById("tdtd_"+id);
	var img = document.getElementById("img_"+id);
	var link = document.getElementById("link_"+id);
	
	if (direct){
		td1.style.backgroundColor="#ffffff";
		td2.style.backgroundColor="#ffffff";
		img.src="/images/menu_men_pressed.gif";
		if (link.className != "part_navi_mark"){
			link.className = "part_navi_active";
		}else{
			link.className = "part_navi_mark_active";
		}
	}else{
		td1.style.backgroundColor="";
		td2.style.backgroundColor="";
		img.src="/images/menu_men_unpressed.gif";
		if (link.className != "part_navi_mark_active"){
			link.className = "part_navi";
		}else{
			link.className = "part_navi_mark";
		}
	}
}

function switchMainParts(id,type){
	if (id == "default"){
		//alert('h');
		document.getElementById("virtual").style.display="block";
		document.getElementById("virtual_img").src='/images/arrow_selected.gif';
		return;
	}
	document.getElementById("virtual").style.display="none";
	document.getElementById("virtual_img").src='/images/arrow_main.gif';
	document.getElementById("individual").style.display="none";
	document.getElementById("individual_img").src='/images/arrow_main.gif';
	//document.getElementById("mail").style.display="none";
	//document.getElementById("mail_img").src='/images/arrow_main.gif';
	document.getElementById("vip_hosting").style.display="none";
	document.getElementById("vip_hosting_img").src='/images/arrow_main.gif';
	document.getElementById("vip_mail").style.display="none";
	document.getElementById("vip_mail_img").src='/images/arrow_main.gif';
	document.getElementById("domain_div").style.display="none";
	document.getElementById("domain_div_img").src='/images/arrow_main.gif';
	document.getElementById("servers").style.display="none";
	document.getElementById("servers_img").src='/images/arrow_main.gif';
	document.getElementById("site").style.display="none";
	document.getElementById("site_img").src='/images/arrow_main.gif';
	if (type){
		document.getElementById(id).style.display = "block";
		document.getElementById(id+"_img").src='/images/arrow_selected.gif';
	}/*else{
		document.getElementById(id).style.display = "none";
		document.getElementById(id+"_img").src='/images/arrow_main.gif';
	}*/
}

function upperDivs(){
	if (navigator.appName == "Netscape"){
		document.getElementById("label_1").style.top = "102px";
		document.getElementById("label_2").style.top = "130px";
		document.getElementById("label_3").style.top = "41px";
		document.getElementById("label_4").style.top = "55px";
		document.getElementById("label_5").style.top = "81px";
	}
}

// Ajax functions

function showWhois(domain,tld){
	main_div = document.getElementById("whois_main_div");
	msg_div = document.getElementById("whois_msg_div");
	main_div.style.marginLeft = '20%';
	main_div.style.marginRight = '35%';
	main_div.style.top = 200 + document.body.scrollTop;
	main_div.style.display = 'block';
	msg_div.style.display = 'block';
	msg_div.style.height = "";
	main_div.style.height = "";
	//document.getElementById("whois_msg_div").style.display = 'none';
	//document.getElementById("pre_loader").style.display='block';
	processWhoisRequest(domain,tld);
}

function closeWhois(){
	main_div = document.getElementById("whois_main_div");
	msg_div = document.getElementById("whois_msg_div");
	main_div.style.marginLeft = '';
	main_div.style.marginRight = '';
	main_div.style.display = 'none';
	msg_div.style.display = 'none';
	main_div.style.top = 0;
	document.getElementById("whois_msg_div").innerHTML = "";
	document.getElementById("whois_msg_div").style.display = 'none';
	document.getElementById("whois_msg_div").innerHTML = "<div id='pre_loader'>";
	document.getElementById("whois_msg_div").innerHTML += "<br><br><center><span class='text' style='padding-top:20px;color:#000000;font-weight:bold'>Подождите, загружаются данные..</span><br><br>";
	document.getElementById("whois_msg_div").innerHTML += "<span style='padding-top:20px;'><img src='/images/loading_progress_bar.gif' border=0></span></center>";
	document.getElementById("whois_msg_div").innerHTML += "<br><br>";
	document.getElementById("whois_msg_div").innerHTML += "</div>";
	document.getElementById("debug").innerHTML = "";
}

function processWhoisRequest(domain,tld){
	JsHttpRequest.query(
	    '/ajax.php', // backend
	    {
	        // pass a text value 
	        'domain': domain,
	        'tld': tld,  
	        'req_type': whois
	    },
	    // Function is called when an answer arrives. 
	    function(result, errors) {
	        // Write the answer.
	        document.getElementById("debug").innerHTML = errors; 
	        //document.getElementById("result_review_dv").innerHTML = result["str"];
	        document.getElementById("whois_msg_div").innerHTML = "";
	        document.getElementById("whois_msg_div").innerHTML = result["whois"];
	        document.getElementById("whois_msg_div").innerHTML += "<center><a href='#' onclick='closeWhois();return false;' style='color:red'>Закрыть окно</a></center><br><br>";
	        document.getElementById("whois_msg_div").style.display='block';
	        //document.getElementById("pre_loader").style.display='none';
	        //document.getElementById("whois_result").style.display='block';    
	        //document.getElementById("debug").style.display='block';               
	    },
	    false  // do not disable caching
	); 
}

function detectCode(event){
	var e = (window.event) ? window.event : event;
	if (e.keyCode == 13){
		showWhois(document.getElementById('domain_up').value,document.getElementById('tld_up').value);return false;document.getElementById('whois').submit();
	}
} 
