function WindowOpen(vUrl, vWidth, vHeight, vScroll, vResize) {
	vLeft = (screen.availWidth - vWidth) / 2;
	vTop = (screen.availHeight - vHeight) / 2;
	if (!vScroll) vScroll = 'no';
	if (!vResize) vResize = 'no';
	parameters = '';
	parameters += 'toolbar=no,';
	parameters += 'location=no,';
	parameters += 'directories=no,';
	parameters += 'status=no,';
	parameters += 'menubar=no,';
	parameters += 'scrollbars=' + vScroll + ',';
	parameters += 'resizable=' + vResize + ',';
	parameters += 'left=' + vLeft + ',';
	parameters += 'top=' + vTop + ',';
	parameters += 'width=' + vWidth + ',';
	parameters += 'height=' + vHeight;
	wId = window.open(vUrl, 'NewWin' + GetRand(), parameters);
	wId.focus();
}

function GetRand() {
	result = '';
	result = Math.random() + '1';
	result = result.split('.');
	return result[1];
}

function stringTrim(strToTrim) {
	var tmp_str = new String(strToTrim);
	return (tmp_str.replace (/^\s+|\s+$/g, ''));
}

function CheckFrmSearch(oForm, vField) {
	vValue = eval(oForm + '.' + oField + '.value');
	vText = stringTrim(vValue);
	if (vText == '') {
		alert('Введите корректное значение поля поиска.');
		return false;
	}
	oForm.submit();
}

function SetCookie(sName, sValue) {
	document.cookie = sName + '=' + escape(sValue) + '; expires=Fri, 25 Dec 2020 23:59:59 GMT;';
}

function DelCookie(sName) {
	document.cookie = sName + '=; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
}

function GetCookie(sName) {
	var aCookie = document.cookie.split('; ');
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0]) return unescape(aCrumb[1]);
	}
	return null;
}

function ajaxBeforeSend(request, settings) {
	ajaxStart();
}
function ajaxComplete(request, settings) {
	ajaxStop();
}
function ajaxSuccess(request, settings) {
}
function ajaxError(request, settings) {
}

function ajaxStart(request, settings) {
	$('#ajaxIsProcess').attr('value', '1');
}
function ajaxStop(request, settings) {
	$.siteloadingout();
	$('#ajaxIsProcess').attr('value', '0');
}

function ajaxLink(vUri) {
	if ($('#ajaxIsProcess').attr('value') == 0) {
		$.siteloading();
		$.get(vUri, ajaxSetContent);
	}
}
function ajaxSetContent(data) {
	$('#framecontent').html(data);
	$('a').click(function () {
		rexp = /[\w-_]\.php/i;
		vHref = this.href;
		if (rexp.test(vHref)) {
			ajaxLink();
			return false;
		}
	});
}

jQuery.extend({
	siteloadingdefaults: {
		prefix: 'frameloading',
		container: 'body',
		opacity: 0.9,
		overlayspeed: 'slow'
	},
	setsiteloadingdefaults: function(o){ 
		jQuery.siteloadingdefaults = jQuery.extend({}, jQuery.siteloadingdefaults, o);
	},
	siteloadingout: function(o){
		o = jQuery.extend({}, jQuery.siteloadingdefaults, o);
		var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);
		var b = (ie6) ? jQuery(document.body) : jQuery(o.container);
		var jqif = $('#' + o.prefix);
		jqif.fadeOut(o.overlayspeed);
	},
	siteloading: function(o) {
		o = jQuery.extend({}, jQuery.siteloadingdefaults, o);
		var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);
		var b = (ie6) ? jQuery(document.body) : jQuery(o.container);
		var jqif = $('#' + o.prefix);
		var getfoffset = function() {
			return (document.documentElement.scrollTop || document.body.scrollTop) + 'px';
		};
		var ie6scroll = function() {
			jqif.css({top: getfoffset()});
		};
		jqif.css({
			position: 'absolute',
			height: (ie6) ? '100%' : b.height(),
			width: '100%',
			top: (ie6) ? getfoffset() : 0,
			left: 0,
			right: 0,
			bottom: 0,
			zIndex: 999,
			display: 'none',
			opacity: o.opacity
		});
		if(ie6) jQuery(window).scroll(ie6scroll);
		jqif.fadeIn(o.overlayspeed);
		return;
	}
});
