/**
 * @author manuel.ruefenacht
 */
// Client side AJAX/XMLHTTP requests File

var xmlHttp;
var p1Visible = true;
var pictureIsLoading = false;
var path = "";

function GetXmlHttpObject()
{
    var xmlHttp=null;
    
	try
        {
            xmlHttp=new XMLHttpRequest();   // Firefox, Opera 8.0+, Safari
        }
    catch (e)
        {
        try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
    return xmlHttp;
}

function getContent(params, pictureChange, getHome, picturePath){
	
	xmlHttp=GetXmlHttpObject();
	document.getElementById('waiting').style.visibility='visible';
	clearTimeout(timeoutId);
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    
    var url="actions.php?";
	url = url + params;
	
	path=picturePath;
	
    xmlHttp.onreadystatechange=function(){
		getContentStateChanged(pictureChange, getHome);
	};
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);

}

function getContentStateChanged(pictureChange, getHome){
	
	if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){
	
		isLocked = false;
		document.getElementById('divMiddleMain').innerHTML = xmlHttp.responseText;
		if(pictureChange){
			if(!getHome)
			{
				setTimeout('getNextPic('+getHome+')', 2000);
			}
			else
			{
				getNextPic(getHome);	
			}
		}	
		document.getElementById('waiting').style.visibility = 'hidden';
		initializeOpacityValues('div', 'clickableItem');
		if(setOpValues)
		{
			isLocked = true;
			setOpacity();
			setOpValues = false;
		}
	}
}

function getNextPic(getHome)
{
	nextPicture();
	getVisibleMainPicture();
	document.getElementById('mainPicture2').src="images/blank.gif";
	if(getHome){
		fadeIn(0);
		getVisibleMainPicture();
	}
	
}

function getNextPicture(){
	
	if (!pictureIsLoading) {
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null) {
			alert("No AJAX support for this browser");
			return;
		}
		
		var url = "nextPicture.php";
		
		url=url+"?sid="+Math.floor(1000*Math.random());
		
		url=url+"&path="+path;
		
		xmlHttp.onreadystatechange = nextPictureStateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		p1Visible = !p1Visible;
		pictureIsLoading = true;
	}
	
}


function nextPictureStateChanged(){
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
		pictureIsLoading = false;
		
		if(p1Visible){
			fadeOut(100);
			document.getElementById('mainPicture2').src = xmlHttp.responseText;
		}
		else{
			fadeIn(0);
			document.getElementById('mainPicture').src = xmlHttp.responseText;
		}
	}
}

function getLinkList(){
	
	xmlHttp=GetXmlHttpObject();
	document.getElementById('waiting').style.visibility='visible';
	clearTimeout(timeoutId);
	
	if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
	var url="actions.php";
    url = url + "?action=serviceLinks";
	
    xmlHttp.onreadystatechange=getServiceContentStateChanged; 
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function getServiceList(){
	
	xmlHttp=GetXmlHttpObject();
	document.getElementById('waiting').style.visibility='visible';
	clearTimeout(timeoutId);
	
	if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
	var url="actions.php";
    url = url + "?action=serviceContacts";
	
    xmlHttp.onreadystatechange=getServiceContentStateChanged; 
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function getServiceContentStateChanged(){
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById('serviceLeft').innerHTML = xmlHttp.responseText;
		document.getElementById('waiting').style.visibility='hidden';
	}
	
}

