var xmlHttp
var historypage = "";

function createXMLHttp()
{
	if (typeof XMLHttpRequest != "undefined")
	{
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		var aVersions = [ "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];

		for (var i = 0; i < aVersions.length; i++)
		{
			try {
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			}
			catch (oError) {
				//Do nothing
			}
		}
	}
	
	throw new Error("XMLHttp object could be created.");
}

function getRequestBody(oForm)
{
	var aParams = new Array();
	
	for(var i=0 ; i < oForm.elements.length ; i++)
	{
		var sParam = encodeURIComponent(oForm.elements[i].name);
		var addEntry = true;
		
		sParam += "=";

		if( oForm.elements[i].type == "checkbox" )
		{
			sParam += encodeURIComponent(oForm.elements[i].checked);
		}
		else if( oForm.elements[i].type == "radio" )
		{
			if( oForm.elements[i].checked )
			{
				sParam += encodeURIComponent(oForm.elements[i].value);
			}
			else
			{
				addEntry = false;
			}
		}
		else if( oForm.elements[i].type == "select-multiple")
		{
			$optionsname = sParam;
			$options = oForm.elements[i];
			$optionslen = eval($options.options.length);

			for (var z=0; z < $optionslen;z++)
			{
				if ($options.options[z].selected)
				{
					sParam = $optionsname + encodeURIComponent($options.options[z].value);
					aParams.push(sParam);
				}
			}
			addEntry = false;			
		}
		else
		{
			sParam += encodeURIComponent(oForm.elements[i].value);
		}
		
		if( addEntry == true )
			aParams.push(sParam);
	}

	return aParams.join("&");
}

function handleEnter (field, event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	{
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	{
		return true;
	}
} 

function show_home()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/home.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function show_create_resume()
{
	var stats	= document.getElementById('hdn_stats');
	var sub_tbl	= document.getElementById('sub_resume');
	if(stats.value == "off")
	{
		sub_tbl.style.display	= "";
		stats.value				= "on";
	}
	else
	{
		sub_tbl.style.display	= "none";
		stats.value				= "off";
	}
}
function show_resume_photo()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/resume_photo_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function show_resume_profile()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/resume_profile_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_photo()
{
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_photo_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
			}
		}
	};
	oXmlHttp.send(sBody)
}
function submit_resume_profile()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_profile");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_profile_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_contact()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/resume_contact_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_contact()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_contact");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_contact_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_education()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_education_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function add_education_row()
{	
	var row_ctr = document.getElementById('row_ctr').value;
	row_ctr			= eval(row_ctr);
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/education_add_row.php?row_ctr="+row_ctr, true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('educ_add_row').innerHTML += oXmlHttp.responseText;
				row_ctr++;
				document.getElementById('row_ctr').value = row_ctr;
			}
		}
	};
	oXmlHttp.send(null);
}
function setCourseField(row_num)
{
	var row	= document.getElementById('cmb_educ_level['+row_num+']').value;
	if(row > 2)
	{
		document.getElementById('txt_course['+row_num+']').disabled = false;
	}
	else
	{
		document.getElementById('txt_course['+row_num+']').value = " ";
		document.getElementById('txt_course['+row_num+']').disabled = true;
	}
	
}
function submit_resume_education()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_education");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_education_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}
function show_resume_work_experience()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_work_experience_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function add_work_experience_row()
{	
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/work_experience_add_row.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('work_experience_add_row').innerHTML += oXmlHttp.responseText;
			}
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_work_experience()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_work_experience");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_work_experience_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_projects()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_projects_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_projects()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_projects");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_projects_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_skill()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_skill_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function add_skill_row()
{	
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/skill_add_row.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('skill_add_row').innerHTML += oXmlHttp.responseText;
			}
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_skill()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_skill");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_skill_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_user_reference()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_user_reference_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function add_user_reference_row()
{	
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/user_reference_add_row.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('user_reference_add_row').innerHTML += oXmlHttp.responseText;
			}
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_user_reference()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_user_reference");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_user_reference_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_about_self()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_about_self_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_about_self()
{
	show_loadingbar();
	var oForm = document.getElementById("form_resume_about_self");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_about_self_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_resume();
				dhtmlHistory.add("resume", "");
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_resume_work_preference()
{	
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_work_preference_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}
function submit_resume_work_preference()
{
	var oForm = document.getElementById("form_resume_work_preference");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/resume_work_preference_submit.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				if( oXmlHttp.responseText.substring(0,5) == "error" )
				{
					alert(oXmlHttp.responseText.substring(5));
				}
				else
				{
					show_resume();
					dhtmlHistory.add("resume", "");
				}
			}
		}
	};
	oXmlHttp.send(sBody)
}


