var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all);
function init() {
	if (!(document.getElementById || document.all || document.layers)) return;
	document.getElementById("NonogramsTable").onselectstart = new Function ("return false")
	document.onmouseup = u;

	for (i=0;i<document.images.length;i++)	{
		if (document.images[i].className == 'l'){
			document.images[i].onmousedown = c;
			//document.images[i].onmouseup = function() {return false};
			//document.images[i].onmouseup = u;
			document.images[i].onmouseover = ov;
			//document.images[i].onmouseout = ou;
			document.images[i].ondragstart = function() {return false};
		}
	}
	timer();
}
var down = 0;
var lastAns = 'y';
function swap(el){
	if (el.className == 'done'){
		el.className = 'none'
	}else{
		el.className = 'done'
	}
}
function ou(e){
        if (!isIE && window.Event)       {
                sender = e.target;
        }else{
                var e = window.event;
                sender = e.srcElement;
        }
	if (sender.name){
                var ar = new Array();
                ar = sender.name.split('_');
                i = ar[1]*1;
                j = ar[2]*1;
		document.getElementById('th_0_'+(j+1)).style.backgroundColor = '#FFFFFF';
		document.getElementById('th_'+(i+1)+'_0').style.backgroundColor = '#FFFFFF';
	}


}
function ov(e){
	if (!isIE && window.Event)	{
		rtightclick = (e.which == 3 || (e.modifiers & Event.CONTROL_MASK) || (e.modifiers & Event.SHIFT_MASK));
		sender = e.target;
	}else{
		rtightclick = (window.event.button == 2 || window.event.ctrlKey || window.event.shiftKey);
		var e = window.event;
		sender = e.srcElement;
	}
	if (sender.className == 'l'){
  	if (down){
		  setImg(sender, lastAns);
	  }
	  /*
        if (sender.name){
                var ar = new Array();
                ar = sender.name.split('_');
                i = ar[1]*1;
                j = ar[2]*1;
                document.getElementById('th_0_'+(j+1)).style.backgroundColor = '#EEFFEE';
                document.getElementById('th_'+(i+1)+'_0').style.backgroundColor = '#EEFFEE';
        }
    */
	  /*
	  else{
    	if (sender.name){
    		var ar = new Array();
    		ar = sender.name.split('_');
    		i = ar[1];
    		j = ar[2];
    		w = document.answerForm.w.value;
    		h = document.answerForm.h.value;
    		for (var n = 1; n <= w; n++){
    		  if (n != j+1)
    		    document.getElementById('th0'+n).className = 't0'+((n-1)%5==0 ? '1' : '0');
    		}
  		  for (var m = 1; m <= h; m++){
    		  if (m != i+1)
    		    document.getElementById('th'+m+'0').className = 't'+((m-1)%5==0 ? '1' : '0')+'0';
  		  }
  		  var ii = i*1+1;
  		  var jj = j*1+1;
  		  
  		  document.getElementById('th0'+jj).className = 't0'+(j%5==0 ? '1' : '0')+'_on';
  		  document.getElementById('th'+ii+'0').className = 't'+(i%5==0 ? '1' : '0')+'0'+'_on';
    	}
  	}
  	*/
	}

	return false;
}
function u(e){
	down = 0;
	return false;
}
function getstatus(s){
	var ar = new Array();
	ar = s.split('/');
	return ar[ar.length-1].charAt(0);
}
function getdirection(s){
	var ar = new Array();
	ar = s.split('_');
	return ar[0];
}
function getnextsrc(status, reverse){
	if (reverse){
		switch (status){
			case 'y': return RightClick?'x':'n';
			case 'n': return RightClick?'x':'y';
			case 'x': return RightClick?'n':'x';
		}
	}else{
		switch (status){
			case 'y': return RightClick?'n':'x';
			case 'n': return RightClick?'y':'y';
			case 'x': return RightClick?'y':'n';
		}
	}
}
function setImg(sender, ans){
	if (sender.name){
		var ar = new Array();
		ar = sender.name.split('_');
		i = ar[1];
		j = ar[2];
		w = document.answerForm.w.value;
		h = document.answerForm.h.value;
		sender.src = ans + '.gif';
		var s = document.answerForm.ansH.value;
		n = i * (1 * w) + (j * 1);
		l = s.length;
		s = s.substr(0,n) + ans + s.substr(n + 1, l);
		document.answerForm.ansH.value = s;
	}
}
function c(e){
	
	down = 1;
	var rtightclick = 0;
	if (!isIE && window.Event)	{
		rtightclick = (e.which == 3 || (e.modifiers & Event.CONTROL_MASK) || (e.modifiers & Event.SHIFT_MASK));
		sender = e.target;
	}else{
		rtightclick = (window.event.button == 2 || window.event.ctrlKey || window.event.shiftKey);
		var e = window.event;
		sender = e.srcElement;
	}
	ans = getnextsrc(getstatus(sender.src), rtightclick);
	lastAns = ans;
	setImg(sender, ans);
	return false;
}


a1 = new Image();
a1.src = 'x.gif';
a2 = new Image();
a2.src = 'y.gif';
a3 = new Image();
a3.src = 'n.gif';

