/**
* Friction TV - companys.js
* 
* functions for login page
* 
* @author						Neil Young neil.young@neilyoungcv.com
* @version						0.9
* @todo							???
* 
*/

/**
* @var object http
*/

var http = createRequestObject();

/**
* Friction TV - companys.js - createRequestObject
* 
* create an ajax request object
* 
* @author						Neil Young neil@friction.tv
* @version						0.9
* @todo							???
* 
*/

function createRequestObject() 
{
	
	try 
	{ 
		return new XMLHttpRequest(); 
	
	} 
	catch(e)
	{
		
		//alert("There was a problem with XMLHttpRequest");
		
	}
   
	try
	{ 
		
		return new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch (e)
	{
		
		//alert("There was a problem with ActiveXObject(Msxml2.XMLHTTP)");
		
	}
   
	try 
	{ 
		
		return new ActiveXObject("Microsoft.XMLHTTP"); 
	
	} 
	catch (e) 
	{
		
		//alert("There was a problem with ActiveXObject(Microsoft.XMLHTTP)");
		
	}
   
	alert("XMLHttpRequest not supported");
   
	return null;
 
}

/**
* Friction TV - companys.js - atAGlance()
* 
* shows each company at a glance
* 
* @author						Neil Young neil.young@neilyoungcv.com
* @version						0.9
* @todo							???
*
* @param int					offset
* @param int					max
*
*/

function atAGlance(offset, max)
{
	
	document.getElementById('glance_script_form').style.display = 'block';
	
	url = 'http://' + document.location.hostname + '/ajax.php?call=companys_at_a_glance&params=' + offset + '|' + max + '';
		
	http.open('POST', url, false);
	
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http.send(url);

	var response = http.responseXML;
	
	var moreCompanys = response.getElementsByTagName("moreCompanys")[0].childNodes[0].nodeValue;
	
	var nextButton = document.getElementById("next_button");
	
	var previousButton = document.getElementById("previous_button");
	
	nextButton.innerHTML = "";
	
	previousButton.innerHTML = "";
	
	var moreLink = document.getElementById("more_link");
	
	if (moreCompanys == 1 && offset == 0)
	{

		document.getElementById("company_src").src = 'http://images.neilyoungcv.com/companys/' + response.getElementsByTagName("companyId")[0].childNodes[0].nodeValue + '_small.png';
		
		document.getElementById("company_src").alt = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;
	
		document.getElementById("company_name").innerHTML = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		
		document.getElementById("company_dates").innerHTML = '<span style="color:#FFF">From:</span> ' + response.getElementsByTagName("dateFrom")[0].childNodes[0].nodeValue + '<br/><span style="color:#FFF">To:</span> ' + response.getElementsByTagName("dateTo")[0].childNodes[0].nodeValue;

		anchorNext = document.createElement('a');
	
		anchorNext.setAttribute('onclick', 'atAGlance(' + (offset + 1) + ', ' + max + ')');
		
		// for IE6+7
		
		anchorNext.onclick = function() { atAGlance((offset + 1), max); }
		
		//
		
		divNext = document.createElement('div');
		
		divNext.setAttribute('class', 'nycv_glance_next_off');
		
		// for IE6+7
		
		divNext.className = "nycv_glance_next_off";

		anchorNext.appendChild(divNext);
		
		nextButton.appendChild(anchorNext);
		
		moreLink.innerHTML = "Details...";
		
		moreLink.setAttribute('href', response.getElementsByTagName("rewriteUrl")[0].childNodes[0].nodeValue);

	}
	else if (moreCompanys == 1)
	{
		
		document.getElementById("company_src").src = 'http://images.neilyoungcv.com/companys/' + response.getElementsByTagName("companyId")[0].childNodes[0].nodeValue + '_small.png';
		
		document.getElementById("company_src").alt = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;
	
		document.getElementById("company_name").innerHTML = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;

		document.getElementById("company_dates").innerHTML = '<span style="color:#FFF">From:</span> ' + response.getElementsByTagName("dateFrom")[0].childNodes[0].nodeValue + '<br/><span style="color:#FFF">To:</span> ' + response.getElementsByTagName("dateTo")[0].childNodes[0].nodeValue;

		anchorPrevious = document.createElement('a');
	
		anchorPrevious.setAttribute('onclick', 'atAGlance(' + (offset - 1) + ', ' + max + ')');
		
		// for IE6+7
		
		anchorPrevious.onclick = function() { atAGlance((offset - 1), max); }
		
		//
		
		divPrevious = document.createElement('div');
		
		divPrevious.setAttribute('class', 'nycv_previous_off');
		
		// for IE6+7
		
		divPrevious.className = "nycv_previous_off";
		
		anchorPrevious.appendChild(divPrevious);
		
		previousButton.appendChild(anchorPrevious);

		anchorNext = document.createElement('a');
	
		anchorNext.setAttribute('onclick', 'atAGlance(' + (offset + 1) + ', ' + max + ')');
		
		// for IE6+7
		
		anchorNext.onclick = function() { atAGlance((offset + 1), max); }
		
		//
		
		divNext = document.createElement('div');
		
		divNext.setAttribute('class', 'nycv_glance_next_off');
		
		// for IE6+7
		
		divNext.className = "nycv_glance_next_off";
		
		//
		
		anchorNext.appendChild(divNext);
		
		nextButton.appendChild(anchorNext);
		
		moreLink.innerHTML = "Details...";
		
		moreLink.setAttribute('href', response.getElementsByTagName("rewriteUrl")[0].childNodes[0].nodeValue);
	
	}
	else
	{
		
		document.getElementById("company_src").src = 'http://images.neilyoungcv.com/companys/' + response.getElementsByTagName("companyId")[0].childNodes[0].nodeValue + '_small.png';
		
		document.getElementById("company_src").alt = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;
	
		document.getElementById("company_name").innerHTML = response.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		
		document.getElementById("company_dates").innerHTML = '<span style="color:#FFF">From:</span> ' + response.getElementsByTagName("dateFrom")[0].childNodes[0].nodeValue + '<br/><span style="color:#FFF">To:</span> ' + response.getElementsByTagName("dateTo")[0].childNodes[0].nodeValue;
		
		anchorPrevious = document.createElement('a');
	
		anchorPrevious.setAttribute('onclick', 'atAGlance(' + (offset - 1) + ', ' + max + ')');
		
		// for IE6+7
		
		anchorPrevious.onclick = function() { atAGlance((offset - 1), max); }
		
		//
		
		divPrevious = document.createElement('div');
		
		divPrevious.setAttribute('class', 'nycv_previous_off');
		
		// for IE6+7
		
		divPrevious.className = "nycv_previous_off";
		
		//
		
		anchorPrevious.appendChild(divPrevious);
		
		previousButton.appendChild(anchorPrevious);
		
		moreLink.innerHTML = "Details...";

		moreLink.setAttribute('href', response.getElementsByTagName("rewriteUrl")[0].childNodes[0].nodeValue);
		
	}

}

// done