var arItem=new Array();var indexSelected;var indexCounter=0;var addStatus=1;var deleteStatus=2;var updateStatus=3;function populateInitialCategories(){var F=document.step1.jsdata.value;document.step1.display.options.length=0;if(F!=""){var C=F.split("^");for(var B=0;B<C.length;B++){var A=C[B].split("~");var E=document.step1.display.length;var D=new Option("set "+indexCounter,indexCounter);document.step1.display.options[E]=D;arItem[indexCounter]=new objEntity(A[0],A[1],A[2],indexCounter,A[4],A[5],A[6],A[7]);indexCounter++}}clearValues();calculateYardage();calculateTime();buttonStatus(false,true,true)}function buttonStatus(B,A,C){document.step1.btnAdd.disabled=B;document.step1.btnUpdate.disabled=A;document.step1.btnDelete.disabled=C}function objEntity(C,E,H,D,B,F,A,G){this.type=C;this.stroke=E;this.distance=H;this.description=D;this.repetition=B;this.interval_minutes=F;this.interval_seconds=A;this.comment=G}function bld_js_array(strValue){var subStrings=strValue.split("^");for(x=0;x<subStrings.length;x++){var stringValue=subStrings[x].split("~");var tstring="new objEntity(";for(y=0;y<stringValue.length;y++){tstring=tstring+"'"+stringValue[y].toString()+"'";if(stringValue.length!=(y+1)){tstring=tstring+","}else{tstring=tstring+")"}}tbstring="arItem[";tbstring=tbstring+x.toString();tbstring=tbstring+"] = ";tfstring=tbstring+tstring;eval(tfstring)}}function editItem(B){if(B.value!=""){indexSelected=document.step1.display.selectedIndex;var A=locateArrayIndex();document.step1.type.value=arItem[A].type;document.step1.stroke.value=arItem[A].stroke;document.step1.distance.value=arItem[A].distance;document.step1.repetition.value=arItem[A].repetition;document.step1.interval_minutes.value=arItem[A].interval_minutes;document.step1.interval_seconds.value=arItem[A].interval_seconds;document.step1.comment.value=arItem[A].comment;buttonStatus(false,false,false)}}function locateArrayIndex(){var C=document.step1.display.options[indexSelected].value;var A="";for(var B=0;B<arItem.length;B++){if(typeof (arItem[B])!="undefined"){if(C==arItem[B].description){A=B;break}}}return A}function addItem(){typeIndexSelected=document.step1.type.selectedIndex;strokeIndexSelected=document.step1.stroke.selectedIndex;var A=document.step1.type.options[typeIndexSelected].value;var H=document.step1.stroke.options[strokeIndexSelected].value;var B=document.step1.distance.value;var I="set "+indexCounter;var F=document.step1.repetition.value;var G=document.step1.interval_minutes.value;var C=document.step1.interval_seconds.value;var D=document.step1.comment.value;if(B==""){alert("you must enter a Distance!");document.step1.distance.select();document.step1.distance.focus()}else{if(F==""){alert("you must enter the Repetition!");document.step1.repetition.select();document.step1.repetition.focus()}else{if(G==""&&C==""){alert("you must enter an interval!");document.step1.interval_minutes.select();document.step1.interval_minutes.focus()}else{var J=document.step1.display.length;var E=new Option(I,indexCounter);document.step1.display.options[J]=E;arItem[indexCounter]=new objEntity(A,H,B,indexCounter,F,G,C,D);indexCounter++;clearValues();calculateYardage();calculateTime();deselectList();buttonStatus(false,true,true)}}}}function updateItem(){typeIndexSelected=document.step1.type.selectedIndex;strokeIndexSelected=document.step1.stroke.selectedIndex;var E=document.step1.type.options[typeIndexSelected].value;var C=document.step1.stroke.options[strokeIndexSelected].value;var H=document.step1.distance.value;var D=document.step1.repetition.value;var F=document.step1.interval_minutes.value;var B=document.step1.interval_seconds.value;var G=document.step1.comment.value;if(H==""){alert("you must enter a Distance!");document.step1.distance.select();document.step1.distance.focus()}else{if(D==""){alert("you must enter the Repetition!");document.step1.repetition.select();document.step1.repetition.focus()}else{if(F==""&&B==""){alert("you must enter an interval!");document.step1.interval_minutes.select();document.step1.interval_minutes.focus()}else{var A=locateArrayIndex();arItem[A].type=E;arItem[A].stroke=C;arItem[A].distance=H;arItem[A].repetition=D;arItem[A].interval_minutes=F;arItem[A].interval_seconds=B;arItem[A].comment=G;clearValues();calculateYardage();calculateTime();deselectList();buttonStatus(false,true,true);document.step1.display.blur()}}}}function deleteArrayElement(){var C=arItem.length;var B=locateArrayIndex();var A=delete arItem[B]}function deleteItem(){deleteArrayElement();document.step1.display.options[indexSelected]=null;clearValues();calculateYardage();calculateTime();deselectList();buttonStatus(false,true,true)}function clearValues(){document.step1.type.selectedIndex=0;document.step1.stroke.selectedIndex=0;document.step1.distance.value="";document.step1.repetition.value="";document.step1.interval_minutes.value="";document.step1.interval_seconds.value="";document.step1.comment.value=""}function bldServerList(){var C="";for(i=0;i<arItem.length;i++){if(typeof (arItem[i])!="undefined"){var E=arItem[i].type;var I=arItem[i].stroke;var A=arItem[i].distance;var H=arItem[i].description;var F=arItem[i].repetition;var G=arItem[i].interval_minutes;var B=arItem[i].interval_seconds;var D=arItem[i].comment;if(i==0){C=C+E;C=C+"~";C=C+I;C=C+"~";C=C+A;C=C+"~";C=C+H;C=C+"~";C=C+F;C=C+"~";C=C+G;C=C+"~";C=C+B;C=C+"~";C=C+D}else{C=C+"^";C=C+E;C=C+"~";C=C+I;C=C+"~";C=C+A;C=C+"~";C=C+H;C=C+"~";C=C+F;C=C+"~";C=C+G;C=C+"~";C=C+B;C=C+"~";C=C+D}}}document.step1.jsdata.value=C;document.step1.totalDistance.disabled=false}function deselectList(){for(var A=0;A<document.step1.display.length;A++){document.step1.display.options[A].selected=false}}function calculateYardage(){var B=0;for(var A=0;A<arItem.length;A++){if(typeof (arItem[A])!="undefined"){B=B+(arItem[A].distance*arItem[A].repetition)}}document.step1.totalDistance.value=B}function calculateTime(){var C=0;var D=0;var G=0;var F=0;var B=0;for(var A=0;A<arItem.length;A++){if(typeof (arItem[A])!="undefined"){F=arItem[A].interval_seconds;if(F==""){F=0}B=arItem[A].interval_minutes;if(B==""){B=0}D=(parseInt(F)+(parseInt(B)*60));G=arItem[A].repetition*D;C=C+G}}var E=sec2ms(C);document.step1.totalTime.value=E}function sec2ms(D){var C="";var A=Math.floor(D/3600);if(A>0){C+=A+":"}else{C+="00:"}var B=Math.floor((D/60)%60);B=B.toString();if(B.length<2){B="0"+B}C+=B+":";var E=Math.floor(D%60);E=E.toString();if(E.length<2){E="0"+E}C+=E;return C}function moveUp(C){if(C.length==-1){alert("There are no values which can be moved!")}else{var E=C.selectedIndex;if(E==-1){alert("You must select an entry to be moved!")}else{if(C.length==0){alert("There is only one entry!\nThe one entry will remain in place.")}else{if(E==0){alert("The first entry in the list cannot be moved up.")}else{var D=locateArrayIndex();var G=C[E-1].text;var B=C[E-1].value;var F=C[E].text;var A=C[E].value;C[E].text=G;C[E].value=B;C[E-1].text=F;C[E-1].value=A;arItem=moveUp2();deselectList()}}}}}function moveDown2(){modArray=arItem;index=locateArrayIndex();if(index==0){return modArray}modArray.splice(index-1,2,modArray[index],modArray[index-1]);return modArray}function moveUp2(){modArray=arItem;index=locateArrayIndex();if(index>modArray.length-2){return modArray}modArray.splice(index,2,modArray[index+1],modArray[index]);return modArray}function moveDown(C){if(C.length==-1){alert("There are no values which can be moved!")}else{var D=C.selectedIndex;if(D==-1){alert("You must select an entry to be moved!")}else{if(C.length==0){alert("There is only one entry!\nThe one entry will remain in place.")}else{if(D==C.length-1){alert("The last entry in the list cannot be moved down.")}else{var F=C[D+1].text;var E=C[D].text;var B=C[D+1].value;var A=C[D].value;C[D].text=F;C[D].value=B;C[D+1].text=E;C[D+1].value=A;arItem=moveDown2();deselectList()}}}}}function goTo(A){document.location=A}function validateRegister(F){var G=F.emailAddress.value;var C=/^\w+.*@(\w|-)+(\.\w+)+$/;if(F.firstName.value==""){alert("You must enter your first name!");F.firstName.focus();return false}if(F.lastName.value==""){alert("You must enter your last name!");F.lastName.focus();return false}var E=false;var D=F.elements.gender;for(var A=0;A<D.length;A++){if(D[A].checked){E=true;break}}if(!E){alert("You must choose your gender!");return false}if((F.birthMonth.value.length!=2)||(F.birthDay.value.length!=2)||(F.birthYear.value.length!=4)){alert("You must enter your birth date in the format of mm/dd/yyyy!");F.birthMonth.focus();return false}if(F.emailAddress.value==""){alert("You must enter your e-mail address!");F.emailAddress.focus();return false}if(!C.test(G)){alert(G+" is an invalid e-mail address!");F.emailAddress.select();F.emailAddress.focus();return false}if(F.countryId.selectedIndex==0){alert("You must select your country!");F.countryId.focus();return false}if(F.city.value==""){alert("You must enter your city!");F.city.focus();return false}if(F.zipCode.value==""){alert("You must enter your zip code!");F.zipCode.focus();return false}if(F.distanceTypeId.selectedIndex==0){alert("You must select your measurement type!");F.distanceTypeId.focus();return false}var B=checkArray(F,"background[]");if(B.length==0){alert("You must select your swimming background!");return false}if(F.contribute.selectedIndex==0){alert("You must select whether or not your wish to contribute to Dynoswim.com!");F.contribute.focus();return false}if(F.password.value==""){alert("You must enter your password!");F.password.focus();return false}if(F.confirmPassword.value==""){alert("You must enter enter your confirm password!");F.confirmPassword.focus();return false}if(F.password.value!=F.confirmPassword.value){alert("Your password and confirm password must match!");F.confirmPassword.focus();return false}}function checkArray(D,E){var A=new Array();for(var B=0;B<D.elements.length;B++){var C=D.elements[B];if(C.type=="checkbox"&&C.name==E&&C.checked){A.push(C.value)}}return A}function validateLogin(A){if(A.emailAddress.value==""){alert("You must enter your e-mail address!");A.emailAddress.focus();return false}if(A.password.value==""){alert("You must enter your password!");A.password.focus();return false}}function validateContact(B){var C=B.emailAddress.value;var A=/^\w+.*@(\w|-)+(\.\w+)+$/;if(B.name.value==""){alert("You must enter your name!");B.name.focus();return false}if(B.emailAddress.value==""){alert("You must enter your e-mail address!");B.emailAddress.focus();return false}if(!A.test(C)){alert(C+" is an invalid e-mail address!");B.emailAddress.select();B.emailAddress.focus();return false}if(B.comment.value==""){alert("You must enter your comment!");B.comment.focus();return false}}function validateStep1(A){if(A.workout_name.value==""){alert("You must enter your workout name!");A.workout_name.focus();return false}if(A.pool_type.selectedIndex==0){alert("You must select your pool type!");A.pool_type.focus();return false}if(A.workout_category.selectedIndex==0){alert("You must select your workout category!");A.workout_category.focus();return false}}function validateStep2(A){var A=document.step1;if(A.type.selectedIndex==0){alert("You must select your set type!");A.type.focus();return false}if(A.stroke.selectedIndex==0){alert("You must select your stroke!");A.stroke.focus();return false}if(A.repetition.value==""){alert("You must enter your repetition!");A.repetition.focus();return false}if(A.distance.value==""){alert("You must enter your distance!");A.distance.focus();return false}if(A.interval_seconds.value==""){alert("You must enter your interval!");A.interval_seconds.focus();return false}addItem()}function validateChangePassword(A){if(A.currentPassword.value==""){alert("You must enter your current password!");A.currentPassword.focus();return false}if(A.newPassword.value==""){alert("You must enter enter your new password!");A.newPassword.focus();return false}if(A.confirmNewPassword.value==""){alert("You must enter enter your confirm new password!");A.confirmNewPassword.focus();return false}if(A.newPassword.value!=A.confirmNewPassword.value){alert("Your new password and confirm new password must match!");A.newPassword.focus();return false}}function validateEvent(A){if(A.tShirtSize.selectedIndex==0){alert("You must select your t-shirt size!");A.tShirtSize.focus();return false}}function validateComment(A){if(A.comment.value==""){alert("You must enter a comment in the comment field!");A.comment.focus();return false}};