var timear=new Array( 0.38,0.57,0.76,0.95,1.14,1.33,1.52,1.71,1.9,2.09,2.28,2.47,2.66,2.85,3.04,3.23,3.42,3.61,3.8,3.99,4.18,4.37,4.56,4.75,4.94,5.13,5.32,5.51,5.7,5.89,6.08,6.27,6.46,6.65,6.84,7.03,7.22,7.41,7.6,7.79,7.98,8.17,8.36,8.55,8.74,8.93,9.12,9.31,9.5,9.69,9.88,10.07,10.26,10.45,10.64,10.83,11.02,11.21,11.4,11.59,11.78,11.97,12.16,12.35,12.54,12.73,12.92,13.11,13.3,13.49,13.68,13.87,14.06,14.25,14.44,14.63,14.82,15.01,15.2);
var costar=new Array( 5.70,9.05,10.40,11.75,12.10,13.45,14.80,15.15,16.50,17.85,18.78,19.13,20.58,21.15,22.82,23.61,24.50,25.49,26.60,27.81,28.14,29.57,30.10,31.75,33.50,35.37,37.34,41.41,44.60,47.89,50.30,55.81,62.42,66.15,69.98,73.93,77.98,82.13,86.40,90.77,95.26,99.85,104.54,109.35,114.26,119.29,124.42,129.65,135.00,140.45,146.02,151.69,157.46,163.35,169.34,175.45,181.66,187.97,194.40,207.84,212.76,218.76,221.84,229.00,238.24,245.56,251.96,262.44,270.00,275.64,285.36,295.16,300.04,305.00,311.04,327.16,330.36,340.64,360.00);

// курс вечно-зеленого президента %)
var kurs = 31;	 

var reput=new Array(
					
//0 Netherwing(Drake)

[[5,8],[5,8],[5,8],[5,8],[5,8]],					

//1 Honor Hold/Thrallmar (Argent Dawn)

[[8,4],[8,4],[8,4],[8,4],[8,4]],

//2 Sha'tar (Cenarion Circle )

[[8,4],[8,4],[8,4],[8,4],[8,4]],

//3 Lower City (Timbermaw Hold)

[[8,4],[8,4],[8,4],[8,4],[8,4]],

//4 Keepers of Time (Alterac Valley)

[[8,4],[8,4],[8,4],[8,4],[8,4]],

//5 Cenarion Expedition (Wintersaber trainers)

[[8,4],[8,4],[8,4],[8,4],[8,4]]);



var reput_amount=new Array(3000, 3000, 6000, 12000, 21000);

/*

В массиве для каждого уровня репутации у каждой фракции используется пара (для 1000 репутации) [стоимость,затраченное время]



Стоимость и сроки набора 1000 репутации:
     
	Netherwing(Drake) -$5 , 8 часов

	Argent Dawn — $8 , 5 часов

	Cenarion Circle — $11 , 6 часов

	Timbermaw Hold — $9, 6 часов

	Alterak Valley - $8, 5 часов

	Wintersaber trainers – 15$, 7 часов				



//0 unfriendly 0-3000

//1 neutral 0-3000

//2 friendly 0-6000

//3 honored 0-12000

//4 revered 0-21000

*/



// Коэффициенты ждя профессий

//1-150

var coef_1 = 1.0071;

var coef_1_st = 0.0575;

//150-225

var coef_2 = 1.0075;

var coef_2_st = 0.25;

//225-300

var coef_3 = 1.0071;

var coef_3_st = 0.4;

//Множитель сложности для каждой профессии

//"Blacksmithing", "Leatherworking", "Engineering", "Alchemy", "Enchanting", "Mining",

//"Herbalism", "Skining", "Tailor","Jewelcrafting"

var prof_hardest=new Array(2, 2, 2, 2, 2, 1, 1, 1,2, 2);

var d=0;
var c=0;
var	rep_d=0;
var	rep_c=0;
var	rep_p=0;


