var ajax = new sack();
var submenu = new sack();
var articleListObj;
var activeArticle = false;
var clickedArticle = false;
var contentObj;	// Reference to article content <div>
var captionObj;	// Reference to article content <div>
var menuListObj;
var nnn;

function str_replace(subject,search, replace) {
    return subject.split(search).join(replace);
}

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 showContent()	// Displaying content in the content <div>
{
	contentObj.innerHTML = ajax.response;	// ajax.response is a variable that contains the content of the external file
	initializeAfterResponse();
	//contentObj.innerHTML = "<input type='text' value='"+ajax.response+"'>");
    //alert('content '+ajax.response);	
}

function showWaitMessage(fileName)
{
	contentObj.innerHTML = 'Finding article.....<br>'+fileName+' <br>Please wait';
}

function showLoadingProgress()
{
contentObj.innerHTML = "<table width='820' height='230' ><tr align='center' valign='center'><td><img src='./images/progressbar.gif'></td></tr></table>";
}

function errorAjax()
{
	contentObj.innerHTML = "<table width='820' height='100' border=0><tr align='center'><td>Запрашиваемая информация не найдена, приносим извинения.</td></tr></table>";
}


function getAjaxFile(fileName,autoload)
{
    fileName = './info/'+fileName+'.info.php';
	ajax.requestFile = fileName;	// Specifying which file to get
	ajax.onCompletion = showContent;	// Specify function that will be executed after file has been found
	ajax.onLoading = showLoadingProgress; 
	ajax.onError = errorAjax;
	ajax.method='GET';

	ajax.runAJAX();		// Execute AJAX function	

}

function setCaption(caption,autoload)	// User have clicked on an article
{
	var gets = location.search;
	if ((gets.indexOf('staticpage') + 1)&&(autoload==1)){
		return;
	}
	captionObj.innerHTML = caption;
}

function selectArticle(articleFileName,autoload,caption)	// User have clicked on an article
{
    var gets = location.search;
	if ((gets.indexOf('staticpage') + 1)&&(autoload==1)){
		return;
	}
	getAjaxFile(articleFileName,autoload);	// Calling the getAjasFile function. argument to the function is id of this <li> + '.html', example "article1.html"
    if (caption != "")
       setCaption(caption,0); 
}

function selectPHP(fileName,autoload)
{
    var gets = location.search;
	if ((gets.indexOf('staticpage') + 1)&&(autoload==1)){
		return;
	}
	fileName = './'+fileName;
	ajax.requestFile = fileName;	// Specifying which file to get
	ajax.onCompletion = showContent;	// Specify function that will be executed after file has been found
	ajax.onLoading = showLoadingProgress; 
	ajax.onError = errorAjax;
	ajax.method='GET';

	ajax.runAJAX();		// Execute AJAX function	

}


function showNewsEntry(nRequest,autoload)
{
	var gets = location.search;
	if ((gets.indexOf('staticpage') + 1)&&(autoload==1)){
		return;
	}
    fileName = './news_entries.php?'+nRequest;
    ajax.onLoading = showLoadingProgress; 
	ajax.requestFile = fileName;
	ajax.onCompletion = showContent;
	ajax.onError = errorAjax;
	ajax.method='GET';
	ajax.runAJAX();	  
}


function initAjaxDemo()
{
	contentObj = document.getElementById('infoContainer');
	captionObj = document.getElementById('caption');	
	menuListObj = document.getElementById('menu_items_news');
}

function showNewsListContent()
{
    menuListObj.innerHTML = submenu.response; 
}

function showLoadingProgressMenu()
{
menuListObj.innerHTML = "<table width='100%' height='100' border=0><tr align='center'><td><img src='./images/progressbar.gif'></td></tr></table>";
}


function showNewsList(pageNo)
{
    fileName = './menu.php?newslist='+pageNo;
   	submenu.onLoading = showLoadingProgressMenu; 
	submenu.requestFile = fileName;	
	submenu.onCompletion = showNewsListContent;
	submenu.onError = errorAjax;
	submenu.method='GET';
	submenu.runAJAX();	  
}

function priceOver(x){ 
   x.style.backgroundColor='#cccccc';
} 

function priceOut(x){ 
   x.style.backgroundColor='';
}

  window.onload = initAjaxDemo;
