// @cvs-id $Id: lib.js,v 1.10 2005/02/01 15:32:22 nsadmin Exp $ $Name:  $
// Copyright 2004-2006 MedTouch LLC

// Cross-browser utilities

var agt = navigator.userAgent.toLowerCase();
var is_mac = (agt.indexOf("mac") != -1);


var isIE = ((agt.indexOf("msie") != -1) && (agt.indexOf("webtv") == -1)); 
var is_ie = isIE;
var ieP = isIE;


/*
function getByID( id, doc )
{
    if ( doc == null ) doc = 'document';

    if (eval(doc).getElementById) {
	// Newer browsers
	return eval(doc).getElementById(id);
    } else if (eval(doc).all) {
	// IE4
	return eval(doc).all[id];
    } else if (eval(doc).layers) {
	// NS4
	return eval(doc).layers[id];
    } else {
	alert( 'We couldn\'t recognize your browser.  Please use a different one or upgrade to the newest version.' );
	window.close();
    }
	return "";
}
*/
function getByID(id)
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function getXMLRequest () {
  if (window.ActiveXObject  && !is_mac) {
    return new window.ActiveXObject("Msxml2.XMLHTTP");
  } else if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }
}

// Useful color changing functions to highlight changed data or fields that
// need to be changed

function changeColor( id, color ) {
    var tag = getByID( id );
    if (tag.style) {
//	alert(id + "   ---  " + tag.style.backgroundColor + "  ---  " + color);
	tag.style.backgroundColor = color;
    } else if (tag.document && tag.document.bgColor)
	tag.document.bgColor = color;
}
 
var changedColor = '#ffddee';
var unchangedColor = 'white';

function markChanged( id ) {
    changeColor('row.'+id, changedColor);
} 

function markUnchanged( id ) {
    changeColor('row.'+id, unchangedColor);
} 

// onSubmit handlers for double-click protection
 
function refuseDoubleClick()
{
        alert('It looks like this form has already been submitted.  In order to prevent duplicate or broken data, we are refusing this submission.  You may re-load this page to re-submit');
        return false;
}
 
function testDoubleClick()
{
        return confirm('It looks like this form has already been submitted. If you re-submit it it could result in duplicate, or even broken, data.  Do you wish to proceed?');
}

var doubleClickProtect = false;

// If submitted once, use one of the above functions.
function checkDoubleClick( force )
{
    if ( doubleClickProtect ) {
	if ( force ) {
	    return refuseDoubleClick();
	} else {
	    return testDoubleClick();
	}
    } else {
	doubleClickProtect = true;
	return true;
    }
}

// Utilities for making alternating colors
var colorchanger = 0;
function makeCol (Color1, Color2)
{
    colorchanger++
    if (colorchanger % 2 == 0) {
	colorchanger = 0;
	document.write ("<TR bgcolor = "+ Color1 + ">");
    } else {
	document.write ("<TR bgcolor = "+ Color2 + ">");	
	
    }
}

function lastmakeCol (Color1, Color2)
{
    if (colorchanger % 2 == 0) {
	colorchanger = 0;
	document.write ("<TR bgcolor = "+ Color1 + ">");
    } else {
	document.write ("<TR bgcolor = "+ Color2 + ">");
    }
}

// Form validation (by paulm@oho.com)

function test_item_name (item_name, thisform)
{
    return (test_item (thisform[item_name]));

}

function set_id (item_name, id, thisform)
{
    if (!thisform[item_name].id) {
	thisform[item_name].id = id;
    }

}

function test_item (item)
{
var i;
/* alert (item.type + "  " + item.name); */
    
if (item.type == "text" || item.type == "textarea" || item.type=="password" || item.type=="hidden") {
    if (item.value != "") {
	return true;
    } else {
	return false;
    }
} else if (item.type == "checkbox" || item.type == "radio") {
    return item.checked;
} else if (item.type == "select-one" || item.type == "select-multiple") {
    for (i = 0; i < item.length; i++) 
    {
	if (item[i].selected && item[i].value != "") {
		return true;
	}
    }
    return false;
} else {
    for (i = 0; i < item.length; i++) 
    {
	if (test_item(item[i])) {
		return true;
	}
    }
}
return false;
}

