﻿var currentTab = 0;
var currentPhotoId = 0;
var currentPhotoGuid = "";

function SwitchTab(tabNo) {

	var oldTab = document.getElementById("tab" + currentTab);
	oldTab.className = "tab tabOff";
	oldTab.innerHTML = "<a href='javascript: SwitchTab(" + currentTab + ");'>" + oldTab.getAttribute("title") + "</a>";

	var oldTabC = document.getElementById("tabC" + currentTab);
	oldTabC.style.display = "none";

	var newTab = document.getElementById("tab" + tabNo);
	newTab.className = "tab tabOn";
	newTab.innerText = newTab.getAttribute("title");

	var newTabC = document.getElementById("tabC" + tabNo);
	newTabC.style.display = "";

	currentTab = tabNo;
}

function ShowPhotoOptions(PhotoId) {
	var options = document.getElementById("options" + PhotoId);
	options.style.visibility = "visible";
}

function HidePhotoOptions(PhotoId) {
	var options = document.getElementById("options" + PhotoId);
	options.style.visibility = "hidden";
}

function LoadPhoto(PhotoId, Filename) {

	document.getElementById("ajaxLoader").style.display = "";

	var mainPhoto = document.getElementById('mainPhoto');
	mainPhoto.style.display = "none";
	mainPhoto.src = httpPhotoFolder + "photos/" + Filename;
	mainPhoto.setAttribute("filename", Filename);

	document.getElementById("fullPhoto").href = httpPhotoFolder + "fullphotos/" + Filename;

	currentPhotoId = PhotoId;
	currentPhotoGuid = Filename;
}

function HideLoader(SrcElement) {
	if (document.getElementById) {
		document.getElementById("ajaxLoader").style.display = "none";
		SrcElement.style.display = "";
	}
}

function ShowPhoto(PhotoId, Guid) {

	var profileSection = document.getElementById("profileSection");
	profileSection.style.display = "none";

	var photoSection = document.getElementById("photoSection");
	photoSection.style.display = "";

	LoadPhoto(PhotoId, Guid);
}

function NextPhoto() {
	if (document.getElementById && document.getElementsByTagName) {

		var tabC0 = document.getElementById("tabC1");
		var images = tabC0.getElementsByTagName('img');
		var mainPhoto = document.getElementById('mainPhoto');
		var found = -1;

		for (var i = 0; i < images.length - 1; i++) {
			if (images[i].getAttribute("filename") == mainPhoto.getAttribute("filename")) {
				found = i;
				break;
			}
		}

		LoadPhoto(images[found + 1].getAttribute("photoId"), images[found + 1].getAttribute("filename"));
	}
	else
		alert('This function is not supported by your browser.');
}

function ShowGallery() {

	var profileSection = document.getElementById("profileSection");
	profileSection.style.display = "";

	var photoSection = document.getElementById("photoSection");
	photoSection.style.display = "none";
}

function FlagGirl(girlId) {
	var txt = document.getElementById('txtFlagGirl').value;
	if (UProfile.FlagGirl(girlId, txt).value) {
		document.getElementById('girlFlag').removeAttribute("href");
		document.getElementById('girlFlag').innerText = '[Reported]';
		document.getElementById('flagGirlDiv').style.display = 'none';
	}
	else
		alert('Your message could not be delivered just now. Please try again.');
}

function DeleteComment(controlId, commentId) {
	if (UProfile.DeleteComment(commentId)) {
		document.getElementById(controlId).removeAttribute("href");
		document.getElementById(controlId).innerText = '[Deleted]';
	}
	else
		alert('Comment could not be deleted');
}

function ActionComment(controlId, commentId) {
	var actionLink = document.getElementById(controlId);

	if (UProfile.SetCommentStatus(commentId, actionLink.innerText)) {
		if (actionLink.innerText == "Approve")
			actionLink.innerText = "Reject";
		else
			actionLink.innerText = "Approve";
	}
	else
		alert('Comment could not be actioned.');
}

function RequestLink(girlId) {
	var requestLink = document.getElementById("thisisme");

	if (UProfile.RequestLink(girlId)) {
		alert('A request has been sent to the webmaster. You will be notified by email if your request is succesful.');
		requestLink.removeAttribute("href");
		requestLink.innerText = '[Requested]';
	}
	else
		alert("Your request couldn't be processed.");
}

function RemoveLink(girlId) {
	alert("Sorry we can't do this yet. Please contact us by using the contact page instead.");
}

function Subscribe(girlId) {
	var control = document.getElementById("subscribe");
	if (UProfile.Subscribe(girlId)) {
		control.removeAttribute("href");
		control.innerText = '[Subscribed]';
	}
	else
		alert("Couldn't be subscribed.");
}

function DeletePhoto(photoId) {
	if (confirm("Are you sure you want to delete this photo?")) {
		if (UProfile.DeletePhoto(photoId).value) {
			var div = document.getElementById("photoDiv" + photoId);
			div.style.display = "none";
		}
		else
			alert('Photo could not be deleted');
	}
}

function SetToProfile(girlId) {
	if (UProfile.SetToProfile(girlId, currentPhotoId).value) {
		var profilePhoto = document.getElementById('DefaultPhoto');
		var oldSrc = profilePhoto.src;
		profilePhoto.src = profilePhoto.src.substring(0, oldSrc.lastIndexOf("/") + 1) + currentPhotoGuid;
		alert('OK');
	}
	else
		alert('Failed');
}

function SetFrontPage(girlId, value) {
	if (UProfile.SetFrontPage(girlId, value).value)
		alert('OK');
	else
		alert('Failed');
}

function SetEditorPick(girlId, value) {
	if (UProfile.SetEditorPick(girlId, value).value)
		alert('OK');
	else
		alert('Failed');
}

function SetCreatorAsOwner(girlId) {
	if (confirm("Are you sure?")) {
		if (UProfile.SetCreatorAsOwner(girlId).value)
			alert('OK');
		else
			alert('Failed');
	}
}

function SendMessage(girlId) {
	if (confirm("Are you sure?")) {

		var messageBox = document.getElementById("TxtMessage");
		var subjectBox = document.getElementById("TxtSubject");
		if (UProfile.SendMessage(girlId, subjectBox.value, messageBox.value).value)
			alert('OK');
		else
			alert('Failed');
	}
}
