function Write_eMail(strUser,strDomain,strPrompt,strSubject,strBody,strSource) {
 // this script hides the email address from web bots and spiders
  if (strUser=='admin' && strDomain.length==0) {
    strDomain = 'hogbarn.com';
    strUser = 'mark';
  }
  var strRecipient = strUser + '@' + strDomain;
  if (strRecipient=='@') {strRecipient = '';}
  if (strPrompt.length==0) {var strPrompt = strRecipient;}
  if (strBody.length > 0) {
    if(navigator.appVersion.indexOf("PPC") != -1) {
      var strSubject = strBody;
      var strBody = '' }
     else {
      var strBody = '&body='+strBody
    } }
   else {var strBody = ''
  }
  if (strSource.length>0) {var strSubject = strSubject + ' (from ' + strSource + ')';}
//  document.write('<a href="mailto:' + strRecipient + '?subject=' + strSubject + strBody + '" onMouseOver="window.status=\'Send an e-mail\'; return true" onMouseOut="window.status=\'\'; return true">' + strPrompt + '<\/a>');
  document.write('<a href="mailto:' + strRecipient + '?subject=' + strSubject + strBody + '" onMouseOver="window.status=\'Send an e-mail\'; return true" onMouseOut="window.status=\'\'; return true">' + strRecipient + '<\/a>');
//  document.write('<a class="contact" href="mailto:' + strRecipient + '?subject=' + strSubject + strBody + '" onMouseOver="window.status=\'Send an e-mail\'; return true" onMouseOut="window.status=\'\'; return true">' + strPrompt + '<\/a>');
}

function redirectHome(displayFlag,homeAddress) {
  if (displayFlag) {
    document.write('<b>THIS IS A FRAME ELEMENT</b><br />' +
                'You will be redirected to the main frames page in a second...' +
                '<meta http-equiv="refresh" content="2; url=' + homeAddress + '">') 
  }
}

function framePrint(whichFrame){
 parent[whichFrame].focus();
 parent[whichFrame].print();
}

function displayPrintButton(whichFrame) {
 var quoteMark = String.fromCharCode(39);
 document.write('<div style="text-align:right;float:right;">' +
                ' <a href="#" onclick="framePrint(' + quoteMark + whichFrame + quoteMark + ')"' +
                '   onMouseOver="window.status=' + quoteMark + 'Print this page' + quoteMark + '; return true"' +
                '   onMouseOut="window.status=' + quoteMark + quoteMark + '; return true">' +
                '  <img height="13" alt="Print this page" src="../Images/print_window_sm.gif" align="right" vspace="2" border="0" />' +
                ' </a></div>');
}

function WinPop(url,winName,iWidth,iHeight,scroll) {
  if (iWidth == null) { iWidth = 680; }
  if (iHeight == null) { iHeight = 280; }
  if (scroll == null) { scroll = 'no'; }
  if (navigator.appName == 'Netscape') {
    iWidth = iWidth+20;
    iHeight = iHeight+20; }
   else {
    iWidth = iWidth+0;
    iHeight = iHeight+0;
  }
  window.open(url,'','scrollbars='+scroll+',toolbar=no,menubar=no,location=no,height='+iHeight+',width='+iWidth);
}

function DisplayDate(dtDate) { 
  if ( dtDate.length==0 ) {var now = new Date();} else {var now = new Date(dtDate);}  // Get today's current date
  var days = new Array('Sun','Mon','Tues','Wed','Thurs','Fri','Sat');
//  var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  var months = new Array('Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec');
//  var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
 // Calculate the number of the current day in the week.
  var date = ((now.getDate()<10) ? '0' : '')+ now.getDate();
 // Calculate four digit year.
  function fourdigits(number)	{ return (number < 1000) ? number + 1900 : number; }
 // Join it all together
  today =  days[now.getDay()] + ' ' +
           months[now.getMonth()] + ' ' +
           date + ', ' +
           (fourdigits(now.getFullYear())) ;
 // write the data. Concatenate with a string for type conversion.
  document.write('' +today);
}