function test_items (thisform)
{
    var i;	
    var emptyitems = "";
//Check date first
    startDate = $('Event Start Daterq').value;
    endDate = $('Event End Daterq').value;
    var myDate = new Date();
    var sDate = new Date(startDate);
    var eDate = new Date(endDate);
    if (sDate > eDate) {
      emptyitems += "Event Start Date\n";
    }
    if (sDate < myDate) {
      emptyitems += "Event Start Date\n";
    }
    if (myDate > eDate) {
      emptyitems += "Event End Date\n";
    }

/*
    if (startYear > endYear) {
      emptyitems += "Event End Date\n";
      emptyitems += "Event Start Date\n";
    } else {
        if (startYear < testYear) {
          emptyitems += "Event Start Date\n";
        } else {
            if (startMonth < testMonth && startYear == testYear)
		emptyitems += "Event Start Date\n";
            if (startMonth
*/    
    for (i=0; i < thisform.length; i++) {
	
//	thisform[i].id = "TEST";
	if (thisform[i].id != "" && thisform[i].id.substring(thisform[i].id.length - 2) == "rq" ) {
	    if (!thisform[i].id) {
		var j;
		var item = thisform[i];
		for (j=0; i < item.length; j++) 
		{		
		    if (item[j].id != "") 
		    {
		        if (test_item_name (item.name, thisform))
			{

			} else {
			    if (thisform[i].id) {
				emptyitems += thisform[i].id;
			    } else {
			 	emptyitems += thisform[i].name;
			    }
			    emptyitems += "\n";
		
			}
		    }
		}
	     } else {
		if (test_item_name (thisform[i].name, thisform)) {

		} else {
		    if (thisform[i].id) {
			if (thisform[i].type == 'hidden') {
				var Pretty = getByID(thisform[i].id + 'Pretty');
				if(Pretty) {
					changeColor(thisform[i].id + 'Pretty',changedColor);	
					Pretty=function onfocus(event) {
					    changeColor(this.id,unchangedColor);
					};
				}
			} else {
				changeColor (thisform[i].id, changedColor);

				thisform[i].onfocus=function onfocus(event) {
				    changeColor(this.id,unchangedColor);
				};
			}
			emptyitems += thisform[i].id.substring(0, thisform[i].id.length - 2);
		    } else {
			emptyitems += thisform[i].name;
		    }
		    emptyitems += "\n";
		}
	    }
	}
    }
    if (emptyitems != "") {
	alert ("You need to enter information for the following items: \n\n" + emptyitems);
	return false;
    } else {
	return true;
    }
}

// Display the source of the document (including everything that has been
// written into it via DHTML)
// tigre@ybos.net 2004-12-17

function showCurrentSource (doc, returnWin) {
    if (!doc) doc = document;
    var newWin = window.open(null,
			     'source_view',
			     'width=800,height=600,resizable=yes,toolbar=no,location=on,scrollbars=yes,status=no');
    newWin.document.write('<code><pre>\n'+doc.body.innerHTML.replace(/</g, '&lt;')+'</pre></code>');
    if (returnWin) {
	return newWin;
    }
}

// Snagged these two functions from http://www.quirksmode.com/js/findpos.html

function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
	while (obj.offsetParent)
	{
	     curleft += obj.offsetLeft
	     obj = obj.offsetParent;
	}
    }
    else if (obj.x)
	curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
	while (obj.offsetParent)
	{
	     curtop += obj.offsetTop
	     obj = obj.offsetParent;
	}
    }
    else if (obj.y)
	curtop += obj.y;
    return curtop;
}

