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 LoginMenu = Class.create({
	initialize: function() {
		this.domContainer = $('loginDiv');
		this.domLoginLink = $('loginLink');
		this.domForm = this.domContainer.down('form');
		this.domLoginLink.onfocus = function() {this.blur()}
		this.domLoginLink.observe('click', this.loginClick.bindAsEventListener(this));
		this.bodyClickBound = this.bodyClick.bindAsEventListener(this);
		this.visible = false;
	},

	loginClick: function(event) {
		if (this.visible) {
			this.hide();
		} else {
			this.show();
		}
		event.stop();
	},

	show: function() {
		if (this.effect) {
			this.effect.cancel();
		}
		this.effect = new Effect.Appear(this.domContainer, {duration: 0.3});
		$(document.body).observe('click', this.bodyClickBound);
		this.visible = true;
	},

	hide: function() {
		if (this.effect) {
			this.effect.cancel();
		}
		this.effect = new Effect.Fade(this.domContainer, {duration: 0.3});
		this.visible = false;
	},

	bodyClick: function(event) {
		if (!this.visible || event.element().descendantOf(this.domContainer)) {
			return;
		}
		this.hide();
	}
});

Init = function (){
	if (!$('leftmenu')) return;
	var submenus = $('leftmenu').select('li.submenu 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) {
		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');
			}
		}
	}

}
	var ua = navigator.userAgent.toLowerCase();
	var client = {
		isStrict:   document.compatMode == 'CSS1Compat',
		isOpera:    ua.indexOf('opera') > -1,
		isIE:       ua.indexOf('msie') > -1,
		isIE7:      ua.indexOf('msie 7') > -1,
		isSafari:   /webkit|khtml/.test(ua),
		isWindows:  ua.indexOf('windows') != -1 || ua.indexOf('win32') != -1,
		isMac:      ua.indexOf('macintosh') != -1 || ua.indexOf('mac os x') != -1,
		isLinux:    ua.indexOf('linux') != -1
	};
	client.isBorderBox = client.isIE && !client.isStrict;
	client.isSafari3 = client.isSafari && !!(document.evaluate);
	client.isGecko = ua.indexOf('gecko') != -1 && !client.isSafari;
	var ltIE7 = client.isIE && !client.isIE7;
	var outCount = 0;

function showDropdowns() {
	var paras = $A(document.getElementsByTagName('select'));
	paras.each(Element.show);
}

Element.addMethods({
	downChild: function(element, expression, index) {
		element = $(element);
		if (arguments.length == 1) return element.firstDescendant();
		var descendants = element.childElements();
		return expression ? Selector.findElement(descendants, expression, index) :
			descendants[index || 0];
	},

	selectChildren: function() {
		var args = $A(arguments), element = $(args.shift());
		var res1 = Selector.findChildElements(element, args);

		var res = $A([]);
		for (var i = 0; i < res1.length; i++)
		{
			if (res1[i].parentNode == element)
			res.push(res1[i])
		}

		return res;
	}

});


var MainMenu = Class.create({
	initialize: function(container, activeClassName)
	{
		this.lengths = new Array();
		this.heights = new Array();
		this.offsets = new Array();

		this.domContainer = $(container);
		this.activeClassName = activeClassName;

		var menuItems = this.domContainer.selectChildren('li');
		var len = 0;
		var ofs = 1;

		for (var i = 0; i < menuItems.length; i++)
		{
			var domMenuItem = menuItems[i];

			len = domMenuItem.getWidth()+58;
			this.lengths[i] = len;
			this.offsets[i] = ofs;
			this.heights[i] = 0;
			ofs = ofs+len;

			domLink = domMenuItem.select('a');
			if (domLink.length>1) {
				domLink.fx1 = this.onMouseOverLink.bindAsEventListener();
				Event.observe(domLink[0], 'mouseover', domLink.fx1);
			}

			domMenuItem.fx1 = this.onMouseOver.bindAsEventListener(this, domMenuItem, i);
			domMenuItem.fx2 = this.onMouseOut.bindAsEventListener(this, domMenuItem);
			Event.observe(domMenuItem, 'mouseover', domMenuItem.fx1);
			Event.observe(domMenuItem, 'mouseout', domMenuItem.fx2);

			var domSubMenus = domMenuItem.select('ul > li > ul');

			if (domSubMenus.length)
			{
				for (var j=0; j<domSubMenus.length; j++) {
					var tmp = domSubMenus[j].up();
					tmp.fx1 = this.onMouseOver2.bindAsEventListener(this, tmp);
					tmp.fx2 = this.onMouseOut2.bindAsEventListener(this, tmp);
					Event.observe(tmp, 'mouseover', tmp.fx1);
					Event.observe(tmp, 'mouseout', tmp.fx2);
				}
			}
		}

		if (this.domDefaultMenuItem)
		{
			var domSubmenu = this.domDefaultMenuItem.downChild('ul');
			if (domSubmenu)
			{
				domSubmenu.style.display = 'block';
			}
		}
	},

	onMouseOver: function(event, domLi, num)
	{
		if (this.queuedHandler)
			this.queuedHandler();

		if (this.inactivityTimer)
			clearTimeout(this.inactivityTimer);

		if (this.domDefaultMenuItem)
			this.domDefaultMenuItem.removeClassName(this.activeClassName);

		if (this.domDefaultMenuItem && this.domDefaultMenuItem != domLi)
		{
			var domSubmenu = this.domDefaultMenuItem.downChild('ul');
			if (domSubmenu) {
				domSubmenu.style.display = 'none';
			}
		}

		domLi.addClassName(this.activeClassName);

		var domSubmenu = domLi.downChild('ul');
		if (domSubmenu)
		{
			domSubmenu.style.display = 'block';
		}
	},

	onMouseOut: function(event, domLi)
	{
		this.queuedHandler = this.onMouseOutDelayed.bind(this, domLi);
		this.inactivityTimer = setTimeout(this.onInactivity.bind(this), 200);
		if (this.queuedHandler2)
			this.queuedHandler2();
	},

	onMouseOutDelayed: function(domLi)
	{
		var domSubmenu = domLi.downChild('ul');
		if (domSubmenu)
		{
			domSubmenu.style.display = 'none';
		}

		domLi.removeClassName(this.activeClassName);
	},

	onMouseOver2: function(event, domLi)
	{
		if (this.queuedHandler2)
			this.queuedHandler2();

		if (this.domDefaultMenuItem)
			this.domDefaultMenuItem.removeClassName(this.activeClassName);

		if (this.domDefaultMenuItem && this.domDefaultMenuItem != domLi)
		{
			var domSubmenu = this.domDefaultMenuItem.downChild('ul');
			if (domSubmenu)
			{
				domSubmenu.style.display = 'none';
			}
		}


		domLi.addClassName(this.activeClassName);

		var domSubmenu = domLi.downChild('ul');
		if (domSubmenu)
		{
			domSubmenu.style.display = 'block';
		}

	},

	onMouseOut2: function(event, domLi)
	{
		this.queuedHandler2 = this.onMouseOut2Delayed.bind(this, domLi);
	},

	onMouseOut2Delayed: function(domLi)
	{
		var domSubmenu = domLi.downChild('ul');
		if (domSubmenu)
		{
			if (client.isIE) {
				outCount++; //a hack to remove blinking in IE
				if (outCount >= 2) {
					domSubmenu.style.display = 'none';
					outCount = 0;
				}
			} else {
				domSubmenu.style.display = 'none';
			}
		}

		domLi.removeClassName(this.activeClassName);
	},

	onInactivity: function()
	{
		if (this.queuedHandler)
		this.queuedHandler();

		if (this.domDefaultMenuItem)
		{
			this.domDefaultMenuItem.addClassName(this.activeClassName);

			var domSubmenu = this.domDefaultMenuItem.downChild('ul');
			if (domSubmenu)
			{
				domSubmenu.style.display = 'block';
			}
		}
	},

	onMouseOverLink: function() {
		var paras = $A(document.getElementsByTagName('select'));
		paras.each(Element.hide);
		setTimeout('showDropdowns()', 1);
	}

});

