﻿function objById(id)
{
  if (document.getElementById)
    var returnVar = document.getElementById(id);
  else if (document.all)
    var returnVar = document.all[id];
  else if (document.layers)
    var returnVar = document.layers[id];
  return returnVar;
}
function ow(id, url, opt)
{
  window.open(id, url, opt);
}
// phd pet selection
function pchk(id,pfx,msg)
{
  var chk = objById(id);
  if (chk != null)
  {
    if (chk.checked==true)
    { 
       // checking
       var b = false;
       var cnt = 0;
       var i = 0;
       var el;
       do
       {
         el = objById(pfx + "chkIsPetPhd" + i);
         if (el == null)
         {
           b = true;
         }
         else if (el.checked == true && el.id != chk.id)
         {           
           cnt++;
         }
         i++;
       } while (b==false);
       if (cnt >= 3)
       {
         alert("You already have three pets enrolled for the PHD.");
         chk.checked = false;
         return;         
       }    
    }
    else
    {  
      // unchecking
      if (msg != null)
      {
        var c = confirm(msg);
        if (c==false) 
        { 
          chk.checked = true;
        }
      }    
    }
  }
  return true;
}
function checkTipFrm()
{
    var frm = document.forms['aspnetForm'];
    if (frm.petType.selectedIndex==0)
    {
      alert("Please select a pet type.");
      frm.petType.focus();
      return false;
    }
    if (trim(frm.TipTitle.value) == "")
    {
      alert("Please enter a tip title.");
      frm.TipTitle.focus();
      return false;
    }
    if (trim(frm.Tip.value) == "")
    {
      alert("Please enter a tip.");
      frm.Tip.focus();
      return false;
    }
    if (frm.Tip.value.length > 600)
    {
      alert("Your tip exceeds 600 characters (" + frm.Tip.value.length + "), please reduce the size and try again");
      frm.Tip.focus();
      return false;
    }    
    return true;
}
function trim(str) {
  //trims leading and trailing spaces
  str = this != window ? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function fixPetImg(p,i)
{
  if (p==1)
  {
    i.src="img/home/outline_cat.gif";
  }
  else
  {
    i.src="img/home/outline_dog.gif";  
  }
}
function scrollToPetDiv(){
    document.all.petDiv.scrollIntoView(true);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function viewTerm(file)
{
	window.open(file,'img','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=675,height=600');
}