// radioGetVal

function radioGetVal(form, fieldName) {
    var radio = form[fieldName];
    var buttons = radio.length;
    var i = 0;
    var selection;
    while (i < buttons)  {
	if (radio[i].checked) {
	    selection = radio[i].value;
	    break;
	}
	i++;
    }
    return selection;
}

// Encode the values of the fields listed in an array into a URLstring

function fieldsToQuery (arr) {
  var query = "";
  var field;
  for (var i = 0; i < arr.length; i++) {
    field = getByID(arr[i]);
    if (field.type != "checkbox" || field.checked) {
      value = field.value;
    } else {
      value = "";
    }
    if (i > 0) query += "&";
    query += encodeURIComponent(arr[i]) + "=" + encodeURIComponent(value);
  }
  return query;
}

// Flash stuff?  Who put this in?

var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
                var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i)
            {
                if (isNaN(parseInt(words[i])))
                continue;
                var MM_PluginVersion = words[i];
            }
        var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
   && (navigator.appVersion.indexOf("Win") != -1)) {
        document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
        document.write('on error resume next \n');
        document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
        document.write('</SCR' + 'IPT\> \n');
}
// added by BD 1/20
function openNewWin(page, win_name, width, height, scrollbars) {
        if(scrollbars) {
                var remote = window.open(page,win_name,"width=" + width + ",height=" + height + ",scrollbars");
        } else {
                var remote = window.open(page,win_name,"width=" + width + ",height=" + height + ",scrollbars=auto,resize=no");
        }
}
 
// added by BD 1/20
function randQuote() {
        var index = Math.floor(Math.random() * 12);
        quote = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
        document.write('<img src="/images/quotes/quote-' + quote[index] + '.gif" border="0" width="476" height="77">');
}

function ShowMenu(menuname) {
	var menu = getByID(menuname);
	menu.className = 'menu';
	menu.style.visibility = '';
	menu.style.top = '';
}


function HideMenu(menuname) {
	var menu = getByID(menuname);
	menu.style.visibility = 'hidden';
	menu.style.top = '-1000px';
}


function ShowObj(objname) {
	var obj = getByID(objname);
	obj.style.visibility = '';
	obj.style.top = '';
}


function HideObj(objname) {
	var obj = getByID(objname);
	obj.style.visibility = 'hidden';
	obj.style.top = '-1000px';
}

function HoverMenu2(objname) { 
	obj=getByID(objname);
	var sfEls = obj.getElementsByTagName("TD");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			
			this.className+="HoverMenu"; 
		}
		sfEls[i].onmouseout=function() {

			this.className=this.className.replace(new RegExp("HoverMenu\\b"), "");
		}
	}
}

function delete_quick_item(objname, type, id) {
	if (type != "special-packages" && type != "events") {
		type = "account";
	} else {
		id = type + "-" + id;
	}

	// Find out the number of entries, and increase it
	var number_of_entries = getByID('quicklist_number_of_entries').innerHTML;
	number_of_entries--;
	getByID('quicklist_number_of_entries').innerHTML = number_of_entries;

	if(number_of_entries == 1)
	  getByID('quicklist_entry_text').innerHTML = "entry";
	else
	  getByID('quicklist_entry_text').innerHTML = "entries";

	var obj = getByID(objname);
	obj.style.visibility = 'hidden';
	obj.style.position='absolute';
	obj.style.top = '-1000px';
	var cookies = readCookie('quick_items');
	var found_p = "false";
	var temp = 0;
	if (cookies != "null" && cookies) {
		var cookies_search = cookies;
		var first = 0;
		last = cookies_search.indexOf(",");
		while(last != -1 && found_p == "false" && temp++ < 50) {
			var item = cookies_search.substring(first, last);
		
			if (type == "account" && item.substring(0, item.indexOf("-")) != "events" && item.substring(0, item.indexOf("-")) != "special-packages") {
				item = item.substring((item.indexOf("-") + 1));		
			}
		//	alert("---" + item + "======" + id + "----");
			if (item == id) {
				found_p = "true";
			} else {
				first = last + 2;
				last = cookies_search.indexOf(",", first);
			}
			
		}
		if (found_p == "false") {
			item = cookies_search.substring(first);
			if (item == id) {
				found_p = "true";
			}
		}
	}
	if (first == 0) {
		if (last == -1) {
			// only one
			//	alert("delete");
			getByID('quick_items').innerHTML = "Click <em>Add to Trip Builder</em> button to create a customized list of accommodations, events, shops, etc.";
			writeCookie('quick_items', "");
		} else {
			writeCookie('quick_items', cookies_search.substring(last + 2));

		}
	} else {
		if (last == -1) {
			// last one
			writeCookie('quick_items', cookies_search.substring(0, first - 2));
		} else {
			writeCookie('quick_items', cookies_search.substring(0, first - 2) + cookies_search.substring(last));
		}
	}
}


