//ajax için xmlhttp oluşturan nesne
function createAjaxObj()
	{
		var retval=null;
		try
		{
		  retval=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
          try
          {
               retval=new ActiveXObject("Microsoft.XMLHTTP");
          } 
          catch(oc)
          {
               retval=null;
          }
		}

		if(!retval && typeof XMLHttpRequest != "undefined") 
		{
          retval=new XMLHttpRequest();
		}
		return retval;
	}
	
	//async olarak veri alınıyor
	function callAjaxAsync(id,page,elemId,fillElemId,subElemId)
	{		
		var oXmlHttp = createAjaxObj();
		var data;
		var url;
		var drp;
		var ilce;
		var semt;	
		//alert(id);
		drp=document.getElementById(fillElemId);
						
		drp.add(new Option("Yükleniyor....","0"));
		url=page+id;
		
		/*if (elemId=='drpSehir')
		{
			ilce=document.getElementById("hdnIlce");
			semt=document.getElementById("hdnSemt");
			
			ilce.value='0';
			semt.value='0';
		} 
		
		if (elemId=='drpIlce')
		{
			ilce=document.getElementById('hdnIlce');
			semt=document.getElementById("hdnSemt");
			
			ilce.value=document.getElementById('drpIlce').item(document.getElementById('drpIlce').selectedIndex).value;
			semt.value='0';
		} */
				
	if  (oXmlHttp)
		{
          oXmlHttp.open("GET",url,true);
		  //oXmlHttp.setRequestHeader("Content-Type","text/plain; charset=iso-8859-9");
          oXmlHttp.onreadystatechange=function()
          {
               if(oXmlHttp.readyState==4) 
               {
                    //alert(oXmlHttp.responseText);
					data=unescape(oXmlHttp.responseText);
					data=preg_replace(data);
					//alert(data);
                    parseData(data,fillElemId,subElemId);
               } 
          }; 
          oXmlHttp.send();
     }
	}
	//gelen veri parse ediliyor
	//satırlar £ ile sütunlar $ ile ayrılıyor
	function parseData(data,elemId,subElemId)
	{
		var rows;
		var cols;
		var i;
		var drp;
		
		drp=document.getElementById(elemId);
		drp.innerHTML="";
		//data=unescape(data);
		//alert(data);
		//data.replace(/ğ/, "g");
		//data.replace(/Ğ/, "G");
		//alert(data);
		rows=data.split("£");
		//alert(rows.length);
		drp.add(new Option("Tümü","0"));
		for (i=0;i<rows.length;i++)
		{			
			cols=rows[i].split("$");
			//alert(cols[1].toString());
			drp.add(new Option(cols[1].toString(),cols[0].toString())); 			  
		}
		
		if (subElemId.length>0)
		{
			drp=document.getElementById(subElemId);
			drp.innerHTML="";
			drp.add(new Option('Seçiniz',''));
		}
		
	}
	function disableIlDurum(control)
	{	
		if (document.getElementById(control+'1_il').selectedIndex>0)
		{
			document.getElementById(control+'1_yakinlik').disabled=false;
		}
		else
		{
			document.getElementById(control+'1_yakinlik').disabled=true;
		}
	}
	/*function openPopup()
	{
		var drp;
		drp=document.getElementById("HizliArama1_marka"); 
		if (drp.selectedIndex>0)
		{
			window.open('modellerPopUp.aspx?markaId='+drp[drp.selectedIndex].value+"&marka="+drp[drp.selectedIndex].text,
			"Modeller",
			"height=380,width=220,top=100,left=300,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes").focus();    
		}
		else
		{
			alert('Marka seçmediniz');
		}
	}*/
	function markaChange()
	{		
		var cnt;
		
		cnt=document.getElementById("HizliArama1_txtModel");
		cnt.value="Model seçmek için -->";		
		cnt=document.getElementById("HizliArama1_hdnModel");		
		cnt.value="0";
	}
	function galeriGenel(control,type)
	{
		var cnt1;
		var cnt2;
		var cntGal;
		var cntGenel;
		var cnt;
		
		cnt1=document.getElementById(control+"1_btnGaleri");
		cnt2=document.getElementById(control+"1_btnGenel");
		cntGal=document.getElementById(control+"1_tblGaleri");
		cntGenel=document.getElementById(control+"1_tblGenel");
		cnt=document.getElementById(control+"1_satici");
		
		cnt.value=type;		
		if (type==1)
		{
			cnt1.src="_img/galeriden1.gif";
			cnt2.src="_img/genel2.gif";
			
			//galeriden		
			cntGenel.style.borderBottomColor="#c8cac5";
			cntGenel.style.borderBottomWidth="1px";      	  			
			cntGenel.style.borderBottomStyle="solid";
			cntGenel.bgcolor="#DFEFF7";
			cntGal.style.borderBottomColor="";
			cntGal.style.borderBottomWidth="0px";      	  			
			cntGal.style.borderBottomStyle=""; 			
			cntGal.bgcolor="#FFFFFF";
			
		}
		else
		{
			cnt1.src="_img/galeriden2.gif";
			cnt2.src="_img/genel1.gif";											
			cntGal.style.borderBottomColor="#c8cac5";
			cntGal.style.borderBottomWidth="1px";      	  			
			cntGal.style.borderBottomStyle="solid";
			cntGal.bgcolor="#DFEFF7";
			cntGenel.style.borderBottomColor="";
			cntGenel.style.borderBottomWidth="0px";      	  			
			cntGenel.style.borderBottomStyle=""; 			
			cntGenel.bgcolor="#FFFFFF";
		}
	}
	function searchCont(control)
	{
		var marka;
		var model;
		var yil1;
		var yil2;
		var fiyat1;
		var fiyat2;
		var satici;
		var kur;
		var yakin;
		var il;
		var t1;
		var t2;
		var page='ara.php';	
		var satici;	
		
		if (control!='')
		{				
			marka=document.getElementById(control+'1_marka');
			model=document.getElementById(control+'1_model');
			yil1=document.getElementById(control+'1_yil1');
			yil2=document.getElementById(control+'1_yil2');		
			fiyat1=document.getElementById(control+'1_fiyat1');
			fiyat2=document.getElementById(control+'1_fiyat2');		
			kur=document.getElementById(control+'1_pbirim');
			satici=document.getElementById(control+'1_satici');		
			il=document.getElementById(control+'1_il');		
			yakin=document.getElementById(control+'1_yakinlik');
			satici=document.getElementById(control+'1_satici');			
		}
		else
		{	
			marka=document.getElementById('marka');
			model=document.getElementById('model');
			yil1=document.getElementById('yil1');
			yil2=document.getElementById('yil2');		
			fiyat1=document.getElementById('fiyat1');
			fiyat2=document.getElementById('fiyat2');		
			kur=document.getElementById('pbirim');
			satici=document.getElementById('satici');		
			il=document.getElementById('il');		
			yakin=document.getElementById('yakinlik');
			satici=document.getElementById('satici');
			page='hizliara.php';
		}
				
		if (model.value.length==0)
		{	
			model.value='0';
		}
						
		//hiçbir şey seçilmedi
		if (control!='')
		{
			if (marka.selectedIndex==0 && yil1.selectedIndex==0 
				&& yil2.selectedIndex==0 && fiyat1.value=='' && fiyat2.value=='' && il.selectedIndex==0)
			{			
				alert('Arama yapmak için en az bir kriter belirtmelisiniz');			
				return;
			}
		}
		if (yil1.selectedIndex!=0 && yil2.selectedIndex!=0)
		{	
			if (yil1.options[yil1.selectedIndex].value>yil2.options[yil2.selectedIndex].value)
			{
				alert('İlk Model yılı son model yılından büyük olamaz');
				return;			
			}			
		}
		if (fiyat1.value!='' && fiyat2.value!='')
		{	
			fiyat1.value=fiyat1.value.replace(',','');
			fiyat1.value=fiyat1.value.replace('.','');
			fiyat2.value=fiyat2.value.replace(',','');
			fiyat2.value=fiyat2.value.replace('.','');
			
			if (fiyat1.value.length>=fiyat2.value.length)
			{
				if (fiyat1.value>fiyat2.value)
				{
					alert('İlk fiyat son fiyattan büyük olamaz');
					return;			
				}			
			}
		}
		
		if (satici==null)page=page+'?satici=0';
		else page=page+'?satici='+satici.value;
				
		if (control=='HizliAramaMotor')
			page=page+'&aractipi=3';
		else
			page=page+'&aractipi=1';
			
		//if (control=='')
			//page=page+'&nissanGaleri=1';
			
		if (control!='')
		{		
			if (marka.selectedIndex>0)
			{
				page=page+'&marka='+marka.item(marka.selectedIndex).value;
			}
		}
		else
		{
			page=page+'&marka='+marka.item(marka.selectedIndex).value;
		}
		if (model.selectedIndex>0)
		{
			page=page+'&modelgrup='+model.item(model.selectedIndex).value;
		}		
		if (yil1.selectedIndex>0)
		{			
			page=page+'&ilkmodel='+yil1.item(yil1.selectedIndex).value;
		}
		if (yil2.selectedIndex>0)
		{
			page=page+'&sonmodel='+yil2.item(yil2.selectedIndex).value;
		}		
		if (fiyat1.value.length>0)
		{
			page=page+'&pbirim='+kur.item(kur.selectedIndex).value+'&ilkfiyat='+fiyat1.value.replace(',','').replace('.','');
		}
		if (fiyat2.value.length>0)
		{
			page=page+'&pbirim='+kur.item(kur.selectedIndex).value+'&sonfiyat='+fiyat2.value.replace(',','').replace('.','');
		}
		//page=page+'&pbirim='+kur.item(kur.selectedIndex).value;
		if (il.selectedIndex>0)
		{
			page=page+'&il='+il.item(il.selectedIndex).value;
			//'&yakinlik='+yakin.item(yakin.selectedIndex).value;
		}		
		window.location.href=page;  
	}



