function showBigImage(image, width, height) {
	popupWin = window.open('/scripts/image.php?image=/'+image+'&w='+width+'&h='+height,'','width='+width+', height='+height+', left=100, top=10, directories=no, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no');
	popupWin.focus();
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function SetCheckbox(oThis) { 
	
	var cClass = $(oThis).attr('class');
	cClass = (cClass == 'no-checked' ? 'checked' : 'no-checked' );
	$(oThis).attr('class', cClass);
	
	var oCheckbox = $(oThis).next("input[type='checkbox']").eq(0);
	var checkValue = ( oCheckbox.attr('checked') == true ? false : true );
	oCheckbox.attr('checked', checkValue);

}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// AJAX-bugtracking: openDialog(dialogName), errorSendData(obj)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function openDialog(dialogName) {
	$("#" + dialogName).dialog("open");
}

// инициализация полей формы при открытии окна
function errorOpenDialog(dialogName) {
	$("#" + dialogName + '-form').css("display", "block");
	$("#" + dialogName).everyTime(2000, dialogName + '_timer', function() { errorValidateForm(dialogName); })
	
	var jForm = $("#" + dialogName + '-form');
	jForm.children("[name=errorType]").val(0);
	jForm.children("[name=errorComment]").val('');
	jForm.children("[name=errorButton]").addClass("btn-unactive");
	jForm.children("[name=errorButton]").removeClass("btn-active");
	jForm.children("[name=errorButton]").unbind('click');
	
	$("#" + dialogName + '-errmess').text('');
	$("#" + dialogName + '-succmess').text('');
}

// проверка на формы на заполение для активация кнопки
function errorValidateForm(dialogName, i) {
	var jForm = $("#" + dialogName + '-form');
	var jSelect = jForm.children("[name=errorType]");
	var jTextarea = jForm.children("[name=errorComment]");
	var jButton = jForm.children("[name=errorButton]");

	if ( jSelect.val() != 0 && jTextarea.val() != '' && !jButton.hasClass("btn-active") ) {
		jButton.removeClass("btn-unactive");
		jButton.addClass("btn-active");
		jButton.click( function() { errorSendData(dialogName) } );
	};
	
	if ( (jSelect.val() == 0 || jTextarea.val() == '') && !jButton.hasClass("btn-unactive") ) {
		jButton.removeClass("btn-active");
		jButton.addClass("btn-unactive");
		jButton.unbind('click');
	};
}

