function search_jobs(list_page, company_id, order_by, by_letter, search_type)
{

	if (company_id == undefined)
	{
		company_id	= "";
	}
	if (company_id == 0)
	{
		company_id	= "";
	}

	if (by_letter == undefined)
	{
		by_letter	= "";
	}
	if (search_type == undefined)
	{
		search_type	= "";
	}
	// get work_areas
	var work_area	= new Array();
	work_area 		= get_multiple_list_selection(document.this_page.work_area);

	// location
 	var location	= new Array();
	location 		= get_multiple_list_selection(document.this_page.location);

	// job_types
 	var job_type	= new Array();
	job_type 		= get_multiple_list_selection(document.this_page.job_type);
	
	// free_text
 	var free_text	= document.this_page.free_text.value;
	
	if (order_by == "" || order_by == undefined)
		{
			var order_by = "";
		}
	var re = new RegExp("LJA-", "gi");
	free_text = String(free_text).replace(re, "");

	if (free_text.search("Indtast søgeord") >-1)
		{
			free_text = "";
		}
	
	// build Search Parameters
	var search_params  = new Array();
	search_params[search_params.length] = "work_area=" + work_area;
	search_params[search_params.length] = "location=" + location;
	search_params[search_params.length] = "job_type=" + job_type;
	search_params[search_params.length] = "free_text=" + free_text;
	search_params[search_params.length] = "search_type=" + search_type;
	if(company_id != "" && company_id != undefined) search_params[search_params.length] = "company_id=" + company_id;
	else search_params[search_params.length] = "company_id="+ company_id;
	if(list_page != "" && list_page != undefined) search_params[search_params.length] = "list_page=" + list_page;
	else search_params[search_params.length] = "list_page=1";
	if(order_by != "" && order_by != undefined) search_params[search_params.length] = "order_by=" + order_by;
	else search_params[search_params.length] = "order_by=";
	if(by_letter != "" && by_letter != undefined) search_params[search_params.length] = "by_letter=" + by_letter;
	else search_params[search_params.length] = "by_letter=";
	
	str_params = search_params.join("&");
	
	document.this_page.action = "job-liste.asp?" + str_params;
	document.this_page.submit();
}

function search_jobs_map(location)
{
	if (location == "" || location == undefined)
		{
			var location = document.this_page.maparea_location.value;
		}

	var list_page		= "";
	var work_area 		= "";
	var job_type		= "";
	var free_text		= "";
	var order_by		= "";
	// build Search Parameters
	var search_params  = new Array();
	search_params[search_params.length] = "work_area=" + work_area;
	search_params[search_params.length] = "location=" + location;
	search_params[search_params.length] = "job_type=" + job_type;
	search_params[search_params.length] = "free_text=" + free_text;
	if(list_page != "" && list_page != undefined) search_params[search_params.length] = "list_page=" + list_page;
	else search_params[search_params.length] = "list_page=1";
	search_params[search_params.length] = "order_by=" + order_by;
	
	str_params = search_params.join("&");
	
	document.this_page.action = "job-liste.asp?" + str_params;
	document.this_page.submit();
}


function search_jobs_mainarea(work_area)
{

	var list_page		= "";
	var location 		= "";
	var job_type		= "";
	var free_text		= "";
	var order_by		= "";
	// build Search Parameters
	var search_params  = new Array();
	search_params[search_params.length] = "work_area=" + work_area;
	search_params[search_params.length] = "location=" + location;
	search_params[search_params.length] = "job_type=" + job_type;
	search_params[search_params.length] = "free_text=" + free_text;
	if(list_page != "" && list_page != undefined) search_params[search_params.length] = "list_page=" + list_page;
	else search_params[search_params.length] = "list_page=1";
	search_params[search_params.length] = "order_by=" + order_by;
	
	str_params = search_params.join("&");
	
	document.this_page.action = "job-liste.asp?" + str_params;
	document.this_page.submit();
}

// get_multiple_list_selection
function get_multiple_list_selection(list_name)
{	
	var multiple_list_array	= new Array();
	if (list_name[0].selected == 0)
	{
		for (var i=0; i < list_name.length; i++)
		{
			if (list_name[i].selected == 1)
			{
				multiple_list_array[multiple_list_array.length] = list_name[i].value;
			}
		}
	}
	multiple_list_array = multiple_list_array.join(",");
	return multiple_list_array;
}


