
////////////////////////////////////////////

function processing(el) {
	//Make the Progress Icon Appear
	new toggleInline(el);
}

////////////////////////////////////////////

function completed(el) {
	new Effect.Fade(el,{duration:2.0});
}

////////////////////////////////////////////

function finishQuestionUpdate(div1, div2) {
	doubleswap(div1, div2);
	new Effect.Highlight(div1);
}

////////////////////////////////////////////

function finishSkyscraperUpdate(div1, div2, hiLite) {
	doubleswap(div1, div2);
	new Effect.Highlight(hiLite);
}

////////////////////////////////////////////

function updateSkyscraperPicDetails(theForm, pID) {
	
	var div1 = 'picDetails';
	var div2 = 'picForm';
	var hiLite = 'pic_' + pID;
	var url = '/actions/skyscraper.details.update.php';
	
	new Ajax.Updater(div1, url, {onComplete:function(request){finishSkyscraperUpdate(div1, div2, hiLite)},asynchronous:true, parameters:Form.serialize(document.forms[theForm])});

	return false;

}

////////////////////////////////////////////

function updateQuestionDetails(theForm) {
	
	var div1 = 'questionDetails';
	var div2 = 'questionForm';
	var url = '/actions/question.details.update.php';
	
	new Ajax.Updater(div1, url, {onComplete:function(request){finishQuestionUpdate(div1, div2)},asynchronous:true, parameters:Form.serialize(document.forms[theForm])});

	return false;

}

////////////////////////////////////////////

function updateQuestionApprovedStatus(qID) {
	var selectBox = document.getElementById("approved");
	var optSelected = selectBox.selectedIndex;
	var optSelectedValue = selectBox.options[optSelected].value;

	var div = 'approvedUpdate';
	var url = '/actions/question.approve.update.php?approved=' + optSelectedValue + '&qID=' + qID;

	document.getElementById(div).style.display = "inline";
	//new Effect.Appear(div);
	
	new Ajax.Updater(div, url, {onComplete:function(request){completed(div)},asynchronous:true});

}

////////////////////////////////////////////

function updateSkyscraperApprovedStatus(pID) {
	var selectBox = document.getElementById("approved");
	var optSelected = selectBox.selectedIndex;
	var optSelectedValue = selectBox.options[optSelected].value;

	var div = 'approvedUpdate';
	var url = '/actions/skyscraper.approve.update.php?approved=' + optSelectedValue + '&pID=' + pID;

	document.getElementById(div).style.display = "inline";
	//new Effect.Appear(div);
	
	new Ajax.Updater(div, url, {onComplete:function(request){completed(div)},asynchronous:true});

}

////////////////////////////////////////////

function goToUrl(url) {

location.href = url;

}

////////////////////////////////////////////

function showSearchCities() {

	//var country = document.forms[1].elements["searchCountries"].value;

	var selectBox = document.getElementById("searchCountries");
	var optSelected = selectBox.selectedIndex;
	var optSelectedValue = selectBox.options[optSelected].value;

	var updater = 'countryCities';
	var url = '/actions/horizon.cities.inc.php?country=' + optSelectedValue;
	new Ajax.Updater(updater, url, {asynchronous:true});

}

////////////////////////////////////////////

function emailOptFocus() {

	var myInput = document.forms[0].fromEmail;

	//defaults

	var defaultText = myInput.defaultValue;
	var currentVal = myInput.value;
	
	var defaultColor = "#666";
	var focusColor = "#000";

	var newStyle = "color:" + focusColor;

	if(currentVal == defaultText) {
		myInput.value = "";
		myInput.setAttribute("style", newStyle);
		myInput.style.color = focusColor;
	}
}

////////////////////////////////////////////

function emailOptBlur() {

	var myInput = document.forms[0].fromEmail;

	//defaults

	var defaultText = myInput.defaultValue;
	var currentVal = myInput.value;

	var defaultColor = "#666";

	if(currentVal == "") {
		var newStyle = "color:" + defaultColor;
		myInput.value = defaultText;
		myInput.setAttribute("style", newStyle);
		myInput.style.color = defaultColor;
	}
}

////////////////////////////////////////////