// ajax-отправка сообщения
function errorSendData(dialogName) {
	var jForm = $("#" + dialogName + '-form');
	var jErrMess = $("#" + dialogName + '-errmess');
	var jSuccMess = $("#" + dialogName + '-succmess');
	
	var jData = jForm.serialize();
	jErrMess.text();
	
	$.ajax({ 
		type: "POST",
		url: "/modulesAjax/errorPut.php",
		data: jData,
		success: function (msg) {
			jSuccMess.text(msg);
			jForm.css("display", "none");
		}
	});
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// AJAX - авторизация
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	function authInitContent(userName, authObj) {
	// определяет содержимое элементов авторизации
		if ( userName == '' ) {
			authObj['auth-mess'].css("display", "block").
				html("");
			authObj['auth-enter'].html("Войти").
				bind("click", authOpenDialog);
			if (document.getElementById('noauth-auth')) {
				authObj['noauth-auth'].
					bind("click", authOpenDialog);	
			}
			authObj['auth-form'].css("display", "block");
			authObj['auth-field-email'].css("display", "block");
			authObj['auth-field-pass'].css("display", "block");
			authObj['auth-btn-remind'].css("display", "none").
				bind("click", function() { authAjaxRemind(authObj); } );
			
			authObj['auth-link-remind'].css("display", "inline").
				bind("click", function() { authRemindView(authObj); } );
				
//			authObj['auth-link-register'].css("display", "block");
		} else {
			authObj['auth-room'].css("display", "block");
			authObj['auth-enter'].html("Выйти").
				unbind().
				bind("click", authAjaxUnauth);
			
			authObj['auth-mess'].html("Вы вошли как " + userName);
			authObj['auth-form'].css("display", "none");
		}
	}
	function authOpenDialog() {
	// открывает диалоговое окно
		var dialogName = 'dialog-auth';
		$("#" + dialogName).dialog("open");
	}
	function authCloseDialog() {
	// закрывает диалоговое окно
		alert('close dialog');
	}
	
	function authAjaxAuth(authObj) {
	// выполняет ajax-авторизацию
		var email = authObj['auth-field-email'].children("input").eq(0).val();
		var pass = authObj['auth-field-pass'].children("input").eq(0).val();
		var actionName = "auth";

		if ( email == '' || pass == '' ) {
			authObj['auth-mess'].html("Ошибка. Заполнены не все поля.");
		} else {
			var sendVars = new Object();
			sendVars['action'] = actionName;
			sendVars['email'] = email;
			sendVars['pass'] = pass;
			
			$.ajax({ 
				type: "POST",
				url: "/modulesAjax/auth.php",
				data: sendVars,
				dataType: "json",
				success: function (respVars) {
					if ( respVars['authmess'] != '' ) { 
						authObj['auth-mess'].html(respVars['authmess']);
					}
					if ( respVars['logon'] == 1 ) {
						authObj['auth-form'].css("display", "none");
						authObj['auth-room'].attr("href", respVars['roomPath']).
							css("display", "block");
						authObj['auth-enter'].html("Выйти").
							unbind("click", authOpenDialog).
							attr('href', '?unauth');
					}
				}
			});
		}
	}

	function authAjaxUnauth() {
	// выполняет ajax-выход
	}
	
	function authRemindView(authObj) {
	// готовит содержимое диалогового окна для вспоминания пароля
		authObj['auth-field-pass'].css("display", "none");
		authObj['auth-btn-remind'].css("display", "inline");
		authObj['auth-btn-enter'].css("display", "none");
		authObj['auth-link-remind'].
			html("ой, вспомнила").
			unbind().
			bind("click", function() { authRemindHide(authObj); } );
	}
	function authRemindHide(authObj) {
	// готовит содержимое диалогового окна для вспоминания пароля
		authObj['auth-field-pass'].css("display", "block");
		authObj['auth-btn-remind'].css("display", "none");
		authObj['auth-btn-enter'].css("display", "block");
		authObj['auth-mess'].css("display", "block").
				html("");
		authObj['auth-link-remind'].
			html("напомнить пароль").
			unbind().
			bind("click", function() { authRemindView(authObj); } );
	}
	function authAjaxRemind(authObj) {
	// выполняет отправку нового пароля
		var email = authObj['auth-field-email'].children("input").eq(0).val();
		var actionName = "remind";
		
		if ( email == '' ) {
			authObj['auth-mess'].html("Введите E-mail");
		} else {
			var sendVars = new Object();
			sendVars['action'] = actionName;
			sendVars['email'] = email;
			
			$.ajax({ 
				type: "POST",
				url: "/modulesAjax/remind.php",
				data: sendVars,
				dataType: "json",
				success: function (respVars) {
					if ( respVars['authmess'] != '' ) { 
						authObj['auth-mess'].html(respVars['authmess']);
					}
				}
			});
		}
		
	}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// AJAX - "позвать подругу"
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		function callOpenDialog(dialogName) {
			$("#" + dialogName + '-form').css("display", "block");
			var jForm = $("#" + dialogName + '-form');
			jForm.children("[name=callToEmail]").val('');

			var jButton = jForm.children("[name=callButton]");
			jButton.click( function() { callSendData(dialogName) } );
		}

		// ajax-отправка сообщения
		function callSendData(dialogName) {
			var jForm = $("#" + dialogName + '-form');
			var jMess = $("#" + dialogName + '-mess');
			var jData = jForm.serialize();
			jMess.text();
			
			$.ajax({ 
				type: "POST",
				url: "/modulesAjax/callFriend.php",
				data: jData,
				dataType: "json",
				success: function (respVars) {
					if ( respVars['authmess'] != '' ) { 
						jMess.text(respVars['authmess']);
						jForm.children("[name=callToEmail]").val('');
					}
				}
			});
		}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Установить куки
function setCookie(name, value) {
      var valueEscaped = escape(value);
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() + 365 * 24 * 60 * 60 * 1000); // срок - 1 год, но его можно изменить
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
}

// Получить куки
function getCookie(name) {
      var prefix = name + "=";
      var flag = '-1000';
      var cookieStartIndex = document.cookie.indexOf(prefix);
      if (cookieStartIndex == -1) return flag;
      var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
      if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
      return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
