// 05/10/2001 division-7.com This javascript is for the headshot selector at http://www.reproductions-online.com/RPU
// 07/10/2009 division-7.com url changed to reproductions.photo-proofs.com
var OWN="RPU"
var HOME="http://"+location.hostname+"/"+OWN

var Timg=new Image
Timg.src=HOME+"/images/div7-75x39.gif"


// Use this function to save a cookie.
function setCookie(name, value) {
  var D=new Date()
  var T=new Date((1000*60*60*24*31) + D.getTime()) // one month
  var exp=T.toGMTString()
  document.cookie=name+"=" + escape(value)  + ";expires="+exp + ";path=/;"//  + location.pathname
  }

// Use this function to delete a cookie.
function delCookie(Name) {
  if(Name=='_ALL_') {
    var dc=document.cookie.split(';');
    for (i in dc){
      var name=dc[i].split('=')
      document.cookie=name+"=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
      }
    }
  else {
    var C=getCookie(Name)
    if (C!="") {document.cookie=Name+"=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT"}
    }
  }

// this adds a favorite to the cookie
function addCookie(name,num){
  setCookie('Fave',num+','+getCookie('Fave'))
  }

// this removes one favorite from the cookie
function remCookie(name, num){
  var a=getCookie(name).split(',')
  var newt=''
  for (i=0; i<a.length; i++){
    if(num==a[i]){continue}
    newt += a[i]+','
    }
  newt=newt.substr(0,newt.length-1)
  setCookie('Fave',newt)
  }

// Use this function to retrieve a cookie.
var count=0
function getCookie(name) {
  var oldCookie=""
  var dc=document.cookie;
  var c_name=name + "=";
  if (dc.length > 0) {
    var begin=dc.indexOf(c_name);
    if (begin!=-1) {
      begin+=c_name.length;
      var end=dc.indexOf(";", begin);
      if (end==-1) { end=dc.length; }
      oldCookie=unescape(dc.substring(begin, end));
      }
    }
  return oldCookie
  }


function cookIt(){
  var St=getCookie('Session')
  if(St==''){
    var now=new Date()
    var t=now.getTime()
    //alert(t)
    setCookie('Session',t)

    if(getCookie('Session') != t){
      var atext ="Your browser is not returning a cookie.\n"
          atext+="Cookies are used to track print orders, and Favorites\n"
          atext+="To store your favorites, please enable cookies in your browser.\n"
      alert(atext)
      }
    }
  var session=getCookie('Session')
  if ((session)&&(session.length>9)){
    if(document.Select){document.Select.Session.value=session}
    }
  }


var ctr=0
// Sets the favorite mark ON for images with cookies, turns others OFF.
// revised for one at a time ordering
function checkCookie(page, spec) {
  //if(document.upd){document.upd.src=HOME+"/images/update.gif"}
  if (! spec) {spec=''}
  var ImA=window['ImA'+page]
  var L=ImA.length
  var flag=0
  var Qi='Fave'
  var CQ = Qi+spec
  C=getCookie(CQ)
  for (var i=0;i<L;i++) {
    var I=ImA[i]
    var tst = "|"+I+"|"
    if (C.indexOf(tst)>-1) {
      var It=document[Qi+I]
      if (typeof It=='object'){
        if (It.src.indexOf('ON.gif')==-1){flag++}
        It.src=tempFR.src
        }
      }
    else {
      It=document[Qi+I]
      if (typeof It=='object'){
        It.src=tempFO.src
        }
      }
    }
  //if(document.upd){setTimeout('document.upd.src="http://www.reproductions-online.com/'+OWN+'/images/onepixel.gif"',1000)}
  //if(flag!=0){history.go(0)}
  //tempI=It.src
  }


var OM=new Array('','Click to view enlargement.')
// function for status on mouseover
function Om(arg) {
  window.status=OM[arg]
  return true
  }

// mouseovers for the page list
function Op(page) {
  page0=(page<10)?"0"+page : page;
  if(page0==self.location.href.substr(-7,2)) {
    window.status='This page.'
    return true
    }
  else {
    if (page==0) {
      window.status=''
      return true
      }
    else {
      window.status="go to images "+(12*(page-1)+1)+" to "+(12*page)
      return true
      }
    }
  }

