Ajax.Request.prototype.abort = function() {
	// prevent and state change callbacks from being issued
	this.transport.onreadystatechange = Prototype.emptyFunction;
	// abort the XHR
	this.transport.abort();
	// update the request counter
	Ajax.activeRequestCount--;
	if (Ajax.activeRequestCount < 0) {
		Ajax.activeRequestCount = 0;
	}
};

var dropDown_countries;
var dropDown_regions;
var dropDown_islands;
var dropDown_locations;
var curAjaxReques;
var rss;
var destination = 0;

Config = {
	CSS_dropDownMenuLink:'msDropDownMenuLink',
	CSS_dropDownMainMenuPad:'msDropDownMenu',
	CSS_dropDownMainMenuPadHover:'msDropDownMenu',//Hover',
	CSS_dropDownChildMenuPad:'MS_ChildMenuPad'
};

MsgCountries = {
	choosen: new Hash({empty:'Please select a Country', choose:'Countries', all:'All Countries ', mixed:'Preferred Countries '})
};
MsgIslands = {
	choosen: new Hash({empty:'Please select a Island', choose:'Islands', all:'All Islands ', mixed:'Preferred Islands '})
};
MsgRegions = {
	choosen: new Hash({empty:'Please select a Region', choose:'Regions', all:'All Regions ', mixed:'Preferred Regions '})
};
MsgLocations = {
	choosen: new Hash({empty:'Please select a Location', choose:'Locations', all:'All Locations ', mixed:'Preferred Locations '})
};

function initMasterSite() {
	setCurrentMenu();
	dropDown_countries = new CustomComponents.DropDownMenu('searchCountries');
	dropDown_regions = new CustomComponents.DropDownMenu('searchRegions');
	dropDown_islands = new CustomComponents.DropDownMenu('searchIslands');
	dropDown_locations = new CustomComponents.DropDownMenu('searchLocations');
	dropDown_countries.create(selectCountries, loadRegions, "checkbox", {Messages:MsgCountries, MsgCurrent:'empty'});
	dropDown_regions.create(selectRegions, loadIslandsLocations, "checkbox", {Messages:MsgRegions, InactiveCss:'msDropDown_grey'});
	dropDown_islands.create(selectIslands, loadLocations, "checkbox", {Messages:MsgIslands, InactiveCss:'msDropDown_grey'});
	dropDown_locations.create(selectLocations, '', "checkbox", {Messages:MsgLocations, InactiveCss:'msDropDown_grey'});
}

function resetSearchForm() {
	var subMenus = $('searchForm').getElementsByClassName('MS_ChildMenuPad');
	if (subMenus) {
		for (var i=0; i<subMenus.length; i++) {
			subMenus[i].hide();
		}
	}
	subMenus = $('searchForm').getElementsByClassName('MS_ChildMenuPad2');
	if (subMenus) {
		for (var i=0; i<subMenus.length; i++) {
			subMenus[i].hide();
		}
	}
	dropDown_countries.create(selectCountries, loadRegions, "checkbox", {Messages:MsgCountries, MsgCurrent:'empty'});
	dropDown_regions.create(selectRegions, loadIslandsLocations, "checkbox", {Messages:MsgRegions, InactiveCss:'msDropDown_grey'});
	dropDown_islands.create(selectIslands, loadLocations, "checkbox", {Messages:MsgIslands, InactiveCss:'msDropDown_grey'});
	dropDown_locations.create(selectLocations, '', "checkbox", {Messages:MsgLocations, InactiveCss:'msDropDown_grey'});
	$('searchForm').reset();
	$('itemName').value = '';
	$('resortsSelected').checked = true;
}

function isValidEmail(str) {
	return str.match(new RegExp("^([a-zA-Z0-9_]|\\-|\\.)+@(([a-zA-Z0-9_]|\\-)+\\.)+[a-zA-Z]{2,4}$"));
}

function checkFields() {
	var i, a=checkFields.arguments;
	for(i=0;i<a.length;i++) {
		var obj = $(a[i]);
		if(obj && !obj.value.length) {
			alert("Empty field '"+obj.name+"'");
			return false;
		}
		if (obj && obj.name.match(/(.*?)email(.*?)/i)) {
			if (!isValidEmail(obj.value)) {
				alert("Wrong email format");
				return false;
			}
		}
	}
	return true;
}

function checkJoinForm() {
	if (!checkFields('FName','LName','UName','EMail','EMail2','pwd1','pwd2','code')) {
		return false;
	}
	if ($('EMail').value!=$('EMail2').value) {
		alert("EMail addresses do not match");
		return false;
	}
	if ($('pwd1').value!=$('pwd2').value) {
		alert("Password and Confirm Password fields do not match");
		return false;
	}
	if ($('pwd1').value.length<6) {
		alert("Please enter a password at least six characters in length");
		return false;
	}
	if (!$('accepterms').checked) {
		alert("You must agree to the legal terms");
		return false;
	}
	emailJoinForm();
	return false;
}

function emailJoinForm() {
	var params = $('join').serialize(true);
	new Ajax.Request('/members',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var responseJS = transport.responseText.evalJSON();
			if (!responseJS.success) {
				alert(responseJS.content);
			} else {
				if (responseJS.login && responseJS.password) {
					new Ajax.Request('/blog/wp-ajaxlogin.php',
					{
						method: 'post',
						parameters: {
							action: 'login',
							log: responseJS.login,
							pwd: responseJS.password
						},
						onSuccess: function() {
							window.location.href = "/members/success";
						}
					});
				}
			}
		}
	});
}

function checkSettings() {
	var old = $('curpwd').value;
	if (!old.length) {
		// nothing to test
		return true;
	}
	if (old.length<6) {
		alert("Password should be at least six characters in length");
		return false;
	}
	if ($('pwd1').value!=$('pwd2').value) {
		alert("Password and Confirm Password fields do not match");
		return false;
	}
	if ($('pwd1').value.length<6) {
		alert("Please enter a password at least six characters in length");
		return false;
	}
	return true;
}

function loadRegions(porop) {
	if (!porop.items.length) return;
	$('searchLocations').innerHTML = "Locations";
	dropDown_locations.create([], '', "checkbox", {Messages:MsgLocations, InactiveCss:'msDropDown_grey'});
	//$('searchLocations').addClassName('msDropDown_grey');
	$('searchIslands').innerHTML = "Islands";
	dropDown_islands.create([], loadLocations, "checkbox", {Messages:MsgIslands, InactiveCss:'msDropDown_grey'});
	//$('searchIslands').addClassName('msDropDown_grey');
	if (!porop.checked.length) {
		$('searchRegions').innerHTML = "Regions";
		dropDown_regions.create([], loadIslandsLocations, "checkbox", {Messages:MsgRegions, InactiveCss:'msDropDown_grey'});
		//$('searchRegions').addClassName('msDropDown_grey');
		return;
	}
	var parents = [];
	porop.checked.each( function(item) {
		parents.push(item.value);
	});
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
		method: 'post',
		parameters: {
			m: 'areasearch',
			action: 'getCombo',
			type: 'region',
			parent: parents.toString()
		},
		onSuccess: function(transport){
			var tmp = transport.responseText.evalJSON();
			dropDown_regions.create(tmp, loadIslandsLocations, "checkbox", {Messages:MsgRegions, MsgCurrent:'empty'});
			$('searchRegions').removeClassName('msDropDown_grey');
		},
		onFailure: function() {}
	});
}

