    debuging = false;
    
    var urlAddress = location.href;
    var pageName = document.title;
    function addToFavorites() { 
        if (window.sidebar) {
            window.sidebar.addPanel(pageName, urlAddress, "");
        } else if (window.opera && window.print) {
            var elem = document.createElement('a');
            elem.setAttribute('href', urlAddress);
            elem.setAttribute('title', pageName);
            elem.setAttribute('rel', 'sidebar');
            elem.click();
        } else if (window.external) { 
            window.external.AddFavorite(urlAddress,pageName) 
        } else { 
            alert("Sorry! Your browser doesn't support this function."); 
        } 
    }

    function fetchXmlData (xmlUrl, xmlGet, xmlPost) {
        ajaxXmlUrl = xmlUrl;
        ajaxXmlGet = xmlGet;
        ajaxXmlPost = xmlPost;
        window.setTimeout("fetchXmlData2()",50);
    }

    function fetchXmlData2 () {
        updateDataContent(ajaxXmlUrl, ajaxXmlGet, ajaxXmlPost);
    }

    function addLog(text) {
        if(debuging)
            if(document.getElementById("internalTest"))
                document.getElementById("internalTest").value = text + "\r\n" + document.getElementById("internalTest").value
    }

    function clearLog() {
        if(debuging)
            if(document.getElementById("internalTest"))
                document.getElementById("internalTest").value = ""
    }
    
    function updateDataContent (sFromUrl, xmlGet, xmlPost/*, oTargetElement*/) {
        try 
        {
            clearLog();
            
            url = sFromUrl;
            if(xmlGet != "") {
                url = url + "?" + xmlGet;
            }

            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("POST", url, true);
            addLog("posting data to : "+url);
            addLog("params : "+xmlPost);
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4) {
                    try {
                        if (xmlhttp.responseXML != null) {
                            addLog("Data received : "+xmlhttp.responseText);

                            doc = xmlhttp.responseXML.documentElement;
                            if(doc) {
                                try{
                                    targetNode = doc.getElementsByTagName("target").item(0);
                                    targetValue = targetNode.childNodes.item(0).nodeValue;
                                }catch(err){addLog("failed to get targetValue : "+err);}
                                try{
                                    contentNode = doc.getElementsByTagName("content").item(0);
                                    contentValue = contentNode.childNodes.item(0).nodeValue;
                                }catch(err){addLog("failed to get contentValue : "+err);}

                                try {
                                    addLog("Sending content to section : "+targetValue);
                                    UpdateContent(targetValue, contentValue);
                                }catch(err){addLog("Exception updating content : "+err);}

                            } else {
                                addLog("XML is invalid.");
                            }
                        } else {
                            addLog("Response is null. "+xmlhttp.responseText);
                        }
                    } catch(err) {
                        addLog("Exception caught : "+err);
                    }
                } else {
                    addLog("Connection state : "+xmlhttp.readyState);
                }
            };
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttp.send(xmlPost);
        } 
        catch(e) {
            addLog('exception catched : '+e);
        }
    }

    function UpdateContent(target, content) {
        oTargetElement = document.getElementById(target);
        oTargetElement.innerHTML="";
        oTargetElement.innerHTML = content;
    }
    
    function urlencode(str) {
        str = escape(str);
        str = str.replace(/\+/g, '%2B');
        str = str.replace(/%20/g, '+');
        str = str.replace(/\*/g, '%2A');
        str = str.replace(/\//g, '%2F');
        str = str.replace(/@/g, '%40');
        return str;
    }

    function urldecode(str) {
        str = str.replace(/\+/g, ' ');
        str = unescape(str);
        return str;
    }

    function good(id) {
        fetchXmlData("/vote/"+id+"/good/", "", "");
    }
    
    function bad(id) {
        fetchXmlData("/vote/"+id+"/bad/", "", "");
    }
    
    function share(form) {
        try {
            if(form.share_sender.value == ""){
                return false;
            }
            post = "sender="+urlencode(form.share_sender.value);
            post += "&url="+urlencode(location.href);
            post += "&title="+urlencode(document.title);
            objArray = document.getElementsByName("share_email[]");
            hasDest = false;
            for(i=0; i<objArray.length; i++) {
                if(objArray[i].value != "") {
                    //emails.push(objArray[i].value);
                    post += "&share_email[]="+urlencode(objArray[i].value);
                    hasDest = true;
                }
            }
            if(!hasDest) {
                return false;
            }
            
            //alert(post);
            fetchXmlData("/?m=share&method=ajax&target=share_result", "", post);
        } catch(ex) {
            alert(ex);
        }
        return false;
    }
