var myobjects = jsonstring;
var regions = new Object(myobjects.regions); 
var districts = new Object(myobjects.districts); 
var suburbs = new Object(myobjects.suburbs); 

function GetKeepMePostedRegions() {
  var options = regions;	
  var rSelect = document.getElementById('keep_me_posted_address_region'); 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      rSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      rSelect.appendChild(newOption); 
    } 
  }	
}

function GetKeepMePostedDistricts(region) {
  var options = districts[region];

  // remove the current options from Districts 
  var cSelect = document.getElementById('keep_me_posted_address_district'); 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  // remove the current options from Suburbs
  var sSelect = document.getElementById('keep_me_posted_address_suburb'); 
  var len=sSelect.options.length; 
  while (sSelect.options.length > 1) { 
    sSelect.remove(1); 
  }

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}

function GetKeepMePostedSuburbs(region,district) {
  var options = suburbs[region][district];

  // get the country select element via its known id 
  var cSelect = document.getElementById('keep_me_posted_address_suburb'); 
  // remove the current options from the country select 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];
    newOption.text = options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}


function GetSupplyCheckRegions() {
  var options = regions;	
  var rSelect = document.getElementById('supply_check_address_region'); 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      rSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      rSelect.appendChild(newOption); 
    } 
  }	
}

function GetSupplyCheckDistricts(region) {
  var options = districts[region];

  // remove the current options from Districts 
  var cSelect = document.getElementById('supply_check_address_district'); 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  // remove the current options from Suburbs
  var sSelect = document.getElementById('supply_check_address_suburb'); 
  var len=sSelect.options.length; 
  while (sSelect.options.length > 1) { 
    sSelect.remove(1); 
  }

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}

function GetSupplyCheckSuburbs(region,district) {
  var options = suburbs[region][district];

  // get the country select element via its known id 
  var cSelect = document.getElementById('supply_check_address_suburb'); 
  // remove the current options from the country select 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];
    newOption.text = options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}


function ShowKeepMePosted() {
  pageTracker._trackEvent("Keep me posted", "Overlay open");

  $('keep_me_posted_form').reset();
  
  $('popup_fade').style.display='block';
  $('popup').style.display='block';

  $('keep-posted-error').innerHTML = "";
  $('keep_me_posted_success').hide();
  $('keep_me_posted').show();
  
  GetKeepMePostedRegions();

	sIFR.replace(omnesmedium, {
	      selector: 'div.SupplyCheck h2',
	      wmode: 'transparent',
	      css: '.sIFR-root { font-size: 34px; color: #ec0e64; padding: 0 }'
	});
}

function HideKeepMePosted() {
  pageTracker._trackEvent("Keep me posted", "Overlay close");
  $('popup_fade').style.display='none';
  $('popup').style.display='none';
  $('keep_me_posted_success').hide();
  $('keep_me_posted').hide();
}

function GetRegions() {
  var options = regions;	
  var rSelect = document.getElementById('address_region'); 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      rSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      rSelect.appendChild(newOption); 
    } 
  }	
}

function GetDistricts(region) {
  var options = districts[region];

  // remove the current options from Districts 
  var cSelect = document.getElementById('address_district'); 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  // remove the current options from Suburbs
  var sSelect = document.getElementById('address_suburb'); 
  var len=sSelect.options.length; 
  while (sSelect.options.length > 1) { 
    sSelect.remove(1); 
  }

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];  // assumes option string and value are the same 
    newOption.text= options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}

function GetSuburbs(region,district) {
  var options = suburbs[region][district];

  // get the country select element via its known id 
  var cSelect = document.getElementById('address_suburb'); 
  // remove the current options from the country select 
  var len=cSelect.options.length; 
  while (cSelect.options.length > 1) { 
    cSelect.remove(1); 
  } 

  var newOption; 
  // create new options 
  for (var i=0; i<options.length; i++) { 
    newOption = document.createElement("option"); 
    newOption.value = options[i];
    newOption.text = options[i]; 
    // add the new option 
    try { 
      cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
    } 
    catch (e) { 
      cSelect.appendChild(newOption); 
    } 
  } 
}
