function open_window(src, name, width, height) {
    if (width<700) width=700;
    window.open(src,name,"width="+width+",height="+height+",resizable,scrollbars=yes");
}

function send_email_show() {
	document.getElementById('send').style.display='block'
}

function send_email(to) {
	document.getElementById('send').style.display='none';
	ajax_call('/send_link?email='+escape(to)+'&url='+escape(location.href), 'GET');
}

function ajax_init_object() {
 			
 			var A;
 			
 			var msxmlhttp = new Array(
				'Msxml2.XMLHTTP.5.0',
				'Msxml2.XMLHTTP.4.0',
				'Msxml2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP');
			for (var i = 0; i < msxmlhttp.length; i++) {
				try {
					A = new ActiveXObject(msxmlhttp[i]);
				} catch (e) {
					A = null;
				}
			}
 			
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				alert("Could not create connection object.");
			return A;
}

function parse_form(form) {
	var str = '';
	if (form)
		for (i=0; i<form.elements.length; i++) {
		  if (form.elements[i].tagName == 'INPUT' && form.elements[i].type == 'checkbox' && !form.elements[i].checked) continue; 
		  if (!form.elements[i].disabled && (form.elements[i].tagName == 'INPUT' || form.elements[i].tagName == 'SELECT' || form.elements[i].tagName == 'TEXTAREA')) 
		    str += '&'+form.elements[i].name+'='+encodeURIComponent(form.elements[i].value);
		}
		 
	return str;
}

function ajax_send_form(form, callback_function) {
			var uri;
			var post_data;
			var target_id;
			
			sajax_request_type = form.method.toUpperCase();
			uri = form.action;
				
				if (uri.indexOf("?") == -1) 
					uri += "?rsrnd=" + new Date().getTime();
				else
					uri += "&rsrnd=" + new Date().getTime();
					
			if (sajax_request_type == "GET") {
				uri += parse_form(form);
				post_data = null;
			} 
			else if (sajax_request_type == "POST") {
				post_data = parse_form(form);
			}
			else {
				alert("Illegal request type: " + sajax_request_type);
			}
	
			ajax_call(uri, sajax_request_type, callback_function, post_data);
}

function ajax_call(uri, sajax_request_type, callback_function, post_data) {
	var x;
	
	x = ajax_init_object();
	
	if (x == null) {
		alert("NULL sajax object for user agent:\n" + navigator.userAgent);
		return false;
	} else {
		x.open(sajax_request_type, uri, true);
		// window.open(uri);
					
		if (sajax_request_type == "POST") {
			x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
			x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
	
		x.onreadystatechange = function() {
			if (x.readyState != 4) 
				return;
			if (callback_function) {
				if ( typeof callback_function == "function" ) {
					callback_function(x.responseText);
				} else {
					try { eval(callback_function+'(\''+x.responseText+'\')'); } catch(e) {}
				}
			}
		}
	}
	
	x.send(post_data);
	delete x;
	return true;
}

var tmo = false;
var oldp = '';

function search_person() {
    if (tmo) clearTimeout(tmo);
    tmp = setTimeout("show_person_ex()", 500);
}

function show_person_ex() {
    var p = document.getElementById('person_search');
    if (!p) return;
    if (!p.value) return;
    if (oldp == p.value) return;
    oldp = p.value;
    x_get_person(p.value,person_cb);
}

function person_cb(msg) {
  var p = document.getElementById('person_list');
  if (!p) return;
  p.innerHTML = msg;
  p.parentNode.style.display = 'block';
}

pi=0;
function openddm(idm){
   if(pi!=0) closeddmenu(pi);
   openddmenu(idm);
   pi=idm;
   }
function openddmenu(idm){document.getElementById(idm).style.display = "block";}
function closeddmenu(idm){document.getElementById(idm).style.display = "none";}

var id_cat = 0
function get_archive(idcat, rubric, star, year, month, fdate) {
  var p = document.getElementById('archive'+idcat);
  if (!p) return;
  p.style.height = '80px';
  p.innerHTML = '<h3>Загрузка ...</h3>';
  if (!fdate) fdate = '';
  id_cat = idcat;
  ajax_call('/get_archive?idcat='+idcat+'&rubric='+rubric+'&star='+star+'&year='+year+'&month='+month+'&fdate='+fdate+'&r='+new Date().getTime(), 'GET', get_archive_cb);
}

function get_archive_cb(msg) {
  var p = document.getElementById('archive'+id_cat);
  if (!p) return;
  p.innerHTML = msg;
}

function show_ca() {
/*	document.getElementById('cmm').style.display='block';*/
    document.getElementById('cmm').style.visibility='visible';
}

function hide_ca() {
/*	document.getElementById('cmm').style.display='none';*/
    document.getElementById('cmm').style.visibility='hidden';
}
function press ( mark, unmark ) {
	mark.style.borderTopWidth='1px'; 
	mark.style.borderRightWidth='1px';
	mark.style.borderLeftWidth='1px';
	mark.style.borderBottomWidth='0px';
	mark.style.backgroundColor='RGB(240,240,240)';

	unmark.style.borderTopWidth='0px'; 
	unmark.style.borderRightWidth='0px';
	unmark.style.borderLeftWidth='0px';
	unmark.style.borderBottomWidth='1px';
	unmark.style.borderBottomColor='RGB(216, 216, 216)';
	unmark.style.backgroundColor='#fff';
}

function flashlentaelementresize(id, height, idtext) {
	if ( height > 0) { id.style.width = '247px'; idtext.style.visibility = 'visible';} 
	else { id.style.width = '58px'; idtext.style.visibility = 'hidden'; }
	return false;	
}

