//20041122-183403 SLdocumentation.pl 888sf0syyyysq XXNOTPERLXX
//consecut.js V. 2.1
//created by David W. Behroozi david@davidwbehroozi.com
// modified by HW 20110506 

//var imgsrcSwitch_A_o_SERVER_0="http:\/\/www.handbook.org\/A_o_SERVER_0\/";
var imgsrcSwitch_A_o_SERVER_0="http:\/\/handbook.org\/A_o_SERVER_0\/";


var fontnorm='<font face="ms sans serif" size="1" color="#000000">';
var fontx='<\/font>';
var s="&nbsp;";

//split URL, into URL and parameters
var params = document.location.href.split("?");
var filename = /(\w*\.\w*)$/.exec(params[0]);

// the array
var pictures = new Array();
var thefilename = new Array();
var theNEWnumber = new Array();
var theOLDnumber = new Array();
var thelaufnr = new Array();
var thetitle = new Array();
var captions = new Array();
var thecategory1 = new Array();
var thecategory2 = new Array();
var thecategory3 = new Array();
var thecategory4 = new Array();
var thedatum = new Array();
var themeasure = new Array();
var thetechnic = new Array();
var thestatus = new Array();
var theexhibit = new Array();
var thepubl = new Array();
var thecomment = new Array();



//number of consecs
var numConsecs=1;

//for temporarily storing the folder name
var folderName;
var thefilenamee;
var theNEWnumbere;
var theOLDnumbere;
var thelaufnre;
var thetitlee;
var caption;
var thecategory1e;
var thecategory2e;
var thecategory3e;
var thecategory4e;
var thedatume;
var themeasuree;
var thetechnice;
var thestatuse;
var theexhibite;
var thepuble;
var thecommente;



//current consec and picture number
var picture=0;
var consec=0;

//for storing additional parameters from URL
var paramString="?";

//increment through all of the params, extract consec and picture information and save additional params
if(params[1]){
	splitParams = params[1].split("&");
	for(i in splitParams){
		var a = /consec=(\d+)/.exec(splitParams[i]);
		if(a)
			consec=parseInt(a[1]);
		else{
			var p = /pic=(\d+)/.exec(splitParams[i]);
			if(p)		
				picture=parseInt(p[1]);
			else{
				paramString+=splitParams[i]+"&";
			}
		}
	}
}

//Adds a picture to the current consec with the filename and caption you specify
function add(thefilenamee,theNEWnumbere,theOLDnumbere,thelaufnre,thetitlee,caption,thecategory1e,thecategory2e,thecategory3e,thecategory4e,thedatume,themeasuree,thetechnice,thestatuse,theexhibite,thepuble,thecommente){
        if(numConsecs==0)
                alert("You must create an new consec using newConsec() before adding pictures to it");
        var index = pictures[numConsecs-1].length;
        //*chg987996g pictures[numConsecs-1][index] = folderName+filename;
        pictures[numConsecs-1][index] = thefilenamee;
        thefilename[numConsecs-1][index] = thefilenamee;
        theNEWnumber[numConsecs-1][index] = theNEWnumbere;
        theOLDnumber[numConsecs-1][index] = theOLDnumbere;
        thelaufnr[numConsecs-1][index] = thelaufnre;
        thetitle[numConsecs-1][index] = thetitlee;
        captions[numConsecs-1][index] = caption;
        thecategory1[numConsecs-1][index] = thecategory1e;
        thecategory2[numConsecs-1][index] = thecategory2e;
        thecategory3[numConsecs-1][index] = thecategory3e;
        thecategory4[numConsecs-1][index] = thecategory4e;
        thedatum[numConsecs-1][index] = thedatume;
        themeasure[numConsecs-1][index] = themeasuree;
        thetechnic[numConsecs-1][index] = thetechnice;
        thestatus[numConsecs-1][index] = thestatuse;
        theexhibit[numConsecs-1][index] = theexhibite;
        thepubl[numConsecs-1][index] = thepuble;
        thecomment[numConsecs-1][index] = thecommente;
}

