function depReq()
{document.getElementById("selectDepReq").style.display="block";}

function depReqOut()
{document.getElementById("selectDepReq").style.display="none";}

	$(function(){
		$('#selectDep').change(function(e){ 
			$('.formContainer').hide();
			$('#CSliveChatOff').hide();
			$('#' + this.value).show();
			if(this.value == "chatCustServRep"  && CSHoursFlag != true){
				$('#CSliveChatOff').show();
			    $('#chatCustServRep').hide();
			}
			if(this.value == "chatSalesRep"  && CSHoursFlag != true){
				$('#CSliveChatOff').hide();
			    $('#chatSalesRep').show();
			}
			if(this.value == "chatProductPro"  && CSHoursFlag != true){
				$('#CSliveChatOff').hide();
			    $('#chatProductPro').show();
			}
			if(this.value == "chatUsed"){	
				// grey out the form
				
				var salesOptions = '<option value="" selected="selected">Select</option><option value="24520">Used Audio Sales</option><option value="24523">Used Lighting Sales</option><option value="24522">Used Photography Sales</option><option value="24521">Used Video Sales</option>'
 				var csOptions = '<option value="" selected="selected">Select</option><option value="24524">Used Returns &amp; Exchanges</option><option value="24525">Used - Other Issues</option>'
				
				$('.usedOptions').show();
				$("table").addClass("dummyForm");
				$("button").attr('disabled', 'disabled');
				// check what value of secondary select is
				$(".usedOptions select").change(function(){	
					// if val is default									 
					if($(".usedOptions select").val() == "Select"){ 
						$("table").addClass("dummyForm");
						$("button").attr('disabled', 'disabled');}	
					// if val is sales									 
					if($(".usedOptions select").val() == "Sales"){ 
						$("table").removeClass("dummyForm");
						$("button").removeAttr('disabled');
						$('#chatUsed').show();
						$('#CSliveChatOff').hide();
						$("select.used_select").empty(); $("select.used_select").append(salesOptions);
					}
					// if val is Customer Service		
					if($(".usedOptions select").val() == "Customer Service"){
						$("table").removeClass("dummyForm");
						$("button").removeAttr('disabled');
						$("select.used_select").empty(); $("select.used_select").append(csOptions);
							// if Customer Service and it's after customer service hours
							if(usedCSon != true){
								$('#CSliveChatOff').show();
								$('#chatUsed').hide();}
					}
				});
			}
			if ($(this).val() !== "chatUsed"){
				$("table").removeClass("dummyForm");
				$("button").removeAttr('disabled');
				$('.usedOptions').hide();
			}
		});
	});
	
	function checksfg(valid) {
		$("form").submit(function(){
			return valid;
		});
	}
	
	$(function(){
		$("button").mouseenter(function (){
				$("img.chatNowBtn").attr('src','/images/liveChat/chatNowBtn_o.jpg');
		});
		$("button").mouseleave(function (){
				$("img.chatNowBtn").attr('src','/images/liveChat/chatNowBtn.jpg');
		});
	});

 function testResultsSR()
	{
	var mytopic = document.chat_form_sales_rep.di.value;
	var mycustomername = document.chat_form_sales_rep.fname.value;
	var test = mycustomername.match(/^\s*$/);
	if(test != null)
	mycustomername = "";
		 
	if (mytopic != "" && mycustomername != "")
			{
				return;
			}
	else if (mytopic != "" && mycustomername == "")
			{
				alert('Please enter a name');
				return false;
			}
	else if (mytopic == "" && mycustomername != "")
			{
				alert('Please select a topic');
				return false;
			}
	else if (mytopic == "" && mycustomername == "")
			{
				alert('Please enter a name and select a topic.');
				return false;
			}
	}
		
function testResultsCS()
	{
	var mytopic = document.chat_form_cust_serv.optionaldata3.value;
	var mycustomername = document.chat_form_cust_serv.fname.value;
	var test = mycustomername.match(/^\s*$/);
	if(test != null)
	mycustomername = "";
	
	if (mytopic != "" && mycustomername != "")
			{
				return;
			}
	else if (mytopic != "" && mycustomername == "")
			{
				alert('Please enter a name');
				return false;
			}
	else if (mytopic == "" && mycustomername != "")
			{
				alert('Please select a topic');
				return false;
			}
	else if (mytopic == "" && mycustomername == "")
			{
				alert('Please enter a name and select a topic.');
				return false;
			}
	}

function testResultsPP()
	{
	var mytopic = document.chat_form_product_pro.di.value;
	var mycustomername = document.chat_form_product_pro.fname.value;
	var test = mycustomername.match(/^\s*$/);
	if(test != null)
	mycustomername = "";
	
	if (mytopic != "" && mycustomername != "")
			{
				return;
			}
	else if (mytopic != "" && mycustomername == "")
			{
				alert('Please enter a name');
				return false;
			}
	else if (mytopic == "" && mycustomername != "")
			{
				alert('Please select a topic');
				return false;
			}
	else if (mytopic == "" && mycustomername == "")
			{
				alert('Please enter a name and select a topic.');
				return false;
			}
	}

function testResultsUsed()
	{
	var mytopic = document.chat_form_Used.di.value;
	var mycustomername = document.chat_form_Used.fname.value;
	var test = mycustomername.match(/^\s*$/);
	if(test != null)
	mycustomername = "";
	
	if (mytopic != "" && mycustomername != "")
			{
				return;
			}
	else if (mytopic != "" && mycustomername == "")
			{
				alert('Please enter a name');
				return false;
			}
	else if (mytopic == "" && mycustomername != "")
			{
				alert('Please select a topic');
				return false;
			}
	else if (mytopic == "" && mycustomername == "")
			{
				alert('Please enter a name and select a topic.');
				return false;
			}
	}

function gotoPage(someURL) {
    opener.location.href = someURL;
	window.location.href = "/BHPopUp.html"
    window.close(self);
}
