function showF(){
$('#f').toggle('slow');
}

function showMsg(responseText, statusText, xhr, $form){
 $('#msg').fadeIn(1000);
 $('#msg').fadeOut(4000);
}

function showMsgCart(msg){
	$('#msg').html(msg);
	$('#msg').fadeIn(1000);
 $('#msg').fadeOut(4000);
	
	}


function showResponse(responseText, statusText, xhr, $form){
$('#pageFoot').remove();
   }


function wakoko(){
	
var c = $('#selectSchool option:selected').text();
var v = $('#selectSchool').val();
if(v!=0){
    $('#napili').empty();
	$('#napili').append('<span id="for">For : </span>'+c);
 }
}


function removeTeam(id,t){
 if(confirm("Are you sure you want to delete this Team? All Athletes on this team will also be deleted")){
    var rand = Math.floor(Math.random() * (1000 - 3 + 1) + 3);
	var a = '<span id="add_'+rand+'">'+t+' &nbsp;&nbsp;<a href="#i" onclick="addTeam('+rand+',\'Girls Track\')" title="1">Add</a><br /></span>';
						
    $.post("ajax.php", {teamid: id, 'do': 'removeTeam'},function(data){
	$('#del_'+id).remove();
	$('#n').append(a);
	showMsg();
	   });
  }
}


function addTeam(userid,id,t){
	
	alert(t);
	
$.post('ajax.php', {teamname: t, userid: userid,  'do': 'addTeam'},function(data){
	  
	   if(data==1){
		 alert("Sorry This Team is no longer available");   
	   }else{
		   
	   $('#add_'+id).remove();
	   $('#e').append(data);
	   showMsg();
	   }
	    });
}


function deleteRoster(id){
 if (confirm("Are you sure you want to delete this Roster? All athletes under this roster will also be deleted")){
	     $.post("ajax.php", {teamid: id, 'do': 'removeTeam'});
		 $('#roster_'+id).remove();
	      }
}


function padDigit(n) 
    { 
	   var totalDigits = 2;
	   n = n.toString();
	   n = n.replace('.',''); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    }
	
function padD(n){
  var totalDigits = 2;
	   n = n.toString();
	   n = n.replace('.',''); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return n.toString()+pd;
}


function removeDot(str){
 var ret  = str.replace('.','');
 
 return ret;
}

function addMeet(id,meet,t){
var ar = t.replace('s','');
var add = '<p class="remove'+t+'Meet" id="'+t+'del_'+id+'" onclick="removeMeet('+id+',\''+meet+'\',\''+t+'\')" title="Remove '+meet+'" >'+meet+'<input type="hidden" name="'+ar+'[]" value="'+id+'" /></p>';
$('#'+t+'HolderDelete').append(add);
$('#'+t+'add_'+id).remove();	
}

function addDiv(id,dn){
var con = $('#divA_'+id).html();
var add = '<p class="removeDiv" id="divR_'+id+'" onclick="removeDiv('+id+',\''+dn+'\')">'+con+'</p><input id="divRin_'+id+'" type="hidden" name="divisions[]" value="'+id+'" />';	
$('#divHolderDelete').append(add);	
$('#divA_'+id).remove();	
}

function addRelDiv(id,dn){
var con = $('#relDivA_'+id).html();
var add = '<p class="removeDiv" id="divRelR_'+id+'" onclick="removerelDiv('+id+',\''+dn+'\')">'+con+'</p><input id="divRelRin_'+id+'" type="hidden" name="reldivisions[]" value="'+id+'" />';	
$('#relaysDivHolderDelete').append(add);	
$('#relDivA_'+id).remove();	
}

function removerelDiv(id,dn){
var con = $('#divRelR_'+id).html();	
var add = '<p class="addDiv" id="relDivA_'+id+'" onclick="addRelDiv('+id+',\''+dn+'\')">'+con+'</p>';
$('#relaysDivHolderAdd').append(add);
$('#divRelR_'+id).remove();
$('#divRelRin_'+id).remove();
}

function removeMeet(id,meet,t){
var add ='<p class="add'+t+'Meet" id="'+t+'add_'+id+'" onclick="addMeet('+id+',\''+meet+'\',\''+t+'\')">'+meet+'</p>';
$('#'+t+'HolderAdd').append(add);
$('#'+t+'del_'+id).remove();	
}id="rosteronly"

