// JavaScript Document


function getModul(name, pFunction) {
	loadXML(null
			, '/servlet/com.netreality.servlet.GetModul?modul='+name
			, "GET"
			, function(xml){
					loadData(xml);
					if(pFunction) {
						pFunction();
					}
				}
			);		
}

function postModulData(data, name, pFunction) {
	loadXML(data
			, '/servlet/com.netreality.servlet.GetModul?modul='+name
			, "POST"
			, function(xml){loadData(xml,pFunction);}
			);		
}


function loadData(xml, pFunction) {
	$('content',xml)
		.each(function(i) {
			target = $(this).attr('target');
			type = $(this).attr('type');			
			if(type == 'root') {
				location.href='/?'+$(this).text();
			} else {
				$('#'+target).html($(this).text());
			}
		}
	);
	var script = $(xml).find("script").text();
	eval(script);
	$('message',xml)
		.each(function(i){
				alert($(this).text());
		}
	);
}

// CMP
function initCMPData() {
	getCMPData();
	window.setInterval('getCMPData()', 30000);
}
function getCMPData() {	
	loadXML(null
		, '/servlet/com.netreality.cmp.MessageGetter'
		, "GET"
		, function(xml){loadCMPData(xml);}
		);
}
function loadCMPData(xml) {
	$('message',xml)
		.each(function(i) {
			target = $(this).attr('target');
			type = eval($(this).attr('type'));
			if(type == 0) { // setContent
				$('#'+target).html($(this).text());
			} else if(type == 1) { //addContent
				$('#'+target).append($(this).text());
			} else if(type == 2) { //javascript
				eval($(this).text());
			} 
		}
	);
}

// captcha
function createCaptcha() {
	Recaptcha.create("6LfTTgAAAAAAAEqkgOpqVl_8IbJTuBBxFVQXVD-V",
	"captcha", {
    theme: "white",
    callback: Recaptcha.focus_response_field
	});
}

var editor;
function initNicEditor(divId) {
	editor = new nicEditor(
				{iconsPath : '/script/nicEditorIcons.gif'
				,buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','link']}
		).panelInstance(divId);
}

function getCookie(c_name) {
if (document.cookie.length>0) {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}


