var Loader = {
	start: function(message){
		//$('loadmsg').update(message);
		//$('loadpnl').show();
	},
	stop: function(){
		//$('loadpnl').hide();
	}
}

function backTo(page)
{
	window.location = page;
}

function goTo(page)
{
	window.location = page;
}

function signupUser()
{
	Form.disable('ID_SIGNUP');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'signup',
			newusername: $('tfUserName').getValue(),
			email: $('tfEmail').getValue(),
			password: $('tfPassword').getValue(),
			company: $('tfCompany').getValue(),
			street: $('tfStreet').getValue(),
			city: $('tfCity').getValue(),
			state: $('tfState').getValue(),
			country: $('listCountry').getValue(),
			zipcode: $('tfZipCode').getValue(),
			agree: $('cbAgree').getValue()
		},
		onSuccess: function(transport)
		{
			switch(transport.responseText)
			{
				case 'RESPONSE_INVALID_USERTYPE':
				{
					alert('Are you an Employer or a Jobseeker? Please choose a user type!');
					Form.enable('ID_SIGNUP');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_INVALID_USERNAME':
				{
					alert('The username must be between 4 to 16 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfUserName').focus();
				}
				break;
				
				case 'RESPONSE_USERNAME_HAS_SPACE':
				{
					alert('The username cannot contain spaces. Please choose another one.');
					Form.enable('ID_SIGNUP');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_USERNAME_EXIST':
				{
					alert('The username you provided is already registered.');
					Form.enable('ID_SIGNUP');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_INVALID_EMAIL':
				{
					alert('The email address does not appear to be valid.');
					Form.enable('ID_SIGNUP');
					$('tfEmail').focus();
				}
				break;

				case 'RESPONSE_INVALID_PASSWORD':
				{
					alert('The password must be at least 4 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfPassword').focus();
				}
				break;

				case 'RESPONSE_INVALID_COMPANY':
				{
					alert('The company name must be at least 4 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfCompany').focus();
				}
				break;

				case 'RESPONSE_INVALID_STREET':
				{
					alert('The street address must be at least 4 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfStreet').focus();
				}
				break;

				case 'RESPONSE_INVALID_CITY':
				{
					alert('The city or town must be at least 4 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfCity').focus();
				}
				break;

				case 'RESPONSE_INVALID_STATE':
				{
					alert('The state or province must be at least 4 characters long.');
					Form.enable('ID_SIGNUP');
					$('tfState').focus();
				}
				break;

				case 'RESPONSE_INVALID_COUNTRY':
				{
					alert('Please choose a country.');
					Form.enable('ID_SIGNUP');
					$('tfCountry').focus();
				}
				break;

				case 'RESPONSE_PLEASE_AGREE':
				{
					alert('You must agree to the terms of use to create an account.');
					Form.enable('ID_SIGNUP');
					$('cbAgree').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					alert('Congratulations! You will receive an email shortly on how to activate your account. If you did not receive any email, please check your JUNK/SPAM folder or contact us. Thank you!');
					window.location = 'signin';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_SIGNUP');
					$('tfUserName').focus();
				}
				break;
			}
		}
	});
}

function signinUser()
{
	Form.disable('ID_SIGNIN');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'signin',
			oldusername: $('tfUserName').getValue(),
			password: $('tfPassword').getValue(),
			remember: $('cbRemember').getValue()
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{
				case 'RESPONSE_USERNAME_NOT_EXIST':
				{
					alert('The username does not exist in our database.');
					Form.enable('ID_SIGNIN');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_INVALID_PASSWORD':
				{
					alert('The password you entered is invalid.');
					Form.enable('ID_SIGNIN');
					$('tfPassword').focus();
				}
				break;

				case 'RESPONSE_INACTIVE_ACCOUNT':
				{
					if(confirm('Your account is not yet confirmed. Resend confirmation email?'))
					{
						resendConfirmation();
					}
					else
					{
						Form.enable('ID_SIGNIN');
						$('tfUserName').focus();
					}
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					window.location = 'profile';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('The email and password is not valid. Please try again!');
					Form.enable('ID_SIGNIN');
					$('tfUserName').focus();
				}
				break;
			}
		}
	});
}

