// These vars reference HTML tags in the page whose
// values may be read or set dynamically.
	var browserName=navigator.appName; 
	var m_t11;
	var m_t12;
	var m_t13;
	var m_t14;
	var m_t15;
	var m_t16;
	var m_t17;
	var m_t18;
	var m_t19;
	var m_t21;
	var m_t22;
	var m_t23;
	var m_t24;
	var m_t25;
	var m_t26;
	var m_t27;
	var m_t28;
	var m_t29;
	var m_t31;
	var m_t32;
	var m_t33;
	var m_t34;
	var m_t35;
	var m_t36;
	var m_t37;
	var m_t38;
	var m_t39;
	var m_t41;
	var m_t42;
	var m_t43;
	var m_t44;
	var m_t45;
	var m_t46;
	var m_t47;
	var m_t48;
	var m_t49;
	var m_t51;
	var m_t52;
	var m_t53;
	var m_t54;
	var m_t55;
	var m_t56;
	var m_t57;
	var m_t58;
	var m_t59;
	var m_t61;
	var m_t62;
	var m_t63;
	var m_t64;
	var m_t65;
	var m_t66;
	var m_t67;
	var m_t68;
	var m_t69;
	var m_t71;
	var m_t72;
	var m_t73;
	var m_t74;
	var m_t75;
	var m_t76;
	var m_t77;
	var m_t78;
	var m_t79;
	var m_t81;
	var m_t82;
	var m_t83;
	var m_t84;
	var m_t85;
	var m_t86;
	var m_t87;
	var m_t88;
	var m_t89;
	var m_t91;
	var m_t92;
	var m_t93;
	var m_t94;
	var m_t95;
	var m_t96;
	var m_t97;
	var m_t98;
	var m_t99;
	var m_r1;
	var m_r2;
	var m_r3;
	var m_r4;
	var m_r5;
	var m_r6;
	var m_r7;
	var m_r8;
	var m_r9;
	var m_c1;
	var m_c2;
	var m_c3;
	var m_c4;
	var m_c5;
	var m_c6;
	var m_c7;
	var m_c8;
	var m_c9;
	var m_g1;
	var m_g2;
	var m_g3;
	var m_g4;
	var m_g5;
	var m_g6;
	var m_g7;
	var m_g8;
	var m_g9;
	var m_rad1;
//	var m_rad2;
	var m_rad3;
//	var m_rad4;
	var m_t100;
	var m_gtpuz;
	var mylabel;
	var given = new Array(81);
	var Solved;
	var possib = new Array(81);
	var relements = new Array(9);
	var celements = new Array(9);
	var gelements = new Array(9);
	var nextstep = 0;
	var storestring;
	var changesmade;
	var emptyCellsAreError;
	var backupctr;
	var possibbackup = new Array;
	var givenbackup = new Array;
	var started = false;
	var goneonestep = false;
	var allnonempty = false;
	var browser;
	var currentpuz;
	var newpuz;
//	var puzcount;
//	var Puzzle;
//	var lilperm;
//	var bigperm;
// *******************************************************************
// *********************** STARTUP FUNCTION **************************
// *******************************************************************
function startUp() {
// Purpose: Fires when the page first loads.  
var i;
var j;
var s;
var istring;
var cookiedata;
var getcookie;
var splitcookie = new Array;
var backupentry = new Array;
var cookielength;

m_rad1 = document.getElementById("RAD1");
//m_rad2 = document.getElementById("RAD2");
m_rad3 = document.getElementById("RAD3");
//m_rad4 = document.getElementById("RAD4");
m_t100 = document.getElementById("T100");
m_gtpuz = document.getElementById("GTPUZ");
m_puzlabel = document.getElementById("PUZLABEL");

for (i = 1; i<10; i++) {
s = 'm_r' + i + ' = document.getElementById("R' + i + '");';
eval(s);
s = 'm_c' + i + ' = document.getElementById("C' + i + '");';
eval(s);
s = 'm_g' + i + ' = document.getElementById("G' + i + '");';
eval(s);
for (j = 1; j<10; j++) {
s = 'm_t' + i + j + ' = document.getElementById("T' + i + j + '");';
eval(s);
}
}
browser = "";
//if (browserName.indexOf("Opera") >=0){browser = "Opera";}
//if (browserName.indexOf("Explorer") >=0){browser = "IE";}
if (browserName.indexOf("Netscape") >=0){browser = "Netscape";}
//if (browserName.indexOf("Mozilla") >=0){browser = "Netscape";}
//if (browserName.indexOf("Firefox") >=0){browser = "Firefox";}

for (i = 0; i < 9; i++) {
relements[i] = "";
celements[i] = "";
gelements[i] = "";
}

for(i = 0; i < 81; i++) {
istring = i.toString()
relements[findRow(i + 1) - 1] = relements[findRow(i + 1) - 1] + istring + "|";
celements[findColumn(i + 1) - 1] = celements[findColumn(i + 1) - 1] + istring + "|";
gelements[findSubgrid(i + 1) - 1] = gelements[findSubgrid(i + 1) - 1] + istring + "|";
possib[i]="";
given[i]="";
}

for(i = 0; i < 9; i++) {
relements[i] = relements[i].substring(0,relements[i].length - 1);
celements[i] = celements[i].substring(0,celements[i].length - 1);
gelements[i] = gelements[i].substring(0,gelements[i].length - 1);
}

backupctr = 0;
currentpuz = "n000000";
newpuz = "n000001";
Solved = false;
mylabel = "";

cookiedata = readCookie();
try {
cookielength = cookiedata.length;}
catch (e){cookielength = -1;}
if (cookielength >=0) {
getcookie = confirm("Do you want to load your saved data?");
if (getcookie) {
splitcookie = cookiedata.split('~');

for (i=0;i<splitcookie.length;i++) {
backupentry = splitcookie[i].split('@');
possibbackup[i] = backupentry[0];
givenbackup[i] = backupentry[1];
}

backupctr = splitcookie.length;
possib = possibbackup[backupctr - 1].split("&");
given = givenbackup[backupctr - 1].split("&");
started = true;

Display_Results();
} // end inquiry if
} // end "cookie data if"

}

