// JavaScript Document
var url=document.URL.toLowerCase();
var th=new Arrẻr
y(0,0,0,0,0,0,0,0,0,0);

function createUrl(j,value,obj)
{
	base=Array();
	base=url.replace(base_url.toLowerCase()+"raovat/"+obj.toLowerCase()+"/","").split('/');	
	
	var tmp_url="";
	for(var i=0;i<base.length;i++)
	{		
		if(i!=3)
			tmp_url+=i!=j?base[i]+"/":value+"/";	
		else
			tmp_url+="0/";
	}
	
	return tmp_url.substring(0,tmp_url.length-1);
}	

function ChangeView(obj)
{		
	window.location.href=base_url+"raovat/"+obj+"/"+createUrl(0,document.getElementById('result').value,obj);	
}
function ChangeHost(obj)
{
	window.location.href=base_url+"raovat/"+obj+"/"+createUrl(1,document.getElementById('host').value,obj);
}
function ChangeLocation(obj)
{
	window.location.href=base_url+"raovat/"+obj+"/"+createUrl(2,document.getElementById('location').value,obj);
}
function show(i)
{	
	id="rutgon"+i;
	if(th[i]==0)
	{
		document.getElementById("long_item"+i).style.display="block";
		document.getElementById(id).className="a-shorten";
		th[i]=1;
	}
	else
	{
		document.getElementById(id).className="a-more";
		document.getElementById("long_item"+i).style.display="none";			
		th[i]=0;		
	}
}

function hide_box( id ) {
	var cssname 	= $( '#close-' + id ).attr('class');	
	var rbbox 		= $( '#rb-box-' + id );
	var rbbotton 	= $( '#close-' + id );
	
	if ( cssname == 'a-open' ) {
		rbbox.fadeIn('fast');
		rbbotton.removeClass().addClass( 'a-close' );
		myDrray[id] = 1;
	}else {
		rbbox.fadeOut('fast');
		rbbotton.removeClass().addClass( 'a-open' );
		myDrray[id] = 0;
	}
		 	
	set_cookies_value( myDrray );
};


function ajax_rv( id, numbs, cat_id, cat_type, next_back ) {	
	var text_values = $('#value-' + id ).val();
	
	if ( text_values >= 0 ) {
		
		if ( text_values <= 30 ) {				
			if ( next_back == 0 )get_items = parseInt( text_values ) - parseInt(  numbs );	
			else {
				get_items = parseInt( text_values ) + parseInt(  numbs );
				if ( get_items > 30 ) get_items = 30 
			}
		}else get_items = parseInt( text_values );
		
		if ( get_items < 0 ) get_items = 0
		$('#value-' + id ).val( get_items );
	}else {
		get_items = numbs;
		$('#value-' + id ).val( get_items );
	}
	
	$('#' + id ).css('display','none');
	$('#loading-' + id ).show();							
	$('#' + id ).load( base_url + 'raovat/ajaxData/' + cat_id + '/' + get_items + '/' + numbs + '/' + cat_type, '', ajax_start(id) );	
};

function ajax_start(id) {
	$('#' + id ).ajaxStop(function(){
		$('#loading-' + id ).hide();						   	
   		$(this).fadeIn();
 	});	
}

function clicksend() {
	$('#sendmail').toggle();
}

function reload_box( id, value ) {
	if ( value == 0 ) {
		$( '#rb-box-' + id ).css('display','none');
		$( '#close-' + id ).removeClass().addClass( 'a-open' );
	}
};

function set_cookies_value( my_array ) {
	$.cookie( 'rv_align', my_array, { expires: 30, path: '/'});
};

function search_rv( id_textbox, url_base ) {
	var ob 		= document.getElementById( id_textbox );
	var decode 	= replacequery_search( ob.value );
	url_temp = url_base + 'raovat/search/1/0/0/0/'+  decode ;
	
	if( decode != null && decode != '' )
		window.location.href = url_temp;
	
};

