var service;

function selection_gettext(selid)
{
	var x;
	if(document.getElementById(selid)!=null)
	{
		x = document.getElementById(selid).selectedIndex;
		document.getElementById(selid).options[x].value = document.getElementById(selid).options[x].text;
	}
}

function submitAppData()
{
	selection_gettext("selPos");
	selection_gettext("selService");
	selection_gettext("selDel");
	selection_gettext("selWords");
	selection_gettext("selCv");
	selection_gettext("selCl");
	selection_gettext("selSr");

	document.order.submit();
}

function SetService(sel)
{
	show_nextstep("false");
	service = sel;
	sndReq(sel);
	
	if(sel==2||sel==5||sel==6||sel==7)
	{
		show_nextstep("true");
		document.getElementById("fillbox").innerHTML = "Our price quotes are based on word count and the degree of editing required for each document. We will review your work and in most cases get back to you with a quotation within 6 hours. Please proceed to the next step. ";
	}
}

function show_nextstep(bool)
{
	if(bool=="true")
	{
		document.getElementById("nextstep").style.display = "block";
	}
	else
	{
		document.getElementById("fillbox").innerHTML = "* Please Fill All Boxes";
		document.getElementById("nextstep").style.display = "none";
	}
	
}

function calc_Total()
{
	var calc;
	switch(service)
	{
		case 1:
			if(document.getElementById("selWords").value !=0 && document.getElementById("selDel").value != 0)
			{
				calc = Math.ceil(document.getElementById("selWords").value/5*document.getElementById("selDel").value/5)*5;
				calc = calc.toFixed(2);
				document.getElementById("fillbox").innerHTML = "&pound;"+ calc;
				show_nextstep("true");
			}
			else
				show_nextstep("false");
			break;
		case 3:
			if(document.getElementById("selCv").value !=0 && document.getElementById("selDel").value != 0)
			{
				calc = Math.ceil(document.getElementById("selCv").value*document.getElementById("selDel").value/5)*5;
				calc = calc.toFixed(2);
				document.getElementById("fillbox").innerHTML = "&pound;"+ calc;
				show_nextstep("true");
			}
			else
				show_nextstep("false");
			break;
		case 4:
			if(document.getElementById("selCl").value !=0 && document.getElementById("selDel").value != 0)
			{
				calc = Math.ceil(document.getElementById("selCl").value*document.getElementById("selDel").value/5)*5;
				calc = calc.toFixed(2);
				document.getElementById("fillbox").innerHTML = "&pound;"+ calc;
				show_nextstep("true");
			}
			else
				show_nextstep("false");
			break;
		case 8:
			if(document.getElementById("selSr").value !=0 && document.getElementById("selWords").value !=0  && document.getElementById("selDel").value != 0)
			{
				calc = Math.ceil(document.getElementById("selSr").value*document.getElementById("selDel").value/5)*5;
				calc = calc.toFixed(2);
				document.getElementById("fillbox").innerHTML = "&pound;"+ calc;
				show_nextstep("true");
			}
			else
				show_nextstep("false");
			break;
	}
	
	document.order.calc.value = calc;
}


function sndReq(action)
{
  if (window.XMLHttpRequest)
  { 
      xmlHttp = new XMLHttpRequest();
      if (xmlHttp.overrideMimeType)
      {
          xmlHttp.overrideMimeType('text/xml');
      }
  }
  else if (window.ActiveXObject) { // IE 
    try
    {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
              xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

        if (!xmlHttp) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
        }
  var req = "?action="+action;
  xmlHttp.onreadystatechange = updateTable;
  xmlHttp.open("GET","selList.php"+req,true);
  xmlHttp.send(null)

}


function updateTable()
{
  
  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    document.getElementById("dynamicform").innerHTML=xmlHttp.responseText;
  }
}

