function createRequestObject() {
    var tmpXmlHttpObject;
    
    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest) { 
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();
	
    } else if (window.ActiveXObject) { 
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return tmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
var http = createRequestObject();


function share(id) {
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', 'ajaxshare.php?share=' + id, true);
	
    //assign a handler for the response
    http.onreadystatechange = processShare;
	
    //actually send the request to the server
    http.send(null);a
}

function processShare() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
        //document.getElementById('votes').innerHTML = response + ' votes.';
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }

}

var divid;

function vote(id) {

    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', 'ajaxvote.php?vote=' + id, true);
	
    //assign a handler for the response
    http.onreadystatechange = processVote;
	
    //actually send the request to the server
    http.send(null);
	
	divid = id;
}

function processVote() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		var divid2 = "vote" + divid;
        //in this case simply assign the response to the contents of the <div> on the page. 
        document.getElementById(divid2).innerHTML = response;
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}

var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	

	// close old layer
     
	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'block';
	var linkid = "link" + id;
	document.getElementById(linkid).innerHTML = '<a href="javascript:void(0);" onclick="mclose(\'' + id + '\'); return false;">Comments <<</a>';

}
// close showed layer
function mclose(id)
{
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'none';
	var linkid = "link" + id;
	document.getElementById(linkid).innerHTML = '<a href="javascript:void(0);" onclick="mopen(\'' + id + '\'); return false;">Comments >></a>';
}

function nopen(id)
{	

	// close old layer
     
	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'block';
	var linkid = "link" + id;
	document.getElementById(linkid).innerHTML = '<a href="javascript:void(0);" onclick="nclose(\'' + id + '\'); return false;">Dont add <<</a>';

}
// close showed layer
function nclose(id)
{
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'none';
	var linkid = "link" + id;
	document.getElementById(linkid).innerHTML = '<a href="javascript:void(0);" onclick="nopen(\'' + id + '\'); return false;">Add Comment</a>';
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#C4CEFF'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
var addcomartid;

function addcomment(artid) {
var formname = "comform" + artid;
	 var form = document.forms[formname];
	var name = form.sname.value;
	var email = form.semail.value;
	var message = form.stext.value;

	var reason = "";

  reason += validateEmpty(form.sname);
  reason += validateEmpty(form.stext);
	
	if (reason != "") {
	var comerrordiv = "comformerror" + artid;
	document.getElementById(comerrordiv).innerHTML = "Please complete the blue fields.";
	}
	else {
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', 'addcomment.php?name=' + name + '&email=' + email + '&message=' + message + '&artid=' + artid, true);
	
    //assign a handler for the response
    http.onreadystatechange = processaddcomment;
	
    //actually send the request to the server
    http.send(null);
	
	addcomartid = artid;
	}
}

function processaddcomment() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		var addcomdiv = 'com' + addcomartid;
        //in this case simply assign the response to the contents of the <div> on the page. 
        document.getElementById(addcomdiv).innerHTML = response;
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}

//Add Tag

var addtagartid;

function addtag(artid) {
var formname = "tagform" + artid;
	 var form = document.forms[formname];
	var tag = form.tag.value;

	var reason = "";

  reason += validateEmpty(form.tag);
	
	if (reason != "") {
	var tagerrordiv = "tagformerror" + artid;
	document.getElementById(tagerrordiv).innerHTML = "Please complete the blue field.";
	}
	else {
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', 'addtag.php?art=' + artid + '&tag=' + tag, true);
	
    //assign a handler for the response
    http.onreadystatechange = processaddtag;
	
    //actually send the request to the server
    http.send(null);
	
	addtagartid = artid;
	}
}

function processaddtag() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		var addtagdiv = 'tagholder' + addtagartid;
        //in this case simply assign the response to the contents of the <div> on the page. 
        document.getElementById(addtagdiv).innerHTML = response;
		
		var formname = "tagform" + addtagartid;
	 var form = document.forms[formname];
	var tag = form.tag.value;
		form.tag.value = "";
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}

function tagopen(id)
{	
	// close old layer
	// get new layer and show it
	newid = "addtag" + id;
	ddmenuitem = document.getElementById(newid);
	ddmenuitem.style.display = 'block';
	var taglink = "addtaglnk" + id;
	document.getElementById(taglink).innerHTML = '<a href="javascript:void(0);" onclick="tagclose(\'' + id + '\'); return false;">Dont add <<</a>';

}
// close showed layer
function tagclose(id)
{
	newid = "addtag" + id;
	ddmenuitem = document.getElementById(newid);
	ddmenuitem.style.display = 'none';
	var taglink = "addtaglnk" + id;
	document.getElementById(taglink).innerHTML = '<a href="javascript:void(0);" onclick="tagopen(\'' + id + '\'); return false;">Add Tag</a>';
}