// JavaScript Document

function copy_str() {
	
			var text = null;
			w = window;
			if (w.document.getSelection) {
							text = (w.document.getSelection());
			} else if (w.getSelection) {
					text = (w.getSelection());
			} else if (w.document.selection) {
					var selection = w.document.selection;
					text = selection.createRange().text;
			} else {
					return false;
			}
			if (text != '')	{
				if ( text.length < 150 ) {
					return text;
				}
				else {
					alert('Вы выделили слишком длинный текст. Текст не должен содержать более 150 символов');
				}
			}
			else {
				//alert('Вы не выделили текст');
			}
}

document.onkeyup = function press_key(event){ 

			if ( typeof event == "undefined" ) event = window.event;
            var k = event.keyCode;
			var ctrl=event.ctrlKey;
			if (k==13 && ctrl) {
				
				var element = document.getElementById('field_2');
				if (element.value == '') {
				
					var str = copy_str();
					
					if (str != null) {
						
						if ( confirm('Вы уверены что хотите отправить этот текст: \n\n\"'+str+'\"') ) {
		
								var location_url = window.location;
								ajax_send('POST', '/service/send_error/send_error.php', str, location_url);
						}
					}
				}//if (element.value == '') 
			}
}

function ajax_send(method, handler, var_1, var_2) {
    
	var xmlHttp = false; 
	try 
	{ 
		 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) 
	{ 
		try 
		{ 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (e2) 
		{ 
			xmlHttp = false; 
		} 
	} 
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){ 
		xmlHttp = new XMLHttpRequest(); 
	}
	
	xmlHttp.open(method, handler, true);
	//xmlHttp.onreadystatechange = result;
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send('str='+var_1+'&url='+var_2+'');
	alert('Текст отправлен. Спасибо');
	
	

}