var req;
var target;
var isIE;
var pdf;

function initRequest(url) 
{
    if (window.XMLHttpRequest) 
	{
        req = new XMLHttpRequest();
		//alert("Created XMLHttpRequest object probably because you are NOT using IE");
    } 
	else if (window.ActiveXObject) 
	{
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
		//alert("Created ActiveX object because you ARE using IE");
    }
	return req;
}

function returnGuides(id,element,countLis,pdf,lang,itemTitle)
{		
	var url = "/ajax/guideresponder.php?g="+id+"&lang="+lang+"&itemtitle="+itemTitle;
    initRequest(url);
    
    setPdfLink(pdf);
    
    if(lang == "en")
    {
    	setPrintMsg("Print Version");
    	setDownloadMsg("Download Guide PDF");
    }
    else if(lang == "fr")
    {
    	setPrintMsg("Imprimer la version");
    	setDownloadMsg("T&eacute;l&eacute;charger le fichier PDF");
    }
    else
    {
    	setPrintMsg("Print Version");
    	setDownloadMsg("Download Guide PDF");
    }
	
	req.onreadystatechange = processGuideContent;
		
	req.open("GET", url, true); 
    req.send(null);
}

function linkBullet(element,countLis)
{
	for(i=0; i<countLis; i++)
	{
		if(document.getElementById("li_"+(i+1)))
			document.getElementById("li_"+(i+1)).style.backgroundImage = "";
	}
	
	bulletImg = "url(/images/bullet_grey_arrow.gif)";
	document.getElementById(element).style.backgroundImage = bulletImg;
}

function getFocus()
{
	document.getElementById('top').focus();
}
// Set the PDF Link
function setPdfLink(pdf)
{
	this.pdf = pdf;
}
function setPrintMsg(pmsg)
{
	this.pmsg = pmsg;
}
function setDownloadMsg(dmsg)
{
	this.dmsg = dmsg;
}
// Get the PDF Link
function getPdf()
{
	return pdf;
}
function getPrintMsg()
{
	return pmsg;
}
function getDownloadMsg()
{
	return dmsg;
}
function processGuideContent() 
{
    if (req.readyState == 4) 
	{
        if (req.status == 200) 
		{
			var id = req.responseXML.getElementsByTagName("id")[0].childNodes[0].nodeValue; // id
			var title = req.responseXML.getElementsByTagName("title")[0].childNodes[0].nodeValue; // title
			var introtext = req.responseXML.getElementsByTagName("introtext")[0].childNodes[0].nodeValue; // introtext
			var message = "";
			
			var status = "status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no";
			
			var printStatus = "";
			var printLink = "/index2.php?option=com_content&task=view&id="+id+"&Itemid=1&pop=1&page=0";
			
			message += '<a onclick="window.open(\''+printLink+'\',\'win2\',\''+status+'\')" style="cursor:pointer" return false;">'+getPrintMsg()+'</a><img class="media_icon" src="/images/icon_printer.gif" alt="" width="15" height="15" />';
			message += '<a onclick="window.open(\''+getPdf()+'\',\'win2\',\''+status+'\')" style="cursor:pointer" return false;">';
			message += getDownloadMsg()+'</a><img class="media_icon" src="/images/icon_pdf.gif" alt="" width="16" height="16" />';
			message += "<h3>"+title+"</h3>"+introtext;
			
			document.getElementById('gcopy').innerHTML=message;
		}
    }
}
