$(document).ready(function() {

   $(".noneoftheabove").click(function() {
                $(".notnoneoftheabove").attr('checked',false);
   });
   $(".notnoneoftheabove").click(function() {
                $(".noneoftheabove").attr('checked',false);
   });

    // next button hover effect
    //$("div.next input").hover(
    //    function() {$(this).attr("src","img/next_on.gif"); }, // over
    //    function() {$(this).attr("src","img/next.gif");}      // out
    //);
    
    // start survey hover effect
    $("div.start input").hover(
        function() {$(this).attr("src","img/start_on.gif");}, // over
        function() {$(this).attr("src","img/start.gif");}      // out
    )
    
    // something vs nothing checkboxes (none of the above)
    $('td.something').click(function() { 
        $('td.nothing input').attr('checked',''); 
        $('td.nothing input').closest('tr').removeClass('AnsSelected');
    });
    $('td.nothing').click(function() { 
        $('td.something input').attr('checked',''); 
        $('td.something input').closest('tr').removeClass('AnsSelected');
    });
    
       // x5b highlighting 
   $("td.clickable").click( function() {
        $(this).parent('tr').children('td').removeClass('RadioH');
        $(this).children('input').attr('checked',true);
        $(this).addClass('RadioH');
        $(this).parent('tr').addClass('Marked');
    });
    $('input:checked').parent('td.XBRadio').addClass('RadioH');
	$(window).unload( function () {} );    
    
	// MD highlighting
   $("#MaxDiff td.clickableMD").click( function() {
      $(this).parent('tr.MDRow').children('td.MDRadio').removeClass('MDRadioH');
      ($(this).hasClass('max')) ? $('td.max').removeClass('MDRadioH'): $('td.min').removeClass('MDRadioH');
      $(this).children('input').attr('checked',true);
      $(this).addClass('MDRadioH');
   });
   
   $(".dataCHANGE").animate({
       backgroundColor: "#FEFF5F"
   },1000);
   
    $("input.Points").change(function() {
        var tot = 0;
        $("input.Points").each(function(i) { 
            tot += (jQuery.trim($(this).val()) == "" || isNaN(jQuery.trim($(this).val()))) ? 0 : parseFloat($(this).val()); });
            $("#Total").val(tot);
        }); // each
    $("#container").mousemove(function() { $("input.Points").change(); });
         
    $(".ClearText").click( function() {
        $(".ClearRadios").val("");
    });
    
    $(".ClearRadios").keypress(function(){$(".ClearText").attr("checked","");});
    $(".ClearRadios").click(function(){$(".ClearText").attr("checked","");});
   
    // |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
    //OnPageErr();
    // |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
   
});   // ready

// Clears all checkboxes on the page, except for the calling element. Useful for "None of the above" type answers.
//	Usage: 	<input type="checkbox" id="checkbox42" name="foo42" value="1" onclick="ClearAll(checkbox42, this.form);">
//				Clears all checkboxes on the form, except for id="checkbox42"
function ClearAll(me, form){
	if( me.checked == true )
		for(i = 0; i < form.elements.length; i++)
			if(form.elements[i].type == "checkbox" && form.elements[i].name != me.name)
				form.elements[i].checked = false;
}

// Clears one checkbox.  Useful for clearing out the "None..." answer when selecting something else.
// Usage: 	<input type="checkbox" id="checkbox1" name="foo1" value="1" onclick="ClearOne(checkbox42);">
//				Clears id="checkbox42"
function ClearOne(control){
   control.checked = false;    // the 'None' control
}

function ClearOne2(control){
   document.getElementById('checkbox' + control).checked = false;
   document.getElementById('td' + control).style.backgroundColor = "";
}


// Clears a range of checkboxes.  Useful when you need to clear a few checkboxes, but not all of them!
// Usage: 	<input type="checkbox" id="checkbox1" name="foo1" value="1" onclick="ClearRange(2, 10);">
//				Clears id="checkbox2", id="checkbox3" ... id="checkbox9", id="checkbox10"
function ClearRange(row, start, end){
	var foo;
	for(i = start; i <= end; i++) {
		foo = 'checkbox1_' + row + '_' + i;
		document.getElementById(foo).checked = false;
	} //for
}

function ClearRange2(row, start, end){
	var foo;
   var bar;
	for(i = start; i <= end; i++) {
		foo = 'checkbox1_' + row + '_' + i;
      bar = 'td1_' + row + '_' + i;
		document.getElementById(foo).checked = false;
      document.getElementById(bar).style.backgroundColor = "";
	} //for
}

// Clears the contents of one textbox.  When clearing out a series of radios/checks, clear out the textbox
// attached to the "other"" response as well.
// Usage: 	<input type="checkbox" id="checkbox1" name="foo1" value="1" onclick="ClearAll(checkbox42, this.form); ClearText('text2');">
//				Clears all checkboxes on the page, and the textbox with id="text2"

function ClearText(control){
	document.getElementById(control).value = '';    // the 'None' control
}

// toggle TD highlights for Radio button grids
function ToggleTDHighlight(qNum,row, me) {
	var i
   for (i = 1; document.getElementById('td'+qNum+'_'+row+'_'+i); i++)
	   document.getElementById('td'+qNum+'_'+row+'_'+i).style.backgroundColor = "";
	document.getElementById('td'+qNum+'_'+row+'_'+me).style.background = "#9BB9CF";
	document.getElementById('radio'+qNum+'_'+row+'_'+me).checked = true;
}

// toggle TD highlights for checkbox grids
function ToggleTDHighlightC(qNum,row, me) {
	var i
	if (document.getElementById('checkbox'+qNum+'_'+row+'_'+me).checked == false) {
    	document.getElementById('td'+qNum+'_'+row+'_'+me).style.background = "#9BB9CF";
		document.getElementById('checkbox'+qNum+'_'+row+'_'+me).checked = true;
   } //if
   else {
      document.getElementById('td'+qNum+'_'+row+'_'+me).style.backgroundColor = "";
      document.getElementById('checkbox'+qNum+'_'+row+'_'+me).checked = false;
	} //else
   
}

//onload highlight the right boxes
function ReHighlightTDs(numQs) {
	var i, j, k
	i = 1;
	j = 1;
	k = 1;
	q = 1;	// for the question number!
	for(q=1; q<=numQs; q++) {	// loop through the number of questions..., provided in the body tag of the page
		if (document.getElementById('td'+q+'_'+i+'_'+j)) { 
			for(k = q; document.getElementById('td'+k+'_'+i+'_'+j); k++) {
				for(i = 1; document.getElementById('td'+k+'_'+i+'_'+j); i++) {
					for(j = 1; document.getElementById('td'+k+'_'+i+'_'+j); j++) {
						if (document.getElementById('radio'+k+'_'+i+'_'+j)) {
							if (document.getElementById('radio'+k+'_'+i+'_'+j).checked == true)
								document.getElementById('td'+k+'_'+i+'_'+j).style.backgroundColor="#9BB9CF";
						} //if
						else {
							if (document.getElementById('checkbox'+k+'_'+i+'_'+j).checked == true)
								document.getElementById('td'+k+'_'+i+'_'+j).style.backgroundColor="#9BB9CF";
						} //else
					}	//for
					j = 1
				} //for
				i = 1
			} //for k
		} //if
	} //for q
} // function
