//AJAX FORMS FOR ONLINE_SUBMISSION FORM AND APPLICATION_FOR_JOB FORM

var xmlHttp;

function getFormExisting(option)
{
	xmlHttp = getXmlHttpObject();
	
	if(xmlHttp == null)
	{
		window.alert("Your browser does not support AJAX");
		return;
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
		{
			if(xmlHttp.status == 200)
			{
				if(option == 'select')
				{
					document.getElementById('ajaxdiv').innerHTML = '';
				}
				else
				{
					printForm(xmlHttp.responseText);
				}
			}
		}
	
	}
	
	if(option == 'existing')
	{
		var url = "adds/existing.php";
	}
	else
	{
		var url = "adds/notexisting.php";
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);	
}

function doAjax(option)
{

	xmlHttp = getXmlHttpObject();
	
	if(xmlHttp == null)
	{
		window.alert("Your browser does not support AJAX");
		return;	
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
		{
			if(xmlHttp.status == 200)
			{
				switch(option)
				{
					case 'c2c':
					ajaxify(xmlHttp.responseText);
					break;
					
					case 'select':
					document.getElementById('ajaxdiv').innerHTML = '';
					document.getElementById('payrate1').innerHTML = '';
					document.getElementById('payrate2').innerHTML = '';
					break;
					
					default:
					printAjax(xmlHttp.responseText);
					break;
				}
			}
		}
	}
	
	if(option == 'c2c')
		var url = "adds/c2c.php";
	else if(option != 'c2c' || option != 'select')
		var url = "adds/notc2c.php";
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function getXmlHttpObject()
{
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function printForm(response)
{	
	var ajaxDiv = document.getElementById('ajaxdiv');	
	ajaxDiv.innerHTML = response;
}

function ajaxify(response)
{
	var ajaxDiv = document.getElementById('ajaxdiv');
	ajaxDiv.innerHTML = response;
	
	var payrate1 = document.getElementById('payrate1');
	var payrate2 = document.getElementById('payrate2');
	
	payrate1.innerHTML = '';
	payrate2.innerHTML = '';
}

function printAjax(response)
{
	var payrate1 = document.getElementById('payrate1');
	var payrate2 = document.getElementById('payrate2');
	
	payrate1.innerHTML = 'Pay Rate';
	//payrate2.innerHTML = "<input type=\"text\" name=\"rate\" id=\"rate\"></input>";
	payrate2.innerHTML = response;
	
	var ajaxDiv = document.getElementById('ajaxdiv');
	ajaxDiv.innerHTML = '';
}