function resendConfirmation()
{
	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'resend',
			username: $('tfUserName').getValue()
		},
		onLoading: function()
		{
			//Loader.start('Resending activation email, please wait...');
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);
			//Loader.stop();
			switch(transport.responseText)
			{
				case 'RESPONSE_USERNAME_NOT_EXIST':
				{
					alert('The username does not exist in our database.');
					Form.enable('ID_SIGNIN');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_INVALID_EMAIL':
				{
					alert('The email address does not appear to be valid.');
					Form.enable('ID_SIGNIN');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					window.location = 'signin';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_SIGNIN');
					$('tfUserName').focus();
				}
				break;
			}
		}
	});
}

function retrieveUser()
{
	Form.disable('ID_RETRIEVE');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'retrieve',
			oldusername: $('tfUserName').getValue()
		},
		onLoading: function(){
			//Loader.start('Retrieving password, please wait...');
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);
			//Loader.stop();
			switch(transport.responseText)
			{
				case 'RESPONSE_USERNAME_NOT_EXIST':
				{
					alert('The username does not exist in our database.');
					Form.enable('ID_RETRIEVE');
					$('tfUserName').focus();
				}
				break;

			    case 'RESPONSE_INVALID_EMAIL':
				{
					alert('The email address does not appear to be valid.');
					Form.enable('ID_RETRIEVE');
					$('tfUserName').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					alert('Your new password has been sent to the email address associated with your username.');
					window.location = 'signin';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_RETRIEVE');
					$('tfUserName').focus();
				}
				break;
			}
		}
	});
}

function signoutUser()
{
	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'signout'
		},
		onSuccess: function(transport)
		{
			window.location = 'signout';
		}
	});
}

function updateProfile()
{
	Form.disable('ID_UPDATE_PROFILE');
	$('msg').hide();

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'update_profile',
			company: $('tfCompany').getValue(),
			desc: $('taDescription').getValue(),
			street: $('tfStreet').getValue(),
			city: $('tfCity').getValue(),
			state: $('tfState').getValue(),
			country: $('listCountry').getValue(),
			zipcode: $('tfZipCode').getValue(),
			telephone: $('tfTelephone').getValue(),
			website: $('tfWebsite').getValue()
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{

				case 'RESPONSE_INVALID_COMPANY':
				{
					alert('The company name must be at least 4 characters long.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfCompany').focus();
				}
				break;

				case 'RESPONSE_INVALID_STREET':
				{
					alert('The street address must be at least 4 characters long.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfStreet').focus();
				}
				break;

				case 'RESPONSE_INVALID_CITY':
				{
					alert('The city or town must be at least 4 characters long.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfCity').focus();
				}
				break;

				case 'RESPONSE_INVALID_STATE':
				{
					alert('The state or province must be at least 4 characters long.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfState').focus();
				}
				break;

				case 'RESPONSE_INVALID_COUNTRY':
				{
					alert('Please choose a country.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfCountry').focus();
				}
				break;

				case 'RESPONSE_INVALID_TELEPHONE':
				{
					alert('The telephone number does not appear to be valid.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfTelephone').focus();
				}
				break;

				case 'RESPONSE_INVALID_WEBSITE':
				{
					alert('The website does not appear to be valid.');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfWebsite').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					//window.location = 'profile_edit';

					$('msg').update("Company profile has been updated!");
					$('msg').show();

					Form.enable('ID_UPDATE_PROFILE');
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_UPDATE_PROFILE');
					$('tfCompany').focus();
				}
				break;
			}
		}
	});
}

function confirmReset()
{
	Form.disable('ID_ADD_POST');
	
	var answer = confirm ("Are you sure you want to reset? This will erase the current job details.")
	if (answer)
	{
		$('tfTitle').setValue('');
		$('tfShortDesc').setValue('');
		$('tfSalaryMin').setValue('');
		$('tfSalaryMax').setValue('');
		$('taLongDesc').setValue('');
	}
	
	Form.enable('ID_ADD_POST');
	$('tfTitle').focus();
}