Event.observe(document, 'dom:loaded', function() {new MainMenu($$('#mainmenuend>ul').first(), 'current')});
var dp_cal;
var calendarPopUp, calendarPopUp2, calendarPopUp3;
var prop_id, prop_sys;
var addEndDate;
var curAjaxReques = null, curAjaxReques1 = null;
var curPath;
var dropDown_islands;
var dropDown_neighborhoods;
var dropDown_resorts;
var dropDown_features;
var dropDown_bedrooms;
var zeroPadding = false;
var weatherBlocks;
var curPointer = 0;
var weatherSpeed = 4000;
var requestProps = [];
var developer = false;
var priceDivOnClose;
var datesChanged = false;
var islandNames = {
	'i1': 'Big Island',
	'i2': 'Maui',
	'i5': 'Oahu',
	'i6': 'Kauai'
};
var ajaxNarrowServlet = '/search/narrow_list';
var btnToHide;

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

MsgIslands = {
	choosen: new Hash({all:'Select an Island ', mixed:'Preferred Islands '})
};
MsgNeightborhoods = {
	choosen: new Hash({all:'All Neighborhoods ', mixed:'Preferred Neighborhoods '})
};
MsgResorts = {
	choosen: new Hash({all:'All Resorts ', mixed:'Preferred Resorts '})
};
MsgFeatures = {
	choosen: new Hash({all:'All Features ', mixed:'Preferred Features '})
};
MsgBedrooms = {
	choosen: new Hash({all:'Any', mixed:''})
};

function init(islandsDropDown) {
	new LoginMenu();
	if (islandsDropDown) {
		dropDown_islands = new CustomComponents.DropDownMenu('searchIslands');
		dropDown_islands.create(selectIslands, loadNeighborhoods2, "dropdown2", {Messages:MsgIslands});
	} else {
		var id = parseInt($('islands').value);
		if (id) {
			$('searchIslands').innerHTML = islandNames['i'+id];
		}
	}
	dropDown_neighborhoods = new CustomComponents.DropDownMenu('searchNeighborhoods');
	dropDown_neighborhoods.create(selectNeightborhoods, loadResorts, "checkbox", {Messages:MsgNeightborhoods, InactiveCss:'msDropDown_grey'});
	dropDown_resorts = new CustomComponents.DropDownMenu('searchResorts');
	dropDown_resorts.create(selectResorts, null, "checkbox", {Messages:MsgResorts, InactiveCss:'msDropDown_grey'});
	dropDown_features = new CustomComponents.DropDownMenu('searchFeatures');
	dropDown_features.create(selectFeatures, null, "checkbox", {Messages:MsgFeatures});
	dropDown_bedrooms = new CustomComponents.DropDownMenu('searchBedrooms');
	dropDown_bedrooms.create(selectBedrooms, setBedrooms, "dropdown", {Messages:MsgBedrooms});
	if ($(curPath)) {
		$(curPath).addClassName('current');
	}
	initWeather();
}
function init2() {
	new LoginMenu();
	if ($(curPath)) {
		$(curPath).addClassName('current');
	}
	initWeather();
}
function resetSearchForm(islandsDropDown) {
	$('islands').value = '';
	if (islandsDropDown) {
		unselectIslands();
		dropDown_islands.closeMenu();
		dropDown_islands.create(selectIslands, loadNeighborhoods2, "dropdown2", {Messages:MsgIslands});
	} else {
		$('searchIslands').innerHTML = 'Select an Island';
	}
	dropDown_neighborhoods.closeMenu();
	dropDown_neighborhoods.create(selectNeightborhoods, loadResorts, "checkbox", {Messages:MsgNeightborhoods});
	dropDown_resorts.closeMenu();
	dropDown_resorts.create(selectResorts, null, "checkbox", {Messages:MsgResorts});
	dropDown_features.closeMenu();
	dropDown_features.create(selectFeatures, null, "checkbox", {Messages:MsgFeatures});
	dropDown_bedrooms.create(selectBedrooms, setBedrooms, "dropdown", {Messages:MsgBedrooms});
	$('searchForm').reset();
}
function unselectIslands() {
	selectIslands.each( function(item) {
		item.selected = false;
	});
}

