function k$(str) {
	if(document.getElementById(str)) {
		return document.getElementById(str);
	}
	else return undefined;
}
function dteSearchFocus() {
	if(k$('dteSearchTxt').value == 'search for dog trials here') {
		k$('dteSearchTxt').value = '';
	}
}
function dteSearchBlur() {
	if(k$('dteSearchTxt').value == '') {
		k$('dteSearchTxt').value = 'search for dog trials here';
	}
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   if ((sText.length==0) ||
	   (sText==null))
   {
   	  IsNumber=false;
   }
   else
   {
   		for (i = 0; i < sText.length && IsNumber == true; i++)
   		   {
   		   Char = sText.charAt(i);
   		   if (ValidChars.indexOf(Char) == -1)
   		      {
   		      IsNumber = false;
   		      }
   		   }
   		return IsNumber;
   }
   return IsNumber;
}

// moved from selTrial.php
function dte_waiverset() {
	if (document.trialinfo.getWaiver.checked==true)
	{
	    alert('Thank you. Your agreement to the waivers and releases has been noted. Enjoy the event.');
	}else
	{
	    alert('Please agree to the waivers and releases to enter this event.');
	}
	
}

// jmb
function IsPswd(sText) 
{
  // quotes, ampersands, commas, and < > etc. are not allowed. Tildi is ok.
  // ValidChars is what is allowed.
   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%_";
   var IsPswd=true;
   var Char;
   if ((sText.length<4) ||
	   (sText==null))
   {
   	  IsPswd=false;
   }
   else
   {
   		for (i = 0; i < sText.length && IsPswd == true; i++)
   		   {
   		   Char = sText.charAt(i);
   		   if (ValidChars.indexOf(Char) == -1)
   		      {
   		      IsPswd = false;
   		      }
   		   }
   		return IsPswd;
   }
   return IsPswd;
}
// jmb
function IsText(sText) 
{
  // quotes, ampersands, commas, and < > etc. are not allowed. Tildi and backtic(by tildi on keyboard) are ok.
  // ValidChars is what is allowed.
   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#$_~`";
   var IsText=true;
   var Char;
   if ((sText.length<1) ||
	   (sText==null))
   {
   	  IsText=false;
   }
   else
   {
   		for (i = 0; i < sText.length && IsText == true; i++)
   		   {
   		   Char = sText.charAt(i);
   		   if (ValidChars.indexOf(Char) == -1)
   		      {
   		      IsText = false;
   		      }
   		   }
   		return IsText;
   }
   return IsText;
}

