function cmfAjaxLog(text) 
{
	$('#idAjaxLog').html('' + text + '');
}

function cmfAjaxCommand(url) 
{
	$('#idAjaxCommand2').html('<iframe src="'+ url +'" width="100%" height="1000px" scrolling="yes" frameborder="0"></iframe>');
	$('#idAjaxCommand1').show();
}


function cmfRedirect(url) 
{
	document.location = url;
}

function cmfReload() 
{
	cmfRedirect(document.location);

}

function cmfInnerHTML(id, value) 
{
	cmfGetId(id).innerHTML = value;
}

function cmfGetId(id) 
{
	return document.getElementById(id);
}

function cmfSetValue(id, value) 
{
	if(cmfGetId(id)) 
		cmfGetId(id).value = value;
}

function cmfDeleteChildTag(line, tag) 
{
	while(line.tagName.toUpperCase()!=tag)
		line = line.parentNode;
	line.parentNode.removeChild(line);
}

function cmfDeleteChildTag(line) 
{
	line.parentNode.removeChild(line);
}

function cmfGetChildTag(line, tag) 
{
	while(line.tagName.toUpperCase()!=tag)
		line = line.parentNode;
	return line;
}

function cmfCheckboxPrefix(form, prefix, value) 
{
	var elements = form.elements;
	for(i=0; i<elements.length; i++)
		if(elements[i].id.indexOf(prefix)!=-1) 
			elements[i].checked = value;
}

function cmfOpenWindow(url, id, width, height) 
{
	//width = screen.width;
	//height = screen.height;

	window_top =20+ (screen.height - height) / 2-100;
	window_left =20+ (screen.width - width) / 2-100;
	window.open(url + '&height=' + (height-100), id, 'width='+(width+20)+', height='+(height+20)+', top='+window_top+', left='+window_left+', toolbar=0, statusbar=0, location=0, scrollbars=no, resizable=0');
}

function cmfVisibleHidden(id) 
{
	var id = cmfGetId(id);
	if(id.style.display=='none') 
	{
		id.style.display='';
		return true;
	} 
	else 
	{
		id.style.display='none';
		return false;
	}
}

function cmfHidden(id) 
{
	if(cmfGetId(id)) 
		cmfGetId(id).style.display='none';
}

function cmfVisible(id) 
{
	if(cmfGetId(id)) 
		cmfGetId(id).style.display='';
}

function cmfTextFocus(id, value) 
{
	if(id.value==value) 
		id.value = '';
}

function cmfTextOnblur(id, value) 
{
	if(id.value=='') 
		id.value = value;
}

function cmfAjaxSendForm(form, url) 
{
	return cmfAjaxSend(url, { form: form });
}

function cmfAjaxSend(url, value, func, cache) 
{    
	var req = new JsHttpRequest();
    req.caching = cache? true :false;
    req.onreadystatechange = function() 
    {
        if (req.readyState == 4) 
        {
        	//cmfCreateMessage("Минуточку...");
        	
            cmfAjaxLog(req.responseText);

            if(func) 
            	func(req);
            if(req.responseJS && req.responseJS.js) 
            	$.globalEval(req.responseJS.js);
            	
            
        }
        
        
    }
    req.open(null, url, true);
    req.send(value);
    return false;
}

function cmfAjaxSendCache(url, value, func) 
{	
	return cmfAjaxSend(url, value, func, true);
}

function cmfGetCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function cmfHideMessage()
{
	with(document.getElementById('idAjaxMessage'))
	{
		innerHTML = "";
		style.display = "none";		
	}
}

function cmfCreateMessage(mess_text, time_to_show)
{
	var mess_div = document.getElementById('idAjaxMessage');
	mess_div.style.display = "block";
	mess_div.innerHTML = mess_text;	
	
	if(time_to_show > 0) 
	{ 
		setTimeout("cmfHideMessage()", time_to_show); 
	}
}

function cmfMovePop() 
{	
	if (document.getElementById("idAjaxMessage") == null)
	return;

	if (document.body.scrollTop==0) 
		document.getElementById("idAjaxMessage").style.top=document.documentElement.scrollTop+250; 
	else
		document.getElementById("idAjaxMessage").style.top=document.body.scrollTop+250;
} 

if (document.getElementById("idAjaxMessage") != null)
	setTimeout("cmfMovePop()", 5);
		
window.onscroll = cmfMovePop;