
/*-----------------------------
	Skirmisher
------------------------------*/

function ShowTCs(ResourceURL,Type)
{
	$.modal('<iframe src="' + ResourceURL + Type+'-TCs.html" height="250px" width="100%" style="border:0">',{maxHeight:250,maxWidth: 450});
}

function Share(ResourceURL,CurrentURL)
{
	$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=Share&CurrentURL='+CurrentURL+'" height="200" width="100%" style="border:0">',{maxHeight:200,maxWidth: 450});
}

function Contact(ResourceURL)
{
	$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=Contact" height="200" width="100%" style="border:0">',{maxHeight:200,maxWidth: 450});
}

function Info(ResourceURL,Info)
{
	$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=Info&Info='+Info+'" height="230" width="100%" style="border:0">',{maxHeight:230,maxWidth: 450});
}

function CancelReservation(ResourceURL,ReservationID)
{
	//$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=Cancel&ReservationID='+ReservationID+'" height="230" width="100%" style="border:0">',{maxHeight:230,maxWidth: 480});
	$.get(ResourceURL+"ajax.php?Function=CancelReservation&ReservationID="+ReservationID, function(data){
		$("#left").hide();
		$("#left").html(data);
		$("#left").fadeIn("slow");
	});
	
}

function ConfirmCancelReservation(ResourceURL,ReservationID,SubTry)
{
	//$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=Cancel&ReservationID='+ReservationID+'" height="230" width="100%" style="border:0">',{maxHeight:230,maxWidth: 480});
	$.get(ResourceURL+"ajax.php?Function=ConfirmCancelReservation&ReservationID="+ReservationID+"&SubTry="+SubTry, function(data){
		$("#left").hide();
		$("#left").html(data);
		$("#left").fadeIn("slow");
	});
	
}

function RecoverCredentials(ResourceURL,CredentialType)
{
	$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=RecoverCredentials&CredentialType='+CredentialType+'" height="200" width="100%" style="border:0">',{maxHeight:200,maxWidth: 450});
}

function ShowFlowPlayer(ResourceURL,Video)
{
	$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=ShowFlowPlayer&Video='+Video+'" height="360" width="480" style="border:0">',{maxHeight:360,maxWidth: 480});
}

function toggleSDSetting(HTTPSURL,SettingType,UserID,Key)
{
	$.get(HTTPSURL+"ajax.php?Function=UpdateSDSettings&SettingType="+SettingType+"&UserID="+UserID+"&Key="+Key, function(data){
		if(SettingType == 'GenNewHash')
		{
			$("#URLWithHash").hide();
			$("#URLWithHash").html(data);
			$("#URLWithHash").fadeIn("slow");
		}
		else
		{
			$("#URLWithHash").append(data);
			$("#"+SettingType).attr("src", HTTPSURL+'images/account_resources/sd_wait.gif');
		}
	  
});
}

function ShowAdvancedSearch()
{
	$("#AdvSearch").slideDown("slow");
	$("#AdvSearchSuggest").fadeOut("slow");
	//$("#AdvSearchSuggest").html("<h2>Advanced Search Function:</h2>");
	$("#AdvSearchSuggest").html('<a name="adv_search"></a><div class="ribbon"><div class="wrapAround"></div><div class="tab"><span>Advanced Search Function:</span></div></div>');
	$("#AdvSearchSuggest").fadeIn("slow");
}

function AdvSearch()
{
	if($("#EventDetails").val() == "" && $("#StartDate").val() == "" && $("#EndDate").val() == "" && $("#SiteName").val() == "")
	{
		$("#AdvSearchResults").fadeOut("slow");
		//$("#AdvSearchResults").html("<h2>Advanced Search Error</h2><p>Please fill in the Event Details search query</p>");  
		$("#AdvSearchResults").html('<a name="adv_search"></a><div class="ribbon"><div class="wrapAround"></div><div class="tab"><span>Advanced Search Error</span></div></div><p>Please fill in the Event Details search query</p>');
		$("#AdvSearchResults").fadeIn("slow");
	}
	else
	{
		$("#AdvSearchResults").fadeOut("slow");
		
		var StartDate = $("#StartDate").val();
		var EndDate = $("#EndDate").val();
		var SiteName = $("#SiteName").val();
		var EventDetails = $("#EventDetails").val();
		
		$.get("http://mils.im/ajax.php?Function=AdvSearch&StartDate="+escape(StartDate)+"&EndDate="+escape(EndDate)+"&SiteName="+escape(SiteName)+"&EventDetails="+escape(EventDetails), function(data){
			$("#AdvSearchResults").html(data);  
		});
		
		$("#AdvSearchResults").fadeIn("slow");
	}
}


