
jQuery.fn.center = function() {
	var w = $(window);
	this.css("position","absolute");
	this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
	return this;
}


function UserLogin() {

	var url = '/ajax?action=login&' + $('#loginForm').serialize() + '&r=' + Math.round(Math.random() * 6);

	$.getJSON(url, 
		function(data) {
		
        	if (data.Error) {
        		var pos = $('#login_u').offset();
        		
        		if ( $('#err').length == 0 ) $(document.body).append('<div id="err"></div>');
        		else $('#err').show().stopTime('hi');	
        		
        		$('#err').css({top: (pos.top + $('#login_u').height() + 4 + 'px'), left: (pos.left + 'px')})
        		$('#err').html(data.Error).oneTime('2s', 'hi', function () { $('#err').hide(400);});
       		
        		return;
        	}
        	
        	if ( data.OK ) document.location.href = document.location;
        	
    	});
	return false;
}


function createIframeWindow(params) {
	createBackgroundDiv();
	
	if ( $('#lbl_iframe').length == 0 ) $(document.body).append('<div id="lbl_iframe"></div>');
	$('#lbl_iframe').css({width: params.width + 'px', height: params.height + 'px'}).show();
	$("#lbl_iframe").html('<iframe src="' + params.url + '" frameborder="0" style="width:100%;height:100%;"></iframe>');
	$('#lbl_iframe').center();
}

function IframeWindowClose() {
	BackgroundDivClose();
	parent.document.getElementById('lbl_iframe').style.display='none';
}

function BackgroundDivClose() {
	parent.document.getElementById('lbl_background_div').style.display='none';
}

function createBackgroundDiv() {
	if ( $('#lbl_background_div').length == 0 ) $(document.body).append('<div id="lbl_background_div"></div>');
	$('#lbl_background_div').show();
	$('#lbl_background_div').css({width: $(document.body).width() + 16 + 'px', height: $(document.body).height() + 15 + 'px', top: '0px', left: '0px'});
}

// 
function banners_update() {
	
	var arr = new Array();
	
	$(".ban").each(function(i){
		arr[i] = {id: this.id, type: this.title};
	});
	
	for (i = 0; i < arr.length; i++) {
		$.getJSON('http://vashtest.ru/adv/b/' + arr[i].type + '/?ajax=1&lbl_id=' + arr[i].id + '&jsoncallback=?', function (data) {
				$('#' + data.lbl_id).replaceWith(data.html);
			});
	}
}

function errorHandler(e) {
	return true;
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}


