/*  Peekok Button Javascript Widget
 *  (c) 2008 Peekok, All Rights Reserved
 *  www.peekok.com
 */

function peekok_set_cookie( name, value, expires, path, domain, secure ) {
  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );

  if ( expires ) {
    expires = expires * 1000 * 60 * 60; // hours
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}       

function peekok_isInteger(s) {
    return Math.ceil(s) == Math.floor(s);
}

function peekok_button_submit(widget_id) {
  var url = "https://www.peekok.com/checkout/checkout?keepThis=true";

    if(peekok_isInteger(widget_id)) { 
      url += "&widget_id=" + widget_id;
      url += "&TB_iframe=true&height=560&width=470";
      p_lightbox.launchLightbox(url);
    }
}


var buttonContent = "";
function peekok_write(c) {
  buttonContent += c;
  return;
}

function peekok_writeButton(divId) {
  var d = document.getElementById(divId)
  if (d != null) {d.innerHTML = buttonContent};
  return;
}

function peekok_button_main(id) {
  // Open write stream
  peekok_write('<a href="#" onClick="peekok_button_submit('+ id +')" class="peekok_widget_buy_button">Buy</a>');

  // write widget to peekok div.
  peekok_writeButton('peekokButton'+id);
}

peekok_button_main(1);
peekok_set_cookie('peekok_widget_ref', document.referrer, 12);