function addPost()
{
	Form.disable('ID_ADD_POST');

	var salary = $('listSalary').getValue();
	var salary_min = 0;
	var salary_max = 0;

	if (salary == 0)
	{
		salary_min = $('tfSalaryMin').getValue();
		salary_max = $('tfSalaryMax').getValue();
	}

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'add_post',
			title: $('tfTitle').getValue(),
			shortdesc: $('tfShortDesc').getValue(),
			loc_code: $('listLocation').getValue(),
			loc_sub_code: $('listSubLocation').getValue(),
			cat_code: $('listCategory').getValue(),
			cat_sub_code: $('listSubCategory').getValue(),
			sal_code: salary,
			sal_min: salary_min,
			sal_max: salary_max,
			//tags: $('tfTags').getValue(),
			fulltime: $('cbFullTime').getValue(),
			parttime: $('cbPartTime').getValue(),
			contract: $('cbContract').getValue(),
			internship: $('cbInternship').getValue(),
			longdesc: $('taLongDesc').getValue(),
			attachok: $('cbAttachOK').getValue(),
			emailok: $('cbEmailOK').getValue(),
			phoneok: $('cbPhoneOK').getValue(),
			repostok: $('cbRepostOK').getValue()
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{
				case 'RESPONSE_INVALID_TITLE':
				{
					alert('The title must be at least 4 characters long.');
					Form.enable('ID_ADD_POST');
					$('tfTitle').focus();
				}
				break;

				case 'RESPONSE_INVALID_SHORT_DESC':
				{
					alert('The short description must be at least 50 characters long.');
					Form.enable('ID_ADD_POST');
					$('tfShortDesc').focus();
				}
				break;

                case 'RESPONSE_INVALID_LOCATION':
				{
					alert('The location is invalid. Please select a location.');
					Form.enable('ID_ADD_POST');
					//$('listLocation').focus();
				}
				break;

               	case 'RESPONSE_INVALID_SUB_LOCATION':
				{
					alert('The sub location is invalid. Please select a sub location.');
					Form.enable('ID_ADD_POST');
					//$('listLocation').focus();
				}
				break;

                case 'RESPONSE_INVALID_CATEGORY':
				{
					alert('The category is invalid. Please select a category.');
					Form.enable('ID_ADD_POST');
					//$('listCategory').focus();
				}
				break;

                case 'RESPONSE_INVALID_SUB_CATEGORY':
				{
					alert('The sub category is invalid. Please select a sub category.');
					Form.enable('ID_ADD_POST');
					//$('listCategory').focus();
				}
				break;

				case 'RESPONSE_INVALID_SALARY':
				{
					alert('The salary range you enter is not valid. Make sure the minimum salary is lower than maximum and greater than zero.');
					Form.enable('ID_ADD_POST');
					//$('listCategory').focus();
				}
				break;

				/*case 'RESPONSE_INVALID_TAGS':
				{
					alert('The tags must be at least 4 characters long.');
					Form.enable('ID_ADD_POST');
					$('tfTags').focus();
				}
				break;*/

				case 'RESPONSE_INVALID_LONG_DESC':
				{
					alert('The long description must be at least 50 characters long.');
					Form.enable('ID_ADD_POST');
					$('taDetails').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					alert('Your post has been added successfully!');
					window.location = 'post_list';

					/*$('msg').update("Your post has been added successfully!");
					$('msg').show();

					Form.enable('ID_ADD_POST');
					$('tfTitle').setValue('');
					$('tfShortDesc').setValue('');
					$('tfTags').setValue('');
					$('taLongDesc').setValue('');

					$('tfTitle').focus();*/
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_ADD_POST');
					$('tfTitle').focus();
				}
				break;
			}
		}
	});
}