//Creates a new consec and looks for images in current folder or the folder you specify
function newConsec(folder){
        pictures[numConsecs]=new Array();
        thefilename[numConsecs]=new Array();
        theNEWnumber[numConsecs]=new Array();
        theOLDnumber[numConsecs]=new Array();
        thelaufnr[numConsecs]=new Array();
        thetitle[numConsecs]=new Array();
        captions[numConsecs]=new Array();
        thecategory1[numConsecs]=new Array();
        thecategory2[numConsecs]=new Array();
        thecategory3[numConsecs]=new Array();
        thecategory4[numConsecs]=new Array();
        thedatum[numConsecs]=new Array();
        themeasure[numConsecs]=new Array();
        thetechnic[numConsecs]=new Array();
        thestatus[numConsecs]=new Array();
        theexhibit[numConsecs]=new Array();
        thepubl[numConsecs]=new Array();
        thecomment[numConsecs]=new Array();

        if(folder)
                folderName=folder+"/";
        else
                folderName="";
        numConsecs++;
}


//returns number of the previous image
function prevLinkHtml(content){
		consecExists();
		if(!content)
			content="";
        document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+pictures[consec].length-1)%pictures[consec].length+"'>"+content+"</a>");
}

//returns the number of the next image
function nextLinkHtml(content){
	consecExists();
	if(!content)
		content="";
	document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+1)%pictures[consec].length+"'>"+content+"</a>");
}


//returns number of the 5 previous image
function prevLinkHtmlminus5(content){
		consecExists();
		if(!content)
			content="";
        document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+pictures[consec].length-5)%pictures[consec].length+"'>"+content+"</a>");
}

//returns the number of the 5 next image
function nextLinkHtmlplus5(content){
	consecExists();
	if(!content)
		content="";
	document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+5)%pictures[consec].length+"'>"+content+"</a>");
}


//returns number of the 10 previous image
function prevLinkHtmlminus10(content){
		consecExists();
		if(!content)
			content="";
        document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+pictures[consec].length-10)%pictures[consec].length+"'>"+content+"</a>");
}

//returns the number of the 10 next image
function nextLinkHtmlplus10(content){
	consecExists();
	if(!content)
		content="";
	document.writeln("<a href='"+filename[0]+paramString+"consec="+consec+"&pic="+(picture+10)%pictures[consec].length+"'>"+content+"</a>");
}



//prints html code to display current image
function printImageHtml(){
	consecExists();

var nuryear = (theNEWnumber[consec][picture]);
var nuryear = nuryear.replace(/(\d\d\d\d)(.*)/, "$1");


	if(pictures[consec][picture])
		document.write('<a href="' + imgsrcSwitch_A_o_SERVER_0 + 'hw/Images/b/'+pictures[consec][picture]+'b.jpg" onClick="window.open(&#039;&#039;,&#039;'+pictures[consec][picture]+'&#039;,&#039;scrollbars=yes,status=no,width=501,height=549,resizable&#039;).focus();" target="'+pictures[consec][picture]+'"><img src="' + imgsrcSwitch_A_o_SERVER_0 + 'hw/Images/s/'+thefilename[consec][picture]+'.jpg" title="'+thetitle[consec][picture]+' '+nuryear+' ENLARGE" height="400" border="0"></a>');

	else
		//alert("Picture doesn't exist");
		document.write('<td width="400" height="300" bgcolor="#ffffff" align="center"><font face="ms sans serif" size="3" color="#ff0000"><b>N O\&nbsp\;\&nbsp\;\&nbsp\;E N T R I E S<\/b><\/font><\/td>');
}

