//<SCRIPT LANGUAGE="JavaScript">
<!--
//----------------------------------------------------------------------------//
// Mainfunction can be called in two ways (in both cases title is optional) : //
//                                                                            //
// tranferview(image,type,title)              (type may NOT be numeric)       //
// tranferview(image,width,height,type,title) (width MUST be numeric)         //
//----------------------------------------------------------------------------//

//----------------//
// User variables //
//----------------//

// Default title (use if not given when calling transferview)
var default_title="Strippagina Image"

// Maximum number of retries to get the picture (1 retries is 0.5 second wait)
// Put it to -1 to wait forever (or user cancel).
var maxretries = 20

// Define if you want to wait for the full image to load before display (true) or not (false)
// NOTE: This is only applicable when NO height and width are specified !!
var image_loadcomplete = true

// Background image for screens below
var info_background_image = 'preload_background.jpg'

// Image info for load(wait) screen
var info_load_image = 'preload_loadtxt.gif'
var info_load_height = 162
var info_load_width = 48
var info_load_headtext = 'Loading wait...' 
// Image info for timed-out screen
var info_to_image = 'preload_errortxt.gif'
var info_to_height = 185
var info_to_width = 47
var info_to_headtext = 'Not found in time'
// Image info for not found screens
var info_nf_image = 'preload_errortxt.gif'
var info_nf_height = 185
var info_nf_width = 47
var info_nf_headtext = 'Not found'

// This function changes a type specification to a URL, this way when pictures are
// moved to another site this is all that has to be changed (not the HTML pages)
function TypeToUrl(type) {
	// Convert the destination URL
	// Remember to also change  include_settings.asp if new entries are added below
	if (type=="same") URL = ""
//	if (type=="cplycos") URL = "http://members.lycos.nl/stripscans/"
//	if (type=="lycos2") URL = "http://members.lycos.nl/stripscans/part2/"
//	if (type=="cpbravenet") URL = "http://www.strippagina.nl/get_image.asp?get_image=http://rslegt.bravepages.com/"
//	if (type=="bravenet2") URL = "http://www.strippagina.nl/get_image.asp?get_image=http://rslegt.bravepages.com/part2/"
	if (type=="local") URL = "http://www.strippagina.nl/images/"
	if (type=="home") URL = "http://82.95.171.158/Strippage/local/"
}

//-----------------------//
// End of user variables //
//-----------------------//

// Several variables use in the routines
var width,height,image,type
var cond1,cond2
var titel,URL
var retries = 0
var picture = new Image()

// Mainfunction can be called in two ways (in both cases title is optional) :
// image,type,title (type may NOT be numeric)
// image,width,height,type,title (width MUST be numeric)
function transferview(image,parm1,parm2,parm3,parm4) {
	
	// Find out if parm1 (type or width) is numberic or not
	if (isNaN(parm1)) {
		// Put destination in front of image
		TypeToUrl(parm1)
		image = URL + image
		PreloadImage(image,parm2)
	}
	else {
		// Put destination in front of image
		TypeToUrl(parm3)
		image = URL + image
		DisplayImage('image',image,parm1,parm2,parm4)
	}
}
	
// Function to Preload the image and in this way get the size of it,
// this way this doesn't have to be specified when calling transferview
function PreloadImage(image,titel) {

	// Max retries 0 is not allowed (picture will never be shown)
	if (maxretries == 0) maxretries = -1
	
	// Put a wait picture in the window
	if (retries == 0) {
		DisplayImage('load',info_load_image,info_load_height,info_load_width,info_load_headtext)
		// Preload Image
		picture = new Image()
		picture.onerror = ImageError
		picture.src = image
	}
	
	// ReTry 10 times to load the picture, if still fails put error picture in window
	if (retries == maxretries | LoadWindow.closed) {
		// Close the wait window (if still open)
		if (!LoadWindow.closed) LoadWindow.close()
		// Show error picture if time out occured
		if (retries == maxretries) DisplayImage('error',info_to_image,info_to_height,info_to_width,info_to_headtext)
		// Reset retries
		retries = 0
	}
	else {
		// Test to see if picture is to be fully loaded and if it is fully loaded
		if (image_loadcomplete && picture.complete) {
			ImageLoaded(image,titel)
		}
		else {
			// If picture heigth and width are known and image doesn't have to be fully loaded
			if (picture.height && picture.width && !image_loadcomplete) {
				ImageLoaded(image,titel)
			}
			else {
				// Non of the above applied so retry again
				retries = retries + 1
				setTimeout("PreloadImage('"+image+"','"+titel+"')",500);
			}
		}
	}
}

