var selectedKeyword="";
var DID=0;
var sourceLanguage=0;
var targetLanguage=0;
var styleColorList=new Array("#E3A1C4", "#C8C866", "#FFBD00", "#DFDFFF", "#80FF80", "#EAEAFF", "#C9FFA8", "#DDDD00");
var DictionaryFormTOP='90';

function opacity(id, opacStart, opacEnd, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	if (opacity==0){object.visibility='hidden';}else{object.visibility='visible';}
}



window.onscroll = function()
{
	if( window.XMLHttpRequest ) {
			
			document.getElementById('BottomDIV').style.position = 'fixed';
			document.getElementById('BottomDIV').style.bottom = '0px';
			document.getElementById('LoginFormDIV').style.position = 'fixed';			
			document.getElementById('LoginFormDIV').style.bottom = '38px';
			document.getElementById('LoginFormOKDIV').style.position = 'fixed';			
			document.getElementById('LoginFormOKDIV').style.bottom = '38px';
			document.getElementById('RegisterFormDIV').style.position = 'fixed';			
			document.getElementById('RegisterFormDIV').style.bottom = '38px';
			document.getElementById('RegisterFormOKDIV').style.position = 'fixed';			
			document.getElementById('RegisterFormOKDIV').style.bottom = '38px';
			document.getElementById('RegisterFormErrorDIV').style.position = 'fixed';			
			document.getElementById('RegisterFormErrorDIV').style.bottom = '38px';
			
			
		if (document.documentElement.scrollTop > DictionaryFormTOP) {
			document.getElementById('DictionaryFormDIV').style.position = 'fixed';
			document.getElementById('DictionaryFormDIV').style.top = '0px';
		} else {
			document.getElementById('DictionaryFormDIV').style.position = 'absolute'; 
			document.getElementById('DictionaryFormDIV').style.top = DictionaryFormTOP+'px';
		}
	}
}

function showhideLingoBar(){
	if (document.getElementById('topDIV').style.display=="none"){
		document.getElementById('topDIV').style.display="";
		opacity('topDIV', 0, 100, 500);
		document.getElementById("LingoBarButtonsDIV").innerHTML='<a href="javascript:showhideLingoBar();"  class="showHide" title="Lingo Sözlük Bari Gizle!">Gizle <img src="images/close.gif" border="0" alt="Lingo Sözlük Bari Gizle!" ></a>';
		DictionaryFormTOP='90';
		
		}else{
		opacity('topDIV', 100, 0, 500);
		setTimeout("document.getElementById('topDIV').style.display='none'",500);
		document.getElementById("LingoBarButtonsDIV").innerHTML='<a href="javascript:showhideLingoBar();"  class="showHide" title="Lingo Sözlük Bari Göster!">Göster <img src="images/arrow1.png" border="0" alt="Lingo Sözlük Bari Göster!"></a>';
		DictionaryFormTOP='0';
		
		}
		document.getElementById('DictionaryFormDIV').style.top = DictionaryFormTOP+'px';
}

