
function submitSearchForm(form_name) {
	if ((document.forms[form_name].originalsearch.value == null) ||
		(document.forms[form_name].originalsearch.value.search(/^\W*$/) != -1)) {
		alert("Please insert keyword(s) before submitting search");
		return false;
	}

	var newSubmit=document.forms[form_name].originalsearch.value;
	document.forms[form_name].freesearch.value=insertAND(newSubmit);

	document.forms[form_name].submit();
}

function submitSearch() {
	return submitSearchForm('sitesearch');
}


function submitAgain() {
	return submitSearchForm('searchagain');
}

function selectStartOption(opt,startType){
	today=new Date();
	switch (opt)
	{
	case "1":
	/*today*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=0;

		break;
		
	case "2":
	/*tomorrow*/
		var oneDay=1000*60*60*24;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneDay);
		fromDay=nextday.getDate()-1;
		fromMonth=nextday.getMonth()-today.getMonth();
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;
	case "3": {
		/*next weekend */
		var oneDay=1000*60*60*24;
		var daysahead;
		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);
		fromDay=saturday.getDate()-1;
		fromMonth=0;
		toDay=sunday.getDate()-1;
		toMonth=sunday.getMonth()-saturday.getMonth();

		break;	
		}
	case "4":
	/*nextweek*/
		var oneWeek=1000*60*60*24*7;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneWeek);
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;	
	case "5":
	/*next month*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=1;
		break;	
	case "6":
	/*next three month*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=3;
		break;	
	case "7":
	/*next nine month*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=9;
		break;	
	default:
		fromDay=-1;
		fromMonth=-1;
		toDay=-1;
		toMonth=-1;
		break;

	}

	if (startType==1 ) { 
		document.campSearchForm.fromDaySearch.selectedIndex=fromDay;
		document.campSearchForm.fromMonthSearch.selectedIndex=fromMonth;
		document.campSearchForm.toDaySearch.selectedIndex=toDay;
		document.campSearchForm.toMonthSearch.selectedIndex=toMonth;
		document.campSearchForm.dateSearch.selectedIndex=opt-1;
	}
	else {	
		document.getElementById["fromDaySearch"].value=fromDay;
		document.getElementById["fromMonthSearch"].value=fromMonth;
		document.getElementById["toDaySearch"].value=toDay;
		document.getElementById["toMonthSearch"].value=toMonth;
	}
}


function selectOption(opt,startType){

	today=new Date();
	switch (opt)
	{
	case "1":
	/*today*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=0;

		break;
		
	case "2":
	/*tomorrow*/
		var oneDay=1000*60*60*24;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneDay);
		fromDay=nextday.getDate()-1;
		fromMonth=nextday.getMonth()-today.getMonth();
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;
	case "3": {
		/*next weekend */
		var oneDay=1000*60*60*24;
		var daysahead;
		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);
		fromDay=saturday.getDate()-1;
		fromMonth=0;
		toDay=sunday.getDate()-1;
		toMonth=sunday.getMonth()-saturday.getMonth();

		break;	
		}
	case "4":
	/*nextweek*/
		var oneWeek=1000*60*60*24*7;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneWeek);
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;	
	case "5":
	/*next month*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=1;
		break;	
	case "6":
	/*next three months*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=3;
		break;
	case "7":
	/*next nine months*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=9;
		break;
			
	default:
		fromDay=-1;
		fromMonth=-1;
		toDay=-1;
		toMonth=-1;
		break;

	}

	if (startType==1 ) { 
		document.all["fromDaySearch"].selectedIndex=fromDay;
		document.all["fromMonthSearch"].selectedIndex=fromMonth;
		document.all["toDaySearch"].selectedIndex=toDay;
		document.all["toMonthSearch"].selectedIndex=toMonth;
	}
	else {	
		document.all["fromDaySearch"].value=fromDay;
		document.all["fromMonthSearch"].value=fromMonth;
		document.all["toDaySearch"].value=toDay;
		document.all["toMonthSearch"].value=toMonth;
	}
}

function selectOption(opt,startType, form){
	today=new Date();
	switch (opt)
	{
	case "1":
	/*today*/
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=0;

		break;
		
	case "2":
	/*tomorrow*/
		var oneDay=1000*60*60*24;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneDay);
		fromDay=nextday.getDate()-1;
		fromMonth=nextday.getMonth()-today.getMonth();
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;
	case "3": {
		/*next weekend */
		var oneDay=1000*60*60*24;
		var daysahead;
		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);
		fromDay=saturday.getDate()-1;
		fromMonth=0;
		toDay=sunday.getDate()-1;
		toMonth=sunday.getMonth()-saturday.getMonth();

		break;	
		}
	case "4":
	/*nextweek*/
		var oneWeek=1000*60*60*24*7;
		nextday=new Date();
		todayInMs=today.getTime();
		nextday.setTime(todayInMs+oneWeek);
		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=nextday.getDate()-1;
		toMonth=nextday.getMonth()-today.getMonth();
		break;	
	case "5":
	/*next month*/

		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=1;
		break;	
	case "6":
	/*next three months*/

		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=3;
		break;	
	case "7":
	/*next nine months*/

		fromDay=today.getDate()-1;
		fromMonth=0;
		toDay=today.getDate()-1;
		toMonth=9;
		break;	
		
	default:
		fromDay=-1;
		fromMonth=-1;
		toDay=-1;
		toMonth=-1;
		break;

	}

	if (startType==1 ) { 
		form.fromDaySearch.selectedIndex=fromDay;
		form.fromMonthSearch.selectedIndex=fromMonth;
		form.toDaySearch.selectedIndex=toDay;
		form.toMonthSearch.selectedIndex=toMonth;
	}
	else {	
		form.fromDaySearch.value=fromDay;
		form.fromMonthSearch.value=fromMonth;
		form.toDaySearch.value=toDay;
		form.toMonthSearch.value=toMonth;
	}

	
}