function tip_friend(job_title)
{
	document.getElementById('tipAFriendContainer').style.display = 'inline';
}

function apply_1(job_id)
{
	relocate("/shared/cv/source/cv_start.hts?nav_to=no_logon,search,id,"+job_id+",apply","self");
}
function apply_2(application_url)
{
	window.open(application_url);
}
function apply_3(contact_email)
{
	window.open("mailto:"+contact_email);
}
function show_on_map(adress, post_no, post_name)
{
	//document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><meta http-equiv="Content-Language" content="en-us" /></head><body>'+adress+'</body></html>');
	//adress = escape(adress);
	adress = escape(adress);
	post_no = escape(post_no);
	post_name = escape(post_name);
	map_string = "http://map.fynskemedier.dk/?t=fynskejob.dk&to="+adress+","+post_no+","+post_name;
	window.open(map_string);

}
function showPrint(job_id)
{
	window.open('print-job.asp?sa_id='+job_id, 'autoPrint', 'menubar=no, toolbar=no, scrollbars=yes, resizable=yes, width=710, height=600');
}
function autoPrint()
{
	window.print();
}
function showPrintCompany(company_id)
{
	window.open('virksomhedsprofil-print.asp?company_id='+company_id, 'autoPrint', 'menubar=no, toolbar=no, scrollbars=yes, resizable=yes, width=710, height=600');
}

function goto_mail_agent()
{

	document.this_page.action = "jobagent.asp";
	document.this_page.submit();
}
function create_cv_from_jobagent()
{
	relocate("/shared/cv/source/cv_start.hts?nav_to=no_logon,private_data,create","self");
}
function relocate(url, target)
{
	eval(format_str("%s.location.href=url", target));
}

function change_sort_order(order, categori, search_type)
{
	var order_by = "";
//alert(order+"-"+categori+"-"+search_type);
	if (categori == 1)
	{
		if (order != 2 && order != 3)
		{
			order_by = 2;
		}
		if (order == 2)
		{
			order_by = 3;
		}
		if (order == 3)
		{
			order_by = 2;
		}
	}
	if (categori == 2)
	{
		if (order != 7 && order != 1)
		{
			order_by = 1;
		}
		if (order == 1)
		{
			order_by = 7;
		}
		if (order == 7)
		{
			order_by = 1;
		}
	}
	if (categori == 3)
	{
		if (order != 4 && order != 5)
		{
			order_by = 4;
		}
		if (order == 5)
		{
			order_by = 4;
		}
		if (order == 4)
		{
			order_by = 5;
		}
	}
	search_jobs(1, '', order_by, '', search_type);
}


function create_mail_agent()
{

	// Validate
	if (!validate_not_blank(document.this_page.agent_name, 'Navn på jobagent'))
		return false;
	if (!validate_not_blank(document.this_page.agent_mail, 'Din mail adresse'))
		return false; 
	if (!validate_email_address(document.this_page.agent_mail, document.this_page.agent_mail.value))
		return false;
 	

	// Get info
	var agent_name 		= document.this_page.agent_name.value;
	var agent_mail 		= document.this_page.agent_mail.value;
	var job_type		= new Array();
	job_type 			= get_multiple_list_selection(document.this_page.agent_job_type);
	var work_area		= new Array();
	work_area 			= get_multiple_list_selection(document.this_page.agent_work_area);
 	var location		= new Array();
	location 			= get_multiple_list_selection(document.this_page.agent_location);
	var free_text		= document.this_page.agent_free_text.value;
	var agent_type 		= (document.this_page.agent_type[0].checked == true)? 1 : 0;
	
	// Define parameters
	var agent_params  = new Array();
	agent_params[agent_params.length] = "command=save_mail_agent";
	agent_params[agent_params.length] = "agent_name=" + escape(agent_name, 1);
	agent_params[agent_params.length] = "agent_mail=" + escape(agent_mail, 1);
	agent_params[agent_params.length] = "agent_type=" + agent_type;
	agent_params[agent_params.length] = "work_area=" + work_area;
	agent_params[agent_params.length] = "job_type=" + job_type;
	agent_params[agent_params.length] = "location=" + location;
	agent_params[agent_params.length] = "free_text=" + free_text;
	
	str_params = agent_params.join("&");
	
	document.this_page.action = "jobagent.asp?" + str_params;
	document.this_page.submit();

}