function loadIslandsLocations(porop) {
	// collect selected regions and islands
	var together = [];
	var tmp1 = $('searchRegions').select('input[type=checkbox]');
	if (tmp1 && tmp1.length) {
		tmp1.each( function(item) {
			if (item.checked) {
				together.push(item.value);
			}
		});
	}
	var tmp2 = $('searchIslands').select('input[type=checkbox]');
	if (tmp2 && tmp2.length) {
		tmp2.each( function(item) {
			if (item.checked) {
				together.push(item.value);
			}
		});
	}
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
		method: 'post',
		parameters: {
			m: 'areasearch',
			action: 'getCombo2',
			parent: together.toString()
		},
		onSuccess: function(transport){
			var tmp = transport.responseText.evalJSON();
			if (tmp && tmp.islands && tmp.islands.length) {
				dropDown_islands.create(tmp.islands, loadLocations, "checkbox", {Messages:MsgIslands, MsgCurrent:'empty'});
				$('searchIslands').removeClassName('msDropDown_grey');
			}
			if (tmp && tmp.locations && tmp.locations.length) {
				dropDown_locations.create(tmp.locations, '', "checkbox", {Messages:MsgLocations, MsgCurrent:'empty'});
				$('searchLocations').removeClassName('msDropDown_grey');
			}
		},
		onFailure: function() {}
	});
}

function loadLocations(porop) {
	// collect selected regions and islands
	var together = [];
	var tmp1 = $('searchRegions').select('input[type=checkbox]');
	if (tmp1 && tmp1.length) {
		tmp1.each( function(item) {
			if (item.checked) {
				together.push(item.value);
			}
		});
	}
	var tmp2 = $('searchIslands').select('input[type=checkbox]');
	if (tmp2 && tmp2.length) {
		tmp2.each( function(item) {
			if (item.checked) {
				together.push(item.value);
			}
		});
	}
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
		method: 'post',
		parameters: {
			m: 'areasearch',
			action: 'getCombo2',
			parent: together.toString()
		},
		onSuccess: function(transport){
			var tmp = transport.responseText.evalJSON();
			/*
			if (tmp.islands) {
				dropDown_islands.create(tmp.islands, loadLocations, "checkbox", {Messages:MsgIslands});
				//$('searchIslands').removeClassName('msDropDown_grey');
			}
			*/
			if (tmp && tmp.locations && tmp.locations.length) {
				dropDown_locations.create(tmp.locations, '', "checkbox", {Messages:MsgLocations, MsgCurrent:'empty'});
				$('searchLocations').removeClassName('msDropDown_grey');
			}
		},
		onFailure: function() {}
	});
}

function setCurrentMenu() {
	var url = window.location.href;
	if (!url.match(/\/$/)) {
		url += '/';
	}
	var pathname = window.location.pathname;
	if (!pathname.match(/\/$/)) {
		pathname += '/';
	}
	var els = $('mainmenu').select('a.firstLevel');
	if (els) {
		els.each(function(item) {
			var tmp = item.href;
			if (!tmp.match(/\/$/)) {
				tmp += '/';
			}
			var tmp1 = '';
			if (item.rev.length) {
				tmp1 = window.location.protocol+'//'+window.location.host+item.rev;
			}
			if (tmp==url || tmp==pathname || tmp1==url) {
				item.up().addClassName('current');
				return;
			}
			var dEl = $(item.id).next();
			if (dEl) {
				var downEls = dEl.select('a');
				if (downEls) {
					downEls.each(function(item2) {
						var tmp2 = item2.href;
						if (!tmp2.match(/\/$/)) {
							tmp2 += '/';
						}
						var tmp3 = '';
						if (item2.rev.length) {
							tmp3 = window.location.protocol+'//'+window.location.host+item2.rev;
						}
						if (tmp2==url || tmp2==pathname || tmp3==url ) {
							item.up().addClassName('current');
							return;
						}
					});
				}
			}
		});
	}
}
function coursesPage(page) {
	if( !$("featured_list_courses_content")) {
		return;
	}
	var q = new Ajax.Request( "/nav.php",{
				method:"get",
				parameters: 'm=courses&d='+destination+'&p=' + page,
				onComplete: function(res) {
					//$("featured_list_courses").innerHTML = res.responseText;
					var responseJS = res.responseText.evalJSON();
					if (responseJS.success) {
						$("featured_list_courses_content").innerHTML = responseJS.html;
						if ($("tprev_course")) {
							$("tprev_course").onclick = function() {
								coursesPage(responseJS.prev);
							}
						}
						if ($("tnext_course")) {
							$("tnext_course").onclick = function() {
								coursesPage(responseJS.next);
							}
						}
						if ($("tpages_course")) {
							var dots = "";
							for (var i = 0; i < responseJS.pagesnum; i++) {
								if (responseJS.currpage == i) {
									dots += "	<b class='current'>&nbsp;</b>"
								} else {
									dots += "	<b>&nbsp;</b>"
								}
							}
							$("tpages_course").innerHTML = dots;
						}
					}
				}
			});
}

function resortsPage(page) {
	if( !$("featured_list_resorts_content")) {
		return;
	}
	var q = new Ajax.Request( "/nav.php",{
				method:"get",
				parameters: 'm=resorts&p=' + page,
				onComplete: function(res) {
					var responseJS = res.responseText.evalJSON();
					if (responseJS.success) {
						$("featured_list_resorts_content").innerHTML = responseJS.html;;
						if ($("tprev_resort")) {
							$("tprev_resort").onclick = function() {
								resortsPage(responseJS.prev);
							}
						}
						if ($("tnext_resort")) {
							$("tnext_resort").onclick = function() {
								resortsPage(responseJS.next);
							}
						}
						if ($("tpages_resort")) {
							var dots = "";
							for (var i = 0; i < responseJS.pagesnum; i++) {
								if (responseJS.currpage == i) {
									dots += "	<b class='current'>&nbsp;</b>"
								} else {
									dots += "	<b>&nbsp;</b>"
								}
							}
							$("tpages_resort").innerHTML = dots;
						}
					}
				}
			});
}

function episodesYear(year, id) {
	if( !$("episodes_inner_container")) {
		return;
	}
	var q = new Ajax.Request( "/episode_year.php",{
				method:"get",
				parameters: 'y=' + year + '&id='+id,
				onComplete: function(res) {
					if ($("episodesListContainer")) {
						$("episodesListContainer").innerHTML = res.responseText;
					}
				}
		});
}

