(function(){
    if (window.XMLHttpRequest) return;
    var o = null, s,
    a = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
    for (var i=0,j=a.length; i<j; i++) {
        s=a[i];
        try {
            if (o=new ActiveXObject(s))  break;
        }
        catch(e){};
    }
    window.XMLHttpRequest = o ? function(){return new ActiveXObject(s)} : null;
    o = null;
})();

// JavaScript Document
Array.prototype.find = function(arr){
	for(i=0;i<this.length;i++)
		if( this[i][0] == arr[0] && 
			this[i][1] == arr[1]
		)
			return true;
	return false;
}
Array.prototype.Print = function(){
	var out = "";
	for(i=0;i<this.length;i++)
		out += "(" + this[i] + "),"
	return out;
}
Array.prototype.Rotate = function(length, height){ 
	var o = new Array( height )
	
	for(i=0; i<height; i++){
		o[i] = new Array()
		for(j=0; j<length; j++)
			o[i][j] = this[j][i]
	}
	return o;
}

function LoadURL(action,url,postbody,delegateReturn, isXML)
{
    var xmlhttp = new XMLHttpRequest();

    if ( xmlhttp )
    {
        xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState==4){
                if (xmlhttp.status==200){
                    if(delegateReturn != null)
                    {
                        if(isXML){    delegateReturn( xmlhttp.responseXML );}
                        else{        delegateReturn( xmlhttp.responseText );}
                    }
                }else{
                    alert("Error: " + xmlhttp.status + "\n\nURL: "+URL);
                }
                xmlhttp = null;
            }
        };
        try{
            xmlhttp.open(action,url, true);
            xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
            xmlhttp.send(postbody);
        }catch(e){
            alert("xmlhttp error: \n" + e.message);
        }
    }else{
        alert("Your browser does not support XMLHTTP.");
    }
}

var colorArr = new Array("#000000","#FF3333","#33FF33","#3333FF","#FFFF33","#33FFFF","#FF33FF");

function byid(id){ 
	return document.getElementById(id); 
}
function getBgColor(int){ 
	return colorArr[int]; 
}
function fromColor(color){ 
	for(i=0; i<6; i++)
		if( colorArr[i+1] == color.toUpperCase() )
			return i+1
	return 0;
}
function sortNumber(a,b){
	return a[0] - b[0]
}
function validate(input){
	if( ! String(input.value).match(/(^[a-zA-Z??????0-9 ]*$)/) ){
		alert("unsupported character")
		byid("navn").value = String(input.value).match(/(^[a-zA-Z??????0-9 ]*)/gi)[0]
	}
}

function Timer(){
	this.times = new Array()
//methods	
	this.find = function( str ){
		for(i=0;i<this.times.length;i++)
			if( str == this.times[i][0] )
				return i;
	}
	this.createTimer = function( strName ){
		if( !this.find(strName) )
			this.times[ this.times.length ] = new Array(strName,0 /* Temp and Result */, null, /* Temp Date */ false /* Active */)
	}
	this.start = function( strName ){
		
		i = this.find(strName)
		this.times[i][2] = new Date();
		this.times[i][3] = true;
	}
	this.stop = function( strName ){
		i = this.find(strName)
		
		var sTime = this.times[i][2]
		var eTime = new Date();
		var elapsed = (eTime.getTime() - sTime.getTime() );
		
		this.times[i][1] = elapsed
		this.times[i][2] = null
		this.times[i][3] = false
	}
	this.print = function(){
		out = "<table>"
		if( this.times.length > 0 )
			for(i=0;i<this.times.length;i++)
				if( !this.times[i][3] )
					out += "<tr><td>" + this.times[i][0] + "<td>" + this.times[i][1] + " ms"
		return out
	}
}

function arraycopy(Q,W){
	for(a=0;a<Q.length;a++)
		for(b=0;b<Q[a].length;b++)
			Q[a][b] = W[a][b]
	return Q;
}

