//CSS Discovery Content Management System - Javascript 



var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}





// Check Weather Link

function checkweatherlink() {

	var map = document.getElementById('weatherplace').value;
	alert("This will check the link for weather at: "+map+" in a new window");
	window.open('http://www.bbc.co.uk/cgi-perl/weather/search/new_search.pl?search_query='+map+'&x=28&y=8');

}


function insertweatherlink() {

	var map = document.getElementById('weatherplace').value;

	var openNewWin = document.getElementById('weathernewwindow').value;

		if (document.getElementById('weathernewwindow').checked) {
				var linkopen = 'target="_new"';
		} else {
				var linkopen = 'target="_self"';
		}

	
	var maplink = '<a href="http://www.bbc.co.uk/cgi-perl/weather/search/new_search.pl?search_query='+map+'&x=28&y=8" ' + linkopen +'>Weather Link</a>';

	// Write Link to Text Area
	document.getElementById('maincontent').value = document.getElementById('maincontent').value + maplink;
	
	
}

// Check Weather Link

function checkmaplink() {

	var map = document.getElementById('mapplace').value;
	alert("This will check the link for weather at: "+map+" in a new window");
	window.open('http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc='+map+'&quicksearch='+map+'');

}


function insertmaplink() {

	var map2 = document.getElementById('mapplace').value;

	var openNewWin = document.getElementById('mapnewwindow').value;

		if (document.getElementById('mapnewwindow').checked) {
				var linkopen = 'target="_new"';
		} else {
				var linkopen = 'target="_self"';
		}

	
	var maplink = '<a href="http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc=' + map2 + '&quicksearch=' + map2 + '" ' + linkopen + '>Map Link</a>';

	// Write Link to Text Area
	document.getElementById('maincontent').value = document.getElementById('maincontent').value + maplink;
	
	
}


var quotes = "\"";



function showRoute() {
	
		var $postcode= document.getElementById("source").value;
		var $destination = document.getElementById("destination").value;
		var $googleMapsUrl = "http://maps.google.co.uk/maps?q=http://maps.google.co.uk/maps?&hl=en&saddr="+$postcode+"&daddr="+$destination;
		
		popUpWindow($googleMapsUrl, 20,20,768,500);
		
}

function insertroutelink() {

	var route = document.getElementById('routeplace').value;

	var routelink = '<p>Enter your postcode: <input type="hidden" value="'+route+'" id="source" /><input type="text" value="" id="destination" /> <input type="button" value="Show Route" onclick="showRoute();" /></p>';

	alert(routelink);
	
	// Write Link to Text Area
	document.getElementById('maincontent').value = document.getElementById('maincontent').value + routelink;
	
	
}