var hasfocus=0;

function getCookieVal (offset) 
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) 
 {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function savecorrection(msg1,msg2)
{

 	if(document.forms[0].comment.value.length == 0)
 	{
 	    alert(msg1);
 	    return 1;
   	}
  	else if(document.forms[0].dest.value.length == 0 || document.forms[0].source.value.length == 0)
    {
	  	alert(msg2);
     	return 2;
 	}
 	else
	{
       document.forms[0].submit();
	}
}


function textout(inchar)
{
  if(hasfocus == 1)
  {
    document.forms[0].term_source.value=document.forms[0].term_source.value + inchar;
  	document.forms[0].term_source.focus();
  }
  else if(hasfocus == 2)
  {
    document.forms[0].term_destination.value=document.forms[0].term_destination.value + inchar;
  	document.forms[0].term_destination.focus();
  }
  else if(hasfocus == 3)
  {
    document.forms[0].source.value=document.forms[0].source.value + inchar;
  	document.forms[0].source.focus();
  }
  else if(hasfocus == 4)
  {
    document.forms[0].dest.value=document.forms[0].dest.value + inchar;
  	document.forms[0].dest.focus();
  }
  else if(hasfocus == 5)
  {
    document.forms[0].comment.value=document.forms[0].comment.value + inchar;
  	document.forms[0].comment.focus();
  }
  else if(hasfocus == 6)
  {
    document.forms[0].translation.value=document.forms[0].translation.value + inchar;
  	document.forms[0].translation.focus();
  }
  else if(hasfocus == 7)
  {
    document.forms[0].obs.value=document.forms[0].obs.value + inchar;
  	document.forms[0].obs.focus();
  }
  else if(hasfocus == 8)
  {
    document.forms[0].term_destination2.value=document.forms[0].term_destination2.value + inchar;
  	document.forms[0].term_destination2.focus();
  }
  else if(hasfocus == 9)
  {
    document.forms[0].term_destination3.value=document.forms[0].term_destination3.value + inchar;
  	document.forms[0].term_destination3.focus();
  }
  else if(hasfocus == 10)
  {
    document.forms[0].term_destination4.value=document.forms[0].term_destination4.value + inchar;
  	document.forms[0].term_destination4.focus();
  }
  else if(hasfocus == 11)
  {
    document.forms[0].term_destination5.value=document.forms[0].term_destination5.value + inchar;
  	document.forms[0].term_destination5.focus();
  }
  else
  {
  	document.forms[0].keyword.value=document.forms[0].keyword.value + inchar;
	document.forms[0].keyword.focus();
  }
  
}


	
function CheckLang(from)
{
	var nextind;
	box = document.inputform.FromLang;
}
	
function callfind(word2search)
{
		document.inputform.keyword.value=word2search;
		document.inputform.value = 0;
		document.inputform.submit();
}
	
function CopyToClipboard(msg) 
{	
	tempval = document.szotar.buffer;
	tempval.value = msg
	therange=tempval.createTextRange();
	therange.execCommand("Copy");		
}

function vote(ID)
{
        window.open('votes.php?termID='+ID,'vote','width=350,height=170,toolbar=0,resizable=0');
}


function OpenRequest(id, tipus, lang)
{
        window.location.href ='index.php?action=20&lang='+lang+'&requestID='+id+'&tipus='+tipus,'myrequest';
}

function viewRequest(ID, tipus, lang)
{
        window.location.href='index.php?action=19&requestID='+ID +'&tipus='+tipus;
}

function showuser(username,lang)
{
     var w = 600;
     var h = 400;
     var winl = (screen.width - w) / 2;
     var wint = (screen.height - h) / 2;
     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;

 	newwin = window.open('userprofile.php?lang='+lang+'&username='+username ,'user_profile', winprops);
 	newwin.focus();
	return 0;
}


//***************************//
//    Ajax                  //
//**************************//
function processData( xmlHttp, intID )
{
	// process text data
		switch(intID)
		{
			case 1:
				direction_span.innerHTML = xmlHttp.responseText;
				if(document.forms[0].keyword.value == "")
					window.location.reload();
				break;
			case 2:
				direction_span.innerHTML = xmlHttp.responseText;
				if(document.forms[0].keyword.value == "")
					window.location.reload();
				break;
			case 3:
				if(xmlHttp.responseText.search("ERROR")==-1)
				{
					res_val.innerHTML = xmlHttp.responseText;
				}
				break;	
			case 4:
				//alert(xmlHttp.responseText);
				if(xmlHttp.responseText.search("ERROR")==-1)
				{
					data = xmlHttp.responseText;
					res = data.split("^%");
					if(res.length==3)
					{
						uzenet.innerHTML = res[1];
						req.innerHTML = res[2];
						users.innerHTML = res[0];
					}
				}
				break;	
			case 5:
				if(xmlHttp.responseText.search("ERROR")==-1)
				{
					data = xmlHttp.responseText;
					res = data.split("^%");
					showme = "";
					for(i=0;i<res.length;i++)
					{
						if(res != "")
						{
							showme = showme + res[i] + "<br>";
						}
					}
					if(showme != "")
					{
							check.innerHTML = "<br><font color='red'><i>"+showme+"</i></font>";
							check.style.display = 'inline';
					}
				}
				break;
			case 6:
				data = xmlHttp.responseText;
				google.innerHTML = data;
				break;	
			case 7:
				fb.innerHTML = '<img src="images/connect.gif" align="left"><font face="Tahoma" size="2">'+xmlHttp.responseText+'</font>';
				break;
		}
}


function change_direction()
{
	var strURL = "ajaxrequests.php?function=changedirection";
	sendRequest( strURL,'',0,1); 
}

function disconnect_facebook(username)
{
	var strURL = "ajaxrequests.php?function=disconnect_f&uname="+username;
	sendRequest( strURL,'',0,7); 
}

function change_dictionary(dictionary)
{
	var strURL = "ajaxrequests.php?function=changedictionary&dict=" + dictionary;
	sendRequest( strURL,'',0,2); 

}

function makerequest(language,keyword,fromlang)
{
	var strURL = 'ajaxrequests.php?function=makerequest&lang='+ language +'&Term='+encodeURIComponent(keyword)+'&FromLang='+fromlang;
	sendRequest( strURL,'',0,3);
}

function google_translation(keyword, ls, lt)
{
	window.open('http://translate.google.ca/?hl=en&tab=wT#'+ls+'|'+lt+'|'+keyword,'gt','width=780,height=400,toolbar=0,resizable=1');
}

function update_userstatus()
{
	var strURL = 'ajaxrequests.php?function=updatestatus';
	sendRequest( strURL,'',0,4);
}

function check_translation(source, direction)
{
	var strURL = 'ajaxrequests.php?function=check_translation&direction='+direction+'&source='+source;
	sendRequest( strURL,'',0,5);
}

//********** end ajax **************//


function submitadd(mode)
{
   if(document.forms[0].term_destination.value == "" || document.forms[0].term_source.value == "")
     return 0;
   //setcookie();
   document.forms[0].submit();
}

function CheckLang()
{
	var sel_option = document.forms[0].FromLang.options[document.forms[0].FromLang.selectedIndex].text;
	var array_val = sel_option.split("->");
	if (array_val.length > 1)
	{
        	sourcetag.innerHTML = array_val[0] + ':';
        	destinationtag.innerHTML = array_val[1] + ':';
			destinationtag2.innerHTML = array_val[1] + '2:';
			destinationtag3.innerHTML = array_val[1] + '3:';
			destinationtag4.innerHTML = array_val[1] + '4:';
			destinationtag5.innerHTML = array_val[1] + '5:';
       }
}

function checkterm()
{

    if(document.forms[0].term_source.value == '')
	  return 0;
    parent.frames['checkres'].location.href='checkterm.php?lang=<?php echo $lang; ?>&FromLang='+document.forms[0].FromLang.value+'&keyword='+document.forms[0].term_source.value;
    //parent.frames['checkres'].location.reload();
    check_term = 1;
    checkit.style.display = 'inline';
}

function tip_it(which, TTitle, TContent)
{
	if(which)
	{
	//	tip_active = 1;
		document.onmousemove = getMouseXY;
		if(mouse_X == 0)
			return;
		obj=document.getElementById('ToolTip');
		ContentInfo = EnterContent(TTitle, TContent);
		obj.innerHTML = ContentInfo;
		update_tip_pos(obj.offsetHeight);
		obj.style.visibility = "visible";
	}
	else{
	//	tip_active = 0;
		document.getElementById('ToolTip').style.visibility = "hidden";
	}
}

function update_tip_pos(magas){
		document.getElementById('ToolTip').style.left = mouse_X + 20;
		document.getElementById('ToolTip').style.top  = mouse_Y - (magas/2);
}

function getMouseXY(e) 
{
	if (ie) 
	{ // grab the x-y pos.s if browser is IE
		mouse_X = event.clientX + document.body.scrollLeft;
		mouse_Y = event.clientY + document.body.scrollTop;
	}
	else 
	{ // grab the x-y pos.s if browser is NS
		mouse_X = e.pageX;
		mouse_Y = e.pageY;
	}
	if (mouse_X < 0){mouse_X = 0;}
	if (mouse_Y < 0){mouse_Y = 0;}
	//if(tip_active==1){update_tip_pos();}
}

function EnterContent(TTitle, TContent)
{
	ContentInfo = '<table border="0" width="300" cellspacing="0" cellpadding="0" bgcolor="#EEEEEE">'+
	'<tr><td width="100%">'+
	'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
	'<tr><td width="100%" >'+
	'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center" bgcolor=#00000>'+
	'<tr><td width="100%">'+
	'<font class="tooltiptitle"><a href="javascript:document.getElementById(\'ToolTip\').style.visibility=\'hidden\';void(0);">X</a>&nbsp;'+TTitle+'</font>'+
	'</td></tr>'+
	'</table>'+
	'</td></tr>'+
	'<tr><td width="100%">'+
	'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+
	'<tr><td width="100%">'+
	'<font class="tooltipcontent">'+TContent+'</font>'+
	'</td></tr>'+
	'</table>'+
	'</td></tr>'+
	'</table>'+
	'</td></tr>'+
	'</table>';
	return ContentInfo;
}

function openmail(mailid, lang)
{
    window.location.href='index.php?action=23&msgid='+mailid;
}

function menu(cella, val)
{
   obj = document.getElementById(cella);
   obj.style.cursor = 'hand';

 	if(val)
 	{
      obj.bgColor = "#D4D0C8";
  	  obj.style.borderLeftStyle = "solid";
	  obj.style.borderRightStyle = "solid";
 	  obj.style.borderLeftColor = "#919b9c";
 	  obj.style.borderRightColor = "#919b9c";
 	  obj.style.borderRightWidth = "1px";
 	  obj.style.borderLeftWidth  = "1px";
	}
	else
	{
	  obj.bgColor = "#C0C0C0";
	  obj.style.borderLeftStyle = "solid";
	  obj.style.borderRightStyle = "solid";
 	  obj.style.borderLeftColor = "#C0C0C0";
 	  obj.style.borderRightColor = "#C0C0C0";
 	  obj.style.borderRightWidth = "1px";
 	  obj.style.borderLeftWidth  = "1px";
    }
}

function viewHistory(tipus,lang)
{
     window.location.href ='index.php?action=33&mode=' + tipus;
}

function refreshlist()
{
                
    if(document.forms[0].filter.checked)
	{
		alfabet.style.display = 'inline';
           querystr = 'index.php?action=18&filter=1&letter=A';
	}
	else
	{
		alfabet.style.display = 'none';
	    querystr = 'index.php?action=18&filter=0';
	}       
    window.location.href = querystr;
}
	
function get_letter(letter)
{
	window.location.href = 'index.php?action=18&filter=1&letter=' + letter;
}
	
function get_topten()
{
	window.location.href = 'index.php?action=18&filter=1&topten=1';
}
	
//ketch the Enter action off search box	
function searchit(e)
{
	var key;
 	if(window.event)
	   key = window.event.keyCode;     //IE
	else
	   key = e.which;     //firefox
	if(key == 13)
	{
	 	if(document.forms[0].searchtxt.value != '')
		{
			window.location.href = 'index.php?action=18&filter=1&keyword='+ document.forms[0].searchtxt.value;
		}
	    return false;
	}
	else
	    return true;
}

function showuser(username, lang)
{
    window.location.href ='index.php?action=21&username='+username;
	return 0;
}

function submit_req(tip, missing,reason)
{
   if( tip <3  && document.forms[0].translation.value == '')
   {
	alert(missing);
	return 0;
   }
   
   if( tip==3  && document.forms[0].obs.value == '')
   {
	alert(reason);
	return 0;
   }

   document.forms[0].Save.value = tip;
   document.forms[0].submit();
}

function submit_ownreq(tip)
{
   document.forms[0].Save.value = tip;
   document.forms[0].submit();
}

function setSelRange(inputEl, selStart, selEnd)
{
	  if (inputEl.setSelectionRange)
	  {
	    inputEl.focus();
	    inputEl.setSelectionRange(selStart, selEnd);
	   } 
	   else if (inputEl.createTextRange)
	   {
	      var range = inputEl.createTextRange();
	      range.collapse(true);
	      range.moveEnd('character', selEnd);
	      range.moveStart('character', selStart);
	      range.select();
	    }
}

function submit_readmail(tipus)
{
   		if(tipus==1)
   		{
  			document.forms[0].tipus.value =1;
     	}
     	else
     		document.forms[0].tipus.value =2;
       // document.forms[0].bodytxt.value=body;
 		document.forms[0].submit();
}

function setpicture(pictfile)
{
	document.forms[0].picturefile.value = pictfile;
}

function showhide_stat()
{
	if(stat.style.display == 'none')
		stat.style.display = 'inline';
	else
		stat.style.display = 'none';
}

function showhide_news()
{
	if(news.style.display == 'none')
		news.style.display = 'inline';
	else
		news.style.display = 'none';
}

function filter_selection(gomb)
{
	gomb.checked=true;
	void(0);
}

function filter_selection2(gomb)
{
	if(gomb.checked == true)
		gomb.checked=false;
	else 
		gomb.checked=true;
	void(0);
}