function levelcost()
{
	var days = 0;
	var cost = 0;

	// Стоимость раскачки по уровням
	for (i=document.Keypad.c_from.value; i <= document.Keypad.c_to.value-1; i++) {
		days = days + timear[i-1];
		cost = cost + costar[i-1];
	};

	// Доп. навыки
	if (document.Keypad.profA1.checked) {cost = cost + 500.0;};
    if (document.Keypad.profA2.checked) {cost = cost + 1000.0;};
    if (document.Keypad.profA3.checked) {cost = cost + 1000.0;};
	
	// Золото
	if (document.Keypad.gold_amount.value > 0)
	{
		// Требуемое количество золота
    	k = document.Keypad.gold_amount.options[document.Keypad.gold_amount.selectedIndex].value;

		if (k <= 5)
		{
			rub = 180;
		} else 
		if (k <= 10)
		{
			rub = 170;
		} else
		if (k <= 15)
		{
			rub = 160;
		}else
		{
			rub = 150;
		}
		cost = cost + k * rub ;
	};

	s1=document.Keypad.prof1C.value;
	s2=document.Keypad.prof1To.value;
	pr= document.Keypad.prof1.options[document.Keypad.prof1.selectedIndex].value;
 	if (pr>4 && pr<8) {
	 costx=(document.Keypad.prof1To.value - document.Keypad.prof1C.value)*1000/450;
 	 if (costx>0) {cost = cost + costx;	 days = days + (s2-s1)*0.1;}
	}
	else if (pr!=-1) {
	 if (s2>450) {s2=450};
	 if (s1<s2) {
        	if (s2<150) { costx = (s2-s1) * 250/150;}
		else if (s2<300) { 
			if (s1>=150) { costx = (s2-s1) * 500/150;}
			else { costx= (150-s1) * 250/150 +(s2-150) * 500/150;}
			}
		else if (s2<=450) {
			if (s1>=300){ costx = (s2-s1) * 750/150;}
			else if (s1>=150) { costx= (s2-150) * 500/150 +(s2-300) * 750/150;}
				else { costx= 500 +(150-s1) * 500/150 +(s2-300) * 750/150;}
			}
		 days = days + (s2-s1)*0.1; cost=cost+costx;
	 }
	}
	
	 s1=document.Keypad.prof2C.value;
	 s2=document.Keypad.prof2To.value;
	pr= document.Keypad.prof2.options[document.Keypad.prof2.selectedIndex].value;
 	if (pr>4 && pr<8) {
	 costx=(document.Keypad.prof2To.value - document.Keypad.prof2C.value)*1000/450;
 	 if (costx>0) {cost=cost+costx;	 d = d+ (s2-s1)*0.1;}
	}
	else if (pr!=-1) {
	 if (s2>450) {s2=450};
	 if (s1<s2) {
        	      	if (s2<150) { costx = (s2-s1) * 250/150;}
		else if (s2<300) { 
			if (s1>=150) { cost = (s2-s1) * 500/150;}
			else { costx= (150-s1) * 250/150 +(s2-150) * 500/150;}
			}
		else if (s2<=450) {
			if (s1>=300){ costx = (s2-s1) * 750/150;}
			else if (s1>=150) { cost= (s2-150) * 500/150 +(s2-300) * 750/150;}
				else { costx= 500 +(150-s1) * 500/150 +(s2-300) * 750/150;}
			}
		 d = d+ (s2-s1)*0.1; cost=cost+costx;
	 }
	}

	if (document.Keypad.mount.value==1) {cost=cost+500;}
	if (document.Keypad.mount.value==2) {cost=cost+1000;}
	


	// Ускоренный вариант
	if (document.Keypad.c_speed.value == 3) { days = days * 0.7; cost = cost * 1.4;	};

	// Выводим результат стоимость
	document.Keypad.c_days.value = Math.floor(days/24)+ " Дней " + Math.round(days % 24) + " Часов";
	document.Keypad.cost.value = Math.floor(cost) + " руб";
}

