var isEnterTrue = 0;
var oRequest;
var scins;
function strart(stisng){
strsa = stisng.replace(/ /gi, "+");
	return encodeURI(strsa);//escape(strsa);
}
function SetFocus(){objal("q").focus();}
function doPrventdouble(){isEnterTrue = 0;}
function validateForm(oForm) {
    var oQ = objal("q");
    if (oQ.value.replace(/ /g, "") == "" || isEnterTrue == 1){
        oQ.focus();
        return false;
    }
    isEnterTrue = 1;
    setTimeout ( "doPrventdouble()", 1500 );
    return true;
}
function objal(element){
	if (document.getElementById) element = document.getElementById(element);
	else if (document.all) element = document.all[element];
	else element = null;
	return element;
}
function sTypeSel(oE){
   var x = oE.parentNode.parentNode.getElementsByTagName("li");
   for(var i=0;i<x.length;i++){
     x[i].childNodes[0].className="sType";
   }
   oE.className="sTypeSel";
   objal('sBtn').value = oE.getAttribute("sSearch");
   objal('sBtn').setAttribute('sAction', oE.getAttribute("sAction"));
   objal('sType').value = oE.getAttribute("sAction");
   scins = oE.getAttribute("sAction");
   SetFocus();
   if (validateForm(objal('SearchForm'))){
         window.location.href = "http://"+objal('sType').value+".izledin.com/" + objal('sType').value + "/0/" + strart(objal("q").value) +".html";// objal('SearchForm').submit();
   }
}

function submitForm2(oE,qur){   
   objal('sType').value = oE;
   if (validateForm(objal('SearchForm'))){
       window.location.href = "http://"+oE+".izledin.com/" + oE + "/0/" + strart(qur) +".html";// objal('SearchForm').submit();
   }
}
function submitForm(oE){   
   objal('sType').value = oE;

   if (validateForm(objal('SearchForm'))){
	  
       window.location.href = "http://"+oE+".izledin.com/" + oE + "/0/" + strart(objal("q").value) +".html";// objal('SearchForm').submit();
   }
}
function toggleDisplay(id, show, bindWindowClick) {
    show = show || 'block';
    bindWindowClick = bindWindowClick || false;
    var el = document.getElementById(id);
    if (el.style.display == 'none') {
        el.style.display = show;
        if (bindWindowClick) {
            document.onclick = function(e) {
                if (!bindWindowClick) { el.style.display = 'none'; }
                bindWindowClick = false;
            }
        }
    } else {
        el.style.display = 'none';
        if (bindWindowClick) {
            document.onclick = null;
        }
    }
}
function showStatus( ln ) {
	window.status = ln;  
	return true;
}
function clearStatus() {
	window.status = "";
}
function sugesstSize(){
 objal('suggest').width = objal('q').offsetWidth + 'px';
}

	var focus = {y: -1,table: objal('suggestions')};
	function focusOn(focus, row) {
		for (var i = focus.table.rows.length - 1; i >= 0; i--) {
			focus.table.rows[i].style.backgroundColor = '';
		}
		if (row === undefined) {
			focus.table.rows[focus.y].style.backgroundColor = '#D5E2FF';
			objal('q').value = focus.table.rows[focus.y].cells[0].innerHTML.replace(/(<([^>]+)>)/ig,"");
			objal('asVal').value = ac;
		} else {
			row.style.backgroundColor = '#D5E2FF';
			focus.y = row.getAttribute('sugID');
		}
	}
	function reqSuggest(q){
		 var sUrl = "http://api.autocompleteplus.com/?f=1&n=10&l=" + encodeURIComponent(hl) + "&q=" + encodeURIComponent(q) + "&b=1&callback=acp_new";
		this.c(sUrl);
	}
	function reqRelated(q){//1B_pNxnV34FtwptIxkGs8XNh8q06MrNw5sMzsMCifNXMHqaWW1kMRG.bq5cjx7Y3
		var sUrl = "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&output=json&callback=yahRel&query=" + encodeURIComponent(q);
		this.c(sUrl);
	}
	function call(sUrl){
	var s = document.createElement('script');
	s.setAttribute('type', 'text/javascript');
	s.setAttribute('id', 'dsJSON');
	s.setAttribute('src', sUrl);
	var oldCall=objal('dsJSON');
    var head = document.getElementsByTagName('head').item(0);
    if (oldCall)
		oldCall.parentNode.removeChild(oldCall);
	head.appendChild(s);
	}
	function suggest(e, q) {
		objal('asVal').value = '0';
		if (q.value.length <= 0){ objal('suggest').style.display = 'none'; return};
		objal('suggest').width = q.offsetWidth;
		var e = e || event;
			if(e.keyCode == 13){
				submitForm2(liradakok,q.value);
				return;
				}
		switch (e.keyCode) {
		
		case 38: focus.y--;break;
		case 40:focus.y++;break;
		case 13:  return; break; 		
		case 39:case 37:return;break;
		default: this.rS(q.value);focus.y = -1;return;
		}
		if (focus.y < 0) focus.y = focus.table.rows.length - 1;
		if (focus.y >= focus.table.rows.length) focus.y = 0;
		if (focus.y >= focus.table.rows.length) focus.y = 0;
		this.f(focus);
	}
	function related(q){
		this.rR(q.value);
	}	
	function drawRelated(str) {
		var related = String(str.ResultSet.Result).split(',');
		for (r in related) {
			if (related[r] == '' || related[r] == 'null') continue;
			if (r > 2) break;
			newlink = document.createElement('a');
			newlink.setAttribute('style', 'padding-right:10px;');
			newlink.innerHTML = related[r];
			alert( objal('lnkWeb').href.substring(0, objal('lnkWeb').href.indexOf("q=")))
			newlink.setAttribute('href', objal('lnkWeb').href.substring(0, objal('lnkWeb').href.indexOf("q=")) + "q=" + related[r]);
			objal('related').appendChild(newlink);
			
		}
		if (r < 1){ objal('relContainer').style.display = 'none'; if (objal('webResult')) objal('webResult').style.display = 'block'; }
	}
	function draw(str) {
		var tbody = objal('suggestions');
		if (ac == 2 ) var suggest = String(str[1].items).split(',');
		else var suggest = String(str.items).split(',');
		while (tbody.rows.length) tbody.deleteRow(-1);
			for (s in suggest) {
				if (suggest[s] == '') continue;
				var row = tbody.insertRow(-1); 
				var cell = row.insertCell(0);
				if (ac == 2) var data = str[0] + '<b>' + suggest[s].substr(str[0].length, suggest[s].length) + '</b>';
				else var data = str.query + '<b>' + suggest[s].substr(str.query.length, suggest[s].length) + '</b>';
				cell.innerHTML = data;
				cell.style.width = '';
				row.setAttribute('sugID', s);
				row.onmouseover = function () {
					window.ssgObj.ac.f(focus, this)
				};
				row.onclick = function () {
					objal('q').value = this.cells[0].innerHTML.replace(/(<([^>]+)>)/ig,"");
					objal('asVal').value = ac;
					    window.location.href = "http://"+objal('sType').value+".izledin.com/" + objal('sType').value + "/0/" + strart(objal("q").value)+".html";//objal('SearchForm').submit();
				};
			}
		if (objal('suggest').style.display == 'none') objal('suggest').style.display = 'block';
		if (tbody.rows.length == 0) objal('suggest').style.display = 'none';
		document.onclick = function (e) {
			objal('suggest').style.display = 'none'
		}
}
	
