// ==========    index.asp scripts =============================

//This function validates the login form.
//Function used to validate form data
function checklogon(thisform)
{

	//Validates user name
	if(thisform.txtUserName.value=="")
		{
			alert("Please enter a User Name.")
			thisform.txtUserName.focus()
			return false;
		}
		
	// there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
//	var sInput = thisform.txtUserName.value
//    var i = 1;
//    var sLength = sInput.length;

    // look for @
//    while ((i < sLength) && (sInput.charAt(i) != "@"))
//    { i++
//    }
	
//    if ((i >= sLength) || (sInput.charAt(i) != "@")) {
//		alert("Please enter a valid User Name.")
//		thisform.txtUserName.focus()
//		return false;
//	}
//    else {i += 2;}
	
    // look for .
//    while ((i < sLength) && (sInput.charAt(i) != "."))
//    { i++
//    }

    // there must be at least one character after the .
//    if ((i >= sLength - 1) || (sInput.charAt(i) != ".")) {
//		alert("Please enter a valid User Name.")
//		thisform.txtUserName.focus() 
//		return false; 
//	}

	//Checks for blank password
	if(thisform.txtPassword.value=="")
		{
			alert("Please enter a password.")
			thisform.txtPassword.focus()
			return false;
		}

}


// ==========    account_detailsindex.asp =============================


