function ValidateArray() {
	this.blog = 0;
	this.news = 0;
}
 
Val = new ValidateArray();
var elementNum = 0;
var max_results = 0;
var lastscroll = 0;
function Ajax(file, data, div, method, rateid, target, placeRating, newsFlag, flag, buttonUP, news_in)
{
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	if(newsFlag!='1'){
        	document.getElementById(div).innerHTML = html;
        	}else{	
        	document.getElementById(div).src = html;
        	document.getElementById(div).className = '';
        	document.getElementById(div).width = '20';
        	document.getElementById(div).height = '20';
        	document.getElementById(div).align = '';
        	document.getElementById("rup"+rateid).style.display = 'none';
        	//gornite 5 reda se mahat ako vra6tame ra4i4kite
        	}
        //  $("#"+div).html(html);
         valid = html;
         if ( rateid > 0 ) {
         
           if(news_in == '1'){	
         	Ajax('/ajaxtabs/returnRating2/'+rateid+'/'+target, null, placeRating, 'GET');
           } else {
           	Ajax('/ajaxtabs/returnRating/'+rateid+'/'+target, null, placeRating, 'GET');
           }
         }
        }
     });
//     if(flag == '1') document.getElementById(buttonUP).src = "/i/rateup.jpg";
//		if(flag == '0') document.getElementById(buttonUP).src = "/i/ratedown.jpg";tozi i gorniq komentar se mahat ako vra6tame ra4i4kite
}
/*function AjaxUP(file, data, link, method)
{
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	document.getElementById(link).src = html;
         valid = html;
        }
     });
}*/

function AjaxKV(file, data, div, method)
{
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	document.getElementById(div).innerHTML = html;
        //  $("#"+div).html(html);
         valid = html;
        // initpodKvartali();
        }
     });
}

function AjaxSearch(file, data, div, method)
{
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	document.getElementById(div).innerHTML = html;
        	document.getElementById(div).style.display = 'block';

        	if ( document.getElementById('des').value == '') 	document.getElementById(div).style.display = 'none';

			
			
			valid = html;
        }
     });
}

/*function buttonUP(id,flag){
		if(flag == '1') document.getElementById(id).src = "/i/rateup.jpg";
		if(flag == '0') document.getElementById(id).src = "/i/ratedown.jpg";
}*/

function SetValue(id, val) {
		document.getElementById('des').value = val;
		document.getElementById('hidden_id').value = id;
		document.getElementById('key_search').style.display = 'none';
		elementNum = 0;
}

function validate(field, content, div, success, error) {
	   $.ajax({
        type: "GET",
        url: '/validations/field/'+field+'/'+content+'/'+success+'/'+error,
        cache: false,
        success: function(html){
        string=html.split("[DELIMITER]");
        $("#"+div).html(string[0]);
   
        eval("Val."+field +"= string[1]");
   		 
        }
        
     });
}

function checkValidate( arr ) {
	retval = true;
	for (var i = 0;i<arr.length;i++) {
			 if ( eval("Val."+arr[i]) == 0 ) {
			 	alert('Моля, попълнете всички полета правилно');
			 	retval = false;
			 }
	}
	return retval;
		
}

function kvartal_dropdown(city, selected) {
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/areas_dropdown/'+city+'/'+selected,
        cache: false,
        success: function(html){
        document.getElementById("kvartali").innerHTML = html;
 		initpodKvartali();
        }
        
     });
}

function podkvartal_dropdown(area, selected) {
 
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/subareas_dropdown/'+area+'/'+selected,
        cache: false,
        success: function(html){
        document.getElementById("podkvartali").innerHTML = html;
 		
        }
        
     });
}

function brokers_dropdown(agency, selected) {
 
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/brokers_dropdown/'+agency+'/'+selected,
        cache: false,
        success: function(html){
        document.getElementById("brokers").innerHTML = html;
 		
        }
        
     });
}