function updatePost()
{
	Form.disable('ID_EDIT_POST');

	var salary = $('listSalary').getValue();
	var salary_min = 0;
	var salary_max = 0;

	if (salary == 0)
	{
		salary_min = $('tfSalaryMin').getValue();
		salary_max = $('tfSalaryMax').getValue();
	}

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'update_post',
			postid: $('tfPostId').getValue(),
			title: $('tfTitle').getValue(),
			shortdesc: $('tfShortDesc').getValue(),
			loc_code: $('listLocation').getValue(),
			loc_sub_code: $('listSubLocation').getValue(),
			cat_code: $('listCategory').getValue(),
			cat_sub_code: $('listSubCategory').getValue(),
			sal_code: salary,
			sal_min: salary_min,
			sal_max: salary_max,
			//tags: $('tfTags').getValue(),
			fulltime: $('cbFullTime').getValue(),
			parttime: $('cbPartTime').getValue(),
			contract: $('cbContract').getValue(),
			internship: $('cbInternship').getValue(),
			longdesc: $('taLongDesc').getValue(),
			attachok: $('cbAttachOK').getValue(),
			emailok: $('cbEmailOK').getValue(),
			phoneok: $('cbPhoneOK').getValue(),
			repostok: $('cbRepostOK').getValue()
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{

				case 'RESPONSE_INVALID_TITLE':
				{
					alert('The title must be at least 4 characters long.');
					Form.enable('ID_EDIT_POST');
					$('tfTitle').focus();
				}
				break;

				case 'RESPONSE_INVALID_SHORT_DESC':
				{
					alert('The short description must be at least 50 characters long.');
					Form.enable('ID_EDIT_POST');
					$('tfTags').focus();
				}
				break;

				case 'RESPONSE_INVALID_LOCATION':
				{
					alert('The location is invalid. Please select a location.');
					Form.enable('ID_EDIT_POST');
					//$('listLocation').focus();
				}
				break;

               	case 'RESPONSE_INVALID_SUB_LOCATION':
				{
					alert('The sub location is invalid. Please select a sub location.');
					Form.enable('ID_EDIT_POST');
					//$('listLocation').focus();
				}
				break;

                case 'RESPONSE_INVALID_CATEGORY':
				{
					alert('The category is invalid. Please select a category.');
					Form.enable('ID_EDIT_POST');
					//$('listCategory').focus();
				}
				break;

                case 'RESPONSE_INVALID_SUB_CATEGORY':
				{
					alert('The sub category is invalid. Please select a sub category.');
					Form.enable('ID_EDIT_POST');
					//$('listCategory').focus();
				}
				break;

				case 'RESPONSE_INVALID_SALARY':
				{
					alert('The salary range you enter is not valid. Make sure the minimum salary is lower than maximum and greater than zero.');
					Form.enable('ID_EDIT_POST');
					//$('listCategory').focus();
				}
				break;

				/*case 'RESPONSE_INVALID_TAGS':
				{
					alert('The tags must be at least 4 characters long.');
					Form.enable('ID_EDIT_POST');
					$('tfTags').focus();
				}
				break;*/

				case 'RESPONSE_INVALID_LONG_DESC':
				{
					alert('The long description must be at least 50 characters long.');
					Form.enable('ID_EDIT_POST');
					$('taDetails').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					//window.location = 'confirm';

					$('msg').update("Your post has been updated successfully!");
					$('msg').show();

					Form.enable('ID_EDIT_POST');
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_EDIT_POST');
					$('tfTitle').focus();
				}
				break;
			}
		}
	});
}

function deletePost()
{
	Form.disable('ID_DELETE_POST');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'delete_post',
			postid: $('tfPostId').getValue()
		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{

				case 'RESPONSE_SUCCESS':
				{
					alert('Your post has been deleted successfully!');
					window.location = 'post_list';

					/*$('msg').update("Your post has been deleted successfully!");
					$('msg').show();

					Form.enable('ID_DELETE_POST');

					$('btnDelete').hide();*/
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_DELETE_POST');
				}
				break;
			}
		}
	});
}

function updateSettings()
{
	Form.disable('ID_SETTINGS');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'update_settings',
			oldpassword: $('tfOldPassword').getValue(),
			newpassword: $('tfNewPassword').getValue(),
			confirmpassword: $('tfConfirmPassword').getValue()
		},
		onSuccess: function(transport)
		{
			switch(transport.responseText)
			{

				case 'RESPONSE_INVALID_PASSWORD':
				{
					alert('The old password does not appear to be valid.');
					Form.enable('ID_SETTINGS');
					$('tfOldPassword').focus();
				}
				break;

				case 'RESPONSE_INVALID_NEW_PASSWORD':
				{
					alert('The new password must be at least 4 characters long.');
					Form.enable('ID_SETTINGS');
					$('tfNewPassword').focus();
				}
				break;

				case 'RESPONSE_INVALID_CONFIRM_PASSWORD':
				{
					alert('The confirm password must be at least 4 characters long.');
					Form.enable('ID_SETTINGS');
					$('tfConfirmPassword').focus();
				}
				break;

				case 'RESPONSE_INVALID_MATCH':
				{
					alert('The new password does match the retyped password.');
					Form.enable('ID_SETTINGS');
					$('tfNewPassword').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					//window.location = 'confirm';

					$('msg').update("Your password has been updated successfully!");
					$('msg').show();

					Form.enable('ID_SETTINGS');
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_SETTINGS');
					$('tfOldPassword').focus();
				}
				break;
			}
		}
	});
}

function updateActive(_postid, _active)
{
	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'update_active',
			postid: _postid,
			active: _active

		},
		onSuccess: function(transport)
		{
			//alert(transport.responseText);

			switch(transport.responseText)
			{

				case 'RESPONSE_SUCCESS':
				{
					window.location = 'post_list';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
				}
				break;
			}
		}
	});
}

