function createXMLHttpRequest() {
	var XMLRequest = false;
    
    // create object for IE7, Mozilla, Safari, etc. (native object)
    if (window.XMLHttpRequest) {
    	XMLRequest = new XMLHttpRequest();
    }
    // create object for IE6, IE5, etc. (ActiveX object)
    else if (window.ActiveXObject) {
    	var success = false;
    	var progIDs = new Array(
    		"Msxml2.XMLHTTP.6.0",
    		"Msxml2.XMLHTTP.3.0",
    		"Msxml2.XMLHTTP",
    		"Microsoft.XMLHTTP"
    	);
    	
    	for (i=0; i<progIDs.length && !success; i++) {
    		try {
    			XMLRequest = new ActiveXObject(progIDs[i]);
    			success = true;
    		}
    		catch (failure) {
    			
    		}
    	}
    }
    
    return XMLRequest;
}

function moreItems(page_a, section, prev_next) {
	var post_variables = "page_a=" + page_a + "&section=" + section + "&prev_next=" + prev_next;
        
    AjaxRequest = createXMLHttpRequest();
   
    AjaxRequest.open("POST", "../scripts/ajax-show-new-items.php", true);
    AjaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    AjaxRequest.onreadystatechange = function() {
    	if (AjaxRequest.readyState == 4 && AjaxRequest.status == 200) {
    		document.getElementById('archives_list').innerHTML=AjaxRequest.responseText;
    	}
    }
    
    AjaxRequest.send(post_variables);
}

function ajaxVote() {
	// Get variables
	var poll_id = document.getElementById('poll_id').value;
	var poll_questions_num = document.getElementById('poll_questions_num').value;
	var poll_answer=0;
	for (i=0;i<poll_questions_num;i++) {
		if (document.getElementById('poll_answer_'+i).checked==true) {
			poll_answer=document.getElementById('poll_answer_'+i).value;			
		}
	}
	
	if (poll_answer==0) {
		alert("You must select an option.");
	}
	else {
		document.getElementById('poll_results_div').innerHTML='<div>&nbsp;</div><div style="text-align:center"><img src="images/ajax-loader.gif" alt="ajax-loader" width="32" height="32" border="0" /></div><div>&nbsp;</div>';
		
		var post_variables = "poll_id=" + poll_id + "&poll_answer=" + poll_answer;
        
	    AjaxRequest = createXMLHttpRequest();
	   
	    AjaxRequest.open("POST", "scripts/ajax-vote-system.php", true);
	    AjaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    
	    AjaxRequest.onreadystatechange = function() {
	    	if (AjaxRequest.readyState == 4 && AjaxRequest.status == 200) {
	    		document.getElementById('poll_results_div').innerHTML=AjaxRequest.responseText;
	    	}
	    }
	    
	    AjaxRequest.send(post_variables);	
	}
}

function ajaxVoteArchive(poll_id) {
	// Get variables
	var poll_questions_num = document.getElementById('poll_questions_num_'+poll_id).value;
	var poll_answer=0;
	for (i=0;i<poll_questions_num;i++) {
		if (document.getElementById('poll_answer_'+i+'_'+poll_id).checked==true) {
			poll_answer=document.getElementById('poll_answer_'+i+'_'+poll_id).value;			
		}
	}
	
	if (poll_answer==0) {
		alert("You must select an option.");
	}
	else {
		document.getElementById('poll_results_div'+'_'+poll_id).innerHTML='<div>&nbsp;</div><div style="text-align:center"><img src="/images/ajax-loader.gif" alt="ajax-loader" width="32" height="32" border="0" /></div><div>&nbsp;</div>';
		
		var post_variables = "poll_id=" + poll_id + "&poll_answer=" + poll_answer;
    	    
	    AjaxRequest = createXMLHttpRequest();
	   
	    AjaxRequest.open("POST", "/scripts/ajax-vote-system.php", true);
	    AjaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    
	    AjaxRequest.onreadystatechange = function() {
	    	if (AjaxRequest.readyState == 4 && AjaxRequest.status == 200) {
	    		document.getElementById('poll_results_div'+'_'+poll_id).innerHTML=AjaxRequest.responseText;
	    	}
	    }
	    
	    AjaxRequest.send(post_variables);	
	}
}
