/*******************************************************
CHANGE ACTIVE ID - PRIMARY NAVIGATION
********************************************************/
function showActive1(){
$(document).ready(function() { 
	$('#nav1').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showActive2(){
$(document).ready(function() { 
	$('#nav2').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showActive3(){
$(document).ready(function() { 
	$('#nav3').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showActive4(){
$(document).ready(function() { 
	$('#nav4').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showActive5(){
$(document).ready(function() { 
	$('#nav5').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function removeNav(){
$(document).ready(function() { 
	$('#nav5').fadeOut("medium");
	$('#nav4').addClass("Last").fadeIn("medium"); //Activate first tab		
	}); 
}
function addNav(){
$(document).ready(function() { 
	$('#nav5').fadeIn("medium");
	$('#nav4').removeClass("Last");  //Activate first tab		
	}); 
}

/*******************************************************
CHANGE ACTIVE ID - SECONDARY NAVIGATION
********************************************************/
function showSecondaryActive1(){
$(document).ready(function() { 
	$('#nav_2_1').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive2(){
$(document).ready(function() { 
	$('#nav_2_2').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive3(){
$(document).ready(function() { 
	$('#nav_2_3').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive4(){
$(document).ready(function() { 
	$('#nav_2_4').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive5(){
$(document).ready(function() { 
	$('#nav_2_5').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive6(){
$(document).ready(function() { 
	$('#nav_2_6').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive7(){
$(document).ready(function() { 
	$('#nav_2_7').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}
function showSecondaryActive8(){
$(document).ready(function() { 
	$('#nav_2_8').addClass("active").fadeIn("medium"); //Activate first tab	
	}); 
}


function showQuestionActive1(){
$(document).ready(function() { 
	$('#nav_q_1').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}
function showQuestionActive2(){
$(document).ready(function() { 
	$('#nav_q_2').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}
function showQuestionActive3(){
$(document).ready(function() { 
	$('#nav_q_3').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}
function showQuestionActive4(){
$(document).ready(function() { 
	$('#nav_q_4').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}
function showQuestionActive5(){
$(document).ready(function() { 
	$('#nav_q_5').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}
function showQuestionActive6(){
$(document).ready(function() { 
	$('#nav_q_6').addClass("active_questions").fadeIn("medium"); //Activate first tab	
	}); 
}

/*******************************************************
DROP DOWN MENU - HOLD PARENT ACTIVE CLASS
********************************************************/
  $(function() {
    //Preserves the mouse-over on top-level menu elements when hovering over children
    $("#nav_primary ul").each(function(i){
      $(this).hover(function(){
        $(this).parent().find("parentTXT").slice(0,1).addClass("active");
      },function(){
        $(this).parent().find("parentTXT").slice(0,1).removeClass("active");
      });
    });
  });

/*******************************************************
SELECTION LOGIC
********************************************************/
$(document).ready(function() {
  $.viewMap_1 = {
    '0' : $([]),
    'addInput_1' : $('#addInput_1'),
    'view2' : $('#view2a, #view2b'),
  };

  $('#optionSelect_1').change(function() {
    // hide all
    $.each($.viewMap_1, function() { this.fadeOut("fast"); });
    // show current
    $.viewMap_1[$(this).val()].fadeIn("fast");
  });
});

$(document).ready(function() {
  $.viewMap_2 = {
    '0' : $([]),
	'addInput_2' : $('#addInput_2'),
  };

  $('#optionSelect_2').change(function() {
    // hide all
    $.each($.viewMap_2, function() { this.fadeOut("fast"); });
    // show current
    $.viewMap_2[$(this).val()].fadeIn("fast");
  });
});


/*******************************************************
LOGIC - HIDE AND SHOW BASED ON SELECTIONS
********************************************************/
function Logic1(){
  switch (document.getElementById("Selection_Logic1").options[document.getElementById("Selection_Logic1").selectedIndex].value){
  case 'Default':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";	
	break;	  
  case 'Multiple':
 	document.getElementById('Question_Name_1').style.display="block";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";	
	break;	
  case 'Rating':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="block";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";	
	break;	
  case 'Text':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="block";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";
	break;	
  case 'Comment':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="block";
	document.getElementById('Question_Name_7').style.display="none";
	break;	
  case 'Number':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="block";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";	
	break;	
  case 'Date':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="block";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="none";
	break;	
  case 'Image':
 	document.getElementById('Question_Name_1').style.display="none";	 
	document.getElementById('Question_Name_2').style.display="none";	
	document.getElementById('Question_Name_3').style.display="none";
	document.getElementById('Question_Name_4').style.display="none";
	document.getElementById('Question_Name_5').style.display="none";
	document.getElementById('Question_Name_6').style.display="none";
	document.getElementById('Question_Name_7').style.display="block";
	break;		
  }
}


/*******************************************************
SKIP LOGIC
********************************************************/
$('.skip1').live('click',function(){
	$('#nextStandard').fadeOut("fast");
    $('#nextSkip1').fadeIn("fast");
	$('#nextSkip2').fadeOut("fast");	
	$('#nextSkip3').fadeOut("fast");	
	$('#nextSkip4').fadeOut("fast");	
	$('#nextSkip5').fadeOut("fast");				     
});
$('.skip2').live('click',function(){
    $('#nextStandard').fadeOut("fast");
    $('#nextSkip1').fadeOut("fast");
	$('#nextSkip2').fadeIn("fast");	
	$('#nextSkip3').fadeOut("fast");	
	$('#nextSkip4').fadeOut("fast");	
	$('#nextSkip5').fadeOut("fast");				     
});
$('.skip3').live('click',function(){
    $('#nextStandard').fadeOut("fast");
    $('#nextSkip1').fadeOut("fast");
	$('#nextSkip2').fadeOut("fast");	
	$('#nextSkip3').fadeIn("fast");	
	$('#nextSkip4').fadeOut("fast");	
	$('#nextSkip5').fadeOut("fast");				     
});
$('.skip4').live('click',function(){
    $('#nextStandard').fadeOut("fast");
    $('#nextSkip1').fadeOut("fast");
	$('#nextSkip2').fadeOut("fast");	
	$('#nextSkip3').fadeOut("fast");	
	$('#nextSkip4').fadeIn("fast");	
	$('#nextSkip5').fadeOut("fast");				     
});
$('.skip5').live('click',function(){
    $('#nextStandard').fadeOut("fast");
    $('#nextSkip1').fadeOut("fast");
	$('#nextSkip2').fadeOut("fast");	
	$('#nextSkip3').fadeOut("fast");	
	$('#nextSkip4').fadeOut("fast");	
	$('#nextSkip5').fadeIn("fast");				     
});

/*******************************************************
FORM LOGIC - HIDE AND SHOW BASED ON SELECTIONS
********************************************************/
$(function(){     
  $('.radioSelect_1').click(function(){
    if ($(this).attr("id") == "option_1")
    {
      $('#sub_1').fadeIn("fast");
      $('#sub_2').fadeOut("fast");
	  $('#sub_3').fadeOut("fast");
	  $('#sub_4').fadeOut("fast");
	  $('#sub_5').fadeOut("fast");
	  $('#sub_6').fadeOut("fast");
    } 
    else if ($(this).attr("id") == "option_2")
    {
      $('#sub_1').fadeOut("fast");
      $('#sub_2').fadeIn("fast");
	  $('#sub_3').fadeOut("fast");
	  $('#sub_4').fadeOut("fast");
	  $('#sub_5').fadeOut("fast");
	  $('#sub_6').fadeOut("fast");	  
    } 	
	else if ($(this).attr("id") == "option_3")
    {
      $('#sub_1').fadeOut("fast");
      $('#sub_2').fadeOut("fast");
	  $('#sub_3').fadeIn("fast");
	  $('#sub_4').fadeOut("fast");
	  $('#sub_5').fadeOut("fast");
	  $('#sub_6').fadeOut("fast");	  
    } 	
	else if ($(this).attr("id") == "option_4")
    {
      $('#sub_1').fadeOut("fast");
      $('#sub_2').fadeOut("fast");
	  $('#sub_3').fadeOut("fast");
	  $('#sub_4').fadeIn("fast");
	  $('#sub_5').fadeOut("fast");
	  $('#sub_6').fadeOut("fast");	  
    } 	
	else if ($(this).attr("id") == "option_5")
    {
      $('#sub_1').fadeOut("fast");
      $('#sub_2').fadeOut("fast");
	  $('#sub_3').fadeOut("fast");
	  $('#sub_4').fadeOut("fast");
	  $('#sub_5').fadeIn("fast");
	  $('#sub_6').fadeOut("fast");	  
    } 				
	else {
      $('#sub_1').fadeOut("fast");
      $('#sub_2').fadeOut("fast");
	  $('#sub_3').fadeOut("fast");
	  $('#sub_4').fadeOut("fast");
	  $('#sub_5').fadeOut("fast");
	  $('#sub_6').fadeIn("fast"); 
    }
    });
});


$(function(){     
  $('.radioSelect_2').click(function(){
    if ($(this).attr("id") == "sub_option_1")
    {
      $('#secondary_sub_1').fadeIn("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeOut("fast");
	  $('#secondary_sub_7').fadeOut("fast");	
    } 
    else if ($(this).attr("id") == "sub_option_2")
    {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeIn("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeOut("fast");	 
	  $('#secondary_sub_7').fadeOut("fast");	  
    } 	
	else if ($(this).attr("id") == "sub_option_3")
    {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeIn("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeOut("fast");	
	  $('#secondary_sub_7').fadeOut("fast");	  
    } 	
	else if ($(this).attr("id") == "sub_option_4")
    {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeIn("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeOut("fast");
	  $('#secondary_sub_7').fadeOut("fast");		  
    } 	
	else if ($(this).attr("id") == "sub_option_5")
    {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeIn("fast");
	  $('#secondary_sub_6').fadeOut("fast");	
	  $('#secondary_sub_7').fadeOut("fast");	  
    } 	
else if ($(this).attr("id") == "sub_option_6")
    {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeIn("fast");	
	  $('#secondary_sub_7').fadeOut("fast");	  
    } 					
	else {
      $('#secondary_sub_1').fadeOut("fast");
      $('#secondary_sub_2').fadeOut("fast");
	  $('#secondary_sub_3').fadeOut("fast");
	  $('#secondary_sub_4').fadeOut("fast");
	  $('#secondary_sub_5').fadeOut("fast");
	  $('#secondary_sub_6').fadeOut("fast"); 
	  $('#secondary_sub_7').fadeIn("fast");	
    }
    });
});

$('.checkShow_1').live('click',function(){
    if (this.checked)
    {
      $('#sub_1').fadeIn('medium');
    }
    else
    {
        if ( !$('.checkbox:checked').length )
        {
            $('#sub_1').fadeOut('medium');
			clearField();	
        }
    }
});

$('.checkShow_2').live('click',function(){
    if (this.checked)
    {
      $('#sub_2').fadeIn('medium');
    }
    else
    {
        if ( !$('.checkbox:checked').length )
        {
            $('#sub_2').fadeOut('medium');
			clearField();	
        }
    }
});

/*******************************************************
ADD and REMOVE INPUT BOXES
********************************************************/
$(function() {
	var i01 = $('.answersMC').size() + 1;
	var i02 = $('.careareas').size() + 1;
	var i03 = $('.deparments').size() + 1;
	
	$('#addCareAreas').click(function() {
		var numcareareas = $('input#mc_carearea').length + 1;
		$('<li class="careareas" id="ca_' + numcareareas +'"><input type="text" name="careareas_' + numcareareas + '" id="mc_carearea" value="" class="Large" /><label class="iconButton"><a class="deleteCAs icon Delete" id="deleteCAs">-</a></label></li>').fadeIn("fast").appendTo('#caInputs');
		$('#deleteCALabel').fadeIn("fast");
	});
	
	// $('#addDepartments').click(function() {
	// 	var numdepartments = $('input#mc_department').length + 1;
	// 	$('<li class="deparments" id="d_' + numdepartments +'"><input type="text" name="department_' + numdepartments + '" id="mc_department" value="" class="Large" /> <input type="text" name="deparmenthead_last_name" class="Medium" /> <input type="text" name="department" class="Medium" /> <label class="iconButton"><a class="deleteDepartments icon Delete" id="deleteDepartments">-</a></label></li>').fadeIn("fast").appendTo('#deptInputs');
	// 	$('#deleteDeptLabel').fadeIn("fast");
	// });
	// 
	// $('#addDepartmentHeads').click(function() {
	// 	var numdepartments = $('input#mc_department').length + 1;
	// 	$('<li class="deparments" id="d_' + numdepartments +'"><input type="text" name="department_' + numdepartments + '" id="mc_department" value="" class="Medium" /> <input type="text" name="deparmenthead_last_name" class="Medium" /> <input type="text" name="department" class="Medium" /> <label class="iconButton"><a class="deleteDepartments icon Delete" id="deleteDepartments">-</a></label></li>').fadeIn("fast").appendTo('#deptInputs');
	// 	$('#deleteDeptLabel').fadeIn("fast");
	// });
	
	
	$('#addQuestions').click(function() {
		var numanswers = $('input#mc_answer').length + 1;
		$('<span class="answersMC" id="question_' + numanswers +'"><input id="mc_answer" name="a_' + numanswers + '" class="extraLarge FloatLeft extraMargin"/><input name="sl_' + numanswers + '" class="SmallSkip default_value" value="Next" maxlength="3"/></span>').animate({ opacity: "show" }, "medium").appendTo('#surveyQuestions');
	});
	
	$('#removeQuestions').click(function() {
		var numanswers = $('input#mc_answer').length;
		var theid = '#question_' + numanswers
		if(numanswers > 1) {
			$(theid).animate({opacity:"hide"}, "medium").remove();
		}
	});
	
	
});


function showHideAnswer()
{
	var numericID = this.id.replace(/[^\d]/g,'');
	var obj = document.getElementById('a' + numericID);
	if(obj.style.display=='block'){
		obj.style.display='none';
	}else{
		obj.style.display='block';
	}		
}
function initShowHideContent()
{
	var divs = document.getElementsByTagName('DIV');
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='question'){
			divs[no].onclick = showHideAnswer;
		}			
	}	
}
window.onmousemove =initShowHideContent();


/*******************************************************
CALENDAR
********************************************************/
// jQuery(document).ready(function () {
// 	$('input.Date').simpleDatepicker();
// 	$('input.employee_status_2_date_start').simpleDatepicker();	
// 	$('input.employee_status_2_date_end').simpleDatepicker();		
// });

/*******************************************************
SEARCH BOX - SUBMIT ON ENTER 
********************************************************/
    function submitenter(myfield,e)
    {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

        if (keycode == 13) 
        {
            location.href = 'find_1.html';
            return false;
        }
        else
            return true;
    }



/*******************************************************
COMPACT FORM - DEFAULT TEXT VALUES - SCRIPT
********************************************************/
var active_color = '#2d2d2d'; // Colour of user provided text
var inactive_color = '#a0a0a0'; // Colour of default text

jQuery(document).ready(function() {
  jQuery("input.default_value").css("color", inactive_color);
  var default_values = new Array();
  jQuery("input.default_value").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    jQuery(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
});

jQuery(document).ready(function() {
  jQuery("input.default_value_2").css("color", inactive_color);
  var default_value_2 = new Array();
  jQuery("input.default_value_2").focus(function() {
    if (!default_value_2[this.id]) {
      default_value_2[this.id] = this.value;
    }
    if (this.value == default_value_2[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    jQuery(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_value_2[this.id];
      }
    });
  });
});


/*******************************************************
TOOLTIP
********************************************************/
$(document).ready(function() {

	//Select all anchor tag with rel set to tooltip
	$('li[class=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipBody">' + tip + '</div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('medium');
		//For Opacity $('#tooltip').fadeTo('10',0.9);
		
	})
	.mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
 		$('#tooltip').css('top', e.pageY + 25 );
		$('#tooltip').css('left', e.pageX - 50 );
		
	})
	.mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
		
	});

});