function handleOnLocationChange(dd1, formname, listid)
{
	var idx = dd1.selectedIndex;
	var val = dd1[idx].value; //.text;
	var par = document.forms[formname];
	var sub_loc_elem = par.elements;
	var sub_loc_option = sub_loc_elem[listid];
	var loc_code = val;

	if (loc_code != 0)
	{
		new Ajax.Request('lib/request.lib.php',
		{
			method: 'post',
			parameters:
			{
				action: 'sub_location',
				loc_code: loc_code

			},
			onSuccess: function(transport)
			{
				var response = transport.responseText;
				var sub_loc = response.split("|");

				sub_loc_option.length = sub_loc.length - 1;

				for (i=0; i < sub_loc_option.length; i++)
				{
					var loc = sub_loc[i].split(":");

					sub_loc_option[i].value = loc[0];
					sub_loc_option[i].text = loc[1];
				}
			}
		});
	}
}

function handleOnCategoryChange(dd1, formname, listid)
{
	var idx = dd1.selectedIndex;
	var val = dd1[idx].value; //.text;
	var par = document.forms[formname];
	var sub_cat_elem = par.elements;
	var sub_cat_option = sub_cat_elem[listid];
	var cat_code = val;

	if (cat_code != 0)
	{
		new Ajax.Request('lib/request.lib.php',
		{
			method: 'post',
			parameters:
			{
				action: 'sub_category',
				cat_code: cat_code

			},
			onSuccess: function(transport)
			{
				var response = transport.responseText;
				var sub_cat = response.split("|");

				sub_cat_option.length = sub_cat.length - 1;

				for (i=0; i < sub_cat_option.length; i++)
				{
					var cat = sub_cat[i].split(":");

					sub_cat_option[i].value = cat[0];
					sub_cat_option[i].text = cat[1];
				}
			}
		});
	}
}

function changeDisplay(dd1, elem)
{
	var idx = dd1.selectedIndex;
	var val = dd1[idx].value;

	if (val == 0)
	{
		document.getElementById(elem).style.display = 'block';
	}
	else
	{
		document.getElementById(elem).style.display = 'none';
	}
}

function changeVisibility(dd1, elem)
{
	var idx = dd1.selectedIndex;
	var val = dd1[idx].value;

	if (val == 0)
	{
		document.getElementById(elem).style.visibility = 'visible';
	}
	else
	{
		document.getElementById(elem).style.visibility = 'hidden';
	}
}

function contactUs()
{
	Form.disable('ID_CONTACT');

	new Ajax.Request('lib/request.lib.php',
	{
		method: 'post',
		parameters:
		{
			action: 'contact_us',
			name: $('tfName').getValue(),
			email: $('tfEmail').getValue(),
			subject: $('tfSubject').getValue(),
			message: $('taMessage').getValue()
		},
		onSuccess: function(transport)
		{
			switch(transport.responseText)
			{
				case 'RESPONSE_INVALID_NAME':
				{
					alert('The name must be between 2 to 100 characters long.');
					Form.enable('ID_CONTACT');
					$('tfName').focus();
				}
				break;

				case 'RESPONSE_INVALID_EMAIL':
				{
					alert('The email address does not appear to be valid.');
					Form.enable('ID_CONTACT');
					$('tfEmail').focus();
				}
				break;

				case 'RESPONSE_INVALID_SUBJECT':
				{
					alert('The subject must be between 4 to 150 characters long.');
					Form.enable('ID_CONTACT');
					$('tfSubject').focus();
				}
				break;

				case 'RESPONSE_INVALID_MESSAGE':
				{
					alert('The message must be between 4 to 150 characters long.');
					Form.enable('ID_CONTACT');
					$('taMessage').focus();
				}
				break;

				case 'RESPONSE_SUCCESS':
				{
					alert('Thanks for contacting us! We will get back to you shortly.');
					window.location = 'contact';
				}
				break;

				case 'RESPONSE_FAILED':
				{
					alert('Unknown error encountered. Please try again!');
					Form.enable('ID_CONTACT');
					$('tfName').focus();
				}
				break;
			}
		}
	});
}

function checkEnter(e)
{ //e is event object passed from function invocation 
	var characterCode; // literal character code will be stored in this variable

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit(); //submit the form
		retrieveUser();
		return false;
	}
	else
	{
		return true;
	}
}
