﻿var ajax_cursor_html = '<img src="' + SitePath + '/upload/images/js_123_cafe/hour_glass2.gif" width="25" height="24" alt="Пожалуйста, подождите, пока загрузятся данные с сервера.">';
var ajax_wait_message = 'Пожалуйста, подождите, пока загрузятся данные с сервера.';
var ajax_cursor_class_name = 'hour_glass';
var cursor_x_shift = -2;
var cursor_y_shift = -2;

function trim(s) {
	return rtrim(ltrim(s));
} // end function

function ltrim(s) {
	return s.replace(/^\s+/, ''); 
} // end function

function rtrim(s) {
	return s.replace(/\s+$/, ''); 
} // end function
function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
	{
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent)
		{
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
    	}
    }
    return [curleft,curtop];
}
function AddPageId(uri) {
	if (uri.indexOf('?') == -1) uri += '?';
	else if ((uri.charAt(uri.length - 1) != '?') && (uri.charAt(uri.length - 1) != '&')) uri += '&';
	uri += 'page.id=' + PageId;
	return uri;
}
function LoadPage(uri, divId, callback) {
	var div = document.getElementById(divId);
	if (div) {
		var event = 
			function (result) {
				div.style.visibility = "hidden";
				
				div.innerHTML = result;
				
                if (window.startAccordion) startAccordion();
				if (callback) eval(callback);
				div.style.visibility = "visible";
			} // end event
		HttpRequest(SitePath + AddPageId(uri), null, divId, event);		
	} // end if	
	return false;
} // end function

function ShowPhoto(link, image) {
	var div = document.getElementById("body");
	var popup = document.getElementById("fotka");
	if (div && popup) {
		var event = 
			function (result) {
				
				popup.style.top = findPos(link)[1]-100+"px";
				popup.style.left = (document.body.offsetWidth/2)-200+"px";
				popup.innerHTML = result;
				div.className="op";
				popup.style.display="block";
                //if (window.startAccordion) startAccordion();
				//if (callback) eval(callback);
			} // end event
		if (image) {
			HttpRequest(SitePath + AddPageId("/AJAX/getmenuimage.aspx?image="+image), null, popup, event);
		} else {
			HttpRequest(SitePath + AddPageId("/AJAX/getmenuimage.aspx?image=no-image.gif"), null, popup, event);
		}

	} // end if
}

function HidePhoto() {	
	var div = document.getElementById("body");
	var popup = document.getElementById("fotka");
	div.className="";
	popup.style.display="none";
}

function DynamicBanner(divId, bannerId, positionId)
{
	this.div = document.getElementById(divId);
	this.bannerId = bannerId;
	this.positionId = positionId;
	this.ajaxUrl = 'AJAX/GetNextBanner.aspx?';
	var self = this;
	var reload = function()
	{
		var event = 
		function (result) {
		    var root = XmlRootByText(result);
   	        var currentBannerId = GetXmlNodeValue(GetXmlNodeByTagName(root, 'CurrentBannerId'));
			if (self.bannerId != currentBannerId) {
			
				self.div.innerHTML = GetXmlNodeValue(GetXmlNodeByTagName(root, 'HtmlContent'));
				self.bannerId = currentBannerId;
			}
			
		} // end event
		HttpRequest(SitePath + AddPageId(self.ajaxUrl + 'currentBannerId=' + self.bannerId + '&positionId=' + self.positionId), null, null, event);	
		window.setTimeout(reload, 5000);
	}
	window.setTimeout(reload, 5000);
	//window.setInterval(reload, 5000);
}

function addLoadEvent(func) 
{ 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function'){ 
        window.onload = func; 
    } else {
        window.onload = function(){ 
            oldonload(); 
            func();
        } 
    } 
}