function initWeather() {
	weatherBlocks = $('hiddenWeather').childElements();
	if (weatherBlocks.length) {
		$('currentWeather').innerHTML = weatherBlocks[curPointer].innerHTML;
		//$('currentWeather').update(weatherBlocks[curPointer]);
		setTimeout(changeWeather, weatherSpeed);
	}
}

function changeWeather() {
	if (++curPointer>=weatherBlocks.length) {
		curPointer = 0;
	}
	$('currentWeather').innerHTML = weatherBlocks[curPointer].innerHTML;
	//$('currentWeather').update(weatherBlocks[curPointer]);
	setTimeout(changeWeather, weatherSpeed);
}

function showIslandsForm(force) {
	if ($('searchIslandsPopup').style.display=='none' || force==true) {
		$('searchIslandsPopup').style.display = 'block';
	} else {
		$('searchIslandsPopup').style.display = 'none';
	}
}

function chooseIsland(id) {
	$('islands').value = id;
	$('searchIslands').innerHTML = islandNames['i'+id];
	// emulate mouse click :)
	var evt = {value:id}
	loadNeighborhoods2(evt);
	$('searchIslandsPopup').style.display = 'none';
}

function ensureNumeric(e) {
var k = (typeof e.charCode == "undefined" ? e.keyCode : e.charCode);
if (k < 32 || e.ctrlKey || e.altKey || e.metaKey)
	return true;
return (k >= 48 && k <= 57);
}

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 switchDetailsTab(link, div) {
	var links = $('property_tabs').select('a');
	if (links) {
		links.each(function(item) {
			item.removeClassName('current_tab');
		});
	}
	link.addClassName('current_tab');
	$(active_prop_tab).hide();
	$(div).show();
	$(div).setStyle({zIndex:0,visibility:'visible',position:'relative'});
	active_prop_tab = div;
}

function switchEl(cur, id) {
	var links = $($(cur).parentNode).select('a');
	if (links) {
		links.each( function(item) {
			item.removeClassName('current');
		});
	}
	$(cur).addClassName('current');
	var uls = $($($(cur).parentNode).parentNode).select('ul');
	if (uls) {
		uls.each( function(item) {
			item.hide();
		});
	}
	if ($(id)) {
		$(id).show();
	}
}

function setSearchPage(page) {
	var loc = document.location;
	var s = loc.search;
	var path = loc.pathname;
	if (s.match(/pageNumber=/)) {
		// request from search form
		s = s.replace(/pageNumber=\d+/, 'pageNumber='+page);
	} else if (!s.length) {
		// request from menu or map
		if (path.match(/page\d+\.html/)) {
			path = path.replace(/page\d+\.html/, 'page'+page+'.html');
		} else {
			if (!path.match(/\/$/)) {
				path += '/';
			}
			path += 'page'+page+'.html';
		}
	}
	document.location.href = document.location.protocol+'//'+document.location.host+path+s;
}

function setPerPage(number) {
	$('number').value = number;
	$('searchForm').submit();
}

function setSortOrder(val) {
	var loc = document.location;
	var s = loc.search;
	var path = loc.pathname;
	if (s.match(/pageNumber=/)) {
		s = s.replace(/pageNumber=\d+/, 'pageNumber=1');
	} else {
		if (path.match(/page\d+\.html/)) {
			path = path.replace(/page\d+\.html/, '');
		}
		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;
	}
	if (!s.match(/token=/)) {
		s += '&token='+parseInt(Math.random()*1000);
	}
	document.location.href = document.location.protocol+'//'+document.location.host+path+s;
}

function narrowSetPage(num) {
	var tmp = $('narrowList').innerHTML;
	$('narrowList').innerHTML = '<img src="/img/progress3.gif" width="82" height="22" alt="" />';
	if (curAjaxReques1) {
		curAjaxReques1.abort();
	}
	try {
		curAjaxReques1 = new Ajax.Request(ajaxNarrowServlet, {
			method: 'post',
			parameters: {
				prop_id: escape(prop_id),
				page: num
			},
			onComplete: function(transport) {
				var respJS = transport.responseText.evalJSON();
				if (respJS.success) {
					$('narrowList').innerHTML = respJS.content;
					if (respJS.requestProps) {
						requestProps = respJS.requestProps;
						ajaxRequestProps();
					}
				}
			},
			onFailure: function() {
				$('narrowList').innerHTML = tmp;
			}
		});
	} catch (e) {
		alert(e);
	}
}


function loadNeighborhoods(porop) {
	if (!porop.items.length) return;
	// reset resorts
	$('searchResorts').innerHTML = "All Resorts";
	dropDown_resorts.create([], null, "checkbox", {Messages:MsgResorts});
	$('searchResorts').addClassName('msDropDown_grey');
	if (!porop.checked.length) {
		$('searchNeighborhoods').innerHTML = "All Neighborhoods";
		dropDown_neighborhoods.create([], loadResorts, "checkbox", {Messages:MsgNeightborhoods});
		$('searchNeighborhoods').addClassName('msDropDown_grey');
		return;
	}
	var parents = '';
	porop.checked.each( function(item) {
		if (parents.length) {
			parents += ',';
		}
		parents += item.value;
	});
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
		method: 'post',
		parameters: {
			m: 'areasearch',
			action: 'getNeighborhoodCombo',
			type: 'neighborhood',
			parent: parents
		},
		onSuccess: function(transport){
			var tmp = transport.responseText.evalJSON();
			dropDown_neighborhoods.create(tmp, loadResorts, "checkbox", {Messages:MsgNeightborhoods});
			$('searchNeighborhoods').removeClassName('msDropDown_grey');
		},
		onFailure: function() {}
	});
}

