/*
The following file contains functions to create custom checkboxes and radio buttons
*/

/*
Note: check_value is an optional parameter in case you wanted a custom value when the checkbox is checked instead of having 1
      isgreen is optional by default this is false
	  imagelocation is optional if it is undefined we take the image from the babyclub
*/

function swapCheckBox(img_id,text_box_id,check_value,isgreen,link_prefix)
{
	if(check_value === undefined)
	{
		check_value = "1"
		
	}
	
	if(isgreen == undefined)
	{
		isgreen="false"
	
	}
	if(link_prefix == undefined)
	{
		link_prefix = "/en_ca/babyclub/images/"
	}
	
	
	image_name_on = "checkbox_form_on.gif";
	image_name_off = "checkbox_form_off.gif";
	
	if(isgreen == "true")
	{
		image_name_on = "checkbox_green_on.gif";
	    image_name_off = "checkbox_green_off.gif";
	}
	
	
	
	img_src_value = $("#" + img_id).attr("src")
	
	
	
	if(img_src_value.indexOf(image_name_off) != -1)
	{
		$("#" + img_id).attr("src",link_prefix + image_name_on )
		
		$("#" + text_box_id).attr("value",check_value) 
	}
	
	//otherwise if it is checked we set the check box to off
	else
	{
		$("#" + img_id).attr("src", link_prefix + image_name_off) 
		
		$("#" + text_box_id).attr("value","")
	}
}

function swapRadio(img_id_prefix,text_box_id,num_radio,selected_num,selected_value,isSurvey)
{
	/*
	The following function swaps all the radio buttons in the group to the off image then swithces the selected one to the on position and sets the text box value
	
	naming convention for radio image id : img_id_prefix_ count 
	
	example (2 radio buttons for language):
	
	gender_image_0    
	gender_image_2  
	
	(text_box) gender_text_box
	
	if male is selected you call the function like this swapRadio("gender_image","gender_text_box","2","0","m")
	
	
	*/
	radio_img_off = "/en_ca/babyclub/images/radiobt_form_off.gif"
	radio_img_on = "/en_ca/babyclub/images/radiobt_form_on.gif"
	
	if(isSurvey == "true")
	{
		radio_img_off = "/en_ca/babyclub/images/radiobt_survey_off.gif"
		radio_img_on = "/en_ca/babyclub/images/radiobt_survey_on.gif"
	}
	
	//switching all the radio images to the off position
	for(i=0; i < num_radio;i++)
	{
		current_radio_image_id = "#" + img_id_prefix + "_" + i
		
		
		
		$(current_radio_image_id).attr("src",radio_img_off)
		
		
	}
	
	//switching the selected radio image to the on position and updating the text box
	selected_radio_image_id = "#" + img_id_prefix + "_" + selected_num
	
		
	$(selected_radio_image_id).attr("src",radio_img_on)
	
	
	$("#" + text_box_id).attr("value",selected_value)
	
	
	
}