 // JavaScript Document

// select a tab number
//var test = "{$module_name}";


//var _tabSelected = 0;  // index starts with zero

$(document).ready( function() {

 var _max = $('.tabs').size() - 1;
 if(_tabSelected > _max || _tabSelected < 0) _tabSelected = 0;
 var _selected = $('.tabs:eq(' + _tabSelected + ')');
 var _index = $('a').index(_selected);


 _selected.attr('id',_selected.attr('id') + '-selected');

 $('#searchContent > div').eq(_index - 3).css("display","block");

 $('.tabs').click( function() {
  var _t = $(this);
  _selected.attr('id',_selected.attr('id').replace("-selected",""));
  _index = $('a').index(_selected);
  $('#searchContent > div').eq(_index - 3).css("display","none");
  _t.attr('id',_t.attr('id').replace(_t.attr('id'),_t.attr('id') + '-selected'));
  _index = $('a').index(_t);
  $('#searchContent > div').eq(_index - 3).css("display","block");
  _selected = _t;

 });


 $('#priced_from').change( function() {
 	//alert(home_url);

 	if ((($('#priced_to').attr('value').length)==0) || (($('#priced_to').attr('value'))==null))
 	{
 		//alert("second value has been not set");
 	}
 	if(module_name == "price")
 	{
 		//alert("Y-module_name :" + module_name);
 		window.location = home_url + "price/" + $('#priced_from').attr('value');
 	}
 	else
 	{
 		window.location = home_url + "price/" + $('#priced_from').attr('value');

 	}

 });


 $('#priced_to').change( function() {
 	//var selected_price_from_value = '' + selected_price_from;
 	//alert(selected_price_from_value);


 	if ((($('#priced_from').attr('value').length)==0) || (($('#priced_from').attr('value'))==null))
 	{
 		//alert("second value has been  set");
 	}
 	if(($('#priced_to').attr('value')) <= ($('#priced_from').attr('value')))
 	{
 	//alert("Pleas select the Priced From value  lower than Priced To value.");
 	}



 	if(module_name == "price")
 	{
		var _URL = '' + window.location;
		var _first = _URL.split('price/');
		var _second = '';

		from_price = parseInt($('#priced_from').attr('value').replace('$','').replace(',',''));
		to_price = parseInt($('#priced_to').attr('value').replace('$','').replace(',',''));

		if(from_price>to_price)
		{
			alert('Please select valid Priced To');
			return false;
		}
		
		
		if(document.getElementById('from_site_page'))
			window.open(home_url + "price/" + $('#priced_from').attr('value')+'/'+$('#priced_to').attr('value'), "_parent");
		else
			window.location = home_url + "price/" + $('#priced_from').attr('value')+'/'+$('#priced_to').attr('value');
		
		
		//window.location = home_url + "price/" + $('#priced_from').attr('value')+'/'+$('#priced_to').attr('value');

	/*  var _URL = '' + window.location;
		var _first = _URL.split('price/');
		var _second = '';

		if(_first[1])
		{
			_second = _first[1].split('?');
		}
		if(_second[1])
		{
			var _temp = '' + window.location;
			window.location = _temp.replace(("?" + _second[1]),("/" + $('#priced_to').attr('value')));
		}
		else
		{
			window.location += '/' + $('#priced_to').attr('value');
		}
		*/
 	}

 	else
 	{
	//window.location = home_url + "price/" + $('#priced_from').attr('value') + "/" + $('#priced_to').attr('value');
	//alert("else of price_to");
 	}
 });



	var selected_from = window.location;
	var _loc = '' + selected_from;
	var _first = _loc.split('price/');
	if (_first_first != null)
	{

		var _first_first = _first[1].split('?');
		if(!_first_first[1])
		{
			var _temp = _first[1];
		}
		else
		{
			var _temp = _first_first[0];

		}

		if(_temp)
		{
			var _second = _temp.split('/');
			$('#priced_from :selected').text(_second[0]);
			if(_second[1] != undefined)
			{
				$('#priced_to :selected').text(_second[1]);
			}
		}
	}

});

function goPriceButton()
{
	var price_from =document.getElementById('priced_from').value;
	var priced_to =document.getElementById('priced_to').value;
	//---//added validation on 06-Mar-2010
	if(price_from =='' && priced_to == '')
	{
		alert('Please select Price');
		return false;
	}
	if(price_from =='' && priced_to != '')
	{
		alert('Please select Priced From');
		return false;
	}
	if(price_from !='' || priced_to != '')
	var url = home_url + "price/" + price_from;
	if(priced_to!='')
		url += '/'+priced_to;
		
	if(document.getElementById('from_site_page'))
		window.open(url , "_parent");
	else
		window.location = url;
}
