var urlArg = window.location.search;
var referredBy = document.referrer;
var referredByDomain = "";
var gclid = grabArguments("gclid");
var anythingChanged = false;
var grabbedFromCookie = false;
var campaign = readCookie("campaign");

if (grabArguments("r")) {
  // if the clicked link contains a referral code/site, overrides any previous referral data
  referredBy = grabArguments("r");
  referredByDomain = referredBy;
  setCookie("referredBy", referredBy, new Date(2025,12,31,20,5,8,10));
  if (campaign == "") {
    setCookie("campaign", referredBy, new Date(2025,12,31,20,5,8,10));
  }
} else if ((referredBy != "") && (document.referrer.indexOf("konkolvillemotel.com") == -1)) {
  // if was referred by (linked from) a site other than konkolvillemotel.com
  setCookie("referredBy", document.referrer, new Date(2025,12,31,20,5,8,10));
  if (campaign == "") {
    setCookie("campaign", document.referrer, new Date(2025,12,31,20,5,8,10));
  }
  referredByDomain = document.referrer.match( /:\/\/(www\.)?([^\/:]+)/ )[2];
  referredByDomain = referredByDomain?referredByDomain:'';
} else {
  // no referral information was supplied in arguments or document.referrer, so look in the cookie
  referredBy = readCookie("referredBy");
  if (referredBy != null) {
    var referredArray = referredBy.match( /:\/\/(www\.)?([^\/:]+)/ );
    if (referredArray == null) {
      referredByDomain = "";
    } else {
      referredByDomain = referredArray[referredArray.length-1];
    }
  } else {
    referredByDomain = "";
  }
}

function goto(myUrl, windowName)
{
  var keepGoing;
  if ((anythingChanged) && (grabCurrentFileName() == "reservations.html")){
    keepGoing = confirm("YOU HAVE NOT COMPLETED YOUR RESERVATION.\n\nClick 'OK' to continue to the new page.\nOr click 'Cancel' to return to your reservation.");
  } else {
    keepGoing = true;
  }

  if (keepGoing) {
    var newUrlArg = urlArg;
    var questionSpot = myUrl.indexOf("?");

    if (myUrl.indexOf("maps.html") == -1) {
      newUrlArg = newUrlArg.replace(/(&|\?)zoom=\d*/,"");
      newUrlArg = newUrlArg.replace(/(&|\?)bubbles=(open|closed)/,"");
    }

    if (questionSpot != -1) {
      newUrlArg = newUrlArg.replace(/\?/,"&")
    }
    myUrl += newUrlArg;

//    var refSpot = myUrl.indexOf("ref=");
//    if ((refSpot == -1) && (document.referrer) && (document.referrer.indexOf("konkolvillemotel.com") == -1)) {
//      myUrl += "&ref=" + forceEscape(document.referrer);
//    }


    var questionSpot  = myUrl.indexOf("?");
    var ampersandSpot = myUrl.indexOf("&");

    if ((ampersandSpot < questionSpot) || (questionSpot == -1)) {
      myUrl = myUrl.replace(/&/,"?");
    }

    if (windowName == "") {
      window.location.href = myUrl;
    } else {
      myRef = window.open(myUrl,windowName);
    }
  }
}

function mapFrom(where,windowName)
{
  var mapAddress = "http://maps.google.com/maps?daddr=2000+Konkolville+Rd,+Orofino,+ID+83544&saddr=" + where + "&f=d&hl=en";
  goto(mapAddress,windowName);
}

function gotoPicture(which, windowName)
{
  goto("photos.html?img="+which, windowName);
}

function gotoMap(zoom, bubbles, windowName)
{
  goto("maps.html?zoom="+zoom+"&bubbles="+bubbles, windowName);
}

function googleBug()
{
//  document.write('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">');
//  document.write('</script>');
//  document.write('<script type="text/javascript">');
//  document.write('_uacct = "UA-1642238-1";');
//  document.write('urchinTracker();');
//  document.write('</script>');
  
  document.write('<script type="text/javascript">');
  document.write('var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");');
  document.write('document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));');
  document.write('</script>');
  document.write('<script type="text/javascript">');
  document.write('try {');
  document.write('var pageTracker = _gat._getTracker("UA-1642238-1");');
  document.write('pageTracker._trackPageview();');
  document.write('} catch(err) {}</script>  '); 
}

