function showhide(name, name2){ 
	if (document.getElementById){ 
		obj = document.getElementById(name);
		obj2 = document.getElementById(name2); 
	
		if (obj2.style.display == "none"){ 
			obj2.style.display = "";
			obj.style.display = "none";
		} else { 
			obj2.style.display = "none";
			obj.style.display = "";
		}
		
		/*
		if (obj.disabled){ 
			obj.disabled = false;
			obj2.disabled = true; 
		} else { 
			obj.disabled = true;
			obj2.disabled = false; 
		} 
		*/
	} 
} 

function ObjectFocus(objectID)
{
	document.getElementById(objectID).focus();
}

function createQuery(form, flag)
{
    var elements = form.elements;
    var pairs = new Array();

    for (var i = 0; i < elements.length; i++) {

		if(elements[i].name != "documentType" && elements[i].style.display != "none" && elements[i].type != "button" && elements[i].type != "file" && elements[i].type != "hidden" && elements[i].type != "submit")
		{
			name = elements[i].name;
			value = elements[i].value;
			
			
			if(flag == 0){
				pairs.push(name + "=" + encodeURIComponent(value));
			}else{
				if(value != "")
				 pairs.push(name + "=" + encodeURIComponent(value));
			}
		}
    }

	if(flag == 0) {
		var lease_date = form.yearLease.value + "-" + form.monthLease.value + "-" + form.dayLease.value;
		pairs.push("Lease_Date=" + lease_date);

		var exp_date = form.yearExp.value + "-" + form.monthExp.value + "-" + form.dayExp.value;
		pairs.push("Expiration=" + exp_date);
	}
	
    return pairs.join("&");
}

function populate(field, value)
{
	for(var i=0; i<field.length; i++)
	{
		document.getElementById(field[i]).value=value[i];
	}
}

function printSelected(printStyle)
{
	var checkboxes = document.form_container.list;

	var count=0;

	for (i = 0; i < checkboxes.length; i++)
	{
		if(checkboxes[i].checked)
		{
			count++;
		}
	}
	
	if(count > 0)
	{
		document.form_container.doccsv.value = printStyle;
		document.form_container.submit();
	}
	else
	{
		alert("Please select something to print.");
	}

}

function printAll()
{
	document.form_container.submit();
}

/*
function printAll()
{
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/printAll.php";

	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	alert(xmlHttp.responseText);
}
*/

function deleteUser(name, id)
{
	var answer = confirm("Are you sure you want to delete user: \"" + name + "\"?")
	if (answer){
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		
		// display the progress circle
		document.getElementById("outerdiv").style.display = "block";

		var url = "/inc/redirect.php?deleteUser=true&id="+id;
	
		xmlHttp.onreadystatechange = function ()
		{
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
			{
				// hide the progress circle
				document.getElementById("outerdiv").style.display = "none";

				showControlPanel();
			}
		};

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} else {
		;
	}
	return false;
}

function saveUser(name, id)
{
	
	xmlHttp = GetXmlHttpObject();
		
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	// display the progress circle
	document.getElementById("outerdiv").style.display = "block";

	var url = "/inc/redirect.php?saveUser=true&id="+id;

	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			// hide the progress circle
			document.getElementById("outerdiv").style.display = "none";

			showControlPanel();
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	return false;
}

function refreshDropInstrument()
{
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/dropdown_instrument.php";

	var response;
	
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			response = xmlHttp.responseText;

			document.getElementById("dropProspect").innerHTML = response;
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function totalInterest(t)
{
	xmlHttp2 = GetXmlHttpObject();
	
	if (xmlHttp2 == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/redirect.php?totalInterest="+t;
	
	xmlHttp2.onreadystatechange = function ()
	{
		if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == "complete")
		{
			document.getElementById("totalInterest").innerHTML = xmlHttp2.responseText;
		}
	};

	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
}

function totalNet(t)
{
	xmlHttp3 = GetXmlHttpObject();
	
	if (xmlHttp3 == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/redirect.php?totalNet="+t;
	
	xmlHttp3.onreadystatechange = function ()
	{
		if (xmlHttp3.readyState == 4 || xmlHttp3.readyState == "complete")
		{
			document.getElementById("totalNet").innerHTML = xmlHttp3.responseText;
		}
	};

	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
}

function totalBonus(t)
{
	xmlHttp4 = GetXmlHttpObject();
	
	if (xmlHttp4 == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/redirect.php?totalBonus="+t;
	
	xmlHttp4.onreadystatechange = function ()
	{
		if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == "complete")
		{
			document.getElementById("totalBonus").innerHTML = xmlHttp4.responseText;
		}
	};

	xmlHttp4.open("GET",url,true);
	xmlHttp4.send(null);
}


function buildUploadTable(id)
{
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/redirect.php?uploadTable=" + id;

	
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			document.getElementById("content2").innerHTML =  xmlHttp.responseText;
			refreshDropInstrument();
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function refreshLastUser()
{
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "/inc/redirect.php?showLast=1";

	
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			document.getElementById("lastUser2").innerHTML =  xmlHttp.responseText;
			// just in case the user has added a new prospect
			refreshDropDown(1);
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function deleteUpload(name)
{
	var answer = confirm("Are you sure you want to delete file: \"" + name + "\"?")
	if (answer){
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		
		// display the progress circle
		document.getElementById("outerdiv").style.display = "block";

		var url = "/inc/redirect.php?delete_file=" + name;
		
		xmlHttp.onreadystatechange = function ()
		{
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
			{
				// hide the progress circle
				document.getElementById("outerdiv").style.display = "none";

				document.getElementById('tab2').onclick();
			}
		};

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} else {
		;
	}
	return false;
}



/*
function printSelected()
{
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var checkboxes = document.form_container.list;

	// display the progress circle
	document.getElementById("outerdiv").style.display = "block";

	var url = "/inc/print.php";

	var params_hold = escape(params);
	params = "advancedSearch=true&sortField=" + sortField + "&sortOrder=" + sortOrder + "&page=" + page + "&perPage=" + perPage + "&" + params;
	
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	var values = '';
	var count = 0;
	
	for (i = 0; i < checkboxes.length; i++)
	{
		if(checkboxes[i].checked)
		{
			values += (checkboxes[i].value + ',');
			count++;
		}
	}
	
	alert(count);

	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") 
		{
			// hide the progress circle
			document.getElementById("outerdiv").style.display = "none";
		}
	}

	xmlHttp.send(params);
}*/
