function toggleDiv(divid)
{
	if(document.getElementById(divid).style.display == 'none')
	{
		document.getElementById(divid).style.display = 'block';
	} else {
		document.getElementById(divid).style.display = 'none';
	}
}

function calc_piv()
{
   var b = document.piv;
   if(b.close.value != '' && b.high.value != '' && b.low.value != ''){
      var i = document.getElementById('piv_results');
      high1 = b.high.value * 1;      low1 = b.low.value * 1;
      close1 = b.close.value * 1;

      pivot = Math.round(((high1 + low1 + close1) / 3) * Math.pow(10,4)) / 10000;
      r1 = Math.round((2 * pivot - low1) * Math.pow(10,4)) / 10000;
      s1 = Math.round((2 * pivot - high1) * Math.pow(10,4)) / 10000;
      r2 = Math.round((pivot - s1 + r1) * Math.pow(10,4)) / 10000;
      s2 = Math.round((pivot - (r1 - s1)) * Math.pow(10,4)) / 10000;
      r3 = Math.round((2 * (pivot - low1) + high1) * Math.pow(10,4)) / 10000;
      s3 = Math.round((low1 - (2 * (high1 - pivot))) * Math.pow(10,4)) / 10000;  
      i.innerHTML = "<strong>R3: </strong>" + r3 + "<br/>";
      i.innerHTML += "<strong>R2: </strong>" + r2 + "<br/>";
      i.innerHTML += "<strong>R1: </strong>" + r1 + "<br/>";
      i.innerHTML += "<strong>Pivot: </strong>" + pivot + "<br/>";
      i.innerHTML += "<strong>S1: </strong>" + s1 + "<br/>";
      i.innerHTML += "<strong>S2: </strong>" + s2 + "<br/>";
      i.innerHTML += "<strong>S3: </strong>" + s3 + "<br/>";
   } else {
      alert('Please fill out all of the fields');
   }
}


function calc_fib()
{
   var errors = '';
   if((document.fib.low.value != '') && (document.fib.high.value != ''))
   {
      if(document.fib.low.value < document.fib.high.value)
      {
         var difference = document.fib.high.value - document.fib.low.value;
         var fibonacci = "From " + document.fib.low.value + " to " + document.fib.high.value + " the retracement levels are:" + "\n";
         fibonacci += "0% = " + document.fib.low.value + "\n";
			fibonacci += "23.6% = " + ((difference) * .236 - (-document.fib.low.value)) + "\n";
         fibonacci += "38.2% = " + ((difference) * .382 - (-document.fib.low.value)) + "\n";
         fibonacci += "50% = " + ((difference) * .50 - (-document.fib.low.value)) + "\n";
         fibonacci += "61.8% = " + ((difference) * .618 - (-document.fib.low.value)) + "\n";
			fibonacci += "100% = " + document.fib.high.value + "\n\n";
         fibonacci += "From " + document.fib.high.value + " to " + document.fib.low.value + " the retracement levels are:" + "\n";
         fibonacci += "100% = " + document.fib.high.value + "\n";
			fibonacci += "61.8% = " + ((difference) * .382 - (-document.fib.low.value)) + "\n";
         fibonacci += "50% = " + ((difference) * .50 - (-document.fib.low.value)) + "\n";
         fibonacci += "38.2% = " + ((difference) * .618 - (-document.fib.low.value)) + "\n";
         fibonacci += "23.6% = " + ((difference) * .764 - (-document.fib.low.value)) + "\n";
			fibonacci += "0% = " + document.fib.low.value;
         alert(fibonacci);
      } else { alert('Low must be lower than high'); }
   } else { alert('Fill out both low and high'); }
}

function select_all(name,value){
   for(var t, i=0;t=document.analyze.elements[name][i++];t.checked=value);
}


function processVote(v_value)
{
    var bElem = get_radio_value();
        var aElem = v_value;
      var url = 'processpoll.php';
      var params = 'a=' + aElem + '&b=' + bElem;
      var ajax = new Ajax.Updater({success: 'aResults'},url, {method: 'get', parameters: params, onFailure: reportError, onSuccess: slideDown});
}
function reportError(){
   alert('There was an error processing your vote.');
}
function slideDown(){
   document.getElementById('poll_holder').innerHTML = "<strong>Thank you for your vote!</strong><br/>";
   document.getElementById('votepoll').visibility = 'hidden';
	document.getElementById('pollResponses').style.display = 'none';
	document.getElementById('resultsBtn').style.display = '';
	document.getElementById('voteholder').style.display = 'none';
}

function get_radio_value()
{
    for (var i=0; i < document.frm_poll.vote.length; i++)
    {
    if (document.frm_poll.vote[i].checked)
        {
        return document.frm_poll.vote[i].value;
        }
    }
}

function noBlank(btn)
{
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return false;
}


