// JavaScript Document
function ajaxFunction()
{
	doWorking();
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if( (xmlHttp.readyState == 4) && (xmlHttp.status == 200) )
		{
			var result = xmlHttp.responseText;
			var sr = result.split("|");
			var success = sr[0]; 
			var msg = sr[1];
			if ( success == "1" )
			{
				clearFields();
				showMessage(msg);
				showSuccess();
			}
			else
			{
				showMessage(msg);
			}
		}
	}
	name 	= getName();
	email 	= getEmail();
	phone 	= getPhone();
	address = getAddress();
	note	= getNote();
	
	data = "name=" + name + "&email=" + email + "&phone=" + phone + "&address=" + address + "&note=" + note;
	xmlHttp.open("POST","../save_employee.php",true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", data.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(data);
}

function getName( )
{
	return document.getElementById( 'name' ).value;
}
function getEmail( )
{
	return document.getElementById( 'email' ).value;
}
function getPhone( )
{
	return document.getElementById( 'phone' ).value;
}
function getAddress( )
{
	return document.getElementById( 'address' ).value;
}
function getNote( )
{
	return document.getElementById( 'note' ).value;
}

function doWorking( )
{
	document.getElementById( 'spmsg' ).innerHTML = 'Sending...';
}
function clearFields()
{
	document.getElementById( 'name' ).value = "";
	document.getElementById( 'phone' ).value = "";
	document.getElementById( 'email' ).value = "";
	document.getElementById( 'address' ).value = "";
	document.getElementById( 'note' ).value = "";
}

function showMessage( msg )
{
	document.getElementById( 'spmsg' ).innerHTML = msg;
}

function showSuccess()
{
	document.getElementById( 'emp_form' ).style.display = 'none';
	document.getElementById( 'pmsg' ).innerHTML = 'Your information is sent';
}