// mouseovers for the orders hot spots
var oc_flag=0
function Oc(imag,state) {
  var It=document['Order'+imag]
  var WS=''
  if (state=='on') {
    tempI=It.src
    if (tempI.indexOf("ON")==-1){
      oc_flag=0
      WS="Add this image to your order."
      It.src=tempOV.src // for mouseover
      }
    else {
      oc_flag=1
      WS="Remove "+imag+" from your order?"
      It.src=tempOR.src // for mouseover
      }
    }
  else {
    It.src=tempI
    }
  window.status=WS
  return true
  }

// mouseovers for favorites
var tempFO = new Image()
var tempFR = new Image()
var tempFV = new Image()
tempFO.src = HOME+"/images/starOFF.gif"
tempFR.src = HOME+"/images/starON.gif"
tempFV.src = HOME+"/images/starOVER.gif"
var of_flag=0
var tempI=''
function Of(imag,state) {
  var It=document['Fave'+imag]
  var WS=''
  if (state=='on') {
    tempI=It.src
      It.src=tempFV.src
    if (tempI.indexOf("ON")==-1){
      of_flag=0
      WS="Add this image to your favorites."
      }
    else {
      of_flag=1
      WS="Remove "+imag+" from your favorites?"
      }
    }
  else {
    It.src=tempI
    }
  window.status=WS
  return true
  }

var winText=''
function selectIt(imag){
  cookIt()
  winText="Adding "+imag+" to favorites..."
  var S=document.Select
  S.Action.value="ADD"
  nSrc=tempFR.src
  var iSrc=document['Fave'+imag]
  if(of_flag){
    winText="Removing "+imag+" from favorites..."
    S.Action.value="REM"
    nSrc=tempFO.src
    //remCookie('Fave', imag)
  }
  //else{addCookie('Fave', imag)}
  tempI=nSrc
  var features="width=200,height=100,resizable,scrollbars"
  ordWin=window.open('','sel',features)
  if(imag==''){winText='View Favories...'}
  setTimeout("writeOrd(winText)",200)
  var H=location.pathname
  var Di = H.lastIndexOf('/')
  var D = H.substring(0,Di)
  var dirs=D.split('/')
  S.Dir.value=dirs[2]+"/"+dirs[3]
  S.Image.value=imag
  if((S.Session)&&(S.Session.value)){
    S.target="sel"
    S.action=HOME+"/cgi-bin/Select.pl"
    setTimeout("document.Select.submit()",300)
  }
  else {alert("no session")}
  return false
  }

var Page=0
// function to show the favorites pages
function cL(){
  var features="status,scrollbars,resizable,location,menubar,width=800,height=600"
  showWin=window.open('','Showwin',features)
  //setTimeout("writeShow('showWin')",200)

  var Url=HOME+"/cgi-bin/list.pl"

  var content='<HTML><HEAD><TITLE>SHOW FAVORITES</TITLE>\n'
  content+='</HEAD><body text="#666666" bgcolor="#000000" link="#666666" vlink="#333333" alink="#FF0066">\n'
  content+='<center><br>&nbsp;<br>&nbsp;Gathering favorites...</center><br>\n'
  content+='<form name="Show" action='+Url+' method="post">\n'
  content+='<input type="hidden" name="h_ref" value="'+location.pathname+'">\n'
  content+='<input type="hidden" name="User" value="'+Fi+'">\n'
  content+='</form>\n'
  content+='<script language="javascript">\n'
  content+='document.Show.target="Showwin"\n'
  content+=''
  content+='document.Show.submit()\n'
  content+=''
  content+='</script>\n'
  content+='</BODY></HTML>\n'

  showWin.document.write(content)
  //setTimeout("showWin.document.close()",300)  // throws an error in NN ??
  showWin.document.close()
  }
// this makes a window for the favorites list
function OldcL(page){
  document.fav1.src=HOME+"/images/pickON.gif"
  var listName="List"
  var features="scrollbars,resizable,status,width=250,height=200"
  listWin=window.open("",listName,features)
  Page=page
  setTimeout("writeList(Page)",200)
  setTimeout("listWin.focus()",300)
}