window.ssgObj.ac={s:suggest,r:related,h:draw,hr:drawRelated,rS:reqSuggest,rR:reqRelated,c:call,f:focusOn};

function acp_new(str){
	window.ssgObj.ac.h(str);
}
function yahRel(str){
	window.ssgObj.ac.hr(str);
}


function ajx2(obje,datas,sayfa,yonlendir){
$.ajax({ type: "GET",url: sayfa+"?"+datas,async: false,success : function(text){obje.html(text) ;yonlendir(text);} }); 
  }
  function ajx3(datas,sayfa,yonlendir){
$.ajax({ type: "GET",url: sayfa+"?"+datas,async: false,success : function(text){yonlendir(text);} }); 
  }
 function ajx4(datas,sayfa){
$.ajax({ type: "GET",url: sayfa+"?"+datas,async: false,success : function(text){} }); 
  }
  
(function($){$.fn.jBrowserBookmark=function(options,lang){var defaults=$.extend(opts={language:{'':['[key] + ',' tuslarina basarak ekleyin. ']},defaultLanguage:'',functionButton:['CTRL','CMD']},options);var docUrl=window.location.href;var docTitle=document.title;var browserName;browserName=getBrowser();return this.each(function(){$(this).click(function(e){e.preventDefault();try{switch(browserName){case'konqueror':case'firefox':window.sidebar.addPanel(docTitle,docUrl,'');break;case'msie':window.external.AddFavorite(docUrl,docTitle);break;case'opera':if(versionOpera()<11){$(this).attr('rel','sidebar').attr('title',docTitle).attr('href',docUrl);break;}else{throw error;}default:throw error;}}catch(error){var hotkey=getHotkey(browserName);var alertText=getLanguageText();if(/mac/.test(navigator.platform.toLowerCase()=='mac')){prefix=alertText[0].replace('[key]',opts.functionButton[1]);}else{prefix=alertText[0].replace('[key]',opts.functionButton[0]);}alert(prefix+hotkey+alertText[1]);}});});function getBrowser(){if($.browser.msie){return'msie';}if($.browser.mozilla){return'firefox';}if($.browser.opera){return'opera';}if($.browser.safari&&/chrome/.test(navigator.userAgent.toLowerCase())){return'chrome';}if($.browser.safari){return'safari';}if(/konqueror/.test(navigator.userAgent.toLowerCase())){return'konqueror';}}function getHotkey(browserName){switch(browserName){case'konqueror':return'B';break;case'opera':return(versionOpera()<9)?'T':'D';break;default:return'D';break;}}function getLanguageText(){var languageChosen;if(opts.language[lang]!=undefined){languageChosen=lang;}else{if(opts.language[navigator.language.toLowerCase().substring(0,2)]!=undefined){languageChosen=navigator.language.toLowerCase().substring(0,2);}else{if(opts.language[opts.defaultLanguage]!=undefined)languageChosen=opts.defaultLanguage;else{for(var i in opts.language){languageChosen=i;break;}}}}return opts.language[languageChosen];}function versionOpera(){version=navigator.userAgent.substring(navigator.userAgent.toLowerCase().indexOf('version/')+8);return parseInt(version.substring(0,version.indexOf('.')));}};})(jQuery);
