// 
// Feature Cycler
// 

var curIndex = 0;

function prevFeature(id)
{
	curIndex--;
	if (curIndex < 0) {
		curIndex = featureArray.length - 1;
	}
	FeatureCycler(id, curIndex);
}
function nextFeature(id) 
{
	curIndex++;
	if (curIndex > (featureArray.length - 1)) {
		curIndex = 0;
	}
	FeatureCycler(id, curIndex);
}
function FeatureCycler(id, index) 
{	
	document.getElementById(id).innerHTML = featureArray[index];
}

function xmlHttpPost(strURL, strSubmit, strResultFunc) {

    var xmlHttpReq = false;
        
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
    	xmlHttpReq = new XMLHttpRequest();
        xmlHttpReq.overrideMimeType('text/xml');
    }
    // IE
    else if (window.ActiveXObject) {
         xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 
		'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
        	eval(strResultFunc + '(xmlHttpReq.responseText);');
        }
    }
	xmlHttpReq.send(strSubmit);
}

//
// Poll Functions
//

function pollVote() {
	var poll = pollform.poll;
	for(var i=0; i < poll.length; i++) 
		if(poll[i].checked) {
			createCookie('pollid'+document.getElementById('pid').value,'y',10);
			xmlHttpPost("assets/includes/poll/poll.submit.php", "&id="+poll[i].value,"pollResult");
		}
}
function pollResult(data) {
	document.getElementById('pollvote').style.display = 'none';
	document.getElementById('pollSubmit').disabled = true;
	document.getElementById('pollresult').style.display = 'block';
}

function checkVote() {
	if(readCookie('pollid'+document.getElementById('pid').value) == 'y') {
		document.getElementById('pollvote').style.display = 'none';
		document.getElementById('pollSubmit').disabled = true;
		document.getElementById('pollresult').style.display = 'block';	
	}	
}
//
// Cookie functions
//

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function strReplace(s, r, w){
	return s.split(r).join(w);
}