
var status=''
//var pnum

// Catalog Page Fetcher
function pageFetch(pnum){
pnum=pnum
// Catalog Section page range values
//  sX= last page number in section, sX1= last page number in subsection 1, sX2= last page number in subsection 2
// Change these values if section page ranges change
var s1=106
var s2=220
var s3=393
var s4=432
var s5=519
var s6=619
var s7=797
var s8=814
var s9=909
var s10=1017
var s11=1125
var s12=1207
var s13=1307
var s14=1435
var s15=1596
var s16=1669
var s17=1754
var s18=1837
var s19=1918
var s20=2068

var sec=0
var adj=0
var page=-1
var okay=true
var pmax=s20+1
var tempage= pnum
}

if(pnum==''||parseInt(pnum,10)<100||parseInt(pnum,10)>s20){
okay=false
}else{
if(parseInt(pnum,10)<1000){
sec=pnum.substr(0,1)
page=parseInt(pnum.substr(1,2),10)
}else{
sec=pnum.substr(0,2)
page=parseInt(pnum.substr(2,2),10)
}
pnum=parseInt(pnum,10)
}

// page system fix
// if 300a ok  if 300+ add 1
// if 1509 if a add 1, if  b add 2  if 1510 add 2
if(isNaN(pnum)==true){
if(tempage=='300a'){
sec='3'
page=0
pnum=300
}else if(tempage=='1509a'){
page=10
pnum=1509
}else if(tempage=='1509b'){
page=11
pnum=1509
}else {
okay=false               
}
}

if(okay==true){
for(i=1;i<pmax;i++){
if(sec==i){
if(pnum>eval("s"+i)){
okay=false
break
}
}
}
}

// Multi-PDF section checkers below- remember to edit or delete as required

if(okay==false){
errors(pnum)
}else{
page=page+1
var url='sec'+sec+'.pdf#page='+page
viewit(url)
}


// Page Error Notification
function errors(page){
window.alert("Sorry, "+page+" is an invalid page number")
document.getElementById('page').value=''
document.getElementById('page').focus()
}

// Catalog Section Viewer
function viewit(stuff){
if(status=="catalog"){
if(typeof vwr=="undefined"||vwr.closed()){
var wintxt='<html>'
wintxt=wintxt+'<head>'
wintxt=wintxt+'<title>MacMurray Pacific Catalog Viewer<\/title>'
wintxt=wintxt+'<\/head>'
wintxt=wintxt+'<frameset rows="82%, 7%" frameborder="0">'                 // original- <frameset rows="82%, 18%" frameborder="0">
wintxt=wintxt+'<frame name="pdf" src="catalog/'+stuff+'">'
wintxt=wintxt+'<frame name="nav" src="nav.html">'
wintxt=wintxt+'<\/frameset>'
wintxt=wintxt+'<\/html>'
var vwr= window.open("viewer.html","viewer")
vwr.document.open()
vwr.document.write(wintxt)
vwr.document.close()
}else{
vwr.document.pdf.src="catalog/"+stuff
}
vwr.focus()
}else{
parent.pdf.location='catalog/'+stuff
}
}

// Catalog Page Viewer- With INPUT & BUTTON
function catpage(){
pageFetch(document.getElementById('page').value)
}

// Catalog Page Viewer- With Links
function linkpage(){
pageFetch()
}

function getKey(e){
if(navigator.userAgent.indexOf('Mac') == -1){
var unicode=e.keyCode? e.keyCode : e.charCode
if(unicode==13){
document.getElementById('fetchit').click()
}
}
}

function ss(current){
if(document.getElementById("sales").value=="special"){
current='specials/'+current+'special.pdf'
window.open(current,'viewer')
}else if(document.getElementById("sales").value=="sspast"){
window.open('specials/index.html','viewer')
}else{window.alert("Correct!")}
}
