 function sh(iMax) {
	for (var i=0; i<iMax; i++) {
		hideCnt(i)
		shAction(i);
	} 
 }
 
 function hideCnt(iNum) {
	 $('ul.shcnt'+iNum).hide();
 }
 
 function shAction(iNum) {
	 $("a.shbtn"+iNum).click(function() {
     	$('ul.shcnt'+iNum).toggle('slow');
	 	return false;
   	});
 }
 
 
 /////
 
/* search box functions */

function ini_search () {
	var oSearch =  document.getElementById("search_box"); 
	if (oSearch.value == "Search LEWIS PR") {	
		oSearch.value = '';
	}
}


function clear_search () {
	var oSearch =  document.getElementById("search_box");
	if (oSearch.value== '') {
		oSearch.value = "Search LEWIS PR";
	}
}

document.onkeydown = checkKeycode

function checkKeycode(e) {
	var oSearch =  document.getElementById("search_box");
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == 13 && oSearch.value != '') {
		start_search();
	}
}

function start_search () {
	var oSearch =  document.getElementById("search_box");
	window.location = "search.php?key=" + oSearch.value;
}


	//////////////////////////////////
	//US Jobs//
	///////////////////////
	

 function getJobFeed() {
   $.ajax({
   		type: "POST",
   		url: "jobfeed.php",
   		dataType: "xml",
		
		//beforeSend: function(){$('#jobNavi').html("<i>loading data ...</i>")},
		
   		success: function(feed){
     		loadMenu(feed);
			loadUK(feed); // added to test UK jobs
			loadAPAC(feed); // added to test APAC jobs
			loadEU(feed); // added to test Europe
			
   		}
		
 	});
   
   
 }
 
 function loadMenu(feed) {

	var html = "";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var Region = $(this).find('region').text();
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		if(Region=='US'){
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> - <span class='office'>"+location+"</span></li>"
								 }
	});
	
	$('.usMenu').html(html);
	
	
	//uncomment the line below if you want to hide al jobs and show them when a region is clicked
	//$('.usMenu').hide();
	
	$('.usTitle a').click(togDiv);

 }
 /////////////  the following is to test UK
 
 function loadUK(feed) {

	var html = "";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var Region = $(this).find('region').text();
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		if(Region=='UK'){
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> - <span class='office'>"+location+"</span></li>"
								 }
	});
	
	$('.ukMenu').html(html);
	
	
	//uncomment the line below if you want to hide al jobs and show them when a region is clicked
	//$('.ukMenu').hide();
	
	$('.ukTitle a').click(togDiv2);

 }
 
 
 
 /////////////
 
  /////////////  the following is to test APAC
 
 function loadAPAC(feed) {

	var html = "";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var Region = $(this).find('region').text();
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		if(Region=='APAC'){
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> - <span class='office'>"+location+"</span></li>"
								 }
	});
	
	$('.apMenu').html(html);
	
	
	//uncomment the line below if you want to hide al jobs and show them when a region is clicked
	//$('.apMenu').hide();
	
	$('.apTitle a').click(togDiv3);

 }
 
 
 
 /////////////
 
  /////////////  the following is to test Europe
 
 function loadEU(feed) {

	var html = "";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var Region = $(this).find('region').text();
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		if(Region=='Europe'){
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> - <span class='office'>"+location+"</span></li>"
								 }
	});
	
	$('.euMenu').html(html);
	
	
	//uncomment the line below if you want to hide al jobs and show them when a region is clicked
	//$('.euMenu').hide();
	
	$('.euTitle a').click(togDiv4);

 }
 
 
 
 /////////////
 
 function togDiv() {
	 $('.usMenu').toggle('slow');
	 
 }
 
  function togDiv2() {
	
	 $('.ukMenu').toggle('slow');
 }
 
 function togDiv3() {
	
	 $('.apMenu').toggle('slow');
 }
 
 function togDiv4() {
	
	 $('.euMenu').toggle('slow');
 }
 
 function loadJobInfo(q, a) {
	 
	$.ajax({
   		type: "GET",
   		url: "jobinfo.php",	
		data: q,
		dataType: "xml",
		beforeSend: function(){$('#main_content').html("<i>loading data ...</i>")},
		
   		success: function(feed){
     		getDesc(feed, a);
   		}
		
 	});
 }

 
 function getDesc(feed, a){
		var desc = $(feed).find('description').text();
		var html = "<h1>careers - job opportunities</h1>" + desc
		html += "<p><a href='apply.php?"+a+"'>Apply Now</a></p>";
		
		$('#main_content').html(html);
		
		$.ajax({
   			type: "POST",
   			url: "jobfeed.php",
   			dataType: "xml",
		
			beforeSend: function(){$('.job_navi').html("<i>loading data ...</i>")},
		
   			success: function(feed){
     			loadOtherJobsMenu(feed);
   			}
		
 	    });
 }
 
 function loadOtherJobsMenu(feed){
	 	
		var html = "<h1>Other jobs in US</h1>"
		html += "<ul>";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> <br /> <span class='office'>"+location+"</span></li>"
	});
	
	html += "</ul><hr />";
	
	html += "<h1>Other regions</h1>";
	
	html += "<ul><li><a href='jobs-R6.html'>Australia</a></li>";
	html += "<li><a href='jobs-R5.html'>Benelux</a></li>";
	html += "<li><a href='jobs-R4.html'>France</a></li>";
	html += "<li><a href='jobs-R3.html'>Germany</a></li>";
	html += "<li><a href='jobs-R13.html'>Greater China</a></li>";
	html += "<li><a href='jobs-R11.html'>India</a></li>";
	html += "<li><a href='jobs-R9.html'>Italy</a></li>";
	html += "<li><a href='jobs-R16.html'>Japan</a></li>";
	html += "<li><a href='jobs-R7.html'>Nordics</a></li>";
	html += "<li><a href='jobs-R10.html'>Poland</a></li>";
	html += "<li><a href='jobs-R12.html'>Singapore</a></li>";
	html += "<li><a href='jobs-R8.html'>Spain</a></li>";
	html += "<li><a href='jobs-R1.html'>UK</a></li>";
	html += "</ul><hr />";
	
	html += "<p class='more'><a href='jobs.html'>view all the jobs</a></p>";
	
	$('.job_navi').html(html);
 }
 
 
 function getUS() {
	 	$.ajax({
   			type: "POST",
   			url: "jobfeed.php",
   			dataType: "xml",
		
			beforeSend: function(){$('#main_content').html("<i>loading data ...</i>")},
		
   			success: function(feed){
     			loadRegUS(feed);
   			}
		
 	    });
 }
 
 function loadRegUS(feed){
	 var html = "<h1>careers - job opportunities</h1>";
	 html += "<h2>US</h2>";
	 html += "<ul>";
	
	$('job', feed).each(function() {
		//var title = $(this).find('title').text();
		//var pieces = title.split("-");
		//var jobTitle = trim(pieces[0]);
		//var location = trim(pieces[1]);
		var jobTitle = $(this).find('title').text();
		var location = ($(this).find('location').text()).replace(", United States", "");
		var href = $(this).find('detail-url').text();
		var q = href.split("?")[1];
		var ahref = $(this).find('apply-url').text();
		var a = ahref.split("?")[1];
		
		html += "<li><a href='#' onclick='loadJobInfo(\""+q+"\", \""+a+"\")'>"+jobTitle+"</a> - <span class='office'>"+location+"</span></li>"
	});
	
	html += "</ul>";
	
	$('#main_content').html(html);
	
	html = "<h1>Other regions</h1>";
	
	html += "<ul><li><a href='jobs-R6.html'>Australia</a></li>";
	html += "<li><a href='jobs-R5.html'>Benelux</a></li>";
	html += "<li><a href='jobs-R4.html'>France</a></li>";
	html += "<li><a href='jobs-R3.html'>Germany</a></li>";
	html += "<li><a href='jobs-R13.html'>Greater China</a></li>";
	html += "<li><a href='jobs-R11.html'>India</a></li>";
	html += "<li><a href='jobs-R9.html'>Italy</a></li>";
	html += "<li><a href='jobs-R16.html'>Japan</a></li>";
	html += "<li><a href='jobs-R7.html'>Nordics</a></li>";
	html += "<li><a href='jobs-R10.html'>Poland</a></li>";
	html += "<li><a href='jobs-R12.html'>Singapore</a></li>";
	html += "<li><a href='jobs-R8.html'>Spain</a></li>";
	html += "<li><a href='jobs-R1.html'>UK</a></li>";
	html += "</ul><hr />";
	
	html += "<p class='more'><a href='jobs.html'>view all the jobs</a></p>";
	
	$('.job_navi').html(html);
 }

 
 
 function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
 