//common scripts for most Wellsprings-antiques.com documents
//script list:
//whocalled()
//getBP()
//newWin
//infolink(ilink,iwparm)
//varcheck()

//whocalled variables
var calledby
var opWN //openerWindowName
var WSidx
var prevDoc

// getBP() variables: browser & platform determination
var browser
var platform
var browserwarn="Wellsprings-antiques.com was designed for navigation using Microsoft Internet Explorer or Netscape Navigator for Windows or Macintosh, versions 4.0 or later.  For best results, please use one of these browsers to view our site.  If you *are* using one of them and get this message, please let me know at once!  Thank you!  ...Dave, Wellsprings Antiques webmaster, dse@Wellsprings-antiques.com"
var BP

//varcheck variables..this one only used by learn pages
var compare //is specified on each learn page but here also in case learn page opened externally

//getwindims variables
var newWidth
var newHt

//infolink variables
var winPath
var winName
var winFeats
var winDims
var winParms
var ifiletype

//end of variable declarations...for now

//whocalled() determines how document was opened so back, close and home buttons work...
function whocalled() { 
//was this document opened by a javascript call
if (window.opener==null) {
calledby="extDoc"
} // end if A
else {  // was it called by other than WSdotcom
	opWN=window.opener.name
	WSidx=window.opener.name.indexOf("WS")
	if (WSidx==-1){
	calledby="extWin"
	} // end if B
	else{ // what WS document type called it 
		if (WSidx==0) {
		//calledby WShome, WSitem or WSprf, but check not WSinfo
		calledby=opWN
			if (opWN=="WSinfo"){ //was it opened by an infodocument using an unpatched infolink 
			alert ("opWN error; please inform the webmaster what link you clicked when this message appeared.  Thanks!");
			} // end if D, error check for orphan infolinks 
		} // end if C
	} // end else B
}  // end else A
//alert ("Calledby="+calledby);
} // end whocalled()


//getBP() determines browser and platform so ideosyncracies can be compensated for
function getBP() {
if (navigator.appName=="Microsoft Internet Explorer") {
	if (navigator.userAgent.indexOf("AOL")>-1) {
	browser="AOL"
	}
	else {
	browser="MSIE"
	}
}
else {
	if (navigator.appName=="Netscape") {
	browser="Netscape"
	}
	else {
	alert(browserwarn);
	}
} //browser determined
if (navigator.appVersion.indexOf("Win")>0) {
platform="PC"
}
else {
	if (navigator.appVersion.indexOf("Mac")>0) {
	platform="Mac"
	}
	else {
	alert(browserwarn);
	}
} //platform determined
BP=(browser+","+platform);
} //end getBP



//newWin() provides browser and platform specific size adjustment for use by window.open calls
function newWin() {
getBP(); //determines browser and platform
switch (BP){
	case "MSIE,PC":
	newWidth=screen.availWidth*.95
	newHt=screen.availHeight*.83
	break;
	case "MSIE,Mac":
	newWidth=Math.round(screen.availWidth*.97)
	newHt=Math.round(screen.availHeight*1)
	break;
	case "Netscape,PC":
	newWidth=Math.round(screen.availWidth*.98)
	newHt=Math.round(screen.availHeight*1)
	break;
	case "Netscape,Mac":
	newWidth=Math.round(screen.availWidth*.98)
	newHt=Math.round(screen.availHeight*.97)
	break;
	case "AOL,PC":
	newWidth=Math.round(screen.availWidth*.95)
	newHt=Math.round(screen.availHeight*.83)
	break;
	case "AOL,Mac":
	newWidth=Math.round(screen.availWidth*.95)
	newHt=Math.round(screen.availHeight*.8)
	break;
	default:
	alert (browserwarn);
	newWidth=screen.availWidth
	newHt=screen.availHeight
	}//end switch
}//end newWin

//infolink opens a new window of the appropriate size and features and the desired document
function infolink(ilink,iwparm) {
newWin(); //gets the full window adjusted dimensions
//next determine name and location of document to open
if (ilink=="learn") { //this is for all compare pages, opens learn.htm in local directory
winPath=("learn.htm")
} // end if ilink==learn
else {
	if (iwparm==null) { //this is for all infopages, opens document from /common directory
	winPath=(tldPath+"common/"+ilink+".htm");
	} // end if iwparm==null
	else {
		if (iwparm.charAt(0)=='#') { //in case want to open a page not at the top
		winPath=(tldPath+"common/"+ilink+".htm"+iwparm)
		}// end if iwparm==#...
		else {
		winPath=(tldPath+"common/"+ilink+".htm"); //default
		}// end else iwparm==#...
	}// end else iwparm==null
} // end else ilink==learn
//name and location determined

//next, name the window to keep Netscape happy; document will rename it
winName=(ilink)
//gee that was simple...

//now specify size (winDims) and features (winFeats)
winDims=("top=20,left=20,screenX=20,screenY=20,width="+newWidth+",outerwidth="+newWidth+",height="+newHt+",outerheight="+newHt); //full sized window
if (iwparm=='r0') {	//r0 turns off resize so imagemaps open in Netscape-Mac...
winFeats="scrollbars=1,status=1,location=1,resizable=0"
} //end if iwparm=='r0'
else {
winFeats="scrollbars=1,status=1,location=1,resizable=1,toolbar=1,menubar=1"
//alert ("New window should be full chrome");
} //full featured
winParms=(winDims+","+winFeats) //these are the window parameters

switch (iwparm){
case "later":
alert ("Unfortunately the page for this link is still under construction.  Please click 'Okay' to resume.")
break;
case "info":
window.location=winPath
break;
default:
window.open (winPath,winName,winParms);
}//end switch
}//end of infolink

function varcheck() {
alert ("calledby="+calledby+", opWN="+opWN+", WSisdx="+WSidx+", referring document= "+document.referrer)
}


//end of global scripts