var selectDiv=document.createElement("div");var isSelect=false,isMSIE=false,isScrolling=false;var left,top,oWidth,nWidth,oHeight,spreadHeight=60;var selectionValue="Null",appClipBoard="";var startSelect="0";var endSelect="0";var dragColRow="Null";var elemCallId="Null";var scrollController;var lastUsedElem=new Array(0,1);var default_number_per_box=4;var completed=false;var originalValues="";var this_puzzle="";var cells=new Array(9);for(var i=0;i<9;i++){cells[i]=new Array(9)}function disableSelection(a){if(isMSIE){a.onselectstart=function(){return false}}}function loadFile(){var c=document.getElementById("workspace:fileOpenContent").value;lastUsedElem[0]=getWidth(c,",","|"),lastUsedElem[1]=getHeight(c,"|");var d=c.split("|");if(c.length>0){for(var e=0;e<=lastUsedElem[1];e++){var b=d[e].split(",");for(var a=0;a<lastUsedElem[0];a++){if(b[a].length>0){document.getElementById(a+"-"+(e+1)).innerHTML=b[a]}}}}}function beginSave(){var c="";for(var d=1;d<=lastUsedElem[1];d++){for(var a=0;a<=lastUsedElem[0];a++){var b=stripHTML(document.getElementById(a+"-"+d).innerHTML);c+=b;if(a<lastUsedElem[0]){c+=","}}if(d<lastUsedElem[1]){c+="|"}}document.getElementById("workspace:fileSaveContent").value=c}function beginPrint(){childWin=open("childWin",null,"menubar=yes, innerwidth=600,innerheight=600");var a=document.getElementById("workspace:consoleTextArea").value;childWin.document.write("<html><head><title>Preview text</title>");childWin.document.write("</head><body><pre>");childWin.document.write("<p><b>Contents of Console:</b></p>");childWin.document.writeln(a);childWin.document.write("</pre></body></html>");childWin.document.close()}function handleDisplay(){var d=document.getElementById("workspace:result").value;document.getElementById("workspace:objData").value="";if(endSelect!="0"&&startSelect!="0"){var e=startSelect.split("_");var h=endSelect.split("_");var a=getWidth(d,",","|");var c=getHeight(d,"|");h[0]=(parseInt(h[0])+2).toString();var g=h[0]+"_"+e[1];var b=(parseInt(h[0])+a).toString()+"_"+(parseInt(h[1])+c).toString();if(elementExist(b)){setLastUsedElem(parseInt(h[0])+a,parseInt(h[1])+c);var f=document.getElementById("workspace:query").value;f=f.replace(/~/g," ");document.getElementById("workspace:consoleTextArea").value=f+" = "+d+"\n"+document.getElementById("workspace:consoleTextArea").value;displayMultiValues(d,g,a,c)}}else{displaySolution(d)}}function handleMultiDisplay(f,b){if(startSelect!="0"){var a=getWidth(f,",","|");var d=getHeight(f,"|");var e=b.split("_");var c=(parseInt(e[0])+a).toString()+"_"+(parseInt(e[1])+d).toString();if(elementExist(c)){displayMultiValues(f,b,a,d);setLastUsedElem(parseInt(e[0])+a,parseInt(e[1])+d)}}}function displayMultiValues(e,f,l,c){var d=f.split("_");var a=parseInt(d[0]);var k=parseInt(d[1]);var g=0;var b=e.split(/\,|\|/);for(var h=k;h<k+c;h++){for(var j=a;j<a+l;j++){if(g<b.length){}if(b[g].length>0){document.getElementById(j+"-"+h).innerHTML=b[g]}g++}}document.getElementById(d[0]+"-"+d[1]).focus();clearSelection();clearSelectionValue(true)}function getWidth(e,c,d){if(e.length>0){var b=e.indexOf(d);if(b>-1){e=e.substring(0,b)}var a=strCountOccurences(e,c);return a+1}return 0}function getHeight(c,b){if(c.length>0){var a=strCountOccurences(c,b);return a+1}return 0}function strCountOccurences(a,d){var c=0;for(var b=0;b<a.length;b++){if(a.charAt(b)==d){c++}}return c}function checkBrowser(){if(navigator.userAgent.toLowerCase().indexOf("msie")>-1){isMSIE=true}}function stripHTML(b){var a=/<(?:.|\s\n)*?>/g;return b.replace(a,"").replace(/&nbsp;/g,"")}function buildSpreadSheet(){checkBrowser();var c="ABCDEFGHIJKLMNOPQRSTUVWXYZ";var b=26;var a,d;document.write('<div id="container" class="divScroll" onmousemove="continueDrag(event);" onmouseout="startScroll(event);" onmouseup="endDrag(event);">');document.write('<table id="grid" class="sofT">');document.write('<TR><TD class="fixedWidthCell" onmouseover="clearDrag();"></TD>');for(a=0;a<b;a++){document.write('<TD id="col'+a+'" class="headercells" onmousedown="startDragCol(event, this);">'+c.charAt(a)+"</TD>")}document.write("</TR>");for(d=1;d<=spreadHeight;d++){document.write('<TR class="row" ><TD class="fixedWidthCell">'+d+"</TD>");for(a=0;a<b;a++){document.write('<TD id="'+a+"_"+d+'" class="cell" onkeydown="checkArrowPress(this.id, event);" onmousedown="startSelection(this, event);" onmouseover="modDivDimension(this);" onmouseup="endSelection(this);">');document.write('<div id="'+a+"-"+d+'" contenteditable="true" onchange="handleChange(this.id);" class="inputGridElem"></div></TD>')}document.write("</TR>")}document.write("</table>");document.write("</div>");disableSelection(document.getElementById("grid"));setDiv();attachDiv()};