window.onload = function() {
	for(i=0; i<=3; i++) {
		if(document.getElementById('target'+i))
			colorCorrect(document.getElementById('target'+i));
	}	
}
document.onkeypress = function(e) {
		with (this) {
	    	var pressed=0;
		    var we = null;
		    if (window.event) we = window.event;
		    else if (parent && parent.event) we = parent.event;
		    if (we) {
		      // IE & Opera
		      pressed = we.keyCode==10 ||  // IE
		        (we.keyCode == 13 && we.ctrlKey); // Opera 
		    } else if (e) {
		      // NN
		      pressed = 
		        (e.which==10 && e.modifiers==2) || // NN4
		        (e.keyCode==0 && e.charCode==106 && e.ctrlKey) ||
		        (e.keyCode==13 && e.ctrlKey) // Mozilla
		    } 
		    if (pressed) {;
		      doSend();
		      return false;
		    }
  		} 
	};
	function doSend() {
		var t = window.location.toString();
		t = t.replace(/\&/, "__and__");
		var selection = null;
	    if (document.getSelection) {
	      text = document.getSelection();
	    } else {
	      selection = document.selection;
	    }
    
		if (selection) {
	    	  var r = selection.createRange(); 
	    	  if (!r) return;
		      text = "" + r.text;
	    }
	    if (text == null) return;
	    var errorText = "text="+text+"&url="+t;
	    if(navigator.userAgent.indexOf('Opera') != -1) {
	    	var frame = document.getElementById('opera_send');
	    	frame.src = "/index.php?mail_error=1&" + errorText;
	    	return;
	    }
		if(document.all)
			var ajax = new ActiveXObject("Msxml2.XMLHTTP");
		else
			var ajax = new XMLHttpRequest();

		ajax.open("POST", "/index.php?mail_error=1", false);
		/*ajax.onreadystatechange = function() {alert('2');
			if(ajax.readyState == 4)
				alert("Письмо отправлено. Спасибо за сотрудничество"); 
		}*/
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(errorText);	    
	}
function printElement(elementId) {
	if(!document.all ||  (navigator.userAgent.indexOf('Opera') != -1)) {
		window.print();
		return;
	}
	var content = document.getElementById(elementId).innerHTML;
	var total = document.body.innerHTML;
	document.body.innerHTML = content;
	window.onafterprint = function() { document.body.innerHTML = total; }
	window.print();
}
function colorCorrect(obj) {
	if(!obj.hasChildNodes)
		return;
	var children = obj.childNodes;
	var i=0;
	for(i=0; i<children.length; i++) {
		if(children[i].style)
			children[i].style.backgroundColor = (i % 2 == 0 ? '#F1F1F1' : '#FAFAFA');
			//children[i].className = (i % 2 == 0 ? 'row01' : 'row02');

	}
}
function ret(total) {
	document.body.innerHTML = total;
}