function compareDates(fromDay,fromMonth,toDay,toMonth){

	mDay=fromDay.value;
	mMonth=parseInt(fromMonth.value.substring(0,2),10)-1;
	mYear=parseInt('20'+fromMonth.value.substring(3,5),10);
	var FromDate=new Date(mYear,mMonth,mDay);
	
	mDay=toDay.value;
	mMonth=parseInt(toMonth.value.substring(0,2),10)-1;
	mYear=parseInt('20'+toMonth.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()));
}

function findTowns(form, forward) {
form.forward.value = forward;
form.searchMode.value = "2";
form.submit();
}

function setOffset(form, offset) {
form.offset.value=offset;
form.submit();
}


function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true					
	}

function validateAddress(){
	var emailID=document.newsletter.email;
//	alert(emailId);
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }

 function newImage(arg) {
	if (document.images) {
		resultImage = new Image();
		resultImage.src = arg;
		return resultImage;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
	
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {

	if (document.images) {
	
		topbar = newImage("images/topbar.jpg");
		quicklinkstab = newImage("images/quicklinkstab.jpg");
		menuseparator = newImage("images/menu_separator.jpg");
		kidscamp = newImage("images/kidscamp.jpg");
		advertisewithus = newImage("images/advertisewithus.jpg");

		gleneagle_small = newImage("images/gleneagle_small.jpg");
		wagamama = newImage("images/wagamama.jpg");
		irishmap = newImage("images/irish-map.gif");
		killarneysummerfest = newImage("images/killarneysummerfest.jpg");
	
		disneyonice = newImage("images/disneyonice.jpg");
		fossettscircus = newImage("images/fossettscircus.jpg");
		bookadholder = newImage("images/bookadholder.jpg");
		hblogo = newImage("images/hblogo.jpg");
		cul4kids = newImage("images/cul4kids.jpg");

		mcdonalds = newImage("images/mcdonalds.jpg");
		omniplex = newImage("images/omniplex.jpg");
		smyths = newImage("images/smyths.jpg");
		longtextad = newImage("images/longtextad.gif");
		
		preloadFlag = true;
	}
}	
/*------------------------------------------------------------------*/
/**
 *
 * Method to validate length of text.
 *
 */
/*------------------------------------------------------------------*/

function validateLength(inputElement, length) {
    if (inputElement.value.length > length) inputElement.value = inputElement.value.substring(0, length);
}
	
/*------------------------------------------------------------------*/
/**
 *
 * Method to validate numeric fields, to not allowed
 * press wrong character. It checks only last character,
 * because it is going to be used on.
 *
 */
/*------------------------------------------------------------------*/
function validateNumeric(inputElement) {
    
    if ((inputElement.value != null) && (inputElement.value != "")) {

        var character = inputElement.value.charAt(inputElement.value.length - 1);
        
        if (character == '0') {
        } else if (character == '1') {
        } else if (character == '2') {
        } else if (character == '3') {
        } else if (character == '4') {
        } else if (character == '5') {
        } else if (character == '6') {
        } else if (character == '7') {
        } else if (character == '8') {
        } else if (character == '9') {
        } else if (character == '.') {
        } else if (character == ',') {
        } else inputElement.value = inputElement.value.substring(0, inputElement.value.length - 1);
    }
}

function validateAddForm(form, mode){
	var message = "";
	var category="";
	var includeStartDate = false;
	var includeEndDate = false;
	
	for (var i=0; i < form.category.length; i++)   {
	   if (form.category[i].checked)  {
	      	category = form.category[i].value;
	      
	   }
	}
	
	if (category=="3" || category =="8" || category =="9" ||category == "20") {
		form.includeStartDateText.value = "2";
		form.includeEndDateText.value = "2";
     	includeStartDate = true;
     	includeEndDate = true;

	}
	else {
		form.includeStartDateText.value = "1";
		form.includeEndDateText.value = "1";
		includeStartDate = false;
		includeEndDate = false;
	}

if (category=="6") {
		form.categoriesListSelection.value = "125";
	}
	else if (category == "7") {
		form.categoriesListSelection.value = "32";
	}
	else if (category == "8") {
		form.categoriesListSelection.value = "120";
	}
	else if (category == "9") {
		form.categoriesListSelection.value = "143";
		
	}
	else {
		form.categoriesListSelection.value = form.categoriesListSearch.value;
	}	


	//validate Name
	var nameString = form.addName.value;
	nameString = trim(nameString);
	if (nameString.length == 0) {
		message = addMessage(message, "Name cannot be blank");
	}

	
	// validate Short Description
//	var summaryString = form.addShortDescription.value;
//	summaryString = trim(summaryString);
//	if (summaryString.length == 0) {
//		message = addMessage(message,"Summary cannot be blank");
//	}	
	

	if (includeStartDate) {

		form.includeStartDateText.value = "2";
		//validate the dates
		var fromDay = form.fromDaySearch;
		var fromMonth =  form.fromMonthSearch;
		if (!checkValidDate(fromDay,fromMonth)){
			message = addMessage(message + "Start date is not a valid  date.");
		}
	}
	else {
		form.includeStartDateText.value = "1";
	}
	if (includeEndDate) {
		form.includeEndDateText.value = "2";
		var toDay = form.toDaySearch;
		var toMonth =  form.toMonthSearch;
	
		if (!checkValidDate(toDay,toMonth)){
			message = addMessage("End date is not a valid date.");
		}
	}
	else {
		form.includeEndDateText.value = "1";
	}
	if (includeStartDate && includeEndDate) {
		if (!compareDates(fromDay,fromMonth,toDay,toMonth)){
			message = addMessage(message, "The start date is after the end date.");
		}
	}	
	//validate the county
	var countySearch = form.countySearch.value;
	if( countySearch=="999999999") {
		message = addMessage(message, "Please select a location.");
	}
	//validate the town
	var townSearch = form.townSearch.value;
	if( townSearch=="999999999") {
		message = addMessage(message, "Please select a town.");
	}
	//validate the category
	var categorySearch = form.categoriesListSelection.value;
	if( categorySearch=="999999999") {
		message = addMessage(message, "Please select a category.");
	}
	//validate Email address
	var email = form.addEmailAddress.value;
	email = trim(email);
	if (email.length>0) {
		if (!validateEmailAddress(email)) {
			message = addMessage(message, "Invalid e-mail address.")
		}
	}
	
	//validate the age
	var fromAgeString = form.addMinimumAge.value;
	var toAgeString = form.addMaximumAge.value;
	var fromAge = 0;
	var toAge = 14;
	if (fromAgeString.length>0) {
		fromAge = parseInt(fromAgeString);
		if (fromAge < 0 && fromAge > 14) {
			message = addMessage(message, "Minimum age should be between 0 and 14");
		}
		
	}
	if (toAgeString.length>0) {
		toAge = parseInt(toAgeString);
		if (toAge < 0 || toAge > 14) {
			message = addMessage(message, "Maximum age should be between 0 and 14");
		}
	}
	if (fromAge != 0 || toAge !=14) {
		if (!validateAge(fromAge, toAge)) {
			message = addMessage(message, "Minimum age should be less than the maximum age");
		}
	}
	if (message.length>0) {
		alert(message);
		return false;
	}
	return true;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. 
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function addMessage (message, messageString) {
	if (message.length > 0) { 
		message = message + "\r\n";
	}
	message = message + messageString;
	return message;
}

function validateEmailAddress(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var valid = true;		

		if (str.indexOf(at)==-1){
		   valid = false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   valid = false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    valid = false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    valid = false;
		 } 

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    valid = false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    valid = false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    valid = false;
		 }

 		 return valid;					
	}
	
	function validateAge (fromAge, toAge) {
		var valid=true;
		if (fromAge>toAge) {
			valid = false;
		}
		return valid;
	}

	function validateRegistration (form) {
		var message = "";
		//validate Email address
		var email = form.registerEMailAddress.value;
		email = trim(email);
		if (email.length>0) {
			if (!validateEmailAddress(email)) {
				message = addMessage(message, "Invalid e-mail address.")
			}
		}
		else {
			message = addMessage(message, "Please enter an e-mail address")
		}
		
		//validate the passwords
		var pass = form.password.value;
		var verifyPass = form.verifyPassword.value;
		
		pass = trim(pass);
		if (pass.length == 0) {
			message = addMessage(message, "Please enter a password");
		}
		
		verifyPass = trim(verifyPass)
		if (verifyPass.length == 0) {
			message = addMessage(message, "Please verify your password");
		}
		
		if (pass.length > 0 & verifyPass.length > 0) {
			if (pass != verifyPass) {
				message = addMessage(message, "Password and password verification are not the same");
			}
		}
		if (message.length>0) {
			alert(message);
			return false;
		}
		return true;
		
	} 
	
	function validateSignin (form) {
		var message = "";
		//validate Email address
		var email = form.loginEMailAddress.value;
		email = trim(email);
		if (email.length>0) {
			if (!validateEmailAddress(email)) {
				message = addMessage(message, "Invalid e-mail address.")
			}
		}
		else {
		
			message = addMessage(message, "Please enter an e-mail address")

		}
		
		var pass = form.loginPassword.value;
		pass = trim(pass);
		if (pass.length==0) {
			message = addMessage(message, "Please enter a password")

		}
		
		if (message.length>0) {
			alert(message);
			return false;
		}
		return true;
	}
	
function validateSubcategory(form){


	var message = "";
	if (form==null) {
		form = document.activitiesAddForm;
	}
	
	//validate the category
	var categorySearch = form.categoriesListSearch.value;
	
	if( categorySearch=="999999999") {
		message = addMessage(message, "Please select a sub-category.");
	}
	if (message.length>0) {
		alert(message);
		return false;
	}
	activateNextPage();
	return true;
	
}

function validateDetails(form){
	var message = "";
	var category="";
	var includeStartDate = false;
	var includeEndDate = false;
	
	if (form==null) {
		form = document.activitiesAddForm;
	}
	
	for (var i=0; i < form.category.length; i++)   {
	   if (form.category[i].checked)  {
	      	category = form.category[i].value;
	      
	   }
	}
	
	if (category=="3" || category =="8"|| category =="9") {
     	includeStartDate = true;
     	includeEndDate = true;
	}
	else {
		includeStartDate = false;
		includeEndDate = false;
	}

	
	//validate Name
	var nameString = form.addName.value;
	nameString = trim(nameString);
	if (nameString.length == 0) {
		message = addMessage(message, "Name cannot be blank");
	}

	
	// validate Short Description
//	var summaryString = form.addShortDescription.value;
//	summaryString = trim(summaryString);
//	if (summaryString.length == 0) {
//		message = addMessage(message,"Summary cannot be blank");
//	}	
	

	if (includeStartDate) {

		form.includeStartDateText.value = "2";
		//validate the dates
		var fromDay = form.fromDaySearch;
		var fromMonth =  form.fromMonthSearch;
		if (!checkValidDate(fromDay,fromMonth)){
			message = addMessage(message + "Start date is not a valid  date.");
		}
	}
	else {
		form.includeStartDateText.value = "1";
	}
	if (includeEndDate) {
		form.includeEndDateText.value = "2";
		var toDay = form.toDaySearch;
		var toMonth =  form.toMonthSearch;
	
		if (!checkValidDate(toDay,toMonth)){
			message = addMessage("End date is not a valid date.");
		}
	}
	else {
		form.includeEndDateText.value = "1";
	}
	if (includeStartDate && includeEndDate) {
		if (!compareDates(fromDay,fromMonth,toDay,toMonth)){
			message = addMessage(message, "The start date is after the end date.");
		}
	}	
	//validate the county
	var countySearch = form.countySearch.value;
	if( countySearch=="999999999") {
		message = addMessage(message, "Please select a location.");
	}
	//validate the town
	var townSearch = form.townSearch.value;
	if( townSearch=="999999999") {
		message = addMessage(message, "Please select a town.");
	}
	
	//validate the age
	var fromAgeString = form.addMinimumAge.value;
	var toAgeString = form.addMaximumAge.value;
	var fromAge = 0;
	var toAge = 14;
	if (fromAgeString.length>0) {
		fromAge = parseInt(fromAgeString);
		if (fromAge < 0 && fromAge > 14) {
			message = addMessage(message, "Minimum age should be between 0 and 14");
		}
		
	}
	if (toAgeString.length>0) {
		toAge = parseInt(toAgeString);
		if (toAge < 0 || toAge > 14) {
			message = addMessage(message, "Maximum age should be between 0 and 14");
		}
	}
	if (fromAge != 0 || toAge !=14) {
		if (!validateAge(fromAge, toAge)) {
			message = addMessage(message, "Minimum age should be less than the maximum age");
		}
	}
	if (message.length>0) {
		alert(message);
		return false;
	}
	


	activateNextPage();
	return true;
}

function activateNextPage() {
	var pageNumber = document.activitiesAddForm.addPage.value;

	if (pageNumber == "1") {
		for (var i=0; i < document.activitiesAddForm.category.length; i++)   {
		   if (document.activitiesAddForm.category[i].checked)  {
		      	category = document.activitiesAddForm.category[i].value;
		      
		   }
		}
		if (category=="1" || category == "2" || category=="3" || category == "4" || category =="5"){
			document.activitiesAddForm.addPage.value = "2";
		}
		else {
			document.activitiesAddForm.addPage.value = "3";		
		}
	}
	else {
		if (pageNumber=="2") {
			document.activitiesAddForm.addPage.value = "3";		
		
		}
		else {
			if (pageNumber=="3") {
				document.activitiesAddForm.addPage.value = "4";		
			
			}
			else {
				if (pageNumber=="4") {
					document.activitiesAddForm.addPage.value = "5";		
				
				}
				else {
					if (pageNumber=="5") {
						document.activitiesAddForm.addPage.value = "6";		
					
					}
				}
			}
		}
	}
	activatePage();
}

function activatePreviousPage() {
	var pageNumber = document.activitiesAddForm.addPage.value;

	if (pageNumber == "3") {
		for (var i=0; i < document.activitiesAddForm.category.length; i++)   {
		   if (document.activitiesAddForm.category[i].checked)  {
		      	category = document.activitiesAddForm.category[i].value;
		      
		   }
		}
		if (category=="1" || category == "2" || category=="3" || category == "4" || category == "5"){
			document.activitiesAddForm.addPage.value = "2";
		}
		else {
			document.activitiesAddForm.addPage.value = "1";		
		}
	}
	else {
		if (pageNumber=="2") {
			document.activitiesAddForm.addPage.value = "1";		
		}
		else {
			if (pageNumber=="4") {
				document.activitiesAddForm.addPage.value = "3";		
			}
			else {
				if (pageNumber=="5") {
					document.activitiesAddForm.addPage.value = "4";		
				}
				else {
					if (pageNumber=="6") {
						document.activitiesAddForm.addPage.value = "5";		
					}
				
				}
				
			}
		}
	}
	activatePage();
}



function activatePage() {
	var pageNumber = document.activitiesAddForm.addPage.value;

	if (pageNumber == null || pageNumber =="1") {
		document.getElementById("selectCategory").style.display = "block";
		document.getElementById("selectCategoryList").style.display = "none";
		document.getElementById("enterDetails").style.display = "none";
		document.getElementById("enterImages").style.display = "none";
	    document.getElementById("description1").style.display = "none";
		document.getElementById("contactDetails").style.display = "none";
	}
	if (pageNumber == "2") {
		document.getElementById("selectCategory").style.display = "none";
		document.getElementById("selectCategoryList").style.display = "block";
		document.getElementById("enterDetails").style.display = "none";
		document.getElementById("enterImages").style.display = "none";
	    document.getElementById("description1").style.display = "none";
		document.getElementById("contactDetails").style.display = "none";
	}
	if (pageNumber == "3") {
		document.getElementById("selectCategory").style.display = "none";
		document.getElementById("selectCategoryList").style.display = "none";
		document.getElementById("enterDetails").style.display = "block";
		document.getElementById("enterImages").style.display = "none";
	    document.getElementById("description1").style.display = "none";
		document.getElementById("contactDetails").style.display = "none";
	}
	if (pageNumber == "4") {
		document.getElementById("selectCategory").style.display = "none";
		document.getElementById("selectCategoryList").style.display = "none";
		document.getElementById("enterDetails").style.display = "none";
		document.getElementById("enterImages").style.display = "block";
	    document.getElementById("description1").style.display = "none";
		document.getElementById("contactDetails").style.display = "none";

	}
	if (pageNumber == "5") {
		document.getElementById("selectCategory").style.display = "none";
		document.getElementById("selectCategoryList").style.display = "none";
		document.getElementById("enterDetails").style.display = "none";
		document.getElementById("enterImages").style.display = "none";
	    document.getElementById("description1").style.display = "block";
		document.getElementById("contactDetails").style.display = "none";
	}
	if (pageNumber == "6") {
		document.getElementById("selectCategory").style.display = "none";
		document.getElementById("selectCategoryList").style.display = "none";
		document.getElementById("enterDetails").style.display = "none";
		document.getElementById("enterImages").style.display = "none";
	    document.getElementById("description1").style.display = "none";
		document.getElementById("contactDetails").style.display = "block";
	}
}

function validateDescription(form){
	var message = "";
	if (form==null) {
		form = document.activitiesAddForm;
	}
	
	//validate the category
	var descriptionString = form.addLongDescription.value;
	descriptionString = trim(descriptionString);
	if (descriptionString.length == 0) {
		message = addMessage(message, "Description cannot be blank");
	}
	if (message.length>0) {
		alert(message);
		return false;
	}
	activateNextPage();
	return true;
	
}
function validateContactDetails(form){
	var message = "";
	if (form==null) {
		form = document.activitiesAddForm;
	}
	
	//validate the address
	//validate Email address
	var email = form.addEmailAddress.value;
	email = trim(email);
	if (email.length>0) {
		if (!validateEmailAddress(email)) {
			message = addMessage(message, "Invalid e-mail address.")
		}
	}
	else {
		message = addMessage(message, "E-mail address cannot be blank.")
	
	}
	
	//validate the address
	var addressString = form.addAddress.value;
	addressString = trim(addressString);
	if (addressString.length == 0) {
		message = addMessage(message, "Address cannot be blank");
	}
	//validate the telephone
	var telephoneString = form.addTelephone.value;
	telephoneString = trim(telephoneString);
	if (telephoneString.length == 0) {
		message = addMessage(message, "Telephone cannot be blank");
	}

	if (message.length>0) {
		alert(message);
		return false;
	}

	return true;
	
}
	