/* ************* */
/* MOUSEOVER BOX */
/* ************* */
function gi(i) {
     var itm=null;
     if(document.getElementById) {
         itm=document.getElementById(i);
     } else if(document.all) {
         itm=document.all[i];
     } else if(document.layers) {
         itm=document.layers[i];
     }
     return itm;
}

function addEvent(_o, _e, _f) {
     if(_o.addEventListener) {
         _o.addEventListener(_e, _f, false);
     } else {
         _o.attachEvent('on' + _e, _f);
     }
}

var skn = null;

function loadTheStuff() {
     skn = gi("PopUpBox");
     skn.style.visibility="visible";
     skn.style.display="none";
     addEvent(document, "mousemove", get_mouse);
}

function popup(Title,IconURLID,Mileage,Description) {
     skn.style.display="block";
     if (Mileage > 0) {
     	skn.innerHTML = "\
     		<div class='hoverpopup'>\
     		 <table>\
     		  <tr>\
     		   <td width='18'><img src='/images/workout_icons/" + IconURLID + ".gif' alt='' /></td>\
     		   <td><b>"+Title+"</b></td>\
     		  </tr>\
     		  <tr>\
     		   <td colspan='2'>"+Mileage+" miles</td>\
     		  </tr>\
     		  <tr>\
     		   <td colspan='2'>"+Description+"</td>\
     		  </tr>\
     		 </table>\
     		 <br /><center><span style='color: #808080;font-size:9px;'>[Click For More]</span></center>\
     		</div>";
     } else {
     	skn.innerHTML = "\
     	     	<div class='hoverpopup'>\
     		 <table>\
     		  <tr>\
     		   <td width='18'><img src='/images/workout_icons/" + IconURLID + ".gif' alt='' /></td>\
     		   <td><b>"+Title+"</b></td>\
     		  </tr>\
      		  <tr>\
     		   <td colspan='2'>"+Description+"</td>\
     		  </tr>\
     		 </table>\
     		 <br /><center><span style='color: #808080;font-size:9px;'>[Click For More]</span></center>\
     		</div>";
     }     
}

function get_mouse(e){
     if(!e) e=window.event;
     skn.style.left=(e.pageX?e.pageX:e.clientX + (window.pageXOffset!=undefined?window.pageXOffset:(document.documentElement && document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)))+"px";
     skn.style.top=(e.pageY?e.pageY:e.clientY + (window.pageYOffset!=undefined?window.pageYOffset:(document.documentElement && document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)))+"px";
}

function kill(){
     skn.style.display="none";
}


/* ************** */
/* LIGHTBOX STUFF */
/* ************** */
var opacity = null;
var speed = 8; // how fast the fade in and fade out will be

function opener() {
	opacity = 0;
	document.getElementById('popup').style.display='block';
	document.getElementById('overlay').style.display='block';
	fadein();
}

function closer() {
	opacity = 80;
	document.getElementById('popup').style.display='none';
	fadeout();
}

function fadein() {
	opacity = opacity + speed;
	document.getElementById('overlay').style.opacity=((opacity)/100);
	document.getElementById('overlay').style.filter='alpha(opacity=' + (opacity) + ')'
	if (opacity<80) setTimeout("fadein()", 10);

}

function fadeout() {
	opacity = opacity - speed;
	document.getElementById('overlay').style.opacity=((opacity)/100);
	document.getElementById('overlay').style.filter='alpha(opacity=' + (opacity) + ')'
	if (opacity>0) {
		setTimeout("fadeout()", 10);
	} else {
		document.getElementById('overlay').style.display='none';
	}
}

