
function ahah_FeedbackComment()
{
    mycomment = (document.getElementById("comment").value);
    myURL      = document.URL;
    mytitle    = document.title ;
    myScore = "?";
    if (document.getElementById("score0").checked )   myScore="0";
    if (document.getElementById("score1").checked )   myScore="1";
    if (document.getElementById("score2").checked )   myScore="2";
    if (document.getElementById("score3").checked )   myScore="3";
    if (document.getElementById("score4").checked )   myScore="4";
    var myerror = "";
    if (myScore == "?"){
        myerror = "<font color='red'>Please select a rating</font>";
     }
	if ((myScore == "0") && (mycomment == "")){
        myerror = "<font color='red'>Please enter a comment</font>";
		myScore = "?";
    }

    if (mycomment.indexOf("<") > -1) {
        mycomment = "*** bad data detected and removed ***";
        myerror = "<font color='red'>Invalid comment</font>";
        myScore = "?";
    };

    
   if (myScore != "?") {
        url = "/support/feedbackportal.aspx?comment=";
        url = url + mycomment.substring(0,1000) + "&url=" + myURL + "&pagetitle=" + mytitle +  "&score=" + myScore;
        ahah( url , "result");
        myerror = "";
    }
    if (document.getElementById("errmsg")) document.getElementById("errmsg").innerHTML = myerror;
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

// this one does multiple outstanding requests
//from http://groups.google.com/group/XMLHttpRequest/browse_thread/thread/3deab0ff4778fdf7/a8f83be73f135ed5
// http://www.manalab.com/lab/ahah/
// 2006, www.manaLab.com/Lab
//
// Taken form: http://www.gizax.it/articles/2005/ahah/
// and rearrenged by Sax

// the key feature seems to be making the function ahahDone (that handles the return) local to the main ahah function
// invoking a function could be a useful option, also
// timestamp addition to url is to defeat the cache in IE that thinks that all GETs should be cached, even when the response says don't
 function ahah(url, target, funcname) {
        //url = url + '&x=' + new Date().getTime();
        function ahahDone() {
          if(req.readyState == 4){
            if(req.status == 200){
				myresp = req.responseText;
				myresp = myresp.replace(/<\?xml version="1.0" encoding="utf-8" \?>/gi,"")
				myresp = myresp.replace(/<\?xml version="1.0" encoding="utf-8"\?>/gi,"")
				myresp = myresp.replace(/<string xmlns="http:\/\/dialogic.com\/">/,"")
				myresp = myresp.replace(/<\/string>/,"")					
				myresp = myresp.replace(/&gt;/gi,">")
				myresp = myresp.replace(/&lt;/gi,"<")
				myresp = myresp.replace(/&amp;/gi,"&")
				myresp = myresp.replace(/\r/gi,"")
				myresp = myresp.replace(/\n/gi,"")
                if(!(target == undefined)){
					document.getElementById(target).innerHTML = myresp;
                }
                if(!(funcname == undefined)){
                    eval(funcname+"(myresp);");
                }
            }else {
                if(!(target == undefined)){
                    document.getElementById(target).innerHTML = "Error: " + req.statusText;
                }
				if(!(funcname == undefined)){
                    eval(funcname+"(req.responseText);");
                }
            }
          }
        }

        if(!(target == undefined)){
            document.getElementById(target).innerHTML = '<img src="/support/images/loading.gif" border="0"/>';
			//document.getElementById(target).innerHTML = "wait..."
        }
        if(window.XMLHttpRequest){
                var req = new XMLHttpRequest();
        }else if(window.ActiveXObject) {
                var req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if(req){
                req.onreadystatechange = function() {
                        ahahDone();
                };
                req.open("GET", url, true);
                req.send("");
        }
} 