function getAllComments(pid) {
	if( !$("comments_container") || !pid) {
		return;
	}
	var q = new Ajax.Request( "/get_comments.php",{
				method:"get",
				parameters: 'pid=' + pid,
				onComplete: function(res) {
					var r = eval( "(" + res.responseText + ")" );
					if (r.data.length > 0) {
						var content = "";
						for (var i = 0; i < r.data.length; i++) {
							content += '<li>';
							content += '<p>"'+r.data[i].content+'"</p>';
							content += '<p>by <i>'+r.data[i].author+'</i> </p>';
							content += '</li>';
						}
						$("comments_container").innerHTML = content;
						$("read_all_comments_btn").hide();
					}
				}
		});
}

function setSearchPage(page) {
	//$('pageNumber').value = page;
	var loc = document.location;
	var s = loc.search;
	if (s.match(/pageNumber=/)) {
		s = s.replace(/pageNumber=\d+/, 'pageNumber='+page);
	} else {
		if (!s.length) {
			s = '?pageNumber=1';
		} else if (s.indexOf('?')!=-1) {
			s += '&pageNumber='+page;
		} else {
			s += '?pageNumber='+page;
		}
	}
	document.location.href = document.location.protocol+'//'+document.location.host+document.location.pathname+s;
}

function setPerPage(page) {
	//$('pageNumber').value = page;
	var loc = document.location;
	var s = loc.search;
	if (s.match(/number=/)) {
		s = s.replace(/number=\d+/, 'number='+page);
	} else {
		if (!s.length) {
			s = '?number=1';
		} else if (s.indexOf('?')!=-1) {
			s += '&number='+page;
		} else {
			s += '?number='+page;
		}
	}
	document.location.href = document.location.protocol+'//'+document.location.host+document.location.pathname+s;
}

function setSortOrder(val) {
	//$('sortby').value = val;
	var loc = document.location;
	var s = loc.search;
	if (s.match(/pageNumber=/)) {
		s = s.replace(/pageNumber=\d+/, 'pageNumber=1');
	} else {
		if (!s.length) {
			s = '?pageNumber=1';
		} else if (s.indexOf('?')!=-1) {
			s += '&pageNumber=1';
		} else {
			s += '?pageNumber=1';
		}
	}
	if (s.match(/sortby=/)) {
		s = s.replace(/sortby=\w+/, 'sortby='+val);
	} else {
		s += '&sortby='+val;
	}
	document.location.href = document.location.protocol+'//'+document.location.host+document.location.pathname+s;
}

function narrowSetPage(num) {
	var tmp = $('narrowList').innerHTML;
	$('narrowList').innerHTML = '<img src="/img/progress.gif" width="16" height="16" alt="" />';
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/search/narrow_list', {
		method: 'post',
		parameters: {
			page: num
		},
		onSuccess: function(transport){
			var responseJS = transport.responseText.evalJSON();
			if (responseJS.success) {
				if ($('narrowList')) {
					$('narrowList').innerHTML = responseJS.content;
				}
			}
		},
		onFailure: function() {
			$('narrowList').innerHTML = tmp;
		}
	});
}

function playStream(streamID) {
	Shadowbox.open({
		player: 'iframe',
		width: 990,
		height: 470,
		content: '/get_player.php?streamID='+streamID+'&rss='+rss,
		title:  ''
	});
}


function regMe() {
	var log = $('_memberName').value;
	var pwd = $('_memberPwd').value;
	new Ajax.Request('/blog/wp-ajaxlogin.php',
	{
		method: 'post',
		parameters: {
			log: log,
			pwd: pwd
		},
		onSuccess: function(result) {
			var response = result.responseText.evalJSON();
			if (!response.success) {
				$('_memberName').value = $('_memberPwd').value = "";
				alert('User was not found');
			} else {
				var path = document.location.href;
				var tmp = document.location.href.indexOf('#');
				if (tmp>=0) {
					path = document.location.href.substr(0, tmp);
				}
				document.location = path;
			}
		}
	});
}

function unregMe() {
	new Ajax.Request('/blog/wp-ajaxlogin.php',
	{
		method: 'post',
		parameters: {
			action: 'logout'
		},
		onSuccess: function(result) {
			var response = result.responseText.evalJSON();
			if (!response.success) {
				alert('User was not found');
			} else {
				var path = document.location.href;
				var tmp = document.location.href.indexOf('#');
				if (tmp>=0) {
					path = document.location.href.substr(0, tmp);
				}
				document.location = path;
			}
		}
	});
}

function showLogDiv() {
	new Effect.Appear('log_in',{
		duration: 0.5,
		afterFinish: function() {
			$('_memberName').focus();
		}
	});
	return false;
}

function showCommentDiv() {
	new Effect.Appear('add_comment',{
		duration: 0.5,
		afterFinish: function() {
			$('_comment').focus();
		}
	});
	return false;
}

function addComment() {
	if (!checkFields('_comment')) {
		return false;
	}
	new Ajax.Request('/courses/addcomment',
	{
		method: 'post',
		parameters: {
			id: $('post').value,
			content: escape($('_comment').value)
		},
		onSuccess: function(result) {
			var response = result.responseText.evalJSON();
			if (!response.success) {
				alert(response.info);
			} else {
				$('_comment').value = "";
				alert("Thank you for submitting your comment to\n Global Golf Adventure. All comments are\n subject to review for appropriateness\n before appearing on the site.");
			}
		}
	});
	return false;
}

function addFAQ() {
	if (!checkFields('question')) {
		return false;
	}
	new Ajax.Request('/golf_insider/faq/ask',
	{
		method: 'post',
		parameters: {
			question: escape($('question').value)
		},
		onSuccess: function(result) {
			var response = result.responseText.evalJSON();
			if (!response.success) {
				alert(response.info);
			} else {
				$('question').value = "";
				alert("Thank you for submitting your question to\n Global Golf Adventure.");
			}
		}
	});
	return false;
}

function checkEnter(e) {
	var ch;
	if (e && e.which) {
		e = e;
		ch = e.which;
	} else {
		e = event;
		ch = e.keyCode;
	}
	if (ch == 13) {
		regMe();
	}
}

function resizeMap(h) {
	if ($('map')) {
		$('map').style.height = h+'px';
	}
}

function jsSearchFocus() {
	if ($('search').value == "Site Search") {
		$('search').value = "";
	}
}

function jsSearchBlur() {
	if ($('search').value == "") {
		$('search').value = "Site Search";
	}
}
var AjaxObject = Class.create({
showLoading: function()
{

},

hideLoading: function()
{

},

ajaxFailed: function(req)
{
	if (req.status == 401)
	{
		new Ajax.Request('/get_destinations_rss.php',{method: 'get', onFailure:this.ajaxFailed.bind(this)});
	}
	else
	{
		this.hideLoading();
		alert('Sorry. request failed.');
	}
}
});

var mapMode = 0; // 0 - collapsed, 1 - expanded

function setMapMode() {
	if (parseInt(mapMode)) {
		$('map').style.height = '350px';
		$('home_map').style.height = '350px';
		$('resizeButton').removeClassName('expand');
		$('resizeButton').addClassName('collapse');
	} else {
		$('map').style.height = '135px';
		$('home_map').style.height = '135px';
		$('resizeButton').removeClassName('collapse');
		$('resizeButton').addClassName('expand');
	}
}

