// functions.js: functions used throughout the site

function openSound(sound){

    var c = document.cookie;

    // if this sound not already started, start it!
    if (c.indexOf(sound) == -1){

        // add cookie
        var expiry = new Date();
        expiry.setTime(expiry.getTime() + (1 * 60 * 1000)); // one minute
        var cook = "sound=" + sound + "; path=/; expires=" + expiry.toGMTString() ;
        document.cookie = cook;

        // open sound
        var win = window.open(sound, 'sound', 'width=200,height=50,toolbar=no,scrollbars=no,resizeable=yes');

    }
}

function openURL(linky){
    var win = window.open(linky, 'guestbook', 'width=600,height=520,toolbar=no,scrollbars=yes,resizeable=yes');
}

function openAim(u){
    window.open(u, "_aim", "width=600,height=410,menubar=false,scrollbars=false,status=false,toolbar=false,border=false");
}

function openCam(){
    window.open("/v2/media/cam.htm", "_cam", "width=195,height=172,menubar=false,scrollbars=false,status=false,toolbar=false,border=false");
}

function show(id){
    var item = document.getElementById(id);
    if (item != null){
        var disp = item.style.display;
        if (disp == "none"){
            disp = "block";
//        } else {
//            disp = "none";
        }  
        item.style.display = disp; 
    }
    return;
}

function anchor(id){
    document.location = "#" + id + "_a";
}

function setCookie(name, value, expires, path) {
    document.cookie= name + '=' + escape(value) +
        ((expires) ? '; expires=' + expires.toGMTString() : '') +
        ((path) ? '; path=' + path : '; path=/');
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + '=';
    var begin = dc.indexOf('; ' + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(';', begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path) {
    if (getCookie(name)) {
        document.cookie = name + '=' +
            ((path) ? '; path=' + path : '; path=/') +
            '; expires=Thu, 01-Jan-70 00:00:01 GMT';
    }
}

function addFav(){ 
  var combo = document.title + "||" + document.location;
  var stamp = new Date().getTime();
  var exp = new Date();
  exp.setDate(exp.getDate()+365);
  setCookie("fav_" + stamp, combo, exp);
  window.location.replace( document.location );
  
}

function remFav(id){ 
  deleteCookie("fav_" + id);
  window.location.replace( document.location );
}

function replyTo(name, email){
  // alert(name + " " + email);
  var el = document.getElementById('replyName');
  if (el){
      el.innerHTML = name;
  }
  el = document.getElementById('reply_to');
  if (el){
      el.value = email;
  }
  show('replyToBlock');
  show('comments');
  show('guestbook');
}