/*-----------------------------
	Site Operator
------------------------------*/
function ManageUpcomingEvent(HTTPSURL,EventID,Type)
{
	
	$("#left").fadeOut("fast");
	$.get(HTTPSURL+"ajax.php?Function=ManageUpcomingEvent&EventID="+escape(EventID)+"&ManageType="+escape(Type), function(data){
		$("#left").html(data);
		$("#left").fadeIn("slow");
		  
		
		if(Type == 'Edit')
		{
			 $('#EventStartDate').datepicker({dateFormat: 'yy-mm-dd'});//inline: true, 
	         $('#EventEndDate').datepicker({dateFormat: 'yy-mm-dd'});
	         $("#EditEventForm").validate();					       
		}
		else if (Type == 'overview' || Type == 'ManageReservations')
		{
			EnableMilsimPopup();
		}
	});
	
	
}

function ManagePastEvent(HTTPSURL,EventID,Type)
{
	$("#left").fadeOut("fast");
	$.get(HTTPSURL+"ajax.php?Function=ManagePastEvent&EventID="+escape(EventID)+"&ManageType="+escape(Type), function(data){
		$("#left").html(data);
		$("#left").fadeIn("slow");  
		
		EnableMilsimPopup();
	});
	
	
}

function EnableMilsimPopup()
{
	var overlayColor = $('#fancy_overlay').css('background-color') || '#2c2c2c';
	$(".MilsimPopup").fancybox({
	'padding': 12, 
	'overlayOpacity': 0.2,
	'overlayColor': overlayColor, 
	'zoomSpeedIn': 500, 
	'zoomSpeedOut': 500,
	'callbackOnShow': modalStart
	});
}

function ConfirmAttendance(HTTPSURL,EventID)
{
	$.modal('<iframe src="' + HTTPSURL + 'ajax.php?Function=ManagePastEvent&EventID='+EventID+'&ManageType=ConfirmAttendance" height="250px" width="100%" style="border:0">',{maxHeight:250,maxWidth: 450});
}

function ContactAttendees(HTTPSURL,EventID,Type)
{
	$("#left").fadeOut("fast");
	$.get(HTTPSURL+"ajax.php?Function=ContactAttendees&EventID="+escape(EventID)+"&ContactType="+escape(Type), function(data){
		$("#left").html(data);
		$("#left").fadeIn("slow");  
	});
}

function SendAttendeeSMS(HTTPSURL,EventID)
{
	var Content = $("#SMSText").val();
	$("#left").fadeOut("fast");
	$("#left").html("<h2><a>SMS sending in progress.....</a></h2><img src=\""+HTTPSURL+"images/waiting.gif\">");
	$("#left").fadeIn("slow");  
	$.get(HTTPSURL+"ajax.php?Function=ContactAttendees&EventID="+escape(EventID)+"&ContactType=sendsms&Content="+escape(Content), function(data){
		$("#left").fadeOut("fast");
		$("#left").html(data);
		$("#left").fadeIn("slow");  
	});
}

function limitText(limitField, limitNum) 
{
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

function SendAttendeeEmail(HTTPSURL,EventID)
{
	var Subject = $("#EmailSubject").val();
	var Content = $("#EmailText").val();
	$("#left").fadeOut("fast");
	$("#left").html("<h2><a>Email sending in progress.....</a></h2><img src=\""+HTTPSURL+"images/waiting.gif\">");
	$("#left").fadeIn("slow");  
	$.get(HTTPSURL+"ajax.php?Function=ContactAttendees&EventID="+escape(EventID)+"&ContactType=sendemail&Subject="+escape(Subject)+"&Content="+escape(Content), function(data){
		$("#left").fadeOut("fast");
		$("#left").html(data);
		$("#left").fadeIn("slow");  
	});
}

var FlipEdit = true;

function EditEventTitle(EventID)
{
	if(FlipEdit == false)
	{
		var EventTitleEditValue = $("#EventTitleEdit").val();
		$("#EventTitle").html(EventTitleEditValue);
		FlipEdit = true;
	}
	else
	{
		var EventTitle = $("#EventTitle").html();
		$("#EventTitle").html('<input type="text" id="EventTitleEdit" value="'+EventTitle+'"> <a href="#">Save</a>');
		$("#EventTitleEdit").focus();
		FlipEdit = false;
	}
}

function ManageUserReservation(ResourceURL,EventID,ReservationID)
{
	//$.modal('<iframe src="' + ResourceURL + 'ajax.php?Function=ManageUserReservation&EventID='+EventID+'&ReservationID='+ReservationID+'" height="250px" width="100%" style="border:0">',{maxHeight:250,maxWidth: 450});
}

function ShowReservationKey(ResourceURL)
{
	$("#ReservationKey").html('<iframe src="' + ResourceURL + 'ajax.php?Function=GetUserReservationIconKey" height="350px" width="100%" style="border:0">');
	//$("#ReservationKey").fadeIn("slow");
}
