var msgXmlhttp = createHTTPXMLObj();
function createHTTPXMLObj()
{
    if(window.XMLHttpRequest)
    return new XMLHttpRequest();
    else if(window.ActiveXObject)
    return new ActiveXObject("Microsoft.XMLHTTP");
    else return false;
}

function validEmail()
{
    if( document.getElementById("email").value != document.getElementById("emailwdh").value)
    {
        alert("Email and repetition donīt match!");
        return false;
    }
    else
    {
		var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		var email = document.getElementById("email").value;
        if(email.search(validRegExp) == -1)
        {
          alert("No valid email adress!");
          return false;
        }
        return true;
    }
}

function validPWD()
{
    if( document.getElementById("pwdn").value != document.getElementById("pwdnwdh").value)
    {
        alert("Password and repetition donīt match!");
        return false;
    }
    else
    {
        return true;
    }
}

function validUSR()
{
    if( document.getElementById("vorname").value == "" || document.getElementById("nachname").value == "")
    {
        alert("Please complete the form!");
        return false;
    }
    else
    {
        return true;
    }
}

function validPic()
{
    if( !document.getElementById("j").checked )
    {
        alert("Please accept the tearms!");
        return false;
    }
    else
    {
        return true;
    }
}
function show(object)
{
	if(document.getElementById(object).style.display == "")
	{
		document.getElementById(object).style.display = "none";
	}
	else
	{
		document.getElementById(object).style.display = "";
	}

}
function blinkMail()
{
	show('unreadprev');
	show('unreadprev2');
	setTimeout('blinkMail()',1000);
}
function blinkTeaser()
{
	show('unreadteas');
	show('unreadteas2');
	setTimeout('blinkTeaser()',1000);
}
function setFontWhite(object,colors)
{
	if(document.getElementById(object))
		document.getElementById(object).style.color = colors;
}
function close(object)
{
	if(document.getElementById(object))
		document.getElementById(object).style.display = "none";
}
function open(object)
{
	if(document.getElementById(object))
		document.getElementById(object).style.display = "";
}
function closes(object)
{
	if(document.getElementById(object))
		document.getElementById(object).style.display = "none";
}
function closestour(object)
{
	document.getElementById('t1').style.display = "none";
	document.getElementById('t2').style.display = "none";
	document.getElementById('t3').style.display = "none";
	document.getElementById('t4').style.display = "none";
	document.getElementById('t5').style.display = "none";
	document.getElementById('t6').style.display = "none";
	document.getElementById('t7').style.display = "none";
	document.getElementById('ti1').style.background =  "url('img/start/tour_bg.jpg')";
	document.getElementById('ti2').style.background = "url('img/start/tour_bg.jpg')";
	document.getElementById('ti3').style.background = "url('img/start/tour_bg.jpg')";
	document.getElementById('ti4').style.background = "url('img/start/tour_bg.jpg')";
	document.getElementById('ti5').style.background = "url('img/start/tour_bg.jpg')";
	document.getElementById('ti7').style.background = "url('img/start/tour_bg.jpg')";
	document.getElementById(object).style.background = "url('img/start/tour_bg2.jpg')";
}
function opens(object)
{
	if(document.getElementById(object))
		document.getElementById(object).style.display = "";

}
function setBlack(object,farbe)
{
	if(document.getElementById(object))
		document.getElementById(object).style.background = farbe;
}
function setContent(object,content)
{
	if(document.getElementById(object))
		document.getElementById(object).value = content;
}

function fade(object)
{
	if(document.getElementById(object).style.filter == "gray")
	{
		document.getElementById(object).style.filter = "";
	}
	else
	{
		document.getElementById(object).style.filter = "gray";
	}
}

function closeForumsAll()
{
	for(var i=65;i<91;i++)
		closes(String.fromCharCode(i));
}

function urlEncode(i)
{
	i = escape(i);
	i = i.replace(/%u20AC/g,"%80");
	return i;
}

function hoverBg(oj,i)
{
    if(oj)
	    if(i)
		    oj.style.background = '#EEEEEE';
	    else
		    oj.style.background = '#FFFFFF';
}