/*
function NumPressed (FKeyPad){

	d=0;
	c=0;

	for (i=FKeyPad.c_from.value; i<=FKeyPad.c_to.value-1;i++) {
		d=d+timear[i-1];
		c=c+costar[i-1];
	};

	if (FKeyPad.profA1.checked) {c=c+500.0;};
    if (FKeyPad.profA2.checked) {c=c+1000.0;};
    if (FKeyPad.profA3.checked) {c=c+1000.0;};
	
	// количество золота
	if (FKeyPad.gold_amount.value > 0)
	{
		// Требуемое количество золота
    	k = FKeyPad.gold_amount.options[FKeyPad.gold_amount.selectedIndex].value;

		if (k <= 5)
		{
			grub = 180;
		} else
		if (k <= 10)
		{
			grub = 170;
		} else
		if (k <= 15)
		{
			grub = 160;
		}else
		{
			grub = 150;
		}
		
		costD = costD + k* grub / kurs; 
		c = c + k * grub ;
	};
		
	s1=FKeyPad.prof1C.value;
	s2=FKeyPad.prof1To.value;
	pr= FKeyPad.prof1.options[FKeyPad.prof1.selectedIndex].value;
 	if (pr>4 && pr<8) {
	 cost=(FKeyPad.prof1To.value-FKeyPad.prof1C.value)*1000/450;
 	 if (cost>0) {c=c+cost;	 d = d+ (s2-s1)*0.1;}
	}
	else if (pr!=-1) {
	 if (s2>450) {s2=450};
	 if (s1<s2) {
        	if (s2<150) { cost = (s2-s1) * 250/150;}
		else if (s2<300) { 
			if (s1>=150) { cost = (s2-s1) * 500/150;}
			else { cost= (150-s1) * 250/150 +(s2-150) * 500/150;}
			}
		else if (s2<=450) {
			if (s1>=300){ cost = (s2-s1) * 750/150;}
			else if (s1>=150) { cost= (s2-150) * 500/150 +(s2-300) * 750/150;}
				else { cost= 500 +(150-s1) * 500/150 +(s2-300) * 750/150;}
			}
		 d = d+ (s2-s1)*0.1; c=c+cost;
	 }
	}
	
	 s1=FKeyPad.prof2C.value;
	 s2=FKeyPad.prof2To.value;
	pr= FKeyPad.prof2.options[FKeyPad.prof2.selectedIndex].value;
 	if (pr>4 && pr<8) {
	 cost=(FKeyPad.prof2To.value-FKeyPad.prof2C.value)*1000/450;
 	 if (cost>0) {c=c+cost;	 d = d+ (s2-s1)*0.1;}
	}
	else if (pr!=-1) {
	 if (s2>450) {s2=450};
	 if (s1<s2) {
        	      	if (s2<150) { cost = (s2-s1) * 250/150;}
		else if (s2<300) { 
			if (s1>=150) { cost = (s2-s1) * 500/150;}
			else { cost= (150-s1) * 250/150 +(s2-150) * 500/150;}
			}
		else if (s2<=450) {
			if (s1>=300){ cost = (s2-s1) * 750/150;}
			else if (s1>=150) { cost= (s2-150) * 500/150 +(s2-300) * 750/150;}
				else { cost= 500 +(150-s1) * 500/150 +(s2-300) * 750/150;}
			}
		 d = d+ (s2-s1)*0.1; c=c+cost;
	 }
	}

	if (FKeyPad.mount.value==1) {c=c+500;}
	if (FKeyPad.mount.value==2) {c=c+1000;}
	


	if (FKeyPad.c_speed.value == 3){d=d*0.7; c=c*1.4};

	FKeyPad.c_days.value = Math.floor(d/24)+ " Дней " + Math.round(d % 24) + " Часов";

	FKeyPad.c_cost.value = Math.floor(c) + " руб";

} */