function showhideDIV(DivID){
	if(document.getElementById(DivID).style.display=='none'){
		document.getElementById(DivID).style.display='';
		}else{
			document.getElementById(DivID).style.display='none';
			}
	
}
///////////////////////////0000000000000000000000000000000000//////////////////
function loadXMLDoc(Keyword) {
stripWS = true;
var Rnd = 0;
opacity("ResultsDIV", 100, 0, 500);
if (Keyword==""){
	Rnd = Math.round(10000*Math.random())
	}
	xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")
	document.getElementById('loadingDIV').style.visibility="visible";
	xmlRequestObj.onreadystatechange = proccessXML;
	xmlRequestObj.open("GET", 'SelectWord2.asp?Keyword='+Keyword+'&DID='+DID+'&'+Rnd, true);
	xmlRequestObj.setRequestHeader("Content-Type", "text/html; charset=iso-8859-9");//("Content-type", "application/x-www-form-urlencoded;charset=iso-8859-9");
	xmlRequestObj.send(null);
}
function is_ws(nod) {
	return !(/[^\t\n\r ]/.test(nod.data));
}
function findWhiteSpace(node, nodeNo) {
	for (i=0; i<node.childNodes.length; i++) {
		if (node.childNodes[i].nodeType == 3 && is_ws(node.childNodes[i])) {
			nodesToDelete[nodesToDelete.length] = node.childNodes[i]
		}
		if (node.childNodes[i].hasChildNodes()) {
			findWhiteSpace(node.childNodes[i], i);
		}
	}
	node = node.parentNode;
	i = nodeNo;
}
function stripWhiteSpace(node) {
	nodesToDelete = Array();
	findWhiteSpace(node, 0);
	for(i=nodesToDelete.length-1;i>=0;i--) {
		nodeRef = nodesToDelete[i];
		nodeRef.parentNode.removeChild(nodeRef)
	}
}
function proccessXML() {
	if (xmlRequestObj.readyState == 4 && (xmlRequestObj.status == 200 || xmlRequestObj.status == 304)) {
//		if(stripWS) {			stripWhiteSpace(xmlRequestObj.responseXML);		}
		
		//resultXML = xmlRequestObj.responseXML;
		document.getElementById("ResultsDIV").innerHTML=xmlRequestObj.responseText;
		document.getElementById('loadingDIV').style.visibility="hidden";
		document.documentElement.scrollTop=0;
		opacity("ResultsDIV", 0, 100, 500);
	}
}
function selfSearch(Keyword){
	if (Keyword!="" && Keyword!=document.DictionaryForm.Keyword.value){
		document.DictionaryForm.Keyword.value=Keyword;
		loadXMLDoc(document.DictionaryForm.Keyword.value);
	}
}
function dafaultSearch(){
	if (document.DictionaryForm.Keyword.value!=""){
		loadXMLDoc(document.DictionaryForm.Keyword.value);
	}
}
//////////////////////////
function addOpenSearchTr() {
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.lingosozluk.com/tools/opensearchturkish.xml");
 } else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine("http://www.lingosozluk.com/tools/LingoSozluk.src",
                                  "http://www.lingosozluk.com/images/icon.gif",
                                  "LingoSözlük", "Dictionary");
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("Tarayiciniz arama motorlarini desteklemiyor");
 }
}
//////////////////////
function dblclick() {
	window.scrollTo(0,0)
	getSelText()
}
if (document.layers) {
	document.captureEvents(Event.ONDBLCLICK);
}
document.ondblclick=dblclick;
//////////////
function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
document.DictionaryForm.Keyword.value =  txt;
dafaultSearch()
}



function switchDID()
{
	DID=0;
	if (sourceLanguage==1 && targetLanguage==2){DID=1;document.getElementById("DictionaryStatusDIV").innerHTML="Türkçe'den Ingilizce'ye";}
	if (sourceLanguage==2 && targetLanguage==1){DID=2;document.getElementById("DictionaryStatusDIV").innerHTML="Ingilizce'den Türkçe'ye";}
	if (sourceLanguage==1 && targetLanguage==1){DID=3;document.getElementById("DictionaryStatusDIV").innerHTML="Türkçe Sözlük";}
	if (sourceLanguage==3 && targetLanguage==1){DID=4;document.getElementById("DictionaryStatusDIV").innerHTML="Almanca'dan Türkçe'ye";}
	if (sourceLanguage==1 && targetLanguage==3){DID=5;document.getElementById("DictionaryStatusDIV").innerHTML="Türkçe'den Almanca'ya";}	
	if (sourceLanguage==4 && targetLanguage==1){DID=6;document.getElementById("DictionaryStatusDIV").innerHTML="Fransizca'dan Türkçe'ye";}
	if (sourceLanguage==1 && targetLanguage==4){DID=7;document.getElementById("DictionaryStatusDIV").innerHTML="Türkçe'den Fransizca'ya";}	

	if (sourceLanguage==2 && targetLanguage==2){DID=0;document.getElementById("DictionaryStatusDIV").innerHTML="Ingilizce'den Ingilizce'ye Yakinda!";}
	
	loadXMLDoc(document.DictionaryForm.Keyword.value);
	}
function switchSourceLanguage(sourceLanguageID)
{
	sourceLanguage=sourceLanguageID;
	switchDID();
	
	document.getElementById("S1").className = "LanguageImages";
	document.getElementById("S2").className = "LanguageImages";
	document.getElementById("S3").className = "LanguageImages";
	document.getElementById("S4").className = "LanguageImages";	
	document.getElementById("S"+sourceLanguageID).className = "LanguageImagesSelected";		
	
	}
