// *********************************************************
// VIN.js is copyrighted Veterinary Information Network 2004
// *********************************************************

var agt = navigator.userAgent.toUpperCase();
var BrowserVersion = parseInt(navigator.appVersion);
if (agt.indexOf('MSIE 5')) BrowserVersion = 5;
var IsMac = ((agt.indexOf('MAC_') != -1) || (agt.indexOf('MACINTOSH') != -1));
var IsAOL = (agt.indexOf('AOL') != -1);
var IsIE  = (navigator.appName.indexOf('Microsoft') != -1);
var IsNS  = (navigator.appName.indexOf('Netscape') != -1);
var IsNS4 = (IsNS && (BrowserVersion >= 4));
var IsIE4 = (IsIE && (BrowserVersion >= 4));
var IsIE5  = (IsIE && (BrowserVersion >= 5));
var IsDOM = (BrowserVersion >= 5);

var CtrlTxt = (IsMac) ? 'Command' : 'CTRL';
var FavoriteTxt = (IsIE) ? 'Favorite' : 'Bookmark';

var Months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var Days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var CurDate = new Date();
var WeekDay = CurDate.getDay();
var Day = CurDate.getDate();
var Month = CurDate.getMonth();
var Year = CurDate.getYear();
Year = (Year < 1900) ? Year + 1900 : Year;

function CleanDocTitle(Title) {
  if (window.RegExp) {
    var rExp = /[\\\/\:\*\?\"\|\<\>]/g;
    Title = Title.replace(rExp, " ")
    rExp = /  +/g;
    Title = Title.replace(rExp, " ")
  }
  return (Title);
}

function PrintPage() {
  if (((IsNS4 || IsIE5)) && (window.print)) window.print();
  else alert('You may print this page using '+CtrlTxt+'-P.');
}

function SavePage() {
  if (IsIE4 && !IsMac) document.execCommand('SaveAs', true, CleanDocTitle(document.title));
  else alert('You may save this page by selecting the Save As option from the File menu.');
}

function BackPage() {
  history.back();
}

function BookmarkPage() {
   if (IsAOL) alert('Please click the red heart to favorite this page.');
   else if (IsIE4 && !IsMac) window.external.AddFavorite(window.location.href, CleanDocTitle(document.title));
   else alert('You may '+FavoriteTxt+' this page using '+CtrlTxt+'-D.');
}

function GetCenterPos(BWidth, BHeight) {
  var PosX = (screen.availWidth - 10)/2 - BWidth/2;
  var PosY = (screen.availHeight - 30)/2 - BHeight/2;
  return ('width='+BWidth+',height='+BHeight+',left='+PosX+',top='+PosY);
}

function ShowSizedWindow(URL, Width, Height, WndName) {
  if (!WndName) WndName = '_blank'
  var args = 'width='+Width+',height='+Height+',menubar=no,status=no,location=no,directories=no,toolbar=no';
  window.open(URL, WndName, args); 
}

function OpenNewWindow(URL, Width, Height) {
  var args = 'menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes';
  if (Width && Height) args = 'width='+Width+',height='+Height + ',' + args;
  window.open(URL, '_blank', args);
}

function OpenNewBrowser(URL, Width, Height) {
  var args = '';
  if (Width && Height) args = 'width='+Width+',height='+Height;
  window.open(URL, '_blank', args);
}

function ShowPicture(ImgPath, ImgWidth, ImgHeight, Branding) {
  var ScrollBar = "no";
  ImgWidth += 20;
  ImgHeight += 50;
  if (Branding==1) ImgHeight += 10;
  if ((ImgWidth - 20) > screen.availWidth) {ImgWidth = screen.availWidth - 20; ScrollBar = "yes";}
  if ((ImgHeight - 40) > screen.availHeight) {ImgHeight = screen.availHeight - 40; ScrollBar = "yes";}
  var URL = "/Tools/ShowPicture.plx?URL="+ImgPath;
  if (Branding) URL += '&B='+Branding;
  if (!Branding && ImgWidth<335) ImgWidth = 335;
  var args = GetCenterPos(ImgWidth, ImgHeight)+",menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars="+ScrollBar+",resizable="+ScrollBar;
  window.open(URL, "", args); 
}

function ShowRemote() {
  ShowMyVIN()
}

function ShowMyVIN(Page) {
  var URLValue = "/Members/Tools/MyVIN.plx";
  if (Page) URLValue += '?Page='+Page;
  var args = "top=1,width=500,height=400,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=no,resizable=no";
  window.open(URLValue, "MyVIN", args); 
}

function ShowFeedback(EmailTo, Subject) {
  var URLValue = "/Members/Help/FeedbackPopup.asp";
  var args = "width=370,height=370,menubar=no,status=no,location=no,directories=no,toolbar=no";
  if (EmailTo || Subject) {
    URLValue += "?";
    if (EmailTo) URLValue += "EmailTo="+EmailTo+"&";
    if (Subject) URLValue += "Subject="+escape(Subject)+"&";
  }
  window.open(URLValue, "_blank", args); 
}

function ShowUnityInstall(Room) {
  var URLValue = "/VINChat/Steps.asp";
  if (Room) URLValue += '?Room='+Room;
  var args = GetCenterPos(450, 300)+",width=450,height=300,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes";
  window.open(URLValue, "_blank", args); 
}

function LaunchUnity(Room) {
  var PosX = screen.availWidth - 810;
  var PosY = 0;
  RoomName = Room.replace('-','_'); //Steve added this, hyphens were breaking the open script.
  window.open('http://www.vin.com/Members/Unity/Unity.plx?R='+Room, 'VINUnity_'+RoomName, 'left='+PosX+',top='+PosY+',width=800,height=550,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=no,resizable=yes');
}

function SwapImg(Tab, ImgNo) {
  if (Tab == '') return;
  if (Tab == CurrentTab && ImgNo == 1) ImgNo = 3;
  var TabSrc = eval('document.Tab'+Tab+'.src');
  var NewSrc = TabSrc.substring(0, TabSrc.indexOf('.gif') - 1)+ImgNo+'.gif';
  eval('document.Tab'+Tab+'.src = NewSrc');
}