function search_company(list_page, by_letter)
{
	var company_params  = new Array();
	if(list_page != "" && list_page != undefined) company_params[company_params.length] = "list_page=" + list_page;
	else company_params[company_params.length] = "list_page=1";
	if(by_letter != "" && by_letter != undefined) company_params[company_params.length] = "by_letter=" + by_letter;
	else company_params[company_params.length] = "by_letter=";
	
	str_params = company_params.join("&");
	
	document.this_page.action = "virksomhedsprofil-liste.asp?" + str_params;
	document.this_page.submit();
}

function validate_not_blank(field, name)
{
	// strip all spaces at start and end of line
	var regx_output = new String(field.value);
	var re1 = new RegExp("^[ ]*|([ ]*)\$", 'g');
	field.value = regx_output.replace(re1, "");
	
	if (field.value == "")
	{
		alert(format_str('Feltet "%s" kan ikke være blank.', name));
		focus_field(field);
		return false;
	}
	return true;
}


function fieldCheck_company()
{
 	var user_name		= document.getElementById('companyAreaLoginBodyUser').value;

	if (user_name == "")
		{
			document.getElementById('companyAreaLoginBodyUser').value = "Indtast brugernavn";
		}

	return true;
}

function fieldCheck_blur_company()
{
	var pwd_show		= document.getElementById('passwordStars').value;

	if (pwd_show == "" || pwd_show == undefined)
		{
			document.getElementById('passwordText').style.display = 'inline';
			document.getElementById('passwordStars').style.display = 'none';
			document.getElementById('passwordText').value;
		}
	return true;
}

function fieldCheck_focus_company()
{

	document.getElementById('passwordStars').value == "";
	document.getElementById('passwordText').value == "";
	document.getElementById('passwordStars').style.display = 'inline'; 
	document.getElementById('passwordText').style.display = 'none'; 
	document.getElementById('passwordStars').focus()

}


function fieldCheck_jobseeker()
{
 	var user_name		= document.getElementById('jobSeekerFormClass').value;
	if (user_name == "")
		{
			document.getElementById('jobSeekerFormClass').value = "Indtast brugernavn";
		}

	return true;
}

function fieldCheck_blur_jobseeker()
{
	var pwd_show		= document.getElementById('passwordStars').value;

	if (pwd_show == "" || pwd_show == undefined)
		{
			document.getElementById('passwordText').style.display = 'inline';
			document.getElementById('passwordStars').style.display = 'none';
			document.getElementById('passwordText').value;
		}
	return true;
}

function fieldCheck_focus_jobseeker()
{
	document.getElementById('passwordStars').value == "";
	document.getElementById('passwordText').value == "";
	document.getElementById('passwordStars').style.display = 'inline'; 
	document.getElementById('passwordText').style.display = 'none'; 
	document.getElementById('passwordStars').focus()
}

function changeButton(hide, show)
{	
	document.getElementById(hide).style.display = 'none';
	document.getElementById(show).style.display = 'inline';
}


function show_job(sa_id, list_index, from_link, search_type)
{
	var nav_from = "";
	if (from_link != "" && from_link != undefined)
	{	
		from_link == "other_adds";
		nav_from = "&from_link="+from_link;
	}
	document.this_page.action = "job.asp?sa_id="+sa_id+"&list_index="+list_index+nav_from+"&search_type="+search_type;
	document.this_page.submit();
}

function show_company(company_id, list_index, by_letter)
{
	if (by_letter == undefined)
	{	
		by_letter = "";
	}
	document.this_page.action = "virksomhedsprofil.asp?company_id="+company_id+"&list_index="+list_index+"&by_letter="+by_letter;
	document.this_page.submit();
}

function validate_not_blank(field, name)
{
	// strip all spaces at start and end of line
	var regx_output = new String(field.value);
	var re1 = new RegExp("^[ ]*|([ ]*)\$", 'g');
	field.value = regx_output.replace(re1, "");

	if (field.value == "")
	{
		alert(format_str('Feltet "%s" må ikke stå tomt.', name));
		focus_field(field);
		return false;
	}
	return true;
}