function changeMapMode() {
	if (!parseInt(mapMode)) {
		$('map').style.height = '350px';
		$('home_map').style.height = '350px';
		$('resizeButton').removeClassName('expand');
		$('resizeButton').addClassName('collapse');
		mapMode = 1;
	} else {
		$('map').style.height = '135px';
		$('home_map').style.height = '135px';
		$('resizeButton').removeClassName('collapse');
		$('resizeButton').addClassName('expand');
		mapMode = 0;
	}
	BingMapsObj = new BingMaps('home_map','/get_destinations_rss.php');
	BingMapsObj.init();
}

var BingMaps = Class.create(AjaxObject, {
initialize: function(container, url)
{
	this.domContainer = $(container);
	this.url = url;
	this.originalCenter = false;
	setMapMode();
},

init: function()
{
	this.map = new VEMap(this.domContainer.id);
	//this.map.HideDashboard(); //hide default controls
	this.map.ShowMessageBox = false;
	this.map.LoadMap(new VELatLong(0,0), 2,'h' ,false);

	this.map.previousCenter = new Array();
	this.map.previousZoomLevel = new Array();

	this.map.AttachEvent("onclick",this.MouseHandler.bind(this));
	this.map.AttachEvent("onmousedown",this.drawHandlerStart.bind(this));
	this.map.AttachEvent("onmouseup",this.drawHandlerFinish.bind(this));
	this.map.AttachEvent("onchangeview", this.historyHandler.bind(this));
	this.map.AttachEvent("onmousemove", this.mouseMoveHandler.bind(this));

	this.map.containerName = this.domContainer.id;
	this.map.originalCenter = this.map.GetCenter();
	this.map.originalZoomLevel = this.map.GetZoomLevel();
	if (window.BingMapsSlider) BingMapsSlider.setValue(this.map.GetZoomLevel());
	if (this.url) this.loadXML();
},

loadXML: function()
{
	this.map.Clear();
	this.l = new VEShapeLayer();
	var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, this.url, this.l);
	this.map.ImportShapeLayerData(veLayerSpec, this.onFeedLoad.bind(this));
},

onFeedLoad: function(feed)
{
	this.map.ClearInfoBoxStyles(); //otherwise we can't apply own custom styles

	var numShapes = feed.GetShapeCount();
	var shape;

	for(var i = 0; i < numShapes; ++i)
	{
		shape = feed.GetShapeByIndex(i);
		shape.SetCustomIcon(shape.IconId);
	}
/*
	if (numShapes == 1) {
		//center and zoom map if we have 1 item
		this.map.previousCenter.pop();
		this.map.previousZoomLevel.pop();
		//shape = feed.GetShapeByIndex(0);
		this.map.SetZoomLevel(7);
	}
*/
	this.map.SetZoomLevel(1);
	this.map.originalCenter = this.map.GetCenter();
	this.map.originalZoomLevel = this.map.GetZoomLevel();


},

drawHandlerStart: function (e)
{
	if (this.map.mode=='draw') {
		this.map.mode='drawing';
		this.map.drawStartX = e.mapX;
		this.map.drawStartY = e.mapY;
	}
},

drawHandlerFinish: function (e)
{
	if (this.map.mode=='zoom') {
		this.map.mode ='';
		$('map_zoom').removeClassName('nb_zoom_active');
		document.getElementById(this.map.containerName).childNodes[0].style.cursor = 'auto';
	}
	if (this.map.mode=='drawing') {
		var distance = drawCircleHandler(e, this.map);

		this.map.vemapcontrol.EnableGeoCommunity(false);
		document.getElementById(this.map.containerName).style.cursor = '';
		this.map.mode=false;

		var drawStartPixel = new VEPixel(this.map.drawStartX, this.map.drawStartY);
		var drawStartLL = this.map.PixelToLatLong(drawStartPixel);

		if (($("alert_lat")) && $("alert_lon") && $("alert_radius")) {
			$("alert_lat").value = drawStartLL.Latitude;
			$("alert_lon").value = drawStartLL.Longitude;
			$("alert_radius").value = distance;
		}

		if (($("user_notification_radius")) && $("user_notification_lat_cr") && $("user_notification_lon_cr")) {
			$("user_notification_lat_cr").value = drawStartLL.Latitude;
			$("user_notification_lon_cr").value = drawStartLL.Longitude;
			$("user_notification_radius").value = distance;
		}
	}
},

mouseMoveHandler: function (e){
		if (this.map.mode=='drawing') {
			drawCircleHandler(e, this.map);
		}
	},


MouseHandler: function (e)
{
	if ((e.eventName == "onclick") && (e.leftMouseButton))
	{
		var reg = /source_url="([^"]*)/;
		if (this.map.GetShapeByID(e.elementID)) {
			var res = reg.exec(this.map.GetShapeByID(e.elementID).IconId);
			if (res && res[1].length>0) {
				location.href = res[1];
			}
		}
	}

},

historyHandler: function (e)
{
	this.map.previousCenter.push(this.map.GetCenter());
	this.map.previousZoomLevel.push(this.map.GetZoomLevel());
	if (window.BingMapsSlider) {
		if (BingMapsSlider.value != this.map.GetZoomLevel()) {
			BingMapsSlider.setValue(this.map.GetZoomLevel());
		}
	}
},

findLocation: function()
{
	try {
		this.map.Find(null, document.getElementById('map_search_where').value);
	}
	catch(e) {
		alert(e.message);
	}

},

reDrawFromForm: function()
{
	if (($("alert_lat")) && $("alert_lon") && $("alert_radius")) {
		if (($("alert_lat").value) && ($("alert_lon").value) && ($("alert_radius").value)) {
			radius = $("alert_radius").value;
			if ($("alert_radius_type") && ($("alert_radius_type").value=='miles')) radius = radius*1.609344;
			drawCircle(new VELatLong($("alert_lat").value, $("alert_lon").value),radius, this.map);
		}
	}
	if (($("user_notification_lat_cr")) && $("user_notification_lon_cr") && $("user_notification_radius")) {
		if (($("user_notification_lat_cr").value) && ($("user_notification_lon_cr").value) && ($("user_notification_radius").value)) {
			drawCircle(new VELatLong($("user_notification_lat_cr").value, $("user_notification_lon_cr").value),$("user_notification_radius").value, this.map);
		}
	}
}

});



/* ******************************************************** */
/* The code for the GeoCodeCalc class was copied from here: */
/* http://pietschsoft.com/Blog/Post.aspx?PostID=1452        */
/* ******************************************************** */
var GeoCodeCalc = {};
GeoCodeCalc.EarthRadiusInMiles = 3956.0;
GeoCodeCalc.EarthRadiusInKilometers = 6367.0;

GeoCodeCalc.ToRadian = function(v) {
	return v * (Math.PI / 180);
};

GeoCodeCalc.DiffRadian = function(v1, v2) {
	return GeoCodeCalc.ToRadian(v2) - GeoCodeCalc.ToRadian(v1);
};

