// Associate Green Country Javascript

function showCities()
{
	var dest;
	var box;
	var region;

	box = document.forms[0].Regions;
	dest = box.options[box.selectedIndex].value;
	document.getElementById(dest).style.display = "block";
}

function FEGetValue(id){
	var value=document.getElementById('Regions').options[document.getElementById('Regions').selectedIndex].value;
	if(value != "None") document.getElementById(value).style.display = "block";
	else document.getElementById('Cities').style.display = "block";
}

function hideCities()
{
	var rarray = document.getElementsByClassName("Regions");
	var rlen = rarray.length;
		for (x = 0; x < rlen; x++) {
			rarray[x].style.display = "none";
		}
}

function hideSADChildren()
{
	var rarray = document.getElementsByClassName("SADs");
	var rlen = rarray.length;
		for (x = 0; x < rlen; x++) {
			rarray[x].style.display = "none";
		}
}

function showSADParents()
{
	document.getElementById("SADParents").style.display = "block";	
}


function loadurl(dest,output) { try { 
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { 
} 
xmlhttp.onreadystatechange = loadurltrig; 
xmlhttp.open("POST", dest); 
xmlhttp.send(null); } 

function loadurltrig() { 
document.getElementById("output").innerHTML = "<p>Loading, please wait...</p>";
  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { 
    document.getElementById("output").innerHTML = xmlhttp.responseText; } 
}


function loadWindow(dest) { try { 
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { 
} 
xmlhttp.onreadystatechange = loadWindowPage; 
xmlhttp.open("POST", dest); 
xmlhttp.send(null); } 

function loadWindowPage() { 
document.getElementById("windowOutput").innerHTML = "<p>Loading, please wait...</p>";
  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { 
    document.getElementById("windowOutput").innerHTML = xmlhttp.responseText; } 
}


function loadPage(dest,output) { try { 
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { 
} 
xmlhttp.onreadystatechange = loadurltrigPage; 
xmlhttp.open("POST", dest); 
xmlhttp.send(null); } 

function loadurltrigPage() { 
document.getElementById("output").innerHTML = "<p>Loading, please wait...</p>";
  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { 
    document.getElementById("output").innerHTML = xmlhttp.responseText; } 
}





function showSADChild(){

	var psad = document.getElementById('sad');
	var toSAD = psad.options[psad.selectedIndex].value;
	
	document.getElementById(toSAD).style.display = "block";
	
}



function storeCitiesRegion(idt)
{

	// City
	var pc = document.getElementById(idt);
	var toCity = pc.options[pc.selectedIndex].value;
	var region = idt;
	
	loadurl('assets/libraries/lib_greencountryAssocHandle.php?city='+toCity+'&region='+region);
}



// ----------------- Front End Date and City Sort Functions -------------------

//Function to replace the following function
function realByCity(refID,querySend){
	
	var openSelector=document.getElementById(refID).options[document.getElementById(refID).selectedIndex].value;
	if(openSelector == "None") openSelector = "Cities";
	var currentCity = document.getElementById(openSelector).options[document.getElementById(openSelector).selectedIndex].value;
	
	var k = document.getElementById('KeywordInput').value;
	
	loadPage(querySend+'.php?Cities='+currentCity+'&sortBy=City&Keyword='+k);
}


function byCity(Page)
{
	// City
	// Edit : Thanks for the comment, I was wondering what this code was for
	var c = document.getElementById('Cities');
	var City = c.options[c.selectedIndex].value;
	
	// Keyword
	var k = document.getElementById('KeywordInput');
	var Keyword = k.value;

	
	loadPage(Page+'.php?Cities='+City+'&sortBy=City&Keyword='+Keyword);
}



function byDate(Page)
{
	
	// Month
	var d = document.getElementById('Month');
	var Month = d.options[d.selectedIndex].value;
	
	// Month
	var q = document.getElementById('Year');
	var Year = q.options[q.selectedIndex].value;

	loadPage(Page+'.php?Month='+Month+'&Year='+Year+'&sortBy=Date');
	
}


function hideBottom(){

	var a = document.getElementById("assocStop").checked;
	
	var w = document.getElementById('Region');
	var Region = w.options[w.selectedIndex].value;

	var u = Region.substr(6,8);
	
	
	var e = document.getElementById('RegionSel'+u);
	var City = e.options[e.selectedIndex].value;
	

	
	if(City != ""){
	
	if(a == true){
		document.getElementById("hideWindow").style.display = "block";
	} else {
		document.getElementById("hideWindow").style.display = "none";
		
	}
	
	} else {
		
		return false;
		
	}
	
}



function checkChecked(a,b){

	var itschecked = document.getElementById(a).checked;
	
	if(itschecked == true){
		document.getElementById(b).style.display = "block";
	} else {
		document.getElementById(b).style.display = "none";
	}
		
}