function loadResorts(porop) {
	if (!porop.items.length) return;
	var parents = '';
	porop.checked.each( function(item) {
		if (parents.length) {
			parents += ',';
		}
		parents += item.value;
	});
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
		method: 'post',
		parameters: {
			m: 'areasearch',
			action: 'getResortCombo',
			type: 'resort',
			parent: parents
		},
		onSuccess: function(transport){
			var tmp = transport.responseText.evalJSON();
			dropDown_resorts.create(tmp, null, "checkbox", {Messages:MsgResorts});
			$('searchResorts').removeClassName('msDropDown_grey');
		},
		onFailure: function() {}
	});
}

function setBedrooms(evt) {
	// I didn't check what type of component was fired!!!
	if (evt.value && parseFloat(evt.value)) {
		$('bedrooms').value = evt.value;
	} else {
		$('bedrooms').value = '';
	}
}

function loadNeighborhoods2(evt) {
	if (evt.value && parseInt(evt.value)) {
		$('islands').value = evt.value;
		// reset resorts
		$('searchResorts').innerHTML = "All Resorts";
		dropDown_resorts.create([], null, "checkbox", {Messages:MsgResorts});
		$('searchResorts').addClassName('msDropDown_grey');
		$('searchNeighborhoods').innerHTML = "All Neighborhoods";
		dropDown_neighborhoods.create([], loadResorts, "checkbox", {Messages:MsgNeightborhoods});
		$('searchNeighborhoods').addClassName('msDropDown_grey');
		if (curAjaxReques) {
			curAjaxReques.abort();
		}
		curAjaxReques = new Ajax.Request('/utils/ajax_controller', {
			method: 'post',
			parameters: {
				m: 'areasearch',
				action: 'getNeighborhoodCombo',
				type: 'neighborhood',
				parent: evt.value
			},
			onSuccess: function(transport){
				var tmp = transport.responseText.evalJSON();
				dropDown_neighborhoods.create(tmp, loadResorts, "checkbox", {Messages:MsgNeightborhoods});
				$('searchNeighborhoods').removeClassName('msDropDown_grey');
			},
			onFailure: function() {}
		});
	} else {
		$('islands').value = '';
	}
}

function printThis(id) {
	if (typeof(id) != 'undefined') {
		var a = window.open('/property_details/print?prop_id='+escape(id),'printing','scrollbars=yes,width=800');
	} else {
		var a = window.open('','printing','scrollbars=yes,width=700');
		a.document.open("text/html");
		a.document.write('<html><head><link href="/css/styles.css" rel="stylesheet" type="text/css" /><link href="/css/print.css" rel="stylesheet" type="text/css" /></head><body>');
		a.document.write($('print_area').innerHTML);
		a.document.write('</body></html>');
		a.document.close();
		a.print();
		a.close();
	}
}

function checkFavList() {
	if (!checkFields('FromName', 'FromEMail', 'ToName', 'ToEMail', 'Subject', 'code')) {
		return false;
	}
	emailFavLink();
}

function checkInquireForm() {
	if ($('FName').value=='First Name') {
		alert("First Name Field is Empty");
		return false;
	}
	if ($('LName').value=='Last Name') {
		alert("Last Name Field is Empty");
		return false;
	}
	if (!checkFields('FName','LName','EMail','EMail2')) {
		return false;
	}
	if ($('EMail').value!=$('EMail2').value) {
		alert("Emails Are Different");
		return false;
	}
	/*
	if (!$('Phone').value.match(/\d{10}/)) {
		$('Phone').value = "";
	}
	if (!$('Arrival').value.match(/\d{1,2}\/\d{1,2}\/\d{4}/)) {
		$('Arrival').value = "";
	}
	if (!$('Departure').value.match(/\d{1,2}\/\d{1,2}\/\d{4}/)) {
		$('Departure').value = "";
	}
	*/
	emailInquireForm();
}

function checkSearchList() {
	if (!checkFields('FromName', 'FromEMail', 'ToName', 'ToEMail', 'Subject', 'code')) {
		return false;
	}
	emailSearchLink();
}

function checkCompareList() {
	if (!checkFields('FName', 'FEMail', 'Name', 'EMail', 'Subject', 'code')) {
		return false;
	}
	emailCompareLink();
}

function checkPropertyLink() {
	if (!checkFields('FromName', 'FromEMail', 'ToName', 'ToEMail', 'ThisSubject', 'code2')) {
		return false;
	}
	emailPropertyLink();
}

function showEmailListLink(el) {
	var parent = el.parentNode;
	$('popup_email_list_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	$j('#popup_form').show();
	$j('#popup_email_list_div').fadeIn('fast');
}

function showEmailLink(el) {
	var parent = el.parentNode;
	$('popup_email_link_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	$j('#popup_form').show();
	$j('#popup_email_link_div').fadeIn('fast');
}

function showCompareLink(el) {
	var parent = el.parentNode;
	$('popup_email_link_div').clonePosition(parent, {setWidth:false,setHeight:false});
	$j('#popup_form').show();
	$j('#popup_email_link_div').fadeIn('fast');
}

function showEmailFavListLink(el) {
	var parent = el.parentNode;
	$('popup_email_list_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	$j('#popup_form').show();
	$j('#popup_email_list_div').fadeIn('fast');
}

function showFlipKey(el, url) {
	//$('popup_guest_div').hide();
	$('widget').innerHTML = '<img src="/img/progress2.gif" width="90" height="16" alt="" />';
	var parent = el.parentNode.parentNode;
	$('popup_guest_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	new Effect.Appear('popup_guest_div');
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/getcontents.php?url='+escape(url),
	{
		method: 'post',
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('widget')) {
					$('widget').innerHTML = respJS.content;
				}
			}
		}
	});
}