// this makes a list of the images with favorites
function writeList(page){
  var Url=HOME+"/cgi-bin/list.pl"
  var content='<HTML><HEAD><TITLE>picks list</TITLE>\n'
  content+='<script language = "JavaScript">\n'
  content+='function sl () {document.list.submit()}\n'
  //content+='\n'
  //content+='\n'
  //content+='\n'
  content+='</script>\n'

  content+='</HEAD>\n'
  content+='<BODY bgcolor="#FFFFFF" link="#333333" vlink="#666666" alink="#000000">\n'
  content+='<font face="Verdana, Arial, Helvetica, sans-serif" color="#999999">\n'
  content+='One moment please.\n'
  content+='<form name="list" action='+Url+' method="post">\n'
  content+='<input type="hidden" name="h_ref" value="'+location.pathname+'">\n'
  content+='<input type="hidden" name="page" value="'+page+'">\n'
  content+='</form>\n'
  content+='<scr'+'ipt>\nsl()\n</script>\n'
  content+='</BODY></HTML>\n'
  listWin.document.write(content)
  listWin.document.close()
  }

// function to store favorite vote
function Atemp(img) {
  if(img.indexOf('.')>-1){return}
  var D=document.Vote
  if (oc_flag==1) {
    var Q1="Do you wish to unpick this image ("+img+")?"
    if (confirm(Q1)) { D.action.value='del' }
    else {return}
    }
  else {D.action.value='add'}
  var features="width=200,height=100"
  voteWin=window.open('','Votewin',features)
  setTimeout("writeListX('voteWin')",200)
  D.image.value=img
  D.user.value=Fi
  if(D.h_ref.value.indexOf(OWN)==-1){D.h_ref.value=location.pathname}
  D.target='Votewin'
  setTimeout('document.Vote.submit()',300)
  }

// function to stuff comment into voting window
function writeListX(arg){
  var content='<HTML><HEAD><TITLE>VOTE</TITLE>\n'
  content+='</HEAD><body text="#666666" bgcolor="#000000" link="#666666" vlink="#333333" alink="#FF0066">\n'
  content+='<center><br>&nbsp;<br>&nbsp;Accessing voting process...</center><br>\n'
  content+='</BODY></HTML>\n'
  voteWin.document.write(content)
  voteWin.document.close()  // throws an error in NN ??
  }
// function to store favorite vote
function old_Atemp(img) {
  if (Fi=='') {alert("You need to log in with a voter name in\norder to pick your favorites."); return}
  //if(!confirm("Voting is currently unavailable.\n Sorry.\n(press OK or YES)")){

  if (oc_flag==1) {
    var Q1="Do you wish to unpick this image ("+img+")?"
    if (confirm(Q1)) { document.Vote.action.value='del' }
    else {return}
    }
  else { document.Vote.action.value='add' }
  var D = document.Vote.h_ref
  document.Vote.image.value=img
  document.Vote.user.value=Fi
  if(D.value.indexOf(OWN) == -1){D.value=location.pathname}
  //alert(D.value)
  document.Vote.submit()
  } //}


// this opens a new window for a URL
function newBrowser(site) {
  window.open(site,"sub","status,location,menubar,resizable,scrollbars,screenX=20,screenY=20");
  }

// navigates to other pages of headshots, sends the user number too.
function goPage(pg) {location.href=pg+"?"+Fi}

// this runs an email script.
function emails(ses) {
  document.Emails.ses_ID.value=ses
  document.Emails.submit()
  }


function stealth(arg, dims, obj){
  cookIt()
  var features="width=200,height=100"
  ordWin=window.open('','ord',features)
  setTimeout("writeOrd('ordWin')",200)
  var O=document.Order
  O.Action.value="Add"
  var Src=temp.src
  if(oc_flag==1){
    O.Action.value="Delete"
    Src=HOME+"/images/OrderOFF.gif"
    }
  var H=location.pathname
  var Di = H.lastIndexOf('/')
  var D = H.substring(0,Di)
  var dirs=D.split('/')
  var Ddir=dirs[2]
  var Sdir=dirs[3]
  var xy = dims.split('x')

  O.Iurl.value='image.html?'+arg+'.'+xy[0]+'.'+xy[1]+'.'+Ddir+'.'+Sdir+'.1'

  if((O.Session)&&(O.Session.value)){
    O.target="ord"
    //alert(O.Iurl.value)
    setTimeout("document.Order.submit()",300)
    document['Order'+arg].src=Src
    }
  return false
  }

// function to stuff comment into order window
function writeOrd(arg){
  var content='<HTML><HEAD><TITLE>Reproductions</TITLE>\n'
  content+='</HEAD><body bgcolor="#000000" text="#999999">\n'
  content+='<center><br>&nbsp;<br>&nbsp;'+arg+'</center><br>\n'
  content+='</BODY></HTML>\n'
  ordWin.document.write(content)
  ordWin.document.close()  // throws an error in NN ??
  }
//
