window.addEvent('domready', function() {
	var myTips = new Tips('.smsTips', {
		className: 'smsTip'
	});

	var agentSpecialTips = new Tips('.agentSpecialTips', {
		className: 'agentSpecialTip'
	});

	var greenTips = new Tips('.greenTips', {
		className: 'greenTip'
	});


});


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	var sCookie = sName + "=" + encodeURIComponent(sValue);
	if (oExpires) {
		sCookie += "; expires=" + oExpires.toGMTString();
	}
	if (sPath) {
		sCookie += "; path=" + sPath;
	}
	if (sDomain) {
		sCookie += "; domain=" + sDomain;
	}
	if (bSecure) {
		sCookie += "; secure";
	}
	document.cookie = sCookie;
}

function getCookie(sName) {
	var sRE = "(?:; )?" + sName + "=([^;]*);?";
	var oRE = new RegExp(sRE);
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}
}

function clearMess() {
	document.getElementById("addDiv").style.display = 'none';	
}

function addFavor(id) {
	var tmp = getCookie("prog");
	setCookie("prog", tmp + "," + id, '', '/');

	$('addDiv').set('html', 'Объявление добавлено в избранное.').setStyles({
		'top': document.getScroll().y + (document.getSize().y / 2) - 150 + 'px',
		'display': 'block'
	});
//	document.getElementById("addDiv").style.left = (window.screen.width / 3) + 50;
//	document.getElementById("addDiv").style.top = (document.body.scrollTop + (window.screen.height / 2)) - 150;
//	document.getElementById("addDiv").style.display = 'block';
	setTimeout(clearMess,2000);
}

function showFullText(id) {
	var tr = $('objavl' + id);

	if(!$defined(tr)) return false;
	tr.getElement('.beforeMore').destroy();
	tr.getElement('.afterMore').setStyle('display', '');
	tr.getElement('.more').destroy();
}

function openWindow(url, wndname, w, h) {
	window.open(url,wndname,'height=' + h + ',width=' + w + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
}



function makeAdTop(id) {
	id = id.toInt();
	if(!id) return false;
	if(!$defined($('objavl' + id))) return false;
	if(!confirm('Выделить объявление?')) return false;

	options = {
		url: '/ajax/personal_cab.php?action=top',
		data: {
			'id': id
		},
		onRequest: function() {
		},
		onSuccess: function(result) {
			if(result['result']) {
				tr = $('objavl' + id);
				if(tr.hasClass('blue')) tr.addClass('red').removeClass('blue');
				else tr.addClass('lightred');

				alert(result['result']);
			}
			else if(result['errors']) {
				alert(result['errors']);
			}
		}
	};
	new Request.JSON(options).send();
}
