//*****************************************************************************************
// MAIN SITE JS FUNCTIONS
//*****************************************************************************************
var bolContinue = true;

// Logout function
//-----------------------------------------------------------------------------------------
function logout(){
	if(confirm('Are you sure you want to log out of the system?')){
		document.location='/login.asp?logout=yes';
	}
}

// Verify Login function
//-----------------------------------------------------------------------------------------
function verifyLogin(vf){
	//Make sure username & password was provided
	if(vf.username.value==""||vf.password.value==""){
		alert('Please provide your username & password');
		vf.username.select();
		vf.username.focus();
		return false;
	}
}

// Print Window
//-----------------------------------------------------------------------------------------
function printWindow(){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-200;
	iw=iw/2-354;
	window.open('printTestsets.htm','print','top='+ih+'px,left='+iw+'px,width=708px,height=400px,toolbar=0,menubar=1,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

// View help function
//-----------------------------------------------------------------------------------------
function printWorkoutWindow(logID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-210;
	iw=iw/2-300;
	window.open('/MEMBERS/TRAININGPLAN/printWorkout.asp?logID='+logID,'helpWindow','top='+ih+'px,left='+iw+'px,width=600px,height=440px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

// View help function
//-----------------------------------------------------------------------------------------
function helpWindow(helpType){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/MEMBERS/HELP/'+helpType+'.asp','helpWindow','top='+ih+'px,left='+iw+'px,width=300px,height=240px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

// View notes function
//-----------------------------------------------------------------------------------------
function notesWindow(varnotes,vartype){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/MEMBERS/notes.asp?noteID='+varnotes+'&type='+vartype,'notesWindow','top='+ih+'px,left='+iw+'px,width=300px,height=240px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

// Admin view notes function
//-----------------------------------------------------------------------------------------
function notesWindowB(varnotes,vartype,varmember){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/notes.asp?noteID='+varnotes+'&memberid='+varmember+'&type='+vartype+'&Randomstring=adsfgjier','notesWindow','top='+ih+'px,left='+iw+'px,width=300px,height=240px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

// Modify result function
//-----------------------------------------------------------------------------------------
function modifyResult(resultType,resultID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/MEMBERS/HISTORY/MODIFY/'+resultType+'.asp?modify='+resultID,'modifyWindow','top='+ih+'px,left='+iw+'px,width=518px,height=400px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// View graph function
//-----------------------------------------------------------------------------------------
function graphWindow(resultType,resultID,chuck,memberID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/MEMBERS/HISTORY/GRAPHS/'+resultType+'.asp?memberID='+memberID+'&resultID='+resultID+'&chuck='+chuck,'graphWindow','top='+ih+'px,left='+iw+'px,width=640px,height=415px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// Delete result function
//-----------------------------------------------------------------------------------------
function deleteResult(resultType,resultID){
	if(confirm('Are you sure you want to delete this record?'))
		{
		document.location=resultType+'.asp?delete='+resultID
		}
	else
		{
		return false;
		}
}


// 1st application form // my info form
//-----------------------------------------------------------------------------------------
function personalInfoVerify(vf){

	if (vf.firstName.value=='')
		{
		alert("You must provide your first name");
		vf.firstName.focus();
		return false;
		}
		
	if (vf.lastName.value=='')
		{
		alert("You must provide your last name");
		vf.lastName.focus();
		return false;
		}

	if (vf.address.value=='')
		{
		alert("You must provide your street address");
		vf.address.focus();
		return false;
		}
	
	if (vf.city.value=='')
		{
		alert("You must provide your city");
		vf.city.focus();
		return false;
		}
		
	if (vf.state.value=='')
		{
		alert("You must provide your state");
		vf.state.focus();
		return false;
		}
		
	if (vf.zipCode.value=='')
		{
		alert("You must provide your zip code");
		vf.zipCode.focus();
		return false;
		}
	
	var myString = vf.email.value;
	var newString = myString.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)
	if (!newString) {
		alert(myString + " is not a valid e-mail address!");
		vf.email.focus();
		vf.email.select();
		return false;
	}
	
	if (bolContinue){
		bolContinue = false;
		return true;
	}
	else{
		alert('Please wait while we process your request...');
		return false;
	}	

}

// View workouts function
//-----------------------------------------------------------------------------------------
function viewWorkouts(logID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/MEMBERS/TRAININGPLAN/viewWorkouts.asp?logID='+logID,'sendWorkouts','top='+ih+'px,left='+iw+'px,width=300px,height=215px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=0,resizable=0');
}

// TP POPUP function
//-----------------------------------------------------------------------------------------
function tpPopup(eventDate){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('tpPopup.asp?eventDate='+eventDate,'tpPopup','top='+ih+'px,left='+iw+'px,width=500px,height=310px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=0');
}

//*****************************************************************************************
// ADMIN SITE JS FUNCTIONS
//*****************************************************************************************

// Admin login function
//-----------------------------------------------------------------------------------------
function verifyLogin(vf){
	//Make sure username & password was provided
	if(vf.username.value==""||vf.password.value==""){
		alert('Please provide your username & password');
		vf.username.select();
		vf.username.focus();
		return false;
	}
}

// Update window function
//-----------------------------------------------------------------------------------------
function updateWindow(pageName,memberID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/'+pageName+'.asp?memberID='+memberID,'update','top=100px,left=100px,width=400px,height=150px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
}

// Update window function
//-----------------------------------------------------------------------------------------
function updateWindowWithDate(pageName,memberID, day, month, year, version ){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/'+pageName+'.asp?memberID='+memberID+'&day='+day+'&month='+month+'&year='+year+'&version='+version,'update','top=100px,left=100px,width=400px,height=150px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
}

// Update group for event function
//-----------------------------------------------------------------------------------------
function updateGroup(pageName,memberID,eventDate,vargroup){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/'+pageName+'.asp?memberID='+memberID+'&eventDate='+eventDate+'&group='+vargroup,'update','top=100px,left=100px,width=400px,height=150px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
}

// hard code result function
//-----------------------------------------------------------------------------------------
function hardCodeResult(pageName,memberID,resultID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/NEWTESTS/POPUPS/'+pageName+'.asp?memberID='+memberID+'&resultID='+resultID,'update','top=100px,left=100px,width=400px,height=170px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
}

// Update event type
//-----------------------------------------------------------------------------------------
function updateEventType(pageName,eventID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/'+pageName+'.asp?eventID='+eventID,'update','top=100px,left=100px,width=400px,height=150px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
}

// Clear radio button value
//------------------------------------------------------------------------------------------
function clearRadio(radioObject){

	for(i=0;i<radioObject.length;i++)radioObject[i].checked=false
}

// Get radio button value
//------------------------------------------------------------------------------------------
function getRadioValue(radioObject){
	var value = radioObject.value
	for (var i=0; i<radioObject.length; i++){
		if (radioObject[i].checked) 
		{
		value = radioObject[i].value
		break; 
		}
	else{
		value = ""
		}
	}
	
	return value;
}

// Modify result function
//-----------------------------------------------------------------------------------------
function memberInfo(memberID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/MEMBERS/POPUPS/memberInfo.asp?memberID='+memberID,'memberInfo','top='+ih+'px,left='+iw+'px,width=518px,height=430px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// Add Workout function
//-----------------------------------------------------------------------------------------
function addWorkout(eventTypeID,varWeek,varVersion,workoutNum){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/WORKOUTS/addWorkout.asp?eventTypeID='+eventTypeID+'&week='+varWeek+'&version='+varVersion+'&workoutNum='+workoutNum,'addWorkout','top='+ih+'px,left='+iw+'px,width=540px,height=430px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// Update Type & Testing function
//-----------------------------------------------------------------------------------------
function updateTypeTesting(eventTypeID,varWeek,varVersion,workoutNum){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/WORKOUTS/updateTypeTesting.asp?eventTypeID='+eventTypeID+'&week='+varWeek+'&version='+varVersion+'&workoutNum='+workoutNum,'utt','top='+ih+'px,left='+iw+'px,width=300px,height=225px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}


// View Race function
//-----------------------------------------------------------------------------------------
function viewRace(raceID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/CREATEPLAN/viewRace.asp?raceID='+raceID,'viewRace','top='+ih+'px,left='+iw+'px,width=300px,height=250px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// Delete workout function
//-----------------------------------------------------------------------------------------
function deleteWorkout(tpID,eventTypeID,varWeek,varVersion,workoutNum){
	if(confirm('Are you sure you want to delete this workout?')){
		if(confirm('ARE YOU SURE?')){
			parent.document.location = 'default.asp?delete='+tpID+'&eventTypeID='+eventTypeID+'&week='+varWeek+'&version='+varVersion+'&workoutNum='+workoutNum;
		}
	}
}

// Update workout function
//-----------------------------------------------------------------------------------------
function updateWorkouts(){
	if(confirm('Are you sure you want to update these workouts')){
		parent.list.form1.update.value = 1;
		parent.list.form1.submit();
	}
}


// Test workouts function
//-----------------------------------------------------------------------------------------
function testWorkouts(){
	parent.list.form1.test.value = 1;
	parent.list.form1.submit();
}


// Delete week from workout function
//-----------------------------------------------------------------------------------------
function deleteWeek(){
	if(confirm('Are you sure you want to delete the last week?')){
		if(confirm('ARE YOU SURE?')){
			parent.list.form1.deleteWeek.value=1;
			parent.list.form1.submit();
		}
	}
}

// Get IDs and send to email.asp function
//-----------------------------------------------------------------------------------------
function emailit(){
	vf = document.form1;
		
	//build the URL
	var strurl='';
	
	for(i=0;i<vf.length;i++){
		if(vf[i].type == 'checkbox')
			if(vf[i].checked)
				strurl = strurl + vf[i].value + ';'
	}

	if(strurl != ''){
		window.open('/ADMIN/email.asp?IDS='+strurl, 'email', 'top=100px,left=100px,width=560px,height=300px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
	}
}

// Get IDs and send to message.asp function
//-----------------------------------------------------------------------------------------
function msgit(){
	vf = document.form1;
		
	//build the URL
	var strurl='';
	
	for(i=0;i<vf.length;i++){
		if(vf[i].type == 'checkbox')
			if(vf[i].checked)
				strurl = strurl + vf[i].value + ';'
	}

	if(strurl != ''){
		window.open('/ADMIN/message.asp?IDS='+strurl, 'message', 'top=100px,left=100px,width=560px,height=300px,toolbar=no,menubar=no,location=no,status=no,directories=no,scrollbars=no')
	}
}

// Activate account function
//-----------------------------------------------------------------------------------------
function activate(memberID,ant,isc){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/PENDING/activate.asp?memberID='+memberID+'&ant='+ant+'&isc='+isc,'activateWindow','top='+ih+'px,left='+iw+'px,width=410px,height=415px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

function checkAll(varCheck){
 vf = document.form1;
 
 for(i=0;i<vf.length;i++){
   if(vf[i].type == 'checkbox'){
   vf[i].checked = varCheck
  }
  if(varCheck==true){readyvalue = false;}
  else{readyvalue=true;}
 }
}

// Update email function
//-----------------------------------------------------------------------------------------
function updateEmail(emailID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/EMAILS/email.asp?emailID='+emailID,'email','top='+ih+'px,left='+iw+'px,width=560px,height=270px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// View message function
//-----------------------------------------------------------------------------------------
function viewMessage(memberID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('/ADMIN/EMAILS/message.asp?memberID='+memberID,'message','top='+ih+'px,left='+iw+'px,width=560px,height=270px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}

// View upcoming members function
//-----------------------------------------------------------------------------------------
function showUpcomingMembers(memberIDs,eventType,eventTypeID,week,version){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('showUpcomingMembers.asp?eventTypeID='+eventTypeID+'&week='+week+'&version='+version+'&memberIDs='+memberIDs+'&eventType='+eventType,'showUpcomingMembers','top='+ih+'px,left='+iw+'px,width=435px,height=270px,toolbar=0,menubar=0,location=0,status=1,directories=0,scrollbars=1,resizable=1');
}

// View referrals function
//-----------------------------------------------------------------------------------------
function viewReferrals(memberID){
	var iw, ih;
	if (window.innerWidth == null){iw = document.body.clientWidth;ih=document.body.clientHeight;}
	else{iw = window.innerWidth;ih = window.innerHeight;}
	ih=ih/2-100;
	iw=iw/2-150;
	window.open('../POPUPS/referrals.asp?memberID='+memberID,'viewReferrals','top='+ih+'px,left='+iw+'px,width=435px,height=270px,toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,resizable=1');
}