//This function validates the login form.
//Function used to validate form data
function checkAccount(thisform)
{

	//Checks for blank organization name
	//if(thisform.txtOrganization.value=="")
	//	{
	//		alert("Please enter a organization.")
	//		thisform.txtOrganization.focus();
	//		return false;
	//	}

  //Checks to see if a check box is checked
  // JY 08/22/2005 : This checks to make sure the required field is populated
  if(document.all("hidIAmA").value == "0000" || document.all("hidIAmA").value == ""){
    alert("Please complete the \"I am a:\" section.") ;
    thisform.chkIAmA(0).focus();//added 10/09/2009
    return false ;
  }
		
	//Checks for blank address1
	if(thisform.txtOrgAddress1.value=="")
		{
			alert("Please enter the organization address1.")
			thisform.txtOrgAddress1.focus();
			return false;
		}
		
	//Checks for blank organization city
	if(thisform.txtOrgCity.value=="")
		{
			alert("Please enter the organization city.")
			thisform.txtOrgCity.focus();
			return false;
		}
		
	//Checks for blank organization state
	if(thisform.cboOrgState.options.selectedIndex==0)
		{
			alert("Please select the organization state.")
			thisform.cboOrgState.focus();
			return false;
		}
		
	//Checks for blank organization zip
	if(thisform.txtOrgZip.value=="")
		{
			alert("Please enter the organization zip code.")
			thisform.txtOrgZip.focus();
			return false;
		}

	//Checks for blank Organization Contact First Name
	if(thisform.txtFirstName.value=="")
		{
			alert("Please enter the organization contact first name.")
			thisform.txtFirstName.focus();
			return false;
		}
		
	//Checks for blank Organization Contact Last Name
	if(thisform.txtLastName.value=="")
		{
			alert("Please enter the organization contact last name.")
			thisform.txtLastName.focus();
			return false;
		}

	//Checks for blank Organization Contact Address1
	if(thisform.txtContactAddress1.value=="")
		{
			alert("Please enter the organization contact address1.")
			thisform.txtContactAddress1.focus();
			return false;
		}

		
	//Checks for blank Organization Contact Organization City
	if(thisform.txtContactCity.value=="")
		{
			alert("Please enter the organization contact organization city.")
			thisform.txtContactCity.focus();
			return false;
		}
		
	//Checks for blank Organization Contact Organization State
	if(thisform.cboContactState.options.selectedIndex==0)
		{
			alert("Please select the organization contact state.")
			thisform.cboContactState.focus();
			return false;
		}
		
	//Checks for blank Organization Contact Organization Zip Code
	if(thisform.txtContactZip.value=="")
		{
			alert("Please enter the organization contact zip code.")
			thisform.txtContactZip.focus();
			return false;
		}
	
	//Checks for blank Organization Contact Organization Work Phone
	if(thisform.txtContactWorkPhone.value=="")
		{
			alert("Please enter the organization contact work phone.")
			thisform.txtContactWorkPhone.focus();
			return false;
		}		
		

	//Validates password
	if(thisform.txtEmail.value=="")
		{
			alert("Please enter the organization contact e-mail.")
			thisform.txtEmail.focus();
			return false;
		}
		
	// there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
	var sInput = thisform.txtEmail.value
    var i = 1;
    var sLength = sInput.length;

    // look for @
    while ((i < sLength) && (sInput.charAt(i) != "@"))
    { i++
    }
	
    if ((i >= sLength) || (sInput.charAt(i) != "@")) {
		alert("Please enter a valid e-mail address.")
		thisform.txtEmail.focus();
		return false;
	}
    else {i += 2;}
	
    // look for .
    while ((i < sLength) && (sInput.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (sInput.charAt(i) != ".")) {
		alert("Please enter a valid e-mail address.") 
		thisform.txtEmail.focus();
		return false; 
	}
	
		
	//Checks for blank Organization Contact Password
	if(thisform.txtPassword.value=="")
		{
			alert("Please enter a organization contact password.")
			thisform.txtPassword.focus();
			return false;
		}
		

}


function checkAccountName(thisform)
{

	//Checks for blank organization name
	if(thisform.txtOrganization.value=="")
		{
			alert("Please enter an organization name.")
			thisform.txtOrganization.focus();
			return false;
		}
}


function chkBoxSelections() {
  var sCheckValues = "" ;
  for(i=0;i<document.all("chkIAmA").length;i++) {
    if(document.all("chkIAmA")[i].checked == true) {
      sCheckValues = sCheckValues + "1" ; }
    else {
      sCheckValues = sCheckValues + "0" ;
    }
  }//end for loop
  document.all("hidIAmA").value = sCheckValues ;
}


function gotoEventDetails(eventID) {
  if(eventID == ""){
    alert("You must choose an event if you want to add a team.");
    return false ;
  }
  
  document.all("EventID").value = eventID ;
  
  document.all("frmEvents").action = "event_details.asp" ;
  document.all("frmEvents").submit() ;

}

//function addMaleFemale() {
//  var x = (document.all.txtFemales.value != '')?parseInt(document.all.txtFemales.value):0
//  var y = (document.all.txtMales.value != '')?parseInt(document.all.txtMales.value):0
//  var z = (document.all.txtCrossovers.value != '')?parseInt(document.all.txtCrossovers.value):0
//    
//  //lblTotal.innerHTML = x + y;
//  document.all("txtTotal").value = x + y ;
//  document.all("txtCosts").value = (x*curCost) + (y*curCost) + (z*curCrossover);
//}

function addMaleFemale() {
  var iFemales = (document.all.txtFemales.value != '')?parseInt(document.all.txtFemales.value):0
  var iMales = (document.all.txtMales.value != '')?parseInt(document.all.txtMales.value):0
  var iXFemales = (document.all.txtXFemales.value != '')?parseInt(document.all.txtXFemales.value):0
  var iXMales = (document.all.txtXMales.value != '')?parseInt(document.all.txtXMales.value):0
    
  //lblTotal.innerHTML = x + y;
  document.all("txtTotal").value = iFemales + iMales + iXFemales + iXMales;
  document.all("hidTotal").value = document.all("txtTotal").value;

  //Caluculate and write labels
  document.getElementById('lblTotalFirstTeam').innerHTML = iFemales + iMales;
  document.getElementById('lblTotalCrossovers').innerHTML = iXFemales + iXMales;
  document.getElementById('lblTotalFirstTeamCost').innerHTML = (iFemales + iMales) * document.getElementById('hidIndividualRate').value;
  document.getElementById('lblTotalCrossoverCost').innerHTML = (iXFemales + iXMales) * document.getElementById('hidCrossoverRate').value;
  document.getElementById('lblTotalCombinedCost').innerHTML = parseInt(document.getElementById('lblTotalFirstTeamCost').innerHTML) + parseInt(document.getElementById('lblTotalCrossoverCost').innerHTML);
}


function onlyDigits(e) {
	var _ret = true;
	if (window.event.keyCode < 46 || window.event.keyCode > 57)
	{
	window.event.keyCode = 0;
	_ret = false;
	}
return (_ret); 
}

// ==========    team_details.asp =============================


//This function validates the team details form.
//Function used to validate form data
function checkTeamDetails(thisform)
{

  addMaleFemale() ;

	//Checks for blank team nickname
	if(thisform.txtTeamNickName.value=="")
		{
			alert("Please enter a team nickname.")
			thisform.txtTeamNickName.focus();
			return false;
		}
		
	//Checks for blank division
	if(thisform.txtDivision.value=="")
		{
			alert("Please enter a division.")
			thisform.txtDivision.focus();
			return false;
		}
		
	//Checks for entry of female/male entry
	if(thisform.txtFemales.value==0 && thisform.txtMales.value==0)
		{
			alert("Please enter the number of female and/or male participants.")
			thisform.txtFemales.select()
			thisform.txtFemales.focus();
			return false;
		}
	
	return true;
	//Checks for blank crossovers entry
	//10192009 Crossovers are not necessary
//	if(thisform.txtCrossovers.value=="")
//		{
//			alert("Please enter the number of crossover participants.")
//			thisform.txtCrossovers.select()
//			thisform.txtCrossovers.focus();
//			return false;
//		}
}


function deleteTeam() {
  if(confirm("Are you sure you want to DELETE?")){
    document.all("hidMode").value = 3 ;
    document.frmTeamDetails.submit() ; }
  else {
    return false ;
  }
}

function changeFormAction(objForm,strAction) {
	objForm.action = strAction;
	objForm.submit();
}
  




function modifyInvoice(sInvoiceNumber) {
  var theElement = document.all("chkPaid_"+sInvoiceNumber) ;
  document.all("hidInvoiceNumber").value = sInvoiceNumber ;

  if(theElement.checked == true) {
    document.all("hidPaidValue").value = 1 ; }
  else {
    document.all("hidPaidValue").value = 0 ;
  }

  document.all("frmInvoiceListing").action = "_invoice_processing.asp" ;
  document.all("frmInvoiceListing").submit() ;
}  

function popup(where,w,h) {
  var myURL    = where
  var myName   = "NewWindow"
  var myWidth  = w
  var myHeight = h
  var myLeft   = (screen.width/2) - (myWidth/2)
  var myTop    = screen.height/2 - (myHeight/2)
  var myFeat   = 'scrollbars=0,resizable=1,toolbar=0,left='+myLeft+',top='+myTop+',width='+myWidth+',height='+myHeight
  myWindow = window.open(myURL,myName,myFeat);
}