function showInquireForm(el, prop, url) {
	btnToHide = el;
	var head, parent = el.parentNode;
	$('inquire_form_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	if (head = $j('div[prop_id="'+prop+'"]')) {
		$j('#formHeader').replaceWith('<div id="formHeader">'+head.html()+'</div>');
		$('PROPID').value = prop;
		$('Link').value = url;
	}
	$j('#inquire_form_div').show();
}

function showFlipKey3(el, url) {
	//$('popup_guest_div').hide();
	$j.scrollTo($j('#property_tabs'), {duration: 500});
	$('widget').innerHTML = '<img src="/img/progress2.gif" width="90" height="16" alt="" />';
	var parent = el.parentNode;
	$('popup_guest_div').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	new Effect.Appear('popup_guest_div');
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/getcontents.php?url='+escape(url),
	{
		method: 'post',
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('widget')) {
					$('widget').innerHTML = respJS.content;
				}
			}
		}
	});
}

function showFlipKey2(url) {
	//$('popup_guest_div').hide();
	$('widget').innerHTML = '<img src="/img/progress2.gif" width="90" height="16" alt="" />';
	if (curAjaxReques) {
		curAjaxReques.abort();
	}
	curAjaxReques = new Ajax.Request('/getcontents.php?url='+escape(url),
	{
		method: 'post',
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('widget')) {
					$('widget').innerHTML = respJS.content;
				}
			}
		}
	});
}

function emailFavorites() {
	new Ajax.Request('/favorites/email_favorites',
	{
		method: 'post',
		parameters: {
			_prepare: true
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('shadowbox_content')) {
					$('shadowbox_content').innerHTML = respJS.content;
				} else {
					Shadowbox.open({
						content: respJS.content,
						type:   'html',
						title:  '',
						width:  700,
						height: 500
					});
				}
			}
		}
	});
}

function emailFavoritesList() {
	var params = $('favorites_email').serialize(true);
	new Ajax.Request('/favorites/email_favorites',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('shadowbox_content')) {
					$('shadowbox_content').innerHTML = respJS.content;
				}
			}
		}
	});
}

function emailLink() {
	new Ajax.Request('/search/search_email',
	{
		method: 'post',
		parameters: {
			_prepare: $('_currSearchURL').value
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('shadowbox_content')) {
					$('shadowbox_content').innerHTML = respJS.content;
				} else {
					Shadowbox.open({
						content: respJS.content,
						type:   'html',
						title:  '',
						width:  700,
						height: 500
					});
				}
			}
		}
	});
}

function emailProperty() {
	new Ajax.Request('/property_details/property_email',
	{
		method: 'post',
		parameters: {
			_prepare: $('_currSearchURL').value
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('shadowbox_content')) {
					$('shadowbox_content').innerHTML = respJS.content;
				} else {
					Shadowbox.open({
						content: respJS.content,
						type:   'html',
						title:  '',
						width:  700,
						height: 500
					});
				}
			}
		}
	});
}

function emailCompare() {
	new Ajax.Request('/property_details/compare_email',
	{
		method: 'post',
		parameters: {
			_prepare: $('_currSearchURL').value
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				if ($('shadowbox_content')) {
					$('shadowbox_content').innerHTML = respJS.content;
				} else {
					Shadowbox.open({
						content: respJS.content,
						type:   'html',
						title:  '',
						width:  700,
						height: 500
					});
				}
			}
		}
	});
}

function emailPropertyLink() {
	var params = $('property_link').serialize(true);
	$j('#popup_form').hide();
	new Ajax.Request('/property_details/property_email',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				$('FromName').value = $('FromEMail').value = $('ToName').value = $('ToEMail').value = $('ThisSubject').value = $('ThisMessage').value = $('code2').value = '';
				$j('#popup_email_link_div').fadeOut('fast',
					function() {
						// reload captcha
						var rnd = Math.round(Math.random(0)*1000)+1;
						var img = document.images.captcha1;
						if (img && img.src.match(/\?_dc=/)) {
							img.src = img.src.replace(/\?_dc=\d+/, '?_dc='+rnd);
						} else {
							img.src = img.src + '?_dc='+rnd;
						}
						alert(respJS.content);
					}
				);
			} else {
				alert(respJS.content);
			}
		},
		onFailure: function() {}
	});
}

function emailInquireForm() {
	var params = $('prop_inquire').serialize(true);
	new Ajax.Request('/property_details/inquire_property_details',
	{
		method: 'post',
		parameters: params,
		onSuccess: function inquireSuccess1(transport){
			if ($j('#inquire_form_div')) {
				// popup inquire form
				$j('#inquire_form_div').hide();
			}
			if ($j(btnToHide)) {
				$j(btnToHide).hide();
			}
			var respJS = transport.responseText.evalJSON();
			/*
			if (respJS.success) {
				$('Arrival').value = 'Arrival';
				$('Departure').value = 'Departure';
				$('Comment').value = 'Comment';
			}
			*/
			alert(respJS.content);
		}
	});
}

function emailCompareLink() {
	var params = $('compare_link').serialize(true);
	$j('#popup_form').hide();
	new Ajax.Request('/property_details/compare_email',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				$('FName').value = $('FEMail').value = $('Name').value = $('EMail').value = $('Subject').value = $('Message').value = $('code').value = '';
				$j('#popup_email_link_div').fadeOut('fast',
					function() {
						// reload captcha
						var rnd = Math.round(Math.random(0)*1000)+1;
						var img = document.images.captcha;
						if (img && img.src.match(/\?_dc=/)) {
							img.src = img.src.replace(/\?_dc=\d+/, '?_dc='+rnd);
						} else {
							img.src = img.src + '?_dc='+rnd;
						}
						alert(respJS.content);
					}
				);
			} else {
				alert(respJS.content);
			}
		},
		onFailure: function() {}
	});
}

