function AJAXRequest(url,callback)
{
	this.url=url;
	this.callback=callback;
	this.xmlRequest = getXMLHTTPObject();
	var self=this;
	this.xmlRequest.onreadystatechange = function() 
	{
		if (self.xmlRequest.readyState==4 || self.xmlRequest.readyState=="complete")
			{
			self.callback(self.xmlRequest.responseText);
			} 
	}
}

AJAXRequest.prototype.send = function()
{
	this.xmlRequest.open("GET",this.url,true);
	this.xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	this.xmlRequest.send(this.url);
}

function DisplayJobFeed(xmlstring)
{	
	setInnerHTML('cc_jobs','<div class="loading"><div style="padding-top: 140px;"><img src="/app/images/cc_ajax-loader.gif" style="padding-bottom: 4px;"><br>LOADING JOBS...</div></div>');
	// convert string to XML object
	xmlobject=GetXMLObject(xmlstring);
	/* */
	// get a reference to the root-element "rss"
	var root = xmlobject.getElementsByTagName('rss')[0];
	// get reference to "channel" element
	var channels = root.getElementsByTagName("channel");
	
	// now get all "item" tags in the channel
	var items = xmlobject.getElementsByTagName("item");
	
	var listing="";
	var postingclass;
	for(var i=0;i<items.length;i++)
		{
		// in the "item" we have a description, so get that
		var description = items[i].getElementsByTagName("description")[0];
		// we also get the "pubDate" element in the "item"
		var date = items[i].getElementsByTagName("pubDate");
		var location = items[i].getElementsByTagName("location");
		var titlecompany = items[i].getElementsByTagName("title")[0].firstChild.data.split('|');
		var link = items[i].getElementsByTagName("link")[0];
		if(i%2)
			postingclass='cc_posting_even';
		else
			postingclass='cc_posting_odd';
		listing+='<div class="'+postingclass+'"><div class="cc_title"><a href="'+link.firstChild.data+'" class="cc_a cc_title link12">'+titlecompany[0]+'</a></div><div class="cc_company"><b>Company:</b> '+titlecompany[1]+'</div><div class="cc_description">'+description.firstChild.data+'...</div><div class="cc_detaillink link12"><a href="'+link.firstChild.data+'" class="cc_a cc_detaillink link12">View full job description</a></div></div>';
		}
	setInnerHTML('cc_jobs',listing+'<span style="float: right; margin-top: -18px;"><a href="http://careercenter.spie.org/search/results/" class="cc_a cc_detaillink" class="link12">View all job postings</a></span>');
}

function DisplayExperts(responseText)
{
	eval("var data = ["+responseText+"]");	if(data[0].type=='experts')
		{
		var title='In the Workplace';
		var html='<div class="cc_title" style="padding-bottom: 0;"><a href="http://spieworks.com/employment/index.cfm?action=greatminds&id='+data[0].id+'" class="cc_a cc_title">'+data[0].title+'</a></div><div class="cc_company"><b>'+data[0].name+'</b></div><div class="cc_company">'+data[0].affiliation+'</div><div><a href="http://spieworks.com/employment/index.cfm?action=greatmindslist" class="cc_a cc_detaillink">more &raquo;</div>';
		}
	else
		{
		var title='Advice from Recruiters';
		var html='<div class="cc_title" style="padding-bottom: 0;"><a href="http://spieworks.com/employment/index.cfm?action=recruiters&id='+data[0].id+'" class="cc_a cc_title">'+data[0].name+'</a></div><div class="cc_company"><b>'+data[0].title+'</b></div><div class="cc_company">'+data[0].affiliation+'</div><div><a href="http://spieworks.com/employment/index.cfm?action=recruiterslist" class="cc_a cc_detaillink">more &raquo;</div>';
		}
	html='<div class="cc_tab"><a href="" class="cc_tab">'+title+'</a></div><span style="float: left; padding: 0 7px 20px 0;"><img src="http://spieworks.com/images/greatminds/'+data[0].image+'" alt="'+data[0].name+'" border="0"></span>'+html;
	setInnerHTML('cc_'+data[0].type,html);
	
}

function DisplayFeatured(responseText)
{
	eval("var data = ["+responseText+"]");
	var html='';
	for(var i=0;i<data.length;i++)
		{
		html+='<div style="padding: 10px 0 10px 0;"><a href="http://spieworks.com/employment/index.cfm?action=comp_profile&comp_id='+data[i].id+'"><img src="http://spieworks.com/images/logos/thumbnails/'+data[i].logo+'" alt="'+data[i].company+'" border="0"></a></div>';
		}
	setInnerHTML('cc_featured',html);
	
}
	
function LoadJobFeed(count)
{
	if(count==undefined)
		count=3;
	var request=new AJAXRequest('/app/careercenter/rss.cfm?sn='+count,DisplayJobFeed);
	request.send();
}

function LoadExperts(type)
{
	if(type==undefined)
		type='experts';
	var request=new AJAXRequest('/app/careercenter/experts.cfm?type='+type,DisplayExperts);
	request.send();
}

function LoadFeatured(count)
{
	if(count==undefined)
		count=5;
	var request=new AJAXRequest('/app/careercenter/featured.cfm?count='+count,DisplayFeatured);
	request.send();
}