/* Copyright 2004-2009 CodeCogs */

/*---- /equationeditor/js/eq_editor-1.js ----*/
var changed=false;var orgtxt='';
var EQUATION_ENGINE='elimhttp://latex.codecogs.com';
var FAVORITE_ENGINE='http://latex.codecogs.com/json';
var panellock=null;
var panelcount=0;
var paneltimer=null;
var cctype='doxygen';
var cctarget='';
var ccSID=0;
var key_text='';

function insertAttachment(aid) {
	insert1Txt("[attachment="+aid+"]",0);
}
function loadContentFromElementWithID(elID) {
	var text = $el(elID).value; 
	var el = $el('foo');
 	el.innerHTML=text;
	MathJax.Extension.tex2jax.PreProcess(el);
	MathJax.Hub.Process(el);
} 

function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
function $el(name){return document.getElementById(name);}
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=$el(id).style;
	object.opacity=(opacity/100);
	object.MozOpacity=(opacity/100);
	object.KhtmlOpacity=(opacity/100);
	object.filter="alpha(opacity="+opacity+")";
}
function fadeout(id){
	opacity(id,100,20,800);
	setTimeout("$el('"+id+"').style.display='none'",800);
}
function fadein(id){
	changeOpac(20,id);
	$el(id).style.display='block';opacity(id,20,100,800);
}
function opanel(id){
	if(panellock==null)panellock=id;
	else{
		if(id==panellock&&paneltimer!=null){
			clearTimeout(paneltimer);
			paneltimer=null;
		}
	}
	id.style.overflow='visible';
}
function cpaneldo(){
	if(panellock!=null){
		panellock.style.overflow='hidden';
		hidehover();
	}
	panellock=null;
}
function cpanel(id){
	if(id==panellock||id===null){
		if(paneltimer!=null)clearTimeout(paneltimer);
		paneltimer=setTimeout('cpaneldo()',(id===null?200:600));
	}else id.style.overflow='hidden';
}
function cleartext(){
	var id=$el('message');
	id.value="";id.focus();
	changed=false;
	if($el('copybutton')) $el('copybutton').className='greybutton';
	if($el('renderbutton')) $el('renderbutton').className='greybutton';
	$el('equationview').src='spacer.gif';fadein('intro');
}
function textchanged(){
	var txt=getEquationStr();
	if(txt!=orgtxt){
		orgtxt=txt;
		if($el('copybutton'))$el('copybutton').className='lightbluebutton';
		if($el('renderbutton'))$el('renderbutton').className='bluebutton';
		changed=true;
	}
	if(txt.length==0)fadein('intro');
	else fadeout('intro');
}
function formatchanged(){
	var action=false;
	var format=$el('format');
	if(format){
		var type=format.value;
		switch(type){
			case'gif':action=false;break;
			case'png':action=false;break;
			case'pdf':action=true;break;
			case'swf':action=true;break;
			case'emf':action=true;break;
		}
	}
	$el('dpi').disabled=action;
	$el('dpi').readonly=action;
	$el('bg').disabled=action;
	$el('bg').readonly=action;
	changed=true;renderEqn();
}
function addText(wind,textbox,txt){
	myField=wind.getElementById(textbox);
	if(wind.selection){
		myField.focus();
		sel=wind.selection.createRange();
		sel.text=txt;
	}else{var scrolly=myField.scrollTop;
		if(myField.selectionStart||myField.selectionStart=='0'){
			var startPos=myField.selectionStart;
			var endPos=myField.selectionEnd;
			var cursorPos=startPos+txt.length;
			myField.value=myField.value.substring(0,startPos)+txt+myField.value.substring(endPos,myField.value.length);
			pos=txt.length+endPos-startPos;
			myField.selectionStart=cursorPos;
			myField.selectionEnd=cursorPos;
			myField.focus();
			myField.setSelectionRange(startPos+pos,startPos+pos);
		}else myField.value+=txt;
		myField.scrollTop=scrolly;
	}
}
function insert1Txt(txt,pos,inspos){
	key_text='';
	if(pos==1000){
		pos=txt.length-1;
	}
	if(pos==null){
		pos=txt.indexOf('{')+1;
		if(pos<=0){
			txt+=' ';
			pos=txt.length;
		}else{
			if(txt.charAt(pos)!='}')pos=txt.indexOf('}',pos)+1;
		}
	}
	var insert_pos=(inspos==null)?pos:inspos;
	var i;
	var startPos;
	myField=$el('message');
	if(document.selection){
		myField.focus();
		var sel=document.selection.createRange();
		i=myField.value.length+1;
		theCaret=sel.duplicate();
		while(theCaret.parentElement()==myField&&theCaret.move("character",1)==1)--i;
		startPos=i-myField.value.split("\n").length+1;
		if((txt.substring(1,5)=="left"||insert_pos>=0)&&sel.text.length){
			if(txt.substring(1,5)=="left")ins_point=7;
			else ins_point=insert_pos;
			if(insert_pos==null)pos=txt.length+sel.text.length+1;
			else if(insert_pos<pos)pos+=sel.text.length;
			sel.text=txt.substring(0,ins_point)+sel.text+txt.substr(ins_point);
		}else sel.text=txt;
		var range=myField.createTextRange();
		range.collapse(true);
		range.moveEnd('character',startPos+pos);
		range.moveStart('character',startPos+pos);
		range.select();
	}else{
		if(myField.selectionStart||myField.selectionStart=='0'){
			startPos=myField.selectionStart;
			var endPos=myField.selectionEnd;
			var cursorPos=startPos+txt.length;
			if((txt.substring(1,5)=="left"||insert_pos>=0)&&endPos>startPos){
				if(txt.substring(1,5)=="left")ins_point=7;
				else ins_point=insert_pos;
				if(insert_pos==null)pos=txt.length+endPos-startPos+1;
				else if(insert_pos<pos)pos+=endPos-startPos;
				txt=txt.substring(0,ins_point)+myField.value.substring(startPos,endPos)+txt.substr(ins_point);
			}
			myField.value=myField.value.substring(0,startPos)+txt+myField.value.substring(endPos,myField.value.length);
			myField.selectionStart=cursorPos;
			myField.selectionEnd=cursorPos;
			myField.focus();
			myField.setSelectionRange(startPos+pos,startPos+pos);
		}else myField.value+=txt;
	}
	textchanged();
	autorenderEqn(10);
	cpanel(null);
	myField.focus();
}
function insertText(txt,pos,inspos){
	insert1Txt(txt,pos,inspos);
}
function getEquationStr(){
	var val=$el('message').value;
	val=val.replace(/^\s+|\s+$/g,"");
	val=val.replace(/\s+/g," ");
	var size=$el('fontsize');
	if(size){
		var txt=size.options[size.selectedIndex].value;
		if(txt!=='')val=txt+' '+val;
	}if($el('compressed').checked)val='\\inline '+val;
	if($el('dpi')){
		var dpi=$el('dpi').value;
		if(dpi!='110')val='\\'+dpi+'dpi '+val;
	}
	if($el('bg')){
		var bg=$el('bg').value;
		if(bg!='transparent')val='\\bg_'+bg+' '+val;
	}
	if($el('font')){
		var font=$el('font').value;
		if(font!='')val='\\fn_'+font+' '+val;
	}
	return val;
}
function exportEquation(type){
	var format_index;
	var format;
	if($el('format')){
		format_index=$el('format').selectedIndex;
		format=$el('format').options[format_index].value;
	}else{
		format_index=0;
		format='gif';
	}if(type=='phpBB'){
		$el('eqcode').innerHTML='PHP Bulletin Board markup for this equation is:';
		text=getEquationStr();
		return('[tex]'+text+'[/tex]\n');
	}else if(type=='tw'){
		$el('eqcode').innerHTML='TiddlyWiki markup for this equation is:';
		text=getEquationStr();
		text=text.replace(/\[/g,'%5B');
		text=text.replace(/\]/g,'%5D');
		return('[img['+EQUATION_ENGINE+'/'+format+'.latex?'+text+']]');
	}else if(type=='html'){
		$el('eqcode').innerHTML='HTML code to embed this equation into a web page is:';
		text=getEquationStr();
		return('<img src="'+EQUATION_ENGINE+'/'+format+'.latex?'+text+'" title="'+text+'" />');
	}else if(type=='htmledit'){
		$el('eqcode').innerHTML='HTML code to embed this equation into a web page is:';
		text=getEquationStr();
		return('<a href="http://www.codecogs.com/eqnedit.php?latex='+text.replace(/\+/g,'@plus;')+'" target="_blank"><img src="'+EQUATION_ENGINE+'/'+format+'.latex?'+text+'" title="'+text+'" /></a>');
	}else if(type=='url'){
		$el('eqcode').innerHTML='The URL link to this equation is:';
		text=getEquationStr();
		text=text.replace(/\s/g,'&space;');
		text=text.replace(/\+/g,'&plus;');
		return(EQUATION_ENGINE+'/'+format+'.latex?'+text);
	}else if(type=='pre'){
		text=$el('message').value;
		size=$el('fontsize');
		if(size&&size.selectedIndex!=2)text=size.options[size.selectedIndex].value+' '+text;
		$el('eqcode').innerHTML='HTML code using pre-tags is:';
		if($el('inline').checked){
			if(!$el('compressed').checked)text='\\displaystyle '+text;
			return('<code xml:lang="latex">'+text+'</code> ');
		}else{
			if($el('compressed').checked)text='\\inline '+text;
			return('<pre xml:lang="latex">'+text+'</pre>\n');
		}
	}else if(type=='doxygen'){
		$el('eqcode').innerHTML='DOxygen markup for this equation is:';
		text=$el('message').value;
		size=$el('fontsize');
		if(size&&size.selectedIndex!=2)text=size.options[size.selectedIndex].value+' '+text;
		if($el('inline').checked){
			if(!$el('compressed').checked)text='\\displaystyle '+text;text='\\f$'+text+'\\f$ ';
		}else{
			if($el('compressed').checked)text='\\inline '+text;text='\\f['+text+'\\f]\n';
		}
	}else{
		$el('eqcode').innerHTML='LaTeX markup for this equation is:';
		text=$el('message').value;
		size=$el('fontsize');
		if(size&&size.selectedIndex!=2)text=size.options[size.selectedIndex].value+' '+text;
		if($el('inline').checked){
			if(!$el('compressed').checked)text='\\displaystyle '+text;
			return('$'+text+'$ ');
		}else{
			if($el('compressed').checked)text='\\inline '+text;
			return('\\['+text+'\\]\n');
		}
	}
	return text;
}
var initmessage=true;
function processEquationChange(){
	if(initmessage)initmessage=false;
	else{$el('equationcomment').innerHTML='';}
}
function renderEqn(callback){
	var val=$el('message').value;
	val=val.replace(/^\s+|\s+$/g,"");
	if(val.length==0)return true;
	var bracket=0;
	var i;
	for(i=0;i<val.length;i++){
		switch(val.charAt(i)){
			case'{':if(i==0||val[i-1]!='\\')bracket++;break;
			case'}':if(i==0||val[i-1]!='\\')bracket--;break;
		}
	}
	var div;
	if(bracket==0){
		if($el('renderbutton'))$el('renderbutton').className='greybutton';
		val=$el('message').value;
		var img=$el('equationview');
		val=getEquationStr();
		sval=val.replace(/"/g,'\\"').replace(/\s/g,"&space;");
		var format_index;
		var format;
		if($el('format')){
			format_index=$el('format').selectedIndex;
			format=$el('format').options[format_index].value;
		} else{
			format_index=0;
			format='gif';
		} 
		switch(format_index){
			case 0:
			case 1:
			case 5:if(changed){$el('equationcomment').innerHTML="Rendering Equation <img src=\"images/wait.gif\" width=\"13\" height=\"13\"/>";img.src=EQUATION_ENGINE+'/'+format+'.latex?'+val;img.onclick=function(){document.location.href=EQUATION_ENGINE+'/'+format+'.download?'+sval;}	}$el('download').innerHTML='<a href="'+EQUATION_ENGINE+'/'+format+'.download?'+sval+'">Click Image to Download ('+format.toUpperCase()+')</a>';$el('eqcoderaw').value=exportEquation((cctype=='doxygen'?'html':cctype));;break;
			case 2:if(changed){$el('equationcomment').innerHTML="Rendering Equation <img src=\"images/wait.gif\" width=\"13\" height=\"13\"/>";img.src=EQUATION_ENGINE+'/gif.latex?'+val;}$el('download').innerHTML='<a target="_blank" href="'+EQUATION_ENGINE+'/pdf.download?'+sval+'"><img src="images/pdf.jpg" width="30" height="30" align="middle" /> Click here to Download Equation (PDF)</a>';$el('eqcode').innerHTML='HTML to create a download link for a webpage is:';$el('eqcoderaw').value=exportEquation((cctype=='doxygen'?'html':cctype));;break;
			case 3:img.src='spacer.gif';initmessage=true;$el('eqcode').innerHTML='HTML to embed this equation into a webpage is:';AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','600','height','100','src',(EQUATION_ENGINE+'/swf.latex?'+val),'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','align','top','scale','showall','wmode','window','devicefont','false','bgcolor','#ffffff','menu','true','allowFullScreen','true','movie',(EQUATION_ENGINE+'/swf.latex?'+val));$el('download').innerHTML='<a target="_blank" href="'+EQUATION_ENGINE+'/swf.download?'+sval+'">Click here to Download Equation (SWF)</a>';break;
			case 4:if(changed){$el('equationcomment').innerHTML="Rendering Equation <img src=\"images/wait.gif\" width=\"13\" height=\"13\"/>";img.src=EQUATION_ENGINE+'/gif.latex?'+val;}$el('download').innerHTML='<a target="_blank" href="'+EQUATION_ENGINE+'/emf.download?'+sval+'"><img src="images/emf.jpg" width="30" height="30" align="middle" /> Click here to Download Equation (Windows EMF)</a>';$el('eqcode').innerHTML='HTML to create a download link for a webpage is:';$el('eqcoderaw').value=exportEquation((cctype=='doxygen'?'html':cctype));;break;
		}
	}else{
		div=$el('equationcomment');
		if(bracket<0)div.innerHTML="<br/><span class=\"orange\">You have more <strong>closed '}' brackets</strong> than open '{' brackets</span>";
		else div.innerHTML="<br/><span class=\"orange\">You have more <strong>open '{' brackets</strong> than closed '}' brackets</span>";
	}
	changed=false;
}
var auton=0;
function renderCountdown(){
	if(auton>0){
		auton--;
		setTimeout('renderCountdown()',100);
	}
	else renderEqn(null);
}
function autorenderEqn(n){
	if($el('format'))format_index=$el('format').selectedIndex;
	else format_index=0;
	{
		if(auton>0&&n>0)auton=n;
		else{
			auton=n;
			renderCountdown();
		}
	}
}
function addfavorite(){
	text=$el('message').value;
	text=escape(text.replace(/\+/g,"@plus;"));
	if(text!=''){
		var head=document.getElementsByTagName("head")[0];
		var script=document.createElement("script");
		var d=new Date();
		script.src=FAVORITE_ENGINE+'/favorite_json.php?sid='+ccSID+'&add&rand='+d.getTime()+'&eqn='+text;
		head.appendChild(script);
		setTimeout('show_example(null, \'fav\')',200);
	}
}
function deletefavorite(name){
	var head=document.getElementsByTagName("head")[0];
	var script=document.createElement("script");
	var d=new Date();
	script.src=FAVORITE_ENGINE+'/favorite_json.php?sid='+ccSID+'&rand='+d.getTime()+'&delete='+name;
	head.appendChild(script);
	setTimeout('show_example(null, \'fav\')',200);
}
function add_eq_history(){
	text=$el('message').value;
	text=escape(text.replace(/\+/g,"@plus;"));
	var head=document.getElementsByTagName("head")[0];
	var script=document.createElement("script");
	var d=new Date();
	script.src=FAVORITE_ENGINE+'/history_json.php?sid='+ccSID+'&add'+'&rand='+d.getTime()+'&eqn='+text;
	head.appendChild(script);
}
function makeEquationsMatrix(type,isNumbered,isConditional){
	if(isNumbered===undefined)isNumbered=false;
	if(isConditional===undefined)isNumbered=false;var eqns="\\begin{"+type+((isNumbered)?"":"*")+"}";
	var eqi="\n &"+((isNumbered)?" ":"= ")+((isConditional)?"\\text{ if } x= ":"");
	var eqEnd="\n\\end{"+type+((isNumbered)?"":"*")+"}";
	var i=0;
	var dim=prompt('Enter the number of lines:','');
	if(dim!=''&&dim!==null){
		n=parseInt(dim);
		if(!isNaN(n)){
			for(i=1;i<=n-1;i++)eqns=eqns+(eqi+"\\\\ ");
			eqns=(eqns+eqi)+eqEnd;
			insert1Txt(eqns,type.length+((isNumbered)?0:1)+9);
		}
	}
}
function makeArrayMatrix(type,start,end){
	var matr=start+'\\begin{'+type+'matrix}';
	var row="\n";
	var mend="\n\\end{"+type+"matrix}"+end;var i=0;
	var dim=prompt('Enter the array dimensions separated by a comma (e.g. "2,3" for 2 rows and 3 columns):','');
	if(dim!==''&&dim!==null){
		dim=dim.split(',');
		m=parseInt(dim[0]);
		n=parseInt(dim[1]);
		if(!isNaN(m)&&!isNaN(n)){
			for(i=2;i<=n;i++)row=row+' & ';
			for(i=1;i<=m-1;i++)matr=matr+row+'\\\\ ';
			matr=matr+row+mend;
			insert1Txt(matr,type.length+start.length+15);
		}
	}
}
var hoverlock=false;
function hidehover(){
	if(!hoverlock)$el('hover').style.display='none';
}
function hover(elm,e){
	hoverlock=true;
	div=$el('hover');
	div.innerHTML='<img src="'+EQUATION_ENGINE+'/gif.latex?\\200dpi '+elm.latex+'"/>';
	if(document.all){
		div.style.top=(event.clientY-10)+'px';
		div.style.left=(event.clientX+20)+'px';
	}else{
		if(!e)e=window.event;
		div.style.top=(e.pageY-10)+'px';
		div.style.left=(e.pageX+20)+'px';
	}
	div.style.display='block';hoverlock=false;elm.onmouseout=hidehover;
}
var myUndo=0;
var myRedo=0;
store_text=new Array();
store_text.push("");
function countclik(tag){
	var x=tag.value;
	if(myUndo==0||store_text[myUndo]!=x){
		if(myUndo>20)store_text.shift();
		else myUndo++;
		store_text[myUndo]=x;
	}
	myRedo=0;
	$el('redobutton').src='LaTeX_files/redo-x.gif';
	$el('undobutton').src="LaTeX_files/undo.gif";
}
function undo(box){
	tag=$el(box);
	if(myRedo==0){
		if(myUndo>20)store_text.shift();
		else myUndo++;
		store_text[myUndo]=tag.value;
	}
	if(myRedo<myUndo){
		myRedo++;
		if(myRedo==myUndo)$el('undobutton').src="LaTeX_files/undo-x.gif";
		$el('redobutton').src="LaTeX_files/redo.gif";
	}
	else return;
	var z=store_text.length-myRedo-1;
	if(store_text[z])tag.value=store_text[z];
	else tag.value=store_text[0];
	tag.focus();
}
function redo(box){
	tag=$el(box);
	if(myRedo>0){
		myRedo--;
		if(myRedo==0)$el('redobutton').src='LaTeX_files/redo-x.gif';
		$el('undobutton').src="LaTeX_files/undo.gif";
	}else return;
	var z=store_text.length-myRedo-1;
	if(store_text[z])tag.value=store_text[z];
	else tag.value=store_text[0];
	tag.focus();
}
function updateOpener(target,type){
	var text;
	var size;
	if(target!==''){
		text=exportEquation(type);
		addText(window.opener.document,target,text);
	}
	else updateWYSIWYG(type);
	add_eq_history();
	hide_example();
	window.blur();
	return true;
}
var gallery;
var lastbutton=null;
function show_example(button,group){
	$el('bar1').style.display='none';
	$el('bar2').style.display='block';
	var div=$el('photos');
	div.innerHTML='';
	if(button!==null){
		if(lastbutton!==null)lastbutton.className='lightbluebutton';
		button.className='greybutton';
		lastbutton=button;
	}gallery=new Scroll();
	if(group=='fav'||group=='history'){
		var d=new Date();
		gallery.init('photos','leftarrow','rightarrow','overview',FAVORITE_ENGINE+'/example_json.php?fn=gallery&rand='+d.getTime()+'&sid='+ccSID);
	}
	else gallery.init('photos','leftarrow','rightarrow','overview',FAVORITE_ENGINE+'/example_json.php?fn=gallery');
	gallery.visible_num=1;gallery.new_offset=5;
	gallery.maxpanels=1;
	gallery.set_width(600,100,60);
	gallery.set_subtext('&type='+group);
	gallery.add_panel();
	gallery.setarrow();
	gallery.setoverview();
}
function hide_example(){
	$el('bar2').style.display='none';
	$el('bar1').style.display='block';
	if(lastbutton!==null)lastbutton.className='lightbluebutton';
	lastbutton=null;
}
function tabHandler(e){
	var TABKEY=9;
	if(e.keyCode==TABKEY){
		if(document.selection){
			var sel=document.selection.createRange();
			var inp=$el('message');
			i=inp.value.length+1;
			theCaret=sel.duplicate();
			while(theCaret.parentElement()==myField&&theCaret.move("character",1)==1)--i;
			startPos=i-inp.value.split("\n").length+1;
			if(startPos==inp.value.length)return true;
			pos=inp.value.indexOf('{',startPos);
			if(pos==-1)pos=inp.value.length;
			else pos++;
			var range=inp.createTextRange();
			range.collapse(true);
			range.moveEnd('character',pos);
			range.moveStart('character',pos);
			range.select();
		}else{
			startPos=this.selectionStart;
			if(startPos==this.value.length)return true;
			pos=this.value.indexOf('{',startPos);
			if(pos==-1)pos=this.value.length;
			else pos++;
			this.setSelectionRange(pos,pos);
		}if(e.preventDefault)e.preventDefault();
		return false;
	}
}
function backCursor(myField){
	if(document.selection){
		myField.focus();
		sel=document.selection.createRange();
		if(sel.text.length>0)sel.text='';
		else{
			sel.moveEnd('character',1);
			sel.text='';
		}
		sel.select();
	}else if(myField.selectionStart||myField.selectionStart=='0'){
		var startPos=myField.selectionStart;
		var endPos=myField.selectionEnd;
		myField.value=myField.value.substring(0,startPos)+myField.value.substring(endPos+1,myField.value.length);
		myField.selectionStart=startPos;
		myField.selectionEnd=startPos;
		myField.focus();
	}
}
var extendchar=null;
function extendkey(letter){
	if(key_text=='\\left')insert1Txt(' \\right '+letter,0);
	else if(key_text=='\\begin'&&letter=='}')insert1Txt('} \\end{}',0);
	else insert1Txt(letter,0);
	extendchar=letter;
}
function keyHandler(e){
	var keyCode;
	if(window.event)keycode=window.event.keyCode;
	else if(e)keycode=e.which;
	var keystr=String.fromCharCode(keycode);
	if(keystr==extendchar){
		backCursor($el('message'));
	}
	extendchar=null;
	switch(keystr){
		case'{':extendkey('}');break;
		case'[':extendkey(']');break;
		case'(':extendkey(')');break;
		case'"':extendkey('"');break;
	}
	if(keystr==' '){}
	else if(keystr=='\\')key_text='\\';
	else if(!keystr.match(/^[a-zA-Z]$/))key_text='';
	else key_text+=keystr;
}
function jsGet(type){
	if(location.href.match(type+'=')){
		return location.href.split(type+'=')[1].split('&')[0];
	}
}
function isGet(type){
	if(location.href.indexOf('?')>0){
		var val=location.href.split('?')[1];
		var a=val.indexOf(type);
		return(a>=0&&(a==0||val[a-1]=='&'));
	}
	return false;
}
function resize_layers(){
	var x,y;
	return; //elim disabled the nice feature
	if(self.innerHeight)y=self.innerHeight;
	else if(document.documentElement&&document.documentElement.clientHeight)y=document.documentElement.clientHeight;
	else if(document.body)y=document.body.clientHeight;
	var myInput=$el('message');
	myInput.style.height=parseInt((y-200)/3)+'px';
}
function editor_init(SID,target,type,initlatex){
	var areas=document.getElementsByTagName('area');
	for(i=0;i<areas.length;i++){
		areas[i].onmouseover=function(e){hover(this,e);};
		areas[i].latex=areas[i].alt;areas[i].alt='';
	}
	ccSID=SID;
	var myInput=$el('message');
	if(myInput.addEventListener){
		myInput.addEventListener('keydown',this.tabHandler,false);
		myInput.addEventListener('keypress',this.keyHandler,false);
		window.addEventListener('resize',resize_layers,false);
	}else if(myInput.attachEvent){
		myInput.attachEvent('onkeydown',this.tabHandler);
		myInput.attachEvent('onkeypress',this.keyHandler);
		window.attachEvent('onresize',resize_layers);
	}
	if(target===undefined||target===null){
		if(isGet('target'))cctarget=jsGet('target');
		else cctarget='';
	}else cctarget=target;
	if(type===undefined){
		if(isGet('type'))cctype=jsGet('type');
		else cctype='latex';
		$el('type').selectedIndex=0;
	}else cctype=type;
	var latex;
	if(initlatex===undefined&&isGet('latex'))initlatex=jsGet('latex');
	if(initlatex===undefined||initlatex=='')LoadWYSIWYG();
	else{
		latex=unescape(initlatex);
		latex=latex.replace(/@plus;/,'+');
		latex=latex.replace(/&plus;/,'+');
		if(latex.length>0){
			$el('message').value=latex;
			textchanged();
			renderEqn(null);
			fadeout('intro');
		}
	}
//	resize_layers();
	$el('message').focus();
}
/*---- /equationeditor/js/eq_fck.js ----*/
var oEditor=window.opener;
var FCKEquation=null;
var eSelected=null;
function LoadWYSIWYG(){if(oEditor&&typeof(oEditor.FCKEquation)!='undefined'){FCKEquation=oEditor.FCKEquation;if(FCKEquation)eSelected=oEditor.FCKSelection.GetSelectedElement();else alert('Can not find FCK');if(eSelected&&eSelected.tagName=='IMG'&&eSelected._fckequation){var comm=unescape(eSelected._fckequation);var parts=comm.match(/(\\\[|\$)(.*?)(\\\]|\$)/);$el('message').value=parts[2];$el('inline').checked=(parts[1]=='$');textchanged();renderEqn(null);fadeout('intro');}else{$el('message').value='';eSelected=null;}}}function updateWYSIWYG(type){var text=exportEquation(type);if(text.length==0){alert(FCKLang.EquationErrNoEqn);return false;}if(eSelected&&eSelected._fckequation==text)return true;FCKEquation.Add(text);}

/*---- /equationeditor/js/clipboard.js ----*/
var ZeroClipboard={version:"1.0.4",clients:{},moviePath:'js/ZeroClipboard.swf',nextId:1,$:function(thingy){if(typeof(thingy)=='string')thingy=document.getElementById(thingy);if(!thingy.addClass){thingy.hide=function(){this.style.display='none';};thingy.show=function(){this.style.display='';};thingy.addClass=function(name){this.removeClass(name);this.className+=' '+name;};thingy.removeClass=function(name){this.className=this.className.replace(new RegExp("\\s*"+name+"\\s*")," ").replace(/^\s+/,'').replace(/\s+$/,'');};thingy.hasClass=function(name){return!!this.className.match(new RegExp("\\s*"+name+"\\s*"));};}return thingy;},setMoviePath:function(path){this.moviePath=path;},dispatch:function(id,eventName,args){var client=this.clients[id];if(client){client.receiveEvent(eventName,args);}},register:function(id,client){this.clients[id]=client;},getDOMObjectPosition:function(obj){var info={left:0,top:0,width:obj.width?obj.width:obj.offsetWidth,height:obj.height?obj.height:obj.offsetHeight};while(obj){info.left+=obj.offsetLeft;info.top+=obj.offsetTop;obj=obj.offsetParent;}return info;},Client:function(elem){this.handlers={};this.id=ZeroClipboard.nextId++;this.movieId='ZeroClipboardMovie_'+this.id;ZeroClipboard.register(this.id,this);if(elem)this.glue(elem);}};ZeroClipboard.Client.prototype={id:0,ready:false,movie:null,clipText:'',handCursorEnabled:true,cssEffects:true,handlers:null,glue:function(elem){this.domElement=ZeroClipboard.$(elem);var zIndex=99;if(this.domElement.style.zIndex){zIndex=parseInt(this.domElement.style.zIndex)+1;}var box=ZeroClipboard.getDOMObjectPosition(this.domElement);this.div=document.createElement('div');var style=this.div.style;style.position='absolute';style.left=''+0+'px';style.top=''+0+'px';style.width=''+box.width+'px';style.height=''+box.height+'px';style.zIndex=zIndex;this.domElement.appendChild(this.div);this.div.innerHTML=this.getHTML(box.width,box.height);},getHTML:function(width,height){var html='';var flashvars='id='+this.id+'&width='+width+'&height='+height;if(navigator.userAgent.match(/MSIE/)){var protocol=location.href.match(/^https/i)?'https://':'http://';html+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';}else{html+='<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';}return html;},hide:function(){if(this.div){this.div.style.left='-2000px';}},show:function(){this.reposition();},destroy:function(){if(this.domElement&&this.div){this.hide();this.div.innerHTML='';var body=document.getElementsByTagName('body')[0];try{body.removeChild(this.div);}catch(e){}this.domElement=null;this.div=null;}},reposition:function(elem){if(elem){this.domElement=ZeroClipboard.$(elem);if(!this.domElement)this.hide();}if(this.domElement&&this.div){var box=ZeroClipboard.getDOMObjectPosition(this.domElement);var style=this.div.style;style.left=''+box.left+'px';style.top=''+box.top+'px';}},setText:function(newText){this.clipText=newText;if(this.ready)this.movie.setText(newText);},addEventListener:function(eventName,func){eventName=eventName.toString().toLowerCase().replace(/^on/,'');if(!this.handlers[eventName])this.handlers[eventName]=[];this.handlers[eventName].push(func);},setHandCursor:function(enabled){this.handCursorEnabled=enabled;if(this.ready)this.movie.setHandCursor(enabled);},setCSSEffects:function(enabled){this.cssEffects=!!enabled;},receiveEvent:function(eventName,args){eventName=eventName.toString().toLowerCase().replace(/^on/,'');switch(eventName){case'load':this.movie=document.getElementById(this.movieId);var self;if(!this.movie){self=this;setTimeout(function(){self.receiveEvent('load',null);},1);return;}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){self=this;setTimeout(function(){self.receiveEvent('load',null);},100);this.ready=true;return;}this.ready=true;this.movie.setText(this.clipText);this.movie.setHandCursor(this.handCursorEnabled);break;case'mouseover':if(this.domElement&&this.cssEffects){this.domElement.addClass('hover');if(this.recoverActive)this.domElement.addClass('active');}break;case'mouseout':if(this.domElement&&this.cssEffects){this.recoverActive=false;if(this.domElement.hasClass('active')){this.domElement.removeClass('active');this.recoverActive=true;}this.domElement.removeClass('hover');}break;case'mousedown':if(this.domElement&&this.cssEffects){this.domElement.addClass('active');}break;case'mouseup':if(this.domElement&&this.cssEffects){this.domElement.removeClass('active');this.recoverActive=false;}break;}if(this.handlers[eventName]){for(var idx=0,len=this.handlers[eventName].length;idx<len;idx++){var func=this.handlers[eventName][idx];if(typeof(func)=='function'){func(this,args);}else if((typeof(func)=='object')&&(func.length==2)){func[0][func[1]](this,args);}else if(typeof(func)=='string'){window[func](this,args);}}}}};var latexclip=null;var htmlclip=null;function clipboard_init(){latexclip=new ZeroClipboard.Client();latexclip.setHandCursor(true);latexclip.addEventListener('mouseOver',latex_mouse_over);latexclip.glue('latex_copy');htmlclip=new ZeroClipboard.Client();htmlclip.setHandCursor(true);htmlclip.addEventListener('mouseOver',html_mouse_over);htmlclip.glue('html_copy');}function latex_mouse_over(client){latexclip.setText(document.getElementById('message').value);}function html_mouse_over(client){htmlclip.setText(document.getElementById('eqcoderaw').value);}

/*---- /equationeditor/js/eq_flash.js ----*/
var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;var isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;var isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;function ControlVersion(){var version;var axo;var e;try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version=axo.GetVariable("$version");}catch(e){}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version="WIN 6,0,21,0";axo.AllowScriptAccess="always";version=axo.GetVariable("$version");}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version=axo.GetVariable("$version");}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version="WIN 3,0,18,0";}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");version="WIN 2,0,0,11";}catch(e){version=-1;}}return version;}function GetSwfVer(){var flashVer=-1;if(navigator.plugins!==null&&navigator.plugins.length>0){if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]){var swVer2=navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"";var flashDescription=navigator.plugins["Shockwave Flash"+swVer2].description;var descArray=flashDescription.split(" ");var tempArrayMajor=descArray[2].split(".");var versionMajor=tempArrayMajor[0];var versionMinor=tempArrayMajor[1];var versionRevision=descArray[3];if(versionRevision===""){versionRevision=descArray[4];}if(versionRevision[0]=="d"){versionRevision=versionRevision.substring(1);}else if(versionRevision[0]=="r"){versionRevision=versionRevision.substring(1);if(versionRevision.indexOf("d")>0){versionRevision=versionRevision.substring(0,versionRevision.indexOf("d"));}}flashVer=versionMajor+"."+versionMinor+"."+versionRevision;}}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6")!=-1)flashVer=4;else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5")!=-1)flashVer=3;else if(navigator.userAgent.toLowerCase().indexOf("webtv")!=-1)flashVer=2;else if(isIE&&isWin&&!isOpera){flashVer=ControlVersion();}return flashVer;}function DetectFlashVer(reqMajorVer,reqMinorVer,reqRevision){versionStr=GetSwfVer();if(versionStr==-1){return false;}else if(versionStr!=0){if(isIE&&isWin&&!isOpera){tempArray=versionStr.split(" ");tempString=tempArray[1];versionArray=tempString.split(",");}else{versionArray=versionStr.split(".");}var versionMajor=versionArray[0];var versionMinor=versionArray[1];var versionRevision=versionArray[2];if(versionMajor>parseFloat(reqMajorVer)){return true;}else if(versionMajor==parseFloat(reqMajorVer)){if(versionMinor>parseFloat(reqMinorVer))return true;else if(versionMinor==parseFloat(reqMinorVer)){if(versionRevision>=parseFloat(reqRevision))return true;}}return false;}}function AC_AddExtension(src,ext){return src;}function AC_Generateobj(objAttrs,params,embedAttrs){var str='';str+='<embed ';for(var i in embedAttrs){str+=i+'="'+embedAttrs[i]+'" ';}str+='></embed>';$el('equationcomment').innerHTML=str;div=$el('eqcoderaw');if(div)div.value=str;}function AC_FL_RunContent(){var ret=AC_GetArgs(arguments,".swf","movie","clsid:d27cdb6e-ae6d-11cf-96b8-444553540000","application/x-shockwave-flash");AC_Generateobj(ret.objAttrs,ret.params,ret.embedAttrs);}function AC_SW_RunContent(){var ret=AC_GetArgs(arguments,".dcr","src","clsid:166B1BCA-3F9C-11CF-8075-444553540000",null);AC_Generateobj(ret.objAttrs,ret.params,ret.embedAttrs);}function AC_GetArgs(args,ext,srcParamName,classid,mimeType){var ret=new Object();ret.embedAttrs=new Object();ret.params=new Object();ret.objAttrs=new Object();for(var i=0;i<args.length;i=i+2){var currArg=args[i].toLowerCase();switch(currArg){case"classid":break;case"pluginspage":ret.embedAttrs[args[i]]=args[i+1];break;case"src":case"movie":args[i+1]=AC_AddExtension(args[i+1],ext);ret.embedAttrs["src"]=args[i+1];ret.params[srcParamName]=args[i+1];break;case"onafterupdate":case"onbeforeupdate":case"onblur":case"oncellchange":case"onclick":case"ondblclick":case"ondrag":case"ondragend":case"ondragenter":case"ondragleave":case"ondragover":case"ondrop":case"onfinish":case"onfocus":case"onhelp":case"onmousedown":case"onmouseup":case"onmouseover":case"onmousemove":case"onmouseout":case"onkeypress":case"onkeydown":case"onkeyup":case"onload":case"onlosecapture":case"onpropertychange":case"onreadystatechange":case"onrowsdelete":case"onrowenter":case"onrowexit":case"onrowsinserted":case"onstart":case"onscroll":case"onbeforeeditfocus":case"onactivate":case"onbeforedeactivate":case"ondeactivate":case"type":case"codebase":case"id":ret.objAttrs[args[i]]=args[i+1];break;case"width":case"height":case"align":case"vspace":case"hspace":case"class":case"title":case"accesskey":case"name":case"tabindex":ret.embedAttrs[args[i]]=ret.objAttrs[args[i]]=args[i+1];break;default:ret.embedAttrs[args[i]]=ret.params[args[i]]=args[i+1];}}ret.objAttrs["classid"]=classid;if(mimeType)ret.embedAttrs["type"]=mimeType;return ret;}