function showMeldenBox(o,i,h)
{
    document.getElementById("melden_begr").value = "";
    document.getElementById("melden_art").value = i;
    document.getElementById("melden_hash").value = h;
    
    var mb = document.getElementById("melden").style;
    if(mb.display == "")        
        mb.display = "none";
    else
    {
        var pos = getEventItmLUC(o);
        mb.top = pos[1];
        mb.left = pos[0] - 270;
        mb.display = "";
        document.getElementById("melden_begr").focus();
    }
}

function sendMeldenBox()
{
    document.getElementById("melden").style.display = "none";
    var a = document.getElementById("melden_art").value;
    var h = document.getElementById("melden_hash").value;
    var b = escape(document.getElementById("melden_begr").value);
    msgXmlhttp.open("POST","../me/doCreateMeldung.php",true);
	msgXmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	msgXmlhttp.send("a="+a+"&h="+h+"&b="+b);
	alert("Message sent!");
}

function taMl(o,s)
{
    if(o.value.length>s)
        o.value = o.value.substr(0,s);
}

function getEventItmLUC(o)
{
    var i = new Array();
    if(o.offsetParent)
    {
        i[0] = o.offsetLeft;
        i[1] = o.offsetTop;
        while(o=o.offsetParent)
        {
            i[0] += o.offsetLeft;
            i[1] += o.offsetTop;
        }
    }
    return i;
}


var usersOnline = new Array();
function getNewMails()
{
		msgXmlhttp.open("POST","../pns/mailcheck.php",true);
		msgXmlhttp.onreadystatechange = mailReadyStateChanged;
		msgXmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		msgXmlhttp.send("");
		setTimeout('getNewMails()',30000);
}

function mailReadyStateChanged()
{
		if(msgXmlhttp.readyState==4&&msgXmlhttp.status==200)
		{
	        for(var j=0;j<usersOnline.length;j++)
	            usersOnline[j][1] = 0;
            
			var locItms = msgXmlhttp.responseXML.getElementsByTagName("itm");
			for(var i=0;i<locItms.length;i++)
			{
			    var user_hash = locItms[i].childNodes[0].firstChild.nodeValue;
                for(var j=0;j<usersOnline.length;j++)
                {
			        if(usersOnline[j][0]==user_hash)
			        {
			            usersOnline[j][1] = 1;
			            
			            document.getElementById("OLML1_"+usersOnline[j][0]).href = "javascript:showMailInSplash("+j+");";
			            document.getElementById("OLML2_"+usersOnline[j][0]).href = "javascript:showMailInSplash("+j+");";
			        }
			    }
			}
		}
}
startBlinkOLM();
function startBlinkOLM()
{
    for(var i=0;i<usersOnline.length;i++)
    {
        if(usersOnline[i][1]==1)
        {
            var bgc = document.getElementById("OLM_"+usersOnline[i][0]).style;
            if(bgc.marginRight.substr(0,1)=='1')
            {
                bgc.backgroundColor = '#c2c2c2';
                bgc.marginRight = '0';
            }
            else
            {
                bgc.backgroundColor = '#ffffff';
                bgc.marginRight = '1';
            }
        }
        else
        {
            document.getElementById("OLM_"+usersOnline[i][0]).style.background = '#ffffff';
        }
    }
    setTimeout('startBlinkOLM()',1000);
}

function showMailInSplash(h)
{
	document.getElementById("splashFrame").src = "../pns/newmail.php?h="+usersOnline[h][0];
	document.getElementById('splashBack').style.height = document.body.clientHeight;
	document.getElementById('splash').style.display = "";
}

function doSendFriend()
{
    var c = document.getElementById("friendlist").selectedIndex;
    var v = 'a='+document.getElementById("friendlist").options[c].value;
    v += '&n='+document.getElementById('videoCodes').value+' ';
    v += '&t=Videomessage';
	msgXmlhttp.open("POST","../pr/sendMsg.php",true);
	msgXmlhttp.onreadystatechange = mailReadyStateChanged;
	msgXmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	msgXmlhttp.send(v);
    alert("Video has been sent!");
}

function select_site()
{
	choice=document.siteform.pulldown.selectedIndex;
	link = document.siteform.pulldown.options[choice].value;
	top.location.href=link;
}