/* resimleri kontrol et*/

function checkImages(){
   sitePictures  = getElementsByClassName(document,"img","sitePic");
   linkPictures  = getElementsByClassName(document,"a","picLink");
   for(sp =0;sp<sitePictures.length;sp++){
      if(sitePictures[sp].width==124){
         linkPictures[sp].innerHTML="";
      }
      
   }
}
function openHighlight(){
    inputHighligts = getElementsByClassName(document,"input","inputHL");
    for(ih=0;ih<inputHighligts.length;ih++){
       inputHighligts[ih].value="on";
    }
}
function closeHighlight(){
    inputHighligts = getElementsByClassName(document,"input","inputHL");
    for(ih=0;ih<inputHighligts.length;ih++){
       inputHighligts[ih].value="off";
    }
}
/* ARANAN KELIMELERI SE�LI HALE GETIR GETIRME */
function highlightKeyword(){
   try{
     $("on").id = "off"; 
     closeHighlight();
     try{ $("on2").id = "off2"; }catch(Exception){/*ignore*/}
     DWRUtil.setValue("hl","off");
      try{
		    high1s = getElementsByClassName(document,"span","r01");
		     for(h1=0;h1<high1s.length;h1++){
		        high1s[h1].className = "highlight0";
		        
		    }
		    high2s = getElementsByClassName(document,"span","r02");
		     for(h2=0;h2<high2s.length;h2++){
		        high2s[h2].className = "highlight1";
		        
		     }
		    high3s = getElementsByClassName(document,"span","r03");
		     for(h3=0;h3<high3s.length;h3++){
		        high3s[h3].className = "highlight2";
		        
		     }
			 high4s = getElementsByClassName(document,"span","r04");
		     for(h4=0;h4<high4s.length;h4++){
		        high4s[h4].className = "highlight3";
		     }
		     high5s = getElementsByClassName(document,"span","r05");
		     for(h5=0;h5<high5s.length;h5++){
		        high5s[h5].className = "highlight4";
		     }
	     }
    	catch(Exception){
    	 //INGORE
   	    }
   }
   catch(Exception){
    $("off").id = "on";
   openHighlight();
   try{ $("off2").id = "on2"; }catch(Exception){/*ignore*/}
   DWRUtil.setValue("hl","on");
       try{
		    high1s = getElementsByClassName(document,"span","highlight0");
		     for(h1=0;h1<high1s.length;h1++){
		        high1s[h1].className = "r01";
		        
		    }
		    high2s = getElementsByClassName(document,"span","highlight1");
		     for(h2=0;h2<high2s.length;h2++){
		        high2s[h2].className = "r02";
		        
		     }
		    high3s = getElementsByClassName(document,"span","highlight2");
		     for(h3=0;h3<high3s.length;h3++){
		        high3s[h3].className = "r03";
		        
		     }
			 high4s = getElementsByClassName(document,"span","highlight3");
		     for(h4=0;h4<high4s.length;h4++){
		        high4s[h4].className = "r04";
		     }
		     high5s = getElementsByClassName(document,"span","highlight4");
		     for(h5=0;h5<high5s.length;h5++){
		        high5s[h5].className = "r05";
		     }
	     }
    	catch(Exception){
    	 //INGORE
   	    }
    } 
}



function createResultArea(){
  if($("clusterArea").style.display ==""){
   newWidth = document.body.offsetWidth-170;
   $("resultArea").style.width=newWidth+"px";
  }
  else{
  newWidth = document.body.offsetWidth;
  $("resultArea").style.width=newWidth+"px";
  }
}

function createResultArea2(){
  newWidth = document.body.offsetWidth;
  $("resultArea").style.width=newWidth+"px";
 
}
function testGetByClass(){
  titles = new Array();
  titles =  getElementsByClassName(document,"div","title");
  //alert(titles.length);
}
/* CLUSTER AC KAPA */
function openCluster(){
    //DWRUtil.setValue("useclstr","on");
    inputClusters  = getElementsByClassName(document,"input","inputISC");
    for(ic=0;ic<inputClusters.length;ic++){
      inputClusters[ic].value="true";
    }
    //createResultArea();
}
function closeCluster(){
 //DWRUtil.setValue("useclstr","off");
 inputClusters  = getElementsByClassName(document,"input","inputISC");
    for(ic=0;ic<inputClusters.length;ic++){
      inputClusters[ic].value="false";
    }
    //createResultArea2();
}

function showCluster(){
 $("clusterArea").style.display = "";
 createResultArea();
}
function hideCluster(){
 $("clusterArea").style.display = "none";
 createResultArea2();
}
function controlClusterArea(){
   if($("useclstr").checked)
     openCluster();
   else
     closeCluster();
}

function changeSite(newSite) {
	inputSites  = getElementsByClassName(document,"input","inputSite");
  for(is=0;is<inputSites.length;is++){
    inputSites[is].value=newSite;
  }
}

/* TURKCE KARAKTERLERI YAZ*/
function typeLetter(theLetter){
    insertCharacter($("q"),theLetter);
}

