MyFeedback = new function() {
   this.submit = function(theform) {
        var output = '';
        this.collapser()
        if (typeof(featurelist_alerttext) == "undefined") {
            output = "Thanks for the feedback!";
        }
        else {
            output = featurelist_alerttext
        }
        if (output != "none") {
            window.setTimeout("alert('"+output+"');", 500);
        }
   }

   this.collapser = function() {
         var buttondisplay = "normal";
      if (typeof(featurelist_buttondisplay) != "undefined") {
        buttondisplay = featurelist_buttondisplay;
      } 
      
            var imgposition = "fixed";
      if (typeof(navigator.userAgent) != "undefined") {
        if(navigator.userAgent.indexOf("MSIE")!=-1){
            imgposition = "absolute";
        }
      }

      if (typeof(featurelist_imgposition) != "undefined") {
        imgposition = featurelist_imgposition;
      }
        document.getElementById("florg_feedbackdiv").style.display="none";     
        document.getElementById("florg_feedbackopen").style.display= buttondisplay;
   }
   
    this.showdiv = function(element) {
    
          var imgposition = "fixed";
      if (typeof(navigator.userAgent) != "undefined") {
        if(navigator.userAgent.indexOf("MSIE")!=-1){
            imgposition = "absolute";
        }
      }

      if (typeof(featurelist_imgposition) != "undefined") {
        imgposition = featurelist_imgposition;
      }
        j = document.getElementById("florg_feedbackdiv")
        j.style.display="";
        txt = document.getElementById("featurelist_feeedbacktext");
        txt.focus();
        // if it's relative, for now, we want to hide the button.
        if (imgposition == "relative") {
            document.getElementById("florg_feedbackopen").style.display="none";
        }        
    }

    this.init = function() {

      var imgtop = "10%";
      if (typeof(featurelist_imgtop) != "undefined") {
        imgtop = featurelist_imgtop;
      }

      var imgleft = "0pt";
      if (typeof(featurelist_imgleft) != "undefined") {
        imgleft = featurelist_imgleft;
      } 

      var flsite = "http://soon.featurelist.org";
      if (typeof(featurelist_site) != "undefined") {
        flsite = featurelist_site;
      }

      var imgsrc = flsite +"/img/feedback.gif";
      if (typeof(featurelist_imgsrc) != "undefined") {
        imgsrc = featurelist_imgsrc;
      }

      var imgposition = "fixed";
      if (typeof(navigator.userAgent) != "undefined") {
        if(navigator.userAgent.indexOf("MSIE")!=-1){
            imgposition = "absolute";
        }
      }

      if (typeof(featurelist_imgposition) != "undefined") {
        imgposition = featurelist_imgposition;
      }
      
      
      var buttondisplay = "normal";
      if (typeof(featurelist_buttondisplay) != "undefined") {
        buttondisplay = featurelist_buttondisplay;
      } 
      
      var buttontype = "image";
      if (typeof(featurelist_buttontype) != "undefined") {
        buttontype = featurelist_buttontype;
      } 
      
      var linktext = "Feedback";
      if (typeof(featurelist_linktext) != "undefined") {
        linktext = featurelist_linktext;
      }
      
      var headertext = "We'd love to hear your thoughts!";
      if (typeof(featurelist_headertext) != "undefined") {
        headertext = featurelist_headertext;
      }
            
      document.write("<div id='florg_feedbackdiv' style='text-align:left;display:none;position:"+imgposition+";z-index:580;top:"+imgtop+";left:"+imgleft+";background-color:white;color:black;width:300px;border:1px solid black;font-family:Verdana;font-size:small;'>");
      document.write("<div style='margin:5px 5px 0px 5px;text-align:center;'>");
      document.write("<form style='margin:0px;' method='post' onsubmit='MyFeedback.submit(this)' id='florg_feedbackform' target='florg_feedbackformframe' action='"+flsite+"/feedback/widget/" + featurelist_projectname + "'>");
      document.write(headertext + "<br/><br/>");
      document.write("Your email: <small>(optional)</small><center><input type='text' style='width:280px;font-family:Verdana;font-color:black;' value='' name='email'/></center><br/>");
      document.write("Your feedback:<center><textarea id='featurelist_feeedbacktext' style='height:100px;width:280px;font-family:Verdana;font-color:black;font-size:small;' name='feedback'></textarea></center><br/>");
      document.write("<center><button style='padding:5px;' type='submit' class='btn'>Send Feedback</button></center>");
      document.write("<input name='page' type='hidden' value='"+location.href+"' />");
      document.write("</form>");
      document.write("<iframe id='florg_feedbackformframe' name='florg_feedbackformframe' style='width:0px; height:0px; border: 0px'></iframe>");      
      document.write("</div>");
      document.write("<div style='float:right;padding-bottom:6px;padding-right:5px;'><a href='#' onclick='MyFeedback.collapser();return false;'>Cancel</a></div>");
      document.write("<div style='clear:right'></div>")       
      document.write("</div>");      
      document.write("<div id ='florg_feedbackopen' style='display:"+buttondisplay+";cursor:pointer;z-index:550;text-align:left;position:"+imgposition+";top:"+imgtop+";left:"+imgleft+";'>");
      if(buttontype != "text") {
        document.write("<img src='"+ imgsrc + "' onclick='MyFeedback.showdiv(this);return false;'/>");
      }
      else {
        document.write("<a href='#' onclick='MyFeedback.showdiv(this);return false;'>"+ linktext +"</a>"); 
      } 
      document.write("</div>");
    }
}
MyFeedback.init();