function emailSearchLink() {
	var params = $('search_link').serialize(true);
	$j('#popup_form').hide();
	new Ajax.Request('/search/search_email',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				$('FromName').value = $('FromEMail').value = $('ToName').value = $('ToEMail').value = $('Subject').value = $('Message').value = $('code').value = '';
				$j('#popup_email_list_div').fadeOut('fast',
					function() {
						// reload captcha
						var rnd = Math.round(Math.random(0)*1000)+1;
						var img = document.images.captcha;
						if (img && img.src.match(/\?_dc=/)) {
							img.src = img.src.replace(/\?_dc=\d+/, '?_dc='+rnd);
						} else {
							img.src = img.src + '?_dc='+rnd;
						}
						alert(respJS.content);
					}
				);
			} else {
				alert(respJS.content);
			}
		},
		onFailure: function() {}
	});
}

function emailFavLink() {
	var params = $('favorites_email').serialize(true);
	$j('#popup_form').hide();
	new Ajax.Request('/favorites/email_favorites',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				$('FromName').value = $('FromEMail').value = $('ToName').value = $('ToEMail').value = $('Subject').value = $('Message').value = $('code').value = '';
				$j('#popup_email_list_div').fadeOut('fast',
					function() {
						// reload captcha
						var rnd = Math.round(Math.random(0)*1000)+1;
						var img = document.images.captcha;
						if (img && img.src.match(/\?_dc=/)) {
							img.src = img.src.replace(/\?_dc=\d+/, '?_dc='+rnd);
						} else {
							img.src = img.src + '?_dc='+rnd;
						}
						alert(respJS.content);
					}
				);
			} else {
				alert(respJS.content);
			}
		},
		onFailure: function() {}
	});
}


function removeCompare(prop) {
	new Ajax.Request('/compare',
	{
		method: 'get',
		parameters: {
			action: 'remove',
			prop_id: prop
		},
		onComplete: function() {
			document.location.href = '/compare';
		}
	});
}

function addCompare(prop) {
	new Ajax.Request('/compare',
	{
		method: 'get',
		parameters: {
			action: 'add',
			prop_id: prop
		},
		onComplete: function() {
			document.location.href = '/compare';
		}
	});
}

function showCalendar(el, prop, system, token, relocate, onclose) {
	datesChanged = false;
	var parent = el.parentNode.parentNode;
	$('priceQuoteDiv').clonePosition(parent, {setLeft:false,setWidth:false,setHeight:false});
	$('priceQuoteDiv').innerHTML = '<img src="/img/progress.gif" width="16" height="16" alt="" /><span style="color:red;font-weight:bold;" > Loading Real Time Availability & Pricing</span>';
	$('priceQuoteDiv').show();
	if (typeof(relocate)!=='undefined') {
		$j.scrollTo(0, {duration: 500});
	}
	priceDivOnClose = (typeof(onclose)=='function') ? onclose : null;
	new Ajax.Request('/search/price_quote',
	{
		method: 'get',
		parameters: {
			action: 'get_calendar',
			prop_id: prop,
			sys: system,
			token: token
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.calendar) {
				$('priceQuoteDiv').innerHTML = respJS.calendar;
				//minNights = parseInt(respJS.minStay);
				//maxNights = parseInt(respJS.maxStay);
				calendarStart = respJS.calendarStart;
				$j(function() {
						$j('#book_check_in').datepicker({
						changeMonth: true,
						changeYear: true,
						minDate: 0,
						maxDate: '+2Y',
						dateFormat: 'm/d/yy',
						onSelect: function (dates){
							$j('#book_check_out').datepicker("option", {minDate: dates});
							updateCalendar2();
						}
					});
					$j('#book_check_out').datepicker({
						minDate: 0,
						maxDate: '+2Y',
						dateFormat: 'm/d/yy',
						changeMonth: true,
						changeYear: true,
						onSelect: function (dates){
							updateCalendar3();
						}
					});
				});
				if (parseInt($('nights').value) && $('check_in').value.length) {
					$('book_nights').value = $('nights').value;
					$('book_check_in').value = $('check_in').value;
					$('book_check_out').value = $('check_out').value;
				} else{
					$('book_nights').value = minNights;
					dt1 = new Date();
					dt2 = new Date(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()+1, 0, 0, 0, 0);
					dt3 = new Date(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()+minNights+1, 0, 0, 0, 0);
					$('book_check_in').value = zDate(dt2.getMonth()+1)+'/'+zDate(dt2.getDate())+'/'+dt2.getFullYear();
					$('book_check_out').value = zDate(dt3.getMonth()+1)+'/'+zDate(dt3.getDate())+'/'+dt3.getFullYear();
				}
				updateCalendar2();
			} else {
				$('priceQuoteDiv').innerHTML = "Something wrong";
			}
		},
		onFailure: function(transport){
			$('priceQuoteDiv').innerHTML = "We're sorry, this feature is temporarily unavailable. Please try again later. <div style='overflow: hidden; width: 115px; margin-top: 10px; float: right;'><a href='javascript:hideCalendar()' class='button size_100'><span><b>Close Window</b></span></a></div>";
		}
	});
}

function hideCalendar() {
	if (datesChanged && priceDivOnClose && typeof(priceDivOnClose)=='function') {
		priceDivOnClose();
	}
	$('priceQuoteDiv').hide();
}

