/*******************************************************************/

/************************* POPUPS **************************/

function showFriendRequestsPopup()
{
 var where_to= confirm("You have new friend requests. Would you like to view them now?");
 if (where_to== true) {
 	window.location="http://www.broncoscountry.com/view-friend-requests";
 }
}

/************************* GROUPS **************************/
function showInsertGroupForm()
{
    var form = document.getElementById("insertGroupForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertGroupForm()
{
    var form = document.getElementById("insertGroupForm");
    form.style.visibility = "hidden";
}

/************************* PHOTOS **************************/ 

var photoPos = 0;

function validateAddMediaForm(thisForm)
{
	with(thisForm)
	{
		if(!validatePhotoName()) { return false; }
	}
}

function validatePhotoName()
{
	var errorParagraph = document.getElementById("insertPhotoFormInvalidCharacterErrorMessage");
	
	errorParagraph.style.visibility = "visible";
	
	return false;
}

function showInsertPhotoForm(isEditForm)
{
    var form = document.getElementById("insertPhotoForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
    
    document.getElementById('photoIsEditForm').value = isEditForm;
}

function hideInsertPhotoForm()
{
    var form = document.getElementById("insertPhotoForm");
    form.style.visibility = "hidden";
}

function nextPhoto()
{
    if(photoPos == (thumbList.length-1)) 
        photoPos = 0;
    else
        photoPos++;
        
    var photoHolder = document.getElementById("photoHolder");
    fadein(photoHolder);
    setTimeout("loadPhoto()",150);
}

function prevPhoto()
{
    if(photoPos <= 0) 
        photoPos = (thumbList.length-1);
    else
        photoPos--;
    
    var photoHolder = document.getElementById("photoHolder");
    fadein(photoHolder);
    setTimeout("loadPhoto()",150);
}

function loadPhoto()
{
    var photoHolder = document.getElementById("photoHolder");
    if(thumbList.length) photoHolder.src = thumbList[photoPos];
    
    var photoRatingsHolder = document.getElementById("photoRatingsHolder");
    if(photoRatingsList.length) photoRatingsHolder.innerHTML = photoRatingsList[photoPos];
}

function openPhoto()
{
    var openedPhoto = window.open(photoList[photoPos], "Photo", "resizable, scrollbars, height=600, width=800");
	openedPhoto.focus();
}

function deletePhoto()
{
    if(confirm("Are you sure you want to delete this image?"))
    {
        var url = (document.getElementById("siteGeneratorURL").value)+"deletePhoto/"+photoIDs[photoPos];
        window.location = url;
    }
}

function fadein(photo)
{
    new Effect.Opacity(photo, {duration:0.6, from:0.0, to:1.0});
}
/***********************************************************/ 


/************************ VIDEO ****************************/ 
function showInsertVideoForm()
{
    var form = document.getElementById("insertVideoForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertVideoForm()
{
    var form = document.getElementById("insertVideoForm");
    form.style.visibility = "hidden";
}
/***********************************************************/ 


/************************ AUDIO ****************************/ 
function showInsertAudioForm()
{
    var form = document.getElementById("insertAudioForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertAudioForm()
{
    var form = document.getElementById("insertAudioForm");
    form.style.visibility = "hidden";
}
/***********************************************************/ 


/************************ STORY ****************************/ 
function showInsertStoryForm()
{
    var form = document.getElementById("insertStoryForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertStoryForm()
{
    var form = document.getElementById("insertStoryForm");
    form.style.visibility = "hidden";
}

function viewStory(story)
{
    var form = document.getElementById("viewStoryForm");
    var content = document.getElementById("viewStoryContent");
    
    // replace <br /> with \r\n
    pieces = story.split("<br />");
	story = pieces.join("\r\n");
    content.innerHTML = story;
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideStory()
{
    var form = document.getElementById("viewStoryForm");
    form.style.visibility = "hidden";
}
/***********************************************************/ 


/************************ RECIPE ****************************/ 
function showInsertRecipeForm()
{
    var form = document.getElementById("insertRecipeForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertRecipeForm()
{
    var form = document.getElementById("insertRecipeForm");
    form.style.visibility = "hidden";
}

function viewRecipe(recipe)
{
    var form = document.getElementById("viewRecipeForm");
    var content = document.getElementById("viewRecipeContent");
    
    // replace <br /> with \r\n
    pieces = recipe.split("<br />");
	recipe = pieces.join("\r\n");
    content.innerHTML = recipe;
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideRecipe()
{
    var form = document.getElementById("viewRecipeForm");
    form.style.visibility = "hidden";
}
/***********************************************************/ 

/************************ GAME EVENTS ****************************/ 
function showInsertGameEventForm()
{
    var form = document.getElementById("insertGameEventForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertGameEventForm()
{
    var form = document.getElementById("insertGameEventForm");
    form.style.visibility = "hidden";
}
/***********************************************************/ 

/************************ GAME EVENTS ****************************/ 
function showReportInappropriateContentForm(id, contentType)
{
    var badID = document.getElementById("badID");
    var badContentType = document.getElementById("badContentType");
    var badContentForm = document.getElementById("reportInappropriateContentForm");
    
    badID.value = id;
    badContentType.value = contentType;
		badContentForm.style.width = "600px";
		badContentForm.style.height = "300px";
	
		var formLeft = (screen.availWidth/5);
		var formTop = (screen.availHeight/5) + document.documentElement.scrollTop;
	
    badContentForm.style.left = formLeft + "px";
    badContentForm.style.top = formTop + "px";
    badContentForm.style.visibility = "visible";
}

function hideInappropriateContentForm()
{
    var badContentForm = document.getElementById("reportInappropriateContentForm");
    badContentForm.style.visibility = "hidden";
}
/***********************************************************/ 

/************************ COMMENTS *************************/

function showInsertCommentForm()
{
    var form = document.getElementById("insertCommentForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideInsertCommentForm()
{
	var form = document.getElementById("insertCommentForm");
	form.style.visibility = "hidden";
}

function showListGameEventsForm()
{
    var form = document.getElementById("listGameEventsForm");
    
    form.style.left = (screen.availWidth/5) + "px";
    form.style.top = (screen.availHeight/5) + document.documentElement.scrollTop + "px";
    form.style.visibility = "visible";
}

function hideListGameEventsForm()
{
	var form = document.getElementById("listGameEventsForm");
	form.style.visibility = "hidden";
}

/***********************************************************/ 

/************************ OVERLAY *************************/

function hidePageOverlay() {
	var pageOverlay = document.getElementById("pageOverlay");	
	pageOverlay.style.visibility = "hidden";
}

function my_groups_toggle(divId){
	var target = '#' + divId + ' .my_groups_bottom';
	var img = '#' + divId + ' .my_groups_arrow';	
	
	if($(target).css('display') == 'none'){
		// hide all then show
		$('.my_groups_bottom').hide(500, function(){
			$('.my_groups_arrow').attr('src', 'resources/img/groups/arrow_right.png');	
		});
										
		
		$(target).show(500);
		$(img).attr('src', 'resources/img/groups/arrow_down.png');												
	}
	else{
		$(target).hide(500, function(){
			$(img).attr('src', 'resources/img/groups/arrow_right.png');	
		});							
	}
}