function removeDiv(id,dn){
var con = $('#divR_'+id).html();	
var add ='<p class="addDiv" id="divA_'+id+'" onclick="addDiv('+id+',\''+dn+'\')">'+con+'</p>';
$('#divHolderAdd').append(add);
$('#divR_'+id).remove();
$('#divRin_'+id).remove();	
}


function modalSeed(){
$('#tt_event').html($('#relay option:selected').text());

$("#at").modal({
	maxHeight:180,
	maxWidth: 320
});
}

function showD(id){
$('#showD_'+id).modal({
       maxHeight:120,
  	   maxWidth: 320
	
	});
	
	}


function increase(t){
	$('#increase'+t).modal({
		maxHeight:180,
  	   maxWidth: 320
		});

	}


function editAth(id){
	$('#f_'+id).modal({
	maxHeight:480,
	maxWidth: 400
});
  }
  
function updateAth(id){
 $.post('ajax.php',{'do':'updateAth','d':$('#formid_'+id).serialize()},function(data){
      $('#repAth_'+id).html(data);
	  $.modal.close();
	  showMsg();
		});
	}

function alisin(id){
if(confirm("Are you sure you want to remove this event ?")){
	  $('#del_'+id).remove();
	  $('#meetEntries').submit();
  }else{
	return	
	}
}


function showNo(){
	if($('#no').is(':checked')){
		$("#yes").removeAttr("checked");
		$("#noNote").modal({
				maxHeight:150,
				maxWidth: 320
			});
	}
}

function addD(id, athlete){
$('#athleteName').html(athlete);
$('#aid').val(id);
$("#cDivs").modal({
	maxHeight:130,
	maxWidth: 320
});
}

function closeModal(){
var id = $('#aid').val();
$("#ath_"+id).removeAttr("checked");
$("#no").removeAttr("checked");
$.modal.close();
}

function eEdiv(id){
var athlete = $('#ath_'+id).attr('rel');
addD(id,athlete);
}

function displayRelayTeam(v){
var mid = $('#ids').attr('alt');
	var rid = $('#ids').val();
	 if(v!=0){
		  $.post('ajax.php',{'do':'relayTeams','relay_id':v, 'mid':mid, 'rid':rid},function(data){
    		  $('#displayTeams').html(data);
			  });
  
	  }
	}

//meetid,rosterid,athleteid,cols
function delRelay(id,aid){
	 if( confirm("Are you sure you want to remove this relay?")){
		$.post('ajax.php',{'do':'removeRelay','id':id,'aid':aid},function(data){
		  if(data == 1){
			 $('#del_'+id+'_'+aid).remove();	
			}
			
			});
			
	 }else{
	 return false;
	 }
}

function toggleChecked1(status) {
$("#NO input").each( function() {
$(this).attr("checked",status);
})
}



function compare(cl,id){
 
 if($("#id_"+id).attr("checked")==true){
  $('form#YES input').not($("."+cl)).attr('disabled','disabled');
	 
  }else{
	var n =$('.'+cl+':checkbox:checked').length;
     if(n==0){	
	   $('form#YES input').not($("."+cl)).removeAttr('disabled');
	 }
  }
 	
}



function archive(id){
if(confirm("Are you sure you want to archive this transaction? This will mark the athlete as unpaid for the selected item")){
     $.post('ajax.php',{'id':id,'do':'archive'},function(data){
	      if(data ==1){
		    $('#ra_'+id).remove();
			showMsg();		
		 	}//else do nothing
		});
 }
	return false;
	
	}
function urchive(id){

	 $.post('ajax.php',{'id':id,'do':'unarchive'},function(data){
	        if(data ==1){
		      $('#rau_'+id).remove();		
		 	}//else do nothing
		});

	return false;
	
	
	}

function showTransaction(id){
	$('#sb_'+id).modal({maxHeight:340,maxWidth:320});
	}

function editItem(id){
$('#itm_'+id).modal({maxHeight:340,maxWidth:320});
return false;
	
	}


function reviewEntries(){$('form#athletes').submit();}