function findRow(j) {
    var result;
    if (j < 10) {
        result = 1;}
    else
    if (j < 19) {
        result = 2;}
    else
    if (j < 28) {
        result = 3;}
    else
    if (j < 37) {
        result = 4;}
    else
    if (j < 46) {
        result = 5;}
    else
    if (j < 55) {
        result = 6;}
    else
    if (j < 64) {
        result = 7;}
    else
    if (j < 73) {
        result = 8;}
    else {
        result = 9;}
    return result;
}

function findColumn(j) {
    return (j - (findRow(j) - 1) * 9);
}

function findSubgrid(j) {
    var result;
    var row;
    var column;
    row = findRow(j);
    column = findColumn(j);
    result = ((Math.ceil(row / 3) - 1) * 3) + Math.ceil(column / 3);
    return result;
}

function Clear_Form() {
var i;
var j;
var s;
nextstep = 0;

if (confirm("Clear all info? This would clear the screen and all backups."))
{
for (i=0; i<81;i++) 
{
possib[i]="";
given[i]="";
}

for (i = 1; i < 10; i++) {
for (j = 1; j < 10; j++) {
s = 'm_t' + i + j + '.className = "BigBlue";'; 
eval(s);
}
}

backupctr = 0;
started = false;
goneonestep = false;
Solved = false;
m_puzlabel.value = "Puzzle#: ";
m_puzlabel.className = "Easy";
m_t100.value = "";


Display_Results();
}
}

function goOneStep() {
var msg ="";
var possibsave = possib.join("|");
var cnfrm =false;

if (!started) {alert("First enter the 'Given' info and then press 'Start'.");} 
else {

if (goneonestep) {cnfrm = confirm("Reset puzzle to first step?");}

if (cnfrm || !goneonestep) { 
msg = retrieve_possib();
if (msg==""){
//if (!allnonempty)
{for(i=0;i<81;i++){if (given[i].length == 1){possib[i]=given[i];} else {possib[i]="123456789";}}}
updateallsingletons("1");
Display_Results();
goneonestep = true;
Solved = false;
}
else {possib = possibsave.split("|");alert(msg);}

}

}

return msg;

}


function gotgivens() {
var i;
var j;
var valu;
var s;
var result;
var cnfrm;
var possibsave;
var quiet = true;

result = retrieve_possib();

if (result=="") {

for (i=0;i<81;i++){if(possib[i].length==1){given[i]=possib[i];} else {given[i]="";}}
Solved = false;

started = true;
goneonestep = false;
Display_Results();
alert("Your puzzle 'Given' information has been stored.");
back_up(quiet);}
else {alert(result);}

}




function retrieve_possib() {
var i;
var j;
var k;
var valu;
var s;
var result ="";
var savepossib = possib.join("|");
var countgivens = 0;
var giventally = new Array(9);

for (i=0;i<9;i++){giventally[i] = 0;} 

allnonempty = true;

for (i = 1; i < 10; i++) {
for (j = 1; j < 10; j++) {
s = 'm_t' + String(i) + String(j) + '.value';
valu = eval(s);
valu = valu.split(" ").join("");
if(valu.length ==0){allnonempty = false;}
if((valu.length == 1) && valu >= "1" && valu <= "9"){countgivens++;giventally[parseInt(valu) - 1]++;}

for (k=0;k<valu.length;k++){if(valu.substr(k,1) >= "1" && valu.substr(k,1) <= "9" && (valu.substr(k + 1).indexOf(valu.substr(k,1)) < 0)){;} else
{result = "Error in Row "  + i + ", Column " + j + " entry.";}}

possib[(i - 1) * 9 + j - 1] = valu;
}
}

if (result == ""){
j=0; 
for (i=0; i<9; i++){
if(giventally[i]!=0){j++;}
}
if (countgivens<20 || j<8){result="Insufficient information has been entered.";}

} // end if

return result;

}


function solve(dispparm) {
var msg="";
var a;
var b;
var timebegin;
var timeend;
var option;
var possibsave = possib.join("|");

if (!started) {msg="First enter the 'Given' info and then press 'Start'.";} 
else {

Solved = false;
timebegin = new Date();
a = timebegin.getTime();

msg = retrieve_possib();
if (msg == "") {
//if(!allnonempty)
for(i=0;i<81;i++){if(possib[i]==""){possib[i]="123456789";}}
dothesafestuff("");
if(invalidresults()){msg="The software could not find a solution. Please verify that data was entered correctly.";possib = possibsave.split("|");}
else {
if (!Solved){guess(); 
if(invalidresults()){msg="The software could not find a solution. Please verify that data was entered correctly.";possib = possibsave.split("|");}
//else {
//if(!Solved){
//msg = "Unable to solve without guessing.";}
}
//else {
//msg = "Able to solve without guessing.";}


timeend = new Date();
b = timeend.getTime();

if(dispparm){Display_Results();alert("Solution found in " + ((b - a) / 1000).toFixed(3) + " seconds.");}
//if(dispparm){Display_Results();alert(msg);}
//}


//} // end guess invalid check

//} // end (!Solved) if

} // end safe stuff if

} // end retrieve if

} //end started else if

if (msg!=""){alert(msg);}
return msg;

}

function dothesafestuff(fresult) {
var stringstore;
var result = fresult;
var storresult;
var holdresult;
var storestring;

storestring = "";

while (storestring != possib.join("|")) {
storestring = possib.join("|");

{result = updatematchedsets(result, 1);}
{result = updateallsingletons ("T");}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

if(!Solved) {
{storresult = updatematchedsets("", 2);}
{result = updateallsingletons ("T");}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

if (!Solved) {
{storresult = updatematchedsets("", 3);}
{result = updateallsingletons ("T");}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

if (!Solved){
{storresult = updatematchedsets("", 4);}
{result = updateallsingletons ("T");}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

if (!Solved) {
{updatematchedsets("", 5);}
{result = updateallsingletons ("T");}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

if (!Solved) {
{updatematchedsets("", 6);}
{updateallsingletons("T");}

if(!Solved){restrictedby();}

stringstore = possib.join("|");
if (stringstore.length == 161){if (!invalidresults()) {Solved = true;}}

}
}
}
}
}
}

return result;
}



