var xmlHttp = null;

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		xmlHttp.overrideMimeType('text/xml');
	}catch (e){
	// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function ajaxShowJob(id){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX. Please update update to the most recent version of Firefox, Opera or Internet Explorer");
	  return;
	} 

	xmlHttp.onreadystatechange = function(){
	if (xmlHttp.readyState==4){ 
		if (xmlHttp.status == 200) {
			showJobDetails(xmlHttp, id);
		}else{
			// problem with request
			document.getElementById("job"+id).innerHTML='An error has occured. We\'re sorry.';
		}
	}else{
		//waiting
		document.getElementById("job"+id).innerHTML='<div style="height:20px;text-align:center;line-height:20px;vertical-align:middle;">&nbsp;<img src="/scripts/loadingAnimation.gif" />&nbsp;</div>';
	}
	}
	var url="/ajaxLoader.php";
	url=url+"?id="+id;
	url=url+"&sid="+Math.random();
	xmlHttp.open('GET', url, true);                  
	xmlHttp.send(null);
}
function showJobDetails(xmlHttp, id){ 
	var file = xmlHttp.responseXML;   // Assign the XML file to a var

	var root = file.getElementsByTagName('job').item(0)
	
	var page = '<table cellpadding="0" cellspacing="0" border="0" style="width:100%;"><tr><td style="background-color:#ebe11c;font-size:12px;font-weight:bold;padding:5px 0px 5px 15px;text-align:left;border-top:2px solid #ffffff;"><a href="#" onclick="javascript:ajaxCloseJob(\''+id+'\'); return false;" style="float:right;margin-right:10px;text-decoration:none;">[X] Close</a>'+file.getElementsByTagName('title')[0].childNodes[0].nodeValue+'</td></tr><tr><td style="background-color:#d5d2d2;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;">Job Description:</td><tr><tr><td style="background-color:#e9e9e9;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;">'+file.getElementsByTagName('description')[0].childNodes[0].nodeValue+'</td><tr><tr><td style="background-color:#d5d2d2;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;">Download Application:</td><tr><tr><td style="background-color:#e9e9e9;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;"><a href="/uploaded/pdfs/ApplicationforEmployment.pdf" target="_blank"><img src="/uploaded/Miscellaneous%20Images/pdficon_grey.jpg" border="0" alt="" width="39" height="41" align="middle" /> Application Form Kilbirnie Pak\'n Save.pdf</td><tr><tr><td style="background-color:#d5d2d2;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;">Contact Details:</td><tr><tr><td style="background-color:#e9e9e9;font-size:11px;padding:5px 0px 5px 15px;text-align:left;border-top:1px solid #ffffff;"><strong>Name:</strong> '+file.getElementsByTagName('contact_name')[0].childNodes[0].nodeValue+'<br /><strong>Email: </strong><a href="mailto:'+file.getElementsByTagName('contact_email')[0].childNodes[0].nodeValue+'?subject=Job Applications">'+file.getElementsByTagName('contact_email')[0].childNodes[0].nodeValue+'</a></td><tr></table>';

	document.getElementById("job"+id).innerHTML=page; 
}
function ajaxCloseJob(id){
	document.getElementById("job"+id).innerHTML='';
}