var xmlHttp
// request/populate page 
function showDash(url,id)
{ 
	
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 

url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function() { stateChanged(id); };
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//document.getElementById(id).style.display='block';
delete xmlHttp.onreadystatechange;
}

function stateChanged(id){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	 	document.getElementById(id).innerHTML=xmlHttp.responseText;
		//uses html elements on calling page to save form data as users enter it
		//is only good for one ajax call
		/*if (document.getElementById('openTask').value!=""){
			textEl = document.getElementById('task' + document.getElementById('openTask').value ).getElementsByTagName('textarea');
			if (document.getElementById('openTaskVal').value) {textEl[0].value = document.getElementById('openTaskVal').value;}
			toggleTask(document.getElementById('openTask').value);
			//alert(document.getElementById('openTaskVal').value);
		}*/
	}else if(xmlHttp.readyState==1 || xmlHttp.readyState=="loading"){
		document.getElementById(id).innerHTML='<div class="loadingResponse">loading...</div>';
	}
}

function showInternal(url,id)
{ 
	
xmlHttpInternal=GetXmlHttpObject()
if (xmlHttpInternal==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 

url=url+"&sid="+Math.random();
xmlHttpInternal.onreadystatechange=function() { stateChangedInternal(id); };
xmlHttpInternal.open("GET",url,true);
xmlHttpInternal.send(null);

delete xmlHttpInternal.onreadystatechange;
}

function stateChangedInternal(id){ 
	if (xmlHttpInternal.readyState==4 || xmlHttpInternal.readyState=="complete"){ 
	 	document.getElementById(id).innerHTML=xmlHttpInternal.responseText;
		//uses html elements on calling page to save form data as users enter it
		//is only good for one ajax call
		/*if (document.getElementById('openTask').value!=""){
			textEl = document.getElementById('task' + document.getElementById('openTask').value ).getElementsByTagName('textarea');
			if (document.getElementById('openTaskVal').value) {textEl[0].value = document.getElementById('openTaskVal').value;}
			toggleTask(document.getElementById('openTask').value);
			//alert(document.getElementById('openTaskVal').value);
		}*/

	}else if(xmlHttpInternal.readyState==1 || xmlHttpInternal.readyState=="loading"){
		if (id=='body'){
			document.getElementById(id).innerHTML='<div class="loadingResponse">generating report...</div>';
		}else{
			document.getElementById(id).innerHTML='<div class="loadingResponse">loading...</div>';
		}
	}
}

function showContact(url,id)
{ 
xmlHttpContact=GetXmlHttpObject()
if (xmlHttpContact==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 

url=url+"&sid="+Math.random();
xmlHttpContact.onreadystatechange=function() { stateChangedContact(id); };
xmlHttpContact.open("GET",url,true);
xmlHttpContact.send(null);

delete xmlHttpContact.onreadystatechange;
}

function stateChangedContact(id){ 
	if (xmlHttpContact.readyState==4 || xmlHttpContact.readyState=="complete"){ 
	 	document.getElementById(id).innerHTML=xmlHttpContact.responseText;
	}else if(xmlHttpContact.readyState==1 || xmlHttpContact.readyState=="loading"){
		document.getElementById(id).innerHTML='<div class="loadingResponse">loading...</div>';
	}
}

// readystate object for individual items
function showItem(url,id)
{ 
xmlHttpItem=GetXmlHttpObject()
if (xmlHttpItem==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 

url=url+"&sid="+Math.random();
xmlHttpItem.onreadystatechange=function() { stateChangedItem(url,id); };
xmlHttpItem.open("GET",url,true);
xmlHttpItem.send(null);

delete xmlHttpItem.onreadystatechange;
}

function stateChangedItem(url,id){ 
	if (xmlHttpItem.readyState==4 || xmlHttpItem.readyState=="complete"){ 
	 	document.getElementById(id).innerHTML=xmlHttpItem.responseText;
		if(document.getElementById('DPC_pc_YYYY-MM-DD')) DPC_autoInit();
	if (document.getElementById("URL")) document.getElementById("URL").value = url;
	}else if(xmlHttpItem.readyState==1 || xmlHttpItem.readyState=="loading"){
		document.getElementById(id).innerHTML='<div class="loadingResponse">loading...</div>';
	}
}

//////////////////////////////////

// readystate object to reload parent window

function stateChangedParent(id){ 
	if (xmlHttpParent.readyState==4 || xmlHttpParent.readyState=="complete"){ 
	 	opener.document.getElementById(id).innerHTML=xmlHttpParent.responseText;
	}else if(xmlHttpParent.readyState==1 || xmlHttpParent.readyState=="loading"){
		opener.document.getElementById(id).innerHTML='<div class="loadingResponse">loading...</div>';
	}
}

function reloadParent(url,id)
{ 
xmlHttpParent=GetXmlHttpObject()
if (xmlHttpParent==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 

url=url+"&sid="+Math.random();
xmlHttpParent.onreadystatechange=function() { stateChangedParent(id); };
xmlHttpParent.open("GET",url,true);
xmlHttpParent.send(null);

delete xmlHttpParent.onreadystatechange;
}

//////////////////////////////////

// readystate object for form saves
function saveForm(url,id)
{ 
xmlHttpForm=GetXmlHttpObject()
if (xmlHttpForm==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
url=url+"&sid="+Math.random();
xmlHttpForm.onreadystatechange=function() { stateChangedForm(id); };
xmlHttpForm.open("GET",url,true);
xmlHttpForm.send(null);

delete xmlHttpForm.onreadystatechange;
}

function stateChangedForm(id){ 
	if (xmlHttpForm.readyState==4 || xmlHttpForm.readyState=="complete"){ 
		if (document.getElementById("leadMarker")){
			setSalesManager();
		}else if (document.getElementById("develop")){
			setCsManager();
		}else if (document.getElementById("contacts")){
			ajaxTimeoutContacts();
		}
	 	document.getElementById(id).innerHTML=xmlHttpForm.responseText;
	}else if(xmlHttpForm.readyState==1 || xmlHttpForm.readyState=="loading"){
		document.getElementById(id).innerHTML='<div class="loadingResponse">saving...</div>';
	}
}
//////////////////////////////////

//////////////////////////////////

// readystate object for actions
function saveAction(url,id)
{ 
xmlHttpAction=GetXmlHttpObject()
if (xmlHttpAction==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }

actionVal = getActionType(url);	
url=url+"&sid="+Math.random();
xmlHttpAction.onreadystatechange=function() { stateChangedAction(id,actionVal); };
xmlHttpAction.open("GET",url,true);
xmlHttpAction.send(null);

delete xmlHttpAction.onreadystatechange;
}

function stateChangedAction(id,actVal){ 
	if (xmlHttpAction.readyState==4 || xmlHttpAction.readyState=="complete"){ 
	 	if (document.getElementById("URL")) showItem(document.getElementById("URL").value,'handleProject');
		if (actVal==1 || actVal==7 || actVal==9){
			if (document.getElementById('theURL')) showContact(document.getElementById('theURL').value,'contactHistory');
		};
		document.getElementById(id).innerHTML=xmlHttpAction.responseText;
	}else if(xmlHttpAction.readyState==1 || xmlHttpAction.readyState=="loading"){
		document.getElementById(id).innerHTML='<div class="loadingResponse">saving...</div>';
	}
}
//////////////////////////////////
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