function guess() {
// ok we have done all humanly possible - time to start guessing
var i;
var j;
var k;
var tryj;
var totry;
var result;
var stepchangesmade = true;
var tryctr;
var possibhist = new Array;
var idxattmpt = new Array;
var guesscount = 0;
var guessesretracted = 0;

Solved = false;
tryctr = 0;
possibhist[0] = possib.join("|");
idxattmpt[0] = 0;
while((!Solved) && (tryctr >= 0)) {
possib = possibhist[tryctr].split("|");
k = 0;
while ((possib[k].length < 2) && (k < 81)) {k++;}
if (k == 81){Solved = true;} else {
tryj = idxattmpt[tryctr];
totry = possib[k];
result = "Impossible";}

while ((!Solved) && (result != "") && (tryj < totry.length)) {    //try each possible entry in slot k
possib = possibhist[tryctr].split("|");
possib[k] = totry.substr(tryj,1);
guesscount++;
result = dothesafestuff("");
if (invalidresults()){result = "Impossible";} else {result = "";} // just to be sure of status
tryj++;
idxattmpt[tryctr] = tryj;
} // end of while loop thru these possibilities

if (Solved) {result = "";}
else if (result == "") 
{tryctr++;
idxattmpt[tryctr] = 0;
possibhist[tryctr] = possib.join("|");
}
else 
{
tryctr = tryctr - 1;
guessesretracted++;
}  // end of status checking ifs
//if (nextstep > 0) {stepchangesmade = false;}

} // end of while for current guess
if (tryctr<0){result = "No solution possible with info given.";}
return result;

}  // end of function

function invalidresults () {
var result = false;
var i;
var j;
var row;
var column;
var subgrid;
var rthings = new Array(9);
var cthings = new Array(9);
var gthings = new Array(9);

for (j=0;j<81 &&(!result);j++) {
if (possib[j].length == 0){result = true;}
else if (possib[j].length == 1){
row = findRow(j + 1) - 1;
column = findColumn(j + 1) - 1;
subgrid = findSubgrid(j + 1) - 1;
rthings = relements[row].split("|");
cthings = celements[column].split("|");
gthings = gelements[subgrid].split("|");
for (i = 0; (i < 9) && (!result); i++){
if ((parseInt(rthings[i]) != j) && possib[parseInt(rthings[i])] == possib[j]){result = true;}
if ((parseInt(cthings[i]) != j) && possib[parseInt(cthings[i])] == possib[j]){result = true;}
if ((parseInt(gthings[i]) != j) && possib[parseInt(gthings[i])] == possib[j]){result = true;}
} // end for

} // end if
} // end for

return result;
}

function Display_Results() {
var s;
var i;
var j;
var k;
var m;
var n;
var p;
var result;
var empty = false;
var possibstring ="";
var rthings = new Array;
var cthings = new Array;
var gthings = new Array;
var row;
var column;
var subgrid;

if (given.join("").length ==0){empty = true;}

for (i = 1; i < 10; i++) {
s = 'm_r' + i.toString() + '.value = "";';
eval(s);
s = 'm_r' + i.toString() + '.className = "SmallBlue";';
eval(s); 

s = 'm_c' + i.toString() + '.value = "";';
eval(s);
s = 'm_c' + i.toString() + '.className = "SmallerBlue";';
eval(s); 

s = 'm_g' + i.toString() + '.value = "";';
eval(s);
s = 'm_g' + i.toString() + '.className = "SmallerBlue";';
eval(s); 

for (j = 1; j < 10; j++) {
if ((given[(i - 1) * 9 + j - 1].length > 0) || empty){s = 'm_t' + i + j + '.className ="BigBlue";';}
else if (possib[(i - 1) * 9 + j - 1].length <= 1){s = 'm_t' + i + j + '.className = "BigBlack";';}
else {s = 'm_t' + i + j + '.className = "SmallBlack";';}
eval(s);
s = 'm_t' + i + j + '.value = "' + possib[(i - 1) * 9 + j - 1] + '";';
eval(s);
}
}

for(i=0;i<9;i++) {

rthings = relements[i].split("|");
possibstring = "";
result = 0;
for(j=0;j<9;j++){
if(possib[parseInt(rthings[j])].length==1){
if(possibstring.indexOf(possib[parseInt(rthings[j])])<0)
{possibstring = possibstring + possib[parseInt(rthings[j])];} 
else {result = -1;}}}
if(possibstring.length == 9)
{s = 'm_r' + String(i+1) + '.value = "Valid:";';
eval(s);
s = 'm_r' + String(i+1) + '.className = "SmallBlue";';
eval(s);} 
else if(result == -1)
{s = 'm_r' + String(i+1) + '.value = "Invalid:";';
eval(s);
s = 'm_r' + String(i+1) + '.className = "SmallRed";';
eval(s);} 

cthings = celements[i].split("|");
possibstring = "";
result = 0;
for(j=0;j<9;j++){
if(possib[parseInt(cthings[j])].length==1){
if(possibstring.indexOf(possib[parseInt(cthings[j])])<0)
{possibstring = possibstring + possib[parseInt(cthings[j])];} 
else {result = -1;}}}
if(possibstring.length == 9)
{s = 'm_c' + String(i+1) + '.value = "Valid";';
eval(s);
s = 'm_c' + String(i+1) + '.className = "SmallerBlue";';
eval(s);} 
else if(result == -1)
{s = 'm_c' + String(i+1) + '.value = "Invalid";';
eval(s);
s = 'm_c' + String(i+1) + '.className = "SmallerRed";';
eval(s);} 

gthings = gelements[i].split("|");
possibstring = "";
result = 0;
for(j=0;j<9;j++){
if(possib[parseInt(gthings[j])].length==1){
if(possibstring.indexOf(possib[parseInt(gthings[j])])<0)
{possibstring = possibstring + possib[parseInt(gthings[j])];} 
else {result = -1;}}}
if(possibstring.length == 9)
{s = 'm_g' + String(i+1) + '.value = "Valid";';
eval(s);
s = 'm_g' + String(i+1) + '.className = "SmallerBlue";';
eval(s);} 
else if(result == -1)
{s = 'm_g' + String(i+1) + '.value = "Invalid";';
eval(s);
s = 'm_g' + String(i+1) + '.className = "SmallerRed";';
eval(s);} 

} // end for

} // end function


