<!--
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_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_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 toggleDiv(tagid)
{
	$(tagid).style.display = ($(tagid).style.display == "block") ? 'none' : 'block';
}

function updateNameFromURL(ufield, tfield)
{
	var URLval = 'titlelookup.php?url=' + encodeURIComponent($(ufield).value);

	if ($(tfield).value == '')
	{
		new Ajax.Request(URLval, {
			onComplete: function(transport) {
				$(tfield).value = transport.responseText;
			}
		});
	}
}

function updateNameFromEmail(ufield, tfield, rfield, ifield)
{
	var URLval = 'namelookup.php?email=' + encodeURIComponent($(ufield).value);

	if ($(tfield).value == '')
	{
		new Ajax.Request(URLval, {
			onComplete: function(transport) {
				var fields = transport.responseText.split('|');
				$(tfield).value = fields[0];
				$(rfield).value = fields[1];
				$(ifield).value = fields[2];
			}
		});
	}
}

function selectItem(itemid)
{
	var fld = 'item_'+itemid;
	if ($(fld).hasClassName('select-off'))
	{
		$(fld).removeClassName('select-off');
		$(fld).addClassName('select-on');
	}
	else
	{
		$(fld).removeClassName('select-on');
		$(fld).addClassName('select-off');
	}
}

function postSelections()
{
	var selectlist = $$('tr.select-on');
	var item;
	var idlist = '';
	
	for (var index=0, len = selectlist.length; index < len; ++index) {
	  item = selectlist[index];
		idlist += item.name.substr(5) + '|';
	}

	var u = document.URL;
	var connector = '?';
	if (u.indexOf("?") > 0)
	{
		connector = '&';
	}
	document.location = document.URL + connector + 'selections=' + idlist;
}

function loadCompeteStats(fld, ufield, visits, visitors)
{
	var URLval = 'statslookup.php?d=' + encodeURIComponent($(ufield).value);
	
	if (fld.checked)
	{
		if (confirm('Do you want to load site statistics now?'))
		{
			new Ajax.Request(URLval, {
				onComplete: function(transport) {
					var fields = transport.responseText.split('|');
					$(visits).value = fields[0];
					$(visitors).value = fields[1];
				}
			});
		}
	}
}

function setSelectValue(fld,val)
{
	for(i=1;i<20;i++)
	{
		node = $('thumbpic'+i);
		if (node != undefined)
		{
			if (node.hasClassName('thumbselected'))
			{
				node.removeClassName('thumbselected');
				node.addClassName('thumb');
			}
		}
	}

	$(fld).value = val;
	$('thumbpic'+val).removeClassName('thumb');
	$('thumbpic'+val).addClassName('thumbselected');
	return;
}

function handleKeyPress(e)
{
	if (!e)
	{
		e = window.event;
	}
		alert(e.keyCode);
	if (e && e.keyCode == 13)
	{
		// handle Enter key
		return false; // cancel the event
	}
}

function openTagEditField(fld)
{
	toggleDiv('tagentry_'+fld);
	$('tagaddlink_'+fld).style.display = 'none';
	$('tagfield_'+fld).value = '';
	$('tagfield_'+fld).focus();
}

function removeTag(fld, tag)
{
	$('tagitem_'+tag).style.display = 'none';
	currval = $(fld).value;
	$(fld).value = currval.replace(tag, '');
}

function addTag(fld)
{
	tag = $('tagfield_'+fld).value;
	toggleDiv('tagentry_'+fld);
	$('tagaddlink_'+fld).style.display = 'block';
	$(fld).value = $(fld).value + ', ' + tag;
	$('taglist_'+fld).innerHTML = $('taglist_'+fld).innerHTML + ' <span id="tagitem_'+tag+'"><nobr>'+tag+'&nbsp;<a href="javascript:removeTag(\''+fld+'\',\''+tag+'\');"><img src="/imgs/btn-x.png" width="12" height="12" border="0" alt="Delete tag"></a></nobr></span>';
}

function addFolder(parentid)
{
	toggleDiv('folder_'+parentid);
	$('foldername_'+parentid).value = '';
	$('foldername_'+parentid).focus();
}

function deleteFolder(fid)
{
	if (confirm('Do you really want to delete this folder and move all of its contents up one folder level?'))
	{
		document.location = 'folder.php?mode=delete&folderid=' + fid + '&ref=' + escape(document.URL);
		return true;
	}
}

function loadEmailFolderList(fidfield, eidfield)
{
	var currHTML = $('selectcontainer_'+eidfield).innerHTML;
	var re = new RegExp("<SELECT(.*?)>");
	var m = re.exec(currHTML);
	
	var URLval = 'emailoptions.php?f=' + encodeURIComponent($(fidfield).value)
	new Ajax.Request(URLval, {
				onComplete: function(transport) {
					$('selectcontainer_'+eidfield).update(m[0] + transport.responseText + '</select>');
				}
			});
				
	//new Ajax.Updater(eidfield, '/admin/emailoptions.php', {parameters : {f: $(fidfield).value} });
}

