var CONTENT_ID = 'divBodyContent';
var LAST_PROFILE = 0;

function SwitchToProfile(id, season, zone, ssroll) {
		if (id!='' && id!=0) {
			if (LAST_PROFILE > 0) {
				document.getElementById('tab_profile_' + LAST_PROFILE).style.backgroundImage = 'url(images/tab_pcalc.gif)';
				document.getElementById('tab_profile_' + LAST_PROFILE).style.color = '#000000';
			}

			document.getElementById('tab_profile_' + id).style.backgroundImage = 'url(images/tab_pcalc_over.gif)';
			document.getElementById('tab_profile_' + id).style.color = '#FFFFFF';
			LAST_PROFILE = id;
			startLoading();
			
			http.open("GET", 'http://www.dailygrain.com.au/demo_calc_result.asp?profile=' + id + '&season=' + season + '&zone=' + zone + '&ssroll=' + ssroll + '&nocache=' + new Date().getTime(), true);
			http.onreadystatechange = handleResponse;
			http.send(null);
		}
}

function startLoading() {
	document.getElementById(CONTENT_ID).innerHTML = '<img src="images/loading.gif" border="0" width="100" alt="Loading..." align="center">';
}

function ShowAdhocForm() {
	if (LAST_PROFILE > 0) {
		document.getElementById('tab_profile_' + LAST_PROFILE).style.backgroundImage = 'url(images/tab_pcalc.gif)';
		document.getElementById('tab_profile_' + LAST_PROFILE).style.color = '#000000';
	}

	document.getElementById('tab_profile_0').style.backgroundImage = 'url(images/tab_pcalc_over.gif)';
	document.getElementById('tab_profile_0').style.color = '#FFFFFF';
	LAST_PROFILE = 0;
	
	//startLoading();
	//http.open("GET", 'http://www.dailygrain.com.au/marea_pcalc_profiled_form.asp', true);
	//http.onreadystatechange = handleResponse;
	//http.send(null);
}

function handleResponse() {
	var retGridVal = "";

	if (http.readyState == 4) {
		retGridVal = http.responseText;
	}
	else
		return false;
	
	document.getElementById(CONTENT_ID).innerHTML = retGridVal;
}

function no_null(str_in) {
	if (str_in == null || str_in == 'undefined')
		return '';
	else
		return str_in;
}


function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}



var http = getHTTPObject(); // We create the HTTP Object