function addToCompare(obj)
{
	thisdate = new Date();
	
	$.get($(obj).attr('href'),"pmode=empg&mishforref="+ thisdate.getTime(),function(msg){
	
		if (msg == "true")
		{
			$(obj).removeClass('add_to_compare');
			
			$(obj).addClass('remove_from_compare');
			$(obj).html('הסר מהשוואה');
		}
		else if (msg == "tooMacth")
		{
			MyAlert("אין אפשרות להשוות יותר מ3 רכבים");
		}
		else
		{
			$(obj).removeClass('remove_from_compare');
			
			$(obj).addClass('add_to_compare');
			$(obj).html('הוסף להשוואה');
		}
	});
	
	return false;
}

function addToSave(obj, id)
{
	var id = id;
	thisdate = new Date();
	
	if ($(obj).hasClass('remove_from_save'))
	{
		if (!confirm("האם אתה בטוח שברצונך למחוק את הרכב?"))
		{
			return "";
		}
	}
		
	$.get($(obj).attr('href'),"pmode=empg&mishforref="+ thisdate.getTime(),function(msg){


		if (msg == "true")
		{
			$(obj).removeClass('add_to_save');
			
			$(obj).addClass('remove_from_save');
			$(obj).html('הסר משמירה');
		}
		else if (msg == "remove")
		{
			$(obj).removeClass('remove_from_save');
			
			$(obj).addClass('add_to_save');
			$(obj).html('שמירת רכב');
			
			if ($(obj).hasClass('hideSavedCarOnClick'))
			{
				$(".carGroup_" + id).fadeOut();
			}
		}
		else
		{
			MyAlert("יש להתחבר כדי לשמור רכבים");
		}
	});
	
	return false;
}


function saveSearch()
{
	MyAlert("שם החיפוש: <input id='searchNameInp' type=text /> <input type=button value='שמור חיפוש' onclick=\"saveSearchStrpB($('#searchNameInp').val())\" />");
}

function saveSearchStrpB(name)
{
	thisdate = new Date();
	
	serial = $('#searchFRM').serialize();
	
	$.get("index.php?module=Listings&pname=saveSearch&pmode=empg&searchName=" + name + "&mishforref="+ thisdate.getTime(), "searchUrl=" + encodeURIComponent(serial),function(msg){

		if (msg == "true")
		{
			MyAlert("החיפוש נשמר");
		}
		else if (msg == "remove")
		{
			MyAlert("החיפוש הוסר מהרשימה");
		}
		else
		{
			MyAlert("יש להתחבר כדי לשמור חיפושים");
		}
	});
	
	return false;
}

$(document).ready(function() {
	$('.remove_from_compare').html('הסר מהשוואה');
	
	$('.remove_from_save').html('הסר משמירה');
});


function seperateVin(nStr)
{
	newStr = nStr[0] + nStr[1] + "-" + nStr[2] + nStr[3] + nStr[4] + "-" + nStr[5] + nStr[6];
	return newStr;
}

$(document).ready(function() {
	
	$('.seperateVin').each(function(index)
	{
		$(this).html(seperateVin($(this).html()));
	});
	
	$('.showPhone').click(function()
	{
		var dealerID = $(this).attr('dealerID'); 
		var carID = $(this).attr('carID');
		
		$.get("index.php?module=PickCar_Users&pname=getPhone&pmode=empg&uid=" + dealerID + "&carID=" + carID, function(msg){

			$('a[dealerID=' + dealerID + '][carID=' + carID + ']').hide();
			$('span[dealerID=' + dealerID + '][carID=' + carID + ']').html(msg);
		});
		
	});
	
});


function removeSearch(serial)
{
	thisdate = new Date();
		
	$.get("index.php?module=Listings&pname=saveSearch&pmode=empg&mishforref="+ thisdate.getTime(), "searchUrl=" + encodeURIComponent(serial),function(msg){

		if (msg == "remove")
		{
			//$(obj).removeClass('remove_from_save');
			
			//$(obj).addClass('add_to_save');
			MyAlert("החיפוש הוסר מהרשימה");
		}
		else
		{
			MyAlert("יש להתחבר כדי לשמור חיפושים");
		}
	});
	
	return false;
}