function IsAsName(sText) 
{
  // quotes, ampersands, commas, and < > etc. are not allowed. Tildi and backtic(by tildi on keyboard) are ok.
  // ValidChars is what is allowed.
   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_~`- ";
   var IsText=true;
   var Char;
   if ((sText.length<1) ||
	   (sText==null))
   {
   	  IsText=false;
   }
   else
   {
   		for (i = 0; i < sText.length && IsText == true; i++)
   		   {
   		   Char = sText.charAt(i);
   		   if (ValidChars.indexOf(Char) == -1)
   		      {
   		      IsText = false;
   		      }
   		   }
   		return IsText;
   }
   return IsText;
} // end IsAsName


// ******** begin - hide button functionality **********
function dte_setHide()
{
  // ** Hide div sections that end in Profile ** //
  // **  Set div section buttion text to SHOW ** // 
  // $("div [id$=Profile]").hide();
   
   
 
   $("div [id$=helpProfile]").hide();           // ** hide  help,  ** // 11/8/2010
   
   $("div [id$=helpProfileBtn]").each(function() {
      var btnValueThis=$(this).attr("value");           
      var btnIdLength=$(this).attr("Id").length;        
      btnValueThis = 'Show' + btnValueThis.substr(4);
      $(this).attr({value: btnValueThis});
   });
   
   $("div [id$=trialInfoProfile]").hide();           // ** hide  info,  ** // 11/8/2010
   
   $("div [id$=trialInfoProfileBtn]").each(function() {
      var btnValueThis=$(this).attr("value");           
      var btnIdLength=$(this).attr("Id").length;        
      btnValueThis = 'Show' + btnValueThis.substr(4);
      $(this).attr({value: btnValueThis});
   });

   // *** DOES NOT WORK IN IE7 (syntax is probably bad) *** ///
   //$('#eventTable input, select, textarea').filter('[id*=tev]').attr(
   //  {value: '', title: 'Required', class: 'fred'}
   // ).show();
   
   //$('#tev_name').focus();
   
   //  ** PopUp Window Example **
   //  DesignerWizWin=window.open(
   //  'pageIssues.php','DogTrialEntry - HELP ','toolbar=0, location=0,directories=0, menuBar=0,scrollbars=1, resizable=1,width=400,height=380,left=200, top=50'
   //  );
}
 $(function(){                                          // *** Button is used to hide    ** //
    $("input[type=button]").click(function (e) {        // *** indivial sections of      ** //
      // id=NoHidexxxxxx shuts off Hide/Show logic
      if ($(this).attr("id").substr(0,6) == 'noHide') 
      { return; } // noHide buttons excluded 5/2011 jmb (AKC)
      var btnValueThis=$(this).attr("value");           // *** form. Each of which are   ** //
      var divIdThis=$(this).attr("Id");                 // *** a div with a coresponding ** //
      var btnIdLength=$(this).attr("Id").length;        // *** name to the button.       ** //
      var divIdThis=$(this).attr("Id").substr(0,btnIdLength-3);
      divIdThis="#"+divIdThis;                          // manufacture Id of div section
      if ($(this).attr("value").substr(0,4) == 'Hide')  // *** built in seperate tables *** //
      { 
         btnValueThis = 'Show' + btnValueThis.substr(4);
         $(this).attr({value: btnValueThis});
      }else{
         btnValueThis = 'Hide' + btnValueThis.substr(4);
         $(this).attr({value: btnValueThis});
      }
      $(divIdThis).toggle(250, function(){
        $(' td:first input', this).select();
      });
    });
 });
// ******** end - hide button functionality **********

//**********************************************************************

function toDisplay(i) {
  // look up and display judges bio here
  // AJAX will need be used I believe

   var id=i.substring(0,i.indexOf('-'));
   id=id*1; // get pa_id and make it a number
   judgeInfo = '';

  // Temp fix 11/20/09
  if (id=='3')
  {
      j =  "Cheryl Jagger Williams lives with her husband Richard in Hop Bottom, Pa. \n\n";
      j += "Annually, for 28 years, the Pa. State Championship SDT in Hop Bottom, Pa has been her home town event. ";
      j += "They have now winter in Branford, Florida and have a trial there. \n\n";

      j += "Cheryl has been training border collies and trialing for close to 30 years, ";
      j += "each year qualifying her dogs for the USBCHA national finals. ";
      j += "She has  placed in several finals and she keeps her dogs consistently ";
      j += "in the top rankings of the USBCHA. Cheryl has been Champion and/or Reserve Champion ";
      j += "in both high points and the Finals several times in the Northeast Border Collie Assc. \n\n";

      j += "Cheryl comes highly qualified to sort out the runs at the Lazy~J classic. ";
      j += "She has provided judging/trialing training clinics annually for many aspiring judges ";
      j += "resulting in several more open judges for the trialing community. \n\n";

      j += "Cheryl herself has a plethora of judging experience. She has judged many open trials ";
      j += "including the Bluegrass,  the On the Lamb ranch in New Mexico, Ewesful Acres in Ontario, ";
      j += "and trials in Okeechobee, and elsewhere. \n\n ";

      j += "We thank her for accepting the judging responsibilities for the 2010 Lazy~J Classic and ";
      j += "we again welcome her to our farm.\n\n";

      judgeInfo = j;
      alert(judgeInfo);
  }
  else
  {
     id = id*1; // ensure id is numeric or query will not work
     bio_filtered = '';
     var jg_url =  'ajaxBioResults.php?jgId=' + id;
     // ** Ajax get of bio info
     $.get(
         jg_url,
         function(bio_Data)
         {
            bracketPos   = bio_Data.length; // find last bracket
            bio_filtered = bio_Data.substr(0,bracketPos-2);
            bio_filtered = bio_filtered.replace(/\\r\\n/g, " \n ")
            bio_filtered = bio_filtered.replace(/\\"/g, "'")
            alert(bio_filtered.substring(12));
         },
         "json"
     );

  } // end if(id==3)
}  // function toDisplay(i)


