// Panel Functions
YAHOO.namespace("infoPanelNS");
	function init(phead,pbody,pfoot,pwidth) {
		YAHOO.infoPanelNS.infoPanel = new YAHOO.widget.Panel("infoPanel", { 
			width:pwidth, 
			visible:false, 
			constraintoviewport:true,
			underlay:"shadow", 
			draggable:false 
		});
			YAHOO.infoPanelNS.infoPanel.render();
	}
	function showInformationPanel(phead,pbody,pfoot,pwidth,elementID,draggable)  {
		var width = pwidth;
		var el = YAHOO.infoPanelNS.infoPanel.innerElement;
		YAHOO.util.Dom.setStyle(el, "width", width); // reset Width'
		YAHOO.infoPanelNS.infoPanel.cfg.setProperty("context", [document.getElementById(elementID),"tl","bl", ["beforeShow", "windowResize"]], true);
		YAHOO.infoPanelNS.infoPanel.cfg.setProperty("draggable", draggable);
		YAHOO.infoPanelNS.infoPanel.align("tl", "bl"); // reset Location align - Move to Under the Link
		YAHOO.infoPanelNS.infoPanel.setHeader(phead);
		YAHOO.infoPanelNS.infoPanel.setBody(pbody);
		YAHOO.infoPanelNS.infoPanel.setFooter(pfoot);
		YAHOO.infoPanelNS.infoPanel.show();
		
	}
	
	var entities=[['&amp;','&'],['&nbsp;',' '],['&lt;','<'],['&gt;','>'],['&quot;&','\'']];
	function decodeHTML(e){
			var clean = e.toString()
			for( var i=0, limit=entities.length; i < limit; ++i) {
				clean = clean.replace( new RegExp(entities[i][0],"ig"), entities[i][1]);
			}
			return clean;
		}

	
	function showInformationPanelArray(phead,ArrayID,pfoot,pwidth,elementID)  {
		if (lrip.tagAsins["AllInfoPanels"]) {
          
		var width = pwidth;
		var pbody = '';
		lrip.asins = Array();
        lrip.asins = lrip.tagAsins["AllInfoPanels"];
		
		for (i = 0; i < lrip.asins.length; i++) {
            var level = lrip.asins[i].split("{}");
            if (level) {
                if (ArrayID == parseInt(level[0])) {
                	pbody = decodeHTML(level[1]);
                }
            }
        }
		
		var el = YAHOO.infoPanelNS.infoPanel.innerElement;
		YAHOO.util.Dom.setStyle(el, "width", width); // reset Width'
		YAHOO.infoPanelNS.infoPanel.cfg.setProperty("context", [document.getElementById(elementID),"tl","bl", ["beforeShow", "windowResize"]], true);
		YAHOO.infoPanelNS.infoPanel.align("tl", "bl"); // reset Location align - Move to Under the Link
		YAHOO.infoPanelNS.infoPanel.setHeader(phead);
		YAHOO.infoPanelNS.infoPanel.setBody(pbody);
		YAHOO.infoPanelNS.infoPanel.setFooter(pfoot);
		YAHOO.infoPanelNS.infoPanel.show();
		 } 
	}
	function hideInformationPanel() {
		YAHOO.infoPanelNS.infoPanel.hide();
	}
YAHOO.util.Event.onDOMReady(init);


// ---------------------------------------------------------------
// YAHOO agent autocomplete 
// ---------------------------------------------------------------
function ResAgentAutoComplete(formID,formContainer) {
    var oDS = new YAHOO.util.XHRDataSource("/services/yahoo/autocomplete_resagents.aspx");
    oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
    oDS.responseSchema = {recordDelim: "|",fieldDelim: ","};
    oDS.maxCacheEntries = 15;
    var oAC = new YAHOO.widget.AutoComplete(formID, formContainer, oDS);
	oAC.animVert = false; 
	oAC.useShadow = true; 
	oAC.autoHighlight = false;
	oAC.forceSelection = false; 
    oAC.minQueryLength = 0;
	oAC.useIFrame = true; 
	oAC.highlightClassName = "AgentReserveHighlightClass"; 
    oAC.prehighlightClassName = "AgentReservepreHighlightClass"; 
    var textboxFocusHandler = function() {

        setTimeout(function() {oAC.sendQuery("");
		
		// get selected list item and highlight it
		oAC.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults) { 
		var items = oAC.getListItems(), item, itemData;
			for (var i = 0; i < items.length; i++) {
				item = items[i];
				//itemData = oAC.getListItemData(item);  gets both data items
				itemData = oAC.getListItemMatch(item);
				 if (itemData == oAC._elTextbox.value) {
					oAC._toggleHighlight(item, "to");
					oAC.itemArrowToEvent.fire(oAC, item);
					oAC._typeAhead(item,sQuery);
					break;
				}
			}	
		
			return true;
		}
			
		}, 0);
    };
	
	oAC.textboxFocusEvent.subscribe(textboxFocusHandler); // on Focus - mouse clicks inside text area // On Blur - typeing change
	
    return {oDS: oDS, oAC: oAC};
		
}
