/*
 * javascript for sallybarker.org
 */

//frame buster
if (top != self) { top.location = self.location; }
//navigation functions
function jumpFromSelect()
{
    var url=document.source.destination[document.source.destination.selectedIndex].value;
  if((url!='')&&(url!=null)&&(url!="null")){
    window.location = url;
  }
}
function checkNav(){
  var url=document.source.destination[document.source.destination.selectedIndex].value;
  if((url!='')&&(url!=null)&&(url!="null")){
    alert("please select a page from the list");
    return false
  }else{
    return true;
  }
}
//status function
function setMsg(msg){
  window.status=msg;
  return true;
}
//popup window functions
function setOptions(winx, winy, scrx, scry, scrolling)
{
    var opts = "";
    var globalopts = "toolbar=no,location=no,directories=no,status=no,resizeable=no,menubar=no";
    if (window.innerHeight) {
        opts = globalopts + ",innerWidth=" + winx + ",innerHeight=" + winy + ",screenX=" + scrx + ",screenY=" + scry;
    } else {
        opts = globalopts + ",width=" + winx + ",height=" + winy + ",left=" + scrx + ",top=" + scry;
    }
    opts += scrolling? ",scrollbars": ",scrollbars=no";
    return opts;
}
function openWindow(url, opts, scrx, scry, name)
{
    var newWindow = window.open(url, name, opts);
    if (document.layers || document.getElementById) {
        newWindow.moveTo(scrx, scry);
        newWindow.focus();
    }
}
var sw = 800;
var sh = 600;
if (screen.width) {
    sw = screen.width;
    sh = screen.height;
}
function pop(which)
{
    if (which == "sun") {
        url = '/images/jellytits/sun_article.html';
        scrx = 150;
        scry = 0;
        opts = setOptions(219, 501, scrx, scry, false);
    } else if (which == "pylon_drawing") {
        url = sh < 720? '/images/pylons/drawing_small.html': '/images/pylons/drawing.html';
        scrx = 0;
        winh = sh < 720? 420: 720;
        scry = (sh - winh) / 2;
        opts = setOptions(sw, winh, scrx, scry, true);
    } else if (which == "pylon2") {
        url = '/images/pylons/scw.html';
        winw = 830;
        winh = 600;
        scrx = (sw - winw) / 2;
        scry = (sh - winh) / 2;
        opts = setOptions(winw, winh, scrx, scry, false);
    } else if (which == "pylon1") {
        url = '/images/pylons/studio.html';
        winw = 660;
        winh = 600;
        scrx = (sw - winw) / 2;
        scry = (sh - winh) / 2;
        opts = setOptions(winw, winh, scrx, scry, false);
    } else if (which == "crane1") {
        url = '/images/cranes/crane1.html';
        scrx = 50;
        scry = 0;
        opts = setOptions(271, 413, scrx, scry, false);
    } else if (which == "crane2") {
        url = '/images/cranes/crane2.html';
        scrx = sw - 419;
        scry = 0;
        opts = setOptions(419, 388, scrx, scry, false);
    } else if (which == "crane3") {
        url = '/images/cranes/crane3.html';
        scrx = sw - 500;
        scry = sh - 250;
        opts = setOptions(500, 250, scrx, scry, false);
    } else if (which == "crane4") {
        url = '/images/cranes/crane4.html';
        scrx = 0;
        scry = Math.round((sh - 400) / 2);
        opts = setOptions(350, 400, scrx, scry, false);
    } else if ((which == 1) || (which == 3) || (which == 4) || (which == 6)) {
        url = '/images/comics/c'+which+'.html';
        scrx = 0;
        scry = Math.round((sh - 350) / 2);
        opts = setOptions(sw, 350, scrx, scry, true);
    } else if (which == 2) {
        url = '/images/comics/c2p1n.html';
        scrx = 0;
        scry = 0;
        opts = setOptions(700, sh, scrx, scry, true);
    } else if (which == 5) {
        url = '/images/comics/c5.html';
        scrx = 0;
        scry = Math.round((sh - 455) / 2);
        opts = setOptions(sw, 455, scrx, scry, true);
    } else {
        return;
    }
    openWindow(url, opts, scrx, scry, which);  
}
function openComic(idx)
{
    if (document.images) {
        if (idx == "thumb") {
            idx = parseInt(document.images['thumb'].src.substr(document.images['thumb'].src.length-5));
        }
        if (idx) {
            pop(idx);
        }
    }
}
//call page loading functions
if (location.pathname.indexOf('cranes') != -1) {
    window.onload = cranes_onload;
} else if (location.pathname.indexOf('gallery') != -1 || location.pathname.indexOf('sbg') != -1 ) {
    window.onload = gallery_onload;
} else if (location.pathname.indexOf('comics') != -1) {
    window.onload = comics_onload;
} else if (location.pathname.indexOf('meat') != -1) {
} else if (location.pathname.indexOf('empire') != -1) {
} else if (location.pathname.indexOf('pylons') != -1) {
} else if (location.pathname.indexOf('jellytits') != -1) {
} else {
    window.onload = home_onload;
}
//page loading functions
var comic;
function home_onload()
{
    if (document.images) {
        comic = new Array();
        comic[0] = new Image(160,160);
        comic[1] = new Image(160,160);
        comic[2] = new Image(160,160);
        comic[3] = new Image(160,160);
        comic[4] = new Image(160,160);
        comic[5] = new Image(160,160);
        comic[0].src = '/images/comics/thumbnails/1.gif';
        comic[1].src = '/images/comics/thumbnails/2.gif';
        comic[2].src = '/images/comics/thumbnails/3.gif';
        comic[3].src = '/images/comics/thumbnails/4.gif';
        comic[4].src = '/images/comics/thumbnails/5.gif';
        comic[5].src = '/images/comics/thumbnails/6.gif';
    }
    slideShow();
}
var crane1,crane2,crane3,crane4;
function cranes_onload()
{
    if (document.images) {
        crane1 = new Image();
        crane2 = new Image();
        crane3 = new Image();
        crane4 = new Image();
        crane1.src = '/images/cranes/cranepic1.jpg';
        crane2.src = '/images/cranes/cranepic2.jpg';
        crane3.src = '/images/cranes/cranepic3.jpg';
        crane4.src = '/images/cranes/cranepic4.jpg';
    }
}
var galleries;
function gallery_onload()
{
    if (document.images) {
        galleries = new Array();
        galleries[0] = new Image(400,267);
        galleries[1] = new Image(400,267);
        galleries[2] = new Image(400,267);
        galleries[3] = new Image(400,267);
        galleries[0].src = '/images/gallery/gallerypic1.jpg';
        galleries[1].src = '/images/gallery/gallerypic2.jpg';
        galleries[2].src = '/images/gallery/gallerypic3.jpg';
        galleries[3].src = '/images/gallery/gallerypic4.jpg';
    }
}
var comics;
function comics_onload()
{
    if (document.images) {
        comics = new Array();
        comics[0] = new Image(160,160);
        comics[1] = new Image(160,160);
        comics[2] = new Image(160,160);
        comics[3] = new Image(160,160);
        comics[4] = new Image(160,160);
        comics[5] = new Image(160,160);
        comics[0].src = '/images/comics/thumbnails/1.gif';
        comics[1].src = '/images/comics/thumbnails/2.gif';
        comics[2].src = '/images/comics/thumbnails/3.gif';
        comics[3].src = '/images/comics/thumbnails/4.gif';
        comics[4].src = '/images/comics/thumbnails/5.gif';
        comics[5].src = '/images/comics/thumbnails/6.gif';
    }
}
//slideshow function for home page
var idx=1;
function slideShow()
{
    if (document.images && document.images['comicslideshow']) {
        if (idx < 6) {
            if (comic[idx].complete) {
                document.images['comicslideshow'].src = comic[idx].src;
            }
        } else {
            if (comic[0].complete) {
                document.images['comicslideshow'].src = comic[0].src;
                idx = -1;
            }
        }
        idx++;
        setTimeout("slideShow()", 6000);
    }
}
//image swapping functions for comics page
var showTitle=0;
function swapComic(idx)
{
    if (document.images) {
        if (comics[idx].complete) {
            document.images['thumb'].src = comics[idx].src;
        }
    }
    setTimeout("backToTitle("+showTitle+")",10000);
    showTitle++;
}
function backToTitle(idx)
{
    idx++;
    if (showTitle == idx) {
        document.images['thumb'].src='/images/comics/header.gif';
    }
}
//image swapping function for gallery page
function swap_galleries()
{
    if (document.images) {
        doc = document.layers? document.gallerytext.document: document;
        currentImage = parseInt(doc.images['gallerypic'].src.substr(doc.images['gallerypic'].src.length-5));
        if (currentImage < 4) {
            if (galleries[currentImage].complete) {
                doc.images['gallerypic'].src = galleries[currentImage].src;
            }
        } else {
            if (galleries[0].complete) {
                doc.images['gallerypic'].src = galleries[0].src;
            }
        }
    }
}
//mailing list functions
function checkEmail(member){
  var addr = "";
  var errMsg = "";
  var listDomain = "sallybarker.org";

  if(member){
    addr = document.member.email.value;
  }else{
    addr = document.list.listemail.value;
    if(addr.indexOf(listDomain)<0){
      errMsg += "Please enter a valid email address for the list\n";
      errMsg += "The address must be a '" + listDomain + "' address";
      alert(errMsg);
      return false;
    }
  }
  var atPos = addr.indexOf("@");
  var dotPos = addr.indexOf(".",atPos+2);
  if((atPos<0)||(dotPos<0)){
    errMsg += "The email address you entered appears to be invalid\nPlease check it and try again";
    alert(errMsg);
    return false;
  }else{
    if(!member){
      window.open('submission.php?type=addList&name='+addr,'add','width=400,height=300,scrollbars');
    }
    return true;
  }
}
function deleteList(id,email){
  if(confirm("Are you sure you want to delete this list?\n(All membership information for this list will be lost)")){
    location="update_list.php?listID="+id+"&delete="+email;
  }
}
function deleteMember(id){
  if(confirm("Are you sure?")){
    location="update_member.php?memberID="+id+"&delete=delete";
  }
}
