//Search Functions

function clearSearch() {
	jQuery('#sitesearch').css("color", "#000");
	if ($F('sitesearch') == "Search") {
		$('sitesearch').value = "";
	}
}
function resetSearch() {
	$('sitesearch').style.color="#666";
	if ($F('sitesearch') == "") {
		$('sitesearch').value = "Search";
	}
}


jQuery(document).ready(function() {

	jQuery('#tabbed-content > ul').tabs({
	    fxFade: true,
	    fxSpeed: 'fast',
	    fxAutoHeight: true,
	    selected: 1
	});
	// Hiding and showing items
	jQuery(".hider").css("display", "none");
	jQuery(".list-item").css("cursor", "pointer");

	jQuery(".list-item").click(function() {
		jQuery(this).children().children(".hider").slideToggle();
	});

	jQuery(".list-link").click(function(){
		$location=jQuery(this).find("a").attr("href"); 
		window.open($location, 'btisystems-opened');
		return false;
	});

	jQuery('#hubspot-submit').click(function(){

	});	

	jQuery("#hubspot-form").submit(function(event) {
		event.preventDefault();
		
		var ErrorCount		= 0;
		var formName 		= jQuery('input[name=formName]');
		var FirstName		= jQuery('input[name=FirstName]');
		var LastName		= jQuery('input[name=LastName]');
		var Email 		= jQuery('input[name=Email]');
		var Company		= jQuery('input[name=Company]');
		var Phone		= jQuery('input[name=Phone]');
		var City 		= jQuery('input[name=City]');
		var Code		= jQuery('input[name=Code]');
		var Type		= jQuery('select[name=Type]');
		var Protocol		= jQuery('input[name=Protocol]');
		var Message		= jQuery('textarea[name=Message]');
		var MessageValue 	= ' ';
		
		if (FirstName.val()=='') {
			FirstName.addClass('missing');
			ErrorCount++; 
		} else FirstName.removeClass('missing');

		if (LastName.val()=='') {
			LastName.addClass('missing');
			ErrorCount++; 
		} else LastName.removeClass('missing');

		if (Email.val()=='') {
			Email.addClass('missing');
			ErrorCount++; 
		} else Email.removeClass('missing');

		if (!checkEmail(Email.val())) {
			Email.parent().addClass('valid');
			ErrorCount++; 
		} else Email.removeClass('valid');
		
		/* Stop on Errors */
		if ( ErrorCount > 0 ) {
			return false;
		}

		if (formName.val()=='Managed-Network-Service-Locator') {
			MessageValue = "Product Type: " + Type.val() + "\r\nProtocols Supported: " + Protocol.val() + "\r\nMessage: \n" + Message.val();		
		};

		if (MessageValue==' ') {
			MessageValue= Message.val();
		};	
		
		var data = 'form=' + formName.val() 
			+ '&FirstName=' + FirstName.val() 
			+ '&LastName=' + LastName.val() 
			+ '&Email=' + Email.val() 
			+ '&Company='  + Company.val() 
			+ '&Phone='  + Phone.val() 
			+ '&City=' + City.val()
			+ '&ZipCode=' + Code.val()
			+ '&Message=' + MessageValue
			;
			//alert(data);
		jQuery.ajax({
			//this is the php file that processes the data and send mail
			url: "/_include/php/form.php",	
			//GET method is used
			type: "GET",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function(html) {				
				//if process.php returned 1/true (send mail success)
				if (html==1) {					
					window.location = document.location.href + "?user=" + Email.val() + "&ts=194885";
					
				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');				
			}		
		});
		_gaq.push(['_trackEvent', 'Landing-Page', 'To Lead', jQuery("h1").html() ]);
		//cancel the submit button default behaviours
		return false;
		});

	jQuery(".list-item").hover(
  		function () {
			jQuery(this).css("background-color", "#eee");
  		},
  		function () {
			jQuery(this).css("background-color", "inherit");
		}
	);

	if (jQuery("#productshowcase_product1").length != 0) {
		productswitch("#productshowcase_product1", "#productshowcase_nav1");
	};


});
	function togglehider(element) {
	};

	function productswitch($selected, $nav) {
		jQuery(".productshowcase_product").css("display", "none");
		jQuery("#productshowcase_nav a").removeClass("active");

		jQuery($selected).css("display", "block");
		jQuery($nav).addClass("active");
	};