GeoCodeCalc.CalcDistance = function(lat1, lng1, lat2, lng2, radius) {
	return radius * 2 * Math.asin(
			Math.min(1,
				Math.sqrt(
					(
						Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lat1, lat2)) / 2.0), 2.0) +
						Math.cos(GeoCodeCalc.ToRadian(lat1)) * Math.cos(GeoCodeCalc.ToRadian(lat2)) *
						Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lng1, lng2)) / 2.0), 2.0)
					)
			)
		)
	);
};

if (GeoCodeCalc == undefined) var GeoCodeCalc = {}
GeoCodeCalc.ToDegrees = function(radians){
	return radians * 180 / Math.PI;
};

function CreateCircle(loc, radius, units)
{
	var earthRadius = parseFloat(units);
	var lat = GeoCodeCalc.ToRadian(loc.Latitude); //radians
	var lon = GeoCodeCalc.ToRadian(loc.Longitude); //radians
	var d = parseFloat(radius) / earthRadius;  // d = angular distance covered on earth's surface
	var locs = new Array();
	for (x = 0; x <= 360; x++)
	{
		var p2 = new VELatLong(0,0)
		brng = GeoCodeCalc.ToRadian(x); //radians

		var latRadians = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(brng));
		var lngRadians = lon + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(lat), Math.cos(d) - Math.sin(lat) * Math.sin(latRadians));

		locs.push(new VELatLong(GeoCodeCalc.ToDegrees(latRadians), GeoCodeCalc.ToDegrees(lngRadians)));
	}

return new VEShape(VEShapeType.Polyline, locs);
}

function drawCircleHandler(e, map)
{
	var drawStartPixel = new VEPixel(map.drawStartX, map.drawStartY);
	var drawFinishPixel = new VEPixel(e.mapX, e.mapY);
	var drawStartLL = map.PixelToLatLong(drawStartPixel);
	var drawFinishLL = map.PixelToLatLong(drawFinishPixel);

	var distance = GeoCodeCalc.CalcDistance(drawStartLL.Latitude, drawStartLL.Longitude, drawFinishLL.Latitude, drawFinishLL.Longitude, GeoCodeCalc.EarthRadiusInKilometers)
	drawCircle(drawStartLL,distance, map);
	return distance;
}

function drawCircle(drawStartLL,distance, map)
{

	map.DeleteAllShapes();

	for(var i=0;i<=0;++i){
		if (i>0)
			radius = distance-(distance/(i*10))*9;
		else
			radius = distance;
		var circle = CreateCircle(
					drawStartLL,
					radius,
					GeoCodeCalc.EarthRadiusInKilometers);
		circle.HideIcon();
		circle.SetLineColor(new VEColor(255,0,0,1));
		map.AddShape(circle);
	}
}

Init = function (){
	if (!$('leftmenu')) return;
	var submenus = $('leftmenu').select('a.slidelink');
	submenus.each(function(item) {
		new SlideMenu(item);
	});
}

window.onload = Init;

var SlideMenu = Class.create();

SlideMenu.prototype = {
	initialize: function(el) {
		this.element = el.next("div");
		this.caller = el;
		this.caller.fx1 = this.onClick.bindAsEventListener(this, this.caller);
		Event.observe(this.caller, 'click', this.caller.fx1);

	},

	onClick: function(event, el) {
		event.stop();
		if (this.element) {
			if (this.element.style.display == 'none') {
				this.element.style.display = 'block';
				el.addClassName('current');
			} else {
				this.element.style.display = 'none';
				el.removeClassName('current');
			}
		}
	}

}
Init2 = function (){
	if (!$('destination')) return;
	var submenus = $('destination').select('a.slidelink');
	submenus.each(function(item) {
		new SlideMenu2(item);
	});
}

var SlideMenu2 = Class.create();

SlideMenu2.prototype = {
	initialize: function(el) {
		this.element = el.next("div");
		this.caller = el;
		this.caller.fx1 = this.onClick.bindAsEventListener(this, this.caller);
		Event.observe(this.caller, 'click', this.caller.fx1);

	},

	onClick: function(event, el) {
		event.stop();
		if (this.element) {
			if (this.element.style.display == 'none') {
				this.element.style.display = 'block';
				el.addClassName('current');
			} else {
				this.element.style.display = 'none';
				el.removeClassName('current');
			}
		}
	}

}

Event.observe(document, 'dom:loaded', Init2);
    function start_slideshow(start_frame, end_frame, delay) {
        setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
    }
                            
    function switch_slides(frame, start_frame, end_frame, delay) {
        return (function() {
            Effect.Fade('slideshow' + frame);
            if (frame == end_frame || !$('slideshow' + frame)) { frame = start_frame; } else { frame = frame + 1; }
            setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
            setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
        })
    }
/*
// Author: Marghoob Suleman
// Copyright (c) 2008 Indiatimes Travel
* $Date: 2007-02-14 10:02:06 -0530 (Thursday, 04th March 2008) $
* $Rev: 0 $
* using Prototype.js
*/
var CustomComponents = {};
/************** Element ***************/
CustomComponents.Elements = {
	coutner:40,
createDiv: function(id) {
	this.id = $(id);
	if(this.id!=null) {
		throw "Element ['"+ id +"'] already exist!";
	} else {
		var div = document.createElement("div");
		if(id) div.setAttribute("id", id);
		return div;
	}
},
getInnerText:function(elem) {
	var elem = $(elem);
	var sText = ""
	if(Prototype.Browser.IE) {
		sText = elem.innerText;
	} else {
		sText = elem.textContent;
	}
	return sText;
},
getTextSize: function(elem) {
	var size = this.getInnerText(elem).length;
	return size;
},
setInnerText: function(elem, value) {
	var elem = $(elem);
	var sText = value;
	elem.firstChild.nodeValue = sText + " ";
},
setLabel: function(elem, value) {
	this.setInnerText(elem, value);
},
setDimension: function(sTarget, wh, ht) {
	var target = $(sTarget);
	var w;
	var h;
	//width
	if(wh) {
		w = wh;
	} else {
		var textcount = this.getTextSize(target);
		w = (textcount*6) + textcount;
	}

	//set size
	//target.setStyle({width:w+'px'});
	//set height;
	if(ht) {
		h = ht;
		target.setStyle({height:h+'px'});
	}
}
};
/************** Element ***************/

CustomComponents.StaticVars = {
	currentChildMenu:null,
	isVisible:false
}