function show_resume()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/resume_screen.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function show_search_jobs()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "pages/view/search_jobs.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function show_change_password()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/change_password.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function submit_change_password()
{
	show_loadingbar();
	var oForm = document.getElementById("form_change_password");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/change_password.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				if( oXmlHttp.responseText.substring(0,5) == "error" )
					alert(oXmlHttp.responseText.substring(5));
				else
					show_view_account_settings(oXmlHttp.responseText);
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_view_account_settings($message)
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/account_settings.php?msg="+encodeURIComponent($message), true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function submit_edit_account_settings()
{
	show_loadingbar();
	var oForm = document.getElementById("form_edit_account_settings");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/process/account_settings.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				show_view_account_settings(oXmlHttp.responseText);
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function show_user_application_status()
{
	show_loadingbar();
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/view/user_application_status.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(null);
}

function delete_user_application_status(job_id)
{
	show_loadingbar();
	var $confirm	= confirm("Are you sure you want to delete it?");
	if($confirm)
	{
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "pages/view/user_application_status.php?job_id="+job_id, true);
		oXmlHttp.onreadystatechange = function ()
		{
			if( oXmlHttp.readyState == 4 )
			{
				if( oXmlHttp.status == 200 )
				{
					document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
				}
				hide_loadingbar();
			}
		};
		oXmlHttp.send(null);
	}
	else
	{
		hide_loadingbar();
	}
}



function submit_search_jobs($logged)
{
	show_loadingbar();
	var oForm = document.getElementById("form_search");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/ajax/search_jobs.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				if($logged == "yes")
					document.getElementById('mainbody').innerHTML = oXmlHttp.responseText;
				else
					document.getElementById('main_forms').innerHTML = oXmlHttp.responseText;
			}
			hide_loadingbar();
		}
	};
	oXmlHttp.send(sBody)
}

function handleEnterSearch (field, event, $logged)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	{
		submit_search_jobs($logged);
		return false;
	}
	else
		return true;
} 


function openWindowJob($url,$jobid,$uid,$cd)
{
	var mypage = $url+'job.php?id='+$jobid+'&uid='+$uid+'&cd='+$cd;
	var w = 650;
	var h = 550;

	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes'
	win = window.open(mypage,'iJobster',settings)
}

function show_loadingbar()
{
	document.getElementById('div_loading').style.display = "block";
}
function hide_loadingbar()
{
	document.getElementById('div_loading').style.display = "none";
}


function check_username()
{
	var oForm = document.getElementById("form_change_password");
	var oXmlHttp = zXmlHttp.createRequest();
	var uname = document.getElementById('uname').value;
	var code1 = document.getElementById('hdn_code1').value;
	var code2 = document.getElementById('hdn_code2').value;
	
	uname = encodeURIComponent(uname);
	code1 = encodeURIComponent(code1);
	code2 = encodeURIComponent(code2);
	var sBody = "&uname=" +uname+ "&hdn_code1=" +code1+ "&hdn_code2="+code2;

	oXmlHttp.open("post", "pages/ajax/check_username.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{	
				document.getElementById('userNameAvailability').innerHTML = oXmlHttp.responseText;
			}
		}
	};
	oXmlHttp.send(sBody)
}

