var Content = null;

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 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) 
        {
        	
        	
            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);
}