function updateallsingletons (result) {
var givenvalue;
var i;
var j;
var row;
var column;
var subgrid;
var rthings = new Array;
var cthings = new Array;
var gthings = new Array;
var stringstore;
var fresult;
fresult = result;

fresult = "T";
while (fresult == "T") {
fresult = "";
for (i = 0; (i < 81) && (fresult=="" || fresult == "T"); i++) {
//if (possib[i].length < 1) {fresult = "Data entered results in no solution.";} else {
if (possib[i].length == 1) {        // relevant difference to post
givenvalue = possib[i];
row = findRow(i + 1) - 1;
column = findColumn(i + 1) - 1;
subgrid = findSubgrid(i + 1) - 1;
rthings = relements[row].split("|");
cthings = celements[column].split("|");
gthings = gelements[subgrid].split("|");
for (j = 0; j < 9; j++) {
if ((parseInt(rthings[j]) != i) && (possib[parseInt(rthings[j])].indexOf(givenvalue) >= 0) 
                                && (possib[parseInt(rthings[j])] != givenvalue))
									{possib[parseInt(rthings[j])] = possib[parseInt(rthings[j])].split(givenvalue).join("");
                               if (possib[parseInt(rthings[j])].length == 1 && result!="1"){fresult="T";}}
if ((parseInt(cthings[j]) != i) && (possib[parseInt(cthings[j])].indexOf(givenvalue) >= 0)
                                && (possib[parseInt(cthings[j])] != givenvalue))
									{possib[parseInt(cthings[j])] = possib[parseInt(cthings[j])].split(givenvalue).join("");
                               if (possib[parseInt(cthings[j])].length == 1 && result!="1"){fresult="T";}}
if ((parseInt(gthings[j]) != i) && (possib[parseInt(gthings[j])].indexOf(givenvalue) >= 0)
                                && (possib[parseInt(gthings[j])] != givenvalue))
									{possib[parseInt(gthings[j])] = possib[parseInt(gthings[j])].split(givenvalue).join("");
                               if (possib[parseInt(gthings[j])].length == 1 && result!="1"){fresult="T";}}

}     // end of for loop updating
}     // end of if statement, relevant differences
//}     // end of if-else, no error yet
}     // end of for loop - search all items for change

}     // end of while loop - no morec changes found
return fresult;
}     // end of function