function fillThePopup(PageURL,ThisIsMe,WorkoutID,Icon,Type,Title,Date,Mileage,Description,Views,Comments,IsComplete) {
	opener();
	
	if (IsComplete == 1) {
		var TheStatus = "Incomplete";
	} else {
		var TheStatus = "Completed";
	}
	
	var FixedTitle = Title.replace(/\'/,"\\'");
	
	if (ThisIsMe == true) {
		document.getElementById('jscontent').innerHTML="\
		  <a style='float: right;' href='javascript:void(0)' onclick='closer()'><img src='/images/icon_close.gif' border='0' alt='' /></a>\
		  <div class='rightmenu'>\
		   <a href='/workouts/print_workout.php?PrintWorkoutID=" + WorkoutID + "' target='_blank'>Print Workout</a>\
		   <a href='" + PageURL + "ToggleIsCompleteID=" + WorkoutID + "'>Mark As " + TheStatus + "</a>\
		   <a href='/workouts/readd_workout.php?ReAddWorkoutID=" + WorkoutID + "'>ReAdd Workout</a>\
		   <a href='/workouts/edit_workout.php?EditWorkoutID=" + WorkoutID + "'>Edit Workout</a>\
		   <a href=\"javascript: deleteWorkout('" + FixedTitle + "','" + WorkoutID + "','" + PageURL + "');\">Delete Workout</a>\
		  </div>\
			\
		  <h1><img src='/images/workout_icons/" + Icon + ".gif' alt='' />  " + Title + "</h1>\
		  <span style='color: #808080;padding-left: 25px;'>" + Date + "</span>\
		  <table style='float: right; width: 265px; margin-top: 10px; margin-left: 22px;'>\
		   <tr>\
			<td><span style='color: #808080;'>Type:</span></td>\
			<td>" + Type + "</td>\
		   </tr>\
		   <tr>\
			<td><span style='color: #808080;'>Mileage:</span></td>\
			<td>" + Mileage + "</td>\
		   </tr>\
		   <tr>\
			<td valign='top'><span style='color: #808080;'>Description:</span></td>\
			<td>" + Description + "</td>\
		   </tr>\
		  </table>\
		  <div style='clear:both;'></div>\
		  ";
	} else {
		document.getElementById('jscontent').innerHTML="\
		  <a style='float: right;' href='javascript:void(0)' onclick='closer()'><img src='/images/icon_close.gif' border='0' alt='' /></a>\
		  <div class='rightmenu'>\
		   <a href='/workouts/readd_workout.php?ReAddWorkoutID=" + WorkoutID + "'>Add This Workout</a>\
		   <a href='/workouts/print_workout.php?PrintWorkoutID=" + WorkoutID + "' target='_blank'>Print Workout</a>\
		  </div>\
			\
		  <h1><img src='/images/workout_icons/" + Icon + ".gif' alt='' />  " + Title + "</h1>\
		  <span style='color: #808080;padding-left: 25px;'>" + Date + "</span>\
		  <table style='float: right; width: 265px; margin-top: 10px; margin-left: 22px;'>\
		   <tr>\
			<td><span style='color: #808080;'>Type:</span></td>\
			<td>" + Type + "</td>\
		   </tr>\
		   <tr>\
			<td><span style='color: #808080;'>Mileage:</span></td>\
			<td>" + Mileage + "</td>\
		   </tr>\
		   <tr>\
			<td valign='top'><span style='color: #808080;'>Description:</span></td>\
			<td>" + Description + "</td>\
		   </tr>\
		  </table>\
		  <div style='clear:both;'></div>\
		  ";
	}
}

function showMeasurementPhoto(PhotoID, Date) {
	opener();
	document.getElementById('jscontent').innerHTML="\
		<a style='float: right;' href='javascript:void(0)' onclick='closer()'><img src='/images/icon_close.gif' border='0' alt='' /></a>\
		<center>\
		<h1>" + Date + "</h1>\
		<div style='clear:both; height: 10px; font-size: 1px;'></div>\
		<img style='border: 1px solid #808080;' src='/images/members/measurements/" + PhotoID + ".jpg' alt='' />\
		</center>\
		";
}


/* ******************** */
/* COLLAPSIBLE ELEMENTS */
/* ******************** */
function toggleContent(obj) {
	var hideObj = obj.nextSibling.nextSibling;
	if(hideObj.style.display=="none") {
		hideObj.style.display="block";
		obj.className="ContentItemHeader";
	} else {
		hideObj.style.display="none";
		obj.className="ContentItemHeaderOff";
	}
}


/* ************** *
/* HIDE FUNCTIONS */
/* ************** *
/* for mileage on the add/edit workout forms */
function showMileage(theOptionValue) {
	var showTheMileage = theOptionValue.split('|');
	if (showTheMileage[1] == "Yes") {
		 document.getElementById('t0').style.display="";
	} else {
		 document.getElementById('t0').style.display="none";
	}
}

function hide(obj) {
	obj.style.display="none";
}


/* **************** */
/* DELETE FUNCTIONS */
/* **************** */
function deleteWorkout(WorkoutTitle,WorkoutID,PageURL) {
    if (confirm('Are you sure you want to delete the Workout titled ' + WorkoutTitle + '?')) {
        window.location.href = PageURL + 'DeleteWorkoutID=' + WorkoutID;
    }
}

function massDeleteWorkouts(obj) {
    if (confirm('Are sure you sure you want to delete the selected workout(s)?')) {
        var n = obj.parentNode;
        while(n.tagName != "FORM") n = n.parentNode;
	var Formname = n.name;
	document[Formname].onsubmit();
    } else {
    	return false;
    }
}

function deleteMember(DeleteMemberID) {
    if (confirm('Are you sure you want to delete your account? All information and workouts will be permanently lost!')) {
        window.location.href = 'deleted.php?DeleteMemberID=' + DeleteMemberID;
    }
}

function deleteMessage(MessageTitle,DeleteMessageID) {
    if (confirm('Are you sure you want to delete the message titled ' + MessageTitle + '?')) {
        window.location.href = 'index.php?DeleteMessageID=' + DeleteMessageID;
    }
}

function massDeleteMessages(obj) {
    if (confirm('Are sure you sure you want to delete the selected message(s)?')) {
        var n = obj.parentNode;
        while(n.tagName != "FORM") n = n.parentNode;
	var Formname = n.name;
	document[Formname].onsubmit();
    } else {
    	return false;
    }
}

function deleteMeasurement(DeleteMeasurementID) {
    if (confirm('Are you sure you want to delete this measurement?')) {
        window.location.href = 'index.php?DeleteMeasurementID=' + DeleteMeasurementID;
    }
}

function deleteGoal(DeleteGoalID) {
    if (confirm('Are you sure you want to delete this goal?')) {
        window.location.href = 'index.php?DeleteGoalID=' + DeleteGoalID;
    }
}


/* ***************** */
/* REMOVE FRIENDSHIP */
/* ***************** */
function removeFriendship(FriendshipID,ThePage) {
     if (confirm('Are you sure you want to remove this friendship?')) {
        window.location.href = ThePage + 'RemoveFriendshipID=' + FriendshipID;
    }
}


/* ************************* */
/* DROP DOWN MENU AUTO CHECK */
/* ************************* */
function checkBox(obj) {
	var Toggleobj = obj.name;
        var n = obj.parentNode;
        while(n.tagName != "FORM") n = n.parentNode;
	var Formname = n.name;
	
	if (obj.checked == true) {
		for (i = 0; i < document[Formname][Toggleobj].length; i++) {
			document[Formname][Toggleobj][i].checked = true;
		}
	} else {
		for (i = 0; i < document[Formname][Toggleobj].length; i++) {
			document[Formname][Toggleobj][i].checked = false;
		}
	}
}