function add_quick_item(id, title, town) {
	var cookies = readCookie('quick_items');
	var temp = 0;
	var found_p = "false";
	var tempid = id.substring(id.lastIndexOf("-"));
	if (cookies != "null" && cookies) {
		var cookies_search = cookies;
		var first = 0;
		last = cookies_search.indexOf(",");
		while(last != -1 && found_p == "false" && temp++ < 50) {
			var item = cookies_search.substring(first, last);
		//	alert("---" + item + "======" + id + "----");
			if (item == id) {
				found_p = "true";
			}
			first = last + 2;
			last = cookies_search.indexOf(",", first);
		}
		if (found_p == "false") {
			item = cookies_search.substring(first);
			if(item.indexOf('event') == -1 || item.indexOf('special-packages') == -1) {
				item = item.substring(item.indexOf("-"));
			
				if (item == tempid) {
					found_p = "true";
				}
			} else {
				if (item == id) {
					found_p = "true";
				}
			}
		}
	} else {
		getByID('quick_items').innerHTML = "";
	}
	if (found_p == "false") {
		var obj = getByID('quick_items');
		if (obj) {
			var output = obj.innerHTML;
		} else {
			var output = "";
		}
		// Find out the number of entries, and increase it
		var number_of_entries = getByID('quicklist_number_of_entries').innerHTML;
		number_of_entries++;
		getByID('quicklist_number_of_entries').innerHTML = number_of_entries;

                if(number_of_entries == 1)
                  getByID('quicklist_entry_text').innerHTML = "entry";
                else
                  getByID('quicklist_entry_text').innerHTML = "entries";


		number_of_quick++;
		output += "<div id=quickcontent_" + number_of_quick + ">\n";
		output += "<span  class=quickname><strong>";
		var tempid = id.substring((id.lastIndexOf("-") + 1));
		if(id.indexOf('event') != -1) {

			output += "<a href='/events/details?id=" + tempid + "'>";
		} else if (id.indexOf('special-packages') != -1) {
			output += "<a href='/trip-planner/details?id=" + tempid + "'>";
		} else {
			output += "<a href='/trip-planner/details?id=" + tempid + "'>";
		}
		output += title + "</a></strong><br>\n";
	        output += town + "</span>\n";
		var type = id.substring(0, id.lastIndexOf("-"));
		newid = id.substring((id.lastIndexOf("-") + 1));
		output += "<span class=quickdelete><a href=\"javascript:delete_quick_item('quickcontent_" + number_of_quick + "', '" + type + "', " + newid + ");\"><img src='/global/images/lcva/delete.gif' alt='delete' width='19' height='13' border='0'></a></span>\n";
	
		output += "<br clear='all'></div>\n\n";
		if (obj) {
		obj.innerHTML = output;
		}
		if (cookies == "" || cookies == null) {
			writeCookie('quick_items', id)
		} else {
			writeCookie('quick_items', cookies + ", " + id)
		}	
	}
}