function typeLetter2(theLetter){
   insertCharacter($("q2"),theLetter);
}
function typeLetter3(theLetter,inputTextRow){
   inputTextId = "q"+inputTextRow;
   
   insertCharacter($(inputTextId),theLetter);
}
function focusKlavye(inputTextRow){
   for(inp = 1;inp<4;inp++)
   {
     charDivId = "trchars"+inp;
	 if(inp!=inputTextRow)
	   $(charDivId).style.display="none";
	 else
	  $(charDivId).style.display="";
   }
}
function insertCharacter(mF, mV) {
	if (document.selection) {
	var t;mF.focus();
	sel=document.selection.createRange();t=sel.text.lenght;sel.text=mV;
	if (mV.length==0){sel.moveStart('character',mV.length);
	sel.moveEnd('character',mV.length);
	}else {
	sel.moveStart('character',-mV.length+t);
	}sel.select();
	}else if (mF.selectionStart || mF.selectionStart=='0'){
	var sP=mF.selectionStart;
	var eP=mF.selectionEnd;
	mF.value=mF.value.substring(0,sP)+mV+mF.value.substring(eP,mF.value.length);
	mF.selectionStart=sP+mV.length;
	mF.selectionEnd=sP+mV.length;
	mF.focus();
	}else{
	mF.value+=mV;}
}

//SELECT CLUSTER RESULTS
function selectCluster(who){

  if(who.className!==""){
  who.className= "";
  try{
  $("cl_selected").className="cluster_li" ;
  oldContent =  $("cl_selected").innerHTML;
  oldContent = "<a href='#'>"+oldContent+"</a>";
   $("cl_selected").innerHTML=oldContent;
  $("cl_selected").id="";
  
   //$(cluster).href="";
  }
  catch(Exception){alert(Exception.message);}
  who.id="cl_selected";
  first = $("cl_selected").innerHTML.indexOf(">");
  newContent = $("cl_selected").innerHTML.substring(first);
  end = newContent.indexOf("<");
  $("cl_selected").innerHTML=newContent.substring(1,end);
  }
  
}
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements);
}

function initPage(){
  createResultArea2();
  isClustered = DWRUtil.getValue("cl");
  if(isClustered!="true"){
    hideCluster();
    closeCluster();
  }
  else {
    showCluster();
    openCluster();
  }
  highlightKeyword();
  //setTimeout("checkImages()",1000);
}
function initNotFoundPage(){
  createResultArea2();
}
function searchPage(qry,start){
   if(qry==null)
    qry  = DWRUtil.getValue("q");
    cl = DWRUtil.getValue("cl");
    hl = DWRUtil.getValue("hl");
    if(start==null)
	    start = DWRUtil.getValue("startVal");
    parameters = "?q="+qry+"&strt="+start+"&isq=true";
    if(cl != null)
    	parameters += "&cl="+cl;
   	if(hl != null)
    	parameters += "&hl="+hl;
    window.location = "ara"+parameters;
}

function searchPage2(qry,start){
   if(qry==null)
    qry  = DWRUtil.getValue("q2");
    cl = DWRUtil.getValue("cl");
    hl = DWRUtil.getValue("hl");
    if(start==null)
	    start = DWRUtil.getValue("startVal");
    parameters = "?q="+qry+"&strt="+start+"&isq=true";
    if(cl != null)
      parameters += "&cl="+cl;
   	if(hl != null)
    	parameters += "&hl="+hl;    
    window.location = "ara"+parameters;
}

function changeTab(el, target, params) {
	qry  = DWRUtil.getValue("q");
	el.href = target;
	if(qry!=null && qry != "" && params != null && params!="")
		el.href += "?";
	if(qry!=null && qry != "")
		el.href += "?q=" + qry;
	if(params!=null && params != "")
		el.href += params;
}

function searchClusteredPage(cid){
    qry  = DWRUtil.getValue("q");
    cl = DWRUtil.getValue("cl");
    hl = DWRUtil.getValue("hl");
    site = DWRUtil.getValue("site");
    domain = DWRUtil.getValue("domain");
    parameters = "?q="+qry+"&strt="+0+"&cind="+cid+"&isq=true";
    if(site != null) 
    	parameters += "&site="+site;
    if(domain != null) 
    	parameters += "&domain="+domain;
    if(cl != null)
      parameters += "&cl="+cl;
   	if(hl != null)
    	parameters += "&hl="+hl;    
    window.location = "ara"+parameters;
}
function controlAction(e){
  keynum = e.keyCode;
  if(keynum==13)
   searchPage(null,0);
}
function controlAction2(e){
  keynum = e.keyCode;
  if(keynum==13)
   searchPage2(null,0);
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
     
function fixPNG(myImage) 
{
  if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
  {
    var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
    var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
    var imgTitle = (myImage.title) ? 
      "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
    var imgStyle = "display:inline-block;" + myImage.style.cssText
    var strNewHTML = "<span " + imgID + imgClass + imgTitle
      + " style=\"" + "width:" + myImage.width 
      + "px; height:" + myImage.height 
      + "px;" + imgStyle + ";"
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
          myImage.outerHTML = strNewHTML   
  }
}
