function win(url,width,height,options,frame)
{
    if (!frame) frame="_blank";
    var left=screen.width/2-width/2;
    var top=screen.height/2-height/2-30;
    window.open(url,frame,"width="+width+",height="+height+",left="+left+",top="+top+","+options);
}

function popup(img,x,y) 
{
    popupwin=window.open("","pics","left="+((screen.width/2)-150)+",top=100,width="+x+",height="+y+";");
    popupwin.document.write("<HTML><BODY topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><a href='javascript:self.close()'><img src='"+ img + "' border='0' alt='Fenster schliessen'></a></BODY></HTML>");
    popupwin.document.close();
}

function omo(object)
{
	object.className="button_omo";
}
function omo2(object)
{
	object.className="button";
}

function reloadData(object,url)
{
	if (!object)
    	object=window.event;
  	if (object.which)
  		code=object.which;
  	else if (object.keyCode) 
  		code=object.keyCode;
  	if (code==13) 
  		window.open(url,"hiddendata");
}

function add(type,id,replace,listdiv,listfield,alt)
{
    eval("field=document.forms[0].elements['data["+listfield+"]'];");
	eval("infoField=document.forms[0].elements['data["+listfield+"_info]'];");
    if (id>0)
    {
        if (replace)
        {
            field.value=id;
            if (infoField) infoField.value="";
            update(type,listdiv,listfield,alt);
        }
        else
        {
            oldvalue=","+field.value+",";
            if (oldvalue.indexOf(","+id+",")==-1)
            {
                if (field.value.length>0)
                {
                    field.value+=","+id;
                    if (infoField) infoField.value+=",";
                }
                else
                {
                    field.value=id;
                    if (infoField) infoField.value=",";
                }
                update(type,listdiv,listfield,alt);
            }
        }
    }
}

function info(type,id,info,listdiv,listfield,alt)
{
	eval("field=document.forms[0].elements['data["+listfield+"]'];");
	eval("infoField=document.forms[0].elements['data["+listfield+"_info]'];");
	if (infoField)
	{
    	old=field.value.split(",");
    	old2=infoField.value.split(",");
	    for (i=0;i<old.length;i++)
	    {
	        if (old[i]==id) 
	        {
	        	old2[i]=info;
	        }
	    }
		infoField.value=old2.join(",");
		update(type,listdiv,listfield,alt);
	}
}

function update(type,listdiv,listfield,alt)
{
    eval("field=document.forms[0].elements['data["+listfield+"]'];");
	eval("infoField=document.forms[0].elements['data["+listfield+"_info]'];");
    if (field)
    {
        if (infoField)
        {
        	window.open("admin_list.php?type="+type+"&listdiv="+listdiv+"&listfield="+listfield+"&update=true&ids="+field.value+"&alt="+alt+"&info="+infoField.value,"hiddendata");
        }
        else
        {
        	window.open("admin_list.php?type="+type+"&listdiv="+listdiv+"&listfield="+listfield+"&update=true&ids="+field.value+"&alt="+alt,"hiddendata");
        }
        return true;
    }
    else
    {
        return false;
    }
}



function del(type,id,listdiv,listfield,alt)
{
	eval("field=document.forms[0].elements['data["+listfield+"]'];");
	eval("infoField=document.forms[0].elements['data["+listfield+"_info]'];");
	old=field.value.split(",");
    if (infoField) old2=infoField.value.split(",");
    neww=new Array();
    if (infoField) neww2=new Array();
    for (i=0;i<old.length;i++)
    {
        if (old[i]!=id) 
        {
            neww[neww.length]=old[i];
            if (infoField) neww2[neww2.length]=old2[i];
        }
    }
    field.value=neww.join(",");
    if (infoField) infoField.value=neww2.join(",");
    update(type,listdiv,listfield,alt);
}

var DHTML=0,DOM=0,MS=0,OP=0;

function DHTML_init() 
{
    if(window.opera)            {OP=1;}
    if(document.getElementById) {DHTML=1;DOM=1;}
    if(document.all && !OP)     {DHTML=1;MS=1;}
}
DHTML_init();

function divUpdate(divName,content)
{
    if (DOM)
        document.getElementById(divName).innerHTML=content;
    else if (MS)
        document.all[divName].innerHTML=content;
}

function divAdd(divName,content)
{
    if (DOM)
        document.getElementById(divName).innerHTML+=content;
    else if (MS)
        document.all[divName].innerHTML+=content;
}

function divScroll(divName)
{
	if (DOM)
        document.getElementById(divName).scrollIntoView(true);
    else if (MS)
        document.all[divName].scrollIntoView(true);
}


var ivto=0;
function cu(action,text,name,color,time)
{
	switch (action)
	{
		//new message
		case 0: divAdd("chat_data","<font class=\"chat\"><font color=\""+color+"\">"+name+":</font> "+text+"</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//new action
		case 1: divAdd("chat_data","<font class=\"chat2\"><font color=\""+color+"\">"+name+"</font> "+text+"</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//new user
		case 2: divAdd("chat_data","<font class=\"chat2\"><font color=\""+color+"\">"+name+"</font> hat gerade den Chat betreten.</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//user out
		case 3: divAdd("chat_data","<font class=\"chat2\"><font color=\""+color+"\">"+name+"</font> hat gerade den Chat verlassen.</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//user timeout
		case 4: divAdd("chat_data","<font class=\"chat2\"><font color=\""+color+"\">"+name+"</font> wurde wegen Inaktivität automatisch ausgeloggt.</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//user changed room
		case 5: divAdd("chat_data","<font class=\"chat2\"><font color=\""+color+"\">"+name+"</font> ist in den Raum <b>"+text+"</b> gewechselt.</font><br>");
				document.forms['chat'].elements['time'].value=time;
				divScroll("chat_bottom");
				break;
		//update user list
		case 7: divUpdate("chat_users",text);
				break;
		//clear message field
		case 8: document.forms['chat'].elements['message'].value="";
				break;
		//set interval
		case 9: clearInterval(ivto);
				ivto=window.setInterval("cr("+text+")",text*1000);
				break;
    }
}

function cr(reload)
{
	window.open("/chatupdate.php?time="+document.forms['chat'].elements['time'].value+"&reload="+reload,"data");
}

function chatframe(mode)
{
	if (DOM)
   		height=document.getElementById("chat_frame").style.height;
	else if (MS)
   	    height=document.all["chat_frame"].style.height;
	height=height.substring(0,height.length-2);
	if (mode==1)
	{
		if (height>100)
		{
			if (DOM)
	    		document.getElementById("chat_frame").style.height=""+(Number(height)-50)+"px";
	   		else if (MS)
	    	    document.all["chat_frame"].style.height=""+(Number(height)-50)+"px";
	   	}
	}
	else
	{
		if (DOM)
	    	document.getElementById("chat_frame").style.height=""+(Number(height)+50)+"px";
	   	else if (MS)
	        document.all["chat_frame"].style.height=""+(Number(height)+50)+"px";
	}
}

        
