var TR3_URL = "http://translation1.paralink.com/translator/translator.asp";
//var excDirList = [1 + 65536*8, 8 + 65536*1, 1 + 65536*64];
var excDirList = [1 + 65536*128];
var EXC_DIR_MSG = "len-msg3.htm";
var translation3 = null;

function testDir()
{
  var dirs = document.forms['trans'].directions
  var n = dirs.selectedIndex;
  var dirid = dirs[n].value;
	for(var i = 0; i < excDirList.length; i++){
		if( dirid == excDirList[i]) {
			parent.frames.botfr.location.href = EXC_DIR_MSG;
			return false;
		}
	}
  return true;	
}
   
 function invokeTranslation3 () {

 var opera=(navigator.userAgent.indexOf("Opera")!=-1);
	if(ns4) {
		alert("Netscape 4.7 is not supported by the current version.");
		return true;
	}
	/*if(opera) {
		alert("Opera is not supported by the current version.");
		return true;
	}*/
 var srcLang = getLangId(getSrcLang());
 var trLang = getLangId(getTrLang());
 var str = document.trans.source.value;

  if(str.length > max_len) {
	str = truncStrByWord(str, max_len);
  }

         translation3 = window.open (TR3_URL + "?text=" + escape(str) + "&dir="+ srcLang + "/" + trLang, 
                     "translator",
                     "width=430,height=391,toolbar=no,status=no,menubar=no,directories=no,resizable=no");


/*         translation3 = window.open (
                     "/translator/translator.asp?ctrl=source&dir="+ srcLang + "/" + trLang,
                     "translator",
                     "width=430,height=391,toolbar=no,status=no,menubar=no,directories=no,resizable=no");
*/

      }
      
 function closeTranslation3 () {
         if (translation3 && !translation3.closed)
            translation3.close ();
      }

function friend()
{
    doMail("tellafriend");
  //wndfriend=window.open("friend.asp","wndfriend","left=50,top=20,width=462,height=530,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}

function feedback()
{
  doMail("feedback");
  //wndfeedback=window.open("feedback.asp","wndfeedback","left=50,top=20,width=450,height=450,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}

function help()
{
  wndhelp=window.open("help.asp","wndhelp","left=50,top=20,width=352,height=400,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}

function bookmarkus()
{
  if( navigator.appName.indexOf("Microsoft") >= 0 )
  {
    window.external.AddFavorite( "http://translation2.paralink.com", "Free Translation Online" );
  }
  else
  {
    wndbookmark=window.open("bookmark.asp","bookmark","left=50,top=20,width=352,height=400,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
  }
}

function getLangId(name)
{
	switch ( name )
	 {
	  case "English": return "en"; 
	  case "Russian": return "ru";
	  case "German" : return "de";
	  case "French" : return "fr";
	  case "Spanish": return "es";
	  case "Portuguese": return "pt";
	  case "Italian": return "it";
	 }
	return "";
}

function speller (t2spell)
{

 var lang = getSrcLang();
 var lang2spell;
 lang2spell = getLangId(lang);
			
 if(lang2spell == ""){ 	
	alert("Sorry, the spellchecker for this language is not available.");
        return true;
 }
 
 var query = 'lang=' + lang2spell + '&dic=Normal';
    
    if(checkSource("spell check") != -1 ) {
		invokeSpeller('source', query);
	}
	
 return false;
}

function getSrcLang() {
	var n = document.forms['trans'].directions.selectedIndex;
	var str = document.forms['trans'].directions[n].text;
	return str.substr(0, str.indexOf("-"));
}

function getTrLang() {
	var n = document.forms['trans'].directions.selectedIndex;
	var str = document.forms['trans'].directions[n].text;
	return str.substr(str.indexOf("-")+1, str.indexOf(" ")-(str.indexOf("-")+1));
}


function Check()
{
	return checkSource('translate')

}


function chgdir_submit()
{
	if( checkSource ("") >= 0 ){
		document.chgdir.submit();
	}
	return true;
}

function showNewLenMsg(){
parent.document.body.rows='100%,0%';

  if (document.createElement && document.getElementById)
  {
    var die = document.createElement("iframe");
    die.src = "newbot2.asp";
    die.name = "fake";
    die.id="fake";
    die.width="780";
    die.height="250";
    die.frameBorder="0";

    //adjust positioning if body has a margin
    if (document.body.offsetLeft > 0)
      die.style.marginLeft = document.body.offsetLeft + "px";
//    alert("appended");
    document.body.appendChild(die);

  }
openDialog();

document.getElementById('len_msg_div').style.visibility = "visible";
document.getElementById('len_msg_div').style.display = "block";
document.getElementById('len_msg_div').style.zIndex = 999999;
document.getElementById('len_msg_ifr').src = "len_msg_div/body2.asp";

}
function confirmation(service, max_len2,str) {
var answer = confirm("The free service is able to "+ service +" up to "+ max_len2 +" characters at one time.\nThe text will be trimmed.")
	if (answer){
                str = truncStrByWord(str, max_len2-1); 
                document.trans.source.value = str;
                document.trans.submit();
                return true;
	}
	else{
		return -1;
	}

}

function checkSource(service)
{
        
	var str = document.trans.source.value;
	if(str.length == 0) {
		return 0;
	}

	if(str.length > max_len && max_len < max_len2) {
		if (service == "translate" && !ns4) {
			str = truncStrByWord(str, max_len);  //IR was max_len2
			//document.trans.source.value = str;
			
			showNewLenMsg();
	                return -1;
		    } //endif
		else  {	
			alert("The free service is able to "+ service +" up to "+ max_len2 +" characters at one time.");
			if( typeof(document.chgdir) != "undefined") document.chgdir.i.value = str;
  		    } //endelse
	}else{StartGP('gp');}
        if(str.length > max_len2){return confirmation(service,max_len2, str);}
	return str.length;
}

function truncStrByWord (str, length) {
   if (str.length > length) {
      str = str.substring (0, length + 1);
      //str = str.replace (new RegExp ("\\S*$"), "");
      //str = str.replace(/(.{1,12})\b.*/, "$1");
	str = str.replace(new RegExp("/(.{1,"+length+"})\b.*/"), "$1")    // IR - cuts str to max length without splitting words.
      //str = str.substring (0, length);
   }
   return str;
}		

function length_message()
{
parent.frames['botfr'].location.href="len-msg2.asp";
//window.parent.document.frames["botfr"].location.href="len-msg2.htm";
/*
wndlenmsg=window.open("len-msg.htm","wndlenmsg","left=250,top=250,width=370,height=280,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
//window.showModalDialog("len-msg.htm","wndstrlen","dialogWidth:370px; dialogHeight:280px;scroll:no;help:no;status:no;");
*/
}


function terms()
{
  wndterms=window.open("terms.asp","wndterms","left=50,top=20,width=372,height=500,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}

