<!-- Begin

var dDate = new Date();
var dCurMonth = dDate.getMonth();
var dCurDayOfMonth = dDate.getDate();
var dCurYear = dDate.getFullYear();
var objPrevElement = new Object();

function selectmonth() {
	document.forms[0].tbSelMonth.options[dCurDate.getMonth()+1].selected = true;
	for (i = 0; i < document.forms[0].tbSelYear.length; i++)
		if (document.forms[0].tbSelYear.options[i].value == dCurDate.getFullYear())
			document.forms[0].tbSelYear.options[i].selected = true;
}

function fSetSelectedDay(myElement,myNo){
	elem = document.getElementById("calCell_"+myElement);
	if(!isNaN(parseInt(myNo)))
	{
		for(f=1;f<=40;f++)
			document.getElementById("calCell_"+f).className = "sunbox";
	
		elem.className = "sunbox_hl";
		document.forms[0].calSelectedDay.value = parseInt(myNo);
		document.forms[0].calSelectedMonth.value = document.forms[0].tbSelMonth.options[document.forms[0].tbSelMonth.selectedIndex].value;
		document.forms[0].calSelectedYear.value = document.forms[0].tbSelYear.options[document.forms[0].tbSelYear.selectedIndex].value;
		setDST();
	}
}
function fGetDaysInMonth(iMonth, iYear) {
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}
function fBuildCal(iYear, iMonth) {
	var aMonth = new Array();
	aMonth[0] = new Array(7);
	aMonth[1] = new Array(7);
	aMonth[2] = new Array(7);
	aMonth[3] = new Array(7);
	aMonth[4] = new Array(7);
	aMonth[5] = new Array(7);
	aMonth[6] = new Array(7);
	var dCalDate = new Date(iYear, iMonth-1, 1);
	var iDayOfFirst = dCalDate.getDay()-1;
	if(iDayOfFirst<0) iDayOfFirst+=7; 
	var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
	var iVarDate = 1;
	var i, d, w;
	
	for (d = iDayOfFirst; d < 7; d++) {
		aMonth[1][d] = iVarDate;
		iVarDate++;
	}
	for (w = 2; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			if (iVarDate <= iDaysInMonth) {
				aMonth[w][d] = iVarDate;
				iVarDate++;
			}
		}
	}
	return aMonth;
}
function fDrawCal(iYear, iMonth, iDay) {
	var myMonth;

	myMonth = fBuildCal(iYear, iMonth);

	document.write("<div class='calrow'><div class='suntitle'>M</div>");
	document.write("<div class='suntitle'>T</div>");
	document.write("<div class='suntitle'>W</div>");
	document.write("<div class='suntitle'>T</div>");
	document.write("<div class='suntitle'>F</div>");
	document.write("<div class='suntitle'>S</div>");
	document.write("<div class='suntitle'>S</div></div>");
	var pos = 1;
	for (w = 1; w < 7; w++) {
		document.write("<div class='calrow'>");
		for (d = 0; d < 7; d++)
		{
			if(myMonth[w][d]==iDay)
				document.write("<div class='sunbox_hl' id=calCell_"+ pos + ">");
			else
				document.write("<div class='sunbox' id=calCell_"+ pos + ">");
			
			if (!isNaN(myMonth[w][d]))
			{
				document.write("<a href='javascript:fSetSelectedDay("+ pos + "," + myMonth[w][d] + ")'>" + myMonth[w][d] + "</a>");
			} else {
				document.write("&nbsp;");
			}
			document.write("</div>")

			pos++;
		}
		document.write("</div>");
	}

}

function settoday(){
	var dCurDate = new Date();

	document.forms[0].calSelectedDay.value = dCurDate.getDate();
	document.forms[0].calSelectedMonth.value = dCurDate.getMonth()+1;
	document.forms[0].calSelectedYear.value = dCurDate.getFullYear();

	document.forms[0].tbSelMonth.options[dCurDate.getMonth()+1].selected = true;
	for (i = 0; i < document.forms[0].tbSelYear.length; i++)
		if (document.forms[0].tbSelYear.options[i].value == dCurDate.getFullYear())
			document.forms[0].tbSelYear.options[i].selected = true;
	
	fUpdateCal(dCurDate.getFullYear(), dCurDate.getMonth()+1);
}