// An error occured loading the image
function ImageError() {
	if (!LoadWindow.closed) LoadWindow.close()
	DisplayImage('error',info_nf_image,info_nf_height,info_nf_width,info_nf_headtext)
}

// The image is loaded
function ImageLoaded(image,titel) {
	// Get height and width of picture
	height = picture.height
	width = picture.width
	// Reset retries
	retries = 0
	// Close the wait window (if still open)
	if (!LoadWindow.closed) LoadWindow.close()
	// Open the picture window
	DisplayImage('image',image,width,height,titel)
}

// This function displays an image in a new window (sizes have to be specified)
function DisplayImage(loadtype,image,width,height,titel) {

	// Test if width & height are given when function called
	if (width == 0) cond1 = 0
		else cond1 = (width+20);
	if (height == 0) cond2=0
		else cond2 = (height+70);

	// Test to see if titel is specified, if not set default
	if (arguments.length <5 | !titel | titel=="undefined") titel=default_title

	// Get screen size (compensate for windows startbar)
	var beeldx = screen.width
	var beeldy = screen.height - 47

	// Calculate to center the new window 
	var scrx = (beeldx-cond1)/2
	var scry = (beeldy-cond2)/2
//	if (scrx < 0) scrx = 0
//	if (scry < 0) scry = 0

	// Calculate if scrollbars are needed
	var scroll="no"
	if (cond1+10 > beeldx) {
		scroll = "yes"
		cond2 = cond2+10
		}
	if (cond2+10 > beeldy) {
		scroll = "yes"
		cond1 = cond1+10
		}
	if (scroll=="no" && cond1+10 > beeldx) scroll = "yes"
	
	// Compensate for scrollbars to fit in fullscreen window if needed
	if (cond1 > beeldx) cond1 = beeldx-10
	if (cond2 > beeldy) cond2 = beeldy-10

	// Fill HTLM new window data variables
	var s1 = "<TITLE>"+titel+"</TITLE>"
	var s3 = "<CENTER><IMG SRC='"+image+"' BORDER='0' HEIGHT='"+height+"' WIDTH='"+width+"'>"
	var s4 = "<FORM><INPUT TYPE='BUTTON' VALUE='Close Window'"+" onClick='self.close()'></FORM>"
	var s5 = "</CENTER></BODY>"

	// Put a new window on the screen depending on loadtype
	if (loadtype == 'load') {
		var s2 = "<BODY BACKGROUND="+info_background_image+">"
		var s4 = "<FORM><INPUT TYPE='BUTTON' VALUE='Cancel Wait'"+" onClick='self.close()'></FORM>"
		LoadWindow=window.open("", "newwin"+width,"toolbar=no,scrollbars="+scroll+",menubar=no,width="+cond1+",height="+cond2+",left="+scrx+",top="+scry)
		LoadWindow.document.write(s1+s2+s3+s4+s5)
		LoadWindow.document.close()
	}

	if (loadtype == 'error') {
		var s2 = "<BODY BACKGROUND="+info_background_image+">"
		ImageWindow=window.open("", "newwin"+width,"toolbar=no,scrollbars="+scroll+",menubar=no,width="+cond1+",height="+cond2+",left="+scrx+",top="+scry)
		ImageWindow.document.write(s1+s2+s3+s4+s5)
		ImageWindow.document.close()
	}

	if (loadtype == 'image') {
		var s2 = "<BODY>"
		ImageWindow=window.open("", "newwin"+width,"toolbar=no,scrollbars="+scroll+",menubar=no,width="+cond1+",height="+cond2+",left="+scrx+",top="+scry)
		ImageWindow.document.write(s1+s2+s3+s4+s5)
		ImageWindow.document.close()
	}
	
}
//-->
//</SCRIPT>