function clear_quick_item() {
	writeCookie('quick_items', "");
	getByID('quick_items').innerHTML = "Click <em>Add to Trip Builder</em> button to create a customized list of accommodations, events, shops, etc.";
	getByID('quicklist_number_of_entries').innerHTML = "0";

}


function readCookie(name)
{
  name = cookie_name_extra + name;
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}



function writeCookie(cookie_name, value) {	
//	alert(document.cookie);
	cookie_name = cookie_name_extra + cookie_name;
	document.cookie = cookie_name + "=" + value +"; expires=Fri, 01-Jan-2035 01:00:00 GMT; path=/";

}



function fakehref(obj, base) {
	return;
	var link = obj.onclick + "";
	link = link.substring((link.indexOf('"') + 1), link.lastIndexOf('"'));
	window.status=base + link; 
	obj.onmouseout = function () {window.status="";};
}



function dropdown_menu_hack(obj)  {
	if (obj.dropdown_menu_hack!=null) {
		// obj.style.width = '';
		window.dropdown_menu_hack = 1;	
	} else {
		
	}
	obj.dropdown_menu_hack = 1
	if (obj.style.width != '') {
//		window.dropdown_menu_hack = 1;	
		var continuex = 0;
		var width = obj.style.width.replace(/px/, '');
		for (var i = 0; i < obj.options.length; i++) {
			// alert(obj.options[i].text.replace(/&nbsp; /, '').length * 6 + " > " + obj.style.width);
			if (obj.options[i].text.replace(/&nbsp; /, '').length * 6 > width) {
				continuex = 1
			}
		}	
//		alert(continuex);
		if (continuex == 1) {
			
			obj.awidth = obj.style.width;
		
			obj.parentNode.style.width=obj.style.width;
			obj.parentNode.style.overflow='hidden';
			f_show = function(e)
				{ 

					e.srcElement.style.width = '';
					return true;
				} 
			f_hide = function(e)
				{ 
					e.srcElement.style.width = e.srcElement.awidth;
					e.srcElement.focos = 'false'
				} 
			f_onfocus = function(e) {
					e.srcElement.focos = 'true'
				}
			f_onmouseout = function(e) {
	
				if (e.srcElement.focos != 'true') {
					e.srcElement.style.width = e.srcElement.awidth;
				}
			}
			obj.attachEvent("onmouseover",f_show);		
			obj.attachEvent("onblur",f_hide);		
			obj.attachEvent("onfocus",f_onfocus);		
			obj.attachEvent("onmouseout",f_onmouseout);	
		}	
		
	}
}

function max_chars (obj, size) {
	if (obj.value.length > size) {
		obj.value = obj.value.substring(0, size);
	}
}

function max_chars (obj, size, field) {
	if (obj.value.length > size) {
		alert("The maximum number of characters that can be entered is" + 
        	" " + size +". You have entered" +
        	" " + obj.value.length + " " + "characters.");
		obj.value = obj.value.substring(0, size);
	}
	field.value = size - obj.value.length;
}

