function isEltChecked(eltSelector){
	if($(eltSelector).attr("checked") == true)
		return true;
	if($(eltSelector).attr("checked") == false)
		return false;
}

function conditionallyShow(eltSelector){

	if(!$(eltSelector).is(':visible')){
		$(eltSelector).show();
	}
}

function conditionallyHide(eltSelector){

	if(!$(eltSelector).is(':hidden')){
		$(eltSelector).hide();		
	}
}


$(document).ready(function(){
	// pre-loading functions
	if(isEltChecked('input[name="file_upload_resume_confirm"]')){
		$('#file-upload-box').show();
	}else{
		$('#file-upload-box').hide();
	}
	
	if(isEltChecked('input[name="simple_text_resume_confirm"]')){
		$('#text-upload-box').show();	
	}else{
		$('#text-upload-box').hide();	
	}
	//registered_with_ACP
	if(isEltChecked('#registered_with_ACP_yes')){
		$('#acp-elements-box').show();	
	}else{
		$('#acp-elements-box').hide();	
	}
	
	//has_H2S_ticket
	if(isEltChecked('#has_H2S_ticket_yes')){
		$('#H2S-elements-box').show();	
	}else{
		$('#H2S-elements-box').hide();	
	}
	
	//has_PST_ticket
	if(isEltChecked('#has_PST_ticket_yes')){
		$('#PST-elements-box').show();	
	}else{
		$('#PST-elements-box').hide();	
	}
	
	// has_drivers_license
	if(isEltChecked('#has_drivers_license_yes')){
		$('#DL-elements-box').show();	
	}else{
		$('#DL-elements-box').hide();	
	}
	// end pre-loading functions
			
	$('input[name="file_upload_resume_confirm"]').click(function() {
		//$('#file-upload-box').toggle();
		if(isEltChecked('input[name="file_upload_resume_confirm"]')){
			conditionallyShow('#file-upload-box');
		}else{
			conditionallyHide('#file-upload-box');
		}		
	});
	
	$('input[name="simple_text_resume_confirm"]').click(function() {
		if(isEltChecked('input[name="simple_text_resume_confirm"]')){
			conditionallyShow('#text-upload-box');
		}else{
			conditionallyHide('#text-upload-box');
		}
	});
	
	
	$('input[name="registered_with_ACP"]').click(function(){
		if(isEltChecked("#registered_with_ACP_yes")){
			conditionallyShow("#acp-elements-box");
		}
		if(isEltChecked("#registered_with_ACP_no")){
			conditionallyHide('#acp-elements-box');
		}		
	});
	$('input[name="has_H2S_ticket"]').click(function(){
		if(isEltChecked("#has_H2S_ticket_yes")){
			conditionallyShow("#H2S-elements-box");
		}
		if(isEltChecked("#has_H2S_ticket_no")){
			conditionallyHide('#H2S-elements-box');
		}		
	});	
	$('input[name="has_PST_ticket"]').click(function(){
		if(isEltChecked("#has_PST_ticket_yes")){
			conditionallyShow("#PST-elements-box");
		}
		if(isEltChecked("#has_PST_ticket_no")){
			conditionallyHide('#PST-elements-box');
		}	
	});
	$('input[name="has_drivers_license"]').click(function(){
		if(isEltChecked("#has_drivers_license_yes")){
			conditionallyShow("#DL-elements-box");
		}
		if(isEltChecked("#has_drivers_license_no")){
			conditionallyHide('#DL-elements-box');
		}		
	});	
	
	// Q tips
	$("#registered_with_ACP_yes").qtip({
		content: "If 'yes' is checked then: <strong>ACP Number</strong> will be required." ,
		style: {
			name: 'cream',
			tip: true,
			width: 350
		},
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: 'mouseover',
		hide: 'mouseout'	
	});
	$("#has_H2S_ticket_yes").qtip({
		content: "If 'yes' is checked then: <strong>H2S Alive number</strong> and <strong>H2S expiry date</strong> will be required." ,
		style: {
			name: 'cream',
			tip: true,
			width: 350
		},
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: 'mouseover',
		hide: 'mouseout'	
	
	});
	$("#has_PST_ticket_yes").qtip({
		content: "If 'yes' is checked  then: <strong>PST ticket number</strong> and <strong>PST expiry date</strong> will be required." ,
		style: {
			name: 'cream',
			tip: true,
			width: 350
		},
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: 'mouseover',
		hide: 'mouseout'	
	
	});
	$("#has_drivers_license_yes").qtip({
		content: "If 'yes' is checked then: <strong>Driver's license number</strong>, <strong>Driver's license class</strong> and <strong>Expiry date</strong> will be required." ,
		style: {
			name: 'cream',
			tip: true,
			width: 350
		},
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: 'mouseover',
		hide: 'mouseout'	
	
	});	
	$("#driver_license_class").qtip({
		content: "If 'Other' is selected then you must specify the <strong>driver's license class</strong> that you hold." ,
		style: {
			name: 'cream',
			tip: true,
			width: 350
		},
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: 'mouseover',
		hide: 'mouseout'	
	
	});						
});