function toggleCode(layerID,imageID){var IMGDIR='/images/browser/';var lyr=document.getElementById(layerID);var img=document.getElementById(imageID);if(lyr==null||img==null)return;if(lyr.style.display=="block"){lyr.style.display="none";img.src=IMGDIR+"view_code.gif";}else{lyr.style.display="block";img.src=IMGDIR+"hide_code.gif";}}function acceptGPLTerms(){return(confirm('CONFIRM:\n\nYou have chosen to download or view at least one item as GPL freeware.\n\nClick the \'OK\' button to declare that you UNDERSTAND AND AGREE TO ABIDE BY THE TERMS OF OUR ADAPTED GPL LICENCE\n(see:\\\\www.codecogs.com\\pages\\licences\\gpl.html).\n\nWe will keep a record of your acceptance. You and/or your company will be held legally responsible for any infringement thereof.\n\nPlease click the \'Cancel\' button if you do NOT wish to be legally bound by these terms.'))}var Examples={edit:function(id,thisid){if(thisid==undefined)thisid=id;$.get('/pages/examples/ajax.php?id='+id+'&mode=edit',function(data){$('#example_'+thisid).replaceWith(data);});},view:function(id,thisid){if(thisid==undefined)thisid=id;$.get('/pages/examples/ajax.php?id='+id+'&mode=view',function(data){$('#example_'+thisid).replaceWith(data);$("a.group").fancybox();});},add:function(id){$.get('/pages/examples/ajax.php?id='+id+'&mode=add',function(data){$('#example_'+id).replaceWith(data);});},del:function(id){if(confirm("Delete Example (Unique ID="+id+")"))$.get('/pages/examples/ajax.php?id='+id+'&mode=delete',function(data){$('#example_'+id).replaceWith(data);});},save:function(id){var title=$('#title_'+id).val();var problem=$('#problem_'+id).val();var workings=$('#workings_'+id).val();var solution=$('#solution_'+id).val();var reference=$('#reference_'+id).val();var type=$('#type_'+id).val();var unit=$('#unit_'+id).val();var scope=$('#scope_'+id).val();$.post('/pages/examples/ajax.php?id='+id+'&mode=save',{'title':title,'problem':problem,'workings':workings,'solution':solution,'type':type,'unit':unit,'scope':scope,'reference':reference},function(data){$('#example_'+id).replaceWith(data);});return false;}};function $$(n){return document.getElementById(n);}function JSONload(url,fn){eval("var old = $$('JSONload')");if(old!=null){old.parentNode.removeChild(old);delete old;}var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.type="text/javascript";script.id="JSONload";script.src=url;head.appendChild(script);if(fn!=undefined){script.onreadystatechange=function(){if(this.readyState=='complete'||this.readyState=='loaded')fn();};script.onload=fn;}}var Cookie={set:function(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());},get:function(c_name){if(document.cookie.length>0){var c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;var c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}return'';}};var Hover={timer:Array(),current:Array(),target:Array(),layer:Array(),position:function(obj){var curleft=curtop=0;if(obj.offsetParent){do{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}while(obj=obj.offsetParent);}return[curleft,curtop];},set:function(obj,opacity){var o=obj.style;o.opacity=(opacity/100);o.MozOpacity=(opacity/100);o.KhtmlOpacity=(opacity/100);o.filter="alpha(opacity="+opacity+")";},fade:function(id){var t=this.target[id];if(this.current[id]>t)this.current[id]--;if(this.current[id]<t)this.current[id]++;var c=this.current[id];if(c!=t)setTimeout("Hover.fade('"+id+"')",15);var obj=$$('ic_hover_'+id);obj.style.display=(c==0?'none':'block');this.set(obj,c);},over:function(lyr,details,id,xoffset){var offset=this.position(lyr);var h=$$('ic_hover_'+id);h.innerHTML=details;h.style.top=(offset[1]+18)+'px';h.style.left=(offset[0]-xoffset)+'px';this.layer[id]=lyr;if(this.current[id]==undefined||this.current[id]=='')this.current[id]=0;if(this.timer[id]!=''){clearTimeout(this.timer[id]);this.timer[id]='';}this.timer[id]=setTimeout("Hover.target["+id+"]=100; Hover.fade("+id+");",1600);},out:function(id){if(this.current[id]==undefined||this.current[id]=='')this.current[id]=0;if(this.timer[id]!=''){clearTimeout(this.timer[id]);this.timer[id]='';}this.timer[id]=setTimeout("Hover.target["+id+"]=0; Hover.fade("+id+");",10);}};var InstantCalc={emailme:null,email:function(module_num,unit_num){if(this.emailme==null){this.emailme=unit_num;var email=$$('email_'+unit_num).value;JSONload('http://www.codecogs.com/products/calculator/email_json.php?m='+module_num+'&u='+unit_num+'&email='+email);}else $$('ic_link_'+unit_num).innerHTML='Sorry we\'re already in the process of sending another email for you. One at a time please!';},link_popup:function(module_num,unit_num){var height;if($$('ic_set_'+unit_num))height=$$('ic_set_'+unit_num).style.height+50;else height=350;mywindow=window.open('http://www.codecogs.com/products/calculator/link_popup.php?m='+module_num+'&u='+unit_num+'&height='+height,'Instant_Calculator','width=220,height=300,resizable=no');},link:function(module_num,unit_num){var a=$$('ic_link_'+unit_num);a.innerHTML='<hr/><strong>YOU CAN SHARE THIS CALCULATOR IN THREE WAYS:</strong><div class="greybox">Embed onto a website with:<textarea readonly="readonly" rows="3" onclick="this.select()" style="font-size:9px"><script type="text/javascript" src="http://www.codecogs.com/ic_json-'+module_num+'&amp;u='+unit_num+'"></script></textarea></div><div id="calcemail">Email to a friend:<input id="email_'+unit_num+'" type="text" class="text" value="Enter their email address here" style="width:190px" onclick="this.select()" /><input type="button" onclick="InstantCalc.email('+module_num+','+unit_num+')" class="emailbutton" value="Email Calculator"/></div><div class="greybox">Make a link to this calculator:<input type="text" class="text" readonly="readonly" value="http://www.codecogs.com/ic-'+module_num+'&amp;u='+unit_num+'" style="width:190px" onclick="this.select()"/></div><a href="http://www.codecogs.com" target="_blank"><img src="http://www.codecogs.com/images/poweredbycc.gif" height="34" width="102" border="0"/></a>';a.style.display='block';},inputs:function(types,modids,single){var range=false;var v='';for(var i=0;i<types.length;i++){var val=$$(modids+i).value;if(val){if(v!='')v+=',';switch(types.substr(i,1)){case'b':{if(val=='true')v+='1';else v+='0';}break;case's':{v+='"'+val+'"';}break;case'e':{if(val=='')val='0';v+=val;}break;default:if(val=='')v+='0';else{if(single){var j=val.indexOf(':');if(j!=-1){val=val.substr(0,j);range=true;}}v+=val.toString();}break;}}}v=escape(v.replace(/\+/g,"&plus;"));return{v:v,range:range};},Agreement:function(){if(Cookie.get('instant_calc')==1||confirm('The calculations made by CodeCogs calculators may not be correct and therefore should not be relied upon. You should not use these calculators if a financial loss, death or injury is possible.\n\nPlease accept the following terms if you wish to continue, otherwise click \'cancel\':\n\nYOU AGREE THAT USE OF THE CODECOGS SITE AND THE SERVICE IS ENTIRELY AT YOUR OWN RISK. THE CODECOGS SITE AND THE SERVICE ARE PROVIDED ON AN "AS IS" OR "AS AVAILABLE" BASIS, WITHOUT ANY WARRANTIES OF ANY KIND. ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY, RELIABILITY, ACCURACY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW.')){Cookie.set('instant_calc',1,7);return true;}return false;},calc:function(mode,file,types,divid){var modids='ic'+divid.toString()+'_';var inputs=InstantCalc.inputs(types,modids,true);if(InstantCalc.Agreement()){if(inputs.range){window.open('http://codecogs.izyba.com/products/calculator/graph.php?table=1&'+mode+'='+file+'&values='+inputs.v,'Instant_Table','width=610,height=400,resizable=yes,scrollbars=yes,scrolling=yes');}else{JSONload('http://codecogs.izyba.com/products/calculator/calc_json.php?'+mode+'='+file+'&values='+inputs.v,new Function('$$(\'ic'+divid+'_result\').innerHTML=json;'));Hover.out(divid);return false;}}},graph:function(mode,file,types,divid){var modids='ic'+divid.toString()+'_';var inputs=InstantCalc.inputs(types,modids,false);if(InstantCalc.Agreement())window.open('http://www.codecogs.com/products/calculator/graph.php?'+mode+'='+file+'&values='+inputs.v,'Instant_Graph','width=650,height=430,resizable=yes');}};var forumchange_running=false;function postPreview(){var val=$('#i_content').val();jQuery.post('/pages/forums/preview_ajax.php',{text:val},function(data,textStatus){if(textStatus=='success')$('#msgpreview_content').html(data);else $('#msgpreview_content').html('error');$('#msginput').animate({height:"hide"},{duration:"slow",queue:false});$('#msgpreview').animate({height:"show"},{duration:"slow",queue:false});$('#prebutton').html('Edit');$$('prebutton').onclick=postEdit;},'html');}function postEdit(){$('#msginput').animate({height:"show"},{duration:"slow",queue:false});$('#msgpreview').animate({height:"hide"},{duration:"slow",queue:false});$('#prebutton').html('Preview');$$('prebutton').onclick=postPreview;}function processEditChange(){if(req.readyState==4){if(req.status==200){if(req.responseXML){var div=$$('forum_dropdown');if(div){var items=req.responseXML.getElementsByTagName("cat");var forum=getElementTextNS("content","encoded",items[0],0);div.innerHTML=forum;}items=req.responseXML.getElementsByTagName("heading");if(items.length>0){var heading=getElementTextNS("content","encoded",items[0],0);$('#i_heading').val(heading);}items=req.responseXML.getElementsByTagName("text");var content=getElementTextNS("content","encoded",items[0],0);try{var tfck=(FCKeditorAPI.GetInstance('i_content'));if(tfck)tfck.SetHTML(content);}catch(e){$('#i_content').val(content).focus();}}}else alert("There was a problem retrieving the XML data:\n"+req.statusText);forumchange_running=false;}}function forum_edit(id,pid){if(forumchange_running)return false;forumchange_running=true;var oldNode=$$('commentreplybox');var newNode=$$('message_'+id);oldNode.parentNode.removeChild(oldNode);newNode.appendChild(oldNode);newNode.scrollIntoView(false);$('#i_id').val(id);$('#submitbutton').val('Save Edit');if(id==pid){$('#reply_id').val(0);$('#editheader').fadeIn();$('#replymsg').html('<strong>Post Heading: (editing main message)</strong>');}else{$('#reply_id').val(pid);$('#editheader').fadeOut();$('#replymsg').html('<strong>Post Heading: (editing reply message)</strong>');}$('#is_edit').val(1);loadXMLDoc('/pages/forums/edit_ajax.xml?id='+id,processEditChange);return true;}function forum_move_reply(id){var oldNode=$$('commentreplybox');var newNode=$$('message_'+id);oldNode.parentNode.removeChild(oldNode);newNode.appendChild(oldNode);newNode.scrollIntoView(false);$('#i_content').focus();}function forum_reply(id,pid){$('#reply_id').val(id);$('#is_edit').val(0);$('#editheader').fadeOut();$('#i_heading').val($('#heading_'+pid).html());$('#submitbutton').val('Post Reply');$('#replymsg').html('<strong>Post Heading: (reply to main message)</strong>');}function forum_fornews(id,state){var val=(state.checked?1:0);loadXMLDoc('/pages/forums/fornews_ajax.xml?id='+id+'&state='+val,null);}function forum_alert(id,state){var val=(state.checked?1:0);loadXMLDoc('/pages/forums/alert_ajax.xml?id='+id+'&state='+val,null);}function forum_alert2(id,state,user){var val=(state.checked?1:0);loadXMLDoc('/pages/forums/alert_ajax.xml?id='+id+'&state='+val+'&user='+user,null);}function reset_edit(){var oldNode=$$('commentreplybox');var newNode=$$('message_new');oldNode.parentNode.removeChild(oldNode);newNode.appendChild(oldNode);newNode.scrollIntoView(false);$('#reply_id').val(0);$('#is_edit').val(0);$('#submitbutton').val('Post New Message');$('#replymsg').html('<strong>Post Heading: (new thread)</strong>');$('#i_content').focus();}function addText(wnd,id,txt){var myField=wnd.getElementById(id);txt+=' ';var pos;var txtsel=0;var txtlen=txt.indexOf('...');if(txtlen==-1)txtlen=txt.length;else txtsel=3;if(wnd.selection){myField.focus();sel=wnd.selection.createRange();var i=myField.value.length+1;theCaret=sel.duplicate();while(theCaret.parentElement()==myField&&theCaret.move("character",1)==1)--i;var pos=i-myField.value.split('\n').length+1+txtlen;sel.text=txt;var range=myField.createTextRange();range.collapse(true);range.moveEnd('character',pos+txtsel);range.moveStart('character',pos);range.select();}else{var scrolly=myField.scrollTop;var pos;if(myField.selectionStart||myField.selectionStart=='0'){var startPos=myField.selectionStart;var endPos=myField.selectionEnd;myField.value=myField.value.substring(0,startPos)+txt+myField.value.substring(endPos,myField.value.length);pos=startPos+txtlen;}else{myField.value+=txt;pos=myField.value.length;}myField.focus();myField.setSelectionRange(pos,pos+txtsel);myField.scrollTop=scrolly;}}function markup(elementType,id){var txt='';switch(elementType){case'bold':txt='\\b';break;case'italic':txt='\\e';break;case'codetemplate':txt='//! Brief Description\n'+'/*!\n'+'Detailed Description...\n\n'+'\\param [details of 1st parameters here]\n\n'+'\\return [details of any return value here]\n\n'+'\\par Example\n'+'\\code\n'+'  [working example goes here]\n'+'\\endcode\n'+'\\b Output:\n'+'\\code\n'+'  [output from working example goes here]\n'+'\\endcode\n\n'+'\\author '+document.getElementById('authordetails').value+'\n'+'\\par References:\n'+'  [enter references here]\n'+'*/\n'+'[ENTER YOUR SOURCE CODE HERE]\n';break;case'function':txt='//! Brief Description\n'+'/*!\nDetailed Description...\n\n*/';+'double fn()\n{\n}\n';break;case'note':txt='\\note '+prompt('Enter the note text here')+'\n';break;case'input_params':txt='\\param '+prompt('Enter the parameter name')+' '+prompt('Describe the parameter')+'\n';break;case'return_val':txt='\\return '+prompt('Describe the function\'s return value')+'\n';break;case'example':txt='\\example\n'+'\\code\n'+'  [working example foes here]\n'+'\\endcode\n'+'\\b Output:\n'+'\\code\n'+'  [output from working example goes here]\n'+'\\endcode\n';break;case'references':txt='\\par References: '+prompt('Enter the reference here')+'\n';break;case'compatibility':txt='\\par Compatibility\n'+'\begin{html}\n'+'<table class="compat">\n'+'<tr><th></th><th>DOS</th><th>UNIX</th><th>Windows</th><th>ANSI C</th><th>C++ only</th></tr>\n'+'<tr><td>[fn]</td><td>&bull; [DOS]</td><td>&bull; [UNIX]</td><td>&bull; [Windows]</td><td>&bull; [ANSI]</td><td>&bull; [C++]</td></tr>\n'+'</table>\n\end{html}\n';break;default:txt='';}insertText(txt,id);}function insertText(txt,id){addText(document,id,txt);}myUndo=0;myRedo=0;store_text=new Array();store_text.push("");var lastkey=0;function countclik(box,e,tag){if(window.event)key=window.event.keyCode;else if(e)key=e.which;if((key!=32&&key!=8&&key!=46)||key==lastkey){lastkey=key;return;}lastkey=key;myUndo-=myRedo;if(myUndo>10)store_text.shift();else myUndo++;store_text[myUndo]=tag.value;myRedo=0;$('#redobutton_'+box).attr('src',"/images/buttons/redo-x.gif");$('#undobutton_'+box).attr('src',"/images/buttons/undo.gif");}function undo(box){tag=document.getElementById(box);if(myRedo==0){if(myUndo>10)store_text.shift();else myUndo++;store_text[myUndo]=tag.value;}if(myRedo<myUndo){myRedo++;if(myRedo==myUndo)$('#undobutton_'+box).attr('src',"/images/buttons/undo-x.gif");$('#redobutton_'+box).attr('src',"/images/buttons/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=document.getElementById(box);if(myRedo>0){myRedo--;if(myRedo==0)$('#redobutton_'+box).attr('src',"/images/buttons/redo-x.gif");$('#undobutton_'+box).attr('src',"/images/buttons/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 display_versions(divid,module,viewingid){var img=$('#'+divid+'IMG');var lyr=$('#'+divid+'LYR');if(!img.length||!lyr.length)return;var bshow=!lyr.is(':visible');img.attr('class',bshow?'arrowup':'arrowdown');if(bshow){lyr.show();if(!lyr.attr('loaded')){lyr.attr('loaded',1);lyr.html("Loading Versions <img src=\"/images/icons/wait.gif\" width=\"13\" height=\"13\" border=\"0\" />");lyr.load('/pages/functions/code_versions_ajax.php?moduleID='+module+(viewingid!=null?'&viewing='+viewingid:''));}}else lyr.hide();}var vc_running=false;function processVersionChange(){if(req.readyState==4){if(req.status==200){if(req.responseXML){var items=req.responseXML.getElementsByTagName("item");var module=getElementTextNS("","module",items[0],0);var version=getElementTextNS("","version",items[0],0);var licence=getElementTextNS("","licence",items[0],0);var price=getElementTextNS("","price",items[0],0);var pub=getElementTextNS("","pub",items[0],0);var brief=getElementTextNS("content","encoded",items[0],0);$('#published'+version).attr('checked',true);$('#lictype'+module).attr('selectedIndex',licence);lyr=$$('price'+module);var fxrate=$$('fxrate');if(fxrate&&lyr)lyr.value=formatCurr(parseFloat(price)*parseFloat(fxrate.value));$('#publish'+module).attr('checked',(pub=='1'?true:false));$('#brief'+module).html(brief);}}else alert("There was a problem retrieving the XML data:\n"+req.statusText);vc_running=false;}}function selectall(selectable){var ids=selectable.split(",");for(i=0;i<ids.length;i++)$('#'.ids[i]).attr(checked,true);}function togglePublishedModule(element,moduleName,module){if(vc_running)return false;vc_running=true;loadXMLDoc('/pages/manage/change_version_ajax.xml?publish='+module+'&toggle',processVersionChange);return true;}function togglePublishedReference(element,moduleName,module){if(vc_running)return false;vc_running=true;loadXMLDoc('/pages/manage/change_version_ajax.xml?publish='+module+'&toggle&refpage',processVersionChange);return true;}function changeActiveVersion(type,moduleName,new_version){if(vc_running)return false;vc_running=true;if(type=='ref')loadXMLDoc('/pages/manage/change_version_ajax.xml?refpage=1&active='+new_version,processVersionChange);else loadXMLDoc('/pages/manage/change_version_ajax.xml?active='+new_version,processVersionChange);return true;}var Content={edit:function(type,id,unit){$.post('/pages/content/ajax.php',{'type':type,'id':id,'unit':unit,'mode':'edit'},function(data){$('#content_'+unit).replaceWith(data);});},view:function(type,id,unit){$.post('/pages/content/ajax.php',{'type':type,'id':id,'unit':unit,'mode':'view'},function(data){$('#content_'+unit).replaceWith(data);$("a.group").fancybox();});},del:function(type,id,unit){if(confirm("Delete Section "+unit+")"))$.post('/pages/content/ajax.php',{'type':type,'id':id,'unit':unit,'mode':'delete'},function(data){$('#content_'+unit).replaceWith(data);});},save:function(type,id,unit){var stype=$('#content_type_'+unit).val();var title=$('#content_title_'+unit).val();var text=$('#content_text_'+unit).val();$.post('/pages/content/ajax.php',{'type':type,'id':id,'unit':unit,'mode':'save','stype':stype,'title':title,'text':text},function(data){$('#content_'+unit).replaceWith(data);});}};