function adjustNights() {
	if ($('check_in').value.length && $('check_out').value.length) {
		dt1 = new Date($('check_in').value);
		dt2 = new Date($('check_out').value);
		if (dt1.getTime()>dt2.getTime()) {
			return;
		}
		var nights = Math.ceil((dt2 - dt1)/86400000);
		if (nights<0) {
			nights = -nights;
		}
		$('nights').value = nights;
	} else {
		$('nights').value = '';
	}
}
function adjustCheckOut() {
	if (parseInt($('nights').value) && $('check_in').value.length) {
		dt1 = new Date($('check_in').value);
		dt2 = new Date(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()+parseInt($('nights').value), 0, 0, 0, 0);
		$('check_out').value = zDate(dt2.getMonth()+1)+'/'+zDate(dt2.getDate())+'/'+dt2.getFullYear();
	}
}
function zDate(x){
	if (!zeroPadding) {
		return x;
	} else {
		return(x<0||x>9?'':'0')+ x;
	}
}

function adjustBookingNights() {
	if ($('book_check_in').value.length && $('book_check_out').value.length) {
		var hold = [$('book_check_in').value, $('book_check_out').value, $('book_nights').value];
		dt1 = new Date($('book_check_in').value);
		dt2 = new Date($('book_check_out').value);
		if (dt1.getTime()>dt2.getTime()) {
			return;
		}
		var nights = Math.ceil((dt2 - dt1)/86400000);
		if (nights<0) {
			nights = -nights;
		}
		/*
		if (nights>maxNights) {
			$('book_check_in').value = hold[0];
			$('book_check_out').value = hold[1];
			$('book_nights').value = hold[2];
			alert('Max nights is '+maxNights);
			return;
		}
		if (nights<minNights) {
			$('book_check_in').value = hold[0];
			$('book_check_out').value = hold[1];
			$('book_nights').value = hold[2];
			alert('Min nights is '+minNights);
			return;
		}
		*/
		$('book_nights').value = nights;
	} else {
		$('book_nights').value = '';
	}
}
function adjustBookingCheckOut() {
	if (parseInt($('book_nights').value) && $('book_check_in').value.length) {
		var hold = [$('book_check_in').value, $('book_check_out').value];
		var nights = parseInt($('book_nights').value);
		/*
		if (nights>maxNights) {
			$('book_check_in').value = hold[0];
			$('book_check_out').value = hold[1];
			$('book_nights').value = maxNights;
			alert('Max nights is '+maxNights);
			return;
		}
		if (nights<minNights) {
			$('book_check_in').value = hold[0];
			$('book_check_out').value = hold[1];
			$('book_nights').value = minNights;
			alert('Min nights is '+minNights);
			return;
		}
		*/
		dt1 = new Date($('book_check_in').value);
		dt2 = new Date(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()+nights-1, 0, 0, 0, 0);
		$('book_check_out').value = zDate(dt2.getMonth()+1)+'/'+zDate(dt2.getDate())+'/'+dt2.getFullYear();
	}
}
function adjustBookingNightsLoad() {
	//adjustBookingNights();
	updateCalendar2();
}
function adjustBookingCheckOutLoad() {
	//adjustBookingCheckOut();
	updateCalendar2();
}

function managerLogin() {
	if (!checkFields('Username', 'Password')) {
		return;
	}
	new Ajax.Request('/utils/ajax_controller?m=login&action=adminLogin',
	{
		method: 'post',
		parameters: {
			m: 'login',
			action: 'managerLogin',
			user: $('Username').value,
			password: $('Password').value,
			referer: escape(document.location.href)
		},
		onSuccess: function(transport){
			var respJS = transport.responseText.evalJSON();
			if (respJS.success) {
				document.location.href = "/admin";
			} else {
				alert('User was not found');
			}
		},
		onFailure: function() {
		}
	});
}

// Sets cookie values. Expiration date is optional
function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

function getCookie(nm) {
	if (document.cookie.length > 0) {
		var re1 = /\s*;\s*/;
		var cooks = document.cookie.split(re1);
		var re2 = /\s*=\s*/;
		for ( i=0; i<cooks.length; i++ ) {
				var parts = cooks[i].split(re2,2);
				if (nm == parts[0]) {
					return unescape(parts[1]);
				}
		}
	}
	return "";
}

function deleteCookie(Name) {
	expireDate = new Date;
	expireDate.setDate(expireDate.getDate()-1);
	document.cookie = Name + "=; expires=" + expireDate.toGMTString();
}

function countCompares() {
	var tmp = [];
	var s = '';
	var cookies = getCookie('compare');
	if (cookies.length) {
		tmp = cookies.split(',');
	}
	if ($('compare_num')) {
		$('compare_num').innerHTML = '('+tmp.length+' Propert'+(tmp.length==1?'y':'ies')+')';
	}
	if ($('compare_number2')) {
		$('compare_number2').innerHTML = '('+tmp.length+')';
	}
	if ($('compare_number3')) {
		$('compare_number3').innerHTML = '('+tmp.length+')';
		$('compareBtn').innerHTML = tmp.length ? '-' : '+';
	}
}

function countFavs() {
	var tmp = [];
	var cookies = getCookie('favorites');
	if (cookies.length) {
		tmp = cookies.split(',');
	}
	if ($('fav_number')) {
		$('fav_number').innerHTML = '('+tmp.length+')';
	}
	if ($('fav_number2')) {
		$('fav_number2').innerHTML = '('+tmp.length+')';
	}
	if ($('fav_number3')) {
		$('fav_number3').innerHTML = '('+tmp.length+')';
		$('favoritesBtn').innerHTML = tmp.length ? '-' : '+';
	}
}