function Clear (FKeyPad) {

	FKeyPad.c_from.value = 1;


	FKeyPad.c_to.value = 2;

	FKeyPad.c_speed.value = 2;

	FKeyPad.c_days.value = "";

	FKeyPad.c_cost.value = "";

}





function RepPressed (RKeyPad)

{

	rep_d=0;

	rep_c=0;

	rep_p=0;

	if (RKeyPad.rep_will.value<RKeyPad.rep_now.value) {

		RKeyPad.rep_will.value=RKeyPad.rep_now.value;

		RKeyPad.num_rep_will.value=0;

		RKeyPad.num_rep_now.value=0;

	}

	if (reput_amount[RKeyPad.rep_will.value]<Number(RKeyPad.num_rep_will.value)) {

		RKeyPad.num_rep_will.value=reput_amount[RKeyPad.rep_will.value];

	}

	if (RKeyPad.rep_will.value==5) {

		RKeyPad.rep_will.value=4;

		RKeyPad.num_rep_will.value=21000;

	}

	for (i=RKeyPad.rep_now.value; i<=RKeyPad.rep_will.value;i++) {

		if (i==RKeyPad.rep_now.value) {rep_p=rep_p-Number(RKeyPad.num_rep_now.value);}

		if (i<RKeyPad.rep_will.value) rep_p=rep_p+reput_amount[i];

	}

	rep_p=rep_p+Number(RKeyPad.num_rep_will.value);

	rep_c = reput[RKeyPad.rep_faction.value][RKeyPad.rep_will.value][0]*(rep_p/1000);

	rep_d = reput[RKeyPad.rep_faction.value][RKeyPad.rep_will.value][1]*(rep_p/1000);

	RKeyPad.rep_days.value = Math.floor(rep_d/24)+ " Дней " + Math.floor(rep_d % 24) + " Часов";

	RKeyPad.rep_cost.value = Math.floor(rep_c) + " $";

}

function RepClear (RKeyPad)

{

	FKeyPad.rep_faction.value = 1;

	RKeyPad.rep_now.value = 1;

	RKeyPad.rep_will.value = 1;

	RKeyPad.num_rep_will.value = "";

	RKeyPad.num_rep_now.value = "";

}




function ProfPressed (RKeyPad)

{

	prof_c=0;

	pro_start = Number(RKeyPad.pro_start.value);

	pro_stop = Number(RKeyPad.pro_stop.value);

	if ((pro_start<1) || (pro_start>299)) {pro_start=1;}

	if ((pro_stop<2) || (pro_stop>300)) {pro_stop=300;}

//	if (Number(pro_start)<Number(pro_stop)) {

		for (i=pro_start; i<=pro_stop;i++) {

			if (i<=150) {prof_c=prof_c+coef_1_st*Math.pow(coef_1,(i-1));}

			if ((i>150) && (i<226)) {prof_c=prof_c+coef_2_st*Math.pow(coef_2,(i-151));}

			if ((i>225) && (i<=300)) {prof_c=prof_c+coef_3_st*Math.pow(coef_3,(i-226));}

		}

		RKeyPad.pro_cost.value = Math.round(prof_c*prof_hardest[RKeyPad.pro_type.value]) + " $";

//	}



}

function ProfClear (RKeyPad)

{

	FKeyPad.pro_type.value = 1;

	pro_start = 1;

	pro_stop = 1;

}


function select_lev(new_lev) {
document.getElementById('userform').className='level'+new_lev; return false;
}


var type;

