

function checkme()
{	

	//alert('ok');
	
			var w_c=1;
			var w_s=0;
			var m_m='<FONT COLOR=red><B>T&uacute; hevur gj&oslash;rt feilir, sum eru v&iacute;stir viš rey&eth;um!</B></FONT>';
			var m_w='<FONT COLOR=purple><B>Okkurt er ikki heilt r&aelig;tt &iacute; * av puntunum!</B></FONT>';
			var m_i='<FONT COLOR=blue><B>Alt er &iacute; lagi, enn eru * eftir!</B></FONT>';
			var m_d='<B>Her er ein Kakuro at loysa. G&oacute;&eth;a eydnu!</B>';

	//alert('ok1');
	if (!document.getElementById) 
		return true;

		//alert('ok2');
	// --------------------------
	// initializing variables
	// --------------------------
	// current block array
	curr_block_array=new Array(9);
	//alert(document.getElementById('rows'));
	//alert(document.getElementById('columns'));	
	var rows = document.getElementById('rows').value;
	var columns= document.getElementById('columns').value;
	var curr_block_defected = false;
	var game_full = true;
	var game_error = false;
//	document.getElementById('message').innerHTML='checking...1';	
	//alert(rows);
	//alert(columns);
	
	m=new Array(rows);
	for (x=0; x<rows; x++) {
		m[x]=new Array(columns);
	}
	for (x=0; x<rows; x++) {
		for (y=0; y<columns;y++){
			m[x][y]=0;
		}
	}

	// ---------------------
	// looping rows
	// ---------------------

	//alert('ok');

	// checking lines
	for (x=0;x<rows ;x++ )
	{
		// checking line no. x
		y=0;
		while (y<columns)
		{
			// checking cell no. x,y

			// if cell is row diagonal sum, check the block associated with it 
			e=document.getElementById('DRow'+x+'_'+y);
			if (e!=null)
			{
				//alert('row diag = '+e.value);
				// clearning the curr_block_array
				for (q=0;q<9 ;q++ )
				{
					curr_block_array[q]=0;
				}

				//alert('1');

				curr_block_sum = parseInt(e.innerHTML);
				//alert('current block sum='+curr_block_sum);
				curr_block_defected = false;
				curr_block_full=true;
				y++;
				curr_block_first_index=y;
				//alert('2');
				// building the block
				e=document.getElementById('N'+x+'_'+y);
				while (e!=null && y<columns)
				{
					// if current cell is empty - update the game_full and curr_block_full variables
					if (e.value=='')
					{
						curr_block_full = false;
						game_full = false;
					}
					// current cell not empty, handle it
					else
					{
						//alert('curr number = '+e.value);
						curr_block_array[(e.value-1)]++;
						if (curr_block_array[(e.value-1)]>1)
						{
							// the same digit apperred twice, block is defected
							curr_block_defected=true;
						    	//Xalert('beacuse of duplicated numbers, the block is marked defected');
						}
					}
					y++;
					//alert('y='+y);
					//alert('columns='+columns);
					e=document.getElementById('N'+x+'_'+y);
				}
				curr_block_last_index=y;
				y--;
				
				//alert('after checking duplicated number');

				// if the block is not defected, checking if block sum is larger or smaller the should be
				if (!curr_block_defected)
				{
					//	alert('block is not defected beacuse of duplicated numbers, checking sums for defected');
					curr_sum=0;
					for (q=0;q<9 ;q++ )
					{
						curr_sum=curr_sum+(q+1)*curr_block_array[q];
						////alert('curr sum='+curr_sum);
						////alert('curr_block_array[q]='+curr_block_array[q]);
					}
					////alert('curr_sum='+curr_sum);
					////alert('curr_block_sum='+curr_block_sum);

					if (curr_block_full)
					{
						if (curr_sum!=curr_block_sum)
						{
							curr_block_defected=true;
							//Xalert('beacuse of sum not equal and cell full, the block is marked defected');
						}
					}
					else
					{
						if (curr_sum>=curr_block_sum)
						{
							curr_block_defected=true;
							//Xalert('beacuse of sum override, the block is marked defected');
						}
					}
				}
				////alert('finished checking both duplication and sum problems, checking for results (curr_block_defected='+curr_block_defected+')');
				////alert('fff');
				////alert('after final check1...');
				if (curr_block_defected)
				{
					game_error = true;
//					//alert('XXXblock is  defected');
					for (tty=curr_block_first_index;tty<curr_block_last_index;tty++)
					{
//									e=document.getElementById('c'+x+'_'+tty);
//									e.className=e.className.charAt(0)+'1';
//									e=document.getElementById('N'+x+'_'+tty);
//									e.className=e.className.charAt(0)+'1';
									m[x][tty]++;
//									alert('m['+x+']['+tty+']='+m[x][tty]);									
					}
				}
				else
				{
					for (tty=curr_block_first_index;tty<curr_block_last_index;tty++)
					{
//									e=document.getElementById('c'+x+'_'+tty);
//									e.className=e.className.charAt(0)+'0';
//									e=document.getElementById('N'+x+'_'+tty);
//									e.className=e.className.charAt(0)+'0';
					}
				}
				
			}
			y++;
		}
	}

//------------------------------------------------------------------------------------
	// ---------------------
	// looping columns
	// ---------------------
	//alert('ok');

	// checking lines
	for (y=0;y<columns ;y++ )
	{
		// checking line no. x
		x=0;
		while (x<rows)
		{
			// checking cell no. x,y

			// if cell is row diagonal sum, check the block associated with it 
			e=document.getElementById('DColumn'+x+'_'+y);
			if (e!=null)
			{
				//alert('row diag = '+e.value);
				// clearning the curr_block_array
				for (q=0;q<9 ;q++ )
				{
					curr_block_array[q]=0;
				}

				//alert('1');

				curr_block_sum = parseInt(e.innerHTML);
				curr_block_defected = false;
				curr_block_full=true;
				x++;
				curr_block_first_index=x;
				//alert('2');
				// building the block
				e=document.getElementById('N'+x+'_'+y);
				while (e!=null && x<rows)
				{
					// if current cell is empty - update the game_full and curr_block_full variables
					if (e.value=='')
					{
						curr_block_full = false;
						game_full = false;
					}
					// current cell not empty, handle it
					else
					{
						//alert('curr number = '+e.value);
						curr_block_array[(e.value-1)]++;
						if (curr_block_array[(e.value-1)]>1)
						{
							// the same digit apperred twice, block is defected
							curr_block_defected=true;
							//Xalert('beacuse of duplicated numbers, the block is marked defected');
						}
					}
					x++;
					//alert('y='+y);
					//alert('columns='+columns);
					e=document.getElementById('N'+x+'_'+y);
				}
				curr_block_last_index=x;
				x--;
				
				//alert('after checking duplicated number');

				// if the block is not defected, checking if block sum is larger or smaller the should be
				if (!curr_block_defected)
				{
					//alert('block is not defected beacuse of duplicated numbers, checking sums for defected');
					curr_sum=0;
					for (q=0;q<9 ;q++ )
					{
						curr_sum=curr_sum+(q+1)*curr_block_array[q];
						//alert('curr sum='+curr_sum);
						//alert('curr_block_array[q]='+curr_block_array[q]);
					}
					//alert('curr_sum='+curr_sum);
					//alert('curr_block_sum='+curr_block_sum);

					if (curr_block_full)
					{
						if (curr_sum!=curr_block_sum)
						{
							curr_block_defected=true;
							//Xalert('beacuse of sum not equal and cell full, the block is marked defected');
						}
					}
					else
					{
					    //Xalert('here : curr_sum='+curr_sum+' curr_block sum='+curr_block_sum);
						if (curr_sum>=curr_block_sum)
						{
							curr_block_defected=true;
							//Xalert('beacuse of sum override, the block is marked defected');
						}
					}
				}
				//alert('finished checking both duplication and sum problems, checking for results (curr_block_defected='+curr_block_defected+')');
				//alert('fff');
				//alert('after final check1...');
				if (curr_block_defected)
				{
//					alert('XXXblock is  defected');
					game_error = true;
					for (ttx=curr_block_first_index;ttx<curr_block_last_index;ttx++)
					{
//									e=document.getElementById('c'+ttx+'_'+y);
//									e.className=e.className.charAt(0)+'1';
//									e=document.getElementById('N'+ttx+'_'+y);
//									e.className=e.className.charAt(0)+'1';
									m[ttx][y]++;
//									alert('m['+x+']['+tty+']='+m[x][tty]);
					}
				}
				else
				{
					for (ttx=curr_block_first_index;ttx<curr_block_last_index;ttx++)
					{
//									e=document.getElementById('c'+ttx+'_'+y);
//									e.className=e.className.charAt(0)+'0';
//									e=document.getElementById('N'+ttx+'_'+y);
//									e.className=e.className.charAt(0)+'0';
					}
				}
				
			}
			x++;
		}
	}

//------------------------------------------------------------------------------------
	for (x=0; x<rows; x++) {
		for (y=0; y<columns;y++){
//			if (m[x][y]>0)
			{
				
									e=document.getElementById('c'+x+'_'+y);
									if (e!=null)
									{
										e.className=e.className.charAt(0)+m[x][y];
									}
//									e=document.getElementById('N'+x+'_'+y);
//									e.className=e.className.charAt(0)+m[x][y];
			}
		}
	}
//------------------------------------------------------------------------------------
	if (!game_error && game_full)
	{
		g='<FONT COLOR=red><B>TILLUKKU Loysnin hj&aacute; t&aelig;r er r&oslash;tt!</B></FONT>';
	}
	else if (!game_error)
	{
		g='<FONT COLOR=#000080><B>Alt er &iacute; lagi higartil, halt bara &aacute;fram...</B></FONT>';	
	}
	else
	{
		g='<FONT COLOR=800000><B>T&iacute;nir feilir eru v&iacute;stir</B></FONT>';
	}
	document.getElementById('message').innerHTML=g;	
	return false;
}

