// JavaScript Document

function editBlurb() {
	document.getElementById('cur-blurb').style.display='none';
	document.getElementById('new-blurb').style.display='inline';
}

function editDisplayName() {
	document.getElementById('cur-displayname').style.display='none';
	document.getElementById('new-displayname').style.display='inline';
}

function editAlbumName(album_id) {
	document.getElementById('album_name_'+album_id).style.display='none';
	document.getElementById('new_album_name_'+album_id).style.display='inline';
}

function editUpdate(update_id) {
	document.getElementById('cur-update-'+update_id).style.display='none';
	document.getElementById('new-update-'+update_id).style.display='inline';
}

function editConfig(update_id) {
	document.getElementById('cur-update-'+update_id).style.display='none';
	document.getElementById('new-update-'+update_id).style.display='inline';
}

function addPeer(user_id) {
	javascript:ajax_loadContent('add-peer','/add-peer.php?user_id='+user_id,'Processing...');	
}

function addPeerMD(user_id) {
	javascript:ajax_loadContent('add-peer-'+user_id,'/add-peer.php?user_id='+user_id,'Processing...');	
}

function deletePeer(user_id) {
	if(window.confirm("Are you sure you want to remove this user as a peer?")) {
		javascript:ajax_loadContent('peer-'+user_id,'/delete-peer.php?user_id='+user_id,'Processing...');	
	}
}

function deleteBlog(blog_id) {
	if(window.confirm("Are you sure you want to remove this blog? This can not be undone!")) {
		javascript:ajax_loadContent('blog-'+blog_id,'/delete-blog.php?blog_id='+blog_id,'Deleting...');	
	}
}

function deleteVideo(video_id) {
	if(window.confirm("Are you sure you want to remove this video? This can not be undone!")) {
		javascript:ajax_loadContent('blog-'+video_id,'/delete-video.php?video_id='+video_id,'Deleting...');	
	}
}

function delCategory(category_id) {
	if(window.confirm("Are you sure you want to remove this category and all ads within? This can not be undone!")) {
		javascript:ajax_loadContent('category-'+category_id,'/del-category.php?category_id='+category_id,'Deleting...');	
	}
}

function delGenre(genre_id) {
	if(window.confirm("Are you sure you want to remove this genre? This can not be undone!")) {
		javascript:ajax_loadContent('genre-'+genre_id,'/del-genre.php?genre_id='+genre_id,'Deleting...');	
	}
}

function deleteAd(post_id) {
	if(window.confirm("Are you sure you want to remove this ad? This can not be undone!")) {
		javascript:ajax_loadContent('ad-'+post_id,'/delete-ad.php?post_id='+post_id,'Deleting...');	
	}
}

function deleteEvent(event_id) {
	if(window.confirm("Are you sure you want to remove this event? This can not be undone!")) {
		javascript:ajax_loadContent('event-'+event_id,'/delete-event.php?event_id='+event_id,'Deleting...');	
	}
}

function deletePage(id) {
	if(window.confirm("Are you sure you want to remove this page? This can not be undone!")) {
		javascript:ajax_loadContent('page-'+id,'/delete-page.php?id='+id,'Deleting...');	
	}
}

function deleteAlbum(album_id) {
	if(window.confirm("Are you sure you want to delete this album and all the artwork in it? This can not be undone!")) {
		javascript:ajax_loadContent('album-'+album_id,'/delete-album.php?album_id='+album_id,'Deleting...');	
	}
}

function deletePhoto(photo_id) {
	if(window.confirm("Are you sure you want to delete this image? This can not be undone!")) {
		javascript:ajax_loadContent('photo-'+photo_id,'/delete-photo.php?photo_id='+photo_id,'Deleting...');	
	}
}

function deleteDir(id) {
	if(window.confirm("Are you sure you want to delete this entry? This can not be undone!")) {
		javascript:ajax_loadContent('dir-'+id,'/delete-dir.php?id='+id,'Deleting...');	
	}
}

function loadImage(artwork_id) {
	var collection = document.getElementById('collections_album');
	
	if(collection.value!='0') {
		var user_id = document.getElementById('collections_album').value;
		javascript:ajax_loadContent('featuredArt','/_view_photo.php?collections='+user_id+'&photo='+artwork_id,'Grabbing Media...');	
	}
	else {
		javascript:ajax_loadContent('featuredArt','/_view_photo.php?photo='+artwork_id,'Grabbing Media...');	
	}
}

function loadAlbum(album_id) {
	document.getElementById('my-artwork').className = 'current';
	document.getElementById('my-collection').className = '';
	document.getElementById('my-personal').className = '';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id='+album_id,'Getting album...');	
}

function loadPersonalAlbum(album_id) {
	document.getElementById('my-artwork').className = '';
	document.getElementById('my-collection').className = '';
	document.getElementById('my-personal').className = 'current';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id='+album_id,'Getting album...');	
}

