// JavaScript Document

// iDreamTracker

function get_dreamtitle(dreamID,intervalName){
  
	var divID = "dreamtitle_dt"+dreamID;
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	xmlhttp.onreadystatechange = function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById(divID).innerHTML=xmlhttp.responseText;
		clearInterval(intervalName); 
		}
	  }
	  
	xmlhttp.open("GET","/ajax/dt_dreamtitle.cfm?did="+dreamID,true);
	xmlhttp.send();

}

function get_dreamsummary(dreamID,intervalName){
	
	var divID = "dreamsummary_dt"+dreamID;
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	xmlhttp.onreadystatechange = function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById(divID).innerHTML=xmlhttp.responseText;
		clearInterval(intervalName); 
		}
	  }
	  
	xmlhttp.open("GET","/ajax/dt_dreamsummary.cfm?did="+dreamID,true);
	xmlhttp.send();
	
}

function get_dreamchart(dreamID,chartType,intervalName){
	
	var divID = "dreamchart_dt"+dreamID;
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	xmlhttp.onreadystatechange = function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById(divID).innerHTML=xmlhttp.responseText;
		clearInterval(intervalName); 
		}
	  }
	  
	xmlhttp.open("GET","/ajax/dt_dreamchart.cfm?did="+dreamID+"&ctype="+chartType,true);
	xmlhttp.send();
	
}

// iDreamTracker Forms

function getform_dt(dreamID,fmName){
	
	alert("getform_dt function called. dreamID: "+dreamID+" | fmName: "+fmName);
	
	var divID = "popUpDiv";
	var divBlanketID = "blanket";
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	xmlhttp.onreadystatechange = function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById(divID).innerHTML=xmlhttp.responseText;
		document.getElementById(divBlanketID).style.display = 'block';
		document.getElementById(divID).style.display = 'block';
		}
	  }
	  
	xmlhttp.open("GET","/ajax/"+fmName+".cfm?did="+dreamID,true);
	xmlhttp.send();
	
}

function reqDTForm(dreamID,fmName){
	alert("reqDTForm function called. dreamID: "+dreamID+" | fmName: "+fmName);
	var fmInt = setInterval( 'getform_dt(dreamID,fmName,fmInt)', 1000 );	
}

function updateMusic(amID,divID){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.open("GET","/ajax/updatemusic.cfm?amid="+amID,false);
	xmlhttp.send();

	document.getElementById(divID).innerHTML=xmlhttp.responseText;
}