function game(){
	this.rows = 18;
	this.cols = 24;
	this.difs = 6;
	this.tmpColor = "";
	this.list = new Array();
	this.gameArr = new Array();
	this.calcs = 0;
	this.point = 0;
	this.key = 0;
	this.timer = new Timer()
	this.UndoHistory = new Array();
	this.UndoPoints = new Array();
//methods
	// timed functions
	this.newgame 	  = function(){
		//---------------------------------
		this.timer.start("newgame();")
		//---------------------------------
		//fit the game array to match the size of the game
		for(i=0;i<this.rows;i++)
			this.gameArr[i] = new Array(this.cols);
		
		//fill the game array with random blobks
		for(a=0;a<this.rows;a++)
			for(b=0;b<this.cols;b++)
				this.gameArr[a][b] = Math.ceil(Math.random()*this.difs)
		
		this.point = 0;
		byid("point").innerHTML = "(potential: " + Math.ceil( this.findPotential() ) + " points)";
		
		//---------------------------------
		this.timer.stop("newgame();")
		//---------------------------------
		aiOut = "<table><tr height='25px'>"
		for(i=1;i<=this.difs;i++)
			aiOut += "<td width='25px' class='s1' style='background-color:"+getBgColor( i )+";'><input type='checkbox' id='AI_"+i+"'></td>"
			
		byid("AI_col").innerHTML = aiOut;
		//----------------------------------------
		this.UndoHistory = new Array();
		this.UndoPoints = new Array();
		this.init();
		this.updateScore();
	}
	this.Undo		  = function(){
		var lastPoint = this.UndoPoints.pop();
		var lastGame = this.UndoHistory.pop();
		
		for(f=0 ; f<this.rows ; f++)
			this.gameArr[f] = lastGame[f].slice(0)
		
		this.point -= lastPoint;
		//this.UndoPoints = 0;
		byid("point").innerHTML = new NumberFormat(this.point).toFormatted() + " point"
		
		if( this.UndoHistory.length <= 0 )
			byid("UndoButton").disabled = true;
			
		this.init();
	}
	this.init 		  = function(){
		//---------------------------------
		this.timer.start("init();")
		//---------------------------------
		blockcounter = new Array(0,0,0,0,0,0,0,0)
		
		out = String();
		out += 	"<button onclick='Game.decreaseDif();'> Easier </button>&nbsp;" + this.difs + '/6&nbsp;' + 
				"<button onclick='Game.increaseDif();'> Harder </button>&nbsp;&nbsp;&nbsp;" + 
				"<button onclick='Game.newgame();Game.init()'> New Game </button>&nbsp;&nbsp;&nbsp;" +
				"<button onclick='Game.decreaseSize();'> Smaller </button>&nbsp;" + this.cols + '/40&nbsp;'+
				"<button onclick='Game.increaseSize();'> Larger </button>"
		out += "<table id='gametable' cellspacing=0 cellpadding=0 width='"+(this.cols*27)+"px' height='"+(this.rows*27)+"px'>";
				
		for(a=0;a<this.rows;a++){
			out += "<tr height='25px'>"
			for(b=0;b<this.cols;b++){
				blockcounter[ this.gameArr[a][b] ] += 1
				
				out += "<td width='25px' "+
							" id='t_" + a + "_" + b + "'" + 
							" style='background-color:"+getBgColor( this.gameArr[a][b] )+";'" +
							" title='" + a + "," + b + "'" +
							" onMouseOver='Game.findOthers(this);' "+
							" onMouseOut='Game.release(this);' "+
							" onClick='Game.Click(this);'" +
							" class='s"+ this.gameArr[a][b] +"'>" +
						//"<img" + 
							
							//" src='ball" + this.gameArr[a][b] + ".gif'>" +
						"</td>"
			}
			out += "</tr>"
		}
		out += 	"</table>"
		byid('game').innerHTML = out;
		//----------------------------------------
		bOut = "<table>"
		for(i=1;i<=this.difs;i++)
			bOut += "<tr height='25px'><td width='25px' class='s1' style='background-color:"+getBgColor( i )+";'></td><td>"+ blockcounter[i] +"</td>"
		byid("blockcnt").innerHTML = bOut;
		
		//---------------------------------
		this.timer.stop("init();")
		//---------------------------------
		if( this.isFinished() )
			alert("Game over, no more blocks to remove\n\nRemember to save your highscore?")
	}
	this.findOthers   = function(ob){
		//---------------------------------
		this.timer.start("findOthers();")
		//---------------------------------
		this.list = new Array();
		t = ob.title.split(",")
		
		if( this.gameArr[t[0]][t[1]] != 0 ){
			this.list.push( new Array(Number(t[0]),Number(t[1]) ) )
			this.calcs = 1
			this.crawlRecurse( Number(t[0]) , Number(t[1]) )
			byid("hover").style.display = "block"
		}else{
			this.calcs = 0
			byid("hover").style.display = "none"
		}
		//---------------------------------
		this.timer.stop("findOthers();")
		//---------------------------------
		this.locate()
	}
	this.organize 	  = function(){
		//---------------------------------
		this.timer.start("organize();")
		//---------------------------------
		this.list.sort(sortNumber);

		for( i=0; i<this.list.length ; i++){
			t = this.list[i]
			x = Number(t[0])
			y = Number(t[1])
			
			while( x > 0 ){
				R = this.gameArr[x-1][y]
				this.gameArr[x-1][y] = this.gameArr[x][y]
				this.gameArr[x][y] = R
				//byid("t_" + x + "_" + y).innerHTML = i
				//byid("t_" + (x-1) + "_" + y).style.backgroundColor = getBgColor(this.gameArr[x-1][y])
				x--
			}
		}
		
		// BUCKET SORT
		//alert(this.gameArr[0].length +' x '+this.gameArr.length )

		var T = this.gameArr.Rotate(this.rows, this.cols)
		var T_empty = new Array()
		var T_full = new Array()
		var t1 = t2 = 0
	
		//alert(T[0].length +' x '+T.length )
		
		for( p=0 ; p<T.length ; p++){
			cnt = 0
			for(j=0 ; j<T[0].length ; j++)
				if( T[p][j]==0 )
					cnt++

			if( cnt == this.rows ){
				//alert( "ping" ) 
				T_empty[t1++] = T[p]
			}else{
				T_full[t2++] = T[p]
			}
		}
		

		this.gameArr = T_full.concat(T_empty).Rotate(this.cols, this.rows);
		
		// BUBBLE SORT
		/*for( p=0 ; p< Math.pow(this.cols,2) ; p++){
			i = p%this.cols
			
			cnt = 0
			for(j=0;j<this.rows;j++){
				if(this.gameArr[j][i]==0)
					cnt++
			}
			
			if( cnt == this.rows ){
				col = i;
				while(col < this.cols-1){
					for(f=0;f<this.rows;f++){
						R = this.gameArr[f][col]
						this.gameArr[f][col] = this.gameArr[f][col+1]
						this.gameArr[f][col+1] = R
						
						//byid("t_" + f + "_" + col).style.backgroundColor = getBgColor(this.gameArr[x][y])
						//byid("t_" + f + "_" + col+1).style.backgroundColor = getBgColor(this.gameArr[x][y+1])
					}
					col++
				}
			}
		}*/	
		//---------------------------------
		this.timer.stop("organize();")
		//---------------------------------
		this.dispTimer();
		this.init();
	}
	this.locate 	  = function(){
		//---------------------------------
		this.timer.start("locate();")
		//---------------------------------
		if( this.calcs >= 2 ){
			for(i=0;i<this.list.length;i++){
				t = this.list[i]
				byid("t_" + t[0] + "_" + t[1]).style.backgroundColor = "#FFFFFF"
				/*byid("t_" + t[0] + "_" + t[1]).innerHTML = "<img" + 
															" title='" + t[0] + "," + t[1] + "'" +
															" onMouseOver='Game.findOthers(this);' "+
															" onMouseOut='Game.release(this);' "+
															" onClick='Game.Click(this);'" +
															" src='white.gif'>"*/
			}
			byid("hover").innerHTML = "&nbsp;&nbsp;" + new NumberFormat(this.calcs * 1.5 * this.calcs).toFormatted() + " points&nbsp;&nbsp;"
			//byid("point2").innerHTML = ((this.calcs * 1.5) * this.calcs) + " point"
		}else{
			//byid("point2").innerHTML = ""
			byid("hover").style.display = "none"
		}
		//---------------------------------
		this.timer.stop("locate();")
		//---------------------------------
	}
	this.updateScore  = function(){
		//---------------------------------
		this.timer.start("updateScore();")
		//---------------------------------
		
		var arr = this.getStats()
		
		LoadURL(
			"GET",
			"score.asp?getdata=" + Math.ceil(Math.random()*872634597234) + "&cols="+arr[2]+"&diff="+arr[1],
			null,
			function(text){ byid("highscore").innerHTML = text }, 
			false
		);
		
		LoadURL(
			"GET",
			"score.asp?getrecords=" + Math.ceil(Math.random()*872634597234),
			null,
			function(text){ byid("records").innerHTML = text }, 
			false
		);
		
		LoadURL(
			"GET",
			"score.asp?getkey=" + Math.ceil(Math.random()*872634597234),
			null,
			function(key){ Game.key = key }, 
			false
		);
		
		//---------------------------------
		this.timer.stop("updateScore();")
		//---------------------------------
	}
	this.AI 		  = function(){
		//---------------------------------
		this.timer.start("AI();")
		//---------------------------------
		//-----------------------------------------------------------
		// This procedure will find the best block to remove...
		// ie. the block that yields the most benefit
		var copy = new Array()
		for(f=0 ; f<this.rows ; f++)
			copy[f] = this.gameArr[f].slice(0)
		
		var best = null;

		var Blocks = this.findBlocks();
		var potential = this.findPotential();
		var br = false
		var point = 0
		var b=0;
		
		//for(b=0; b<Blocks.length; b++) // linear search
		while(!br)
		{
			for(i=0 ; i<Blocks[b].length ; i++){
				t = Blocks[b][i]
				this.gameArr[ t[0] ][ t[1] ] = 0;
			}
			//temp point
			point = Blocks[b].length * 1.5 * Blocks[b].length
			
			//organize before finding new potential
			this.list = Blocks[b]
			this.quickOrgan()
			
			//find best block to remove
			if( this.findPotential() >= (potential-point) ){
				best = Blocks[b]
				potential = this.findPotential()
				br = true
			}
			b++
			for(f=0 ; f<this.rows ; f++)
				this.gameArr[f] = copy[f].slice(0)
		}
		var Undo = new Array()
		for(f=0 ; f<this.rows ; f++){
			this.gameArr[f] = copy[f].slice(0)
			Undo[f] = this.gameArr[f].slice(0)
		}
		this.UndoHistory.push(Undo);
		
		//Standard onClick maneuvre ----
		for(i=0 ; i<best.length ; i++){
			t = best[i]
			this.gameArr[ t[0] ][ t[1] ] = 0;
		}
		var Points = (best.length * 1.5 * best.length);
		this.point += Points
		this.UndoPoints.push( Points );
		
		byid("point").innerHTML = new NumberFormat(this.point).toFormatted() + " point"
		this.list = best
		byid("UndoButton").disabled = false;
		this.organize()

		//---------------------------------
		this.timer.stop("AI();")
		//---------------------------------
		this.init()
		if( byid("autoAI").checked )
			setTimeout("Game.AI();",1500)
	}
	this.removeLargest = function(){
		largest = this.findLargest();
		if( largest.length > 0 ){
			var Undo = new Array()
			for(f=0 ; f<this.rows ; f++)
				Undo[f] = this.gameArr[f].slice(0)
			this.UndoHistory.push(Undo);
			
			for(i=0 ; i<largest.length ; i++){
				t = largest[i]
				this.gameArr[ t[0] ][ t[1] ] = 0;
			}
			var Points = (largest.length * 1.5 * largest.length);
			this.point += Points
			this.UndoPoints.push( Points );
			
			byid("point").innerHTML = new NumberFormat(this.point).toFormatted() + " point"
			this.list = largest
			byid("UndoButton").disabled = false;
			this.organize();
			//largest = this.findLargest();
		}
	}
	this.findLargest  = function(){
		//---------------------------------
		this.timer.start("findLargest();")
		//---------------------------------
		var found = new Array();
		var largest = new Array();
		var AIs = ""
		
		for(i=1;i<=this.difs;i++)
			if( byid("AI_"+i).checked )
				AIs += "," + i + ","
		
		if(AIs.length==0)
			AIs = ",1,2,3,4,5,6,"
		
		for(a=this.rows-1;a>=0;a--)
			for(b=this.cols-1;b>=0;b--)
				if( this.gameArr[a][b]!=0 )
					if( String(AIs).match(this.gameArr[a][b]) )
						if( !found.find(new Array(a,b)) ){
							this.list = new Array()
							this.list.push( new Array(a,b) )
							this.calcs = 1
							this.crawlRecurse( a , b )
							
							if( this.calcs >= 2 ){
								found = found.concat(this.list)
								if( this.list.length > largest.length )
									largest = this.list
							}
						}
		//---------------------------------
		this.timer.stop("findLargest();")
		//---------------------------------
		return largest
	}
	this.findBlocks   = function(){
		//---------------------------------
		this.timer.start("findLargest();")
		//---------------------------------
		var found = new Array();
		
		for(a=this.rows-1;a>=0;a--)
			for(b=this.cols-1;b>=0;b--)
				if( this.gameArr[a][b]!=0 )
					if( !found.find(new Array(a,b)) ){
						this.list = new Array()
						this.list.push( new Array(a,b) )
						this.calcs = 1
						this.crawlRecurse( a , b )
						
						if( this.calcs >= 2 ){
							found.push( this.list )
						}
					}
		//---------------------------------
		this.timer.stop("findLargest();")
		//---------------------------------
		return found
	}
	this.isFinished   = function(){
		//---------------------------------
		this.timer.start("isFinished();")
		//---------------------------------
		var found = new Array();
		var largest = new Array();
		
		
		for(a=this.rows-1;a>=0;a--)
			for(b=this.cols-1;b>=0;b--)
				if( this.gameArr[a][b]!=0 )
					if( !found.find(new Array(a,b)) ){
						this.list = new Array()
						this.list.push( new Array(a,b) )
						this.calcs = 1
						this.crawlRecurse( a , b )
						
						if( this.calcs >= 2 ){
		//---------------------------------
		this.timer.stop("isFinished();")
		//---------------------------------

							return false
						}
					}
		//---------------------------------
		this.timer.stop("isFinished();")
		//---------------------------------
		return true
	}
//-----	
	this.debug 		  = function(str){
		byid("debug2").innerHTML += "<br>" + str
	}
	this.quickOrgan	  = function(){
		this.list.sort(sortNumber);
		for( i=0; i<this.list.length ; i++){
			t = this.list[i]
			x = Number(t[0])
			y = Number(t[1])
			
			while( x > 0 ){
				R = this.gameArr[x-1][y]
				this.gameArr[x-1][y] = this.gameArr[x][y]
				this.gameArr[x][y] = R
				x--
			}
		}
		// BUCKET SORT
		var T = this.gameArr.Rotate(this.rows, this.cols)
		var T_empty = new Array()
		var T_full = new Array()
		var t1 = t2 = 0
		for( p=0 ; p<T.length ; p++){
			cnt = 0
			for(j=0 ; j<T[0].length ; j++)
				if( T[p][j]==0 )
					cnt++

			if( cnt == this.rows ){
				//alert( "ping" ) 
				T_empty[t1++] = T[p]
			}else{
				T_full[t2++] = T[p]
			}
		}
		this.gameArr = T_full.concat(T_empty).Rotate(this.cols, this.rows);
	}
	this.findPotential= function(){
		var uberlist = new Array();
		var potential = 0;
		
		for(a=0;a<this.rows;a++)
			for(b=0;b<this.cols;b++)
				if( ! uberlist.find(new Array(a,b)) ){
					this.list = new Array()
					this.list.push( new Array(a,b) )
					this.calcs = 1
					this.crawlRecurse( a , b )
					
					if( this.calcs >= 2 ){
						uberlist = uberlist.concat(this.list)
						potential += Math.pow(this.calcs,2) * 1.5
					}
				}
				
		return potential;
	}
	this.dispTimer    = function(){
		byid("debug").innerHTML = this.timer.print();
	}
	this.getStats 	  = function(){
		leftovers = 0;
		for(i=0;i<this.rows;i++)
			for(j=0;j<this.cols;j++)
				if( this.gameArr[i][j] != 0)
					leftovers++
		
		var arr = new Array(this.point,
							this.difs,
							this.cols,
							leftovers);
		return arr;
	}
	this.increaseDif  = function(){
		if(this.difs < 6)
			this.difs++
		this.newgame();
	}
	this.setDif 	  = function(dif){
		this.difs = dif;
	}
	this.decreaseDif  = function(){
		if(this.difs > 2)
			this.difs--
		this.newgame()
	}
	this.increaseSize = function(){
		if(this.cols < 40){
			this.cols += 4
			this.rows += 3
		}
		this.newgame();
	}
	this.decreaseSize = function(){
		if(this.cols > 16){
			this.cols -= 4
			this.rows -= 3
		}
		this.newgame()
	}
	this.setSize 	  = function(size){
		if ( String("iso,16,20,24,28,32,36,40").indexOf( String(size) ) ){
			this.cols = Number(size);
			this.rows = (this.cols/4)*3
			//alert( this.cols + ',' + this.rows )
		}
	}
	this.Click 		  = function(ob){
		if( this.calcs >= 2 ){
			//copy to undo history...
			var Undo = new Array()
			for(f=0 ; f<this.rows ; f++)
				Undo[f] = this.gameArr[f].slice(0)
			this.UndoHistory.push(Undo);
			
			for(i=0;i<this.list.length;i++){
				t = this.list[i]
				this.gameArr[ t[0] ][ t[1] ] = 0;
				byid("t_" + t[0] + "_" + t[1]).style.backgroundColor = getBgColor(0);
			}
			var Points = this.calcs * 1.5 * this.calcs
			this.point += Points
			
			this.UndoPoints.push( Points );
			
			byid("point").innerHTML = new NumberFormat(this.point).toFormatted() + " point"
			byid("UndoButton").disabled = false;
			this.organize()
		}
	}
	this.release 	  = function(){
		byid("hover").style.display = "none"
		for(i=0;i<this.list.length;i++){
			t = this.list[i]
			byid("t_" + t[0] + "_" + t[1]).style.backgroundColor = getBgColor( this.gameArr[ t[0] ][ t[1] ]	)	
			/*byid("t_" + t[0] + "_" + t[1]).innerHTML = "<img" + 
														" title='" + t[0] + "," + t[1] + "'" +
														" onMouseOver='Game.findOthers(this);' "+
														" onMouseOut='Game.release(this);' "+
														" onClick='Game.Click(this);'" +
														" src='ball" + this.gameArr[ t[0] ][ t[1] ] + ".gif'>"*/
		}
	}
	this.fromXY 	  = function(x,y){
		return this.gameArr[x][y]
	}
	this.crawlRecurse = function( x, y ){
		if( (x+1) < this.rows )
			if( this.fromXY(x,y) == this.fromXY(x+1,y) && !this.list.find( new Array( (x+1),y) ) ){
				this.calcs++;
				this.list.push( new Array( Number(x+1),Number(y) ) )
				this.crawlRecurse(x+1,y)
			}
		if( (x-1) >= 0 )
			if( this.fromXY(x,y) == this.fromXY(x-1,y) && !this.list.find( new Array((x-1) ,y) ) ){
				this.calcs++;
				this.list.push( new Array( Number(x-1) ,Number(y) ) )
				this.crawlRecurse(x-1,y)
			}
		if( (y+1) < this.cols )
			if( this.fromXY(x,y) == this.fromXY(x,y+1) && !this.list.find( new Array(x,(y+1)) ) ){
				this.calcs++;
				this.list.push( new Array( Number(x),Number(y+1)) )
				this.crawlRecurse(x,y+1)
			}	
		if( (y-1) >= 0 )
			if( this.fromXY(x,y) == this.fromXY(x,y-1) && !this.list.find( new Array(x,(y-1)) ) ){
				this.calcs++;
				this.list.push( new Array(Number(x),Number(y-1)) )
				this.crawlRecurse(x,y-1)
			}
		else
			return
	}
	this.getKey 	  = function(){
		return this.key;
	}
}

