
var	Curr_issue;
var	Install = 5; 	//  0=unset_get_cookie
var     DefPopx = 760;
var     DefPopy = 560;
var     Popx,Popy;
var	Mindimen = 250;		// if dimension out of this range, set to def
var	Maxdimen = 2048;
var	OStype;	//unk=0, win=1,mac=2,linux=3,sunos=4,unix=5 (can't tell os9/osx)
var	Browser;		//browser unk=0, ie=1, ns=2
var     UseDefPopSz = 1;        // if 1, ignore the popup size settings
var     Whentopop = 1;	// 0=not on search, 1=always, 2=never
var     Liteyear=0;	// do not put spaces around '=', set to pubyear if lite
var	ForceEmbed;
var	Topdir = 'http://journal.scconline.org/';
var	Cookienm = 'SCCconfig=';
var	Winnum = 0;

function jsInit(keep_cd){
	var	dir,systype,htmdir;

	systype = getSysInfo();
	OStype = (systype >> 8) & 0xff;
	Browser = systype & 0xff;
	htmdir = '/scc';
	setDefaults();
	// get Cookie to find Install
	getCookieVals();
	setCookieVals(Curr_issue);
}

function setDefaults(){
	var dir;

	Popx = DefPopx;
	Popy = DefPopy;
	Curr_issue = '';
	ForceEmbed = 0;
	if(OStype == 2){	// Mac (cant tell if osx or os9...assume 9)
		Whentopop = 2;	// assume acro reader used as helper
	}
}

function getBrowser(){
	return(Browser);
}

// platform values are MacPPC, Win95, WinNT, SunOS, linux, unix
// appName values are Netscape
// returns int, low order byte is browser, 2nd byte is os according to below
//	browser	unk=0, ie=1, ns=2
//	os	unk=0, win=1,mac=2,linux=3,sunos=4,unix=5 (can't tell os9/osx)
function getSysInfo(){
		var	os,app,sysinfo;

	os = navigator.platform.toLowerCase();
	app = navigator.appName.toLowerCase();
	sysinfo = 0;
	if(os.indexOf('win') != -1)
		sysinfo = 1;
	else if(os.indexOf('mac') != -1)
		sysinfo = 2;
	else if(os.indexOf('linux') != -1)
		sysinfo = 3;
	// haven't tried other unix, leave unknown
	sysinfo = sysinfo << 8;
	if(app.indexOf('microsoft') != -1)
		sysinfo |= 1;
	else if(app.indexOf('netscape') != -1)
		sysinfo |= 2;
	return(sysinfo);
}

function getInstall(){
	return(Install);
}

function getWhentopop(){
	return(Whentopop);
}

function getPopCtrl(){
	return(UseDefPopSz);
}

function getPopWidth(){
	return(Popx);
}

function getPopHeight(){
	return(Popy);
}

function getEmbed(){
	return(ForceEmbed);
}

function setissue(issue){
	Curr_issue = issue;
	setCookieVals(Curr_issue);
}

function showcurrentissue(){
	getCookieVals();
	if(Curr_issue == '')
		alert('No current issue defined!');
	else
		showissue(Curr_issue);
}

function showcookie(){
	confirm('cookie='+unescape(document.cookie));
}

function logout(){
    document.cookie =  '_csuid' + '; expires=Tuesday, 28-Oct-1984 08:00:00 GMT';
}


function clearcookie(nowarn){
	if(nowarn || confirm('Click OK to clear the cookie!')){
		document.cookie =  Cookienm + '; expires=Tuesday, 28-Oct-1984 08:00:00 GMT';
	}
}

function changeSettings(usedef,popwid,popht,whentopop,embed){
	UseDefPopSz = usedef;
	Popx = popwid;
	Popy = popht;
	Whentopop = whentopop;
	ForceEmbed = embed;
	setCookieVals(Curr_issue);
}

function setCookieVals(newissue){
	var	today = new Date();
	var	expires = new Date();
	var	cookie;

	Curr_issue = newissue;
	if(Popx <= Mindimen || Popx > Maxdimen)  Popx = DefPopx;
	if(Popy <= Mindimen || Popy > Maxdimen)  Popy = DefPopy;
	expires.setFullYear(today.getFullYear()+10);
	// make drive always LAST (in case it ever has a ':' in it
	cookie = Cookienm+escape(Install+';'+'crud'+';'+newissue+';'+'crud'
	+';'+Whentopop+';'+UseDefPopSz+';'+Popx+';'+Popy+';'+ForceEmbed) +
					'; expires=' + expires.toGMTString();
	document.cookie = cookie;
}

