var ajax = new sack();
var ajax2 = new sack();
var ajax3 = new sack();
var articleListObj;
var articleListObj2;
var articleListObj3;
var activeArticle = false;
var clickedArticle = false;
var contentObj;
var contentObj2;
var contentObj3;


var articleCache = new Array();

simpleContentPath='helpcenter.action?content=simple_content&id=';
topicListPath='helpcenter.action?content=topic_list&id=';
topicContentPath='helpcenter.action?content=topic_content&id=';

function toggleQuestionsAndAnswers( show ) {
		if ( show ) {
			$('#questionsAndAnswers').show();
		}
		else {
			$('#questionsAndAnswers').hide();
		}
	}	
	
function toggleExample( show ) {
		if ( show ) {
			$('#viewExample').show();
		}
		else {
			$('#viewExample').hide();
		}
	}

function mouseoverArticle()	// Highlight article
{
	if(this==clickedArticle)return;
	if(activeArticle && activeArticle!=this){
		if(activeArticle==clickedArticle)
			activeArticle.className='articleClick';
		else
			activeArticle.className='';
		
	}
	this.className='articleMouseOver';
	activeArticle = this;	// Storing reference to this article
}

function fetchFromCache( key ) {
	var cached = articleCache[ key ];
	return cached; 
}

function storeToCache( key, data ) {
	articleCache[ key ] = data;
}

function showContent()	// Displaying content of GET QUESTION & ANSWERS POPUP'S CONTENT
{
	contentObj.innerHTML = ajax.response;	// ajax.response is a variable that contains the content of the external file
	storeToCache( ajax.requestFile, ajax.reponse );	
}

function showContent2()	// Displaying content of HELP BOXES
{	
	contentObj2.innerHTML = ajax2.response;	// ajax.response is a variable that contains the content of the external file
	storeToCache( ajax2.requestFile, ajax2.response );	
}

function showContent3()	// Displaying content of HELP BOXES
{
	contentObj3.innerHTML = ajax3.response;	// ajax.response is a variable that contains the content of the external file
	
	storeToCache( ajax3.requestFile, ajax3.response );	
}

function showWaitMessage() // showWaitMessage GET QUESTION & ANSWERS POPUP'S CONTENT
{
	contentObj.innerHTML = 'Loading content...';
}

function showWaitMessage2() // showWaitMessage HELP BOXES
{
	contentObj2.innerHTML = 'Loading content...';
}

function showWaitMessage3() // showWaitMessage HELP BOXES
{
	contentObj3.innerHTML = 'Loading content...';
}

function getAjaxFile(fileName) //GET QUESTION & ANSWERS POPUP'S LIST
{
	var cached = fetchFromCache( fileName );
	if ( cached != null ) {
		contentObj.innerHTML = cached;
	}
	else {
		ajax.requestFile = fileName;	// Specifying which file to get
		ajax.onCompletion = showContent;	// Specify function that will be executed after file has been found
		ajax.onLoading = showWaitMessage;	// Action when AJAX is loading the file
		ajax.runAJAX();		// Execute AJAX function	
	}
}

function getAjaxFile2(fileName2) //HELP BOXES
{
	var cached = fetchFromCache( fileName2 );
	if ( cached != null ) {
		contentObj2.innerHTML = cached;
	}
	else {
		ajax2.requestFile = fileName2;	// Specifying which file to get
		ajax2.onCompletion = showContent2;	// Specify function that will be executed after file has been found
		ajax2.onLoading = showWaitMessage2;	// Action when AJAX is loading the file
		ajax2.runAJAX();		// Execute AJAX function
	}	
}

function getAjaxFile3(fileName3) //HELP BOXES
{
	var cached = fetchFromCache( fileName3 );
	if ( cached != null ) {
		contentObj3.innerHTML = cached;
	}
	else {
		ajax3.requestFile = fileName3;	// Specifying which file to get
		ajax3.onCompletion = showContent3;	// Specify function that will be executed after file has been found
		ajax3.onLoading = showWaitMessage3;	// Action when AJAX is loading the file
		ajax3.runAJAX();		// Execute AJAX function
	}	
}

function selectInnerArticle() {
	$('#questionsAndAnswers').show();
	getAjaxFile(topicContentPath+this.id);	// Calling the getAjasFile function. argument to the function is id of this <li> + '.html', example "article1.html"
	if( clickedArticle && clickedArticle != this ) {
		clickedArticle.className='articleMouseOver';
	}
	this.className='articleClick';
	clickedArticle = this;
}

function selectArticle2()	// User have clicked on an article
{
	getAjaxFile2(simpleContentPath+this.id);	// Calling the getAjasFile function. argument to the function is id of this <li> + '.html', example "article1.html"
}

function selectArticle3()	// User have clicked on an article
{	
	getAjaxFile3(topicContentPath+this.id);	// Calling the getAjasFile function. argument to the function is id of this <li> + '.html', example "article1.html"
}

function initAjaxList( eleId ) {
	var element = document.getElementById( eleId );
	var articles = element.getElementsByTagName('LI');
	for(var no=0;no<articles.length;no++){
		articles[no].onclick = selectInnerArticle;
	}
	
}

function initAjaxDemo( id )
{ 
/* GET QUESTIONS & ANSWERS POP UP CONTENT */
	var articleListObj = document.getElementById( id );
	var articles = articleListObj.getElementsByTagName('LI');
	for(var no=0;no<articles.length;no++){
		if ( articles[no].className == "topicListClass" ) {
				articles[no].onclick = function() {
				showPop(articles[no],'questionsAndAnswers');
				getAjaxFile(topicContentPath+this.id);	// Calling the getAjasFile function. argument to the function is id of this <li> + '.html', example "article1.html"
				$('#articleListContainer').html( $( '#'+id ).html() );
				initAjaxList( 'articleListContainer' );
			};
		}
	}
	contentObj = document.getElementById('contentContainer');
}

function initQMarks()
{	
/**********************************************/

/*HELP BOXES*/	
	articleListObj2 = document.getElementById('main');
	var articles2 = articleListObj2.getElementsByTagName('IMG');
	for(var no=0;no<articles2.length;no++){
		if (articles2[no].className=="helpIMG")
			articles2[no].onmouseover = selectArticle2;
	}	
	
	contentObj2 = document.getElementById('contentContainer2');
	
/****************************************************/
initA();
	contentObj = document.getElementById('contentContainer');
}

function initA()
{	
/**********************************************/

/*HELP BOXES*/	
	articleListObj3 = document.getElementById('main');
	var articles3 = articleListObj3.getElementsByTagName('TT');
	for(var no=0;no<articles3.length;no++){
		if (articles3[no].className=="helpA")
			articles3[no].onmouseover = selectArticle3;
	}	
	
	contentObj3 = document.getElementById('theContent');
/****************************************************/
}

function showQList(qlist){
$('#'+qlist).load(topicListPath+qlist, null, function() {initAjaxDemo( qlist );});
}

window.onload=initQMarks;