var Game = new game();
	Game.timer.createTimer("isFinished();")
	Game.timer.createTimer("findLargest();")
	Game.timer.createTimer("AI();")
	Game.timer.createTimer("newgame();")
	Game.timer.createTimer("init();")
	Game.timer.createTimer("findOthers();")
	Game.timer.createTimer("organize();")
	Game.timer.createTimer("locate();")
	Game.timer.createTimer("updateScore();")
	
function mySubmit(){
	var res = Game.getStats();
	var url = "score.asp?name=" + byid("navn").value + "&point=" + Math.ceil(res[0]) + "&diff="  + res[1] + "&cols="  + res[2] +"&left="  + res[3] + "&key=" + Game.getKey();

	LoadURL(
		"GET",
		url,
		null,
		function(text){ 
			byid("highscore").innerHTML = text
			Game.newgame();
		}, 
		false
	);
}
document.onmousemove = function(event){
	if(!event) var event = window.event;
	
	byid("hover").style.top = (event.clientY-20) + 'px'
	byid("hover").style.left = (event.clientX+10) + 'px'
	
	Game.dispTimer();
}

function UndoHandler(event){
	if(!event) var event = window.event;
	
	if(event.ctrlKey && event.keyCode == 90){
		if( Game.UndoPoints.length > 0 )
			Game.Undo();
	}
}