var LangCookieName	= "ETTranslatorLanguage";
var LaunchCookieName	= "ETTranslatorAutoLaunch";


function disableMouseBubbling(element)
{
$(element).mousedown(function(e){e.stopPropagation();});
$(element).mouseup(function(e){e.stopPropagation();});
}
function documentMouseup(e)
{	
  translateContent=dictGetSel();
  //if selection is empty, don't do anything
  if(translateContent=="")
  {
  	return false;
  }
  //disable popup in textbox
  if(isInput)
  {
  	return false;	
  }
  
 if(!autoLaunch)
 {
	  //position and show the popup div
	  var popup=$(transMenuName);
	  popup.css("left",e.pageX+"px");
	  popup.css("top",e.pageY+"px");
	  popup.show();
  }else
  {
  	document.selection.empty();
  	dictShow(translateContent);
  }
}
var isInput=false;
function documentMousedown(e)
{
  if(!autoLaunch)
  {
	  if (!e) var e = window.event;
	  //disable popup in textbox
	  var relTarg = e.relatedTarget||e.srcElement;
	  if(relTarg.tagName=="INPUT")
	  {
	 	isInput=true;
	  }else
	  {
	  	isInput=false;	
	  }
	  $(transMenuName).hide();
  }
}

function clickTranslate(e)
{
     dictShow(translateContent);
     $(transMenuName).hide();
}
function dictGetSel()
{
	if (window.getSelection){
		return window.getSelection();
	}else if (document.getSelection){
		return document.getSelection();
	}else if (document.selection){
		return document.selection.createRange().text;
	}else{
		return '';
	}
}
function dictShowForSearchbox(word)
{
	if($.trim(word)!="")
		dictShow(word);
}

function dictShow(word)
{
	var queryparams="";
	var queryparamscount=0;
	if(word!=null&&word!="")
	{
		queryparams+="word="+word;
		queryparamscount++;
	}
	if(notebookactive!=null&&notebookactive!=undefined)
	{
		if(queryparamscount>0)
		{
			queryparams+="&notebookactive="+notebookactive;
		}else
		{
			queryparams+="notebookactive="+notebookactive;
		}
	}
	window.open("/master/school/translator2/translator.asp?"+queryparams,'Translator','height=500px,width=690px,top=0,left=0,toolbar=no,resizable=no,location=no,status=no');	
}

function getCookie(cookieName,defaultValue)
{
   if($.cookie(cookieName)==null)
   {
   	return defaultValue;
   }
   else
   {
   	return $.cookie(cookieName);
   }
}
function setCookie(cookieName,value)
{
  if(value!=null)
  {
  	$.cookie(cookieName,value,{expires: 7, path:'/'});
  }
}
function setAutoLaunchCookie(value)
{
 //sync variable value at client side
  window.opener.autoLaunch=value;
  //save value to cookie
  setCookie(LaunchCookieName,value.toString());	
}
function createMask()
{
	if (document.getElementById('Message') == null && document.getElementById('Screen') == null){	
 		document.write('<div id="Message" style="position:absolute;z-index:9999;top:135px;left:195px;display: none;">\r\n');
 		document.write('</div>')
		document.write('<div id="Screen" style="position:absolute;z-index:9998;top:0px;left:0px;background:#000000;display: none;filter: alpha(Opacity=50);"></div>\r\n');
	}
}
createMask();
var showxmlwithnote=true;

function showTranslatorTour()
{
	//alert(document.getElementById('Message'));
	if (document.getElementById('Message')!= null && document.getElementById('Screen')!= null){	
		var Element = document.getElementById('Message');
		var Elements = document.getElementById('Screen');    	
			
		Elements.style.top = 0;    	
		Elements.style.width = getWidth();
			
		Elements.style.height = getHeight();
		Element.style.display = 'block';
		Elements.style.display = 'block';
		
		if (showxmlwithnote == true){
			xmlPath = String('/EtownResources/tour/translator2/tour.xml');
		}else{
			xmlPath = String('/EtownResources/tour/translator2/noaddtour.xml');
		}
		
		var folderName =  tmpFolder;
		var lngCode = pagelang;
		    	
		var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="530" height="355" id=ShockwaveFlash1>\r\n';
		str += '<param name="movie" value="' + cacheSvr + '/EtownResources/newschool/flash/activity/productTour.swf?path='+xmlPath+'&folder='+folderName+'&lngCode='+lngCode+'" />\r\n';
		str += '<param name="quality" value="high" />\r\n';
		str += '<param name="bgcolor" value="#808080" />\r\n';		
		str += '<PARAM NAME="AllowScriptAccess" VALUE="always">'
		str += '<embed src="' + cacheSvr + '/EtownResources/newschool/flash/activity/productTour.swf?path='+xmlPath+'&folder='+folderName+'&lngCode='+lngCode+'" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="530" height="355"  bgcolor="#808080"></embed>\r\n';
		str += '</object>\r\n';
			
		Element.innerHTML = str;
	}    	
}
function getWidth()
{
    	var strWidth,clientWidth,bodyWidth;
    	clientWidth = document.documentElement.clientWidth;
    	bodyWidth = document.body.scrollWidth;
    	if(bodyWidth > clientWidth)
    	{
        	strWidth = bodyWidth;
    	} 
    	else 
    	{
        	strWidth = clientWidth;
    	}
    	return strWidth;
}
function getHeight()
{
    	var strHeight,clientHeight,bodyHeight;
    	clientHeight = document.documentElement.clientHeight;
    	bodyHeight = document.body.scrollHeight;
    	if(bodyHeight > clientHeight)
    	{
        	strHeight = bodyHeight
    	} 
    	else 
    	{
        	strHeight = clientHeight;
    	}
    	return strHeight;
}

function closeTour(tmpVal)
{
	if (document.getElementById('Message')!= null && document.getElementById('Screen')!= null){	
		tmpVal = String(tmpVal).toLowerCase();
		var Element = document.getElementById('Message');
		var Elements = document.getElementById('Screen');
		Element.style.display = 'none';
		Elements.style.display = 'none';    
	}
}
