
/**
 * Redirect
 */
var redirectUrl;

function articleRedir(id)
{
	redirectUrl = "?m=page&id=" + id;
	Timer = setTimeout('redirect()', 1500);
}

function campaignRedir()
{
	redirectUrl = "?m=campaign";
	Timer = setTimeout('redirect()', 2000);
}

function contactRedir()
{
	redirectUrl = "?m=contact&sent";
	Timer = setTimeout('redirect()', 3000);
}

function teamGroupRedir(id)
{
	redirectUrl = "?m=team&manageGroups&group=" + id; 
	Timer = setTimeout('redirect()', 2000);
}

function teamRedir(id)
{
	redirectUrl = "?m=team";
	Timer = setTimeout('redirect()', 2000);
}

function redirectTimeout(url, timeout)
{
	redirectUrl = url;
	Timer = setTimeout('redirect()', timeout);
}

function redirect(url)
{
	window.location = redirectUrl;
}

function updateHTML(id, text)
{
	document.getElementById(id).innerHTML = text;
}


function followlink(link, text)
{
	confirm_value = confirm(text);
	if (confirm_value == true)
	{ 	window.location=link;	}
}

function togglediv (id, style)
{
	if (document.getElementById) {
	var mydiv = document.getElementById(id);
	if (mydiv) {
	if (style == undefined) style = (mydiv.style.display=='block'?'none':'block');	
	mydiv.style.display = style;
	}
	}
}

function showNav(id)
{
	for(var i=1; i<20; i++) {
		togglediv("nav" + i, "none");
	}
	togglediv("nav" + id, "block");
}

function caRepPdf()
{
	togglediv("pdfReplace", "block");
	togglediv("pdfExist", "none");
}

function caRepImage()
{
	togglediv("imgReplace", "block");
	togglediv("imgExist", "none");
}

function umRepPass()
{
	togglediv("passwordChange", "block");
	togglediv("passwordShow", "none");
}

var ie;
function iedetect(e)
{
var browser = navigator.appName;

if (browser=="Microsoft Internet Explorer") { ie = 1; }
 else { ie = 0; }
}

document.onmousemove = iedetect();

function nav(id, e)
{
	if (ie)
	{
		for(var i=1; i<=7; i++) {
			var nav = document.getElementById("li" + i);
			nav.style.border = "0px;";
		}
		
		if (id) {
		var nav = document.getElementById("li" + id);
		nav.style.border = "1px solid #fff"; }
		
	}
}	


function ajaxtest()
{
	var input = document.mainform.postalcode.value;
	
	if (input.length == 5)
	{
		xmlHttp1 = new xmlHttp;
        xmlHttp1.open('GET', "api.php?a=ajaxtest&postalcode=" + input, true);
        xmlHttp1.send(null);
        xmlHttp1.onreadystatechange = function()
        {
                if (xmlHttp1.readyState == 4) {
                var response=xmlHttp1.responseText;
                        togglediv("ajaxResult", "block");
                        
                        if (response != "0") {
                        updateHTML("city", response); }
                        else {
                        updateHTML("city", "leider kein Ort zu dieser Postleitzahl gefunden"); }
                }
        }
	}
	else
	{
		togglediv("ajaxResult", "none");
	}
}

function xmlHttp()
{
    var xmlHttp = false;
     
    try
    {
        if( window.ActiveXObject )
        {
            for( var i = 5; i; i-- )
            {
                try
                {
                    if( i == 2 )
                    {
                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }
                    else
                    {   
                        xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
                    }
                    break;
                }
                catch( excNotLoadable )
                {                        
                    xmlHttp = false;
                }
            }
        }
        else if( window.XMLHttpRequest )
        {
            xmlHttp = new XMLHttpRequest();
        }
    }
    catch( excNotLoadable )
    {
        xmlHttp = false;
    }
    return xmlHttp ;
}


function pdfTest()
{
	setTimeout('pdfShow()', 2000);
}

function pdfShow()
{
	togglediv("pdfWait", "none");
	togglediv("pdfShow", "block");
}

