// Xsum Javascript Solution Viewer 0.1
// (c) 2005 www.numberpuzzles.com Inc. All rights reserved.  
//
// Version History
//  2005-06-24 0.0 - Initial version
//
// Global variables
//
var XS_maxX;				// width, derived from puzzle data
var XS_maxY;				// height, derived from puzzle data
var XS_soln;				// string representing solution in LR,TB order (first=0)
var XS_mask;				// string representing cell type (B or W)
var XS_currcell;			// id of currently selected white cell; possibly -1
var XS_perfect;				// flag for no reveals or errors


// Global variables "XS_customerID" and "XS_puzzleID" will be provided by the customer web site.
// Based on these variables, a script will set up XP_data.
if (window.XS_data == null) {
	XS_data = "*0000*0010*0004,*12009000030000,*08007000030000.";
}

// Global variable "XS_sounds_url" MAY be provided by the customer web site.  If not, default.
if (window.XS_sounds_url == null) {
	XS_sounds_url = "http://www.numberpuzzles.com/web/sounds/";
}
if (window.XS_images_url == null) {
	XS_images_url = "http://www.numberpuzzles.com/web/images/";
}
// The following global variables MAY be provided by the customer web site.  If not, default.

if (window.XS_zero_errors_text == null) {
	XS_zero_errors_text = "Congratulations! You solved the puzzle without any mistakes!";	// Default to English
}
if (window.XS_some_errors_text == null) {
	XS_some_errors_text = "Congratulations! You solved the puzzle!";	// Default to English
}

// Build the form table
function XS_buildForm(){

	var out_html = '<center>\n<table border=1  bgcolor="#888888" cellpadding=0 cellspacing=0>\n <tr>';
	var x = 0; var y = 1;	// initialize local/globals output vars
	XS_maxX = 0; XS_maxY = 0;

	var pos = 0;
	while (pos < XS_data.length) {
		switch (XS_data.charAt(pos)) {
		case ".":
			pos++;
			XS_maxX = x;
			out_html += " </tr>\n"
			break
		case ",":
			y++; if (y>XS_maxY) XS_maxY = y;
			x=0;
			pos++;
			out_html += " </tr><tr>\n"
			break
		case "*":
			var chunk = XS_data.substring(pos,pos+5);
			pos+=5;
			out_html += XS_solnBlackCell();
			x++;
			break
		case "1":
		case "2":
		case "3":
		case "4":
		case "5":
		case "6":
		case "7":
		case "8":
		case "9":
			var chunk = XS_data.substring(pos,pos+5);
			pos+=5;
			out_html += XS_solnWhiteCell(chunk.charAt(0));
			x++;
			break
		default:
			var c = XS_data.charAt(pos);
			alert('Data errorc=' + c + ' pos=' + pos);
			break
		}
	}
	
	out_html+='<tr><td colspan="'+XS_maxX+'" class="XScopy">'+XS_puzzleID+' &copy; 2010 www.numberpuzzles.com Inc.</td></tr>\n';
	out_html+='</table>\n';
	out_html+='</center>\n';

	return out_html;
}


// Subroutine - Build a black cell
function XS_solnBlackCell(){
	var res = '';
	res+='  <td><img src="' + XS_images_url + 'sdiv.gif"></td>\n';
	return res;
}

// Subroutine - Build a white cell
function XS_solnWhiteCell(dig){
	var res = "";
	res+='  <td class="XSsolW">' + dig + '</td>\n';
	return res;
}



// Javascript-encoded HTML for number puzzle form

var XS_form = XS_buildForm();


// Display number puzzle form
document.write(XS_form);