function loadNeighborhoods(cidfield, nidfield)
{
	var currHTML = $('selectcontainer_'+cidfield).innerHTML;
	var re = new RegExp("<SELECT(.*?)>");
	var m = re.exec(currHTML);
	
	var URLval = 'neighborhoodoptions.php?c=' + encodeURIComponent($(cidfield).value)
	new Ajax.Request(URLval, {
				onComplete: function(transport) {
					$('selectcontainer_'+nidfield).update(m[0] + transport.responseText + '</select>');
				}
			});
				
	//new Ajax.Updater(eidfield, '/admin/emailoptions.php', {parameters : {f: $(fidfield).value} });
}

function previewEmail(eid, qid, rid)
{
	var emailid = eid;
	var queueid = qid;
	var resourceid = rid;
	
	if (eid == 0 && $('emailid') != undefined)
	{
		emailid = $('emailid').value;
	}
	if (rid == 0 && $('resourceid') != undefined)
	{
		resourceid = $('resourceid').value;
	}
	if (qid == 0 && $('queueid') != undefined)
	{
		queueid = $('queueid').value;
	}
	
	pop = window.open("/admin/previewemail.php?eid=" + emailid + "&qid=" + queueid + "&rid=" + resourceid + "", "preview", "status=0,toolbar=0,location=0,menubar=0,resizable=1,width=630,height=800");
}

function showChangelog(rec, id)
{
	pop = window.open("/admin/changelog.php?rec=" + rec + "&id=" + id + "", "changelog", "status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=yes,width=902,height=600");
}

function getElementPosition(obj)
{
	var topValue= 0,leftValue= 0;
	while(obj){
		leftValue+= obj.offsetLeft;
		topValue+= obj.offsetTop;
		obj = obj.offsetParent;
	}
	if ($('dbx'))
	{
		$('dbx').innerHTML = 'Mouse position is: X='+topValue+' Y='+leftValue;
	}
	return {top:topValue,left:leftValue};
}

function getMousePosition(e)
{
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }
	$('dbx').innerHTML = 'Mouse position is: X='+posx+' Y='+posy;

	return {left:posx,top:posy};
	
//	Document.getElementById('pos').style.left = posx;
//	document.getElementById('pos').style.top = posy;
}

function hideToolTip(){
	$("tooltipper").style.left = 0
	$("tooltipper").style.top = 0
	$("tooltipper").style.width = 1;
	$("tooltipper").style.height = 1;
	$("tooltipper").innerHTML = "" ;
	$("tooltipper").style.visibility = "hidden";
}
function showToolTip(fld){
	//alert($(fld).clientX);
	pos = getElementPosition($(fld));
	//alert(pos.top);
	$("tooltipper").style.left = pos.left
	$("tooltipper").style.top = pos.top+24
	$("tooltipper").style.width = 250;
	$("tooltipper").style.height = 150;
	$("tooltipper").innerHTML = $(fld).innerHTML;
	$("tooltipper").style.visibility = "visible";
}
function showTaskTip(fld){
	//alert($(fld).clientX);
//	$('taskdetail').innerHTML = $(fld).innerHTML;
}

function openEdit(scr, key, id)
{
	document.location = scr + "?mode=edit&" + key + "=" + $(id).value;
}

function loadColumns(e)
{
	new Ajax.Request(
									 'columnlookup.php?t=' + $('actiontable').value
									,{
											 method: 'get'
											,evalJS: true
											,onSuccess: function(transport) {
																		flds = transport.responseText.split("|");
																		for (i=$('actioncolumn').options.length-1; i >= 0; i--)
																		{
																			$('actioncolumn').remove(i);
																		}
																		$('actioncolumn').options[$('actioncolumn').options.length] = new Option('None', '');
																		for (i=1; i < flds.length; i++)
																		{
																			$('actioncolumn').options[$('actioncolumn').options.length] = new Option(flds[i].capitalize(), flds[i]);
																		}
																	}
									 }
	);
}

function saveAndAdd(tourl,fldname)
{
	$('save_tourl').value = tourl;
	$('save_fldname').value = fldname;
	saveFormSession('editform');
	$('saveform').submit();
	
	return true;
}

function saveFormSession(sourceid)
{
	var formsrc = $(sourceid).elements;
	var fldname;
	var val;
	var newfield;
	
//	alert(sourceid);
	for (var i=0; i<formsrc.length; i++)
	{
		if (formsrc[i].name != '')
		{
			newfield = document.createElement("INPUT");
	
			newfield.setAttribute("type", "hidden");
			newfield.setAttribute("name", formsrc[i].name);
			newfield.setAttribute("value", formsrc[i].value);
		
//			alert('adding ' + formsrc[i].type + ' field ' + formsrc[i].name + ' = ' + formsrc[i].value);
			$('saveform').appendChild(newfield);
		}
	}

/*
	for (var i=0; i<$('saveform').length; i++)
	{
		alert($('saveform').name + ' = ' + $('saveform').value);
	}
*/
	
	return true;
}

