// JavaScript Document

function doNothing(){};

var xmlhttp;
	xmlhttp=null;
	
	var targetID;	
	targetID = null;
	
   function getContent(obj) {
      var poststr = "page="+obj; 
      makePOSTRequest('includes/get_content.php', poststr, null);
   }
   
   function getContentByTag(obj) {
      var poststr = "tag="+obj; 
      makePOSTRequest('includes/get_content.php', poststr, null);
   }
   

// COMMENTS FUNCTIONS	
   function getComments(obj) {
      var poststr = "content_id="+obj; 
      makePOSTRequest('includes/get_comments.php', poststr, obj);
   }
   
   function submitComments(obj) {
      var poststr =  "content_id=" + encodeURI( document.getElementById("content_id").value )+
							"&name=" + encodeURI( document.getElementById("name").value )+
							"&email=" + encodeURI( document.getElementById("email").value )+
							"&comment=" + encodeURI( document.getElementById("comment").value )+
							"&captcha_code=" + encodeURI( document.getElementById("captcha_code").value )+
							"&submit=yes"; 
      makePOSTRequest('includes/get_comments.php', poststr, obj);
   }
// SEND TO A FRIEND FUNCTIONS
   
	function getSendToAFriend(obj) {
      var poststr = "content_id="+obj; 
      makePOSTRequest('includes/get_sendtoafriend.php', poststr, obj);
   }
   
   function submitSendToAFriend(obj) {
      var poststr =  "content_id=" + encodeURI( document.getElementById("content_id").value )+
							"&your_name=" + encodeURI( document.getElementById("your_name").value )+
							"&your_email=" + encodeURI( document.getElementById("your_email").value )+
							"&friend_name=" + encodeURI( document.getElementById("friend_name").value )+
							"&friend_email=" + encodeURI( document.getElementById("friend_email").value )+
							"&captcha_code=" + encodeURI( document.getElementById("captcha_code").value )+
							"&submit=yes"; 
      makePOSTRequest('includes/get_sendtoafriend.php', poststr, obj);
   }

   
	function makePOSTRequest(url,parameters,target) {
		targetID = 'content_footer_' + target;
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
                // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

		if (target==null){
	  		http_request.onreadystatechange = newContent;
		} else {
	  	//	http_request.onreadystatechange = writeComments(target);
	  	http_request.onreadystatechange = writeComments;
		}
     
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
	


function newContent() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('main-column').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

function writeComments() {
//alert("made it to writeComments!");
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById(targetID).innerHTML = result;          
         } else {
            alert('There was a problem with the request.');
         }
      }
   }