/*---- /scroll/js/scroll-1.1.js ----*/
var oDiv=document.createElement('div');
var oImg=document.createElement('img');
var Scroll=function(){};
Scroll.prototype={init:function(maindiv,leftarrow,rightarrow,overview,newpanel_php){this.panels=0;this.maxpanels=0;this.speed=10;this.pause=2;this.visible=0;this.visible_num=2;this.layers=new Array();this.layers_offset=new Array();this.new_offset=0;this.subtext='';this.vertical=false;this.left_arrow=document.getElementById(leftarrow);this.right_arrow=document.getElementById(rightarrow);this.maindiv=document.getElementById(maindiv);if(overview!=='')this.overview=document.getElementById(overview);else this.overview=null;if(newpanel_php.indexOf('_json')>-1){this.ajax_php=null;this.json_php=newpanel_php;this.ajax_response_fn=null;}else{this.ajax_php=newpanel_php;this.json_php=null;var obj=this;this.ajax_response_fn=function(){obj.add_panel_response();};}},set_subtext:function(text){this.subtext=text;},set_width:function(width,height,speed){this.width=width;this.height=height;this.speed=speed;if(this.vertical)this.step=this.step_total=this.height/this.speed;else this.step=this.step_total=this.width/this.speed;},add:function(layer){var offset=this.new_offset;if(this.vertical)this.new_offset+=this.height;else this.new_offset+=this.width;this.layers[this.panels]=layer;this.layers_offset[this.panels]=offset;this.panels++;if(this.panels>this.maxpanels)this.maxpanels=this.panels;layer.style.position='absolute';if(this.vertical)layer.style.top=offset+'px';else layer.style.left=offset+'px';},add_id:function(layer_id){var lyr=document.getElementById(layer_id);if(lyr)this.add(lyr);},add_panel_div:function(newdiv){this.add(newdiv);this.maindiv.appendChild(newdiv);if(this.visible+this.visible_num>=this.panels)this.add_panel();},add_panel_response:function(){if(req.readyState==4){if(req.status==200&&req.responseText.length>0){var newdiv=oDiv.cloneNode(false);newdiv.innerHTML=req.responseText;this.add_panel_div(newdiv);}this.setarrow();this.setoverview();}},add_panel_json:function(info){if(info.length>0){var newdiv=oDiv.cloneNode(false);newdiv.innerHTML=info;this.add_panel_div(newdiv);}this.setarrow();this.setoverview();},add_panel:function(){if(this.ajax_php&&this.ajax_response_fn){if(this.ajax_php.indexOf("?")==-1)loadXMLDoc(this.ajax_php+'?panel='+this.panels+this.subtext,this.ajax_response_fn);else loadXMLDoc(this.ajax_php+'&panel='+this.panels+this.subtext,this.ajax_response_fn);}else if(this.json_php){var a=this.panels;var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");if(this.json_php.indexOf("?")==-1)script.src=this.json_php+'?panel='+a+this.subtext;else script.src=this.json_php+'&panel='+a+this.subtext;head.appendChild(script);}},redraw:function(){if(this.json_php||(this.ajax_php&&this.ajax_response_fn)){this.panels=0;this.visible=0;this.new_offset=0;while(this.maindiv.firstChild){this.maindiv.removeChild(this.maindiv.firstChild);}}if(this.ajax_php&&this.ajax_response_fn){var obj=this;if(this.ajax_php.indexOf("?")==-1)loadXMLDoc(obj.ajax_php+'?panel='+this.panels+this.subtext,obj.ajax_response_fn);else loadXMLDoc(obj.ajax_php+'&panel='+this.panels+this.subtext,obj.ajax_response_fn);}else if(this.json_php){var a=this.panels;var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");if(this.json_php.indexOf("?")==-1)script.src=this.json_php+'?panel='+a+this.subtext;else script.src=this.json_php+'&panel='+a+this.subtext;head.appendChild(script);}},move:function(dx){this.new_offset+=dx;for(var p=0;p<this.panels;p++){this.layers_offset[p]+=dx;if(this.vertical)this.layers[p].style.top=this.layers_offset[p]+'px';else this.layers[p].style.left=this.layers_offset[p]+'px';}this.step++;if(this.step<this.step_total){var obj=this;window.setTimeout(function(){obj.move(dx);},this.pause);}},setoverview:function(){if(this.overview!==null){this.overview.innerHTML='';var txt='';var obj=this;for(i=0;i<this.maxpanels;i++){newimg=oImg.cloneNode(false);newimg.className='overview';if(i>=this.visible&&i<(this.visible+this.visible_num))newimg.src="http://www.codecogs.com/images/scroll/soliddot.gif";else{newimg.src="http://www.codecogs.com/images/scroll/emptydot.gif";newimg.i=i;newimg.onclick=function(){obj.jump(this);};}this.overview.appendChild(newimg);}}},setarrow:function(){this.left_arrow.src='http://www.codecogs.com/images/scroll/'+(this.visible<=0?'leftarrow_grey.gif':'leftarrow.gif');this.right_arrow.src='http://www.codecogs.com/images/scroll/'+(this.visible>=(this.panels-1)?'rightarrow_grey.gif':'rightarrow.gif');},jump:function(obj){if(this.step==this.step_total){panel=obj.i;var gap=panel-this.visible;this.step=this.step_total-Math.abs(gap)*this.step_total;if(this.visible>panel)this.move(this.speed);else this.move(-this.speed);this.visible+=gap;if(this.visible+this.visible_num>=this.panels)this.add_panel();else{this.setarrow();this.setoverview();}}},left:function(){if(this.step==this.step_total){if(this.visible<(this.panels-1)){this.visible++;this.step=0;this.move(-this.speed);if(this.visible+this.visible_num>=this.panels)this.add_panel();else{this.setarrow();this.setoverview();}}}},right:function(){if(this.step==this.step_total){if(this.visible>0){this.step=0;this.move(this.speed);this.visible--;this.setarrow();this.setoverview();}}},subsearch:function(text){if(text!=='')this.subtext=('&subtext='+text);else this.subtext='';this.redraw();}};