function test_phone(e, obj) {
	if (navigator.appName == 'Microsoft Internet Explorer')
        	var achar = e.keyCode;
	    else
        	var achar = e.which;
//	if (achar == 8) {
//		obj.oldLen = obj.value.length;
//		return;
//	}
	var value = obj.value;
	if (!obj.oldLen && obj.oldLen != 0)
	{
		obj.oldLen=0
	}
	if (obj.oldLen >= obj.value.length) {
		
		if (obj.value==obj.oldvalue || obj.value == (obj.oldvalue.substr(0, obj.value.length))) {
					obj.oldvalue=obj.value;
			obj.oldLen = obj.value.length;
			return;
		}
	}
	var new_value = "";
	for (i = 0; i < value.length; i++) {
		if (i < 12) {
		//	alert(value.charAt(i) * 1 + " == " + value.charAt(i));
			if (value.charAt(i) * 1 == value.charAt(i) && value.charAt(i) != " ") {
				new_value += value.charAt(i);
			}
			if (new_value.length == 3 || new_value.length == 7) {
				new_value += "-";
			}
		} else {
			new_value += value.charAt(i);
		}
	}
	if (obj.value == new_value) {
		return;
	}
	obj.oldvalue=new_value;
	obj.value=new_value;
	obj.oldLen = new_value.length;
	return true;
	
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

	
function just_numbers (obj) {
	var x=obj.value;
	x = x.replace(/\D/ig,''); 
	if (x != obj.value) {
		obj.value=x;
	}
}


function find_length(obj) {
	var value = obj.value;
	if (value == "") {
		return 0;
	}
	var myString = new String(value);

        var results = myString.split(/\s+/);
	if (!results) {
		return 0;
	}
        var matches = results.length;
	return matches;
}

function setlength(e, obj, length, output_id) {
		
	
	var value = obj.value;
        var matches = find_length(obj);
	if (output_id) {
		var out = getByID(output_id);
		if (out) {
			if (length < matches) {
				out.innerHTML = 0;
			} else {
				out.innerHTML = length - matches;
			}
		}
	}
        if (length < matches) {
	    var reg = "\\S+";
	    for (i = 1; i < length; i++) {
   			reg += "\\s*\\S*"
	    }
            reg += "\\s";
	    var myregexp = new RegExp(reg);
            var output = myregexp.exec(value);
	   obj.value=output;
            return false;
        }
        return true;
}
function toggleObj(obj_id) {

	if (getByID(obj_id).style.display == 'none') {
		getByID(obj_id).style.display = '';
	} else {
		getByID(obj_id).style.display = 'none';
	}
}
function showObj(obj_id) {
	getByID(obj_id).style.display = '';
}
function hideObj(obj_id) {
	getByID(obj_id).style.display = 'none';
}


// Useful for creating a pop-up notification of some sort

function newWindow(url, name, width, height) {
  var newwin = window.open(url,name,
			   (width ? 'width=' + width + ',' : '') +
			   (height ? 'height=' + height + ',' : '') +
			   'resizable=yes, titlebar=no,toolbar=no,location=no,scrollbars=yes,status=no');
  newwin.focus();
  return newwin;
}

// Meetings and Events saved results
function meetings_delete_quick_item(objname, type, id) {
	type = "meeting_facility";
	// Find out the number of entries, and increase it
	var meetings_number_of_entries = getByID('meetings_quicklist_number_of_entries').innerHTML;
	meetings_number_of_entries--;
	getByID('meetings_quicklist_number_of_entries').innerHTML = meetings_number_of_entries;

	if(meetings_number_of_entries == 1)
	  getByID('meetings_quicklist_entry_text').innerHTML = "entry";
	else
	  getByID('meetings_quicklist_entry_text').innerHTML = "entries";

	var obj = getByID(objname);
	obj.style.visibility = 'hidden';
	obj.style.position='absolute';
	obj.style.top = '-1000px';
	var cookies = readCookie('meetings_quick_items');
	var found_p = "false";
	var temp = 0;
	if (cookies != "null" && cookies) {
		var cookies_search = cookies;
		var first = 0;
		last = cookies_search.indexOf(",");
		while(last != -1 && found_p == "false" && temp++ < 50) {
			var item = cookies_search.substring(first, last);
		
			if (type == "account" && item.substring(0, item.indexOf("-")) != "events" && item.substring(0, item.indexOf("-")) != "special-packages") {
				item = item.substring((item.indexOf("-") + 1));		
			}
		//	alert("---" + item + "======" + id + "----");
			if (item == id) {
				found_p = "true";
			} else {
				first = last + 2;
				last = cookies_search.indexOf(",", first);
			}
			
		}
		if (found_p == "false") {
			item = cookies_search.substring(first);
			if (item == id) {
				found_p = "true";
			}
		}
	}
	if (first == 0) {
		if (last == -1) {
			// only one
			//	alert("delete");
			getByID('meetings_quick_items').innerHTML = "";
			writeCookie('meetings_quick_items', "");
		} else {
			writeCookie('meetings_quick_items', cookies_search.substring(last + 2));

		}
	} else {
		if (last == -1) {
			// last one
			writeCookie('meetings_quick_items', cookies_search.substring(0, first - 2));
		} else {
			writeCookie('meetings_quick_items', cookies_search.substring(0, first - 2) + cookies_search.substring(last));
		}
	}
}


function meetings_add_quick_item(id, title, town) {
	var cookies = readCookie('meetings_quick_items');
	var temp = 0;
	var found_p = "false";
	var tempid = id.substring(id.lastIndexOf("-"));
	if (cookies != "null" && cookies) {
		var cookies_search = cookies;
		var first = 0;
		last = cookies_search.indexOf(",");
		while(last != -1 && found_p == "false" && temp++ < 50) {
			var item = cookies_search.substring(first, last);
		//	alert("---" + item + "======" + id + "----");
			if (item == id) {
				found_p = "true";
			}
			first = last + 2;
			last = cookies_search.indexOf(",", first);
		}
		if (found_p == "false") {
			item = cookies_search.substring(first);
			if(item.indexOf('event') == -1 || item.indexOf('special-packages') == -1) {
				item = item.substring(item.indexOf("-"));
			
				if (item == tempid) {
					found_p = "true";
				}
			} else {
				if (item == id) {
					found_p = "true";
				}
			}
		}
	} else {
		getByID('meetings_quick_items').innerHTML = "";
	}
	if (found_p == "false") {
		var obj = getByID('meetings_quick_items');
		if (obj) {
			var output = obj.innerHTML;
		} else {
			var output = "";
		}
		// Find out the number of entries, and increase it
		var meetings_number_of_entries = getByID('meetings_quicklist_number_of_entries').innerHTML;
		meetings_number_of_entries++;
		getByID('meetings_quicklist_number_of_entries').innerHTML = meetings_number_of_entries;

                if(meetings_number_of_entries == 1)
                  getByID('meetings_quicklist_entry_text').innerHTML = "entry";
                else
                  getByID('meetings_quicklist_entry_text').innerHTML = "entries";

	var meetings_number_of_quick = 0;
		meetings_number_of_quick++;
		output += "<div id=meetings_quickcontent_" + id + ">\n";
		output += "<span  class=meetings_quickname><strong>";
		var tempid = id.substring((id.lastIndexOf("-") + 1));

		output += "<a href='/meetings-and-events/facility-details?meeting_facility_id=" + tempid + "'>";

		output += title + "</a></strong><br>\n";
	        output += town + "</span>\n";
		var type = id.substring(0, id.lastIndexOf("-"));
		newid = id.substring((id.lastIndexOf("-") + 1));
		output += "<span class=meetings_quickdelete><a href=\"javascript:meetings_delete_quick_item('meetings_quickcontent_" + id + "', '" + type + "', " + newid + ");\"><img src='/global/images/lcva/delete.gif' alt='delete' width='19' height='13' border='0'></a></span>\n";
	
		output += "<br clear='all'></div>\n\n";
		if (obj) {
		obj.innerHTML = output;
		}
		if (cookies == "" || cookies == null) {
			writeCookie('meetings_quick_items', id)
		} else {
			writeCookie('meetings_quick_items', cookies + ", " + id)
		}	
	}
}

function meetings_clear_quick_item() {
	writeCookie('meetings_quick_items', "");
	getByID('meetings_quick_items').innerHTML = "";

}