/*************** Listeners ************/
CustomComponents.Listeners = {
	addEventListener: function(name, callback, useCapture) {
			document.observe("widget:"+name, function(event) {
												//console.log("Element with ID (" + event.target.id +    ") frobbed widget #" + event.memo.widgetNumber + ".");
												callback(event.memo);
												}
												);
	},
	removeListener: function(name) {
		//alert("widget:"+name);
		document.stopObserving("widget:"+name);
	},
	dispatchEvent: function(objName, eventName, arg) {
	var target = $(objName);
	target.fire("widget:"+eventName, arg);
	}
}
/******************** DROPDOWN *******************************/
CustomComponents.DropDownMenu = Class.create({
initialize: function(sID) {
	this.menuCounter = 20;
	this.divID = $(sID);
	this.menuArray;
	this.itemsArray;
	this.dropDownArrow = CustomComponents.Config.imagePath+"dropDownArrow.gif";
	this.childId;
	this.enableMouseOverOpen = false; //will work on this
	if(this.divID==null) {
		//alert("Element ['"+ sID +"'] does not exist!");
		throw "Element ['"+ sID +"'] does not exist!";
		//return false;
	}
	/*************** Menu Style **************/
	this.mainMenuPadClassName = Config.CSS_dropDownMainMenuPad;
	this.childMenuPadClassName = Config.CSS_dropDownChildMenuPad;
	/*********** end **************/
//	this.makeMenuPad();
},
create: function(menu_Array, callBackFunction, menuType, params) {
	if(this.divID) {
		this.itemsArray = new Array();
		this.menuArray = menu_Array;
		var menu_array = menu_Array;
		var callBack = callBackFunction;
		var sMenuType = (menuType==null || menuType==undefined) ? "normal" : menuType;
		if(sMenuType != "normal" && sMenuType != "button") {
			//alert("sMenuType " + sMenuType + " this.childId "  + this.childId);
			if(this.childId!=undefined && $(this.childId)) {
				$(this.childId).remove();
			} else {
				this.makeMenuPad();
			}
			//alert("sMenuType " + sMenuType + " this.childId "  + this.childId);
			childDiv = this.makeChildPad();
		}
		switch(sMenuType.toLowerCase()) {
			case "normal" :
			case "button" :
				this.createNormalButton(menu_array, callBack, params);
			break;
			case "checkbox" :
				this.createCheboxDropDown(menu_array, childDiv, callBack, params);
			break;
			case "link" :
			case "links" :
				this.createLinkDropDown(menu_array, childDiv, callBack);
			break;
			case "radio" :

			break;
			case "dropdown" :
				this.createDropdown_DropDown(menu_array, childDiv, callBack)
			break;
		}
	}
	//if(menuArray) $(childDiv).innerHTML = menuArray;
	//alert("this.id " + this.id);
},
createNormalButton: function(menu_array, callBack, params) {
	var target = $(this.divID);
	var img = ""
	var sText = target.innerHTML;
	if(params) {
			if(params.iconFile) {
			this.dropDownArrow = params.iconFile;
			img = " <img src="+ this.dropDownArrow +" align='absmiddle' /> ";
			if(params.iconPosition == "before") {
				sText = img + target.innerHTML;
			} else {
				sText = target.innerHTML + img;
			}
			}
	}
	target.update(sText);
	target.observe('click', function(arg) {
											callBack(arg);
											})
	//Set Action
	//target.observe('mouseover', this.highlightMenu);
	//target.observe('mouseout', this.restoreMenu);
},
createDropdown_DropDown: function(menu_Array, childDiv, callBack) {
	var menu_array = menu_Array;
	//console.debug(" CustomComponents --> createDropdown_DropDown() menu_Array " + menu_Array);
	var target_div = $(childDiv);
	var callBackFunction = callBack;
	var total = menu_array.length;
	var selectedItem = null;
	//target_div.upadte("");
	for(var iCount=0; iCount<total; iCount++) {
		var currentObj = menu_array[iCount];
		if(typeof(currentObj) != "object") {
			currentObj = new Object();
			currentObj.label = menu_array[iCount];
			currentObj.value = menu_array[iCount];
			currentObj.selected = false;
		}
		var currentLabel = currentObj.label;
		var currentValue = currentObj.value;
		var currentSelected = currentObj.selected;
		if (currentSelected) {
			selectedItem = currentObj;
		}
		var textID = target_div.id+"_"+iCount;
		var a = new Element('a', {'class':Config.CSS_dropDownMenuLink, href:'javascript:void(0)', id:textID}).update(currentLabel);
		a._properties = currentObj;
		//Add into an array
		this.itemsArray.push(a);
		$(a).observe('mousedown', function(arg) {
										$(target_div).hide();
										var obj = arg.target._properties;
										var currentTarget  = arg.target;
										var parentNode = $(target_div).parentNode;
										CustomComponents.Elements.setInnerText(parentNode, obj.label);
										//set value
										parentNode.label = obj.label;
										parentNode.value = obj.value;
//										 alert(parentNode.id +" parentNode " + parentNode.value);
										if (typeof(callBackFunction)=="function") {
											callBackFunction(obj);
										}
										//this.setLabel(getInnerText);
										});
		target_div.appendChild(a);
	}
	//Default Value
		var parentNode = $(target_div).parentNode;
		var currentObj = selectedItem || menu_array[0];
		if(typeof(currentObj) != "object") {
			currentObj = new Object();
			currentObj.label = menu_array[iCount];
			currentObj.value = menu_array[iCount];
		}
		var currentLabel = currentObj.label;
		//var currentValue = currentObj.value;
		//parentNode.label = currentLabel;
		//parentNode.value = currentValue;
		CustomComponents.Elements.setInnerText(parentNode, currentLabel);
//	 alert("parentNode.value: " + parentNode.value + " parentNode.id : " + parentNode.id + " menu_array[0] " + menu_array[0]);
},
setValue: function(target_div, value) {
	var targetDiv = $(target_div);
	if(targetDiv) {
		targetDiv.value = value;
	}
},
getValue: function(target) {
	//get value
	if(target) {
		$(target).value = obj.value;
	} else {
		$(target_div).value = obj.value;
	}
},
createCheboxDropDown: function(menu_Array, div, callback, params) {
	var menu_array = menu_Array;
	var target_div = $(div);
	var callBackFunction = callback;
	var shouldChecked;
	var checkedArray = new Array();
	var unCheckedArray = new Array();
	var Messages = params.Messages || {};
	var MsgCurrent = params.MsgCurrent || 'choose';
	var inactiveCss = params.InactiveCss || null;
	//init value
	var porop = new Object();
	var checked = checkedArray;
	var unchecked = unCheckedArray;
	porop.checked = checked;
	porop.unchecked = unchecked;
	porop.items = menu_array;
	// set value here
	target_div.label = label;
	target_div.value = porop; // checked | unchecked | items
//	  var chekcBoxString = "";
	for(var iCount=0; iCount<menu_array.length; iCount++) {
		var label = menu_array[iCount][0];
		var val = menu_array[iCount][1];
		shouldChecked = menu_array[iCount][2];
		//var eType = menu_array[iCount][3];
		//console.debug("label " + label + " shouldChecked " + shouldChecked);
		var id = target_div.id+"[]"; //+(iCount)+"]"; //CustomComponents.Elements.counter++;
		var childDiv = CustomComponents.Elements.createDiv();
		$(childDiv).addClassName('ddDiv');
		//var currentCheckBox = new Element("input", {type:'checkbox', id:id, name:id, value:label});
		var currentCheckBox = new Element("input", {'type':'checkbox', 'id':id, 'name':id, 'value':val/*, 'rel':eType*/}); // track object type
		currentCheckBox._properties = this.itemsArray;
		//Add into an array
		this.itemsArray.push(currentCheckBox);
		var lbl = new Element("label", {id:'ddLabels'});
		lbl.appendChild(currentCheckBox);
		lbl.appendChild(document.createTextNode(' '+label));
		//Set check
		if(shouldChecked==true) {
			checkedArray.push(currentCheckBox);
		} else {
			unCheckedArray.push(currentCheckBox);
		}
		$(currentCheckBox).checked = shouldChecked;
		childDiv.appendChild(lbl);
		$(target_div).appendChild(childDiv);
		//Click Event
		$(lbl).observe('click', function(arg) {
										//$(target_div).hide();
										var obj = arg.element().up(3).select('input[type=checkbox]');
										if (!obj) return;
										var currentTarget  = arg.target;
										var checkedArray = new Array();
										var unCheckedArray = new Array();
										for(var objCount=0;objCount<obj.length;objCount++) {
											var isChecked = $(obj[objCount]).checked;
											if(isChecked) {
												checkedArray.push($(obj[objCount]));
											} else {
												unCheckedArray.push($(obj[objCount]));
											}
										}
										var porop = new Object();
										var checked = checkedArray;
										var unchecked = unCheckedArray
										porop.checked = checked;
										porop.unchecked = unchecked;
										porop.items = obj;

										var parentNode = $(target_div).parentNode;
										var label = Messages.choosen.get(MsgCurrent);
										if(porop.items.length != checkedArray.length && checkedArray.length>0) {
											label = Messages.choosen.get("mixed");
											if (inactiveCss) {
												$(target_div).addClassName(inactiveCss);
											}
										} else if(porop.items.length == checkedArray.length && checkedArray.length>0) {
											label = Messages.choosen.get("all");
										} else if (inactiveCss) {
											$(target_div).addClassName(inactiveCss);
										}
										CustomComponents.Elements.setInnerText(parentNode, label);
										// set value here
										parentNode.label = label;
										parentNode.value = porop; // checked | unchecked | items

										//
										if (typeof(callBackFunction)=="function") {
											callBackFunction(porop);
										}
								});
		/*
		$(a).observe('mousedown', function(arg) {
										$(target_div).hide();
										var obj = arg.target._properties;
										var currentTarget  = arg.target;
										var parentNode = $(target_div).parentNode;
										CustomComponents.Elements.setInnerText(parentNode, obj.label);
										callBackFunction(obj);
										//this.setLabel(getInnerText);
										});
		*/
	}
	var child2Div = CustomComponents.Elements.createDiv();
	//$(child2Div).id = '';
	$(child2Div).addClassName('MS_ChildMenuPad2 MS_Child_buttons');
	var childDiv = CustomComponents.Elements.createDiv();
	$(childDiv).addClassName('ddDiv2');
	var a = new Element('a', { href: 'javascript:void(0)', name: 'done'}).update('Done');
	$(a).observe('click', this.closeMenu);
	a.addClassName('ddLinkBigger');
	childDiv.appendChild(a);
	$(child2Div).appendChild(childDiv);
	var childDiv = CustomComponents.Elements.createDiv();
	$(childDiv).addClassName('ddDiv2');
	var a = new Element('a', { href: 'javascript:void(0)', name: 'uncheck'}).update('Uncheck All');
	$(a).observe('click', function(evt) {
		var parent = evt.target.up(2);
		var els = parent.select('input[type=checkbox]');
		if (els) {
			els.each( function(item) {
				item.checked = false;
			});
		}
		var tt = parent.readAttribute('tooltip');
		if (tt) {
			CustomComponents.Elements.setInnerText(parent, tt);
		}
		if (inactiveCss) {
			parent.addClassName(inactiveCss);
		}
		if (typeof(callBackFunction)=="function") {
			porop.checked = [];
			porop.unchecked = [];
			callBackFunction(porop);
		}
	});
	a.addClassName('ddLink');
	childDiv.appendChild(a);
	$(child2Div).appendChild(childDiv);
	$(target_div).appendChild(child2Div);
	/******** Default value **********/
	var porop = new Object();
	var parentNode = $(target_div).parentNode;
	$(parentNode).appendChild(child2Div);
	porop.checked = checkedArray;
	porop.unchecked = unCheckedArray;
	porop.items = this.itemsArray;
	parentNode.value = porop; //checked | unchecked | items
	var label = Messages.choosen.get(MsgCurrent);
	if(porop.items.length != porop.checked.length && porop.checked.length>0) {
		label = Messages.choosen.get("mixed");
		if (inactiveCss) {
			parentNode.addClassName(inactiveCss);
		}
	} else if(porop.items.length == porop.checked.length && porop.checked.length>0) {
		label = Messages.choosen.get("all");
	} else if (inactiveCss) {
		parentNode.addClassName(inactiveCss);
	}
	CustomComponents.Elements.setInnerText(parentNode, label);
	parentNode.setAttribute('tooltip', Messages.choosen.get("all"));
	return porop;
},
createLinkDropDown: function(menu_Array, childDiv, callBack) {
	var menu_array = menu_Array;
	var target_div = $(childDiv);
	var callBackFunction = callBack;
	var total = menu_array.length;
	for(var iCount=0; iCount<total; iCount++) {
		var currentObj = menu_array[iCount];
		if(typeof(currentObj) != "object") {
			currentObj = new Object();
			currentObj.label = menu_array[iCount];
			currentObj.link = menu_array[iCount];
		}
		var currentLabel = currentObj.label;
		var currentLink  = currentObj.link;
		var aId = target_div.id+"_"+iCount;
		var a = new Element('a', { href: currentLink, id:aId}).update(currentLabel);
		a.className = Config.CSS_dropDownMenuLink;
		// new Element('a', { 'class': 'foo', href: '/foo.html' }).update("Next page");
		/*
		var a = document.createElement("A");
		a.setAttribute("id", target_div.id+"_"+iCount);
		a.setAttribute("href", currentLink);
		a.className = Config.CSS_dropDownMenuLink;
		var linkText = document.createTextNode(currentLabel);
		a.appendChild(linkText);
		*/
		if(callBackFunction!=null) {
			$(a).observe('click', function(arg) {
											callBackFunction(arg);
											});
		}
		target_div.appendChild(a);
	}

},
makeMenuPad: function() {
	//update text
	var target = $(this.divID);
	//target.update(target.innerHTML +"<div style='position:absolute;top:2px;right:0px;'> <img src="+ this.dropDownArrow +" align='absmiddle' /> </div>");
	this.setDimension();
},
setDimension: function(w, h) {
	var target = $(this.divID);
	if(w && !h) {
		CustomComponents.Elements.setDimension(target, w);
	} else if(h && !w) {
		CustomComponents.Elements.setDimension(target, null, h);
	} else if(w && h) {
		CustomComponents.Elements.setDimension(target, w, h);
	} else {
		CustomComponents.Elements.setDimension(target);
	}
},
makeChildPad: function() {
	//alert("$(this.divID).id " + $(this.divID).id);
	var childMenuName =  $(this.divID).id+"_Child" //+this.menuCounter++
	//set id for open
	this.childId = childMenuName;
	//create Child
	var childDiv = CustomComponents.Elements.createDiv(childMenuName);
//alert("CustomComponents.DropDownMenu#childId " + CustomComponents.DropDownMenu#childId);
//	childDiv.innerHTML = "Child Menu"; //temp
	childDiv.className = this.childMenuPadClassName;
	$(childDiv).hide();

	var parentDiv = $(this.divID);

	parentDiv.appendChild(childDiv);
	//Set Action
	if(this.enableMouseOverOpen==false) {
		parentDiv.observe('click', this.openMenu);
	} else {
		//parentDiv.observe('click', this.openMenu);
		//parentDiv.observe('mouseover', this.openMenu);
	}
//	parentDiv.observe('mouseover', this.highlightMenu);
//	parentDiv.observe('mouseout', this.restoreMenu);
//  	$(childDiv).observe('click', this.closeMenu);
	return childDiv;
	//alert(textLength);
},
/*
highlightMenu: function(arg) {
	$(this.id).className = Config.CSS_dropDownMainMenuPadHover;
},
restoreMenu: function(arg) {
//	  alert(this.id + " " +Config.CSS_dropDownMainMenuPad);
	$(this.id).className = Config.CSS_dropDownMainMenuPad;
},
*/
openMenu: function(evt) {
	var el;
	if (evt.target.tagName=='DIV') {
		var seek = this.id+'_Child';
		var target = $(this.id);
		//if(target==null) target = $(this.divID);
		var childMenu = CustomComponents.StaticVars.currentChildMenu = $(target.id.toString()+"_Child");
		var subMenus = $('searchForm').getElementsByClassName('MS_ChildMenuPad');
		if (subMenus && subMenus.length) {
			for (var i=0; i<subMenus.length; i++) {
				if (subMenus[i].id!=seek) {
					subMenus[i].hide();
					if (el = subMenus[i].next()) {
						el.hide();
					}
				}
			}
		}
		if ($(childMenu).parentNode.firstDescendant() && !$(childMenu).parentNode.firstDescendant().descendants().length) {
			return;
		}
		if ($(childMenu).style.display=='none') {
			$(childMenu).style.display = 'block';
			if (el = $(childMenu).next()) {
				el.style.display = 'block';
			}
			/*
			if (childMenu.getHeight()>200) {
				childMenu.setStyle({height:'200px'});
			}
			*/
			Event.observe(document.body, 'mouseup', function(evt) {
				var childMenu = CustomComponents.StaticVars.currentChildMenu;
				//$(childMenu).hide();
				Event.stopObserving(document.body, 'mouseup');
				CustomComponents.Listeners.dispatchEvent(childMenu, "onMenuClose");
			});

		} else {
			CustomComponents.StaticVars.isVisible = false;
			$(childMenu).style.display = 'none';
			if (el = $(childMenu).next()) {
				el.style.display = 'none';
			}
		}
	}
},
closeMenu: function() {
	var el;
	var childMenu = CustomComponents.StaticVars.currentChildMenu;
	$(childMenu).hide();
	if (el = $(childMenu).next()) {
		el.hide();
	}
//	 alert($(childMenu))
	CustomComponents.StaticVars.isVisible = false;
	Event.stopObserving(document.body, 'mouseup');
	CustomComponents.Listeners.dispatchEvent(childMenu, "onMenuClose");
},
addEventListener: function(name, callback, useCapture) {
	CustomComponents.Listeners.addEventListener(name, callback, useCapture);
},
removeListener: function(name) {
	CustomComponents.Listeners.removeListener(name);
	//$(this.divID).observe(name, callback, useCapture);
},
dispatchEvent: function(target, eventname) {
	CustomComponents.Listeners.dispatchEvent(target, eventname);
},
setLabel: function(label) {
//	  $(this.divID).innerText = label;
		//alert($(this.divID) + " " + label);
	//this.setDimension();
	CustomComponents.Elements.setInnerText($(this.divID), label);
},
getLabel: function() {
	return $(this.divID).innerText;
},
setStyle: function(style) {
	$(this.divID).setStyle(style);
}
});
/******************** END DROPDOWN *******************************/
CustomComponents.Buttons = Class.create({
initialize: function(id, style) {
	this.id = $(id);
	this.button;
},
create: function(callBackFunction, params) {
	var dropdown = new CustomComponents.DropDownMenu(this.id);
	dropdown.create((this.id).innerHTML, callBackFunction, "normal", params);
	this.button = dropdown;
},
setLabel: function(label) {
	this.button.setLabel(label);
},
getLabel: function() {
	return this.button.getLabel();
},
setStyle: function(style) {
	this.button.setStyle(style);
}
});

