
function SaveSeason(ingId)
  {
  window.MyScript 	= 3;	// for post-ajax processing
  var Country   	= document.TheForm.country.value;
  var Type      	= document.TheForm.type.value;
  var startdate		= window.Knob1Val;
  var enddate		= window.Knob2Val;
  if(Country == -1 || Type == -1 || startdate == -1 || enddate == -1)
    {
	alert('Make sure you select startdate, end date, growing season type and country for which applicable');
    }
  else
    {
	var SaveSecReq  =  getXmlHttpRequestObject();
    var ScriptName	= getURL(5);
    var ParamString = 'start='+startdate+'&end='+enddate+'&iid='+ingId+'&country='+Country+'&type='+Type;
    DoAjaxPost(ScriptName, ParamString);
    }
  }

// start our ajax request. Called from page
function SaveSection(TheId, TheSection, TheType) {
    var SaveSecReq = getXmlHttpRequestObject();
    window.myValue  = TheSection;
	window.MyScript = 1;
	window.ID       = TheId;
	window.Type     = TheType;
	var ScriptName  = getURL(2);
    var Texta       = document.getElementById('ta'+TheSection);
    var TextInput   = Texta.innerHTML;
	var FormName    = 'fo'+TheSection;
	var TextInput    = Texta.value;

	ParamString = 'type='+TheType+'&ct='+TextInput+'&RID='+TheId+'&CPS='+TheSection;
    DoAjaxPost(ScriptName, ParamString);
	}

function GetUnformatted(TheId, TheSection, TheType) {
	window.MyScript = 2;
	var ScriptName  = getURL(2);
	ParamString = 'type='+TheType+'&shw=1&RID='+TheId+'&CPS='+TheSection;
    DoAjaxPost(ScriptName, ParamString);
	}

function ShowEditFormOLD(TheSection, iid, tty) 
  {
  if (document.getElementById('For'+TheSection) == null) 
    {
	if((window.Unformatted == null)||(window.Unformatted == -1))
	  {
	  window.myValue  = TheSection;
 	  window.MyScript = 1;
	  window.ID       = iid;
	  window.Type     = tty;
	  GetUnformatted(iid, TheSection, tty);
	  }
	else
	  {
      OldCont 		    = window.Unformatted
	  var sect			= '\'For\'';
      var FormString 	= '<form name=\"fo'+TheSection+'\"><textarea rows=40 class=\"recipe\" id=\"ta'+TheSection+'\" name=\"ta'+TheSection+'\">'+OldCont+'</textarea><br /><input type=\"button\" value=\"Save\" class=\"smallbut\" OnClick=\"SaveSection('+iid+','+TheSection+', '+tty+');\"><input type=\"button\" value=\"Cancel\" class=\"smallbut\" OnClick=\"DelDiv('+sect+', '+TheSection+');\"></form>';
      var newdiv 		= document.createElement('div');
      var ReplaceEl 	= document.getElementById('c'+TheSection);
	  newdiv.id		    = 'For'+TheSection;
      newdiv.innerHTML  = FormString;  
      ReplaceEl.appendChild(newdiv);
	  window.Unformatted = -1;
	  }
	}
  }	
function ShowEditForm(TheSection, iid, tty, FormBase) 
  {
  if (document.getElementById(FormBase+TheSection) == null) 
    {
	if((window.Unformatted == null)||(window.Unformatted == -1))
	  {
	  window.myValue  = TheSection;
 	  window.MyScript = 1;
	  window.ID       = iid;
	  window.Type     = tty;
	  GetUnformatted(iid, TheSection, tty);
	  }
	else
	  {
      OldCont 		    = window.Unformatted
	  var sect			= '\'For\'';
      var FormString 	= '<form name=\"fo'+TheSection+'\"><textarea rows=40 class=\"recipe\" id=\"ta'+TheSection+'\" name=\"ta'+TheSection+'\">'+OldCont+'</textarea><br /><input type=\"button\" value=\"Save\" class=\"smallbut\" OnClick=\"SaveSection('+iid+','+TheSection+', '+tty+');\"><input type=\"button\" value=\"Cancel\" class=\"smallbut\" OnClick=\"DelDiv('+sect+', '+TheSection+');\"></form>';
      var newdiv 		= document.createElement('div');
      var ReplaceEl 	= document.getElementById('c'+TheSection);
	  newdiv.id		    = FormBase+TheSection;
      newdiv.innerHTML  = FormString;  
      ReplaceEl.appendChild(newdiv);
	  window.Unformatted = -1;
	  }
	}
  }	
	
function ShowSeasons(iid) 
  {
  var FormStringO 	= '<form name=\"aaa\"><textarea></textarea></form>';
  TheSource         = getURL(1);
  var FormString 	= '<div id=\"c0\" class=\"bc\"><iframe style=\"border:0px; height: 135px;\" scrolling=no src =\"'+TheSource+'?iid='+iid+'\" width=\"100%\"></iframe>';
  var newdiv 		= document.createElement('div');
  var ReplaceEl 	= document.getElementById('seasonboxy');
  newdiv.id			= 'sc0';
  newdiv.innerHTML  = FormString;
  ReplaceEl.appendChild(newdiv);
  window.Unformatted = -1;
  }

function FinishSeasonSave(NewContent)
  {
  if(NewContent == -1)
    {
	alert('An error occured when saving this season');
	}
  else
    {
	self.parent.UpdateDivs('seasonboxy', NewContent);
	}
  }