// JavaScript Document
//ugur oto icin gerekli javascript fonksiyonlari ve ajax islemleri

function markalari_al()
{
	var url = 'arama.php?islem=markalar';
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var notice = $('hizli_arama_markalar');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText);			 
		else
		  notice.update('markalar alınamadı');
	  }
	});
}
function araclari_al(marka)
{
	var url = 'araclar.php?marka='+marka;
	
	if( marka==null || marka=='' )
	{
		url = 'araclar.php';
	}
	else
	{
		url = 'araclar.php?marka='+marka;
	}
	
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var notice = $('araclar_grid');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText).setStyle({width:'100%', height:'100%'});
		else
		  notice.update('araçlar alınamadı').setStyle({width:'100%', height:'100%'});
	  },
	  onFailure: function(transport) {
	  	var notice = $('araclar_grid');
		notice.innerHTML = "Yükleme sorunu";
	  }
	});
}

function markalari_al_detay()
{
	var url = 'arama.php?islem=markalar';
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var notice = $('arama_marka');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText);
		else
		  notice.update('markalar alınamadı').setStyle({ background: '#fdd' });
	  }
	});
}


function modelleri_al(marka)
{
	var url = 'arama.php?islem=modeller&marka_isim='+marka;
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var notice = $('arama_model');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText).setStyle({width:'175'});
		else
		  notice.update('modeller alınamadı').setStyle({ background: '#fdd' });
	  }
	});
}

function tarihleri_ata()
{
	var tarih = new Date();
	simdi = tarih.getFullYear();
	once  = simdi - 100;
	
	var seneler = null;
	var seneler_min = "<select id='minimum_yil' name='minimum_yil'>";
	var seneler_max = "<select id='maks_yil' name='maks_yil'>";
	for( i=once;i<=simdi+1;i++)
	{
		seneler += "<option value='"+ i+"'>"+i+"</option>";
	}
	
	seneler_min += '<option value="" style="color:#CCCCCC;">minimum</option>';
	seneler_max += '<option value="" style="color:#CCCCCC;">maksimum</option>';
 	seneler_min += seneler;
	seneler_max += seneler;
	seneler_min += "</select>";
	seneler_max += "</select>";
	
	document.getElementById('min_yillar').innerHTML = seneler_min;
	document.getElementById('max_yillar').innerHTML = seneler_max;
	

}
function kontrolet(element)
{
	if( element.checked == true )
	{
		element.value = 1;
	}
	else
	{
		element.value = 0;
	}
}

function kontrolet_grup(element)
{
	var elements = document.getElementsByName('yakit');
	
	for( i=0; i<elements.length; i++)
	{
		if( elements[i] != element )
		{
			elements[i].checked = false;
			elements[i].value = 0;
		}
	}
	element.checked = true;
	element.value = element.id;
	
}

function verileriGonder()
{
	var url = 'araclar.php?detayli=true';
	
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  parameters: $('form2').serialize(true),  
      method: 'post',
	  onSuccess: function(transport) {
		var notice = $('araclar_grid');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText).setStyle({width:'100%', height:'100%'});
		else
		  notice.update('araçlar alınamadı').setStyle({width:'100%', height:'100%'});
	  }
	});
}

function arac_turleri_al()
{

	var url = 'araclar.php?arac_turleri=true';
	
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, { 
      parameters: $('form_arac_turleri').serialize(true), 
      method: 'post',
	  onSuccess: function(transport) {
		var notice = $('araclar_grid');
		if (transport.responseText.length > 0)
		{
		  notice.update(transport.responseText).setStyle({width:'100%', height:'100%'});
		}
		else
		{
		  notice.update('araçlar alınamadı').setStyle({width:'100%', height:'100%'});
		}
	  },
	 onFailure: function(transport) {
		alert(transport.status);
	  }
	});
}


function donothing()
{
}
function email_form_goster(x,y)
{
	var ajax_email_form = document.getElementById("ajax_email_form");
	ajax_email_form.style.top = x;
	ajax_email_form.style.left = y;
	if( ajax_email_form.style.visibility == "visible" )
	{
		ajax_email_form.style.visibility = "hidden";
	}
	else
	{
		ajax_email_form.style.visibility = "visible";
	}
	document.getElementById('MB_content').innerHTML = ajax_email_form.innerHTML;
	document.getElementById('MB_content').width = 400;
	document.getElementById('MB_content').height = 400;
	
}
function eposta_gonder()
{

	var url = 'eposta.php';
	
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, { 
      parameters: $('ajax_email_gonder').serialize(true), 
      method: 'post',
	  onSuccess: function(transport) {
		var notice = $('bilgilendirme');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText).setStyle({width:'100%', height:'100%'});
		else
		  notice.update('eposta gonderilemedi').setStyle({width:'100%', height:'100%'});
	  }
	});
}
function iletisim_gonder()
{

	var url = 'iletisim.php';
	
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, { 
      parameters: $('ajax_iletisim_form').serialize(true), 
      method: 'post',
	  onSuccess: function(transport) {
		var notice = $('bilgilendirme');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText).setStyle({width:'100%', height:'100%'});
		else
		  notice.update('eposta gonderilemedi').setStyle({width:'100%', height:'100%'});
	  },
	  onLoading: function(transport) {
	  	var notice = $('bilgilendirme');
		notice.innerHTML = "<img src='images/ajax-loader.gif' align='middle' style='text-align:center'/>";
	  }
	});
}
function iletisim_form_goster(x,y)
{

	var ajax_iletisim_form = document.getElementById("ajax_iletisim_div");
	ajax_iletisim_form.style.top = x;
	ajax_iletisim_form.style.left = y;
	if( ajax_iletisim_form.style.visibility == "visible" )
	{
		ajax_iletisim_form.style.visibility = "hidden";
	}
	else
	{
		ajax_iletisim_form.style.visibility = "visible";
	}
	document.getElementById('MB_content').innerHTML = ajax_iletisim_form.innerHTML;
	document.getElementById('MB_content').width = 400;
	document.getElementById('MB_content').height = 400;

}

function ajax_data_send()
{
	function callInProgress (xmlhttp) {
		switch (xmlhttp.readyState) {
		case 1: case 2: case 3:
		return true;
		break;
		// Case 4 and 0
		default:
		return false;
		break;
		}
	}
	function showFailureMessage() {
		alert('uh oh, it looks like the network is down. Try again shortly');
	}
	// Register global responders that will occur on all AJAX requests
	Ajax.Responders.register({
		onCreate: function(request) {
		request['timeoutId'] = window.setTimeout(
		function() {
			// If we have hit the timeout and the AJAX request is active, abort it and let the user know
			if (callInProgress(request.transport)) {
			request.transport.abort();
			showFailureMessage();
			// Run the onFailure method if we set one up when creating the AJAX object
			if (request.options['onFailure']) {
				request.options['onFailure'](request.transport, request.json);
			}
		}
	},
	5000 // Five seconds
	);
	},
	onComplete: function(request) {
	// Clear the timeout, the request completed ok
	window.clearTimeout(request['timeoutId']);
	}
});
}
function submitForm()
{
	document.getElementById('form_arac_turleri').submit();
}

function refresh_captcha()
{
	var url = 'ajax.php?islem=captcha';
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var notice = $('captcha_div_form');
		if (transport.responseText.length > 0)
		  notice.update(transport.responseText);
		else
		  notice.update('veri alinamadi' + transport.responseText);
	  },
	  onFailure: function(transport) {
	  	var notice = $('captcha_div_form');
		notice.innerHTML = "Yükleme sorunu" + transport.responseText;
	  }
	});
}
<!--

//-->
