function pass_type(typ){
	jQuery.testing._show_quest_input(typ);	
}

function pass_num_ans(ans){
	jQuery.testing._show_ans_input(ans);	
}

function pass_question_op(val,ids){
    jQuery.testing._change_question_stat(val,ids);
}

function pass_answer_op(val,ids,anid){
    jQuery.testing._change_answer_stat(val,ids,anid);
}

jQuery.testing = {	
	question_frequency: function() {		
		var number_question = jQuery('#number_question').val();		
		jQuery.testing._show_select_type(number_question);	
		
	},
	_show_select_type: function(frequency){
		jQuery('#question_type').html('');
		var typ = '';
		for (i=1;i<=frequency;i++){
			typ += 'Type of Question '+i+': <select id="test'+ i +'" name="type['+ i +']" onchange="pass_type('+i+')">' +
					'<option value="" selected="true"></option>' +
			       	'<option value="one_line">1 line answer</option>' +
			       	'<option value="essay">essay</option>' +
			       	'<option value="radio_question">radio question</option>' +
			       	'<option value="drop_down">drop down menu</option>' +
				   	'</select><br/><div id="questions'+i+'"></div><br/><br/>\n\n'; 				      			   	
		}			
		jQuery('#question_type').html(typ);			
	},
	_show_quest_input: function(i){
		
		var quest = "";
		var ferqs = "";
		var quest_type = jQuery('#test'+i).val();
		
		for(a=1;a<=31;a++){ 	
			ferqs += '<option value="'+a+'">'+a+'</option>'; 
        } 	
      
		jQuery('#questions'+i).html('');
		quest = "Question: <textarea name='question["+i+"]' cols='20' rows='5'></textarea><br/>\n";
		if (quest_type == "radio_question" || quest_type == "drop_down") {		
			quest += 'How many possible answers would you like for this question<select id="number_answer'+i+'" name="number_answer['+i+']" onchange="pass_num_ans('+i+')">' +
					 '<option value="0" selected="true">0</option>' + 
					  ferqs + '</select><div id="answers'+i+'"></div><br/><br/>\n\n';        	
		}
		jQuery('#questions'+i).html(quest);
		
	},
	_show_ans_input: function(ans){
		var ans_freq = jQuery('#number_answer'+ans).val();
		var answ = "";
		jQuery('#answers'+ans).html('');
		for(c=1;c<=ans_freq;c++){
			answ += "Answer: <input type='text' name='answer["+ans+"]["+c+"]'/><br/>\n";			
		}
		jQuery('#answers'+ans).html(answ);
	},
    _change_question_stat: function(val,ids){
    /*
        alert(val);
        alert(ids);
      */
        if(val=="edit_grammar"){
            $('#question'+ids).removeAttr("readonly");
        }else if(val=="as_is"){           
            $('#question'+ids).attr("readonly", true);
        }else if(val=="delete"){
            $('#question'+ids).attr("readonly", true); 
            var con = confirm("Are you sure you want to delete this Question?");
            if(!con){
                $('#quest'+ids).attr("checked", true);   
            }
        }
        
    },
    _change_answer_stat: function(val,ids,anid){
        if(val=="edit_grammar"){
            $('#answer'+ids+anid).removeAttr("readonly");
        }else{           
            $('#answer'+ids+anid).attr("readonly", true);
        }      
    }    	
};