/* Copyright 2004-2009 CodeCogs */

/*---- /js/docpage.js ----*/
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.'))}

/*---- /js/calc.js ----*/
function ic_over(lyr,details,unit_num,xoffset){var offset=$(lyr).offset();$('#ic_hover_'+unit_num).html(details).css({'top':(offset.top+18)+'px','left':(offset.left-xoffset)+'px'}).fadeIn();}function ic_out(unit_num){$('#ic_hover_'+unit_num).hide();}var emailme=null;function emailmecalc(module_num,unit_num){if(emailme==null){emailme=unit_num;var email=$('#email_'+unit_num).val();$.ajax({url:"/pages/calculator/email.php",global:false,type:"GET",data:({m:module_num,u:unit_num,email:email}),success:function(data){var div=$('#ic_link_'+emailme);if(data=='login')div.html('<div class="yellowbox">Sorry you must <a href="/general.php?subindex=3">login</a> before we can send emails on your behalf</div>');else div.html('<div class="yellowbox">'+data+'</div>');},failure:function(XMLHttoRequest,textStatus,errorThrown){$('#ic_link_'+emailme).html('<div class="yellowbox">There was a problem sending the email:'+textStatus+'</div>');}})}else{$('#ic_link_'+unit_num).html('Sorry we\'re already in the process of sending another email for you. One at a time please!');}}function ic_link_popup(module_num,unit_num){if($('#ic_set_'+unit_num).length)height=$('#ic_set_'+unit_num).height()+50;else height=350;mywindow=window.open('/pages/calculator/link_popup.php?m='+module_num+'&u='+unit_num+'&height='+height,'Instant_Calculator','width=220,height=300,resizable=no');}function ic_link(module_num,unit_num){if($('#ic_set_'+unit_num).length)height=$('#ic_set_'+unit_num).height()+50;else height=350;$('#ic_link_'+unit_num).html('<hr/><strong>YOU CAN SHARE THIS CALCULATOR IN THREE WAYS:</strong><div class="greybox">Embed onto your website with:<textarea readonly="readonly" rows="5" onclick="this.select()"><iframe src="http://www.codecogs.com/ic-'+module_num+'&amp;u='+unit_num+'" frameborder="0" scrolling="no" width="235" height="'+height+'"></iframe></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="emailmecalc('+module_num+','+unit_num+')" class="bluebutton" value="Email Calculator"/></div><div class="greybox">Make a link to this page:<input type="text" class="text" readonly="readonly" value="http://www.codecogs.com/cog-'+module_num+'" style="width:190px" onclick="this.select()"/></div>').show();}function getinputs(types,modids,single){var v='';for(i=0;i<types.length;i++){var val=$('#'+modids+i).val();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){j=val.indexOf(':');if(j!=-1)val=val.substr(0,j);}v+=val.toString();}break;}}}v=escape(v.replace(/\+/g,"&plus;"));return(v);}function confirmAgreement(){if($.cookie('instant_calc')!=null||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('instant_calc',1,{expires:7});return true;}return false;}function calcphpnow(module_num,fn,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,true);if(confirmAgreement()){$("#"+modids+'result').load('/pages/calculator/calc.php?id='+module_num+'&fn='+fn+'&values='+v);ic_out(divid);}}function graphphpnow(module_num,fn,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,false);if(confirmAgreement())window.open('/pages/calculator/graph.php?mod='+module_num+'&fn='+fn+'&values='+v,'Instant_Graph','width=650,height=430,resizable=yes');}function tablephpnow(module_num,fn,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,false);if(confirmAgreement())window.open('/pages/calculator/graph.php?table=1&mod='+module_num+'&fn='+fn+'&values='+v,'Instant_Table','width=610,height=400,resizable=yes,scrollbars=yes,scrolling=yes');}function calcnow(mode,file,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,true);if(confirmAgreement()){$('#'+modids+'result').load('/pages/calculator/calc.php?'+mode+'='+file+'&types='+types+'&values='+v);ic_out(divid);}}function graphnow(mode,file,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,false);if(confirmAgreement())window.open('/pages/calculator/graph.php?'+mode+'='+file+'&types='+types+'&values='+v,'Instant_Graph','width=650,height=430,resizable=yes');}function tablenow(mode,file,types,divid){var modids='ic'+divid.toString()+'_';var v=getinputs(types,modids,false);if(confirmAgreement())window.open('/pages/calculator/graph.php?table=1&'+mode+'='+file+'&types='+types+'&values='+v,'Instant_Table','width=610,height=400,resizable=yes,scrollbars=yes,scrolling=yes');}

/*---- /pages/cart/js/cartbar.js ----*/
function processAddToCart(){if(req.readyState==4){if(req.status==200){if(req.responseXML){var items=req.responseXML.getElementsByTagName("item");var extracost=getElementTextNS("","extracost",items[0],0);var incart=getElementTextNS("","incart",items[0],0);var comment=getElementTextNS("","comment",items[0],0);var lyr=$$('extracost');if(lyr)lyr.innerHTML=extracost;lyr=$$('cartcount');if(lyr)lyr.innerHTML=incart;if(comment.length>0)alert('We added the following extra components so you have the right number of licences for each subcomponent:'+comment);}}else alert("There was a problem retrieving the XML data:\n"+req.statusText);}}function addToCart(id,num){if(typeof(num)=="undefined"||num==null)num=1;var div=$$('cartcount');if(div)div.innerHTML="<img src=\"/images/icons/wait.gif\" width=\"13\" height =\"13\" border=\"0\" />";loadXMLDoc('/pages/cart/add_licence_ajax.xml?module='+id+'&add='+num,processAddToCart);}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 THE GNU 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\nIf you accept, then the available download/view options will show up in the cartbar near the top right of all pages.\n\nPlease click the \'Cancel\' button if you do NOT wish to be legally bound by these terms.'));}function getGPL(){if(acceptGPLTerms())document.location.href=document.location.href+'?getGPL=1';}function processBuyNow(){if(req.readyState==4){if(req.status==200){div=$$('buynow');div.innerHTML=req.responseText;document.pp_paynow.submit();}else alert("There was a problem retrieving the XML data:\n"+req.statusText);}}function buynow(id){loadXMLDoc('/pages/cart/buy_now_ajax.php?module='+id,processBuyNow);}function gotocart(img){img.src="/images/browser/gotocart.gif";img.onclick=function(){window.location='/cart.php';}}

/*---- /pages/forums/js/edit.js ----*/
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();}

/*---- /js/submit.js ----*/
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'+'<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';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();}

/*---- /js/versions.js ----*/
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('src','/images/browser/arrow_'+((bshow)?'up':'down')+'.gif');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");module=getElementTextNS("","module",items[0],0);version=getElementTextNS("","version",items[0],0);licence=getElementTextNS("","licence",items[0],0);price=getElementTextNS("","price",items[0],0);pub=getElementTextNS("","pub",items[0],0);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;}