function restrictedby () {
var i;
var j;
var k;
var teststring1;
var teststring2;
var teststring3;
var flag1;
var flag2;
var flag3;
var rthings = new Array(9);
var cthings = new Array(9);
var gthings = new Array(9);

for(i=0;i<9;i++){
rthings = relements[i].split("|");
teststring1 = possib[parseInt(rthings[0])] + possib[parseInt(rthings[1])] + possib[parseInt(rthings[2])];
teststring2 = possib[parseInt(rthings[3])] + possib[parseInt(rthings[4])] + possib[parseInt(rthings[5])];
teststring3 = possib[parseInt(rthings[6])] + possib[parseInt(rthings[7])] + possib[parseInt(rthings[8])];
for(j=1;j<10;j++){
if(teststring1.indexOf(j.toString())<0){flag1=1;}else{flag1=0;}
if(teststring2.indexOf(j.toString())<0){flag2=1;}else{flag2=0;}
if(teststring3.indexOf(j.toString())<0){flag3=1;}else{flag3=0;}
if(flag1==1&&flag2==1){gthings = gelements[3*Math.floor(i/3)+2].split("|");for(k=0;k<9;k++){if(findRow(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
if(flag2==1&&flag3==1){gthings = gelements[3*Math.floor(i/3)+0].split("|");for(k=0;k<9;k++){if(findRow(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
if(flag1==1&&flag3==1){gthings = gelements[3*Math.floor(i/3)+1].split("|");for(k=0;k<9;k++){if(findRow(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
}
}

for(i=0;i<9;i++){
cthings = celements[i].split("|");
teststring1 = possib[parseInt(cthings[0])] + possib[parseInt(cthings[1])] + possib[parseInt(cthings[2])];
teststring2 = possib[parseInt(cthings[3])] + possib[parseInt(cthings[4])] + possib[parseInt(cthings[5])];
teststring3 = possib[parseInt(cthings[6])] + possib[parseInt(cthings[7])] + possib[parseInt(cthings[8])];
for(j=1;j<10;j++){
if(teststring1.indexOf(j.toString())<0){flag1=1;}else{flag1=0;}
if(teststring2.indexOf(j.toString())<0){flag2=1;}else{flag2=0;}
if(teststring3.indexOf(j.toString())<0){flag3=1;}else{flag3=0;}
if(flag1==1&&flag2==1){gthings = gelements[Math.floor(i/3)+6].split("|");for(k=0;k<9;k++){if(findColumn(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
if(flag2==1&&flag3==1){gthings = gelements[Math.floor(i/3)+0].split("|");for(k=0;k<9;k++){if(findColumn(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
if(flag1==1&&flag3==1){gthings = gelements[Math.floor(i/3)+3].split("|");for(k=0;k<9;k++){if(findColumn(parseInt(gthings[k])+1)!=i+1){possib[parseInt(gthings[k])]=possib[parseInt(gthings[k])].split(j.toString()).join("");}}}
}
}

for(i=0;i<9;i++){
gthings = gelements[i].split("|");
teststring1 = possib[parseInt(gthings[0])] + possib[parseInt(gthings[1])] + possib[parseInt(gthings[2])];
teststring2 = possib[parseInt(gthings[3])] + possib[parseInt(gthings[4])] + possib[parseInt(gthings[5])];
teststring3 = possib[parseInt(gthings[6])] + possib[parseInt(gthings[7])] + possib[parseInt(gthings[8])];
for(j=1;j<10;j++){
if(teststring1.indexOf(j.toString())<0){flag1=1;}else{flag1=0;}
if(teststring2.indexOf(j.toString())<0){flag2=1;}else{flag2=0;}
if(teststring3.indexOf(j.toString())<0){flag3=1;}else{flag3=0;}
if(flag1==1&&flag2==1){rthings = relements[3*Math.floor(i/3)+2].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(rthings[k])+1)!=i+1){possib[parseInt(rthings[k])]=possib[parseInt(rthings[k])].split(j.toString()).join("");}}}
if(flag2==1&&flag3==1){rthings = relements[3*Math.floor(i/3)+0].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(rthings[k])+1)!=i+1){possib[parseInt(rthings[k])]=possib[parseInt(rthings[k])].split(j.toString()).join("");}}}
if(flag1==1&&flag3==1){rthings = relements[3*Math.floor(i/3)+1].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(rthings[k])+1)!=i+1){possib[parseInt(rthings[k])]=possib[parseInt(rthings[k])].split(j.toString()).join("");}}}
}
}

for(i=0;i<9;i++){
gthings = gelements[i].split("|");
teststring1 = possib[parseInt(gthings[0])] + possib[parseInt(gthings[3])] + possib[parseInt(gthings[6])];
teststring2 = possib[parseInt(gthings[1])] + possib[parseInt(gthings[4])] + possib[parseInt(gthings[7])];
teststring3 = possib[parseInt(gthings[2])] + possib[parseInt(gthings[5])] + possib[parseInt(gthings[8])];
for(j=1;j<10;j++){
if(teststring1.indexOf(j.toString())<0){flag1=1;}else{flag1=0;}
if(teststring2.indexOf(j.toString())<0){flag2=1;}else{flag2=0;}
if(teststring3.indexOf(j.toString())<0){flag3=1;}else{flag3=0;}
if(flag1==1&&flag2==1){cthings = celements[(i%3)*3 + 2].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(cthings[k])+1)!=i+1){possib[parseInt(cthings[k])]=possib[parseInt(cthings[k])].split(j.toString()).join("");}}}
if(flag2==1&&flag3==1){cthings = celements[(i%3)*3 + 0].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(cthings[k])+1)!=i+1){possib[parseInt(cthings[k])]=possib[parseInt(cthings[k])].split(j.toString()).join("");}}}
if(flag1==1&&flag3==1){cthings = celements[(i%3)*3 + 1].split("|");for(k=0;k<9;k++){if(findSubgrid(parseInt(cthings[k])+1)!=i+1){possib[parseInt(cthings[k])]=possib[parseInt(cthings[k])].split(j.toString()).join("");}}}
}
}

}

function updatematchedsets (fresult, sizeit) {
var i;
var i1;
var i2;
var i3;
var i4;
var i5;
var i6;
var i7;
var i8;
var i9;
var subsetcount;
var itop;
var givenvalue = new Array(9);
var givenvaluejoin;
var things = new Array(9);
var temp;
var type;
var index;
var result = "";
var collection;

for (type = 0; type < 3; type++) {
for (index = 0; index < 9; index++) {
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");

if (sizeit == 2) {

for (i1=0;   (i1<8); i1++) {
if(givenvalue[i1].length == 2) {
for (i2=i1+1;(i2<9); i2++) {
if(givenvalue[i2].length == 2) {
collection = givenvalue[i1]; 
collection = addtocollection(collection,givenvalue[i2]); 
if (collection.length == 2){result=clearnonsets(type, index, collection);
							givenvaluejoin = computeselection (type, index);
							givenvalue = givenvaluejoin.split("|");
                            if(result == "T"){success = true;}}
}
}
}
}
}

if (sizeit == 3) {

for (i1=0;   (i1<7); i1++) {
if(givenvalue[i1].length > 1 && givenvalue[i1].length<4) {
for (i2=i1+1;(i2<8); i2++) {
if(givenvalue[i2].length > 1 && givenvalue[i2].length<4) {
for (i3=i2+1;(i3<9); i3++) {
if(givenvalue[i3].length > 1 && givenvalue[i3].length<4) {
collection = givenvalue[i1]; 
collection = addtocollection(collection,givenvalue[i2]); 
collection = addtocollection(collection,givenvalue[i3]);
if (collection.length == 3){result=clearnonsets(type, index, collection);
							givenvaluejoin = computeselection (type, index);
							givenvalue = givenvaluejoin.split("|");
							if (result == "T"){success = true;}}
}
}
}
}
}
}
}

if (sizeit == 4) {

for (i1=0;   (i1<6); i1++) {
if(givenvalue[i1].length > 1 && givenvalue[i1].length<5) {
for (i2=i1+1;(i2<7); i2++) {
if(givenvalue[i2].length > 1 && givenvalue[i2].length<5) {
for (i3=i2+1;(i3<8); i3++) {
if(givenvalue[i3].length > 1 && givenvalue[i3].length<5) {
for (i4=i3+1;(i4<9); i4++) {
if(givenvalue[i4].length > 1 && givenvalue[i4].length<5) {
collection = givenvalue[i1]; 
collection = addtocollection(collection,givenvalue[i2]); 
collection = addtocollection(collection,givenvalue[i3]);
collection = addtocollection(collection,givenvalue[i4]);
if (collection.length == 4){result=clearnonsets(type, index, collection);
							givenvaluejoin = computeselection (type, index);
							givenvalue = givenvaluejoin.split("|");
							if (result == "T"){success = true;}}
}
}
}
}
}
}
}
}
}


if (sizeit == 5) {

for (i1=0;   (i1<5);i1++) {
if(givenvalue[i1].length > 1 && givenvalue[i1].length<6) {
for (i2=i1+1;(i2<6);i2++) {
if(givenvalue[i2].length > 1 && givenvalue[i2].length<6) {
for (i3=i2+1;(i3<7);i3++) {
if(givenvalue[i3].length > 1 && givenvalue[i3].length<6) {
for (i4=i3+1;(i4<8);i4++) {
if(givenvalue[i4].length > 1 && givenvalue[i4].length<6) {
for (i5=i4+1;(i5<9);i5++) {
if(givenvalue[i5].length > 1 && givenvalue[i5].length<6) {
collection = givenvalue[i1]; 
collection = addtocollection(collection,givenvalue[i2]); 
collection = addtocollection(collection,givenvalue[i3]);
collection = addtocollection(collection,givenvalue[i4]);
collection = addtocollection(collection,givenvalue[i5]);
if (collection.length == 5){result=clearnonsets(type, index, collection);
							givenvaluejoin = computeselection (type, index);
							givenvalue = givenvaluejoin.split("|");
							if (result == "T"){success = true;}}
}
}
}
}
}
}
}
}
}
}
}

if (sizeit == 6) {

for (i1=0;   (i1<4);i1++) {
if(givenvalue[i1].length > 1 && givenvalue[i1].length<7) {
for (i2=i1+1;(i2<5);i2++) {
if(givenvalue[i2].length > 1 && givenvalue[i2].length<7) {
for (i3=i2+1;(i3<6);i3++) {
if(givenvalue[i3].length > 1 && givenvalue[i3].length<7) {
for (i4=i3+1;(i4<7);i4++) {
if(givenvalue[i4].length > 1 && givenvalue[i4].length<7) {
for (i5=i4+1;(i5<8);i5++) {
if(givenvalue[i5].length > 1 && givenvalue[i5].length<7) {
for (i6=i5+1;(i6<9);i6++) {
if(givenvalue[i6].length > 1 && givenvalue[i6].length<7) {
collection = givenvalue[i1]; 
collection = addtocollection(collection,givenvalue[i2]); 
collection = addtocollection(collection,givenvalue[i3]);
collection = addtocollection(collection,givenvalue[i4]);
collection = addtocollection(collection,givenvalue[i5]);
collection = addtocollection(collection,givenvalue[i6]);
if (collection.length == 6){result=clearnonsets(type, index, collection);
							givenvaluejoin = computeselection (type, index);
							givenvalue = givenvaluejoin.split("|");
							if (result == "T"){success = true;}}
}
}
}
}
}
}
}
}
}
}
}
}
}

if (sizeit == 1) {
if(type == 0){things = relements[index].split("|");} else
if(type == 1){things = celements[index].split("|");} else
             {things = gelements[index].split("|");}
result = "F";
for (i = 1; i<10 && result == "F"; i++) {
if (countoccurance(i.toString(), givenvaluejoin) == 1) {
for (i1 = 0; i1 < 9 && result == "F"; i1++) {
if(possib[parseInt(things[i1])].indexOf(i.toString()) >= 0) {possib[parseInt(things[i1])]=i.toString();result="";}
} // end for
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");
} // end if
} // end for
result ="";
} // end if

if (sizeit == 2) {

for (i1 = 1; i1 < 9; i1++) {
if (countoccurance(i1.toString(), givenvaluejoin) == 2) {
for (i2 = i1 + 1; i2 < 10; i2++) {
if (countoccurance(i2.toString(), givenvaluejoin) == 2) {
collection = i1.toString() + i2.toString();
if (countsubsetsof(collection, givenvaluejoin) == 2) {
result = clearleavesets(type, index, collection);
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");
}
}
}
}
}

}

if (sizeit == 3) {

for (i1 = 1; i1 < 8; i1++) {
if (countoccurance(i1.toString(), givenvaluejoin) == 3) {
for (i2 = i1 + 1; i2 < 9; i2++) {
if (countoccurance(i2.toString(), givenvaluejoin) == 3) {
for (i3 = i2 + 1; i3 < 10; i3++) {
if (countoccurance(i3.toString(), givenvaluejoin) == 3) {
collection = i1.toString() + i2.toString() + i3.toString();
if (countsubsetsof(collection, givenvaluejoin) == 3) {
result = clearleavesets(type, index, collection);
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");
}
}
}
}
}
}
}

}


if (sizeit == 4) {

for (i1 = 1; i1 < 7; i1++) {
if (countoccurance(i1.toString(), givenvaluejoin) == 4) {
for (i2 = i1 + 1; i2 < 8; i2++) {
if (countoccurance(i2.toString(), givenvaluejoin) == 4) {
for (i3 = i2 + 1; i3 < 9; i3++) {
if (countoccurance(i3.toString(), givenvaluejoin) == 4) {
for (i4 = i3 + 1; i4 < 10; i4++) {
if (countoccurance(i4.toString(), givenvaluejoin) == 4) {
collection = i1.toString() + i2.toString() + i3.toString() + i4.toString();
if (countsubsetsof(collection,givenvaluejoin)==4){
result=clearleavesets(type, index, collection);
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");

}
}
}
}
}
}
}
}
}
}


if (sizeit == 5) {

for (i1 = 1; i1 < 6; i1++) {
if (countoccurance(i1.toString(), givenvaluejoin) == 5) {
for (i2 = i1 + 1; i2 < 7; i2++) {
if (countoccurance(i2.toString(), givenvaluejoin) == 5) {
for (i3 = i2 + 1; i3 < 8; i3++) {
if (countoccurance(i3.toString(), givenvaluejoin) == 5) {
for (i4 = i3 + 1; i4 < 9; i4++) {
if (countoccurance(i4.toString(), givenvaluejoin) == 5) {
for (i5 = i4 + 1; i5 < 10; i5++) {
if (countoccurance(i5.toString(), givenvaluejoin) == 5) {
collection = i1.toString() + i2.toString() + i3.toString() + i4.toString() + i5.toString();
if (countsubsetsof(collection,givenvaluejoin)==5){result=clearleavesets(type, index, collection);
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");

}
}
}
}
}
}
}
}
}
}
}
}

if (sizeit == 6) {

for (i1 = 1; i1 < 5; i1++) {
if (countoccurance(i1.toString(), givenvaluejoin) == 6) {
for (i2 = i1 + 1; i2 < 6; i2++) {
if (countoccurance(i2.toString(), givenvaluejoin) == 6) {
for (i3 = i2 + 1; i3 < 7; i3++) {
if (countoccurance(i3.toString(), givenvaluejoin) == 6) {
for (i4 = i3 + 1; i4 < 8; i4++) {
if (countoccurance(i4.toString(), givenvaluejoin) == 6) {
for (i5 = i4 + 1; i5 < 9; i5++) {
if (countoccurance(i5.toString(), givenvaluejoin) == 6) {
for (i6 = i5 + 1; i6 < 10; i6++) {
if (countoccurance(i6.toString(), givenvaluejoin) == 6) {
collection = i1.toString() + i2.toString() + i3.toString() + i4.toString() + i5.toString() + i6.toString();
if (countsubsetsof(collection,givenvaluejoin)==6){result=clearleavesets(type, index, collection);
givenvaluejoin = computeselection (type, index);
givenvalue = givenvaluejoin.split("|");

}
}
}
}
}
}
}
}
}
}
}
}
}
}




} //next index
} //next type
return result;
}

function addtocollection(incollection,addstring){
var j1;
var collection = incollection;
for (j1 = 0; j1 < addstring.length; j1++)
{if (collection.indexOf(addstring.substr(j1,1)) < 0) {collection = collection + addstring.substr(j1,1);}}

return collection;
}

function clearleavesets(type, index, givenvalue) {
var i;
var j;
var things = new Array;
var result = "";
if(type == 0){things = relements[index].split("|");}
if(type == 1){things = celements[index].split("|");}
if(type == 2){things = gelements[index].split("|");}
for (i = 0; (i<9); i++) {
if (issubset(givenvalue,possib[parseInt(things[i])])){possib[parseInt(things[i])] = givenvalue;} 
}
 
return result;
}

function donttouch(thing,givenvalue) {
var i;
var itop = possib[parseInt(thing)].length;
result = true;
for (i = 0; (i < itop) && result; i++) {
if (givenvalue.indexOf(possib[parseInt(thing)].substr(i,1)) < 0) {result = false;}
}
return result;
}

function countoccurance(istring,allstring) {
var result;
var temparray = new Array;
if (allstring.indexOf(istring) < 0)
{result = 0;}
else
{
temparray = allstring.split(istring);
result = temparray.length - 1;}
return result;
}

function countsubsetsof(instring,allstring) {
var result = 0;
var i;
var j;
var givens = new Array(9);
givens = allstring.split("|");
for (i=0;i<9;i++) {if (issubset(instring,givens[i])){result++;}}
return result;
}

function issubset(subsetstring,testset) {
var j;
var result = true;
for (j=0;j<subsetstring.length && result;j++) {if (testset.indexOf(subsetstring.substr(j,1)) < 0) {result = false;}}
return result;
}

function clearnonsets(type, index, givenvalue) {
var i;
var j;
var things = new Array;
var result = "";
if(type == 0){things = relements[index].split("|");}
if(type == 1){things = celements[index].split("|");}
if(type == 2){things = gelements[index].split("|");}
for (i = 0; (i<9); i++) {
if(donttouch(things[i],givenvalue)) {;} else {
for(j = 0;j < givenvalue.length;j++)
{if (possib[parseInt(things[i])].indexOf(givenvalue.substr(j,1)) >= 0)
{result = "T";
 possib[parseInt(things[i])]=possib[parseInt(things[i])].split(givenvalue.substr(j,1)).join("");}
 if(possib[parseInt(things[i])].length == 0){result = "No solution.";}
}
}
} 
 
return result;
}

function computeselection (type, index) {
var things = new Array(9);
var givenvalue = new Array(9);
var givenvaluejoin;
if(type == 0){things = relements[index].split("|");} else
if(type == 1){things = celements[index].split("|");} else
             {things = gelements[index].split("|");}
for (i = 0; (i < 9); i++) {givenvalue[i] = possib[parseInt(things[i])];}
givenvaluejoin = givenvalue.join("|");
return givenvaluejoin;
}

function check_work() {
	var mygiven = new Array(81);
	var mySolved;
	var mypossib = new Array(81);
	var result;
	var msg;

if (!started) {alert("First enter the 'Given' info and then press 'Start'.");} 
else {

msg = retrieve_possib();
if(msg!=""){alert(msg);} else {
mygiven = given.join("|");
mySolved = Solved;
mypossib = possib.join("|");

Solved = false;

result = solve(false);
if(result=="") {
if (invalidresults()){alert("No solution appears consistent with data entered.")}
else if (possib.join("|").length == 161) {if(possib.join("|") == mypossib){alert("This is a valid solution! Congratulations!");}
else {alert("A solution is possible with this data.");}}
else {alert("This software cannot determine if there is a solution with the data given.");}
}
given = mygiven.split("|");
Solved = mySolved;
possib = mypossib.split("|");
Display_Results();

}
}
}

function back_up(quiet) {
var msg = "";

if (!started) {if(!quiet){alert("First enter the 'Given' info and then press 'Start'.");}} 
else {

msg = retrieve_possib();
if (msg=="") {
if(possib.join("").length > 0 && possib.join("").length != 729) {
possibbackup[backupctr] = possib.join("&");
givenbackup[backupctr] = given.join("&");
backupctr++;
Display_Results();
if(!quiet){alert("Your work is backed up - level " + backupctr + ".");}
}
else
{alert("Nothing to back up.");}
}
else {if(!quiet){alert(msg);}}
}
} //end function

function restore() {
var displevel;

if (backupctr >= 1) {
displevel = backupctr;
if (confirm("Restore data? Your current data would be lost.")) {
backupctr--;
possib = possibbackup[backupctr].split("&");
given = givenbackup[backupctr].split("&");
Display_Results();
alert("Your work is restored to level " + displevel + ". Level " + displevel + " backup has been removed.");
}
}
else {alert("No backup available for restore.");}
}

function quitfornow() {
	var savedata;
	var cookiename = "sudokudata";
	var i;
	var datatosave = "";
	var rtnow;
	var expiry;
	var time;
	var year;
	rtnow = new Date();
	time = rtnow.getTime();
	expiry = rtnow.toUTCString();
	year = String(rtnow.getFullYear());
	expiry = expiry.substr(0,expiry.indexOf(year)) + String(parseInt(year) + 1) + expiry.substr(expiry.indexOf(year) + 4);
	savedata = confirm("Save your work?");	
	if (savedata) {
		back_up(true);
		for (i=0;i<backupctr;i++) {
		datatosave = datatosave + possibbackup[i] + '@';
		datatosave = datatosave + givenbackup[i] + '~';
		}
		datatosave = datatosave.substr(0,datatosave.length - 1);
		document.cookie = 'sudokudata=' + datatosave + '; expires=' + expiry + '; path=/';
	}
}


function readCookie() {
	var nameEQ = "sudokudata=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function generate (puzlevel) {
var thepuz = "";
var mycount;
var mylevel;

mylevel = puzlevel;
if(mylevel==1){mycount = epuzcount.substr(1,6);}
//if(mylevel==2){mycount = mpuzcount.substr(1,6);}
if(mylevel==3){mycount = hpuzcount.substr(1,6);}
//if(mylevel==4){mycount = vpuzcount.substr(1,6);}
while(mycount.substr(0,1) == "0"){mycount=mycount.substr(1,mycount.length - 1);}
thepuz = String(Math.floor(Math.random() * parseInt(mycount)) + 1);
while (thepuz.length<6){thepuz = "0" + thepuz;}
if (mylevel==1){thepuz="e"+ thepuz; rexec("javascript/puzs/easy/" + thepuz + ".js","GTPUZ");}
//if (mylevel==2){thepuz="m"+ thepuz; rexec("javascript/puzs/medium/" + thepuz + ".js","GTPUZ");}
if (mylevel==3){thepuz="h"+ thepuz; rexec("javascript/puzs/hard/" + thepuz + ".js","GTPUZ");}
//if (mylevel==4){thepuz="v"+ thepuz; rexec("javascript/puzs/veryhard/" + thepuz + ".js","GTPUZ");}
newpuz = thepuz.toUpperCase();
}

function changelevel(){
var puzlevel = 0;
try{
if(m_rad1.checked){puzlevel=1;}
//if(m_rad2.checked){puzlevel=2;}
if(m_rad3.checked){puzlevel=3;}
//if(m_rad4.checked){puzlevel=4;}
}
catch(e) {;}
if(puzlevel!=0){generate(puzlevel);}
}

function selectpuzzle(){
var usethis;
var thepuz;
var strgiven;
var i;

//usethis = m_gtpuz.src.toUpperCase();

//i = usethis.indexOf(".JS") - 7;
//thepuz = usethis.substr(i,7);
//if(newpuz.length == 7 && newpuz != currentpuz && ((newpuz >= "E000001" && newpuz <= epuzcount.toUpperCase()) || (newpuz >= "M000001" && newpuz <= mpuzcount.toUpperCase()) ||(newpuz >= "H000001" && newpuz <= hpuzcount.toUpperCase()) || (newpuz >= "V000001" && newpuz <= vpuzcount.toUpperCase()))){
if(newpuz.length == 7 && newpuz != currentpuz && ((newpuz >= "E000001" && newpuz <= epuzcount.toUpperCase()) || (newpuz >= "H000001" && newpuz <= hpuzcount.toUpperCase()) )){
if (confirm("Do you want to start a new puzzle?")){
m_t100.value = newpuz;
//m_t100.value = thepuz.toUpperCase();
strgiven = Puzzle;
possib = strgiven.split("|");
given = strgiven.split("|");
started = true;
goneonestep = false;
Display_Results();
back_up(true);
Solved = false;
currentpuz = newpuz;
if(newpuz.substr(0,1)=="E"){m_puzlabel.value = "Easy Puzzle#: "; m_puzlabel.className = "Easy";}
//else if(newpuz.substr(0,1)=="M"){m_puzlabel.value = "Medium Puzzle#: "; m_puzlabel.className = "Medium";}
else if(newpuz.substr(0,1)=="H"){m_puzlabel.value = "Hard Puzzle#: "; m_puzlabel.className = "Hard";}
//else if(newpuz.substr(0,1)=="V"){m_puzlabel.value = "Very Hard Puzzle#: "; m_puzlabel.className = "VeryHard";}
else {m_puzlabel.value = "Puzzle#: ";m_puzlabel.className = "Easy";}
//thepuz.toUpperCase();
m_rad1.checked = false;
//m_rad2.checked = false;
m_rad3.checked = false;
//m_rad4.checked = false;
}
}
else {alert("Please select your difficulty level.");}
}

function puzzlenumberchanged() {
var usethis;
var strgiven;
usethis = m_t100.value;
usethis = usethis.toUpperCase();
if(usethis.length == 7 && usethis != currentpuz && ((usethis >= "E000001" && usethis <= epuzcount.toUpperCase()) || (usethis >= "M000001" && usethis <= mpuzcount.toUpperCase()) ||(usethis >= "H000001" && usethis <= hpuzcount.toUpperCase()) || (usethis >= "V000001" && usethis <= vpuzcount.toUpperCase()))){
usethis = usethis.toLowerCase();
newpuz = usethis.toUpperCase();
if(usethis.substr(0,1)=="e"){rexec("javascript/puzs/easy/" + usethis + ".js","GTPUZ");}
if(usethis.substr(0,1)=="m"){rexec("javascript/puzs/medium/" + usethis + ".js","GTPUZ");}
if(usethis.substr(0,1)=="h"){rexec("javascript/puzs/hard/" + usethis + ".js","GTPUZ");}
if(usethis.substr(0,1)=="v"){rexec("javascript/puzs/veryhard/" + usethis + ".js","GTPUZ");}
}
}

function rexec(cmd,myid){
var old;
var head;
var script;

head = document.getElementsByTagName('head').item(0);
old = document.getElementById(myid);
head.removeChild(old);
script = document.createElement('script');
script.src = cmd;
script.language='JavaScript';
script.type = 'text/javascript';
script.id = myid;
head.appendChild(script);
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}