function ajaxRequestProps() {
	if (!requestProps.length) {
		return;
	}
	var domain = document.location.host.replace('www.','');
	var tmp = 1, count = 1;
	for (var i=0; i<requestProps.length; i++) {
		var url = (developer ? ('http://'+domain) : ('http://r'+tmp+'.helper.'+domain))+'/search/price_quote';
		var params = {
			action: 'get_xrent',
			prop_id: requestProps[i][1],
			sys: requestProps[i][2],
			check_in: $('check_in').value,
			nights: $('nights').value,
			key: requestProps[i][0]
		};
		$j.ajax({
			url: url,
			type: 'post',
			data: params,
			timeout: 20000,
			success: function(transport) {
				var respJS = transport.evalJSON();
				if (respJS.success) {
					if (respJS.data && respJS.data.key && $('price'+respJS.data.key)) {
						if (respJS.data.price && parseFloat(respJS.data.price)>0) {
							$('price'+respJS.data.key).innerHTML = '$'+respJS.data.price;
						} else {
							$('price'+respJS.data.key).innerHTML = '';
						}
					}
				}
			}
		});
		if (++count>2) {
			tmp++;
			count = 1;
		}
	}
}

function ajaxRequestPropsCompare() {
	if (!requestProps.length) {
		return;
	}
	var domain = document.location.host.replace('www.','');
	var tmp = 1, count = 1;
	for (var i=0; i<requestProps.length; i++) {
		var url = (developer ? ('http://'+domain) : ('http://r'+tmp+'.helper.'+domain))+'/search/price_quote';
		var params = {
			action: 'get_xrent',
			prop_id: requestProps[i][1],
			sys: requestProps[i][2],
			check_in: $('book_check_in').value,
			nights: $('book_nights').value,
			key: requestProps[i][0]
		};
		$j.ajax({
			url: url,
			type: 'post',
			data: params,
			timeout: 10000,
			success: function(transport) {
				var respJS = transport.evalJSON();
				if (respJS.success) {
					if (respJS.data && respJS.data.key && $('price'+respJS.data.key)) {
						if (respJS.data.price && parseFloat(respJS.data.price)>0) {
							$('price'+respJS.data.key).innerHTML = '$'+respJS.data.price;
						} else {
							$('price'+respJS.data.key).innerHTML = '';
						}
					}
				}
			}
		});
		if (++count>2) {
			tmp++;
			count = 1;
		}
	}
}

function ajaxRequestProp(token) {
	if (!requestProps.length) {
		return;
	}
	for (var i=0; i<requestProps.length; i++) {
		new Ajax.Request('/search/price_quote',
		{
			method: 'get',
			parameters: {
				action: 'get_discounted_rent',
				prop_id: requestProps[i][1],
				sys: requestProps[i][2],
				check_in: $('check_in').value,
				nights: $('nights').value,
				token: token
			},
			onSuccess: function(transport) {
				if (transport.responseText && $('price0')) {
					$('price0').innerHTML = transport.responseText;
				}
			}
		});
	}
}

function checkPrice(id, url) {
	if (!url.match(/step=/)) {
		if (!$j('#price'+id) || !$j('#price'+id).html() || !$j('#price'+id).html().length || $j('#price'+id+' a.big_arrow_link').length) {
			url += '&step=1';
		} else {
			url += '&step=2';
		}
	}
	document.location.href = url;
}

function resetToken(islandsDropDown) {
	if (!parseInt($('islands').value)) {
		if (islandsDropDown) {
			alert('Select an Island');
		} else {
			showIslandsForm(true);
		}
		return false;
	}
	if ($('token')) {
		$('token').value = Math.floor(Math.random()*1000);
	}
	$('searchForm').submit();
}

function reloadPage() {
	$('check_in').value = $('book_check_in').value;
	$('check_out').value = $('book_check_out').value;
	$('nights').value = $('book_nights').value;
	narrowSetPage(1);
	requestProps = [[0, prop_id, prop_sys]];
	$('price0').innerHTML = '<img src="/img/progress.gif" width="16" height="16" alt="" />';
	ajaxRequestProp($('token').value);
}

function bookingBack() {
	var res, s, f = $('book1');
	s = f.action;
	if (res = s.match(/step=\d+/)) {
		var tmp = res[0].split('=');
		var step = parseInt(tmp[1])-2;
		if (step>0) {
			f.action = s.replace(/step=\d+/, 'step='+step);
			f.submit();
		}
	}
	return false;
}

function reloadCaptcha(id) {
	if (typeof id == 'undefined') {
		id = 'captcha';
	}
	if (!$(id) || !$(id).src) {
		return;
	}
	$(id).src = '/utils/mathcaptcha?' + Math.random();
}
/*
// 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;
			case "dropdown2" :
				this.createDropdown_DropDown2(menu_array, childDiv, callBack, params)
			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]);
},
createDropdown_DropDown2: function(menu_Array, childDiv, callBack, params) {
	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 Messages = params.Messages || {};
	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;
	var currentLabel = Messages.choosen.get("all");
	if(typeof(currentObj) === "object" && currentObj !== null) {
		currentLabel = currentObj.label;
	} else {
		currentObj = new Object();
		currentObj.label = currentLabel;
		currentObj.value = '';
	}
	//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 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];
		//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});
		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("all");
										if(porop.items.length != checkedArray.length && checkedArray.length>0) {
											label = Messages.choosen.get("mixed");
											if (inactiveCss) {
												$(target_div).addClassName(inactiveCss);
											}
										} 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("all");
	if(porop.items.length != porop.checked.length && porop.checked.length>0) {
		label = Messages.choosen.get("mixed");
		if (inactiveCss) {
			parentNode.addClassName(inactiveCss);
		}
	} 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, childMenu = CustomComponents.StaticVars.currentChildMenu;
	if (childMenu!=null) {
		$(childMenu).hide();
		el = $(childMenu).next();
		if (el) {
			el.hide();
		}
		CustomComponents.Listeners.dispatchEvent(childMenu, "onMenuClose");
	}
	CustomComponents.StaticVars.isVisible = false;
	Event.stopObserving(document.body, 'mouseup');
},
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;
	}
}