function popUpTip(tipText)
{
  Tip("<b>" + tipText + "</b>", SHADOW, true, BGCOLOR, "#000000", BORDERCOLOR, "#ffffff", DELAY, 0, FONTCOLOR, "#ffffff", OPACITY, 50);
}

var testimonialArray = new Array();
var random_testimonial = new Testimonial("-1", new Date(1900, 1, 1),"100", "Test", "Boise, ID", "Testing, testing...");

function Testimonial(id, dateofstay, room, name, location, comment)
{
  this.id = id;
  this.dateofstay = dateofstay;
  this.monthNames = new Array("UNKNOWN", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  this.dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  this.nicedate = this.dayNames[this.dateofstay.getDay()] + ", " + this.monthNames[this.dateofstay.getMonth()+1] + " " + this.dateofstay.getDate() + ", " + (this.dateofstay.getFullYear());
  this.room = room;
  if (this.room == "") this.room = "<i>???</i>";
  this.name = name;
  this.location = location;
  this.comment = comment;
}

Testimonial.prototype.draw = function()
{
  var s = "";
  s += '<table style="width:100%;border-bottom:1px inset black;">';
  s += '<tr style="background-color:#C9CBD6;font-weight:bold;">';
  s += '  <td>';
  s += '    <a name="comment'+this.id+'"></a>';
  s += '    Room #' + this.room + ' on ' + this.nicedate;
  if ((this.name != null) && (this.name != "")) {
    s += ' by ' + this.name;
  }

  if ((this.location != null) && (this.location != "")) {
    if ((this.name == null) || (this.name == "")) {
      s += ' by Guest ';
    }
    s += ' from ' + this.location;
  }

  s += '  </td>';
  s += '</tr>';
  s += '<tr>';
  s += '  <td>';
  s += this.comment;
  s += '  </td>';
  s += '</tr>';
  s += '</table>';
  this.drawSub("testimonialarea", s);
}

Testimonial.prototype.drawReunion = function()
{
  var s = "";
  s += '<table style="width:100%;border-bottom:1px inset black;">';
  s += '<tr style="background-color:#C9CBD6;font-weight:bold;">';
  s += '  <td>';
  s += '    <a name="comment'+this.id+'"></a>';
  s += this.nicedate;
  if ((this.name != null) && (this.name != "")) {
    s += ' by ' + this.name;
  }

  if ((this.location != null) && (this.location != "")) {
    if ((this.name == null) || (this.name == "")) {
      s += ' by Guest ';
    }
    s += ' from ' + this.location;
  }

  s += '  </td>';
  s += '</tr>';
  s += '<tr>';
  s += '  <td>';
  s += this.comment;
  s += '  </td>';
  s += '</tr>';
  s += '</table>';
  this.drawSub("reunion_testimonialarea", s);
}

Testimonial.prototype.drawSub = function(where, what)
{
  document.getElementById(where).innerHTML += what;
}

Testimonial.prototype.drawRandom = function()
{
  var s = "";
  s += '<table style="width:100%;border-bottom:1px inset black;font-family:Arial;">';
  s += '<tr style="background-color:#C9CBD6;font-weight:bold;">';
  s += '  <td>';
  s += '    <a href="javascript:goto(&quot;testimonials.html?id='+this.id+'&quot;);">';
  s += '    Guest Comment on ' + this.nicedate;

  if ((this.location != null) && (this.location != "")) {
    s += ' by Guest from ' + this.location;
  }
  s += '  </a>';
  s += '  </td>';
  s += '</tr>';
  s += '<tr>';
  s += '  <td>';
  s += this.comment;
  s += '  </td>';
  s += '</tr>';
  s += '</table>';
  this.drawSub("random_testimonial_area", s);
}

function drawRandomTestimonial()
{
  random_testimonial.drawRandom();


}

function displayTestimonials()
{
  document.getElementById("testimonialarea").innerHTML = "";
  if (testimonialArray.length > 0) {
    for (var t = (testimonialArray.length-1); t > 0; t--) {
      testimonialArray[t].draw();
    }
  }
  if (grabArguments("id")) {
    window.location.href = "#comment" + grabArguments("id");
  }

}


function pageHeader()
{
  var currFile = grabCurrentFileName();
  var currDir  = grabCurrentDirectory();

  var randomPic = "";
  var randomPicThumb = "";
  var randomPicTip = ""

  var alreadyOnPage = "onmouseover=\"popUpTip('You are already on this page');\"";

  document.write('  <link title="stylesheet" rel=stylesheet href="style.css" type="text/css">');
  document.write('  <link rel="shortcut icon" href="http://www.konkolvillemotel.com/images/motellogo.gif"/>');
  document.write('  <script type="text/javascript" src="wz_tooltip.js"></script>');
  document.write('  <script type="text/javascript" src="ajax.js"></script>');

  document.title = 'Konkolville Motel';
  document.bgColor = '#C9CBD6';
  document.write('  <div align="center">');
  document.write('    <table border="0" width="718" cellspacing="0" cellpadding="0" height="711">');

  document.write('      <tr>');
  document.write('        <td colspan="4" background="images/templatepic.jpg" height="198" bgcolor="dbdde4" valign="top">');
  document.write('          <table width="718">');
  document.write('            <tr>');

  document.write('              <td width="185px" rowspan=3 align="center" style="vertical-align:top;"><img src="motellogo.cgi?r='+grabArguments("r")+'&e='+grabArguments("e")+'&ref='+escape(document.referrer)+'" height="188px">');
  document.write('              </td>');
  document.write('              <td height="32px">&nbsp;');
  document.write('              </td>');
  document.write('            </tr>');
  document.write('            <tr height="45px">');
  document.write('              <td valign="top" style="padding:0px;">');
  document.write('                <font size="7" font color="595F75" face="Georgia" style="font-style: italic;">');
  document.write('                  Konkolville Motel');
  document.write('                </font>');
  document.write('              </td>');
  document.write('            </tr>');
  document.write('            <tr height="92px">');
  document.write('              <td valign="top">');
  document.write('                <font face="Georgia" font color="595F75" size="4" style="font-style: italic;">');
  document.write('                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Historically Unique Experience');
  document.write('                  <br>');
  document.write('                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exceptionally Clean Rooms');
  document.write('                </font>');
  document.write('              </td>');
  document.write('            </tr>');
  document.write('          </table>');
  document.write('        </td>');
  document.write('      </tr>');
  document.write('      <tr>');
  document.write('        <td width="6" bgcolor="dbdde4" valign="top">');
  document.write('          &nbsp;');
  document.write('        </td>');
  document.write('        <td width="189" bgcolor="dbdde4" valign="top" id="leftcolumn" name="leftcolumn">');
  document.write('          <p align="left">');
  document.write('            <br>');
  document.write('            <font face="Arial" size="2">');
  if (currFile == "album.cgi") {
    document.title += " - Photo Album";
  }
  if (currFile == "rooms.html") {
    document.write('              <b '+alreadyOnPage+'>Rooms and Rates</b><br>');
    document.title += " - Rooms & Rates";
  } else {
    document.write('              <a href="javascript:goto(\'rooms.html\',\'\');">Rooms and Rates</a><br>');
  }
  if (currFile == "directions.html") {
    document.write('              <b '+alreadyOnPage+'>Directions to Motel</b><br>');
    document.title += " - Directions";
  } else {
    document.write('              <a href="javascript:goto(\'directions.html\',\'\');">Directions to Motel</a><br>');
  }
  if (currFile == "maps.html") {
    document.write('              &nbsp;&nbsp;&nbsp;&nbsp;&#187&#187 <b '+alreadyOnPage+'>Maps</b><br>');
    document.title += " - Maps";
  }

  if (currFile == "optout.html") {
    document.title += " - E-Mail Advertisement Opt-Out Request";
  }

  if (currFile == "amenities.html") {
    document.write('              <b '+alreadyOnPage+'>Amenities</b><br>');
    document.title += " - Amenities";
  } else {
    document.write('              <a href="javascript:goto(\'amenities.html\',\'\');">Amenities</a><br>');
  }
  if (currFile == "reservations.html") {
    document.write('              <b '+alreadyOnPage+'>Make a Reservation Online</b><br>');
    document.title += " - Online Reservations";
  } else {
    document.write('              <a href="javascript:goto(\'reservations.html\',\'\');">Make a Reservation Online</a><br>');
  }
  if (currFile == "reunions.html") {
    document.write('              <b '+alreadyOnPage+'>Reunions or Group Bookings</b><br>');
    document.title += " - Reunions or Group Bookings";
  } else {
    document.write('              <a href="javascript:goto(\'reunions.html\',\'\');">Reunions or Group Bookings</a><br>');
  }
  if (currFile == "attractions.html") {
    document.write('              <b '+alreadyOnPage+'>Area Attractions & Events</b><br>');
    document.title += " - Area Attractions & Events";
  } else {
    document.write('              <a href="javascript:goto(\'attractions.html\',\'\');">Area Attractions & Events</a><br>');
  }
  if (currFile == "testimonials.html") {
    document.write('              <b '+alreadyOnPage+'>Guest Comments</b><br/>');
    document.title += " - Guest Comments";
  } else {
    document.write('              <a href="javascript:goto(\'testimonials.html\',\'\');">Guest Comments</a><br/>');
  }
  if (currFile == "aboutus.html") {
    document.write('              <b '+alreadyOnPage+'>About Us</b>');
    document.title += " - About Us";
  } else {
    document.write('              <a href="javascript:goto(\'aboutus.html\',\'\');">About Us</a>');
  }
  document.write('            </font>');
  document.write('          </p>');
  document.write('          <p align="left">');
  document.write('            <font face="Arial" size="2">');
  if ((currFile == "index.html") || (currFile == "")) {
    document.write('              <br/>');
  } else {
    document.write('              <a href="javascript:goto(\''+currDir+'\',\'\');">');
    document.write('                Return to Main Page');
   document.write('              </a>');
  }
  document.write('            </font>');
  document.write('          </p>');
  document.write('          <p align="left" id="randompicspot" name="randompicspot" style="text-align:center; width:175px; border-top:1px solid #C9CBD6; padding-top:3px; border-bottom:1px solid #C9CBD6; padding-bottom:3px;">');
  document.write('            <a id="randompichref" name="randompichref" href="">');
  document.write('              <img id="randompicimg" name="randompicimg" onmouseover="popUpTip(randomPicTip);" src="images/blank.gif">');
  document.write('            </a><br/>');
  if (currFile != "album.cgi") {
    document.write('          <a style="font-variant:small-caps;" href="javascript:goto(\'album.cgi\',\'\');" onmouseover="popUpTip(\'View the full photo album\');">(view photo album)</a>');
  }
  document.write('          </p>');
  document.write('          <p align="left">');
  document.write('            <b>');
  document.write('              <font face="Arial">');
  document.write('                Call (208) 476-5584<br>');
  document.write('                Toll Free (800) 616-1964<br>');
  document.write('                Fax (208) 476-3268');
  document.write('              </font>');
  document.write('            </b>');
  document.write('          </p>');

  document.write('          <p align="left">');
  document.write('            <b>');
  document.write('              <font face="Arial">');
  document.write('                <font color="red"><i>New address, same great location:</i></font><br/>');
  document.write('                2600 Michigan Ave<br>');
  document.write('                Orofino, Idaho 83544');
  document.write('              </font>');
  document.write('            </b>');
  document.write('          </p>')
  document.write('          <p align="left">');
  document.write('            <b>');
  document.write('              <font face="Arial">');
  document.write('                <font color="red"><i>Old Address:</i></font><br/>');
  document.write('                2000 Konkolville Rd<br>');
  document.write('                Orofino, Idaho 83544<br/>');
  document.write('                <font size="-1"><i>(This address may still be required on some maps or GPS systems)</i></font><br/>');
  document.write('              </font>');
  document.write('            </b>');
  document.write('          </p>')

  document.write('          <p align="center">');
  document.write('            <img src="images/aaa.gif" style="height:125px;"><br/><br/><br/>');
  document.write('            <a href="http://www.facebook.com/pages/Orofino-ID/Konkolville-Motel/115707288462656" target="_blank"><img src="images/facebook.gif" style="height:50px;" alt="We are on FaceBook!"><br/>We Are On FaceBook!</a>');
  document.write('          </p>')
  
  document.write('          <p align="center">');  
  document.write('            <div id="TA_rated889" class="TA_rated">');
  document.write('              <ul id="zdh644Sw6g" class="TA_links n2fnixvoS">');
  document.write('                <li id="Ozsxdudy6Efe" class="GsrtEsWr95">');
  document.write('                  <a href="http://www.tripadvisor.com/Hotel_Review-g35558-d657685-Reviews-Konkolville_Motel-Orofino_Idaho.html">');
  document.write('                    Konkolville Motel');
  document.write('                  </a>');
  document.write('                </li>');
  document.write('              </ul>');
  document.write('            </div>');
  document.write('            <script src="http://www.jscache.com/wejs?wtype=rated&amp;uniq=889&amp;locationId=657685&amp;lang=en_US">');
  document.write('            </script>');
  document.write('          </p>')  
  
  if (currFile == "amenities.html") {
    document.write('        <p align="left">');
    document.write('          <a href="javascript:gotoPicture(\'pictures/PoolAndHotTub.jpg\',\'\');">');
    document.write('            <img src="images/tn_pool.jpg" border=0><br/>');
    document.write('            <font face="Arial" style="text-align:center">');
    document.write('              Our pool and hot tub');
    document.write('            </font>');
    document.write('          </a>');
    document.write('        </p>');
  }
  document.write('          <script language="JavaScript" type="text/javascript" src="randompic.cgi"></script>');
  document.write('        </td>');
  document.write('        <td style="background-color:#dbdde4; width: 518px;vertical-align:top;padding-left:10px;text-align:left;">');

}

function pageFooter()
{
  document.write('        <div id="random_testimonial_area" name="random_testimonial_area" style="width:100%;"></div>');
  document.write('        </td>');
  document.write('      <td width="10" bgcolor="dbdde4" valign="top">');
  document.write('        &nbsp;');
  document.write('      </td>');
  document.write('    </tr>');
  document.write('    <tr>');
  document.write('      <td colspan="4" background="images/templatepic2.jpg" height="116" bgcolor="dbdde4" valign="bottom" style="text-align:center">');
    var currFile = grabCurrentFileName();
  if ((currFile == "index.html") || (currFile == "")) {
    document.write('        <a href="https://mail.google.com/hosted/konkolvillemotel.com/"><font color="dbdde4" style="font-variant:small-caps;" onmouseover="this.color=\'b9bbc2\';" onmouseout="this.color=\'dbdde4\';">motel e-mail</font></a><br/>');
  }
  copyrightNotice();
  document.write('        <br/><br/>');
  document.write('      </td>');
  document.write('    </tr>');
  document.write('  </table>');
  document.write('</div>');
  if (currFile != "testimonials.html") {
    ajax_load_random_testimonial();
//    document.write('<script type="text/javascript" src="random_testimonial.cgi" onload="drawRandomTestimonial();"></script>');
  }
  googleBug();
}

function copyrightNotice()
{
  var today = new Date();
  var thisYear = today.getYear() + 1900;
  document.write('        <font face="Arial" color="b9bbc2" style="border-top:1px solid #C9CBD6; padding-top:3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; Konkolville Motel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>');
}

function grabCurrentDirectory()
{
  var myloc = window.location.href;
  var locarray = myloc.split("/");
  delete locarray[(locarray.length-1)];
  var arraytext = locarray.join("/");
  return arraytext;
}

function grabCurrentFileName()
{
  var thisFile = window.location.href;
  thisFile = thisFile.replace(/#.*/, "");
  var fileArray = thisFile.split("?");
  var pageName  = fileArray[0];
  var arguments = fileArray[1];

  var pageNameArray = pageName.split("/");
  return (pageNameArray[pageNameArray.length-1]);
}

function grabArguments(which)
{
  var thisFile = window.location.href;
  var fileArray = thisFile.split("?");
  var pageName  = fileArray[0];
  var arguments = fileArray[1];
  var returnValue = "";
  if (arguments != undefined) {
    var argumentArray = arguments.split("&");

    for (var a = 0; a < argumentArray.length; a++) {
      var thisArgArray = argumentArray[a].split("=");
      if (thisArgArray[0] == which) {
        returnValue = thisArgArray[1];
      }
    }
  } else {
    returnvalue = "";
  }

  return (returnValue);
}

function showStatus(showme)
{
  window.status = showme;
  return true;
}

// ********************************************** COOKIES **********************************************

function readCookie(name)
{
  var start = parseInt(document.cookie.indexOf(name + "="));
  var cookievalue = "";

  if (start == -1) {
    cookievalue = "cookienotfound";
  }

  if (cookievalue != "cookienotfound") {
    start = document.cookie.indexOf("=", start) + 1;
    var end = document.cookie.indexOf(";",start);

    if (end == -1) {
      end = document.cookie.length;
    }
    cookievalue = unescape(document.cookie.substring(start,end));
  } else {
    cookievalue = "";
  }

  return cookievalue;
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
//  alert(curCookie);
}

function deleteCookie(name, path, domain) {
  if (readCookie(name) != "cookienotfound") {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

