// string trim method implementations
String.prototype.trim = function() {
   return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.ltrim = function() {
   return this.replace(/(^\s*)/g, "");
}

String.prototype.rtrim = function() {
   return this.replace(/(\s*$)/g, "");
}


// get instance of XMLHttpRequest
function getHttpRequest() {
   var xmlHttp = null;

   try {
      xmlHttp = new XMLHttpRequest();
   } catch (e) {
      var progIds = ["Microsoft.XMLHTTP", "MSXML2.XMLHTTP", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"]
      var success = false;

      for (var iterator = 0; (iterator < progIds.length) && ( ! success); iterator ++) {
         try {
            xmlHttp = new ActiveXObject(progIds[iterator]);
            success = true;
         } catch (e) {
         }
      }
      if (!success) {
         return null;
      }
   }

   return xmlHttp;
}

// redirects to login page
function doLogin(url) {
   if (url != null && url.trim().length > 0) {
      window.parent.location.href = url;
   }
}

// remove child nodes in given DOM element
function removeChildNodes(e) {
   if (e != null) {
      while (e.hasChildNodes()) {
         e.removeChild(e.firstChild);
      }
   }
}

function isArray(o) {
   if (o instanceof Array) {
      return true;
   } else {
      return typeof(o.length) == "number";
   }
}

// returns top position of provided element
function findPosX(o) {
   var curleft = 0;

   if (o.offsetParent) {
      while (o.offsetParent) {
         curleft += o.offsetLeft
         o = o.offsetParent;
      }
   } else if (o.x) {
      curleft += o.x;
   }

   return curleft;
}

// returns left position of provided element
function findPosY(o) {
   var curtop = 0;

   if (o.offsetParent) {
      while (o.offsetParent) {
         curtop += o.offsetTop
         o = o.offsetParent;
      }
   } else if (o.y) {
      curtop += o.y;
   }

   return curtop;
}

/* StringBuffer class */
function StringBuffer() {
   this.buffer = [];
}

StringBuffer.prototype.append = function(string) {
   this.buffer.push(string);
   return this;
}

StringBuffer.prototype.toString = function() {
   return this.buffer.join("");
}

function insertAfter(newNode, afterNode) {
   if (newNode == null || afterNode == null) {
      return null;
   }

   var parent = afterNode.parentNode;
   var offset = 0;
   var insert = false;

   var nodes = [];

   for (var i = 0; i < parent.childNodes.length; i++) {
      if (parent.childNodes[i].nodeType == 1) {
         nodes.push(parent.childNodes[i]);

         if (parent.childNodes[i] == afterNode) {
            offset = nodes.length - 1;
         }
      }
   }

   if (nodes.length > offset + 1) {
      insert = true;
   }

   if (insert) {
      return parent.insertBefore(newNode, nodes[offset + 1]);
   } else {
      return parent.appendChild(newNode);
   }
}

function fs(formid, url, method) {
   var f = document.getElementById(formid) != null ? document.getElementById(formid) : null;
   var a = url != null && url.trim().length > 0 ? url : null;
   var m = method != null && method.trim().length > 0 ? method : null;

   if (f != null) {
      if (a != null) {
         f.action = a;
      }

      if (m != null) {
         f.method = m;
      }

      f.submit();
   }
}

function navigate(p) {
   var xmlHttp = getHttpRequest();
   if (xmlHttp == null) return;
   var msg = 'p=' + p;
   msg += '&userId=' + '10398';
   xmlHttp.open('POST', '/uye/profil/getusercomments', true);
   xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4) {
         document.getElementById("usercomments").innerHTML = xmlHttp.responseText;
      }
   }

   xmlHttp.send(msg);
}