//START ON READY FUNCTIONS 
$(document).ready(function(){
$('#girlsIncrease').click(function(){
	var maxt = $(this).attr('name');
	var val = $('#girls_max').val();
	var event_id = $('#event_id').val();
  $.post('ajax.php',{'do':'increaseGirls','maxt':maxt,'val':val,'id':event_id},function(data){
        if(data ==1){
			location.reload(true);
		}else{
		alert(data);
		}
	  });
  });	
	
$('#boysIncrease').click(function(){
	
	var maxt = $(this).attr('name');
	var val = $('#boys_max').val();
	var event_id = $('#event_id').val();
  $.post('ajax.php',{'do':'increaseBoys','maxt':maxt,'val':val,'id':event_id},function(data){
    	if(data ==1){
			location.reload(true);
		}else{
		alert(data);
		}
	  });
 
  });	
	



$('#meetEntries').ajaxForm({success:showMsg});
//add new athlete	

$('.add').click(function(){
	var id = $(this).attr('id');
	location.href = "index.php?view=manage&action=athletes&school="+id
	});
	


$('.setEvent').click(function (e) {
      var t = $(this).attr('id'); 
	$('td').removeClass('current'); 
	$('#cur_'+t).addClass('current');
	$('#app_'+t).append ($('#content_event'));
   	$('#add_'+t).show();
	return false;
	});



$('.addMark').click(function(){
	   var id = $('.addMark').closest("tr").attr("id");
	   var et = $(this).attr('title');
	   var ei = $(this).attr('id');
	   $('#aid').val(id);
	   $('#eid').val(ei);
	   $('#et').val(et);
	   $('#t_event').empty().append(et);
	   $("#am").modal({
	maxHeight:190,
	maxWidth: 320
});
	return false;
	//alert(id);
});


$('.addTime').click(function(){
       var id = $('.addTime').closest("tr").attr("id");
	   var et = $(this).attr('title');
	   var ei = $(this).attr('id');
	   $('#taid').val(id);
	   $('#teid').val(ei);
	   $('#tet').val(et);
	   $('#tt_event').empty().append(et);
  $("#at").modal({
	maxHeight:190,
	maxWidth: 320
});
return false;


});


$('#addMark').submit(function(){
	var rand = String((new Date()).getTime()).replace(/\D/gi,'');
	var eventId = $('#eid').val();
	var athlete_id = $('#aid').val();
	var D = removeDot($('#et').val()) + ' - ';
	var V = removeDot($('#feet').val())+'-'+removeDot($('#inches').val())+'.'+removeDot($('#fraction').val());
	  if (V=='-.00'){var V = 'ND';}
		
    var S = athlete_id.split("_");
	var hiddenF = '<span id="del_'+rand+'" class="del" title="Remove this event" onclick="alisin('+rand+')"><input type="hidden" name="event['+eventId+']['+S[1]+']" value="'+V+'" />'+D+V+'</span>' ;
	$('#elist_'+S[1]).append(hiddenF);
	$.modal.close();
	$('#meetEntries').submit();
	return false;
	 
	});
	

$('#addTime').submit(function(){
	var rand = String((new Date()).getTime()).replace(/\D/gi,'');
	var eventId = $('#teid').val();
	var athlete_id = $('#taid').val();
	var S = athlete_id.split("_");
	var H = removeDot($('#hr').val());
	var TT = removeDot($('#tt').val());
	  if (H==''){H=00;}
	  if (TT==''){TT=00;}
	var D = $('#tet').val() + ' - '; 
	var V = padDigit(H)+':'+padDigit($('#min').val())+':'+padDigit($('#sec').val())+'.'+padD(TT);
	
	     if (V=='00:00:00.00'){var V ='NT';}
	
	
	
	
    var hiddenF = '<span id="del_'+rand+'" class="del" title="Remove this event" onclick="alisin('+rand+')"><input type="hidden" name="event['+eventId+']['+S[1]+']" value="'+V+'" />'+D+V+'</span>' ;
	$('#elist_'+S[1]).append(hiddenF);
	$.modal.close();
	$('#meetEntries').submit();
	return false;
	
	});


$('.del').click(function(){
	var id = $(this).attr('id');
	if(confirm("Are you sure you want to remove this event ?")){
	  $('#'+id).remove();
	  $('#meetEntries').submit();
   }else{
	return	
	}
	});
	

	
	
$('.lahat').click(function(){
	var l = $(this).attr('href');
		 if(confirm("Are you sure you want to delete all athletes from this meet? This will also unregister this roster from the meet")){
		     location.href = l;
			 return true;	  
		  }else{
		  
		  return false;
		  }
	
		
	
	});

$('#for').click(function(){$('#forgotForm').show();});

$('#delAthletes').click(function(){
	   	if(confirm("Are you sure you want to delete all athletes in this Roster? This cannot be undone")){
		alert('uu');
		return false;	
		}else{
		alert('ooohh hindi!');
		return false;
		}
	
		});
	
$('.unregister').click(function(){
		var l = $(this).attr('href');
	 if(confirm("Are you sure you want to unregister from this meet? All Athlete information in this meet will be deleted.")){
		     location.href = l;
			 return true;	  
		  }else{
		     return false;
		  }
});
	
$('#searchUsersSuper, #searchTransaction').ajaxForm({target:'#userOutput',success:showResponse}); 
$('.searchField').click(function(){$(this).val('');});


$('#submitNew').click(function(){
var email = $('#email').val();
var	password = $('#password').val();
$.post("ajax.php", {'email':email, 'password':password, 'do': 'checkuser'},
  function(data){
      if(data==1){
		$('#meronna').append('<label class="error" >This email already exsist. You must specify a different password to use this email for this account</label> ');
		 
	}else{
	   $('#newUser').submit();
		  
	  }
   });
   return false;
   
});


//CHECK IF USERNAME EXISTS
$('#email').click(function(){
	$('#email').val('');
	$('#meronna').empty();
	$('#email_error').empty();
	});
	
$('#email2').click(function(){
	$('#email2').val('');
	$('#confirm_error').empty();
	});	


//Validate
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");





	$("table1").tablesorter({sortList: [[0,0]] });
	$("table.roster").tablesorter({sortList: [[3,0], [1,0], [0,0]] });
	$("table.meets").tablesorter({sortList: [[1,1], [0,0]] });
	
	$(".table, #sel").tablesorter();
	
		
	$("#superUser").tablesorter({headers: { 0: {sorter: false}} }); 
	
$("#rValid, #newUser, #nAccount").validate({
		rules: {
			        email: {required: true, email: true},
		    email_confirm: {equalTo: "#email"},
			     password: {required: true}, 
		 password_confirm: {equalTo: "#password"},
		  phone:{required: true,phoneUS: true},
	     mobile:{required: true,phoneUS: true}
		  }
	});

$("#requireValid").validate();




/// HETO UNG VALIDATION WAG I ISKIP
$('#sdata').click(function(){
var checked = $("#nAccount input:checked").length > 0;
if($('#selectClass').val()==0){
   alert("Please select your school class");
   
}else if($('#selectSchool').val()==0){
   	 alert ('Please Select A School Name');  
	 return false;
  
}

if(!checked){
      $('#wala').show();
	  return false;
   }else{
	$('#nAccount').submit();
   }
});//end ng click


$("#forgot").validate({
rules: {email: {required: true, email: true}}
});

	
$("#payment_info, #schoolAdd, #email_select").validate();


$('#accountContact').click(function(){
	
	var email = $(this).attr('class');
	window.location.href = 'mailto:'+email+'?subject=Track Roster Account';
	
	});



function cc(){
	
	var fields = $('form#formSuperUser').serializeArray(); 
	   if (fields.length == 0){ 
           alert('No item selected'); 
		   return false;
        }else{
 		   return true;
		}
}

$('#act_delete').click(function(){
   
 if(cc()){
   	
	if(confirm("Are you Sure You Want To Delete user/users. This wll also delete the user's Roster")){
		return true;
	}else{
	   return false; 	
	}
   }else{
	return false;   
   }
	
	});


$('#act_edit').click(function(){
  if(cc()){
	return true;	
  }else{
	return false;  
  }
  
  })



$('.delRoster').click(function(){
	var id = $(this).closest("div").attr("id");
	  if(confirm("Are you sure you want to remove this Roster?")){
		$('#'+id).remove();
	}else{
	  return false;	
	}
});

	//CHECK ALL
	
	$('#lahatAh').click(function(){
		 if ($('#lahatAh').attr('checked')){
		     $('form#formSuperUser input:checkbox').each(function() {
			this.checked = true;
		}); 
		 
		 }else{
			 
			 $('form#formSuperUser input:checkbox').each(function() {
			this.checked = false;
			 });
		 }
		
		
		
		});
	
	
	$('a#select_all').click(function() {
		$('form#athletes input:checkbox').each(function() {
			this.checked = true;
		});
	});
	$('a#select_none').click(function() {
		$('form#athletes input:checkbox').each(function() {
			this.checked = false;
		});
	});
	$('form#athletes, form#events, form#NO, form#YES, form#email_select').submit(function() {
		var check = false;
		$('input:checkbox').each(function() {
			if(this.checked)
				check = true;
		});
		
		if(!check) {
			alert('You must select at least one entry.');
			return false;
		}
	})
	$('form#payment_info').submit(function() {
		var response = '';
		$.ajax({ type: "GET", url: "includes/validate.php?ccn="+$('form#payment_info input#credit_card_num').val()+"&expm="+$('form#payment_info select#exp_month').val()+"&expy="+$('form#payment_info select#exp_year').val()+"&csc="+$('form#payment_info input#csc').val(), async: false, success : function(text) { response = text; } });
		
		if(response == "false") {
			alert('You must enter a valid Mastercard, Visa, Discover Card, or American Express number.  Also, make sure a valid expiration date and CSC number is provided.');
			return false;
		}
	});

$('input#birthday').datepicker({
	                  changeYear:true,
					  changeMonth:true,
					  yearRange: "-40:+1" 
					  
					  });

$('input#date, input#deadline').datepicker({
	                  changeYear:true,
					  changeMonth:true,
					  yearRange: "-1:+2" 
					  });

$("#schools").attr("size", function(){return 30});

$('#seeded').click(function(){
if ($('#seeded').attr('checked')){
//alert('wakoko');

$('#event').addClass("required");

}
  });
  
$('#rosteronly').click(function(){
if ($('#rosteronly').attr('checked')){
     $('#event').removeClass("required");
   }
});


/*UPDATE ACCOUNT ROUTINES SIYET ANG ARTE KASI*/ 
$('#updateStatus').click(function(){
	var id = $(this).attr('class');
	var status = $('#status').val();
	$.post('ajax.php',{id:id ,status:status, 'do':'updateStatus'},function(data){
		showMsg();
	  });
  return false;
	});


$('#updateAccess').click(function(){
	var id = $(this).attr('class');
	var access = $('#access').val();
	$.post('ajax.php',{id:id ,access:access, 'do':'updateAccess'},function(data){
		showMsg();
		 
	  });
  return false;
	});


$('#updateEmail').click(function(){
	 	
     var email = $('#email').val();
	 var email2 = $('#email2').val();
	 var id = $('#id').val();
	 
     $('#email_error, #confirm_error').empty();
	 
	 $.post("ajax.php", {id:id, email: email, email2: email2, 'do': 'updateEmail'},function(data){
	  if(data==1){
			$('#email_error').append('Email Not Valid'); 
		 }else if(data==2){
			$('#confirm_error').append('Please enter the same value'); 
		 }else if(data==3){
			 $('#email_error').append('Email Already Exsist'); 
		 }else if (data==4){
			$('#initemail').val(email);
			$('#email, #email2').val('');
			showMsg(); 
		 }else{
			 $('#email_error').append('Please Enter New Email'); 
		 }
	  });
	 return false;
});

$('#phone, #mobile').click(function(){
	$('#phone, #mobile').val('');
	$('#phone_error, #mobile_error').empty();
	});


$('#updatePhone, #updateMobile').click(function(){
	var id = $('#id').val();
	var what = $(this).attr('rel');
     $('#'+what+'_error').empty();
  if (what == 'phone'){
	 var  phone = $('#phone').val();
	}else{
	  var phone = $('#mobile').val();
	}
   
   if (phone==''){
	   $('#'+what+'_error').append('No '+what+ ' number specified');	
   }else{
	   
	$.post("ajax.php", { id:id,phone: phone, type: what,  'do': 'updatePhone'},function(data){
     if(data ==1){
		$('#'+what+'_error').append('Please specify a valid '+what+ ' number');	
		}else{
		showMsg();
          $('#ex_'+what).val(phone);  		
    	}
	   
	   });
      
  }
     
   
	});

$('#updateName').click(function(){
	var what = $(this).attr('rel');
	var first = $('#first').val();
	var last = $('#last').val();
	var ex_first = $('#ex_first').val();
	var ex_last = $('#ex_last').val();
	var id = $('#id').val();
		
	if(first==''){var first =  ex_first;}
	if(last==''){var last = ex_last;}	
  $.post("ajax.php", {id:id, first: first, last: last,  'do': 'updateName'},function(data){
	 if(data==1){
		  showMsg();
		  $('#ex_first').val(first);
		  $('#ex_last').val(last);
	   }else{
		alert(data);  
	  }	  
	  });  
	  
	 return false; 
});




$('.deleteAccount').click(function(){

var userid = $(this).attr('id');

if (confirm("Are you sure you want to delete this account?All rosters and athletes under the rosters will also be deleted")){
	   $.post("ajax.php",{'userid': userid, 'do':'removeAccount'},function(data){
		    $('#del_'+userid).remove();
		   });
	   
	   
}else{
return false	
};
  
});

$('#updateCode').click(function(){
	$('#code_error').empty();
    var schoolid = $(this).attr('class');
	var id = $('#id').val();
	var team_code = $('#team_code').val();
	var tabclass = $('#class').val();
	var access_code = $('#access_code').val();
       if(team_code==''){
		$('#code_error').append('Please Enter A Team Code');   
	   }else{
		$.post("ajax.php", {id:id,  'class': tabclass, access_code:access_code, team_code: team_code,schoolid:schoolid, 'do': 'updateCode'},function(data){
		    showMsg();
							});
	   }
	//return false;
	});

$('#updatePassword').click(function(){
	$('#password_error').empty();
	var p1 = $('#password').val();
	var p2 = $('#password2').val();
	var id = $('#id').val();
	 if(p1 == p2){
		 $.post("ajax.php", {id:id, password: p1, 'do': 'updatePassword'});
		 showMsg();
	 }else{
	  $('#password_error').append('Passwords Did Not Match');
	 }
return false;
	});


$('#addSchool').click(function(){
	var school = $('#school').val();
	  $.post("ajax.php",{school:school,'do':'checkSchool'},function(data){
		   if(data==1){
			 alert(school +'Already Exist');
			 return false;   
		   }else{
			   $('#schoolAdd').submit();
			 return true;
		   }
		  
		  });
	
	
	return false;
	
	});


$('#selectClass').change(function(){
var classd = $(this).val();
 if(classd !=0){
    
  
  
   $('#selSchool, #napili').empty();
	$('#loader').show();
	 
	$.post("ajax.php",{'class': classd, 'do':"getSchools"},function(data){
		 $('#loader').hide();
		 $('#selSchool').append(data);
		 });			
  }
});

//KUNG SEEDED XA 

$('#seeded').click(function(){$('#ifseeded').show();});
$('#rosteronly').click(function(){$('#ifseeded').hide();});

//MODAL PARA SA SEED RELAY 

$('#relay').change(function(){
var v = $(this).val();
var mid = $('#ids').attr('alt');
var rid = $('#ids').val();
$('#relaySeed').val('0').attr('disabled','disabled');
$('#relaydivision').val('0').attr('disabled','disabled');
if(v !=0){
	$.post('ajax.php',{'do':'relayDivs','mid':mid,'rid':rid},function(data){
		if(data=='wala'){
			  alert("No relay division specified for this relay. Please choose a team");
	         displayRelayTeam(data);	
		}else{
		  $('#displayDivs').html(data);	
		}
		});
 }

});

$('#addRelayTime').click(function(){

	var H = removeDot($('#hr').val());
	var TT = removeDot($('#tt').val());
	  if (H==''){H=00;}
	  if (TT==''){TT=00;}
	var V = padDigit(H)+':'+padDigit($('#min').val())+':'+padDigit($('#sec').val())+'.'+padD(TT);
	  $('#relay_seed').val(V);
      $('#addRelay').submit();	
	
	})


$('#mgaRelays label').click(function(){
	var rd = $(this).attr('class');
	var leg = $(this).attr('for');
	$('#mgaAthletes #id').val(rd);
	$('#mgaAthletes #leg').val(leg);
	$("#mgaAthletes").modal({
	maxHeight:180,
	maxWidth: 320
});
});

/* heto pag ung input ang na clkick ska na 
$('#mgaRelays input').click(function(){alert("wakoako");});
*/

$('#addLeg').submit(function(){
	var rd = $('#mgaAthletes #id').val();
	var leg = $('#mgaAthletes #leg').val();
	var aid = $('#athleteS').val();
	if(aid!=0){
    $.post('ajax.php',{'do':'leg','id':rd,'leg':leg,'aid':aid},function(data){
	    $('#'+leg+'_'+rd).val($('#athleteS option:selected').text());	
		$.modal.close();
		showMsg();
		});
	}
	return false;
});


$('.delRelay').click(function(){
	var id = $(this).attr("id");
	if(confirm("Are You sure you want to delete this relay entry")){
	 $.post('ajax.php',{'do':'deleteRelay','id':id},function(data){
		   $('#relay'+id).remove();
		   showMsg();
		});	
	return false;
	}else{
	return false;	
	}
	});
	
	
$('.aDiv').change(function(){
	var id = $(this).val();
	var athlete = $(this).attr('rel');
     if($(this).attr('checked')){
	   addD(id,athlete);
	  }else{
		 $.post('ajax.php',{'do':'removeAthleteMeet',
		                    'id':id,
						   'rid':$('#roster_id').val(),
						   'mid':$('#meet_id').val()},function(data){
							  if(data==1){
							   $('#divid_'+id).empty();
							   }else{
							   alert(data);
							   }
							  })  
		  
	  }
});



$('.bDiv').change(function(){
if($(this).attr('checked')){

$("#cDivs1").modal({
	maxHeight:130,
	maxWidth: 320
});
   $(this).removeAttr('checked');
  }
});



$('.cDiv').change(function(){
if($(this).attr('checked')){

$("#cDivs2").modal({
	maxHeight:130,
	maxWidth: 320
});
   $(this).removeAttr('checked');
  }
});

$('#add_division').submit(function(){
	if($('#divi').val()==0){
    alert("Please select a division");	
}else{
	

var id = $('#aid').val();
var valu =$('#divi').val().split(':');
var divs = '<span class="divStart"> '+valu[1]+'</div>';  
var txt = $('#divi option:selected').text();
var ito = '<input type="hidden" name="division['+id+']" value="'+valu[0]+'" /><span class="eDiv" id="eDiv_'+id+'" onclick="eEdiv('+id+')" title="Change Division">'+txt+' </span>'+divs; 
$('#divid_'+id).html(ito);
	$.modal.close();
	}
	return false;

});
	
$('#goClass').change(function(){
	var v = $(this).val();
	window.location = 'index.php?view=super&class='+v+'#tabs=3';
	});	

$('.goBtn').click(function(){
     window.location="yes.php?do="+$(this).attr('id'); 	
	});	
	
	
$(".tocart").click(function(){
 $.post('ajax.php',{'do':'addToCart','itemid':$(this).val(),'price':$(this).attr('name')},function(data){
	
	 $('#cartBar').html(data);
	 showMsgCart('Item Successfully Added To Cart');
	

	});	
});	
	
$('.subCart').click(function(){
	var id = $(this).attr('title');
	
   $.post('ajax.php',{'do':'subCart','id':id},function(data){
	   var d = data.split('::');
	   $('#itemRow_'+id).hide();
	   $('#cartBar').html(d[0]);
	   if(d[1]=='.00'){
		$(".total").html('<td colspan="2">No items in your cart</td>');
		$("#checkout").hide();
		   }else{
	   
	   $('#cartTotal').html(d[1]);
		   }
	   
	   
	   showMsgCart('Item Successfully Removed From Cart');
	   
   }); 	
	return false;
	});



});//end on ready function

$(function(){
  var tabs = $('#tabs'),
      tab_a_selector = 'ul.ui-tabs-nav a';
      tabs.tabs({ event: 'change' });
      tabs.find( tab_a_selector ).click(function(){
  
    var state = {},
           id = $(this).closest( '#tabs' ).attr( 'id' ),
          idx = $(this).parent().prevAll().length;    
		  state[ id ] = idx;
    $.bbq.pushState( state );
  });
   
  $(window).bind( 'hashchange', function(e) {
      tabs.each(function(){
      var idx = $.bbq.getState( this.id, true ) || 0;
      $(this).find( tab_a_selector ).eq( idx ).triggerHandler( 'change' );
    });
  })
  $(window).trigger( 'hashchange' );
  
});



