
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - cameFromCookie.js - */
// http://www.dwi.com/portal_javascripts/cameFromCookie.js?original=1
function setCFCookie(){var own_domain="dwi.com";var cookie_name="cmfrm";var currRef=document.referrer;var domain=currRef.match(/:\/\/(www\.)?([^\/:]+)/);domain=(domain!=null&&domain[2])?domain[2]:'';if((domain.toLowerCase()!=own_domain)||(domain=='')){createCookie(cookie_name,currRef)}};registerPloneFunction(setCFCookie);

/* - fckeditor.js - */
// http://www.dwi.com/portal_javascripts/fckeditor.js?original=1
var FCKeditor=function(instanceName,width,height,toolbarSet,value){this.InstanceName=instanceName ;this.Width=width||'100%' ;this.Height=height||'200' ;this.ToolbarSet=toolbarSet||'Default' ;this.Value=value||'' ;this.BasePath='/fckeditor/' ;this.CheckBrowser=true ;this.DisplayErrors=true ;this.EnableSafari=false ;this.EnableOpera=false ;this.Config=new Object() ;this.OnError=null }
FCKeditor.prototype.Version='2.4.3' ;FCKeditor.prototype.VersionBuild='15657' ;FCKeditor.prototype.Create=function(){document.write(this.CreateHtml()) }
FCKeditor.prototype.CreateHtml=function(){if(!this.InstanceName||this.InstanceName.length==0){this._ThrowError(701,'You must specify an instance name.') ;return '' }
var sHtml='<div>' ;if(!this.CheckBrowser||this._IsCompatibleBrowser()){sHtml+='<input type="hidden" id="'+this.InstanceName+'" name="'+this.InstanceName+'" value="'+this._HTMLEncode(this.Value)+'" style="display:none" />' ;sHtml+=this._GetConfigHtml() ;sHtml+=this._GetIFrameHtml() }
else{var sWidth=this.Width.toString().indexOf('%')>0?this.Width:this.Width+'px' ;var sHeight=this.Height.toString().indexOf('%')>0?this.Height:this.Height+'px' ;sHtml+='<textarea name="'+this.InstanceName+'" rows="4" cols="40" style="width:'+sWidth+';height:'+sHeight+'">'+this._HTMLEncode(this.Value)+'<\/textarea>' }
sHtml+='</div>' ;return sHtml }
FCKeditor.prototype.ReplaceTextarea=function(){if(!this.CheckBrowser||this._IsCompatibleBrowser()){var oTextarea=document.getElementById(this.InstanceName) ;var colElementsByName=document.getElementsByName(this.InstanceName) ;var i=0;while(oTextarea||i==0){if(oTextarea&&oTextarea.tagName.toLowerCase()=='textarea')
break ;oTextarea=colElementsByName[i++] }
if(!oTextarea){alert('Error: The TEXTAREA with id or name set to "'+this.InstanceName+'" was not found') ;return }
oTextarea.style.display='none' ;this._InsertHtmlBefore(this._GetConfigHtml(),oTextarea) ;this._InsertHtmlBefore(this._GetIFrameHtml(),oTextarea) }}
FCKeditor.prototype._InsertHtmlBefore=function(html,element){if(element.insertAdjacentHTML)
element.insertAdjacentHTML('beforeBegin',html) ;else{var oRange=document.createRange() ;oRange.setStartBefore(element) ;var oFragment=oRange.createContextualFragment(html);element.parentNode.insertBefore(oFragment,element) }}
FCKeditor.prototype._GetConfigHtml=function(){var sConfig='' ;for(var o in this.Config){if(sConfig.length>0) sConfig+='&amp;' ;sConfig+=encodeURIComponent(o)+'='+encodeURIComponent(this.Config[o]) }
return '<input type="hidden" id="'+this.InstanceName+'___Config" value="'+sConfig+'" style="display:none" />' }
FCKeditor.prototype._GetIFrameHtml=function(){var sFile='fckeditor.html' ;try{if((/fcksource=true/i).test(window.top.location.search))
sFile='fckeditor.original.html' }
catch(e){}
var sLink=this.BasePath+'editor/'+sFile+'?InstanceName='+encodeURIComponent(this.InstanceName) ;if(this.ToolbarSet) sLink+='&amp;Toolbar='+this.ToolbarSet ;return '<iframe id="'+this.InstanceName+'___Frame" src="'+sLink+'" width="'+this.Width+'" height="'+this.Height+'" frameborder="0" scrolling="no"></iframe>' }
FCKeditor.prototype._IsCompatibleBrowser=function(){return FCKeditor_IsCompatibleBrowser(this.EnableSafari,this.EnableOpera) }
FCKeditor.prototype._ThrowError=function(errorNumber,errorDescription){this.ErrorNumber=errorNumber ;this.ErrorDescription=errorDescription ;if(this.DisplayErrors){document.write('<div style="COLOR: #ff0000">') ;document.write('[ FCKeditor Error '+this.ErrorNumber+': '+this.ErrorDescription+' ]') ;document.write('</div>') }
if(typeof(this.OnError)=='function')
this.OnError(this,errorNumber,errorDescription) }
FCKeditor.prototype._HTMLEncode=function(text){if(typeof(text)!="string")
text=text.toString() ;text=text.replace(/&/g,"&amp;").replace(/"/g, "&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;") ;return text }
function FCKeditor_IsCompatibleBrowser(enableSafari,enableOpera){var sAgent=navigator.userAgent.toLowerCase() ;if(sAgent.indexOf("msie")!=-1&&sAgent.indexOf("mac")==-1&&sAgent.indexOf("opera")==-1){var sBrowserVersion=navigator.appVersion.match(/MSIE (.\..)/)[1] ;return(sBrowserVersion>=5.5) }
if(navigator.product=="Gecko"&&navigator.productSub>=20030210&&!(typeof(opera)=='object'&&opera.postError))
return true ;if(enableOpera&&sAgent.indexOf('opera')==0&&parseInt(navigator.appVersion,10)>=9)
return true ;if(enableSafari&&sAgent.indexOf('safari')!=-1)
return(sAgent.match(/safari\/(\d+)/ )[1] >= 312 ) ;	// Build must be at least 312(1.3)
return false }

/* - fck_plone.js - */
// http://www.dwi.com/portal_javascripts/fck_plone.js?original=1
var FCKBaseHref={};makeLinksRelative=function(basehref,contents){var base=basehref.replace('http://www.dwi.com','');var href=base.replace(/\/[^\/]*$/,'/');var hrefparts=href.split('/');return contents.replace(/(<[^>]* (?:src|href)=")([^"]*)"/g,
function(str,tag,url,offset,contents){url=url.replace('http://www.dwi.com','');if(url.substring(0,1)=='#'){str=tag+url+'"';alert(str)}
else{var urlparts=url.split('#');var anchor=urlparts[1]||'';url=urlparts[0];var urlparts=url.split('/');var common=0;while(common<urlparts.length&&common<hrefparts.length&&urlparts[common]==hrefparts[common])
common++;var last=urlparts[common];if(common+1==urlparts.length&&last=='emptypage'){urlparts[common]=''}
if(common>0){var path=new Array();var i=0;for(;i+common<hrefparts.length-1;i++){path[i]='..'};while(common<urlparts.length){path[i++]=urlparts[common++]};if(i==0){path[i++]='.'}
str=path.join('/');if(anchor){str=[str,anchor].join('#')}
str=tag+str+'"'}}
return str})};finalizePublication=function(editorInstance){var oField=editorInstance.LinkedField;var fieldName=oField.name;var baseHref=FCKBaseHref[fieldName];if(baseHref){relativeLinksHtml=makeLinksRelative(FCKBaseHref[fieldName],editorInstance.GetXHTML());oField.value=relativeLinksHtml}}
getParamValue=function(id){value=document.getElementById(id).value;if(value=='true') return true;if(value=='false') return false;return value}
FCKeditor_Plone_start_instance=function(fckContainer,inputname){var inputContainer=document.getElementById(inputname+'_'+'cleaninput');if(inputContainer){var fckParams=['path_user','base_path','fck_basehref','links_basehref','input_url','allow_server_browsing','browser_root','allow_file_upload','allow_image_upload','allow_flash_upload','fck_skin_path','lang','fck_default_r2l','force_paste_as_text','allow_latin_entities','spellchecker','keyboard_entermode','keyboard_shiftentermode','fck_toolbar','editor_width','editor_height'];var fckValues={};for(var i=0;i<fckParams.length;i++){var id=inputname+'_'+fckParams [i];fckValues [fckParams [i]]=getParamValue(id)}
var oFck=new FCKeditor(inputname);var pathUser=fckValues ['path_user']+'/';oFck.BasePath=fckValues ['base_path']+'/';oFck.Config['CustomConfigurationsPath']=fckValues ['input_url']+'/fckconfigPlone.js?field_name='+inputname;oFck.BaseHref=fckValues ['fck_basehref'];FCKBaseHref[inputname]=fckValues ['links_basehref'];oFck.Value=inputContainer.innerHTML;oFck.Config['LinkBrowser']=fckValues ['allow_server_browsing'];oFck.Config['LinkBrowserURL']=fckValues ['base_path']+'/fckbrowser/browser.html?field_name='+inputname+'&Connector='+fckValues ['input_url']+'/connectorPlone&ServerPath='+fckValues ['browser_root']+'&CurrentPath='+pathUser ;oFck.Config['LinkUpload']=fckValues ['allow_file_upload'] ;oFck.Config['LinkUploadURL']=fckValues ['input_url']+'/uploadPlone?field_name='+inputname+'&CurrentPath='+pathUser;oFck.Config['ImageBrowser']=fckValues ['allow_server_browsing'];oFck.Config['ImageBrowserURL']=fckValues ['base_path']+'/fckbrowser/browser.html?field_name='+inputname+'&Type=Image&Connector='+fckValues ['input_url']+'/connectorPlone&ServerPath='+fckValues ['browser_root']+'&CurrentPath='+pathUser ;oFck.Config['ImageUpload']=fckValues ['allow_image_upload'] ;oFck.Config['ImageUploadURL']=fckValues ['input_url']+'/uploadPlone?field_name='+inputname+'&CurrentPath='+pathUser;oFck.Config['FlashBrowser']=fckValues ['allow_server_browsing'];oFck.Config['FlashBrowserURL']=fckValues ['base_path']+'/fckbrowser/browser.html?field_name='+inputname+'&Type=Flash&Connector='+fckValues ['input_url']+'/connectorPlone&ServerPath='+fckValues ['browser_root']+'&CurrentPath='+pathUser ;oFck.Config['FlashUpload']=fckValues ['allow_flash_upload'] ;oFck.Config['FlashUploadURL']=fckValues ['input_url']+'/uploadPlone?field_name='+inputname+'&CurrentPath='+pathUser;oFck.Config['SkinPath']=fckValues ['base_path']+'/editor/'+fckValues ['fck_skin_path'];oFck.Config['AutoDetectLanguage']=false;oFck.Config['DefaultLanguage']=fckValues ['lang'];oFck.Config['ForcePasteAsPlainText']=fckValues ['force_paste_as_text'];oFck.Config['IncludeLatinEntities']=fckValues ['allow_latin_entities'];oFck.Config['SpellChecker']=fckValues ['spellchecker'];oFck.Config['EnterMode']=fckValues ['keyboard_entermode'];oFck.Config['ShiftEnterMode']=fckValues ['keyboard_shiftentermode'];oFck.ToolbarSet=fckValues ['fck_toolbar'];oFck.Width=fckValues ['editor_width'];oFck.Height=fckValues ['editor_height'];try{fckContainer.innerHTML=oFck.CreateHtml();document.getElementById(inputname+'_fckLoading').style.display='none'}
catch(e){document.getElementById(inputname+'_fckLoading').style.display='none';document.getElementById(inputname+'_fckError').style.display='block'}}}
Save_inline=function(fieldname,form,editorInstance){if(editorInstance.Commands.GetCommand('FitWindow').GetState()){kukit.log('Full screen mode must be disabled before saving inline');editorInstance.Commands.GetCommand('FitWindow').Execute()} ;saveField=document.getElementById(fieldname+'_fckSaveField');if(saveField){kukit.log('Fire the savekupu server event = save inline without submitting');saveField.value='Document saved !!';if(saveField.fireEvent){saveField.fireEvent('onChange')}
else{var evt=document.createEvent("HTMLEvents");evt.initEvent("change",true,true);saveField.dispatchEvent(evt)}
comp=(setTimeout("saveField.value=''",2000));return false}
else{kukit.log('Try to submit the form in portal_factory');form.submit()}}


/* - fck_ploneInit.js - */
// http://www.dwi.com/portal_javascripts/fck_ploneInit.js?original=1
function getElementsByClassName(oElm,strTagName,strClassName){var arrElements=(strTagName=="*"&&oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);var arrReturnElements=new Array();strClassName=strClassName.replace(/\-/g,"\\-");var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");var oElement;for(var i=0;i<arrElements.length;i++){oElement=arrElements[i];if(oRegExp.test(oElement.className)){arrReturnElements.push(oElement)}}
return(arrReturnElements)}
function FCKeditor_OnComplete(editorInstance){editorInstance.Events.AttachEvent('OnAfterLinkedFieldUpdate',finalizePublication) }
FCKeditor_Plone_Init=function(){var fckContainers=getElementsByClassName(document,'div','fckContainer');for(var i=0;i<fckContainers.length;i++){var fckContainer=fckContainers [i];var fckContainerId=fckContainer.getAttribute('id');var inputname=fckContainerId.replace("_fckContainer","");FCKeditor_Plone_start_instance(fckContainer,inputname)}}
registerPloneFunction(FCKeditor_Plone_Init);

/* - mark_special_links.js - */
// http://www.dwi.com/portal_javascripts/mark_special_links.js?original=1
function scanforlinks(){if(!W3CDOM){return false}
if((typeof external_links_in_content_only!='undefined')&&(external_links_in_content_only==false)){links=document.getElementsByTagName('a');for(i=0;i<links.length;i++){if((links[i].getAttribute('href'))&&(links[i].className.indexOf('link-plain')==-1)){var linkval=links[i].getAttribute('href');if(linkval.toLowerCase().indexOf(window.location.protocol+'//'+window.location.host)==0){} else if(linkval.indexOf('http:')!=0){} else{links[i].setAttribute('target','_blank')}}}}
contentarea=getContentArea();if(!contentarea)
return false;links=contentarea.getElementsByTagName('a');for(i=0;i<links.length;i++){if((links[i].getAttribute('href'))&&(links[i].className.indexOf('link-plain')==-1)){var linkval=links[i].getAttribute('href');if(linkval.toLowerCase().indexOf(window.location.protocol+'//'+window.location.host)==0){} else if(linkval.indexOf('http:')!=0){protocols=['mailto','ftp','news','irc','h323','sip','callto','https','feed','webcal'];for(p=0;p<protocols.length;p++){if(linkval.indexOf(protocols[p]+':')==0){wrapNode(links[i],'span','link-'+protocols[p]);break}}} else{if(links[i].getElementsByTagName('img').length==0){wrapNode(links[i],'span','link-external')}
if((typeof external_links_open_new_window!='undefined')&&(external_links_open_new_window==true)){links[i].setAttribute('target','_blank')}}}}};registerPloneFunction(scanforlinks);

/* - ++resource++suggest_widget.js - */
// Suggestion Widget

function SuggestionWidget(suggest_field_id, suggestQueryTarget) {
    this.suggestReq = false;
    this.suggestTimout = null;
    this.suggestLast = "";

    this.suggestInput = null;
    this.isIE = false;
    this._suggest_cache = new Object();
    this.widthOffset = 1;

    this.suggest_field_id = suggest_field_id;
    this.suggestQueryTarget = suggestQueryTarget;


    // html class names and ids for easier customization are collected here
    this.htmlnames = {'highlight': 'suggest-highlight',
                      'table': 'suggestTable',
                      'row': 'suggestRow',
                      'result': 'suggestResult',
                      'shadow': 'suggestShadow',
                      'container': 'suggestContainer',
                      'iefix': 'suggestIEFix'};

    // private methods goes here
    this.init = function() {
        suggestInput = document.getElementById(this.suggest_field_id);
        if (suggestInput == null || suggestInput == undefined) {
            suggestInput = this.getElementByName(suggest_field_id);
            if (suggestInput == null || suggestInput == undefined) {
                return
            }
        }
        this.suggestInput = suggestInput;

        var eventBinder = function(func, object) {
            return function(event) {
                func.apply(object, [event]);
            }
        }

        // Only keypress catches repeats in moz/FF but keydown is needed for
        // khtml based browsers.
        if (navigator.userAgent.indexOf("KHTML") > 0) {
            suggestInput.addEventListener("keydown", eventBinder(this.suggestKeyPress, this), false);
            suggestInput.addEventListener("focus", eventBinder(this.suggestDoSearch, this), false);
            suggestInput.addEventListener("keydown", eventBinder(this.suggestStart, this), false);
            suggestInput.addEventListener("blur", eventBinder(this.suggestHideDelayed, this), false);
        } else if (suggestInput.addEventListener) {
            suggestInput.addEventListener("keypress", eventBinder(this.suggestKeyPress, this), false);
            suggestInput.addEventListener("blur", eventBinder(this.suggestHideDelayed, this), false);
            suggestInput.addEventListener("keypress", eventBinder(this.suggestStart, this), false);
        } else {
            suggestInput.attachEvent("onkeydown", eventBinder(this.suggestKeyPress, this));
            suggestInput.attachEvent("onkeydown", eventBinder(this.suggestStart, this));
            suggestInput.attachEvent("onblur", eventBinder(this.suggestHideDelayed, this));
            this.isIE = true;
        }

        // Why doesn't this work in konq, setting it inline does.
        suggestInput.setAttribute("autocomplete", "off");
        var pos = this.getElementDimensions(suggestInput);

        result = this.createResultContainer(suggestInput);

        if ((typeof result.offsetParent != 'undefined') && (result.offsetParent != null)) {
            pos.left = pos.left - result.offsetParent.offsetLeft + pos.width;
    //         result.style.left = pos.left - result.offsetParent.offsetLeft + pos.width;
        } else {
            pos.left = pos.left + pos.width;
    //         result.style.left = pos.left + pos.width;
        }
        result.style.display = 'none';
    }

    this.createResultContainer = function(field) {
        var container = document.createElement("DIV");
        container.className = this.htmlnames['result'];
        container.id = this.suggest_field_id + "-result";
        var shadow = document.createElement("DIV");
        shadow = document.createElement("DIV");
        shadow.className = this.htmlnames['shadow'];
        shadow.id = this.suggest_field_id + "-shadow";
        container.appendChild(shadow);
        field.parentNode.appendChild(container);
        return container;
    }

    this.getElementDimensions = function(base) {
        var offsetTrail = base;
        var offsetLeft = 0;
        var offsetTop = 0;
        var width = 0;

        while (offsetTrail) {
            offsetLeft += offsetTrail.offsetLeft;
            offsetTop += offsetTrail.offsetTop;
            offsetTrail = offsetTrail.offsetParent;
        }
        if (navigator.userAgent.indexOf("Mac") != -1 &&
            typeof document.body.leftMargin != "undefined") {
            offsetLeft += document.body.leftMargin;
            offsetTop += document.body.topMargin;
        }
        if (!this.isIE)
            width = this.suggestInput.offsetWidth - this.widthOffset*2;
        else
            width = this.suggestInput.offsetWidth;
        return {left: offsetLeft,
                top: offsetTop,
                width: width,
                height: base.offsetHeight,
                bottom: offsetTop + base.offsetHeight,
                right: offsetLeft + width};
    }

    this.getElementByName = function(elemName) {
        var elms = document.getElementsByName(elemName);
        if (elms.length > 0) {
            return elms[0];
        } else {
            return null;
        }
    }

    this.suggestHideDelayed = function() {
        var self = this;
        function hide() {
            self.suggestHide.apply(self);
        }
        window.setTimeout(hide, 400);
    }

    this.suggestHide = function() {
        document.getElementById(this.suggest_field_id + "-result").style.display = "none";
        var highlight = document.getElementById(this.htmlnames['highlight']);
        if (highlight)
            highlight.removeAttribute("id");
    }

    this.suggestStart = function(event) {
        if (this.suggestTimout) {
            window.clearTimeout(this.suggestTimout);
        }
        var code = event.keyCode;
        if (code != 40 && code != 38 && code != 27 && code != 37 && code != 39 &&
            !(code == 13 && document.getElementById(this.htmlnames['highlight']))) {
            var self = this;
            function doSearch() {
                self.suggestDoSearch.apply(self);
            }
            this.suggestTimeout = window.setTimeout(doSearch, 200);
        }
    }

    this.suggestKeyPress = function suggestKeyPress(event) {
        var highlight = document.getElementById(this.htmlnames['highlight']);
        var self = this;
        if (event.keyCode == 40 )
        //KEY DOWN
        {
            if (!highlight) {
                highlight = this.suggestGetFirstHighlight();
            } else {
                highlight.removeAttribute("id");
                highlight = this.suggestFindNext(highlight, function (o) {return o.className == self.htmlnames['row'];});
            }
            if (highlight)
                highlight.setAttribute("id", this.htmlnames['highlight']);
            if (this.isIE)
                window.event.returnValue = false;
            else {
                event.preventDefault();
            }
        }
        //KEY UP
        else if (event.keyCode == 38 ) {
            if (!highlight) {
                highlight = this.suggestGetLastHighlight();
            }
            else {
                highlight.removeAttribute("id");
                highlight = this.suggestFindPrev(highlight, function (o) {return o.className == self.htmlnames['row'];});
            }
            if (highlight)
                highlight.setAttribute("id", this.htmlnames['highlight']);
            if (this.isIE)
                window.event.returnValue = false;
            else {
                event.preventDefault();
            }
        }
        //ESC
        else if (event.keyCode == 27) {
            if (highlight)
                highlight.removeAttribute("id");
            document.getElementById(this.suggest_field_id + "-result").style.display = "none";
        // ENTER
        } else if (event.keyCode == 13 && highlight) {
            this.suggestInput.value = highlight.innerHTML;
            highlight.removeAttribute("id");
            document.getElementById(this.suggest_field_id + "-result").style.display = "none";
            if (this.isIE)
                window.event.returnValue = false;
            else {
                event.preventDefault();
            }
        }
    }

    this.suggestGetFirstHighlight = function() {
        var set = this.suggestGetHits();
        return set[0];
    }

    this.suggestGetLastHighlight = function() {
        var set = this.suggestGetHits();
        return set[set.length-1];
    }

    this.suggestGetHits = function() {
        var res = document.getElementById(this.suggest_field_id + "-shadow");
        var set = res.getElementsByTagName('li');
        return set;
    }

    this.suggestFindNext = function(object, specifier) {
        var cur = object;
        try {
            while (cur != undefined) {
                cur = cur.nextSibling;
                if (cur.nodeType == 3) {
                    cur = cur.nextSibling;
                }
                if (cur != undefined) {
                    if (specifier(cur) == true) {
                        return cur;
                    }
                } else {
                    break;
                }
            }
        } catch(e) {};
        return null;
    }

    this.suggestFindPrev = function(object, specifier) {
        var cur = object;
        try {
            cur = cur.previousSibling;
            if (cur.nodeType == 3)
                cur = cur.previousSibling;
            if (cur != undefined) {
                if (specifier(cur) == true) {
                    return cur;
                }
            }
        } catch(e) {};
        return null;
    }

    this.suggestDoSearch = function() {
        if (typeof liveSearchRoot == "undefined") {
            if (typeof portal_url == "undefined") {
                liveSearchRoot = "";
            } else {
                if (portal_url[portal_url.length-1] == '/') {
                    liveSearchRoot = portal_url;
                } else {
                    liveSearchRoot = portal_url + '/';
                }
            }
        }
        if (typeof liveSearchRootSubDir == "undefined") {
            liveSearchRootSubDir = "";
        }
        if (this.suggestTimout != this.suggestInput.value) {
            if (this.suggestReq && this.suggestReq.readyState < 4) {
                this.suggestReq.abort();
            }
            if (this.suggestInput.value == "") {
                this.suggestHide();
                return false;
            }
            // Do nothing as long as we have less then two characters -
            // the search results makes no sense, and it's harder on the server.
            if (this.suggestInput.value.length < 1) {
                this.suggestHide();
                return false;
            }

            // Do we have cached results
    //         var result = this._suggest_cache[suggestInput.value + ' || ' + state_field.value];
    //         if (result) {
    //                 suggestShowResult(result);
    //                 return;
    //         }

            this.suggestReq = new XMLHttpRequest();

            function callback(object) {
                return function () {
                    object.suggestProcessReqChange();
                }
            }

            this.suggestReq.onreadystatechange = callback(this); //this.suggestProcessReqChange.apply(this);

            // Need to use encodeURIComponent instead of encodeURI, to escape +
            this.suggestReq.open("GET", liveSearchRoot + this.suggestQueryTarget + encodeURIComponent(this.suggestInput.value) + this.paramprovider(), true);
            this.suggestTimout = this.suggestInput.value + ' || ' + this.paramprovider();
            this.suggestReq.send(null);
        }
    }

    this.suggestShowResult = function(result) {
        var res = document.getElementById(this.suggest_field_id + "-result");
        res.style.display = "block";
        var sh = document.getElementById(this.suggest_field_id + "-shadow");
        sh.innerHTML = this.buildSuggest(result);
        this.applyEventHandlers(sh);
    }

    this.buildSuggest = function(dom) {
        var self = this;

        var container = document.createElement("DIV");
        var fieldset = document.createElement("FIELDSET");
        fieldset.className = this.htmlnames['container'];
        var iefix = document.createElement("DIV");
        iefix.className = this.htmlnames['iefix'];
        var ul = document.createElement("UL");
        ul.className = this.htmlnames['table'];

        var lis = dom.getElementsByTagName("li");
        for (var i = 0, li; li = lis[i]; i++) {
            var row = document.createElement("LI");
            row.className = this.htmlnames['row'];
            row.innerHTML = li.childNodes[0].nodeValue;
            ul.appendChild(row);
        }

        iefix.appendChild(ul);
        fieldset.appendChild(iefix);
        container.appendChild(fieldset);

        return container.innerHTML
    }

    this.applyEventHandlers = function(root) {
        var self = this;
        var lis = root.getElementsByTagName("LI");
        for (var i = 0, li; li = lis[i]; i++) {
            li.onclick = function(event) {self.handleClick.apply(self, [event]);};
        }
    }

    this.suggestProcessReqChange = function() {
        if (this.suggestReq.readyState == 4) {
            try {
                if (this.suggestReq.status > 299 || this.suggestReq.status < 200  || this.suggestReq.responseText.length < 10) {
                    this.suggestHide();
                    return;
                }
            } catch(e) {
                return;
            }
            if (this.suggestReq.responseText && this.suggestReq.responseText != '<empty />') {
                this.suggestShowResult(this.suggestReq.responseXML);
            } else {
                this.suggestHide();
            }
            this._suggest_cache[this.suggestTimout] = this.suggestReq.responseText;
        }
    }

    this.handleClick = function(event) {
        var field = this.suggestInput;
        if (field == null || typeof(field) == "undefined") {
            return false;
        }

        var event = event ? event : window.event;
        var target = event.target ? event.target : event.srcElement;
        var value = target.innerHTML;

        if (value) {
            field.value = value;
        }

        this.suggestHide();
        return false;
    }

}

SuggestionWidget.prototype.start = function (paramprovider) {
    if (typeof(paramprovider) == "function") {
        this.paramprovider = paramprovider;
    } else {
        this.paramprovider = function(){return ""};
    }
    this.init();
}

/* - ++resource++pfmutility.js - */
// provides server method with state parameter
function pfmutility_addStateParameter(id) {
    var state_field = document.getElementById(id);
    if (!state_field) {
        var states = document.getElementsByName(id);
        if (state.length > 0) {
            state_field = states[0];
        }
    }

    if (state_field) {
        return '&state=' + encodeURIComponent(state_field.value);
    }

    return '';
}


// attaches suggestion widget to portlet pfm form
function attachPortletSuggestion(event) {
    // params
    var suggest_field_id = 'pfmportlet.county';
    var state_id = 'pfmportlet.State';

    var suggest_url = "pfmutility_suggest_reply?q=";

    // initialize suggestion widget instance
    var suggest = new SuggestionWidget(suggest_field_id, suggest_url);
    // start widget passing it function for providing additional parameters for server request
    suggest.start(function (){return pfmutility_addStateParameter(state_id);});
}

if (window.addEventListener) {
    window.addEventListener("load", attachPortletSuggestion, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", attachPortletSuggestion);
}


// attaches suggestion widget to main pfm form
function attachMainSuggestion(event) {
    // params
    var suggest_field_id = 'pfmmain.county';
    var state_id = 'pfmmain.State';

    var suggest_url = "pfmutility_suggest_reply?q=";

    // initialize suggestion widget instance
    var suggest = new SuggestionWidget(suggest_field_id, suggest_url);
    // start widget passing it function for providing additional parameters for server request
    suggest.start(function (){return pfmutility_addStateParameter(state_id);});
}

if (window.addEventListener) {
    window.addEventListener("load", attachMainSuggestion, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", attachMainSuggestion);
}


/* - adjustIFrameSize.js - */
// http://www.dwi.com/portal_javascripts/adjustIFrameSize.js?original=1
function adjustIFrameSize(iframeWindow){if(iframeWindow.document.height){var iframeElement=document.getElementById(iframeWindow.name);iframeElement.style.height=iframeWindow.document.height+20+'px'} else if(document.all){var iframeElement=document.all[iframeWindow.name];if(iframeWindow.document.compatMode&&iframeWindow.document.compatMode!='BackCompat'){iframeElement.style.height=iframeWindow.document.documentElement.scrollHeight+20+'px'} else{iframeElement.style.height=iframeWindow.document.body.scrollHeight+20+'px'}}}