CustomComponents.Config = {
	imagePath: "/js/cbdd/img/"
}
CustomComponents.SetterGetter = {
	setValue: function(target, value) {
	var targetDiv = $(target);
	if(targetDiv) {
		targetDiv.value = value;
	}
	},
	getValue: function(target) {
	var targetDiv = $(target);
	if(targetDiv) {
		return targetDiv.value;
	}
	},
	setLabel: function(target, value) {
	var targetDiv = $(target);
	if(targetDiv) {
		CustomComponents.Elements.setInnerText(targetDiv, value);
	}
	},
	getLabel: function(target) {
	var targetDiv = $(target);
	if(targetDiv) {
		CustomComponents.Elements.getInnerText(targetDiv);
	}
	}
}

ElementCreator = {
	createRadio: function(param, insertInto) {
		var oRadio = document.createElement(param);
		if(insertInto) insertInto.appendChild(oRadio);
		return oRadio;
	},
	createDiv: function(sID, insertInto, sClass) {
		var div = document.createElement("DIV");
		if(sID) div.setAttribute("id", sID);
		if(insertInto) insertInto.appendChild(div);
		if(sClass) div.className = sClass;
		return div;
	},
	createTable: function(sID, insertInto, sClass) {
		var oTable = document.createElement("TABLE");
		var oTBody = document.createElement("TBODY");
		oTable.appendChild(oTBody);
		if(sClass) oTable.className = sClass;
		if(insertInto) insertInto.appendChild(oTable);
		return {table:oTable, tBody:oTBody};
		//return oTable;
	},
	createTR: function(sID, insertInto, sClass) {
		var oTR = document.createElement("TR");
		if(sClass) oTR.className = sClass;
		if(insertInto) insertInto.appendChild(oTR);
		if(sID) oTR.setAttribute("id", sID);
		return oTR;
	},
	createTD: function(value, sID, insertInto, sClass) {
		var oTD = new Element('TD');
		if(value) {
			oTD.update(value);
		}
		if(sClass) oTD.className = sClass;
		if(insertInto) insertInto.appendChild(oTD);
		if(sID) {
			oTD.setAttribute("id", sID);
		}
		return oTD;
	},
	inserImage: function(path, width, height, insertInto, id, callback) {
		var imgTag = document.createElement("img");
		imgTag.setAttribute('src', path);
		imgTag.setAttribute('id', id);
		imgTag.setAttribute('name', id);
		if(width!=null) imgTag.setAttribute('width', width);
		if(height!=null) imgTag.setAttribute('height', height);
		if(id!=null  && callback!=null) $(id).observe('click', callback);
		if(insertInto!=null) insertInto.appendChild(imgTag);
		return imgTag;
	}
}

