function showRegion(region) {
	new Ajax.Request('ajax/retrieveregion.php?r=' + region,{
		asynchronous:true,
		evalScripts:true
	});
}

function loadPorts(location) {
	new Ajax.Request('ajax/retrieveports.php?s=' + location,{
		asynchronous:true,
		evalScripts:true
	});
}

function highlightGlobalRow(rowid) {
	
	$$('li.global-row').each(function(r) {
		r.style.background = "#fff";
	});
	
	$$('a.global-link').each(function(r) {
		r.style.color = "#333";
	});
	
	$('global-'+rowid).style.background = "#3875D7";
	$('global-link-'+rowid).style.color = "#fff";

}

function highlightRegionRow(rowid) {
	
	$$('li.region-row').each(function(r) {
		r.style.background = "#fff";
	});
	
	$$('a.region-link').each(function(r) {
		r.style.color = "#333";
	});
	
	$(rowid).style.background = "#3875D7";
	$(rowid).style.color = "#ffffff";
	
}

function togglePort(toggle, port) {
	if(toggle) {
		
		new Ajax.Request('ajax/toggleport.php?action=add&pId=' + port,{
			asynchronous:true,
			evalScripts:true
		});
	} else {
		new Ajax.Request('ajax/toggleport.php?action=remove&pId=' + port,{
			asynchronous:true,
			evalScripts:true
		});
	}
}

function discontinueAd(id) {
	new Ajax.Request('ajax/discontinueAd.php?id=' + id,{
		asynchronous:true,
		evalScripts:true,
		onSuccess: function(response) {
			alert("The Ad has been discontinued.");
	  	}	  
	});
}

function initValue(element) {
	if(element.name == 'text') {
		if(element.value == 'Additional Text...') {
			element.value = '';
		}
	} else {
		if(element.name == element.value) {
			element.value = '';
		}
	}
}

function length_explanation(length) {
	alert("Values longer than " + length + " will run off the edge of an iPhone screen.  We therefore limit you to " + length + " characters to prevent this.");
}

function landing_description() {
	var landingWin = window.open("landingExplanation.php", "pw", "height=556,width=382,resizable=yes");
	landingWin.focus();
}

function previewAd(id) {
	var previewWin = window.open("previewAd.php?id=" + id, "pw", "height=60,width=340,resizable=yes");
	previewWin.focus();
}

function verify_agreed() {
	if($('agree_to_terms').checked) {
		document.location.href = "checkout.php" 
	} else {
		alert("You must agree to the Advertising Terms.");
	}
}