function setselected(){
	document.forms[0].tbSelMonth.options[parseInt(document.forms[0].calSelectedMonth.value)-1].selected = true;
	for (i = 0; i < document.forms[0].tbSelYear.length; i++)
		if (document.forms[0].tbSelYear.options[i].value == document.forms[0].calSelectedYear.value)
			document.forms[0].tbSelYear.options[i].selected = true;
	
	fUpdateCal(document.forms[0].calSelectedYear.value, document.forms[0].calSelectedMonth.value);
}


function fUpdateCal(iYear, iMonth) {

	myMonth = fBuildCal(iYear, iMonth);
	objPrevElement.bgColor = "";


	if(document.forms[0].calSelectedMonth.value == document.forms[0].tbSelMonth.options[document.forms[0].tbSelMonth.selectedIndex].value &&
		document.forms[0].calSelectedYear.value == document.forms[0].tbSelYear.options[document.forms[0].tbSelYear.selectedIndex].value)
	{
		var righttime = true;
	}else{
		var righttime = false;
	}
	pos = 1;
	for (w = 1; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			elem = document.getElementById("calCell_" + pos);
			elem.className = "sunbox";
			if (!isNaN(myMonth[w][d])) {
				elem.innerHTML = "<a href='javascript:fSetSelectedDay("+ pos + "," + myMonth[w][d] + ")'>" + myMonth[w][d] + "</a>";
				if(righttime && myMonth[w][d]==parseInt(document.forms[0].calSelectedDay.value))
					elem.className = "sunbox_hl";
			} else {
				elem.innerHTML = "&nbsp;";
			}
			pos++;
		}
	}
	setDST();
}

function setDST()
{
// Finally set daylight saving time
	var dCurDate = new Date();
	dCurDate.setFullYear(document.forms[0].calSelectedYear.value);
	dCurDate.setMonth(parseInt(document.forms[0].calSelectedMonth.value)-1);
	dCurDate.setDate(document.forms[0].calSelectedDay.value);
	var tme = dCurDate.getTime();

	if((tme >= new Date(2003,2,30) && tme <= new Date(2003,9,26)) ||
		(tme >= new Date(2004,2,28) && tme <= new Date(2004,9,31)) ||
		(tme >= new Date(2005,2,27) && tme <= new Date(2005,9,30)) ||
		(tme >= new Date(2006,2,26) && tme <= new Date(2006,9,29)) ||
		(tme >= new Date(2007,2,25) && tme <= new Date(2007,9,28)))
	{
		document.forms[0].daylight_saving.options[0].selected = true;
	}else{
		document.forms[0].daylight_saving.options[1].selected = true;
	}
}

function map(type)
{
	lat_deg = document.forms[0].lat_deg.value;
	lat_mins = document.forms[0].lat_mins.value;
	lat_secs = document.forms[0].lat_secs.value;
	
	long_deg = document.forms[0].long_deg.value;
	long_mins = document.forms[0].long_mins.value;
	long_secs = document.forms[0].long_secs.value;

	if(isNaN(lat_deg) || isNaN(lat_mins) || isNaN(lat_secs) || isNaN(long_deg) || isNaN(long_mins) || isNaN(long_secs))
		alert("You must have (positive) numbers only in your longitude and latitude boxes");
	else
	{
	
		lat_plus = document.forms[0].lat_plus.selectedIndex==0?true:false;
		long_plus = document.forms[0].long_plus.selectedIndex==0?true:false;
		
		lat_deg = parseInt(lat_deg,10);
		lat_mins = parseInt(lat_mins,10);
		lat_secs = parseInt(lat_secs,10);
		
		long_deg = parseInt(long_deg,10);
		long_mins = parseInt(long_mins,10);
		long_secs = parseInt(long_secs,10);
		
		
		if(!lat_plus)
			latitude = ((((lat_secs/60)+lat_mins)/60)+lat_deg)*-1;
		else
			latitude = ((((lat_secs/60)+lat_mins)/60)+lat_deg);
		
		if(!long_plus)
			longitude = ((((long_secs/60)+long_mins)/60)+long_deg)*-1;
		else
			longitude = ((((long_secs/60.0)+long_mins)/60.0)+long_deg);
	
		PHI = de_ra(latitude);
		LAM = de_ra(longitude);
	
		if(type == "m")
			URL = "http://www.multimap.co.uk/map/browse.cgi?client=public&"+latlong_east(PHI,LAM)+"&gride=&gridn=&scale=25000&coordsys=gb&mapsize=big";
		else
			URL = "http://www.streetmap.co.uk/newmap.srf?"+latlong_east(PHI,LAM)+"&z=4"
		var winx = window.open(URL,'multimap','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes')
	}
}


