/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		request_type = new XMLHttpRequest();
	}
	
	return request_type;
}

var http = createObject();

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function GetResult() {
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('resultdisplay').innerHTML = "Just a second..."
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var UserFVObj= encodeURI(document.getElementById('UserFVObj').value);
	var PVObj = encodeURI(document.getElementById('PVObj').value);
	var AObj= encodeURI(document.getElementById('AObj').value);
	var IntRateObj = encodeURI(document.getElementById('IntRateObj').value);
	var PeriodObj= encodeURI(document.getElementById('PeriodObj').value);
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'resultInCal.php?UserFVObj='+UserFVObj+'&PVObj=' +PVObj+'&AObj='+AObj+'&IntRateObj='+IntRateObj+'&PeriodObj='+PeriodObj+'&nocache='+nocache);
	http.onreadystatechange = GetResultReply;
	http.send(null);
}

function GetResultReply() {
	if(http.readyState == 4 || http.readyState == "complete"){ 
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		document.getElementById('resultdisplay').innerHTML = '<table width="100%" class="T3"><tr><td>&nbsp;</td></tr><tr><td align="left">'+response+'</td></tr><tr><td>&nbsp;</td></tr></table>';
	}
}

function displayCompare() {
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('displayCompare_response').innerHTML = "Loading..."
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var Product2 = encodeURI(document.getElementById('Product2'));
	var Product1= encodeURI(document.getElementById('Product1').value);
	var Product2 = encodeURI(document.getElementById('Product2').value);

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'resultcompare.php?Product1='+Product1+'&Product2=' +Product2+'&nocache = '+nocache);
	http.onreadystatechange = displayCompareReply;
	http.send(null);
}

function displayCompareReply() {
	if(http.readyState == 4 || http.readyState == "complete"){
		var response = http.responseText;
		document.getElementById('displayCompare_response').innerHTML = response;
	}
}
function displayCareers() {
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('displayCareers_response').innerHTML = ""
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var Product2 = encodeURI(document.getElementById('Product2'));
	var Country= encodeURI(document.getElementById('Country').value);
	

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'resultcareers.php?Country='+Country+'&nocache = '+nocache);
	http.onreadystatechange = displayCareersReply;
	http.send(null);
}

function displayCareersReply() {
	if(http.readyState == 4 || http.readyState == "complete"){
		var response = http.responseText;
		document.getElementById('displayCareers_response').innerHTML = response;
	}
}

function displaySales() {
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('displaySales_response').innerHTML = "Loading..."
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var Product2 = encodeURI(document.getElementById('Product2'));
	var Country= encodeURI(document.getElementById('Country').value);
	

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'resultsales.php?Country='+Country+'&nocache = '+nocache);
	http.onreadystatechange = displaySalesReply;
	http.send(null);
}

function displaySalesReply() {
	if(http.readyState == 4 || http.readyState == "complete"){
		var response = http.responseText;
		document.getElementById('displaySales_response').innerHTML = response;
	}
}

function displayPlant() {
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('displayPlant_response').innerHTML = "Loading..."
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var Product2 = encodeURI(document.getElementById('Product2'));
	var CountryT= encodeURI(document.getElementById('CountryT').value);

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'resultplant.php?CountryT='+CountryT+'&nocache = '+nocache);
	http.onreadystatechange = displayPlantReply; 
	http.send(null);
}

function displayPlantReply() {
	if(http.readyState == 4 || http.readyState == "complete"){
		var response = http.responseText;
		document.getElementById('displayPlant_response').innerHTML = response;
	}
}