function extras_dropdown(property, imotid) {
	if ( undefined == imotid ) imotid = 0;
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/extras_dropdown/'+property+'/'+imotid,
        cache: false,
        success: function(html){
        document.getElementById("extras_t").innerHTML = html;
 		
        }
        
     });
}

function ads_dropdown(property, pid) {
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/ads_dropdown/'+property+'/'+pid,
        cache: false,
        success: function(html){
        document.getElementById("areas_data").innerHTML = html;
 		
        }
        
     });
}

function ads_dropdown_site(property, pid) {
	$.ajax({
        type: "GET",
        url: '/ajaxtabs/ads_dropdown_site/'+property+'/'+pid,
        cache: false,
        success: function(html){
        document.getElementById("areas_data_site").innerHTML = html;
 		
        }
        
     });
}


function setSearch(div) {
 
		if (null == div) {
			div='prodajbi';

		}
		$.ajax({
        type: "GET",
        url: '/ajaxtabs/'+div,
        cache: false,
        success: function(html){
        document.getElementById("searchtab").innerHTML = html;
 		
        }
       
     });
     
      document.getElementById('prodajbi').className='prodajbi';
      document.getElementById('naemi').className='naemi';
      document.getElementById('novi_sgradi').className='novi_sgradi';
      document.getElementById('novo_stroitelstvo').className='novo_stroitelstvo';
      
     document.getElementById(div).className=div+'s';
 
      setCookie('search', div);
}


function dg_keydown(event)
{
 
	if (event.keyCode == 40)  {
		document.getElementById('selected_city').focus();
	}
	else {
		val = document.getElementById('des').value;
		obj = document.getElementById('key_search');
		AjaxSearch('/search/SearchAjax/'+val,'abs','key_search','GET');
		document.getElementById('key_search').style.display = 'none';
	}

}

function searchKeyDown(event, text, value) {
	
	if (event.keyCode == 13 ) {
		document.getElementById('region_id').value = value;
		document.getElementById('des').value = text;
		document.getElementById('key_search').style.display = 'none';
		document.getElementById('des').focus();
	}
	else if ( event.keyCode != 40 && event.keyCode != 38) {
	
		document.getElementById('des').focus();
	
	}

	 
}

function searchClick(event, text, value) {
	
		document.getElementById('region_id').value = value; 
		document.getElementById('des').value = text;
		document.getElementById('key_search').style.display = 'none';
		document.getElementById('des').focus();
	
}
function SubmitAjax(field, content, div){

     $.ajax({
        type: "GET",
        url: field,
        cache: false,
        success: function(html){
        string=html.split("[DELIMITER]");
        $("#"+div).html(string[0]);
   
        eval("Val."+field +"= string[1]");
   
        }
        
     });
}
/*function dg_keydown(event)
{
 
	val = document.getElementById('des').value;
	obj = document.getElementById('key_search');
	 if ( max_results == 0 )	 max_results = ( document.getElementById('max_results').value ) ;
//alert(elementNum);
//alert(max_results);
	if (event.keyCode == 40) { // nadol
		document.getElementById('selected_city').focus();
		//if ( elementNum >= max_results ) return;
		 
		//elementNum++;
		//AjaxSearch('/search/SearchAjax/'+val+'/'+elementNum,'abs','key_search','GET');
		//max_results = ( document.getElementById('max_results').value ) ;

			 
	 
	}
	else if ( event.keyCode == 38 ) {
		if ( elementNum <= 1 ) return;
		 
		elementNum--;
		AjaxSearch('/search/SearchAjax/'+val+'/'+elementNum,'abs','key_search','GET');
	
 
	}
	else if ( event.keyCode == 13 ) {
		document.getElementById('des').value = document.getElementById('selected_city').value;
		document.getElementById('hidden_id').value = document.getElementById('selected_cityid').value;
		document.forms.sform.submit();
		
	}
	
	else {
		AjaxSearch('/search/SearchAjax/'+val,'abs','key_search','GET');
		document.getElementById('key_search').style.display = 'none';
	}
	 
	    document.getElementById('key_search').scrollTop = 0;

	
	 
} 
*/

 