function LoadPage(page,usediv,method, param) {
         // Set up request varible
         try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
		 
         //Show page is loading
         //document.getElementById(usediv).innerHTML = '<img src="nt_images/loading.gif" />';
      		
			 //scroll to top
			 
			 scroll(0,0);
			 xmlhttp.open('GET', page+'?'+ param);	
			    xmlhttp.onreadystatechange = function(){
                 //Check page is completed and there were no problems.
                
				 if (xmlhttp.readyState == 4) {
					 if (xmlhttp.status == 200) {
						//alert(http_request.responseText);
						//if(xmlhttp.responseText == 'Posted!')
						//{	
							document.getElementById(usediv).innerHTML = xmlhttp.responseText;
							LoadPage2('http://www.txtmate.com/mycomment.php', 'mypost');
							LoadPage2('http://www.txtmate.com/friendsabout.php', 'post');
							//alert(param);
							clearForms();
						//}
					 } else {
						alert('There was a problem with the request.');
					 }
				  }
					 }
			 //send data
			  		
			  /*xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			  xmlhttp.setRequestHeader("Content-length", param.length);
			  xmlhttp.setRequestHeader("Connection", "close");*/
			  xmlhttp.send(null); 
			  return false ;
		/* }*/
}

function LoadPage2(page,usediv) {
	document.getElementById(usediv).innerHTML = '<img src="http://www.txtmate.com/nt_images/loading.gif" />';
	        xmlhttp.onreadystatechange = function(){
                 //Check page is completed and there were no problems.
                
				 if (xmlhttp.readyState == 4) {
					 if (xmlhttp.status == 200) {
						 document.getElementById(usediv).innerHTML = xmlhttp.responseText;
						  } else {
						alert('There was a problem with the request.');
					 }
				  }
					 }
	
			 xmlhttp.open("GET", page);
			 
			 xmlhttp.send(null);
			 //Stop any link loading normaly
			 return false;
}
 // function will clear input elements on each form
function clearForms(){
  // declare element type
  var type = null;
  // loop through forms on HTML page
  for (var x=0; x<document.forms.length; x++){
    // loop through each element on form
    for (var y=0; y<document.forms[x].elements.length; y++){
      // define element type
      type = document.forms[x].elements[y].type
      // alert before erasing form element
      //alert('form='+x+' element='+y+' type='+type);
      // switch on element type
      switch(type){
        case "text":
        case "textarea":
        case "password":
        //case "hidden":
          document.forms[x].elements[y].value = "";
          break;
        case "radio":
        case "checkbox":
          document.forms[x].elements[y].checked = "";
          break;
        case "select-one":
          document.forms[x].elements[y].options[0].selected = true;
          break;
        case "select-multiple":
          for (z=0; z<document.forms[x].elements[y].options.length; z++){
            document.forms[x].elements[y].options[z].selected = false;
          }
        break;
      }
    }
  }
}

function take() {
   var poststr = "";
     
	 // getstr += "text=" + encodeURI( obj.getElementById("text").value ) ;
     // var poststr;	
	 var text = encodeURI( document.getElementById("text").value );
	 text = text.replace("<", "&lt;").replaceAll(">", "&gt;");
	text = text.replace("eval\\((.*)\\)", "");
	text = text.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
	text = text.replace("((?i)script)", "");
	
	var fid = document.getElementById("fid").value;
	fid = fid.replace("<", "&lt;").replaceAll(">", "&gt;");
	fid = fid.replace("eval\\((.*)\\)", "");
	fid = fid.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
	fid = fid.replace("((?i)script)", "");
	
	var subm= document.getElementById("submit").value;
	subm = subm.replace("<", "&lt;").replaceAll(">", "&gt;");
	subm = subm.replace("eval\\((.*)\\)", "");
	subm = subm.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
	subm = subm.replace("((?i)script)", "");
	
	
	 poststr += "submit="+  + "&fid=" + fid;
	 poststr += "&text=" +  text ;
	 //
	 
	 //alert(poststr);
     LoadPage('http://www.txtmate.com/postit.php', 'comment-post', 'POST', poststr); 
	 	 
	 
   }
