// JavaScript Document
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function initAll()
{
	startCountSessionTime();
	if(document.getElementById("mvPAnimate"))
	{
		animateProfiles(document.getElementById("mvPAnimate"));
	}
	
	if(document.getElementById("cpControlFilled"))
	{
		firstTimeLoaded=1;
		prevalidateFormFields("frmEditProfile");
	}
	
	if(document.getElementById("aProfileAddManagePhotos"))
	{
		enableTooltips('aProfileAddManagePhotos');
		//init();
	}
	
	if(document.getElementById("cpAboutProfil"))
	{
		countCharsInField(document.getElementById("cpAboutProfil"));
	}
	
	if(document.getElementById("countdownSessionLeft"))
	{
		startCountdown(document.getElementById("countdownSessionLeft"));
	}
	if(document.getElementById("frontNewsHere"))
	{
		if(typeof(newsInterval0)!='undefined')
		{
			clearInterval(newsInterval0);
		}
		newsInterval0=window.setTimeout(animateFrontNews, 12000);
	}
	
	
	
		
}
window.onload=initAll;

function handleServerResponse1(whatTDiv) 
{
  if (xmlHttp.readyState == 4) 
  {	   
 	if (xmlHttp.status == 200) 
    {
		var xmlResponse = xmlHttp.responseXML;
		  
		if(!xmlResponse || !xmlResponse.documentElement)
		{
			throw("Invalid XML structure:\n" + xmlHttp.responseText);
		}
		  
		var rootNodeName=xmlResponse.documentElement.nodeName;
		  
		if(rootNodeName == "parserror")
		{
			throw("Invalid XML structure");
		}
	  	xmlRoot=xmlResponse.documentElement;
		
		var titleArray1 = xmlRoot.getElementsByTagName("obj1");
		var helloMessage1=titleArray1.item(0).firstChild.data;
		  
		
		if(whatTDiv)
		{
			whatTDiv.innerHTML=helloMessage1;
		}
		
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


function displaySubFormHere(autoStart)
{
	var x=get_cookie("hTF");
	if(typeof(x)!="undefined" && x!=null && x=="1" && autoStart==1)
	{
		return false;
	}

	if(typeof(hideForever)!="undefined" && hideForever==1 && autoStart==1)
	{
		return false;
	}
	if(autoStart==1)
	{
		var params = "&id=" + 169 + "&type=" + 1000002;
	}
	else if(autoStart==0)
	{
		var params = "&id=" + 169 + "&type=" + 1000001;
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{	
	
	if(!document.getElementById("whatTDiv"))
		{
			var whatTDiv=document.createElement("div");
			whatTDiv.id="whatTDiv";
			whatTDiv.className="whatTDivClass";
			document.getElementById("Site").insertBefore(whatTDiv, document.getElementById("Site").firstChild);
		}
	
	
	
		var date = new Date();
		var timestamp = date.getTime();		

		xmlHttp.open("POST", "index.php", true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse1(whatTDiv);
		}
		
		// make the server request
		xmlHttp.send(params);
	 }		
}


function hideTDiv(a)
{
	if(document.getElementById("whatTDiv"))
	{
		document.getElementById("whatTDiv").parentNode.removeChild(document.getElementById("whatTDiv"));
		if(a==1)
		{
			hideForever=1;			
		}
		else if(a==0)
		{
			hideForever=0;
		}
		document.cookie="hTF=1";
	}
}