function loadCollections(user_id) {
	document.getElementById('my-artwork').className = '';
	document.getElementById('my-collection').className = 'current';
	document.getElementById('my-personal').className = '';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id=collection&user_id='+user_id,'Getting album...');	
}

function viewAllCurrent() {
	var artwork = document.getElementById('my-artwork');
	var collection = document.getElementById('my-collection');
	var personal = document.getElementById('my-personal');
	
	if(artwork.className=='current') { 
		loadAlbum(document.getElementById('album_id').value);
	}
	if(collection.className=='current') {
		loadCollections(document.getElementById('collections-album').value);
	}
	if(personal.className=='current') {
		loadPersonalAlbum(document.getElementById('personal-album').value);
	}
}

function findFriends() {
	document.getElementById('findfriends-link').style.display = 'none';
	document.getElementById('findfriends-search').style.display = 'inline';
}

function giveStar(artwork_id, user_id) {
	javascript:ajax_loadContent('give-star-'+artwork_id,'/give-star.php?photo='+artwork_id+'&user_id='+user_id,'Incrementing...');	
	document.getElementById('star-count').innerHTML = document.getElementById('star-count-incremented').innerHTML;
}

function giveStarMyCanvas(artwork_id, user_id) {
	javascript:ajax_loadContent('give-star-'+artwork_id,'/give-star.php?photo='+artwork_id+'&user_id='+user_id,'Incrementing...');	
}

function addToCollection(artwork_id) {
	javascript:ajax_loadContent('add-to-collection','/add-to-collection.php?photo='+artwork_id,'Adding...');	
}

function addToFeatured(folder_name) {
	javascript:ajax_loadContent('featured-'+folder_name,'/add-to-featured.php?folder_name='+folder_name,'Featuring...');	
}

function changeFeatured(photo_id, featured) {
	javascript:ajax_loadContent('photo-'+photo_id,'/feature-pic.php?photo_id='+photo_id+'&featured='+featured,'Saving...');	
}

function featureAlbum(album_id) {
	javascript:ajax_loadContent('album-'+album_id,'/feature-album.php?album_id='+album_id,'Featuring...');	
}

function addToFeaturedDir(id) {
	javascript:ajax_loadContent('dir-'+id,'/add-to-featured-dir.php?id='+id,'Featuring...');	
}

function removeFromCollection(artwork_id) {
	javascript:ajax_loadContent('photo-'+artwork_id,'/remove-from-collection.php?photo='+artwork_id,'Removing...');	
}

function removeFromFeatured(artwork_id) {
	javascript:ajax_loadContent('photo-'+artwork_id,'/remove-from-featured.php?photo='+artwork_id,'Removing...');	
}

function removeFeaturedDir(dir_id) {
	javascript:ajax_loadContent('dir-'+dir_id,'/remove-from-featured-dir.php?dir='+dir_id,'Removing...');	
}

function validate_required(field,alerttxt)
{
with (field)
{
	if (value==null||value=="")
	  {alert(alerttxt);return false;}
	else {return true}
}
}

function validate_form(thisform)
{
	thisform = document.getElementById(thisform);
	with (thisform)
	{
		if (validate_required(email,"Email must be filled out!")==false) {
				email.focus();
				return false;
		}
	}
}

/* Drop down JS */
window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var menuActive = 0;
var menuOn = 0;
var onLayer;
var timeOn = null;

function showLayer(layerName,aa){
var x =document.getElementById(aa);
var tt =findPosX(x);
var ww =findPosY(x)+20;

if (timeOn != null) {
clearTimeout(timeOn);
hideLayer(onLayer);
}
if (IE4) {
var layers = eval('document.all["'+layerName+'"].style');
layers.left = tt;
eval('document.all["'+layerName+'"].style.display="block"');
}
else {
if(document.getElementById){
var elementRef = document.getElementById(layerName);
if((elementRef.style)&& (elementRef.style.visibility!=null)){
elementRef.style.display = 'block';
elementRef.style.left = tt;
elementRef.style.top = ww;
}
}
}
onLayer = layerName
}

function hideLayer(layerName){
if (menuActive == 0)
{
if (IE4){
eval('document.all["'+layerName+'"].style.display="none"');
}
else{
if(document.getElementById){
var elementRef = document.getElementById(layerName);
if((elementRef.style)&& (elementRef.style.display!=null)){
elementRef.style.display = 'none';
}
}
}
}
}

function btnTimer() {
timeOn = setTimeout("btnOut()",600)
}

function btnOut(layerName){
if (menuActive == 0){
hideLayer(onLayer)
}
}

var item;
function menuOver(itemName,ocolor){
item=itemName;
itemName.style.backgroundColor = ocolor; //background color change on mouse over
clearTimeout(timeOn);
menuActive = 1
}

function menuOut(itemName,ocolor){
if(item)
itemName.style.backgroundColor = ocolor;
menuActive = 0
timeOn = setTimeout("hideLayer(onLayer)", 100)
}

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

/* END DROP DOWN JS */