// JavaScript Document
function ProjAdd(url,targetdiv,showdiv,status, refreshIt){
	statdiv = targetdiv;

	if(showdiv == 1)
		ShowDiv(statdiv);

	try {xmlhttp3 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
	xmlhttp3.onreadystatechange = function(){
	//Check page is completed and there were no problems.
	if (xmlhttp3.readyState != 4) {
		//What to do once the form is submitted - to inform the user.
		document.getElementById(targetdiv).innerHTML= status;
	}
	
	if ((xmlhttp3.readyState == 4) && (xmlhttp3.status == 200)) {
		//What to do once the form is submitted - to inform the user.
		//alert('BAM!');
		document.getElementById(targetdiv).innerHTML=xmlhttp3.responseText;
		if(refreshIt == 1)
			document.location.reload();
		if(showdiv == 1)
			setTimeout("HideDiv(statdiv)",1000);
	}
	}
	xmlhttp3.open("GET","includes/" + url,true);
	xmlhttp3.send(null);
	return false;
	
}

function formAjax(url,query,targetdiv,updatestatus,showdiv,thisdiv,updateResults){
	formGet(url,query,targetdiv,updatestatus,showdiv,thisdiv);
	if(updateResults == 1)
		resultsGet(query);
}
function resultsGet(query,thisdiv){
	var x=2
	if(thisdiv == 100){
		while(document.getElementById('step'+x)){
			document.getElementById('step'+x).style.display = 'none';
			x++;
		}
		thisdiv=1;
	}

	x=1
	if(thisdiv != 0){
		while(document.getElementById(thisdiv+'_'+x)){
			document.getElementById(thisdiv+'_'+x).className = 'item';
			x++;
		}
	}
    	try {xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
		xmlhttp2.onreadystatechange = function(){
			//Check page is completed and there were no problems.
			if (xmlhttp2.readyState != 4) {
				//What to do once the form is submitted - to inform the user.
				document.getElementById('resultsstat').innerHTML= 'Updating...';
			}
	
			if ((xmlhttp2.readyState == 4) && (xmlhttp2.status == 200)) {
				//What to do once the form is submitted - to inform the user.
				document.getElementById('results').innerHTML=xmlhttp2.responseText;
			}
		}
		xmlhttp2.open("GET","connectionwizard/includes/results.php?" + query,true);
		xmlhttp2.send(null);
		return false;
	
}
function formGet(url,query,targetdiv,updatestatus,showdiv,thisdiv,updateResults)
{

	for(x = 8;x>thisdiv;x--){
		document.getElementById('step'+x).innerHTML='';
		document.getElementById('step'+x).style.display = 'none';
	}
	//document.getElementById('results').innerHTML='';

	x=1;
	while(document.getElementById(thisdiv+'_'+x) && showdiv == 1){
		document.getElementById(thisdiv+'_'+x).className = 'item';
		x++;
	}

	if(showdiv == 1){
		document.getElementById(targetdiv).style.display='block';	
	}

    try {xmlhttp1 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
    //Send Ajax Request
    xmlhttp1.onreadystatechange = function(){
        //Check page is completed and there were no problems.
	    if (xmlhttp1.readyState != 4) {
    	    //What to do once the form is submitted - to inform the user.
			if(updatestatus != "") document.getElementById(targetdiv).innerHTML= updatestatus; 
			if(updateResults == 1 || updateResults == 2) document.getElementById('resultsstat').innerHTML= 'Updating...';
	    }

		if ((xmlhttp1.readyState == 4) && (xmlhttp1.status == 200)) {
        	//What to do once the form is submitted - to inform the user.
			document.getElementById(targetdiv).innerHTML=xmlhttp1.responseText;
			if(updateResults == 1) resultsGet(query,0);

    	}
    }
	xmlhttp1.open("GET","connectionwizard/includes/" + url + "?" + query,true);
	xmlhttp1.send(null);
    return false;
}