function and_or_temizle(text)
{
	if (text.toUpperCase().indexOf(" AND ") > -1)
	{
		text = text.replace(/ AND /gi, " ");
		and_or_temizle(text);
	}
	if (text.toUpperCase().indexOf(" OR ") > -1)
	{
		text = text.replace(/ OR /gi, " ");
		and_or_temizle(text);
	}

	return text;
}

function Arama(text, e, lang) // üst menü hızlı arama fonksiyonu
{			
	text = and_or_temizle(text);

	var key = parseInt(e.keyCode);
	var aramaSayfasi = lang == 'TR' ? 'arama' : 'search';
	if(text == ""){return false;}
	if (key == 13){window.location = '/' + aramaSayfasi + '.aspx?keyword=' + text;}
		
	text = text.replace('ç', '-c-');
	text = text.replace('Ç', '-C-');
	text = text.replace('ö', '-o-');
	text = text.replace('Ö', '-O-');
	text = text.replace('ı', '-i-');
	text = text.replace('İ', '-I-');
	text = text.replace('ş', '-s-');
	text = text.replace('Ş', '-S-');
	text = text.replace('ğ', '-g-');
	text = text.replace('Ğ', '-G-');
	text = text.replace('ü', '-u-');
	text = text.replace('Ü', '-U-');
	
	//alert(text);
		
	if (key != 38 && key != 40)
	{
		if (text.length > 2)
		{
			var xmlDoc;
			try
			{
				xmlDoc=new XMLHttpRequest();  
			}
			catch (e)
			{
				try
				{    
					xmlDoc=new ActiveXObject("Msxml2.XMLHTTP");    
				}
				catch (e)
				{    
					try
					{      
						xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");      
					}
					catch (e)
					{
						alert("Your browser does not support AJAX!");      
						return false;      
					}    
				}  
			}
			xmlDoc.onreadystatechange=function()
			{
				if(xmlDoc.readyState==4)
				{
					if (xmlDoc.responseText.substring(0,1) == '1')
					{
						/*document.getElementById('aramaSonucMesaj').style.display = 'none';
						document.getElementById('aramaSonucLink').style.display = 'block';*/
						document.getElementById('aramaSonuclari').innerHTML = xmlDoc.responseText.substring(1);
						aramaKurtarma = 1;
						
						//27 04 2011 arama bos gelırse bg gizleyelim
						if(document.getElementById('aramaSonuclari').innerHTML == ''){
							$('#aramaSonuc').hide();
							$('#aramaSonuc_en').hide();
						}
					}
					else 
					{
						/*document.getElementById('aramaSonucMesaj').style.display = 'block';
						document.getElementById('aramaSonucLink').style.display = 'none';*/
						document.getElementById('aramaSonuclari').innerHTML = '';
						aramaKurtarma = 1;
					}
				}
			}
			
			xmlDoc.open("GET","/upload/hizli_arama" + (lang == "TR" ? "" : "_en") + ".aspx?lang=" + lang + "&keyword=" + escape(text),true);
			xmlDoc.send(null);
			
			
		}
	}
	
}

/*
üst menü arama sonucları listesinde altta bulunan tüm sonuclar linki ve
arama sayfası sol arama kutusunda kullanılan fonksiyon
*/
function AramaSonuc(SayfaID,Obj)
{
	obj_str = document.getElementById(Obj).value;
	obj_str = and_or_temizle(obj_str);
	window.location = '/' + SayfaID + '.aspx?keyword=' + obj_str; //document.getElementById(Obj).value;
}
/*
arama sayfası orta alan sonuç gösterimi
*/
function ShowResult(panel)
{
	var container = document.getElementById(panel + 'Sonuclar');
	if (container)
	{
		var content = container.getElementsByTagName('DIV');
		if (content)
			for (i=0; i<content.length; i++)
			{
				if (content[i].className == "sonuc" && i>2)
					content[i].style.display = content[i].style.display == 'none' ? 'block' : 'none';
				if (content[i].className == "sonucLink")
					if (content[i-1].style.display == 'block')
						content[i].innerHTML = 'tüm sonuçlar | <a href="javascript:ShowResult(\'' + panel + '\');">İlk 3 sonuç için tıklayınız</a>';
					else
						content[i].innerHTML = 'ilk 3 sonuç | <a href="javascript:ShowResult(\'' + panel + '\');">Tüm sonuçlar için tıklayınız</a>';
			}
	}
	updateScroll();
}
function ExpendResult(panel)
{
	var container = document.getElementById(panel + 'Sonuclar');
	if (container)
	{
		var content = container.getElementsByTagName('DIV');
		if (content)
			for (i=0; i<content.length; i++)
			{
				if (content[i].className == "sonuc")
					content[i].style.display = 'block';
				if (content[i].className == "sonucLink")
					content[i].innerHTML = 'tüm sonuçlar | <a href="javascript:ShowResult(\'' + panel + '\');">İlk 3 sonuç için tıklayınız</a>';
			}
	}
	updateScroll();
}
function CollapseResult(panel)
{
	var container = document.getElementById(panel + 'Sonuclar');
	if (container)
	{
		var content = container.getElementsByTagName('DIV');
		if (content)
			for (i=0; i<content.length; i++)
			{
				if (content[i].className == "sonuc" && i>2)
					content[i].style.display = 'none';
				if (content[i].className == "sonucLink")
					content[i].innerHTML = 'ilk 3 sonuç | <a href="javascript:ShowResult(\'' + panel + '\');">Tüm sonuçlar için tıklayınız</a>';
			}
	}
	updateScroll();
}
function updateScroll()
{
	$('#pane1').jScrollPane();
}
function $show(id)
{
	if ($('#ctl00_ctl02_ctl00_pnl' + id))
	{
		$hidden('Bireysel');
		$hidden('Sirket');
		$hidden('Ticari');
		$hidden('Kurumsal');
		$hidden('Private');
		$hidden('Diger');
		$('#ctl00_ctl02_ctl00_pnl' + id).fadeIn('slow');
	}
}
function $hidden(id)
{
	if ($('#ctl00_ctl02_ctl00_pnl' + id))
		$('#ctl00_ctl02_ctl00_pnl' + id).css('display','none');
}
function $showAll(id)
{
	if($('#ctl00_ctl02_ctl00_pnl' + id))
		$('#ctl00_ctl02_ctl00_pnl' + id).fadeIn('slow');
	CollapseResult(id.toLowerCase());
}
function ShowCategory(id)
{
	//$('#pane1').css("top","0px");
	if (id == 'Tum')
	{
		$showAll('Bireysel');
		$showAll('Sirket');
		$showAll('Ticari');
		$showAll('Kurumsal');
		$showAll('Private');
		$showAll('Diger');
	}
	else
	{
		$show(id);
		ExpendResult(id.toLowerCase())
	}
	
}