function latlong_east(PHI,LAM)
{
	a = 6377563.396;
	b = 6356256.91;
 	e0 = 400000;
	n0 = -100000;	
 	f0 = 0.9996012717;
	PHI0 = 0.855211333;
	LAM0 = -0.034906585;

    Pi = Math.PI;
	
    af0 = a * f0;
    bf0 = b * f0;
	e2 = (Math.pow(af0,2) - Math.pow(bf0,2)) / Math.pow(af0,2); 
    n = (af0 - bf0) / (af0 + bf0);
    nu = af0 / (Math.sqrt(1 - (e2 *  Math.pow((Math.sin(PHI)),2) )))
    rho = (nu * (1 - e2)) / (1 - (e2 * Math.pow((Math.sin(PHI)),2)))
    eta2 = (nu / rho) - 1;
    p = LAM - LAM0;
    M = Marc(bf0, n, PHI0, PHI);
    I = M + n0;
    II = (nu / 2) * (Math.sin(PHI)) * (Math.cos(PHI));
    III = ((nu / 24) * (Math.sin(PHI)) * (Math.pow((Math.cos(PHI)),3))) * (5 - (Math.pow((Math.tan(PHI)),2)) + (9 * eta2));
    IIIA = ((nu / 720) * (Math.sin(PHI)) * (Math.pow((Math.cos(PHI)),5))) * (61 - (58 * (Math.pow((Math.tan(PHI)),2))) + (Math.pow((Math.tan(PHI)),4)));
    IV = nu * (Math.cos(PHI));
    V = (nu / 6) * (Math.pow((Math.cos(PHI)),3)) * ((nu / rho) - (Math.pow(Math.tan(PHI),2)));
    VI = (nu / 120) * (Math.pow((Math.cos(PHI)),5)) * (5 - (18 * (Math.pow((Math.tan(PHI)),2))) + Math.pow((Math.tan(PHI)),4) + (14 * eta2) - (58 * (Math.pow((Math.tan(PHI)),2)) * eta2));

	Lat_Long_to_East = Math.round(e0 + (p * IV) + (Math.pow(p,3) * V) + (Math.pow(p,5) * VI),0);
    Lat_Long_to_North = Math.round(I + (Math.pow(p,2) * II) + (Math.pow(p,4) * III) + (Math.pow(p,6) * IIIA),0);

    return "X="+Lat_Long_to_East+"&Y="+Lat_Long_to_North;

}


function Marc(bf0, n, PHI0, PHI)
{
    return bf0 * (((1 + n + ((5 / 4) * Math.pow(n,2)) + ((5 / 4) * Math.pow(n,3))) * (PHI - PHI0)) 
    - (((3 * n) + (3 * Math.pow(n,2)) + ((21 / 8) * Math.pow(n,3))) * (Math.sin(PHI - PHI0)) * (Math.cos(PHI + PHI0))) 
    + ((((15 / 8) * Math.pow(n,2)) + ((15 / 8) * Math.pow(n,3))) * (Math.sin(2 * (PHI - PHI0))) * (Math.cos(2 * (PHI + PHI0))))
    - (((35 / 24) * Math.pow(n,3)) * (Math.sin(3 * (PHI - PHI0))) * (Math.cos(3 * (PHI + PHI0)))));

}

function de_ra(val) {
var pi = Math.PI;
return ((val)*(pi/180));
}

function setlonglat()
{
	var sel = document.forms[0].matchplacenames.selectedIndex;
	var placedetails = document.forms[0].matchplacenames.options[sel].value.split(",");
	
	document.forms[0].place_name.value = placedetails[0];
	document.forms[0].lat_plus.selectedIndex = placedetails[1]<0?1:0;
	document.forms[0].long_plus.selectedIndex = placedetails[4]<0?1:0;

	if(placedetails[1]<0)
		document.forms[0].lat_deg.value = placedetails[1].substr(1);
	else
		document.forms[0].lat_deg.value = placedetails[1];

	if(placedetails[4]<0)
		document.forms[0].long_deg.value = placedetails[4].substr(1);
	else
		document.forms[0].long_deg.value = placedetails[4];
	
	document.forms[0].lat_mins.value = placedetails[2];
	document.forms[0].lat_secs.value = placedetails[3];
	document.forms[0].long_mins.value = placedetails[5];
	document.forms[0].long_secs.value = placedetails[6];
	

}

// End -->
