      isMac=(navigator.appVersion.indexOf("Mac")!=-1);
       isNS=(navigator.appName.indexOf("Netscape")!=-1);
    isOpera=(navigator.userAgent.indexOf("Opera")!=-1);
isKonqueror=(navigator.userAgent.indexOf("Konqueror")!=-1);
      isDOM=(document.getElementById)?true:false;
       isIE=(document.all)?true:false;
      isIE4=isIE&&!isDOM;
     isIE4M=isIE4&&isMac;
   isIE5or6=isIE&&isDOM;
      isNS4=(document.layers)?true:false;
   isNS4old=(isNS4&&(parseFloat(navigator.appVersion)<4.02));
      isNS6=isNS&&isDOM;

function Prepend(Q,L,c){
	var S=Q+'';
	if (c.length>0) while(S.length<L){S=c+S};
	return S;
}
function StrU(X,M,N){
	var T,S=new String(Math.round(X*Number("1e"+N)))
	if (/\D/.test(S)){return ''+X}
	with (new String(Prepend(S, M+N,'0')))
	return substring(0,T=(length-N))+'.'+substring(T)
}
function StrT(X, M, N){return Prepend(StrU(X,1,N),M+N+2,' ')}
function StrS(X, M, N){return StrU(Math.abs(X),M,N)}
Number.prototype.toFixed=new Function('n','return StrS(this,1,n)')

function strTrim(){return this.replace(/^\s+/,"").replace(/\s+$/,"");}
String.prototype.trim=strTrim;

function focusField(objElement){if(objElement.value==objElement.defaultValue)objElement.value="";return true;}
function blurField(objElement){if(objElement.value=="")objElement.value=objElement.defaultValue;return true;}

function setCookie(strName, strValue){
	var dtmExpires=new Date(2015,9,21,12,0,0);
	document.cookie=strName+"="+escape(strValue)+"; expires="+dtmExpires.toGMTString()+"; domain=freetranslation.com; path=/";
}

function getCookie(name){
	var dc=document.cookie;
	var prefix=name+"=";
	var begin=dc.indexOf("; "+prefix);
	if (begin==-1){
		begin=dc.indexOf(prefix);
		if(begin!=0)return null;
	}else{
		begin+=2;
	}
	var end=document.cookie.indexOf(";",begin);
	if(end==-1)end=dc.length;
	return unescape(dc.substring(begin+prefix.length,end));
}

function selectLanguage(objElement,strLang){
	for (var i=0;i<objElement.length;i++){
		if(strLang==objElement[i].value){objElement[i].selected=true;}
	}
}

function doClipboard(objElement, strCmd){
	objElement.focus();
	objElement.select();
	if(document.all){
		var objRange = objElement.createTextRange();
		objRange.execCommand(strCmd);
	}else{
		switch(strCmd){
			case "Copy":
				alert("How to copy text to your clipboard:\n\n- Select the text you want to copy.\n- On your browser's \"Edit\" menu, click \"Copy\".\n\nPC Shortcut:\tCtrl+C\n\nMac Shortcut:\tCommand+C");
				break;
			case "Cut":
				alert("How to cut (or move) text to your clipboard:\n\n- Select the text you want to move.\n- On your browser's \"Edit\" menu, click \"Cut\".\n\nPC Shortcut:\tCtrl+X\n\nMac Shortcut:\tCommand+X");
				break;
			case "Paste":
				alert("How to paste text into our web page:\n\n- Click inside the area where you want the text to appear.\n- On your browser's \"Edit\" menu, click \"Paste\".\n\nPC Shortcut:\tCtrl+V\n\nMac Shortcut:\tCommand+V");
				break;
		}
	}
}

function insertChar(objList){
	var intSelected=objList.selectedIndex;
	if(intSelected!=0){
		if(isIE&&!isMac){
			document.frmTranslator.srctext.focus();
			var strRange=document.selection.createRange();
			var strChar=objList.options[intSelected].value;
			strRange.text=strChar;
		}else{
			strText=document.frmTranslator.srctext.value;
			strText=strText+objList.options[intSelected].value;
			document.frmTranslator.srctext.value=strText;
		}
		objList.selectedIndex=0;
		document.frmTranslator.srctext.focus();
	}
}

var blnSubmitted = false;
function xl8Txt(objForm,blnCheckDefaultText){
	with(objForm.srctext){
		if(blnSubmitted){
			alert("Your request is being processed. Please wait.");
			return false;
		}else if((blnCheckDefaultText&&value==defaultValue)||value.length==0||value.search(/\S/)==-1){
			alert("Please enter some text to translate.");
			focus();
			return false;
		}else if(value.length>10000){
			alert("The text to translate cannot exceed 10000 characters.\n\nPlease remove some of your text and try again.");
			focus();
			return false;
		}else{
			blnSubmitted=true;
			objForm.Submit.value="Translating...";
			objForm.Submit.disabled=true;
			objForm.a.disabled=true;
			objForm.e.disabled=true;
			objForm.i.disabled=true;
			objForm.o.disabled=true;
			objForm.u.disabled=true;
			objForm.misc.disabled=true;
			return true;	
		}
	}
}

function isValidURL(strURL){
	strURL=strURL.trim();
	if(strURL.lastIndexOf(".")>-1){
		var strExtension=strURL.substring(strURL.lastIndexOf(".")+1, strURL.length);
		var regEx=/avi|bmp|class|css|doc|exe|gif|java|jpeg|jpg|js|m3u|mp3|mov|mpg|mpeg|pdf|png|rar|rtf|swf|tif|wav|wma|zip/i;
		if(regEx.test(strExtension)){
			return false;
		}
	}else{
		return false;
	}
	return true;
}

function xl8Web(objForm,blnCheckDefaultText){
	with(objForm.url){
		if(blnSubmitted){
			alert("Your request is being processed. Please wait.");
			return false;
		}else if((blnCheckDefaultText&&value==defaultValue)||value.length==0||value.search(/\S/)==-1){
			alert("Enter a website address to translate.");
			focus();
			return false;
		}else if(!isValidURL(value)){
			alert("This file extension is not supported. Please enter a different website address.");
			focus();
			return false;
		}else{
			blnSubmitted=true;
			objForm.Submit.value="Translating...";
			objForm.Submit.disabled=true;
			return true;	
		}
	}
}

function printText(strTitle, strContents){
	document.frmPrint.title.value=strTitle;
	document.frmPrint.contents.value=strContents;
	document.frmPrint.submit();
}

function charsLeft(objChars, objCount){
	var intCount, strCountSuffix;
	intCount=10000-objChars.value.length;
	if(intCount<0){
		objCount.className="countError";
		intCount=-intCount;
		strCountSuffix=(intCount==1)?" character over":" characters over";
	}else{
		objCount.className="count";
		strCountSuffix=(intCount==1)?" character left":" characters left";
	}
	objCount.value=intCount+strCountSuffix;
}
