//--   JAVASCRIPT FOR AUCTION TICKET ORDER FORM  +++  SECTION 1  +++    ---------------------------------------------------------------------


//-- set focus when page loads  -------------------------------------------------------
document.youthticket.organization.focus();

//-- error messages  -------------------------------------------------------

//-- validate form on submission  -------------------------------------------------------
function validateInfo()
{	 

//-- clear previous error markers
//	for ( var i = 0; i < document.youthticket.elements.length-2; i++ )
//		{  document.youthticket.elements[ i ].style.backgroundColor = "";		}


	if ( document.youthticket.organization.value == '' )
	   {  document.youthticket.organization.style.backgroundColor = errcolor;
	      document.youthticket.organization.focus();
	      err_prompt( 'orgname', 'organization' );
		  return false;  }

	var fname =  document.youthticket.nameFirst.value;
	var lname =  document.youthticket.nameLast.value;
	
	var area =  document.youthticket.phonearea.value;
	var prefix =  document.youthticket.phoneprefix.value;
	var suffix =  document.youthticket.phonesuffix.value;
	
	var SMC = document.youthticket.SMCconcert.value;
	var SWC = document.youthticket.SWCconcert.value;
	var MW = document.youthticket.MWconcert.value;

	var noqty = false;
	var qtyfocus = null;
	var qtycnt = 0;

	if ( ( !fname ) && ( !lname ) )
	   {  document.youthticket.nameFirst.style.backgroundColor = errcolor;
		  document.youthticket.nameLast.style.backgroundColor = errcolor;
	      document.youthticket.nameFirst.focus();
	      err_prompt( 'contactName', 'nameFirst' );
		  return false;  }
	else
	  {
		if ( !fname )
		   {  document.youthticket.nameFirst.style.backgroundColor = errcolor;
			  document.youthticket.nameFirst.focus();
			  err_prompt( 'contactName', 'nameFirst' );
			  return false;  }

		if ( !lname )
		   {  document.youthticket.nameLast.style.backgroundColor = errcolor;
			  document.youthticket.nameLast.focus();
			  err_prompt( 'contactName', 'nameLast' );
			  return false;  }
	  }


	if ( ( !area ) && ( !prefix ) && ( !suffix ) )
	   {  document.youthticket.phonearea.style.backgroundColor = errcolor;
		  document.youthticket.phoneprefix.style.backgroundColor = errcolor;
		  document.youthticket.phonesuffix.style.backgroundColor = errcolor;
		  document.youthticket.phonearea.focus();
	      err_prompt( 'contactPhoneBlank', 'phonearea' );
		  return false;  }
	else
	  {
		if ( !area ) 
	     {  document.youthticket.phonearea.style.backgroundColor = errcolor;
			document.youthticket.phonearea.focus();
			err_prompt( 'phoneArea', 'phonearea' );
			return false;  }

		if ( !prefix ) 
	     {  document.youthticket.phoneprefix.style.backgroundColor = errcolor;
			document.youthticket.phoneprefix.focus();
			err_prompt( 'phonePrefix', 'phoneprefix' );
			return false;  }

		if ( !suffix ) 
	     {  document.youthticket.phonesuffix.style.backgroundColor = errcolor;
			document.youthticket.phonesuffix.focus();
			err_prompt( 'phoneSuffix', 'phonesuffix' );
			return false;  }
	  }


//	if ( document.youthticket.organization.value == '' )
//	   {  document.youthticket.organization.style.backgroundColor = errcolor;
//	      document.youthticket.organization.focus();
//	      err_prompt( 'orgname', 'organization' );
//		  return false;  }
//	
	var emailaddy = document.getElementById("email").value;
	
	//-- if [currfield] is empty 
	if ( !emailaddy ) 
	  {  document.youthticket.email.style.backgroundColor = errcolor;
	     document.youthticket.organization.focus();
	     document.youthticket.email.focus();
	     err_prompt( 'contactEmailBlank', 'email' );
	     return false;
	  }
	else
	  { //-- validate email address
	    var valid = validateEmail ( emailaddy );
		
		if ( !valid )
		  { document.youthticket.email.style.backgroundColor = errcolor;
	        document.youthticket.organization.focus();
	        document.youthticket.email.focus();
	        err_prompt( 'contactEmailInvalid', 'email' );
	        return false;
	      }
	  }



	
	//alert( '[' + SMC + '][' + SWC + '][' + MW + ']'  );
	
	if ( ( SMC == 'void' ) && ( SWC == 'void' ) && ( MW == 'void' ) )
		{ noqty = false;
		  qtycnt = 0; }
	else if ( ( !SMC ) && ( !SWC ) && ( !MW ) )
		{ noqty = true;
		  qtycnt = 3;
		  qtyfocus = 'SMC'; }
	else if ( ( SMC == 'void' ) && ( !SWC ) && ( !MW ) )
		{ noqty = true;
		  qtycnt = 2;
		  qtyfocus = 'SWC'; }
	else if ( ( !SMC ) && ( SWC == 'void' ) && ( !MW ) )
		{ noqty = true;
		  qtycnt = 2;
		  qtyfocus = 'SMC'; }
	else if ( ( !SMC ) && ( !SWC ) && ( MW == 'void' ) )
		{ noqty = true;
		  qtycnt = 2;
		  qtyfocus = 'SMC'; }
	else if ( ( SMC == 'void' ) && ( SWC == 'void' ) && ( !MW ) )
		{ noqty = true;
		  qtycnt = 1;
		  qtyfocus = 'MW'; }
	else if ( ( SMC == 'void' ) && ( !SWC ) && ( MW == 'void' ) )
		{ noqty = true;
		  qtycnt = 1;
		  qtyfocus = 'SWC'; }
	else if ( ( !SMC ) && ( SWC == 'void' ) && ( MW == 'void' ) )
		{ noqty = true;
		  qtycnt = 1;
		  qtyfocus = 'SMC'; }

	
	if ( noqty )
	   {  document.youthticket.organization.style.backgroundColor = errcolor;
	      document.youthticket.organization.focus();
	      document.getElementById(qtyfocus+'concert').focus();
	      if ( qtycnt == 1 )
	       {  err_prompt( 'noqty', qtyfocus+'concert' );  }
	      else //if ( qtycnt >= 2 )
	       {  err_prompt( 'concertmsg', qtyfocus+'concert' );  }
		  
		  return false;
		}


//-- notes not required
//	if ( document.youthticket.notes.value == '' )
//	   {  document.youthticket.notes.style.backgroundColor = errcolor;
//	      document.youthticket.notes.focus();
//	      err_prompt( 'notes', 'notes' );
//		  return false;  }


/*
	//-- if [currfield] is empty 
	if ( !OK ) 
	   {  document.youthticket.[currfield].style.backgroundColor = errcolor;
	      document.youthticket.[priorfield].focus();
	      document.youthticket.[currfield].select();
	      err_prompt( [currfieldmsg], '[currfield]' );
	      return false;
	   } // end if block  [ +currfield+  - empty fields ]
*/

	return true;

}	//-- end function  [ validateInfo ]




//-- validate email address  -------------------------------------------------------
//--  min req. for email is 6 chars, which are:  4 - alpha/numeric, 1 - at  '@' sign, and 1 - period
function validateEmail ( address )
{
	var toggle = true;

	if ( address == "" ) 
		{ toggle = false; }
	else
	{
		if ( ( address.indexOf("@") == -1 ) || ( address.indexOf(".") == -1 ) || ( address.length <6 ) )
			{	toggle = false;		}
	}
	
	return toggle;

}	//-- end function  [ validateEmail ]



function phonetab( currfield, currvalue )
{	
	var numlen = 3;
	
	if ( currfield == "phonesuffix" )	
		{  numlen = 4;	}

	var currlen = new String( currvalue );
	var currlen = currlen.length;
	var currlen = new Number( currlen );
	
	if ( currlen == numlen ) 
		{ 
			switch ( currfield )
				{		case "phonearea" :
								document.youthticket.phoneprefix.focus();
								break;
						case "phoneprefix" :
								document.youthticket.phonesuffix.focus();
								break;
						case "phonesuffix" :
								//document.auditionrequest.phoneext.focus();
								document.youthticket.email.focus();
								break;
				} //-- end switch block		
	
	}  //-- end if block

}	//-- end function  [ phonetab ]


