var pageUrl = new Array();
pageUrl[0] = "application_t0.html";
pageUrl[1] = "application_t1.html";
pageUrl[2] = "application_t2.php";
pageUrl[3] = "application_t3.html";
pageUrl[4] = "application_t4.html";
pageUrl[5] = "application_t5.html";
$(document).ready(function(){
    $("#preloader").hide();
	
	$("#tab0").click(function(){
        loadTab(0);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
    $("#tab1").click(function(){
        loadTab(1);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $("#tab2").click(function(){
        loadTab(2);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $("#tab3").click(function(){
        loadTab(3);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $("#tab4").click(function(){
        loadTab(4);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
	$("#tab5").click(function(){
        loadTab(5);
		$(".tabHead").removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	//is sbes form
	try{
		if(sbes){
			howManyFunc();
			if($("#blahblah").length != 0){
				$("#blahblah").attr('value','TlC!256532');
			}
		}
	}catch(e){
		
	}
	
	//is benefits form
	try{
		if(benefits){
			memBenefits();
		}
	}catch(e){
		
	}
	
});


function loadTab(id){
    if (pageUrl[id].length > 0) {
        $("#preloader").show();
        
        if(id != 2){
	        $.ajax({
	            url: pageUrl[id],
	            cache: false,
	            success: function(message){
	                $("#tabcontent").empty().append(message);
	                $("#preloader").hide();
	    			if($("#blahblah").length != 0){
	    				$("#blahblah").attr('value','TlC!256532');
	    			}
	            }
	        });
        }
        else if (id == 2){
        	
	        $.ajax({
	            url: pageUrl[id],
	            cache: false,
	            success: function(message){

	            	headerbox = '<div id="boxwithcontent"><div style="width: 715px; height: 100px;"><div style="float: left"><img src="images/tlclogo.jpg" /></div><div style="float: right; margin-right: 50px;"><img height="90" src="images/summit_uscc_logo.JPG" /></div></div><div style="width: 715px; height: 100px;"><div style="float: left"></div><div style="float: right; width: 300px; margin-right: 50px; margin-top: 10px; text-align: right;"><a href="http://www.uschambersummit.com/agenda" target="_blank">Click Here</a> to view the latest agenda for the<br /> America’s Small Business Summit 2012</div></div></div>';	            	
	            	
	            	result = $(message).find('#post-61').find('table').css('background-color','red');
	            	
	                $("#tabcontent").empty().append(headerbox + '<table>' + result.html() + '</table>');
	                $("#preloader").hide();
	    			if($("#blahblah").length != 0){
	    				$("#blahblah").attr('value','TlC!256532');
	    			}
	            }
	        });
        }
    
    }
}

/*SBES Form*/
function sbesOpts(){
	var isCertified=$("#cert-opt #certified:checked").val();
	if(isCertified !='Yes'){
		$("#sbes-bmm-opt").hide();		
	}else{
		$("#sbes-bmm-opt").show();
	}
}

function howManyFunc(){
	var isMore=$("#moreReg:checked").val();
	var howMany=0;
	if(isMore !='Yes'){
		$("#howManyDiv").hide();
		$(".participant").hide();
	}else{
		$("#howManyDiv").show();
		howMany=$("#howmany").val();
	}
		
	$(".participant").hide();
	for(i=0; i<=howMany;i++){
		var part='#participant'+i;
		$(part).show();
	}
	
}

/*Membership Benefits*/
function memBenefits(){
	$("#benefits").height($("#benefitsList").height());
	$("#benefitsList ul li a").fadeTo("fast", 0.5);
	$("#benefitsList ul li a").hover(function(){
		$(this).stop(true,true).fadeTo("normal", 1);
	}, function(){
		if(!$(this).hasClass("benefitsActive")){
			$(this).stop(true,true).fadeTo("normal", 0.5);
		}else{
			$(this).stop(true,true).fadeTo("normal", 1);
		}
	});
	
	$("#benefitsList ul li a").click(function(){
		var bname="#"+$(this).attr("id")+"Detail";
		$(".benefitDetail").hide();
		$(bname).slideDown();
		
		$("#benefitsList ul li a").removeClass("benefitsActive");
		$("#benefitsList ul li a").fadeTo("fast", 0.5);
		$(this).fadeTo("fast", 1);;
		$(this).addClass("benefitsActive");
	});
}