function validate_email_address(field, name, allow_name_in_address, display_error)
{
	if (typeof display_error == "undefined")
	{
		display_error = true;
	}

	// Get field value
	var fieldval = field.value;

	// Remove spaces before and after email
	fieldval = fieldval.replace(/^\\s*/, "");
	fieldval = fieldval.replace(/\\s*\$/, "");

	// Update field
	field.value = fieldval;

	// If "name <email>" format is available - get email address
	if (allow_name_in_address)
	{
		var a = fieldval.indexOf("<");
		var b = fieldval.indexOf(">");
		if (a < b)
		{
			fieldval = fieldval.substring(a + 1, b);
		}
	}
	
	// Initialize
	var msg		= "";
	var last_at	= fieldval.lastIndexOf("\@");
	var before	= fieldval.substr(0, last_at);
	var after	= fieldval.substr(last_at + 1, fieldval.length - last_at - 1);
	var reg;
	
	// CHECK: the @ character must exist
	if (last_at < 0)
	{
		msg = "Tegnet @ skal forekomme i e-mail adressen.";
	}

	// CHECK: there must be at least one character preceeding and one character following @
	if (!msg)
	{
		if ((before.length < 1) || (after.length < 1))
		{
			msg = "E-mail adressen skal indeholde mindst ét tegn før @.";
		}
	}
	
	// CHECK: characters below 32 are illegal
	if (!msg)
	{
		for (var i = 0; i < fieldval.length; i++)
		{
			var code = fieldval.charCodeAt(i);
			if (code < 32)
			{
				msg = "Du har brugt et ugyldigt tegn i e-mail adressen.";
				break;
			}
		}
	}
	
	// CHECK: the ".@" combination is illegal
	if (!msg)
	{
		if (before.substr(before.length - 1, 1) == ".")
		{
			msg = "Du har brugt et ugyldigt tegn før @.";
		}
	}

	// CHECK: the "@." combination is illegal
	if (!msg)
	{
		if (after.substr(0, 1) == ".")
		{
			msg = "Der skal stå mindst ét punktum efter @.";
		}
	}

	// CHECK: at least one "." is required in the host section
	if (!msg)
	{
		if (after.indexOf(".") < 0)
		{
			msg = "Der skal være mindst ét punktum i e-mail adressen.";
		}
	}

	// CHECK: "." cannot be the last character
	if (!msg)
	{
		if (after.lastIndexOf(".") == (after.length - 1))
		{
			msg = "Det sidste tegn i e-mail adressen må ikke være et punktum.";
		}
	}

	// CHECK: the "-." combination is illegal following @
	if (!msg)
	{
		reg = /\\-{1}\\.{1}/;
		if (reg.test(after))
		{
			msg = "Der må ikke være bindestreg for punktum i en e-mail adresse.";
		}
	}

	// CHECK: "-" cannot be the last character
	if (!msg)
	{
		if (after.lastIndexOf("-") == (after.length - 1))
		{
			msg = "Bindestreg må ikke være det sidste tegn i en e-mail adresse.";
		}
	}

	// CHECK: certain characters preceeding @ must be escaped
	if (!msg)
	{
		// 1) remove all escaped characters
		// 2) all remaining special characters were not escaped - which is illegal
		before = before.replace(/\\\\{1}.{1}/g, "");
		reg = /[\\s<>()\\[\\]\\\\,;:@\\"]{1,}/;
		if (reg.test(before))
		{
			msg = "Du har brugt et ugyldigt tegn før @.";
		}
	}

	// CHECK: the characters following @ are restricted
	// ASCII Characters below 32, not allowed
	if (!msg)
	{
		reg = new RegExp("^[\\x00-\\x20]*\$");
		if (reg.test(after))
		{
			msg = "Du har brugt et ugyldigt tegn efter @.";
		}
	}

	// If the address is illegal
	if ((msg) && (display_error = true))
	{
		alert(format_str("E-mail adressen '%s' er ugyldig:\n%s\n\nE-mail adresser har typisk følgende format:\n - fornavn.efternavn@firma.dk\n - brugernavn@internetleverandør.dke\n - initialer@domænenavn.com\n   osv.", name, msg));
		focus_field(field);
		return false;
	}

	// The address seems to be in order
	return true;
}


