This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
93 lines (93 loc) · 19.7 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var aws='d2gbom735ivs5c.cloudfront.net/m';var mi2='www.mi2f.com/m';var eon='www.eonhq.com/m';var d=document;function headTags(){tag1=document.createElement('meta');tag1.id="viewport";tag1.name="viewport";tag1.content="width=device-width; initial-scale=1.0; user-scalable=true;";document.getElementsByTagName('head')[0].appendChild(tag1);tag2=document.createElement('meta');tag2.id="HandheldFriendly";tag2.name="HandheldFriendly";tag2.content="true";document.getElementsByTagName('head')[0].appendChild(tag2);}
headTags();function doPic(){var pics=document.getElementsByClassName('pic');for(var i=0;i<pics.length;i++){pictag=pics[i];var notags=pictag.getElementsByTagName('noscript');for(var j=0;j<notags.length;j++){notag=notags[j];var txt=notag.innerHTML;var col0=txt.indexOf('src="');if(col0<0)continue;var col1=txt.indexOf('"',col0+5);if(col1<0)continue;var path=txt.substr(col0+5,col1-col0-5);if(path.length<1)continue;txt=txt.replace(path,cdnPath(path)).replace("<","<").replace(">",">");var el=document.createElement('div');el.innerHTML=txt;els=el.getElementsByTagName('img');var picEl=els[0];var img=pictag.appendChild(picEl);}}}
function cdnPath(path){if(true)return(path);var url=absolute(location.href,path);var dum="[$]";url=url.replace("www.mathsisfun.com",dum);url=url.replace("localhost:81/mathsisfun",dum);var col1=url.indexOf(dum);if(col1==-1)return path;var col2=url.lastIndexOf("../index.html");if(col2==-1)return path;col1+=dum.length;var dirStr=url.substr(col1,col2-col1);var newDom="";var ext=url.split('.').pop();var dirs=[];switch(ext){case "swf":dirs=[["images","mi2"],["activity#","mi2"],["algebra#","mi2"],["calculus#","mi2"],["combinatorics#","mi2"],["data#","mi2"],["definitions#","mi2"],["games#","mi2"],["geometry#","mi2"],["measure#","mi2"],["money#","mi2"],["numbers#","mi2"],["sets#","mi2"],["TI#","mi2"]];break;case "jpg":case "gif":case "png":dirs=[["images","mi2"],["images/style","mi2"],["activity#","mi2"],["algebra#","mi2"],["calculus#","mi2"],["combinatorics#","mi2"],["data#","mi2"],["definitions#","eon"],["games#","mi2"],["geometry#","mi2"],["measure#","mi2"],["money#","mi2"],["numbers#","mi2"],["sets#","mi2"],["TI#","mi2"]];break;}
for(var i=0;i<dirs.length;i++){var dir0="/"+dirs[i][0].replace("#","/images");if(dirStr==dir0){newDom=dirs[i][1];break;}}
switch(newDom){case "eon":url=url.replace(dum,eon);return url;break;case "mi2":url=url.replace(dum,mi2);return url;break;case "aws":url=url.replace(dum,aws);return url;break;}
return path;}
function absolute(base,relative){var stack=base.split("../index.html"),parts=relative.split("../index.html");stack.pop();for(var i=0;i<parts.length;i++){if(parts[i]==".")
continue;if(parts[i]=="..")
stack.pop();else
stack.push(parts[i]);}
return stack.join("../index.html");}
function getLocation(){return window.location.toString();}
DecSep=(1.5).toLocaleString().charAt(1);ThouSep=String.fromCharCode(90-DecSep.charCodeAt(0));if(DecSep==","){DecType="c";}else{DecType="";}
function decfmt(){if(DecSep==","){fixSpells(document.body,"d");var imgs=document.body.getElementsByTagName("img");for(var i=0;i<imgs.length;i++){if(imgs[i].getAttribute("hasdec")!=null&&imgs[i].getAttribute("hasdec")!=""){imgs[i].src=imgs[i].src.replace(/\.(gif|jpg|png)/g,"c.$1");}}}}
function doSpell(){if(typeof(reSpell)=='undefined')return;var userLang=(navigator.language)?navigator.language:navigator.userLanguage;switch(userLang.toLowerCase()){case "en-us":break;case "en-au":case "en-ca":case "en-gb":case "en-ie":case "en-nz":case "en-za":fixSpells(document.body,"s");break;default:}}
function fixSpells(elem,tp){if(!(elem instanceof Node)||elem.nodeType!==Node.ELEMENT_NODE)return;var children=elem.childNodes;for(var i=0;children[i];++i){var node=children[i];switch(node.nodeType){case Node.ELEMENT_NODE:fixSpells(node,tp);break;case Node.TEXT_NODE:if(tp=="s")fixSpell(node);if(tp=="d")fixDec(node);break;}}}
function fixSpell(node){var s=node.nodeValue;if(s.length<4)return;if(s.match(/(?=.*[a-zA-Z])/)){var sStt=s;for(var j=0;j<reSpell.length;j++){var s0=reSpell[j][0];var s1=reSpell[j][1];s=s.replace(new RegExp('\\b'+s0+'\\b','g'),s1)
s=s.replace(new RegExp('\\b'+proper(s0)+'\\b','g'),proper(s1));}
if(s!=sStt)node.nodeValue=s;}}
function fixDec(node){var s=node.nodeValue;var sStt=s;s=s.replace(/(\d),(\d\d)/g,'$1#$2').replace(/(\d)\.(\d)/g,'$1,$2').replace(/(\d)#(\d)/g,'$1.$2');if(s!=sStt){node.nodeValue=s;}}
function doLocal(){decfmt();doSpell();getRelated();document.getElementById('header').addEventListener('click',function(e){if(e.target.id=="header"){location.href='../index-2.html';}},false);}
window.onload=doLocal;function proper(s){return s.charAt(0).toUpperCase()+s.substring(1,s.length).toLowerCase();}
function tellAFriend(){var msg="\nI found '"+document.title+"' here: "+location.href+"\n";window.location="mailto:?subject="+encodeURIComponent(document.title)+"&body="+encodeURIComponent(msg);}
function addFavorites(){if(window.sidebar){window.sidebar.addPanel(document.title,location.href,"");}else if(window.external){window.external.AddFavorite(location.href,document.title);}}
function openEnglish(){if(typeof tranfrom=='undefined')tranfrom='index.html';var path=tranfrom;var url="https://www.mathsisfun.com/"+path;window.location=url;}
function linkToUs(){var path=location.pathname+location.search;var title=document.title;postWith("https://"+document.domain+"/link-to-us.php",{path:path,title:title});}
function Citation(){var months=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var path=location.pathname+location.search;var atitle=document.title;var md=new Date(document.lastModified)
mDate=md.getDate()+" "+months[md.getMonth()]+" "+md.getFullYear();if(typeof Author=='undefined')Author='Pierce, Rod';postWith("https://"+document.domain+"/citation.php",{path:path,title:atitle,moddate:mDate,author:Author});}
function Contribute(){var path=location.pathname+location.search;var atitle=document.title;postWith("https://"+document.domain+"/contribute.php",{path:path,title:atitle});}
function postWith(to,p){var myForm=document.createElement("form");myForm.method="post";myForm.action=to;for(var k in p){var myInput=document.createElement("input");myInput.setAttribute("name",k);myInput.setAttribute("value",p[k]);myForm.appendChild(myInput);}
document.body.appendChild(myForm);myForm.submit();document.body.removeChild(myForm);}
function URLEncode(text){var SAFECHARS="0123456789"+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"-_.!~*'()";var HEX="0123456789ABCDEF";var s="";for(var i=0;i<text.length;i++){var ch=text.charAt(i);if(ch==" "){s+="+";}else if(SAFECHARS.indexOf(ch)!=-1){s+=ch;}else{var charCode=ch.charCodeAt(0);if(charCode>255){s+="+";}else{s+="%";s+=HEX.charAt((charCode>>4)&0xF);s+=HEX.charAt(charCode&0xF);}}}
return s;}
function CopyToClipboard(txtArea){txtArea.focus();txtArea.select();CopiedTxt=document.selection.createRange();CopiedTxt.execCommand("Copy");}
function getFlash6HTML(w,h,fn,querystring,clr){if(!querystring){querystring="";}else{querystring="?"+querystring;}
fn=cdnPath(fn);if(!clr){clr="#d6d9e6";}
if(fn.substring(fn.lastIndexOf('.swf'))!='.swf')fn=fn+'.swf';var s='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,79,0" width="'+w+'" height="'+h+'" id="'+fn+'">\n';s+='<param name="movie" value="'+fn+querystring+'"\/> ';s+='<param name="quality" value="high"\/> ';s+='<param name="bgcolor" value="'+clr+'"\/> ';s+='<param name="menu" value="false"\/> ';s+='<param name="allowScriptAccess" value="sameDomain"\/> ';s+='<param name="allowFullScreen" value="true"\/> ';s+='<embed src="'+fn+querystring+'" quality="high" bgcolor="'+clr+'" ';s+='menu="false" width="'+w+'" height="'+h+'" type="application\/x-shockwave-flash" ';s+='pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer" ';s+='swLiveConnect="true" allowscriptaccess="sameDomain" allowFullScreen="true" id="'+fn+'" name="'+fn+'"><noembed><\/noembed><\/embed>\n';s+='</object>\n';return(s);}
function putFlash6(w,h,fn,querystring,clr,noflash){if(hasFlash()){document.write(getFlash6HTML(w,h,fn,querystring,clr));}else{if(noflash){s=noflash;}else{s='<a href="../flash-player.html"><img src="/images/style/no-flash.jpg" alt="Needs Flash Player"></a>';}
document.write(s);if(Math.random()<0.1){var path=location.pathname;var pg=path+", "+fn;var pgHex='';for(var i=0;i<pg.length;i++){pgHex+=''+pg.charCodeAt(i).toString(16);}
addView(pgHex,"View",window.location.hostname);}}}
function hasFlash(){try{var fo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash');if(fo)return true;}catch(e){if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)return true;}
return false;}
function FlashPHP(w,h,pathtoswf,clr){var path=location.pathname;path=URLEncode(path.substring(0,path.lastIndexOf('../index.html')));var atitle=URLEncode(document.title);var url="https://"+document.domain+"/flash.php?path="+path+"/"+pathtoswf+"&w="+w+"&h="+h+"&col="+URLEncode(clr)+"&title="+atitle;window.location=url;}
var adIDs=Array(Array('topads',1,0),Array('adend',1,0),Array('hideads1',1,0),Array('showads1',0,1));function sethideadscookie(val){var date=new Date();if(val==1)
date.setTime(date.getTime()+(1*25*60*60*1000));else
date.setTime(date.getTime()-(30*24*60*60*1000));document.cookie="math_hideads="+val.toString()+"; expires="+date.toGMTString()+"; path=/";}
function setAds(stateNo){var styles=Array('none','inline');for(var i=0;i<adIDs.length;i++){var e=document.getElementById(adIDs[i][0]);if(e){var styleNo=adIDs[i][stateNo];if(navigator.userAgent.indexOf('MSIE')>0){e.style.display=styles[styleNo];}else{var style="display: "+styles[styleNo]+";";e.setAttribute('style',style);}}}}
function hideads(){sethideadscookie(1);setAds(2);}
function showads(){sethideadscookie(0);setAds(1);}
var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];var pair=c.split('=');var key=pair[0];var value=pair[1];key=key.replace(/ /,'');if(key=='math_hideads'){var styles=Array('none','inline');if(value=='1'){var s='<style type="text/css" media="screen">';for(var j=0;j<adIDs.length;j++){var styleNo=adIDs[j][2];s+='#'+adIDs[j][0]+' { display: '+styles[styleNo]+'; }\n ';}
s+='</style>';document.write(s);}}}
function printImg(s){pwin=window.open(s,"_blank");setTimeout("pwin.print()",2000);}
function doQ(id,qs){var fromPath=location.pathname+location.search;var url="https://www.mathopolis.com/questions/q.php?id="+parseInt(id)+"&site=1"+"&ref="+fromPath;if(typeof qs=='undefined'){url+="&qs=0";}else{url+="&qs="+qs;}
window.open(url,"mathopolis");}
function getQ(){var qs="";for(var i=0;i<arguments.length;i++){if(i>0)qs+="_";qs+=arguments[i];}
var s="";for(i=0;i<arguments.length;i++){s+='<a href="javascript:doQ('+arguments[i]+",'"+qs+"'"+')">Question '+(i+1)+'</a> ';}
document.write(s);}
function getMenuTop(){var stack=location.href.split("../index.html");stack.pop();var url=stack.join("../index.html");var urlStt="../index.html";if(endsWith(url,"/mathsisfun"))urlStt="";if(endsWith(url,"mathsisfun.com"))urlStt="";var links=[["index.htm","Home",0],["algebra/index.html","Algebra",0],["data/index.html","Data",0],["geometry/index.html","Geometry",0],["measure/index.html","Measure",0],["money/index.html","Money",1],["numbers/index.html","Numbers",0],["activity/index.html","Activities",1],["definitions/index.html","Dictionary",0],["games/index.html","Games",0],["puzzles/index.html","Puzzles",0],["worksheets/index.php","Worksheets",0]];var s="";s+='<ul>';var linkLen=links.length;if(window.innerWidth>760){for(var i=0;i<linkLen;i++){if(links[i][2]==0)
s+='<li><a href="'+urlStt+links[i][0]+'">'+links[i][1]+'</a></li>';}}else{s+='<li><a href="'+urlStt+links[0][0]+'">'+links[0][1]+'</a></li>';s+='<li><a href="#">Subjects ▼</a>';s+='<ul>';for(i=1;i<=6;i++){s+='<li><a href="'+urlStt+links[i][0]+'">'+links[i][1]+'</a></li>';}
s+='</ul>';s+='</li>';s+='<li><a href="#">More ▼</a>';s+='<ul>';for(i=7;i<links.length;i++){s+='<li><a href="'+urlStt+links[i][0]+'">'+links[i][1]+'</a></li>';}
s+='</ul>';s+='</li>';}
s+='</ul>';document.write(s);}
function endsWith(str,suffix){return str.indexOf(suffix,str.length-suffix.length)!==-1;}
function getAdRight(){var s="";s+='<div style="margin-left: -425px; width:300px;">';s+=getLinks(true);s+='</div>';document.write(s);}
function getAdRight2(){var s='';s+=getLinks(false);if(true){s+='<div id="google_translate_element" style="border: none; display:inline; float:left; "></div>';s+='<script type="text/javascript">';s+=' function googleTranslateElementInit() {';s+="new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');";s+=' }</script>';s+=' <script type="text/javascript" src="../../translate.google.com/translate_a/elementa0d8.js?cb=googleTranslateElementInit"></script>';}
if(true){var url=location.href;s+='<div style="border: none; display:inline; margin: 0px; position:absolute; left:310px;">';s+='<span class="g-plusone" data-size="standard" data-href="'+url+'"></span>';s+='</div>';}
document.write(s);}
function getAdTop(){var s="";s+='<script async src="../../pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>';s+='<!-- MIFTop -->';s+='<ins class="adsbygoogle"';s+=' style="display:block;height:100px"';s+=' data-ad-client="ca-pub-1389989178296449"';s+=' data-ad-slot="6226552230"';s+=' data-ad-format="auto"></ins>';s+='<script>';s+='(adsbygoogle = window.adsbygoogle || []).push({});';s+='</script>';document.write(s);}
function getAdEnd(){var url=location.href;if(url.indexOf("definitions")>0)return;var s="";s+='<script async src="../../pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>';s+='<!-- MathsIsFunResp -->';s+='<ins class="adsbygoogle mathsisfunresp"';s+=' style="display:inline-block"';s+=' data-ad-client="ca-pub-1389989178296449"';s+=' data-ad-slot="8658120633"></ins>';s+='<script>';s+='(adsbygoogle = window.adsbygoogle || []).push({});';s+='</script>';document.write(s);}
function getLinks(oldQ){var url=location.href;var title=encodeURIComponent(document.title);var linkstt='<a target="_blank" href="';var s="";s+=linkstt+'https://twitter.com/home?status='+title+': '+url+'" id="linktw">Twitter</a> ';s+=linkstt+"https://www.stumbleupon.com/submit?url="+url+"&title="+title.replace(/%20/g,'+')+'" id="linksu">StumbleUpon</a> ';s+=linkstt+"https://www.facebook.com/sharer.php?u="+url+"&t="+title+'" id="linkfb">Facebook</a> ';s+='<a href="javascript:linkToUs()" id="linkus">Link To Us</a>';return s;}
function getBodyEnd(){doPic();var ffq=false;if(navigator.userAgent.indexOf("Firefox")!=-1)ffq=true;var s="";s+=gPlusOneCall();s+=gAnalyticsCall();if(ffq){}else{}
document.write(s);}
function gPlusOneCall(){var s="";s+='<script type="text/javascript">';s+='(function() {';s+="var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;";s+="po.src = '../../apis.google.com/js/plusone.js';";s+="var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);";s+='})();';s+='</script>';return s;}
function gAnalyticsCall(){var s="";s+='<script type="text/javascript">';s+='var _gaq = _gaq || [];';s+="_gaq.push(['_setAccount', 'UA-29771508-1']);";s+="_gaq.push(['_trackPageview']);";s+='(function() {';s+="var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;";s+="ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www/') + '.google-analytics.com/ga.js';";s+="var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);";s+='})();';s+='</script>';return s;}
function logVisit(){var pg=location.pathname;var pgHex='';for(var i=0;i<pg.length;i++){pgHex+=''+pg.charCodeAt(i).toString(16);}
addView(pgHex,"Visit",window.location.hostname);}
if(Math.random()<0.1)logVisit();function addView(pg,viewtype,hostname){var req;req=new XMLHttpRequest();params="type="+viewtype;params+="&pg="+encodeURIComponent(pg);if(hostname=="localhost"){req.open("POST.html","http://localhost:81/mathopolis/links/update.php",true);}else{req.open("POST.html","https://www.mathopolis.com/links/update.php",true);}
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");req.setRequestHeader("Content-length",params.length);req.setRequestHeader("Connection","close");req.send(params);}
function onScroll(){var scrollTop=document.documentElement?document.documentElement.scrollTop:document.body.scrollTop;var menu=document.getElementById("menu");if(scrollTop>100){menu.style.top="0px";menu.style.width="1000px";menu.style.border="1px solid #ffffff";menu.style.boxShadow="0px 12px 12px -12px #77cc77";menu.style.backgroundColor="white";menu.style.textAlign="center";menu.style.position="fixed";menu.style.zIndex="5000";}else{menu.style.boxShadow="none";menu.style.position="static";}}
function getRelated(){if(window.innerWidth<960){return;}
var rels=document.getElementsByClassName('related');if(rels.length==0){return;}
var rel=rels[0];var links=rel.getElementsByTagName("a");var count=links.length;right=null;left=null;if(count>0){right=links[0];if(count>1){left=links[count-1];}}
var pgWd=760;var linkWd=110;var wd=((window.innerWidth-pgWd)/2-linkWd)/2+pgWd/2;wd=Math.max(360,wd);s='';if(left!=null){s+='<div style="position: fixed; top: 0px; right: 50%; margin: 10px '+wd+'px 10px 0; text-align: left; ">';s+=fmtMenuBox(left.href,left.text,0);s+='</div>';}
if(right!=null){s+='<div style="position: fixed; top: 0px; left: 50%; margin: 10px 0 10px '+wd+'px; text-align: right; ">';s+=fmtMenuBox(right.href,right.text,1);s+='</div>';}
document.getElementById("searchBox").innerHTML+=s;}
function fmtMenuBox(url,txt,dirn){var s="";var boxClass="menuLt";if(dirn==1){boxClass="menuRt";}
s+='<a href="'+url+'" style="text-decoration: none; color: #888888; vertical-align: middle; display: table;">';s+='<div class="'+boxClass+'" >';s+=txt;s+='</div>';s+='</a>';return s;}
function initVideo(id,titleid,spanid,style){titleid=typeof titleid!=='undefined'?titleid:'title';spanid=typeof spanid!=='undefined'?spanid:'video';style=typeof style!=='undefined'?style:'h1';if(navigator.appName=="Microsoft Internet Explorer")window.onresize=resizeVideo;title=document.getElementById(titleid).innerHTML;s='';switch(style){case "h1":s+='<div class="centerfull" style="clear:both; font-weight:400; padding: 3px 0 5px 0;">';s+='<div style="float:left; width:60px; text-align:left;">';s+=' <a href="javascript:doVideo(\''+id+'\',\''+spanid+'\')">';s+=' <img src="/images/style/video2.gif" alt="Video" width="75" height="33" style="vertical-align:middle; border:none;" />';s+=' </a>';s+='</div>';s+='<div style="float:right; width:60px; text-align:right;"> </div>';s+=' <div style="margin:0 auto;">';s+=' <h1 align="center">'+title+'</h1>';s+=' </div>';s+='</div>';break;case "h2":s+='<div style="float:right; width:100px; margin: -10px 0 5px 0;">';s+=' <a href="javascript:doVideo(\''+id+'\',\''+spanid+'\')">';s+=' <img src="/images/style/video2.gif" alt="Video" width="75" height="33" style="vertical-align:middle; border:none;" />';s+=' </a>';s+='</div>';s+=' <h2>'+title+'</h2>';break;}
document.getElementById(titleid).innerHTML=s;}
function doVideo(id,spanid){var s="";var visIndex=videoVis.indexOf(spanid);var visQ=visIndex>-1?true:false;if(visQ){var frame=document.getElementById(spanid+"v1");frame.parentNode.removeChild(frame);videoVis.splice(visIndex,1);visQ=false;}else{s+='<div class="center">';s+='<iframe id="'+spanid+'v1" src="https://www.youtube.com/embed/'+id+'?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';s+='</div>';videoVis.push(spanid);visQ=true;}
var vid=document.getElementById(spanid);vid.innerHTML=s;if(visQ)resizeVideo(spanid);}
function resizeVideo(spanid){var v1=document.getElementById(spanid+"v1");var wd=window.innerWidth-40;if(wd>640)wd=640;v1.style.width=wd+"px";v1.style.height=(wd*(340/640)+80)+"px";}
videoVis=Array();