//******************************************** VARIABLES ***************************************************
var ajaxUrl = '/assets/ajax/';

//******************************************************************************************************
// 	             						   CALENDAR FUNCTIONS
//****************************************************************************************************** 
//***************************************************
// 	             	Clear Event
//***************************************************
function clearEvent() {
	var titleBox		= document.getElementById("eventTitle").value = '';
	var startdateBox	= document.getElementById("eventStartDate").value = '';
	var enddateBox		= document.getElementById("eventEndDate").value = '';
	var descriptionBox	= document.getElementById("eventDescription").value = '';
	var keywordsBox		= document.getElementById("eventKeywords").value = '';
	var eIdBox			= document.getElementById("eId").value = '';
	
	var eventStatus	= document.getElementById("eventStatus").value = 'New';
	$('#deleteEvent').hide();
}

//***************************************************
//                Toggle New Event
//***************************************************
function toggleNewEvent() {
	var newEventDiv = document.getElementById('newEvent');
	if (newEventDiv.style.display == 'none') {
		$('#newEvent').show();
	}
	else {
		$('#newEvent').hide();
	}
}

//***************************************************
// 	               Submit Event
//***************************************************
function submitEvent() {
	var title		= document.getElementById("eventTitle").value;
	var startdate	= document.getElementById("eventStartDate").value;
	var enddate		= document.getElementById("eventEndDate").value;
	var description	= document.getElementById("eventDescription").value;
	var eventStatus	= document.getElementById("eventStatus").value;
	var keywords	= document.getElementById("eventKeywords").value;
	var dataString = 'title=' + escape(title) + '&startdate=' + startdate + '&enddate=' + enddate + '&description=' + escape(description) + '&mode=' + eventStatus + '&keywords=' + keywords + '&eId=New';

	$.ajax({
		method: "get",url: ajaxUrl + "ajax_processEvent.php", data: dataString,
		beforeSend: function(){$("#hoverpopup").html(loadingDisplay);},
		success: function(html){
			$("#hoverpopup").html(html);
			$.ajax({
				method: "get",url: ajaxUrl + "ajax_calendar.php", data: "",
				beforeSend: function(){$("#calendar").html(loadingDisplay);},
				success: function(html){
					$("#calendar").html(html);
					clearEvent();
				}
			});
		}
	});
}

//***************************************************
// 	             	Next Month
//***************************************************
function nextMonth(month,year) {
	if (month == 12) {
		month = 1;
		++year;
	}
	else {
		++month;
	}
	$.ajax({
		method: "get",url: ajaxUrl + "ajax_events.php", data: "month="+month+"&amp;year="+year,
		beforeSend: function(){$("#calendar").html(loadingDisplay);},
		success: function(html){
			$("#calendar").html(html);
		}
	});
}

//***************************************************
// 	              Previous Month
//***************************************************
function previousMonth(month,year) {
	if (month == 1) {
		month = 12;
		--year;
	}
	else {
		--month;
	}
	$.ajax({
		method: "get",url: ajaxUrl + "ajax_events.php", data: "month="+month+"&amp;year="+year,
		beforeSend: function(){$("#calendar").html(loadingDisplay);},
		success: function(html){
			$("#calendar").html(html);
		}
	});
}

//******************************************************************************************************
// 	             						CLASSIFIED AD FUNCTIONS
//****************************************************************************************************** 
//***************************************************
// 	             Toggle Edit Tab
//*************************************************** 
function toggleClassified() {
	//Categories
	var classifiedMainContent = document.getElementById('classifiedMainContent');

	$('#classifiedMainContent').show();

	$.ajax({
		method: "get",url: ajaxUrl + "ajax_tab_edit.php",data: "uriCat=" + uriCat,
		beforeSend: function(){$("#classifiedMainContent").html(loadingDisplay);},
		success: function(html){
			$("#classifiedMainContent").html(html);
		}
	});	 
}

//***************************************************
//            Expand Selected Category
//*************************************************** 
function expandCat(strId) {
	//Categories
	var catDiv = document.getElementById('catDiv' + strId);
	var adDiv = document.getElementById('adDiv' + strId);
	var siteId = document.getElementById('siteId').value;

	if (catDiv.style.display == 'none') {
		$('#catDiv' + strId).show();
		$('#tgClassifiedLnk' + strId).html('Collapse');
		
		$.ajax({
			method: "get",url: ajaxUrl + "ajax_get_subcategories.php",data: "subcatid="+strId+"&siteId="+siteId,
			beforeSend: function(){$("#catContent" + strId).html(loadingDisplay);},
			success: function(html){
				$("#catContent" + strId).html(html);
			}
		});	 
	}
	else {
		$('#catDiv' + strId).hide();
		$('#tgClassifiedLnk' + strId).html('Expand');
	}

	//Ads
	if (adDiv.style.display == 'none') {
		
		$('#adDiv' + strId).show();
		$('#tgClassifiedLnk' + strId).html('Collapse');
		
		$.ajax({
			method: "get",url: ajaxUrl + "ajax_get_ads.php",data: "subcatid="+strId+"&siteId="+siteId,
			beforeSend: function(){$("#adContent" + strId).html(loadingDisplay);},
			success: function(html){
				$("#adContent" + strId).html(html);
				}
		 });
	}
	else {
		$('#adDiv' + strId).hide();
		$('#tgClassifiedLnk' + strId).html('Expand');
	}
}

//***************************************************
//            Expand URI Selected Category
//*************************************************** 
function expandUriCat(strId) {
	//Categories
	var catDiv = document.getElementById('catDiv' + strId);
	var adDiv = document.getElementById('adDiv' + strId);
	var siteId = document.getElementById('siteId').value;

	if (catDiv.style.display == 'none') {
		$('#catDiv' + strId).show();
		$('#tgClassifiedLnk' + strId).html('Collapse');
		
		$.ajax({
			method: "get",url: ajaxUrl + "ajax_get_subcategories.php",data: "siteId="+siteId+"&subcatid="+strId+"&amp;uriCat=<?= $uriCat ?>",
			beforeSend: function(){$("#catContent" + strId).html(loadingDisplay);},
			success: function(html){
				$("#catContent" + strId).html(html);
			}
		});
	}

	//Ads
	if (adDiv.style.display == 'none') {
		
		$('#adDiv' + strId).show();
		$('#tgClassifiedLnk' + strId).html('Collapse');
		
		$.ajax({
			method: "get",url: ajaxUrl + "ajax_get_ads.php",data: "subcatid="+strId+"&siteId="+siteId,
			beforeSend: function(){$("#adContent" + strId).html(loadingDisplay);},
			success: function(html){
				$("#adContent" + strId).html(html);
				}
		 });
		 
	}
	else {
		$('#adDiv' + strId).hide();
		$('#tgClassifiedLnk' + strId).html('Expand');
	}	
}