// Steel исправление стоимости золота для локаций
function calcwmz() {
	var count = document.Keypad.gold_amount.value;
	if (count == 0)
	{
		document.Keypad.gold_wmz.value = '';
		return;
	}
	if (count > 20)
	{
		document.Keypad.gold_wmz.value = 'цена договорная...';
		return;
	}
	
	// Подземье (альянс, орда):
	if (document.Keypad.gold_servers.value == 'Подземье')
	{
		grub = 181 - count;
	} else
	// Гордунни (альянс)
	if  ((document.Keypad.gold_servers.value == 'Гордунни') && (document.Keypad.faction.value == 'alliance'))
	{
		grub = 172 - count * 2;
	} else
	// Гром (орда, альянс)
	if  (document.Keypad.gold_servers.value == 'Гром')
	{
		grub = 181 - count;
	} else
	// Разувий (Орда, альянс):
	if  (document.Keypad.gold_servers.value == 'Разувий')
	{
		grub = 181 - count;
	} else
	// стандартный рассчет
	{
		grub = 202 - count * 2;
	}
	
	if	((document.Keypad.paytype.value=="WMR") || (document.Keypad.paytype.value=="YMoney") 
		 || (document.Keypad.paytype.value=="Qiwi"))	
	{ 
		// выводим в рублях
		document.Keypad.gold_wmz.value = parseFloat(grub * count).toFixed(2) + " руб"; 
	}
	else 
	{
		// выводим в баксах
		document.Keypad.gold_wmz.value = parseFloat( (grub / kurs) * count).toFixed(2) + " $";
	}

}





function setgoldfaction()
{
	document.Keypad.gold_servers.className = document.Keypad.gold_faction.value;
	document.Keypad.gold_servers.selectedIndex = 0;

	for (var i=0; i < document.Keypad.gold_servers.length; i++)
	{
		document.Keypad.gold_servers[i].disabled=false;
		if ((document.Keypad.gold_servers[i].className=='h' && document.Keypad.gold_servers.className=='alliance' ) || (document.Keypad.gold_servers[i].className=='a' && document.Keypad.gold_servers.className=='horde' )) {document.Keypad.gold_servers[i].disabled=true;}
	}
	calcwmz();
}

function TrySubmit()
{
	if (document.Keypad.primetime.value =="") {alert('Не заполнено поле Когда будете в игре')}
	else {
		if (document.Keypad.name.value =="") {alert('Не заполнено поле Ник')}
		else {
			if (document.Keypad.email.value =="") {alert('Не заполнено поле E-mail')}
			else {
				document.Keypad.submit();
			}
		}
	}	
}


function TrySubmit1()
{
			if (document.Keypad.email.value =="") {alert('Не заполнено поле E-mail')}
			else {
				document.Keypad.submit();
			}
	
}




function calcArenaPrice () {
 var price=0;
 var start=document.Keypad.startArena.value;
 var end=document.Keypad.endArena.value;
 if (end>start){
 if (end==1500) { price=1500}
 if (end==1650) { price=price+1000;
	if (start<1500) { price=price+1500}}
 if (end==1850) {price=price+1500;
  if (start<1650) {price=price+1000}
  if (start<1500) { price=price+1500}}
 if (end==2050) {price=price+1500;
  if (start<1850) {price=price+1500}
  if (start<1650) {price=price+1000}
  if (start<1500) { price=price+1500}}
 if (end==2350) {price=price+1500;
  if (start<2050) {price=price+1500}
  if (start<1850) {price=price+1500}
  if (start<1650) {price=price+1000}
  if (start<1500) { price=price+1500}}
 if (end==3000) {document.Keypad.price.value="договорная"}
 else document.Keypad.price.value=price;
} else document.Keypad.price.value=price;
}

function calcArenaReq() {
 var price=0;
var end=document.Keypad.frostArena.value;
 if (end==1500) { price=200;}
 if (end==1650) { price=300;}
 if (end==1850) { price=400;}
 if (end==2050) { price=500;}
 if (end==2350) { price=750;}
 if (end==3000) { price="Договорная";}
 document.Keypad.priceF.value=price;

}