function Popup(URL)
{
if(URL.length > 0){
window.open(URL);
}
}

function ViewMap(pc)
{
url='http://maps.google.co.uk/maps?hl=en&q='+pc;
Popup(url);
}

function toggleAll()
{
setAllOn(document.all["cbAll"].checked);
}

function toggleAllOff()
{
document.all["cbAll"].checked=false;

}

function setAllOn(on){

document.all["cbTheatre"].checked=false;
document.all["cbFetes"].checked=false;
document.all["cbGardens"].checked=false;
document.all["cbWildlife"].checked=false;
document.all["cbFamily"].checked=false;
document.all["cbSporting"].checked=false;
document.all["cbMusical"].checked=false;
document.all["cbArt"].checked=false;
document.all["cbLocal"].checked=false;
document.all["cbHistory"].checked=false;
document.all["cbExhibitions"].checked=false;
document.all["cbFood"].checked=false;
document.all["cbTraining"].checked=false;
document.all["cbSales"].checked=false;
document.all["cbFunfairs"].checked=false;
}
function clickNonSelect(){
document.all["ddlFromDay"].selectedIndex=-1;
document.all["ddlFromMonth"].selectedIndex=-1;
document.all["ddlToDay"].selectedIndex=-1;
document.all["ddlToMonth"].selectedIndex=-1;
}

function clickNonSelect1(){
today=new Date();
document.all["ddlFromDay"].selectedIndex=today.getDate()-1;
document.all["ddlFromMonth"].selectedIndex=0;
document.all["ddlToDay"].selectedIndex=today.getDate()-1;
document.all["ddlToMonth"].selectedIndex=0;
}

function clickNonSelect2(){
var oneDay=1000*60*60*24;
today=new Date();
nextday=new Date();
todayInMs=today.getTime();
nextday.setTime(todayInMs+oneDay);
document.all["ddlFromDay"].selectedIndex=nextday.getDate()-1;
document.all["ddlToDay"].selectedIndex=nextday.getDate()-1;
if (nextday.getMonth()==today.getMonth())
{
document.all["ddlFromMonth"].selectedIndex=0;
document.all["ddlToMonth"].selectedIndex=0;
}else{
document.all["ddlFromMonth"].selectedIndex=1;
document.all["ddlToMonth"].selectedIndex=1;
}
}

function clickNonSelect7(){
var oneWeek=1000*60*60*24*7;
today=new Date();
nextday=new Date();
todayInMs=today.getTime();
nextday.setTime(todayInMs+oneWeek);
document.all["ddlFromDay"].selectedIndex=today.getDate()-1;
document.all["ddlFromMonth"].selectedIndex=0;
document.all["ddlToDay"].selectedIndex=nextday.getDate()-1;
if (nextday.getMonth()==today.getMonth())
{
	document.all["ddlToMonth"].selectedIndex=0;
}else{
	document.all["ddlToMonth"].selectedIndex=1;
}
}

function clickNonSelect28(){
var oneWeek=1000*60*60*24*7;
today=new Date();
nextday=new Date();
todayInMs=today.getTime();
nextday.setTime(todayInMs+(oneWeek*4));
document.all["ddlFromDay"].selectedIndex=today.getDate()-1;
document.all["ddlFromMonth"].selectedIndex=0;
document.all["ddlToDay"].selectedIndex=nextday.getDate()-1;
if (nextday.getMonth()==today.getMonth())
{
	document.all["ddlToMonth"].selectedIndex=0;
}else{
	document.all["ddlToMonth"].selectedIndex=1;
}
}

function clickNonSelect8(){
var oneDay=1000*60*60*24;
var daysahead;
today=new Date();
switch (today.getDay())
{
case 0:
	daysahead=6;
	break;
case 6:
	daysahead=7;
	break;
default:
	daysahead=6-today.getDay()
	break;
	
}
saturday=new Date();
sunday=new Date();
todayInMs=today.getTime();
saturday.setTime(todayInMs+(daysahead*oneDay));
sunday.setTime(todayInMs+(daysahead*oneDay)+oneDay);
document.all["ddlFromDay"].selectedIndex=saturday.getDate()-1;
document.all["ddlToDay"].selectedIndex=sunday.getDate()-1;
if (saturday.getMonth()==today.getMonth()){
document.all["ddlFromMonth"].selectedIndex=0;
}else{
document.all["ddlFromMonth"].selectedIndex=1;
}
if (sunday.getMonth()==today.getMonth()){
document.all["ddlToMonth"].selectedIndex=0;
}else{
document.all["ddlToMonth"].selectedIndex=1;
}
}

function clickNonSelect30(){
	today=new Date();
	document.all["ddlFromDay"].selectedIndex=today.getDate()-1;
	document.all["ddlFromMonth"].selectedIndex=0;
	monthPlus1=new Date().getMonth();
	if (monthPlus1==12)
	{
		monthPlus1=0;
	}
	nextMonth=new Date();
	nextMonth.setMonth(nextMonth.getMonth()+1);
	document.all["ddlToDay"].selectedIndex=nextMonth.getDate()-1;
	if (monthPlus1==nextMonth)
	{
		document.all["ddlToMonth"].selectedIndex=1;
	}
	else
	{
		document.all["ddlToMonth"].selectedIndex=2;
	}
}

function clickDate(nFlag){
document.all["rbSelect"].checked=true;
}

function formvalidate(){
if (document.all["rbSelect"].checked){
	if (!checkValidDate(document.all["ddlFromDay"],document.all["ddlFromMonth"])){
		alert("Please correct the 'From' date.");
		return false;	
	}else{
		if (!checkValidDate(document.all["ddlToDay"],document.all["ddlToMonth"])){
		alert("Please correct the 'To' date.");
			return false;
		}
	}
	if (!CompareDates()){
		alert("'From' date is after 'To' date.");
		return false;
	}
}
return true;
}

function CompareDates(){
mDay=document.all["ddlFromDay"].value;
mMonth=parseInt(document.all["ddlFromMonth"].value.substring(0,2),10)-1;
mYear=parseInt('20'+document.all["ddlFromMonth"].value.substring(3,5),10);
var FromDate=new Date(mYear,mMonth,mDay);

mDay=document.all["ddlToDay"].value;
mMonth=parseInt(document.all["ddlToMonth"].value.substring(0,2),10)-1;
mYear=parseInt('20'+document.all["ddlToMonth"].value.substring(3,5),10);
var ToDate=new Date(mYear,mMonth,mDay);
return (FromDate<=ToDate)
}

function checkValidDate(oDay,oMonth){
mDay=oDay.value;
mMonth=parseInt(oMonth.value.substring(0,2),10)-1;
mYear=parseInt('20'+oMonth.value.substring(3,5),10);
var thisDate=new Date(mYear,mMonth,mDay);
return ((mDay==thisDate.getDate()) && (mMonth==thisDate.getMonth()) 
&& (mYear==thisDate.getFullYear()));
}

