// ****************************************************************
//
// PUT ALL CUSTOM JS FUNCTIONALITY NEEDED IN THIS FILE
//
// ****************************************************************
function DisableForm() {
    $("input[type=text],input[type=radio],input[type=checkbox],select,.submit input,textarea").attr("disabled", true);
	//$(".submit").hide();
    //$('.submit').addClass("question_nav_border");
    $('.submit input').hide();
    $('.skip').hide();
	$(".next").show();
	$(".flash_wrapper").fadeIn(500);
}

function checkCheckboxes()
{
	var isChecked = false;
	$("input[type=checkbox],input[type=radio]").each(function(){
	if($(this).attr("checked"))
	{
		isChecked = true;
	}
	});
	if(isChecked == true)
	{
		//alert("is checked")
		$(".submit input").addClass("active");
	}
	else
	{
		//alert("is not checked")
		$(".submit input").removeClass("active");
	}
}



function drawChart( type, data )
{
	var wait = setTimeout(function() {
		var flexApp = FABridge.b_Charts.root();
		flexApp.switchChart(type, data);
		alert('drawChart');
	}, 5000);
}

/************************************
jQuery Slideshow - With Progress Bar

 - Currently all slides must be the same filetype(jpg).
************************************/

$(function(){
	//FIX DEFAULT LABEL FUNCTIONALITY IN MOBILE SAFARI
	if (navigator.userAgent.match(/iPhone/i) || 
  	navigator.userAgent.match(/iPod/i) || 
  	navigator.userAgent.match(/iPad/i)) {
	iPodLabels.fix();
}

	 

});

//FIX DEFAULT LABEL FUNCTIONALITY IN MOBILE SAFARI
var iPodLabels = function () {

function fix() {
var labels = document.getElementsByTagName('label'),
target_id,
el;
for (var i = 0; labels[i]; i++) {
if (labels[i].getAttribute('for')) {
labels[i].onclick = labelClick;
}
}
};

function labelClick() {
el = document.getElementById(this.getAttribute('for'));
if (['radio', 'checkbox'].indexOf(el.getAttribute('type')) != -1) {
el.setAttribute('selected', !el.getAttribute('selected'));
} else {
el.focus();
}
};

return {
fix: fix
}

}();


function makeChart(theData)
{
	var theTotal = 0;
    var counter = 0;
    
    
    //CREATE HTML DIVS AND COUNT THE TOTAL VOTES
    $(theData).each(function(index){
    	$(".chart_bar_label_wrapper").append('<div class="chart_bar_label"></div>');
    	$(".chart_bar_wrapper").append('<div class="bar'+(index+1)+'"></div>');
    	theTotal += parseInt(theData[index][1]);
    });
    
   	
    while(theData.length > counter)
    {
        var theWidth = (parseInt(theData[counter][1]) / theTotal)*294;
        $(".chart_bar_label_wrapper div").eq(counter).html(theData[counter][0]);
        $(".chart_bar_wrapper div").eq(counter).width(theWidth);
		counter++;
	}
}