function countryStateOption() {

	var countrySel = document.forms[0].country;
	var selected_value = countrySel.selectedIndex;
	var curVal = countrySel.options[selected_value].value;

	var states = document.getElementById("statesList");
	var aussieStates = document.getElementById("aussieStatesList");
	var indiaStates = document.getElementById("indiaStatesList");
	var provinces = document.getElementById("provinceList");

	if(curVal == "United States") {
		states.style.display = "inline";
		aussieStates.style.display = "none";
		indiaStates.style.display = "none";
		provinces.style.display = "none";
	} else if(curVal == "Canada") {
		provinces.style.display = "inline";
		states.style.display = "none";
		aussieStates.style.display = "none";
		indiaStates.style.display = "none";
	} else if(curVal == "Australia") {
		aussieStates.style.display = "inline";
		states.style.display = "none";
		indiaStates.style.display = "none";
		provinces.style.display = "none";
	} else if(curVal == "India") {
		indiaStates.style.display = "inline";
		states.style.display = "none";
		aussieStates.style.display = "none";
		provinces.style.display = "none";
	} else {
		states.style.display = "none";
		aussieStates.style.display = "none";
		indiaStates.style.display = "none";
		provinces.style.display = "none";
	}
}

////////////////////////////////////////////

function cityFocus() {

	var myInput = document.forms[0].city;

	//defaults

	var defaultText = myInput.defaultValue;
	var currentVal = myInput.value;
	
	var defaultColor = "#666";
	var focusColor = "#000";

	var newStyle = "color:" + focusColor;

	if(currentVal == defaultText) {
		myInput.value = "";
		myInput.setAttribute("style", newStyle);
		myInput.style.color = focusColor;
	}
}

////////////////////////////////////////////

function cityBlur(myField) {

	var myInput = document.forms[0].city;

	//defaults

	var defaultText = myInput.defaultValue;
	var currentVal = myInput.value;

	var defaultColor = "#666";

	if(currentVal == "") {
		var newStyle = "color:" + defaultColor;
		myInput.value = defaultText;
		myInput.setAttribute("style", newStyle);
		myInput.style.color = defaultColor;
	}
}

////////////////////////////////////////////

function winPopUp(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="slideshow") strOptions="height="+strHeight+",width="+strWidth+"top=150,left=70,scrollbars=no, status=no, resizable=yes";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,scrollbars,resizable,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
window.open(strURL, 'newWin', strOptions);
}

////////////////////////////////////////////

function expand(whichitem) {

	lists = whichitem.parentNode.getElementsByTagName("ul");

/*
	//close all the other ones
	var otherLists = whichitem.parentNode.parentNode.getElementsByTagName("li");

	for (var i=0; i< otherLists.length; i++) {
		if(whichitem.parentNode != otherLists[i]) {
			
			var mySubLists = otherLists[i].getElementsByTagName("ul");
	
				for (var u=0; u< mySubLists.length; u++) {		
						mySubLists[u].setAttribute("style", "display:none");
				}
				var myLink = otherLists[i].firstChild;
				myLink.setAttribute("class", "closed");
		}
	}
*/

	//now open or close the one in question	
	for (var i=0; i< lists.length; i++) {

		if(lists[i].style.display == "block") {

			lists[i].setAttribute("style", "display:none");
			whichitem.setAttribute("class", "closed");
			lists[i].style.display = "none";
			whichitem.className = "closed";


		} else {

			lists[i].setAttribute("style", "display:block");
			whichitem.setAttribute("class", "opened");
			lists[i].style.display = "block";
			whichitem.className = "opened";

		}		

	}

	return false;

}

////////////////////////////////////////////////////////////

function toggleInline(targetId) {
if (document.getElementById)
	{
	target = document.getElementById(targetId);

		if (target.style.display == "none")
			{
			target.style.display = "inline";
			}
		else
			{
			target.style.display = "none"
			}
		}
}

////////////////////////////////////////////////////////////

function swap(targetId) {

if (document.getElementById)
	{
	target = document.getElementById(targetId);

		if (target.style.display == "none")
			{
			target.style.display = "block";
			}
		else
			{
			target.style.display = "none"
			}
		}
}

////////////////////////////////////////////////////////////


function doubleswap(targetId,targetId2) {

if (document.getElementById)
	{
	target = document.getElementById(targetId);

		if (target.style.display == "none")
			{
			target.style.display = "block";
			}
		else
			{
			target.style.display = "none"
			}

		target = document.getElementById(targetId2);

		if (target.style.display == "none")
			{
			target.style.display = "block";
			}
		else
			{
			target.style.display = "none"
			}
		}
}