var ajax_url = 'ajax.php?';

function newWindowSize(scriptName,width,height)
 {
    window.open(scriptName,"","width="+width+",height="+height+",top=50,left=120,alwaysRaised=yes,toolbar=0,directories=0,menubar=0,status=1,resizable=no,location=0,scrollbars=1,copyhistory=0");
 }
 
 function flip(element_id) {
		var element=document.getElementById(element_id);
		if (element.style.display == 'block') {
			element.style.display = 'none';
		} else {
			element.style.display = 'block';
		}
 }

 function checkForSale(auto_id){
		var str=getCookie('userStatusAuto');
		if (str)
		{
			var arr=str.split('||');
			for (var i=0;i<arr.length;i++)
			{
				if (arr[i]==auto_id)
				{
					document.getElementById('struckOff'+auto_id).style.display='none';
				}
			}
		}
	}

	function setCookie(cookieName,cookieValue,nDays) {
 	var today = new Date();
 	var expire = new Date();
 	if (nDays==null || nDays==0) nDays=1;
 	expire.setTime(today.getTime() + 3600000*24*nDays);
 	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
	}
	
	function getCookie(name) {
		var cookie = " " + document.cookie;
		var search = " " + name + "=";
		var setStr = null;
		var offset = 0;
		var end = 0;
		if (cookie.length > 0) {
			offset = cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				end = cookie.indexOf(";", offset)
				if (end == -1) {
					end = cookie.length;
				}
				setStr = unescape(cookie.substring(offset, end));
			}
		}
		return(setStr);
	}
	
	function reset_search_page(ipp,page,count_all){
		
		var old_ipp=getCookie('ipp');
		
		var items=(old_ipp*(page+1));
		
		if ((Math.ceil(count_all/old_ipp)) == (page+1)){
			items=items-(items-count_all);
		}
		
		var new_page=(Math.ceil(items/ipp)-1);
		
		if (new_page<0){ 
			new_page=0;
		}
		
		setCookie('ipp',ipp,365);
		if (window.location.href.indexOf('page=')!==-1){
			window.location.href=window.location.href.replace(/\&page\=\d*/,"&page=" + new_page);
		} else {
			window.location.href=window.location.href+'&page=' + new_page;
		}
		
	}
	
	function addAutoToNoteBook(mode,auto_id){
	if (mode==0){
		var str1=getCookie('favorit');
		if (str1!=null)	{
			var str=str1+auto_id+';';
		} else {
			var str=auto_id+';';
			str1='';
		}
		setCookie('favorit',str,14);
		if (str1.length==str.length){
			alert('Произошла ошибка при добавлении объявления в блокнот');
		} else {	
			document.getElementById('add_'+auto_id).innerHTML=document.getElementById('in_note_book').innerHTML;
		}

	} else {
			this.auto_id = auto_id;
			var url = 'ajax.php?' + Object.toQueryString({target:'search', event:'add_favorit', auto_id:auto_id});
			var my_ajax = new Ajax(url, {
				method: 'get',
				onComplete: resp_favorite.bind(this)
			});
				my_ajax.request();
		}	
	}
	
	function resp_favorite(unswer){
		if (unswer==1){
			document.getElementById('add_'+ this.auto_id).innerHTML=document.getElementById('in_note_book').innerHTML;
			
		} else {
			alert('Произошла ошибка при добавлении объявления в блокнот');
		}
	}
	
	function ShowOnChecked(elem,target)
	{
		if (elem.checked)
		{
			 $(target).style.display='block';
		}
		else
		{
			$(target).style.display='none';
		}
	}
	
	function print_doc()
	{
		text=document;
		print(text);
	}