function sendCloneForm(){
	alert("working");

}
function onVehicleMakeChange(type, make)
{
	new Ajax.Updater("clone-model", "/clone-client.php?ajax=1&mode=getmodels&type="+type+"&make="+make);
} 

function onVehicleTypeChange(type)
{
	new Ajax.Updater("clone-make", "/clone-client.php?ajax=1&mode=getmakes&type="+type); 
}

function onSubmitSearchByType()
{

  $('pageNum').value = 1;
  if ($('clone-yearMin').value > $('clone-yearMax').value)
  {
    $('warning').update("'From' year must be less than or equal to the 'To' year.");
    $('warning').show();
	location.hash = 'warning_a';
    return false;
  }
	
	
 new Ajax.Request('/clone-client.php?ajax=1&mode=showresults', {
  		parameters: $('clone-form').serialize(true),
  		    onSuccess: function(transport)
  		    {
      			var response = transport.responseText || "";
      			document.getElementById('clone-div').innerHTML = response;
    		},
    		onLoading: function(){ document.getElementById('clone-div').innerHTML = "<center><h2>Loading...</h2></center>"; }
  });

	
}


function browsePage(page)
{
	$('pageNum').value = page;
	
	new Ajax.Request('/clone-client.php?ajax=1&mode=showresults', {
  		parameters: $('clone-form').serialize(true),
  		    onSuccess: function(transport){
      			var response = transport.responseText || "";
      			document.getElementById('clone-div').innerHTML = response;
    		},
    		onLoading: function(){ ocument.getElementById('clone-div').innerHTML = "<h2>Loading...</h2>"; }
  });

}



function getVehicleInfo(lot){
	
	new Ajax.Request("/clone-client.php?ajax=1&mode=showVehicle&lot="+lot,
  {
    onSuccess: function(transport){
      var response = transport.responseText || "";
      	document.getElementById('clone-div').innerHTML = response;
    },
    onLoading: function(){document.getElementById('clone-div').innerHTML = "<center><h2>Loading...</h2></center>"; },
    onFailure: function(){  }
  });
}

function getFacilityInfo(facility)
{
$('clone-div').show();
if($('content'))
	$('content').hide();
new Ajax.Request("/clone-client.php?ajax=1&mode=showResults&clone-locationList="+facility,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "";
      	document.getElementById('clone-div').innerHTML = response;
    },
    onLoading: function(){ 
    	document.getElementById('clone-div').innerHTML = "<center><h2>Loading...</h2></center>";
    },
    onFailure: function(){  }
  });
  	
}

function showForm()
{
	$('clone-div').innerHTML = '';
}

function backToResults()
{
	new Ajax.Request('/clone-client.php?ajax=1&mode=showresults', {
  		parameters: $('clone-form').serialize(true),
  		    onSuccess: function(transport){
      			var response = transport.responseText || "";
      			document.getElementById('clone-div').innerHTML = response;
    		},
    		onLoading: function(){ document.getElementById('clone-div').innerHTML = "<center><h2>Loading...</h2></center>"; }
  });
}

function loadCalend()
{
	var headID = document.getElementsByTagName("head")[0];         
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = 'http://easyexport.us/calend.js';
	headID.appendChild(newScript);
}


function change_mode(mode)
{
	new Ajax.Updater("content", "/clone-client.php?ajax=1&mode="+mode, 
	
	{ onLoading: function()
	
	{ document.getElementById('content').innerHTML = "<center><h2>Loading...</h2></center>"; 
	
	
	} }
	
	
	);

	$('content').update('');
	if (mode == "search") 
	{
		setTimeout("loadCalend()", 2000);
		$('clone-div').show();
	}
	else
	{
		//$('clone-form').hide();
	}
	$('clone-div').hide();
}

function popup(lot, num)
{
	newWindow =  window.open('/clone-client.php?ajax=1&mode=photos&lot='+lot+'&i='+num, num, "height=600,width=800, scrollbars");
	newWindow.focus( );
}

function cal_yard(yard, date)
{
	new Ajax.Updater("content", "/clone-client.php?ajax=1&mode=cal_yard&yard="+yard+"&d="+date);
}

function cal_browse(m, y)
{
	new Ajax.Updater("content", "/clone-client.php?ajax=1&mode=calendar&m="+m+"&y="+y);
}

function cal_vehicle(lot)
{
	new Ajax.Updater("content", "/clone-client.php?ajax=1&mode=cal_vehicle&lot="+lot);
}


function getPort(country)
{
	if (country != '') 
	{
		$('price').hide();
		$('order_ship').hide();
		new Ajax.Updater("port", "/clone-client.php?ajax=1&mode=getport&country="+country,
		{
			onComplete: function upd(transport) 
			{
				new Insertion.Top("port", '<option value="">Выберите порт</option>');
				if (trim(transport.responseText) == '')
				{
					$('price').update('<a target="blank" href="http://www.bidux.com/transport/oceantransport/action/request/">Уточнить цену на сайте Bidux</a>');
					$('price').show();
				}
				updateTotal(0); 
			}
		});
	}
}




function getOcean(port_id, base)
{
	if (port_id != '') 
	{
		$('price').hide();
		$('order_ship').hide();
		new Ajax.Updater("price", "/clone-client.php?ajax=1&mode=getprice&port_id="+port_id,
		{
			onComplete: function upd_p(transport) 
			{
				$('price').show();
				if (isNaN(transport.responseText) || transport.responseText == 0)
				{
				    $('price').update('<a target="blank" href="http://www.bidux.com/transport/oceantransport/action/request/">Уточнить цену на сайте Bidux</a>');
				}
				else
				{
				    $('price').update('$'+transport.responseText+' USD');
				    $('order_ship').show();
				    updateTotal(transport.responseText);
				}
			}
		});
	}
	else
	{
		$('price').update('<a target="blank" href="http://www.bidux.com/transport/oceantransport/action/request/">Уточнить цену на сайте Bidux</a>');
	}
}

function updateTotal(ocean)
{
	ocean = isNaN(ocean)? 0 : parseInt(ocean);
	t = parseInt($('land').innerHTML) + ocean;
	$('total').update(t);
}

function trim(string)
{
	return string.replace(/(^\s+)|(\s+$)/g, "");
}
 