function updateField(fld,val)
{
	if ($(fld) != undefined)
	{
/*
		if ($(fld).type == 'select-one')
		{
			for (var index = 0; index < $(fld).length; index++)
			{
				if ($(fld)[index].value == val)
				{
					$(fld).selectedIndex = index;
				}
			}
		}
		else
		{
*/
			$(fld).value = val;
/*
		}
*/
	}
}

function copyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		
		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		
		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');
		
		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();
		
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		
		var copytext=s;
		
		str.data=copytext;
		
		trans.setTransferData("text/unicode",str,copytext.length*2);
		
		var clipid=Components.interfaces.nsIClipboard;
		
		if (!clip) return false;
		
		clip.setData(trans,null,clipid.kGlobalClipboard);
		
		alert('\"' + s + '\" copied to clipboard');
	}
}

function setDateRange()
{
	var opt = $('daterange').value;
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var fromdate = $('fromdate').value;
	var todate = $('todate').value;
	var fromTime = new Date();
	var toTime = new Date();

	if (opt != 'specify')
	{
		$('fromdate').disabled = true;
		$('todate').disabled = true;
	}
		
	switch(opt)
	{
		case 'all':
			fromdate = '';
			todate = '';
			break;
		case 'current':
			fromTime.setDate(currentTime.getDate());
			toTime.setDate(currentTime.getDate());
			fromdate = (fromTime.getMonth() + 1) + '/' + fromTime.getDate() + '/' + fromTime.getFullYear();
			todate = (toTime.getMonth() + 1) + '/' + toTime.getDate() + '/' + toTime.getFullYear();
			break;
		case 'month':
			fromdate = month + '/' + 1 + '/' + year;
			todate = month + '/' + 30 + '/' + year;
			break;
		case 'year':
			fromdate = '01/01/' + year;
			todate = '12/31/' + year;
			break;
		case 'specify':
			$('fromdate').disabled = false;
			$('todate').disabled = false;
			break;
	}
	
	if (fromdate.substr(1, 1) == '/')
	{
		fromdate = '0' + fromdate;
	}
	if (todate.substr(1, 1) == '/')
	{
		todate = '0' + todate;
	}
	
	$('fromdate').value = fromdate;
	$('todate').value = todate;
}

function modIDs(node, oldPattern, newPattern)
{
	var child, nodes = node.childNodes;

	for (var i=0, len=nodes.length; i<len; i++)
	{
		child = nodes[i];
		if ('string' == typeof child.id)
		{
			child.id = child.id.replace(oldPattern, newPattern);
		}
		if (child.childNodes && child.childNodes.length)
		{
			modIDs(child, oldPattern, newPattern);
		}
	}
	
	//alert(node.innerHTML);
}

function cloneElement(oldID, newID, oldNum, newNum)
{
	var el = $(oldID);
	var newEl = el.cloneNode(true);
	var oldPattern = '_' + oldNum;
	var newPattern = '_' + newNum;

	newEl.id = newID;

	modIDs(newEl, oldPattern, newPattern);

	el.parentNode.insertBefore(newEl, el.nextSibling);
}

function addDrink()
{
	var drinkCount = 0;
	var newHTML;
	var divID;
	var foundDrink = true;
	var oldFld, newFld;

	do
	{
		drinkCount++;
		divID = 'editrow_cost_' + drinkCount;
		
		if ($(divID) == undefined)
		{
			foundDrink = false
		}
	} while(foundDrink);
	
	lastDrink = drinkCount - 1;

	cloneElement('editrow_cost_' + lastDrink, 'editrow_cost_' + drinkCount, lastDrink, drinkCount);
	
	$('cost_' + drinkCount).name = 'cost_' + drinkCount;
	$('cost_' + drinkCount).value = '';
	$('drinktypeid_' + drinkCount).name = 'drinktypeid_' + drinkCount;

}

function resizeImage(imgid)
{
	var window_height = document.body.clientHeight;
	var window_width  = document.body.clientWidth;
	var image_width   = 800;
	var image_height  = 600;
	var height_ratio  = image_height / window_height;
	var width_ratio   = image_width / window_width;
	if (height_ratio < width_ratio)
	{
		$(imgid).style.width  = "auto";
		$(imgid).style.height = "100%";
	}
	else
	{
		$(imgid).style.width  = "100%";
		$(imgid).style.height = "auto";
	}
}

function changeLinkType()
{
	var linktype = $('linktype').value;
	
	$('editrow_link_url').style.display = 'none';
	$('editrow_link_article').style.display = 'none';
	$('editrow_link_javascript').style.display = 'none';
	$('editrow_link_email').style.display = 'none';
	
	switch(linktype)
	{
		case '0':	// LINKTYPE_URL
			$('editrow_link_url').style.display = 'block';
			break;
		case '1':	// LINKTYPE_ARTICLE
			$('editrow_link_article').style.display = 'block';
			break;
		case '3':	// LINKTYPE_JAVACRIPT
			$('editrow_link_javascript').style.display = 'block';
			break;
		case '4':	// LINKTYPE_MAILTO
			$('editrow_link_email').style.display = 'block';
			break;
	}
}

//-->link