//prints the caption
function printCaption(){
	consecExists();


var nuryear2 = (theNEWnumber[consec][picture]);
var nuryear2 = nuryear2.replace(/(\d\d\d\d)(.*)/, "$1");

	document.write(fontnorm+'\n');

        //document.write(pictures[consec][picture]);
        //document.write(' thefilename[consec][picture]='+thefilename[consec][picture]);

	document.write('<br> '+thelaufnr[consec][picture]+'.');
	document.write(s+s+s+' <b>'+thetitle[consec][picture]+' '+nuryear2+' <\/b>');


        document.write('<br>new nr:'+s+s+s+theNEWnumber[consec][picture]);

	if(theOLDnumber[consec][picture]){
        document.write('<br>old nr:'+s+s+s+theOLDnumber[consec][picture]);
			}else{
        document.write('<br>old nr:'+s+s+s+'[not available]');
			}

	if(captions[consec][picture]){
        //document.write('<br>descr:'+s+s+s+captions[consec][picture]);
			}else{
        //document.write('<br>descr:'+s+s+s+'[not available]');
			}



// remove tags <font color=\'#ff0000\'><b>ABSTR<\/b><\/font>
var reg1 = (thecategory1[consec][picture]);
var reg2 = (thecategory2[consec][picture]);
var reg3 = (thecategory3[consec][picture]);
var reg4 = (thecategory4[consec][picture]);


var reg1 = reg1.replace(/(<font\scolor=\'#ff0000\'><b>)(.*)(<\/b><\/font>)/, "$2");
var reg2 = reg2.replace(/(<font\scolor=\'#ff0000\'><b>)(.*)(<\/b><\/font>)/, "$2");
var reg3 = reg3.replace(/(<font\scolor=\'#ff0000\'><b>)(.*)(<\/b><\/font>)/, "$2");
var reg4 = reg4.replace(/(<font\scolor=\'#ff0000\'><b>)(.*)(<\/b><\/font>)/, "$2");


	if(thecategory1[consec][picture]){
	//document.write('<br>categories:'+s+s+s+'<a href="..\/..\/Fm1\/CAT'+reg1+'.htm" onClick="window.open(&#039;&#039;,&#039;CAT'+reg1+'&#039;,&#039;scrollbars=yes,status=no,width=501,height=549,resizable&#039;).focus();" target="CAT'+reg1+'">'+thecategory1[consec][picture]);
        //document.write('<\/a>');
			}

	if(thecategory2[consec][picture]){
	//document.write('\/<a href="..\/..\/Fm1\/CAT'+reg2+'.htm" onClick="window.open(&#039;&#039;,&#039;CAT'+reg2+'&#039;,&#039;scrollbars=yes,status=no,width=501,height=549,resizable&#039;).focus();" target="CAT'+reg2+'">'+thecategory2[consec][picture]);
        //document.write('<\/a>');
			}

	if(thecategory3[consec][picture]){
	//document.write('\/<a href="..\/..\/Fm1\/CAT'+reg3+'.htm" onClick="window.open(&#039;&#039;,&#039;CAT'+reg3+'&#039;,&#039;scrollbars=yes,status=no,width=501,height=549,resizable&#039;).focus();" target="CAT'+reg3+'">'+thecategory3[consec][picture]);
        //document.write('<\/a>');
			}

	if(thecategory4[consec][picture]){
	//document.write('\/<a href="..\/..\/Fm1\/CAT'+reg4+'.htm" onClick="window.open(&#039;&#039;,&#039;CAT'+reg4+'&#039;,&#039;scrollbars=yes,status=no,width=501,height=549,resizable&#039;).focus();" target="CAT'+reg4+'">'+thecategory4[consec][picture]);
        //document.write('<\/a>');
			}

	if(thedatum[consec][picture]){
        document.write('<br>date:'+s+s+s+thedatum[consec][picture]);
			}else{
        document.write('<br>date:'+s+s+s+'[not available]');
			}

	if(themeasure[consec][picture]){
        document.write('<br>size:'+s+s+s+themeasure[consec][picture]);
			}else{
        document.write('<br>size:'+s+s+s+'[not available]');
			}


	if(thetechnic[consec][picture]){
        document.write('<br>technic:'+s+s+s+thetechnic[consec][picture]);
			}else{
        document.write('<br>technic:'+s+s+s+'[not available]');
			}


	

	document.write(fontx+'\n');
}

//used to see if a caption exists
function captionExists(){
	consecExists();
	return captions[consec][picture];
}

function consecExists(){
	if(consec>=numConsecs||consec<0)
		alert("Consec doesn't exist");
}