function restartgame()
{
	// --------------------------
	// initializing variables
	// --------------------------
	// current block array
	var m_c='<FONT COLOR=green><B>Lat okkum byrja umaftur!</B></FONT>';
	var rows = document.getElementById('rows').value;
	var columns= document.getElementById('columns').value;
	
	document.getElementById('message').innerHTML='kanni...1';	

	if (!document.getElementById) 
		return true;

	for (x=0; x<rows; x++) {
		for (y=0; y<columns; y++) {

			e=document.getElementById('N'+x+'_'+y);

			if (e!=null)
			{
				e.value='';
				//XXXX i dont know the next commands meaning.....
//				e.className=e.className.charAt(0)+'0';
//				e=document.getElementById('c'+x+y);
//				e.className=e.className.charAt(0)+'0';
			}
			
		}
	}


	checkme();
	document.getElementById('message').innerHTML=m_c;
	
	return false;
}



function tell_friend()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("tellafriend.htm","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=500"); 
}

function contact_us()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("contactus.htm","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=450"); 
}
function block_list()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("blocklist.html","_blank","STATUS=NO,resizable=1,scrollbars=1,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,TOP=40,LEFT=20,WIDTH=410,HEIGHT=500"); 
}
function learn()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("learn.html","_blank","STATUS=NO,resizable=1,scrollbars=1,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,TOP=40,LEFT=20,WIDTH=700,HEIGHT=600"); 
}
function combinations()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("http://www.kevinpluck.net/kakuro/KakuroCombinations.html","_blank","STATUS=NO,resizable=1,scrollbars=1,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,TOP=40,LEFT=20,WIDTH=900,HEIGHT=500"); 
}
function guestbook()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("guestbook.php","_blank","STATUS=NO,resizable=1,scrollbars=1,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,TOP=40,LEFT=20,WIDTH=900,HEIGHT=500"); 
}

function fixspace(x)
{
	//alert('dddd');
	var y=document.getElementById(x).value;
	//alert("!"+y+"!");
	if(y==" ")
	{
		//alert('space');
		document.getElementById(x).value="";
	}
	else
	{
		//alert(y);
	}
}


