﻿ var ajax_cursor_html = '<img src="./images/loading.gif" width="32" height="32" alt="Подождите...">';
var ajax_wait_message = 'Пожалуйста, подождите, пока загрузятся данные с сервера.';
var ajax_cursor_class_name = 'hour-glass';
var cursor_x_shift = -12;
var cursor_y_shift = -12;
var SitePath = "";
var PageId = "";

function ProcessCommonRequest(uri, container, callback) {
	if (container) {
		var event =
			function (result) {
				container.innerHTML = result;
                if (window.startAccordion) startAccordion();
				if (callback) callback();
			} // end event
		HttpRequest(SitePath + uri, null, 'common', event);
	} // end if
	return false;
} // end function

function addtocompare(){};

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 SimpleAjaxRequest(uri, ajaxId){
	HttpRequest(SitePath + AddPageId(uri), null, ajaxId, null);
	return false;
}


function LoadPage(uri, divId) {
	var div = document.getElementById(divId);
	if (div) {
		var event =
			function (result) {
				div.innerHTML = result;
                if (window.startAccordion) startAccordion();
			} // end event
		HttpRequest(AddPageId(uri), null, divId, event);
	} // end if
	return false;
} // end function

/*
function LoadPage(uri, divId, callback) {
	var div = document.getElementById(divId);
	if (div) {
		var event =
			function (result) {
				div.innerHTML = result;
                if (window.startAccordion) startAccordion();
				if (callback) eval(callback);

			} // end event
		HttpRequest( AddPageId(uri), null, divId, event);
	} // end if
	return false;
} // end function
*/

function GetPageByPost(formId, uri, divId) {
	var div = document.getElementById(divId);
	var form = document.getElementById(formId);
	var data = '';
	if (form) {
	    var frm = form.elements;
	    for (i = 0; i < frm.length; i++)
	    {
		    var element = frm[i];
		    if (element.name == "") continue;
			if ( ((element.type == "checkbox") || (element.type == "radio")) &&
				!element.checked) continue;
 		    data += element.name + '=' + encodeURIComponent(element.value) + '&';
	    }
	}
	if (div) {
		var event =
			function (result) {
				div.innerHTML = result;
                if (window.startAccordion) startAccordion();
			} // end event
		HttpRequest(SitePath + AddPageId(uri), data, divId, event);
	} // end if
	else
		HttpRequest(SitePath + AddPageId(uri), data, 'ajax', null);

	return false;
} // end function

function StandardAjaxAction(form, ajaxUrl, ajaxId, div, alertOnSuccess) {
	var data = '';
	if (form) {
	    var frm = form.elements;
	    for (i = 0; i < frm.length; i++)
	    {
		    var element = frm[i];
		    if (element.name == "") continue;
		    if ((element.type) && (element.type == 'password') &&
		        (element.defaultValue) && (element.defaultValue == element.value) )
		        element.value = '';
 		    data += element.name + '=' +
 		        (((element.defaultValue) && (element.defaultValue == element.value) && (element.type) && (element.type != 'hidden')) ?
 		        '' : encodeURIComponent(element.value)) +
 		        '&';
	    }
	}
	var event =
		function (result) {
		    var root = XmlRootByText(result);
		    var returnCode = GetXmlNodeValue(GetXmlNodeByTagName(root, 'Result'));
		    if (alertOnSuccess || (returnCode != '0'))
    	        alert(GetXmlNodeValue(GetXmlNodeByTagName(root, 'ErrorMessage')));
		    if (returnCode == '0') {
		        var successEvent = GetXmlNodeValue(GetXmlNodeByTagName(root, 'SuccessEvent'));
    	        if (div) {
					div.innerHTML = GetXmlNodeValue(GetXmlNodeByTagName(root, 'HtmlContent'));
				}
    	        if (successEvent != '') eval(successEvent);
		    };
		} // end event
	HttpRequest(SitePath + AddPageId(ajaxUrl), data, ajaxId, event);
	return false;
} // end function

function LoadMapPage(uri, divId, mansionId, divMap, scale) {
	var div = document.getElementById(divId);
	if (div) {
		var event =
			function (result) {
				div.innerHTML = result;
                if (window.startAccordion) startAccordion();
				LoadMap(mansionId, divMap, scale);
			} // end event
		HttpRequest(SitePath + AddPageId(uri), null, divId, event);
	} // end if
	return false;
} // end function

function ShowEmailDiv(id){
	var link = document.getElementById('sendByEmailLink'+id);
/*	link.style.visibility = "hidden";
	link.style.position = "absolute";*/
	link.style.display = "none";
	var div = document.getElementById('sendDiv'+id);
/*	div.style.visibility = "visible";
	div.style.height = "30px";*/
	div.style.display = "inline";
	return false;
}

function HideEmailDiv(id){
	var link = document.getElementById('sendByEmailLink'+id);
/*	link.style.visibility = "visible";
	link.style.position = "static";*/
	link.style.display = "inline";
	var div = document.getElementById('sendDiv'+id);
	/*div.style.visibility = "hidden";
	div.style.height = "0px";*/
	div.style.display = "none";
}