function submit_signup()
{
	show_loadingbar();
	clearSignupMessage();
	var oForm = document.getElementById("signupForm");
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();

	oXmlHttp.open("post", "pages/ajax/signup.php", true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	oXmlHttp.onreadystatechange = function () {
	
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				if( oXmlHttp.responseText.substring(0,5) == "error" )
				{
					$errors = oXmlHttp.responseText.substring(5);
					$errors = $errors.split(" ");
					$numerrors = $errors.length;
					
					for( $x=1; $x <= $numerrors; $x++ )
					{
						if( $errors[$x] == "firstname" )
							document.getElementById('fname_error').innerHTML = "Firsname Invalid";
						else if( $errors[$x] == "lastname" )
							document.getElementById('lname_error').innerHTML = "Lastname Invalid";
						else if( $errors[$x] == "email" )
							document.getElementById('email_error').innerHTML = "Email Invalid";
						else if( $errors[$x] == "emailused" )
							document.getElementById('email_error').innerHTML = "Email Already Used";
						else if( $errors[$x] == "password" )
							document.getElementById('pword_error').innerHTML = "Password Invalid";
						else if( $errors[$x] == "repassword" )
							document.getElementById('re_pword_error').innerHTML = "";
						else if( $errors[$x] == "passwordmatching" )
							document.getElementById('re_pword_error').innerHTML = "Password Not Matched";
						else if( $errors[$x] == "username" )
							document.getElementById('userNameAvailability').innerHTML = '<font color="red">Username Not Available</font>';
					}
					hide_loadingbar();
				}
				else
				{
					window.location = "http://localhost/projects/jobs/login.php";
					//alert('here');
					//document.getElementById('main_forms').innerHTML = oXmlHttp.responseText;
					//changeToplinksLogged();
					//hide_loadingbar();
				}
			}
			else
			{
				//alert("An error occured: "+ oXmlHttp.responseText);
			}
		}
	};
	oXmlHttp.send(sBody)
}

function clearSignupMessage()
{
	document.getElementById('fname_error').innerHTML = "";
	document.getElementById('lname_error').innerHTML = "";
	document.getElementById('email_error').innerHTML = "";
	document.getElementById('pword_error').innerHTML = "";
	document.getElementById('re_pword_error').innerHTML = "";
	document.getElementById('re_pword_error').innerHTML = "";
}

function changeToplinksLogged()
{
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "pages/ajax/change_toplinks.php", true);
	oXmlHttp.onreadystatechange = function ()
	{
		if( oXmlHttp.readyState == 4 )
		{
			if( oXmlHttp.status == 200 )
			{
				document.getElementById('navbar').innerHTML = oXmlHttp.responseText;
			}
		}
	};
	oXmlHttp.send(null);
}



function geturl()
{
 var $page = "";
 var $url = this.location.href;
 $url = $url.split("#");
 
	if( $url.length > 1 )
	{
		$page = $url[1];
		historypage = $page;
		
		if( $page == "photo")
			show_resume_photo();
		else if( $page == "profile" )
			show_resume_profile();
		else if( $page == "contact" )
			show_resume_contact();
		else if( $page == "education" )
			show_resume_education();
		else if( $page == "skills" )
			show_resume_skill();
		else if( $page == "workexp" )
			show_resume_work_experience();
		else if( $page == "projects" )
			show_resume_projects();
		else if( $page == "reference" )
			show_resume_user_reference();
		else if( $page == "aboutyou" )
			show_resume_about_self();
		else if( $page == "workpref" )
			show_resume_work_preference();
		else if( $page == "resume" )
			show_resume();
		else if( $page == "account" )
			show_view_account_settings('');
		else if( $page == "applications" )
			show_user_application_status();
		else if( $page == "changepassword" )
			show_change_password()
		else if( $page == "search" )
			show_search_jobs();
		else
			show_home();
	}
	else
	{
		show_home();
	}
}


function initialize()
{
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(historyChange);
	if (dhtmlHistory.isFirstLoad())
	{
		var fakeXML = 
            '<?xml version="1.0" '
            +      'encoding="ISO-8859-1"?>'
            +      '<foobar>'
            +         '<foo-entry/>'
            +      '</foobar>';
		historyStorage.put("fakeXML", fakeXML);
	} 

	var savedXML = historyStorage.get("fakeXML");
	savedXML = prettyPrintXml(savedXML);
	var hasKey = historyStorage.hasKey("fakeXML");
}

	function historyChange(newLocation,historyData)
	{
		//if( historypage != newLocation )
		//{
		//	historypage = newLocation;
			geturl();
		//}
	}

	function prettyPrintXml(content)
	{
		if (content == null)
			return null;
		content = content.replace(/</g, "&lt;");
		content = content.replace(/>/g, "&gt;<br>");
		return content;
	}
	
	
	
	