function switchTargetLanguage(targetLanguageID)
{
	targetLanguage=targetLanguageID;
	switchDID();	
		
	document.getElementById("T1").className = "LanguageImages";
	document.getElementById("T2").className = "LanguageImages";
	document.getElementById("T3").className = "LanguageImages";
	document.getElementById("T4").className = "LanguageImages";	
	document.getElementById("T"+targetLanguageID).className = "LanguageImagesSelected";		
	
	}
function switchLanguages()
{
	var temp=targetLanguage;
	targetLanguage=sourceLanguage;
	sourceLanguage=temp;
	switchSourceLanguage(sourceLanguage);
	switchTargetLanguage(targetLanguage);
	}
function display() {
if(selectedKeyword!=""){return false;}
  if (document.getSelection) {
    var str = document.getSelection();
  } else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    var str = range.text;
  } else {
    var str = "Sorry, this is not possible with your browser.";
  }
  if(str!="" && str.length<50){
	    selectedKeyword=str;
		document.getElementById("selectionSearchDIV").innerHTML='<img src="images/ampul.png" hspace="2" vspace="2" ><strong>"'+str+'"</strong> Sizin için aramamizi ister misiniz? <a href="javascript:void(0);" onclick="seledtedSeach();"> <img src="images/oks.png" hspace="2" vspace="2" border="0" ></a> <a href="javascript:clearseledtedSeach();"><img src="images/cancel.png" hspace="2" vspace="2" border="0"></a>';
		opacity('selectionSearchDIV', 0, 100, 500);
  }else{
	  document.getElementById("selectionSearchDIV").innerHTML=""
	  }
}

if (window.Event){document.captureEvents(Event.MOUSEUP);}
document.onmouseup = display;

function seledtedSeach(){
	document.DictionaryForm.Keyword.value=selectedKeyword;
	loadXMLDoc(document.DictionaryForm.Keyword.value);
	selectedKeyword="";
	opacity('selectionSearchDIV', 100, 0, 500);
	}
function clearseledtedSeach(){
	opacity('selectionSearchDIV', 100, 0, 500);
	selectedKeyword="";
	}

function wordTROver(Word){
document.getElementById(Word+'TR').bgColor='#FFFF99';
document.getElementById(Word+'MainTR').bgColor='#FFFF99';
document.getElementById(Word+'ButtonsDIV').style.visibility='visible';
	}

function wordTROut(Word,bgcolor){
document.getElementById(Word+'TR').bgColor=bgcolor;
document.getElementById(Word+'MainTR').bgColor=bgcolor;
document.getElementById(Word+'ButtonsDIV').style.visibility='hidden';
	}
	

function openWordPop(WordP,WordV,DictionaryID){
	if(document.getElementById(WordP+'PopDIV')){
		opacity(WordP+'PopDIV', 0, 100, 500)
		return false;
		}
	var x,y,styleColor;	
	if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
  	}
  if (browser.isNS) {
    x = window.scrollX;
    y = window.scrollY;
  } 
  styleColor=styleColorList[Math.floor(Math.random()*styleColorList.length)]
  document.getElementById("WordBoxesDIV").innerHTML=document.getElementById("WordBoxesDIV").innerHTML+'<div id=\''+WordP+'PopDIV\' class="box" style="left:'+x+'px; top:'+y+'px;display:; border: 1px solid '+styleColor+';"> <div class="bar" style="height:20px; background-color:'+styleColor+';" ondblclick="showhideDIV(\''+WordP+'contentDIV\');" onmousedown="dragStart(event, \''+WordP+'PopDIV\')"><div style="float:left;">'+WordV+'</div><div style="float:right;"><a href="javascript:void(0);" onclick="showhideDIV(\''+WordP+'contentDIV\');"><img src="images/minmax.gif" hspace="2" vspace="2" border="0" /></a><a href="javascript:void(0);" onclick="opacity(\''+WordP+'PopDIV\', 100, 0, 500);"><img src="images/close.gif" hspace="2" vspace="2" border="0" /></a></div></div><div id="'+WordP+'contentDIV" class="content"  ></div></div>'
  document.getElementById(WordP+'contentDIV').innerHTML='<strong>'+WordV+':</strong> '+document.getElementById(WordP+'MeaningDIV').innerHTML
}