// this sets these globals:  Install, Curr_issue, and Curr_
function getCookieVals(){
	var	cookie,end,offset;
	var	a,crud;

	// First restore globals to their defaults in case of problems
	if(Install < 3)
		Install = 3;
//	Curr_issue = '';
	cookie = unescape(document.cookie);
	if(cookie == '')
		return;
	// if there are any cookies
	offset = cookie.indexOf(Cookienm);
	if(offset == -1)
		return;
	 // if cookie exists
	offset += Cookienm.length;
	cookie = cookie.substr(offset,cookie.length-offset);

	a = cookie.split(';');
	if(a.length < 4){
		// leaving this alert in, while potentially helpful
		// would cause pain if the user might otherwise be functional
//		alert('Cookie problem:  cookie='+cookie+' a.length='+a.length);
		clearcookie(1);	// try cloberring...maybe will work next time
		return;
	}
	Install = parseInt(a[0]);
	crud = a[1];
	Curr_issue = a[2];
	crud = a[3];
	if(a.length >= 8){
		Whentopop = parseInt(a[4]);
		if(Whentopop < 0 || Whentopop > 2)
			Whentopop = 0;
		UseDefPopSz = parseInt(a[5]);
		if(UseDefPopSz != 0 && UseDefPopSz != 1)
			UseDefPopSz = 1;
		Popx = parseInt(a[6]);
		Popy = parseInt(a[7]);
	}
	if(Popx <= Mindimen || Popx > Maxdimen)  Popx = DefPopx;
	if(Popy <= Mindimen || Popy > Maxdimen)  Popy = DefPopy;
	ForceEmbed = 0;
	if(a.length >= 9){
		ForceEmbed = parseInt(a[8]);
		if(ForceEmbed < 0 || ForceEmbed > 1)
			ForceEmbed = 0;
	}
	if(Install != 5)
		Install = 5;
}

function showarticle(year,issue,article,srchclik){
	var	path,i,doc,winopts,winstr;
		var	body,embed;

	if(Install == 0)
		getCookieVals();
	path = Topdir;
	path = path+'/pdf/'+'cc'+year+'/'+issue+'/'+article+'.pdf';
	setCookieVals(year+'/'+issue);
	if(Whentopop == 1 || (srchclik && (Whentopop == 0))){
winopts = 'location=no,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=yes';
		Winnum++;       // avoid ns bug that always uses same win
		winstr = 'w'+Winnum;
//		if(OStype == 1 && Browser == 1){
		if(ForceEmbed == 1){
			win = window.open('',winstr,'location=no, menubar=no, scrollbars=no, toolbar=no status=no',true);
			win.focus();
			doc = win.document;
body = '<body bgcolor=#bbbbbb bottommargin=0 leftmargin=0 rightmargin=0 topmargin=0 marginheight=0 marginwidth=0>';
embed = '<embed src='+path+' type=application/pdf width=100% height=100%></embed>';
//embed = '<OBJECT CLASSID="clsid:CA8A9780-280D-11CF-A24D-444553540000" width=100% height=100%> <PARAM NAME=SRC VALUE='+path+'> </OBJECT>';
			doc.open();
			doc.write(body);
			doc.writeln(embed);
			doc.writeln('</body>');
			doc.close();
		}else{
			win = window.open(path,winstr,winopts,true);
			win.focus();
		}
	}else{
		if(frames[1] == null)
			location.href = path;
		else
			right.view.location.href = path;
	}
}

// args look like cc,1998,cc63n02s,p00001-p00013.pdf
function showabs(year,issue,article){
	var	path;

	path = Topdir;
	path = path+'/abstracts/'+'cc'+year+'/'+issue+'/'+article+'.html';
	right.view.location.href = path;
}

function showissue(issue){
	var	doc;
	var	path;

	path = '/contents/'+issue+'.html';
	top.right.view.location = path;
}
