var jsonUrl;
var cdcont = "";
$(function() {
		
	var fullURL = window.document.URL;
	var queryString = fullURL.substring(fullURL.indexOf('?'), fullURL.length);
		
	//jsonUrl = '/web/open/appsCmsChapterDetailsJson'+queryString;
	jsonUrl = '/web/open/appsCmsChapterDetailsNewJson'+queryString;
	
	$.getJSON(jsonUrl, function(data) {

		cdcont = cdcont + '<div class="leftcol">';
		
		cdcont = cdcont + '<div class="rowchaptername">';		
		cdcont = cdcont + '<img alt="BNI Chapter : '+data.chapterName+'" src="images/bni.jpg" />';
		cdcont = cdcont + '<h1>'+data.chapterName+'</h1>';
		cdcont = cdcont + '</div>';

		cdcont = cdcont + '<h1>'+data.chapterMeetingInformationHeading+'</h1>';
		cdcont = cdcont + '<p>'+data.chapterMeetingDay+' '+data.chapterMeetingTime+'</p>';
		
		cdcont = cdcont + '<p><strong>'+data.chapterMeetingLocationName+'</strong><br/>';
		cdcont = cdcont + data.chapterMeetingLocationAddress+'</p>';
		
		if(data.chapterMeetingLocationPhone != "")
		{
			cdcont = cdcont + '<p><strong>'+data.chapterMeetingLocationPhoneText+'</strong>: ';
			cdcont = cdcont + data.chapterMeetingLocationPhone+'</p>';
		}
		
		if(data.chapterMeetingLocationDirection != "")
		{
			cdcont = cdcont + '<p class="nogapbottom"><strong>'+data.chapterMeetingLocationDirectionHeading+'</strong><br/>';
			cdcont = cdcont + data.chapterMeetingLocationDirection+'</p>';
		}
		
		if(data.chapterMeetingLocationMapUrl != "")
		{ cdcont = cdcont + '<p class="nogaptop"><a href="'+data.chapterMeetingLocationMapUrl+'" id="vieMapLink" target="_blank">'+data.chapterMeetingLocationMap+'</a></p>'; }
		
		cdcont = cdcont + '<h2>'+data.chapterMemberCountHeading+': <span>'+data.chapterMemberCount+'</span>';
		if(data.chapterMemberCount > 0)
		{ cdcont = cdcont + ' <a href="memberlist.html?chapterName='+data.chapterId+'" id="showMembers">'+data.chapterShowMembersText+'</a>'; }
		
		cdcont = cdcont + '</h2></div>';
		

		if(data.chapterLeadershipSub.length > 0)
		{
			cdcont = cdcont + '<div class="rightcol">';
			cdcont = cdcont + '<h1>'+data.chapterLeadershipHeading+'</h1>';
			cdcont = cdcont + '<div class="roleslist">';
			
			$.each(data.chapterLeadershipSub, function(i,item){	
				cdcont = cdcont + '<p>'+item.role;
				cdcont = cdcont + '<span><strong>'+item.name+'</strong>';
				if (item.phone !="") {
					cdcont = cdcont + data.chapterMeetingLocationPhoneText+': '+item.phone;
				}
				cdcont = cdcont + '</span>';
				
				if(item.sendMessage) 
				{ cdcont = cdcont + '<a href="sendmessage.html?userId='+item.userId+'&userName='+item.name+'">'+data.chapterSendMessageText+'</a>'; }
				cdcont = cdcont + '</p>';
			});
			
			cdcont = cdcont + '</div></div>';
		
		}
		
		cdcont = cdcont + '<div class="clearboth"></div>';

		$("#chapterDetailNew").html(cdcont);

	});
	
	
});