function submitCallback()
{
	var name = document.callback.callbackName.value;
	var phone = document.callback.callbackPhone.value;
	
	if (name.length < 3 || phone.length < 3) {
		updateHTML("callbackError", "<font class='error'>" +
			"Name oder Telefonnummer zu kurz</font>");
	}
	else
	{
		xmlHttp1 = new xmlHttp;
        xmlHttp1.open('POST', "api.php?a=callback&name=" + escape(name) + "&phone=" + escape(phone), true);
        xmlHttp1.send(null);
        xmlHttp1.onreadystatechange = function()
        {
           if (xmlHttp1.readyState == 4) {
           var response=xmlHttp1.responseText;
			togglediv("callback", "none");
			togglediv("callbackS", "block");
            }
        }
	}
}



function delRefImg(id, category, reference)
{
	confirm_value = confirm("Bild wirklich löschen?");
	if (confirm_value == true)
	{
		xmlHttp1 = xmlHttp();
		xmlHttp1.open('GET', "api.php?a=reImgDel&id=" + id, true);
		xmlHttp1.send(null);
		xmlHttp1.onreadystatechange = function()
		{
			if (xmlHttp1.readyState == 4) {	
			showAdImages(reference, category, 1);
			}
		}
	}
}



initImage = 0;
function showReImg(id, reference, width, height)
{
	initImage = id;
	setTimeout("displayReImg(" + id + ", " + reference + ", " + width + ", " + height + ")", 4000);	
}

function displayReImg(id, reference, width, height, ignoreInit)
{
	if (initImage == id || ignoreInit == 1)
	{
		document.images.refDetailImg.src = "data/references/" + reference + "-" + id + "-n.jpg" ;
    	userdet = document.getElementById("refDetail");
   	 	userdet.style.display = 'block';
   	 	setDivMousePosition("refDetail", -(width / 2), -height + 100);
   	 	initImage = 0;
	}
}

function hideReImg()
{
	 userdet = document.getElementById("refDetail");
   	 userdet.style.display = 'none';
}

function stopReImg()
{
	initImage = 0;
}

function showAdImages(id, category, doNotToggle)
{
	xmlHttp1 = xmlHttp();
	xmlHttp1.open('GET', "api.php?a=reImg&id=" + id +"&category=" + category, true);
	xmlHttp1.send(null);
	xmlHttp1.onreadystatechange = function()
	{
		if (xmlHttp1.readyState == 4) {
			setinnerHTML ("reAdImg" + id, xmlHttp1.responseText);
		}
	}
	if (doNotToggle != 1) { togglediv("reAdImg" + id); }
}

function setinnerHTML(id, content)
{
	document.getElementById(id).innerHTML = content;
}

function showUploadDiv(id)
{
	togglediv("reImg" + id);
}

var mouseX;
var mouseY;
function setDivMousePosition(id, left, top) {
	if (!left) { left = 0; }
	if (!top) { top = 0; }
    var mydiv = document.getElementById(id);
    mydiv.style.left = mouseX + left + "px";
    mydiv.style.top = mouseY + top + "px";
}

function reShowSave(id)
{
	togglediv("reSave" + id, "block");
}


function reCommentSave(id)
{
	value = document.getElementById("reComment" + id).value;
    var post = "comment="+escape(encodeURI(value)) +
                    "&iid=" + id;
	sendPost("api.php?a=reImgCom",post,"");
	alert("Kommentar wurde gespeichert");
}


function getMouseXY(e)
{ 
  if (!e) e = window.event;
  if (e)
  { 
  	mouseX = e.pageX;
  	mouseY = e.pageY;
  }
}
document.onmousemove = getMouseXY;


function sendPost(url,value,action) {
	xmlHttpPost = xmlHttp();
	xmlHttpPost.open('POST',url,true);
	xmlHttpPost.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlHttpPost.setRequestHeader("Content-length",value.length);
	xmlHttpPost.setRequestHeader("Connection","close");
	xmlHttpPost.send(value);
	xmlHttpPost.onreadystatechange=function()
	{ if (xmlHttpPost.readyState==4) { 
		response = xmlHttpPost.responseText;
		}
	}
}


