
	var a_type = [1,1,3,2,2,1,3,3,2,2,2,2,2,3];
    var a_level = [15,15,12,10,8,6,25,26];  //var a_level = [15,15,12,10,8,6,15,25,26];

function f_submit()
{
	
}

function changeCurrency()
{
	var currency = document.qpq.currency.value;
	var usd_total = document.qpq.usd_total.value;

	var new_total = usd_total * a_currency[currency];

	new_total = "" + Math.floor(new_total*100)/100;
	pos = new_total.indexOf(".");
	if (pos<0) 
		new_total = new_total + ".00";
	else 
		if((new_total.length-pos-1)==1) 
			new_total = new_total + "0";

	document.getElementById("price_label_small").innerHTML = new_total;
}
function update_cost()
{
	var period = document.qpq.period;
	var type = a_type[document.qpq.paper_type.value];
	var level = a_level[document.qpq.level.value];
	var level2 = document.qpq.level.value;
	var currency = document.qpq.currency.value;

	var p_num = 0;
	if (period.value==60) p_num=6;
	if (period.value==30) p_num=5;
	if (period.value==14) p_num=4;
	if (period.value==7) p_num=3;
	if (period.value==4) p_num=2;
	if (period.value==2) p_num=1;

	if (level==-1)
		return false;

	var t_num = type-1;
	var page_count = document.qpq.page_count.value;

	total = price[t_num][p_num][level2]*page_count;
	total = "" + Math.floor(total*100)/100;

	pos = total.indexOf(".");
	if (pos<0) 
		total = total + ".00";
	else 
		if((total.length-pos-1)==1) 
			total = total + "0";

	c_total = "" + total * a_currency[currency];
	c_total = "" + Math.floor(c_total*100)/100;
	pos = c_total.indexOf(".");
	if (pos<0) 
		c_total = c_total + ".00";
	else 
		if((c_total.length-pos-1)==1) 
			c_total = c_total + "0";

	document.getElementById("price_label_small").innerHTML = 	c_total;
	document.qpq.usd_total.value=total;
}

function change_total_words()
{
	var pages = document.qpq.page_count.value;
	var level = a_level[document.qpq.level.value];
	var level2 = document.qpq.level.value;
	var period = document.qpq.period.value;

	if (level==-1)
	{
		document.qpq.submit.disabled=true;
		return false;
	}

	total = period*level;
	if (total < pages)
	{
		if (level2 == 0) _level = "High-School Level";
		if (level2 == 1) _level = "College Level";
		if (level2 == 2) _level = "University Level, Bachelor's";
		if (level2 == 3) _level = "University Level, Master's";
		if (level2 == 4) _level = "Specialized Level (Nursing)";
		if (level2 == 5) _level = "PhD level";
		if (level2 == 6) _level = "Editing (Rewriting)";
		if (level2 == 7) _level = "Proofreading";

		alert("Unfortunately, we cannot write more than "+level+" pages per day at "+_level+", otherwise it will affect the quality of the paper. Please select fewer pages, or extend your deadline.");

		var pages2 = document.qpq.page_count;
		pages2.selectedIndex = (total-pages2.options[0].value);
	}

	document.getElementById("total_words").innerHTML = document.qpq.page_count.value*250;
	update_cost();
}

function change_type()
{
	var type = a_type[document.qpq.paper_type.value];
	var period = document.qpq.period;

	var page_from = 1;
	var page_to = 200;
	var selected_index=0;

	if (type == 2)
		page_from = 2;

	var page_count = document.qpq.page_count;
	var selected_option = page_count.value;

	for (i=page_count.options.length-1;i>=0;i--)
		page_count.remove(i);

	for (i=page_from;i<=page_to;i++)
	{
		page_count.options[i-page_from] = new Option(i,i);
		if (i==selected_option)
			selected_index = i-page_from;
	}
	page_count.selectedIndex=selected_index;

	var level = a_level[document.qpq.level];
	var level2 = document.qpq.level;

	for (i=period.options.length-1;i>=0;i--)
		period.remove(i);

	if (type==1)
	{
		period.options[0] = new Option("Two Weeks", 14);
		period.options[1] = new Option("One Week", 7);
		period.options[2] = new Option("Four Days", 4);
		period.options[3] = new Option("48 Hours", 2);
		period.options[4] = new Option("24 Hours", 1);
	}		

	if (type==2)
	{
		period.options[0] = new Option("Two Months", 60);
		period.options[1] = new Option("One Month", 30);
		period.options[2] = new Option("Two Weeks", 14);
		period.options[3] = new Option("One Week", 7);
		period.options[4] = new Option("Four Days", 4);
	}		

	if (type==3)
	{
		period.options[0] = new Option("Two Months", 60);
		period.options[1] = new Option("One Month", 30);
		period.options[2] = new Option("Two Weeks", 14);
		period.options[3] = new Option("One Week", 7);
		period.options[4] = new Option("Four Days", 4);
		period.options[5] = new Option("48 Hours", 2);
		period.options[6] = new Option("24 Hours", 1);
	}		
	change_total_words();
	update_cost();
}
