
var i, j, k;
var duplicate;
duplicate=false;
var arraymat = new Array(6);
var image;
for (i=0;i<6;i++)
	arraymat[i]=new Array(6);
for (i=0;i<6;i++)
	for (j=0;j<6;j++)
		arraymat[i][j]=0;
		



function incrementarraymatcell(i,j){

arraymat[i][j]=arraymat[i][j]+1;
if (arraymat[i][j]>2)
	arraymat[i][j]=0;
	switch (arraymat[i][j]) {
		case 0:
			return "http://paladn.com/js/images/transparent50.gif";
		case 1:
			return "http://paladn.com/js/images/chick50.jpg";
		case 2:
			return "http://paladn.com/js/images/fox50.jpg"
		default:
			return "http://paladn.com/js/images/transparent50.gif";
	}
}	
function isblank(s){
	for(var i=0;i<s.length;i++){
		var c =s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true
}




function clearboard(){
	for (i=0;i<6;i++){
		for (j=0;j<6;j++){			
			arraymat[i][j]=0;
			MM_swapImage('m'+i+j,'','http://paladn.com/js/images/transparent50.gif',1);
			}
	}		
}


function testwork(){
var result;
var sumf, sumc;
// count the foxes
sumf=0;
result=false;


if (isblank(document.forms(0).elements(0).value) ){	
	alert('You forgot to fill in your name! \nPlease do so and re-submit!');
	result=false;
	return result;
}	
if (duplicate==true){
	alert('Nice try!  Only one to a customer!');
	result=false;
	return result;	
}
else{
	duplicate=true;
	result=true;
	var f='';
	var c='';

	for (i=1;i<6;i++){
		for (j=1;j<6;j++){
			if (arraymat[i][j]==2)
		   		f=f+'('+i.toString()+','+j.toString()+')';
			if (arraymat[i][j]==1)
				c=c+'('+i.toString()+','+j.toString()+')';
		}
	}
	form.foxes_positions.value = f;
	form.chicks_positions.value = c;
	return result;
}	

}

function checkwork(form){

var result;
var sumf, sumc;
// count the foxes
sumf=0;
result=false;
	
	
for (i=1;i<6;i++){
	for (j=1;j<6;j++){
		if (arraymat[i][j]==2)
			sumf=sumf+1;
	}
}			
if (sumf !=5){
	alert('You must have exactly 5 foxes!' );
	result=false;
	return result;
}
// count the chicks
sumc=0;
for (i=1;i<6;i++){
	for (j=1;j<6;j++){
		if (arraymat[i][j]==1)
			sumc=sumc+1;
	}
}			
if (sumc !=3){
	alert('You must have exactly 3 chicks!');
	result=false;
	return result;
}
// check the ranks
for (i=1;i<6;i++){
	for (j=1;j<6;j++){
		if (arraymat[i][j]==1){
			for (k=1;k<6;k++){
				if (arraymat[i][k]==2){
					alert('Fox and chick on the same rank.');
					result=false;
					return result;
				}
			}	
		}			
	}
}			
// check the files
for (i=1;i<6;i++){
	for (j=1;j<6;j++){
		if (arraymat[i][j]==1){
			for (k=1;k<6;k++){
				if (arraymat[k][j]==2){
					alert('Fox and chick on the same file');
					result=false;
					return result;
				}
			}	
		}			
	}
}	

// check upper diagonals	

if (((arraymat[1][1]==1) || (arraymat[2][2]==1)|| (arraymat[3][3]==1)|| (arraymat[4][4]==1) ||(arraymat[5][5]==1)) &&
((arraymat[1][1]==2) || (arraymat[2][2]==2)|| (arraymat[3][3]==2)|| (arraymat[4][4]==2) ||(arraymat[5][5]==2))){
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][2]==1) || (arraymat[2][3]==1)|| (arraymat[3][4]==1) ||(arraymat[4][5]==1)) &&
((arraymat[1][2]==2) || (arraymat[2][3]==2)|| (arraymat[3][4]==2) ||(arraymat[4][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][2]==1) || (arraymat[2][1]==1)) &&
((arraymat[1][2]==2) || (arraymat[2][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][3]==1) || (arraymat[2][2]==1) || (arraymat[3][1]==1)) &&
((arraymat[1][3]==2) || (arraymat[2][2]==2) || (arraymat[3][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][3]==1) || (arraymat[2][4]==1) || (arraymat[3][5]==1)) &&
((arraymat[1][3]==2) || (arraymat[2][4]==2) || (arraymat[3][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][4]==1) || (arraymat[2][3]==1) || (arraymat[3][2]==1)|| (arraymat[4][1]==1)) &&
((arraymat[1][4]==2) || (arraymat[2][3]==2) || (arraymat[3][2]==2)|| (arraymat[4][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][4]==1) || (arraymat[2][5]==1)) &&
((arraymat[1][4]==2) || (arraymat[2][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[1][5]==1) || (arraymat[2][4]==1)|| (arraymat[3][3]==1)|| (arraymat[4][2]==1) ||(arraymat[5][1]==1)) &&
((arraymat[1][5]==2) || (arraymat[2][4]==2)|| (arraymat[3][3]==2)|| (arraymat[4][2]==2) ||(arraymat[5][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}

// check lower diagonals
if (((arraymat[5][4]==1) || (arraymat[4][3]==1) || (arraymat[3][2]==1)|| (arraymat[2][1]==1)) &&
((arraymat[5][4]==2) || (arraymat[4][3]==2) || (arraymat[3][2]==2)|| (arraymat[2][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[5][4]==1) || (arraymat[4][5]==1)) &&
((arraymat[5][4]==2) || (arraymat[4][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[5][2]==1) || (arraymat[4][3]==1) || (arraymat[3][4]==1)|| (arraymat[2][5]==1)) &&
((arraymat[5][2]==2) || (arraymat[4][3]==2) || (arraymat[3][4]==2)|| (arraymat[2][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[5][2]==1) || (arraymat[4][1]==1)) &&
((arraymat[5][2]==2) || (arraymat[4][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[5][3]==1) || (arraymat[4][2]==1) || (arraymat[3][1]==1)) &&
((arraymat[5][3]==2) || (arraymat[4][2]==2) || (arraymat[3][1]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (((arraymat[5][3]==1) || (arraymat[4][4]==1) || (arraymat[3][5]==1)) &&
((arraymat[5][3]==2) || (arraymat[4][4]==2) || (arraymat[3][5]==2))){	
	alert("There's some tasty juicy chick filet \nif foxes move in a diagonal way!");
	result=false;
	return result;
}
if (isblank(document.forms(0).elements(0).value) ){	
	alert('You forgot to fill in your name! \nPlease do so and re-submit!');
	result=false;
	return result;
}	
if (duplicate==true){
	alert('Nice try!  Only one to a customer!');
	result=false;
	return result;	
}
else{
	duplicate=true;
	result=true;
	var f='';
	var c='';

	for (i=1;i<6;i++){
		for (j=1;j<6;j++){
			if (arraymat[i][j]==2)
		   		f=f+'('+i.toString()+','+j.toString()+')';
			if (arraymat[i][j]==1)
				c=c+'('+i.toString()+','+j.toString()+')';
		}
	}
	form.foxes_positions.value = f;
	form.chicks_positions.value = c;
	
	return result;
}	
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapimgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}