function getMonthName(dtDate,lengthName) {
  if (lengthName=='long') {
    var months = new Array('January','February','March','April','May','June','July','Aug','September','October','November','December'); }
   else {
    var months = new Array('Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec');
  }
  return months[dtDate.getMonth()]
}

function formatPhoneNumber(phoneNumber,extension) {
  var strSeparator = '-';
  phoneNumber = phoneNumber.replace(/\ /g,'');
  phoneNumber = phoneNumber.replace(/\./g,strSeparator);
  phoneNumber = phoneNumber.replace(/\(/g,'');
  phoneNumber = phoneNumber.replace(/\)/g,strSeparator);
  phoneNumber = phoneNumber.replace(/\//g,strSeparator);
//  phoneNumber = phoneNumber.replace(/\-/g,strSeparator);
 // determine if there is any punctuation
  var testValue = left(right(phoneNumber,5),1);
  if (!isNaN(parseFloat(testValue)) && isFinite(testValue)) {
    var nLoopCounter = 1;
    for (var i=phoneNumber.length-1;i>=0;i--) {
      if (nLoopCounter==4) {phoneNumber = String(phoneNumber).substr(0,i) + strSeparator + String(phoneNumber).substr(i);}
      if (nLoopCounter==7 && phoneNumber.length > i) {phoneNumber = String(phoneNumber).substr(0,i) + strSeparator + String(phoneNumber).substr(i);}
      nLoopCounter++;
    } 
  }
//  document.write('<a class="siteText phone" href="tel:+1' + phoneNumber.replace(new RegExp(strSeparator,"g"),'') + '">' + phoneNumber + '</a>')
  document.write(phoneNumber);
  if (extension!=null && extension.length > 0) {document.write(' ext ' + extension)}
}

function formatDate(dateValue,dateFormat) {
  inDate = new Date(dateValue);
  var inDay = inDate.getDate(); 
  if (inDay<10) {inDay='0' + inDay};
  var inMon = inDate.getMonth() +1; 
  var inYear = inDate.getFullYear(); 
  if (inMon<10) {inMon='0' + inMon};
  var outDate = dateFormat.replace("YYYY",inYear).replace('MM',inMon).replace('DD',inDay);
  return outDate
}

function IsEmpty( inStr ) {
  if ( leftTrim(inStr) == null || leftTrim(inStr) == '' ) { return true }
  return false
}
function leftTrim (InString) {
  OutString=InString;
  for (Count=0; Count < InString.length; Count++) {
    TempChar=InString.substring (Count, Count+1);
    if (TempChar!=' ') {
      OutString=InString.substring (Count, InString.length);
      break;
    }
  }
  return (OutString);
}
function Right(str, n) {
 /***  IN: str - the string we are RIGHTing
       n - the number of characters we want to return
       RETVAL: n characters from the right side of the string
 ***/
  if (n <= 0)     // Invalid bound, return blank string
    return '';
   else if (n > String(str).length)   // Invalid bound, return
    return str;                     // entire string
   else { // Valid bound, return appropriate substring
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

function Left(str, n) {
  if (n <= 0)
    return "";
   else if (n > String(str).length)
    return str;
   else
    return String(str).substring(0,n);
}

function OpenFileConnection() {
 // *** establish a connection to a file online
  var ajaxRequest=null;
  try { ajaxRequest = new XMLHttpRequest(); }  // Opera 8.0+, Firefox, Safari
  catch (e) { // Internet Explorer Browsers 
        try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } 
        catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 
                    catch (e) { return null; } 
        } 
  } 
  return ajaxRequest;
}

function getLastMod(file) { 
 // *** get the date last modified of a different page than is active
  var msg = '';
  var xhr = OpenFileConnection();
  if (xhr!=null) {
    try { xhr.open('GET', file, false);
          xhr.send(null); }
    catch (e) { return ''; }
    if (xhr.status!=200) return '';
    var hdr = xhr.getResponseHeader('Last-Modified');
    if (hdr > '') { 
      var dt = new Date(hdr);
      msg = 'Last Updated: ' + getMonthName(dt, 'short') + ' ' + dt.getDate() + ', ' + dt.getFullYear() }
  }
  return msg
}

function DetectPage(file) {
 // try to get the last modified date of a file to determine if that file exists
  var msg = true;  // assume the file exists because the browser is unable to issue the command to access a different file.
  xhr = OpenFileConnection();
  if (xhr!=null) {
    try { xhr.open('GET', file, false);
          xhr.send(null); }
    catch (e) { return true; }
    if (xhr.status==0) return true;
    if (xhr.status!=200) return '';
    var msg = new Date(xhr.getResponseHeader('Last-Modified'));
    if (msg.length == 0) { msg = false; } else { msg = true; }
   }
   else {
    msg = true;  // assume the file exists because the browser is unable to issue the command to access a different file.
  }
  return msg;
}

function objSetVisibility(objID,action){
  if (action=='hide'){
    var command1 = 'hidden';
    var command2 = 'none'; }
   else {
    var command1 = 'visible';
    var command2 = 'block';
  }
  if (document.getElementById){ // DOM3 = IE5+, NS6+ 
    document.getElementById(objID).style.visibility = command1;
    document.getElementById(objID).style.display = command2;} 
   else { 
    if (document.layers){ // Netscape 4 
      document.layers[objID].visibility = command1; 
      document.layers[objID].display = command1;} 
     else { // IE 4 
      document.all[objID].style.visibility = command1;
      document.all[objID].style.display = command1;
    }
  } 
}
function objHideAllByTag(objName) { 
  var objs = document.getElementsByTagName(objName); 
  for(i=0;i<objs.length;i++){ 
    if (objs[i].id!='menu' && objs[i].id !='') {objSetVisibility(objs[i].id,'hide');} 
  } 
}
function hidediv(objDiv) {objSetVisibility(objDiv,'hide');}
function showdiv(objDiv) {objSetVisibility(objDiv,'show');}
function objChangeVisibility(objDiv) {
  objHideAllByTag('div');
  showdiv(objDiv);
}

function isDivVisible(objID) {
  if (document.getElementById){ // DOM3 = IE5+, NS6+ 
    var div1 = document.getElementById(objID);} 
   else { 
    if (document.layers){ // Netscape 4 
      var div1 = document.layers[objID];} 
     else { // IE 4 
      var div1 = document.all[objID];
    }
  }
  if (div1.style.display=='' || div1.style.display=='block' || div1.style.visibility=='visible') {return true;} else {return false;}
}

function browserDetect() {
  var uagent = navigator.userAgent.toLowerCase();
  if (uagent.search('android') > -1) return 'mobileWeb';
  if (uagent.search('blackberry') > -1) return 'mobileWeb';
  if (uagent.search('windows ce') > -1) return 'mobileWeb';
  if (uagent.search('iphone') > -1) return 'mobileWeb';
  if (uagent.search('ipod') > -1) return 'mobileWeb';
  if (uagent.search('ipad') > -1) return 'mobileWeb';
  if (uagent.search('series60') > -1) return 'mobileFeature';
  if (uagent.search('symbian') > -1) return 'mobileFeature';
//  if (uagent.search('webkit') > -1) return 'WebKit';
  if (uagent.search('palm') > -1) return 'mobileFeature';
  return '';
}

function loadFile(filename, filetype) {
 if (filetype=='js'){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute('type','text/javascript')
  fileref.setAttribute('src', filename)
 }
 else if (filetype=='css'){ //if filename is an external CSS file
  var fileref=document.createElement('link')
  fileref.rel = 'stylesheet';
  fileref.type = 'text/css';
  fileref.href = filename;
 }
 if (typeof fileref!='undefined') document.getElementsByTagName('head')[0].appendChild(fileref)
}
