// ***  variables **************************************************************


// *****************************************************************************
// ***  jump menu functions ****************************************************

function inv_jumpMenu(form_field) {
	var str_newURL;
	var selected_page = Number(form_field.options[form_field.selectedIndex].value);
	if ( Number(selected_page)  ) {
		// if ( inv_check_page_type("double") ) {
		//	var counter = ( selected_page % 2 == 0 ) ? 0 : 1; 
		//	str_newURL = "pages/page_" + (1000 + selected_page - counter) + "_d.html";
		//	document.form_view_option.form_field_pages_per_site.options[1].selected = true;
		// } else { 
		str_newURL = "pages/page_" + (1000 + selected_page) + "_s.html";
		// document.form_view_option.form_field_pages_per_site.options[0].selected = true; 
		// } 
		parent.fr_content.location = str_newURL;
	}
	form_field.selectedIndex=0
}


// *****************************************************************************
// ***  browse functions *******************************************************

function inv_goto_first_page() {
	// checks double or single page
	var str_contenttype = "s";
	// generates new URL
	var str_newURL = "pages/page_1001_" + str_contenttype + ".html";
	parent.fr_content.document.location = str_newURL;
}

function inv_goto_previous_page() {
	var counter = ( inv_check_page_type("single") ) ? 1 : 2;
	var str_contenttype = "s";
	var str_currentpage = inv_get_page_number();
	var str_newURL;
	// check whether the next page still exists
	if ( str_currentpage - counter > 1000 ) {
		// fix for double pages and first and last page
		if ( inv_check_page_type("double") && inv_get_page_number() == 1002) counter = 1;
		if ( inv_check_page_type("double") && inv_get_page_number() == n_pages-1) counter = 1;
		// generate url	
		str_newURL = "pages/page_" + (str_currentpage - counter) + "_" + str_contenttype + ".html";
	} else {
		var str_lastpage = String(1000 + n_pages);
		str_newURL = "pages/page_" + str_lastpage + "_" + str_contenttype + ".html";
	}
	
	parent.fr_content.document.location = str_newURL;
}

function inv_goto_next_page() {
	var counter = ( inv_check_page_type("single") ) ? 1 : 2;
	var str_contenttype = "s";
	var str_currentpage = inv_get_page_number();
	var str_newURL;
	// check whether the next page still exists
	if ( str_currentpage + counter <= (n_pages + 1000) ) {
		// fix for double pages and first and last page
		if ( inv_check_page_type("double") && inv_get_page_number() == 1001) counter = 1;
		if ( inv_check_page_type("double") && inv_get_page_number() == n_pages-1) counter = 1;
		// generate url	
		str_newURL = "pages/page_" + (str_currentpage + counter) + "_" + str_contenttype + ".html";
	} else {
		str_newURL = "pages/page_1001_" + str_contenttype + ".html";
	}
	parent.fr_content.document.location = str_newURL;
}

function inv_goto_last_page() {
	//creates last page number
	var str_lastpage = String(1000 + n_pages);
	// checks double or single page
	var str_contenttype = "s";
	// generates new URL
	var str_newURL = "pages/page_" + str_lastpage + "_" + str_contenttype + ".html";
	parent.fr_content.document.location = str_newURL;
}

function inv_set_status_field() {
	var str_page = inv_get_page_number() - 1000;
	var status_text;
	// inv_check_page_type(param);
	if ( inv_check_page_type('single') || inv_check_page_type('double') ) {
		if ( str_page <= page_offset ) {
			status_text = " " + page_label[str_page];
		} else {
			status_text = " Page " + (str_page - page_offset) + " of " + (n_pages - page_offset);
		}
		document.form_view_option.form_field_status.value  = status_text;
	} else {
		document.form_view_option.form_field_status.value  = "";
	}
}


// *****************************************************************************
// ***  page type functions ****************************************************

function inv_set_single_page_view() {
	document.form_view_option.form_field_pages_per_site.options[0].selected = true;
}

function inv_set_double_page_view() {
	document.form_view_option.form_field_pages_per_site.options[1].selected = true;
}

function inv_toggle_page_type(page_type) {
	var str_newURL;
	var str_currentURL = inv_get_content_url();
	if ( !(inv_check_download_page() || inv_check_search_page() || inv_check_pdf_file()) ) { 
		if (page_type == 1) {
			// load the left page in single page view
			str_newURL = "pages/page_" + inv_get_page_number() + "_s.html";
		} else {
			var str_newpagenumber;
			// checks for odd page numbers
			if ( inv_get_page_number() % 2 == 0 ) { 
				str_newURL = "pages/page_" + inv_get_page_number() + "_d.html";
			} else {
				var counter = ( inv_get_page_number() == (n_pages + 1000) ) ? 0 : 1;
				if ( inv_get_page_number() == 1001 ) counter = 0; 
				str_newURL = "pages/page_" + ( inv_get_page_number()-counter ) + "_d.html";
			}
			
		}
		parent.fr_content.document.location = str_newURL;
	}
}


// *****************************************************************************
// ***  zoom functions *********************************************************

function inv_set_100_percent() {
	var new_img_width = ( parent.fr_content.document.image_2 ) ? 300 : 731;
	// error trap for download.html, search.html	
	if ( parent.fr_content.document.image_1 ) {
		parent.fr_content.document.image_1.width = new_img_width;
	}
	// if a 2nd image exists then change size
	if ( parent.fr_content.document.image_2 ) {
		parent.fr_content.document.image_2.width = new_img_width;
	}
}

function inv_zoom_out() {
	var current_img_width;
	var new_img_width;
	// error trap for download.html, search.html	
	if ( parent.fr_content.document.image_1 ) {
		current_img_width = parent.fr_content.document.image_1.width;
		new_img_width = ( (current_img_width - 100) >= 100 ) ? current_img_width-100 : current_img_width;
		parent.fr_content.document.image_1.width = new_img_width;
	}
	// if a 2nd image exists then change size
	if ( parent.fr_content.document.image_2 ) {
		parent.fr_content.document.image_2.width = new_img_width;
	}
}

function inv_zoom_in() {
	var current_img_width;
	var new_img_width;
	// error trap for download.html, search.html	
	if ( parent.fr_content.document.image_1 ) {
		current_img_width = parent.fr_content.document.image_1.width;
		new_img_width = ( (current_img_width + 100) <= 1900 ) ? current_img_width+100 : current_img_width;
		parent.fr_content.document.image_1.width = new_img_width;
	}
	// if a 2nd image exists then change size
	if ( parent.fr_content.document.image_2 ) {
		parent.fr_content.document.image_2.width = new_img_width;
	}
}


// *****************************************************************************
// ***  utils ******************************************************************

function inv_print_this_document() {
	inv_open_popup('print_document.html', 'print_view', 550, 450);
}

function inv_print_this_page() {
	if ( !(inv_check_download_page() || inv_check_search_page() || inv_check_pdf_file()) ) { 
		var str_page = inv_get_page_number();
		var str_layout = 'single';
		var str_url = 'print_page.html?page=' + str_page + '&layout=' + str_layout;
		inv_open_popup(str_url, 'print_view', 550, 450);
	}
}

// *****************************************************************************
// ***  utils ******************************************************************

function inv_get_content_url() {
	return String(parent.fr_content.document.location);
}

function inv_check_page_type(param) {
	var str_URL = inv_get_content_url();
	var result;
	if (param == "single") {
		result = (str_URL.indexOf("_s.html") == -1) ? false : true;
	} else if ( param == "double") {
		result = (str_URL.indexOf("_d.html") == -1) ? false : true;
	}
	 return result;
}

function inv_check_download_page() {
	var str_URL = inv_get_content_url();
	if ( str_URL.indexOf('downloads.html') > -1 ) { 
		return true 
	} else { 
		return false 
	}
}

function inv_check_search_page() {
	var str_URL = inv_get_content_url();
	if ( str_URL.indexOf('search.html') > -1 ) {
		return true 
	} else { 
		return false 
	}
}

function inv_check_pdf_file() {
	var str_URL = inv_get_content_url();
	if ( str_URL.indexOf('.pdf') > -1 ) {
		return true 
	} else { 
		return false 
	}
}

function inv_get_page_number() {
	var str_URL = inv_get_content_url();
	var result = parseInt( str_URL.substr(str_URL.indexOf(".html")-6, 4) );
	return result;
}

function inv_check_selection(param_form_name, param_field_name) {
	for(i=0; i<eval('document.' + param_form_name + '.' + param_field_name + '.length'); ++i) {
  		if ( eval('document.' + param_form_name + '.' + param_field_name + '.options[' + i + '].selected') == true ) {
   			return eval('document.' + param_form_name + '.' + param_field_name + '.options[' + i + '].value');
		}
	}
}

function inv_open_popup(str_url, str_name, int_width, int_height) {
	var winX = (screen.width - int_width) / 2;
	var winY = (screen.height - int_height) / 2;
	str_WinParams = 'height=' + int_height +',width=' + int_width + ',top=' + winY+',left=' + winX + ',menubar=1,toolbar=0,scrollbars=1,resizable=0,status=1,location=0'; 
	win = window.open(str_url, str_name, str_WinParams);
	if ((parseInt(navigator.appVersion) >= 4)|| (navigator.appName = 'Netscape')) { win.window.focus(); }
}

// *****************************************************************************

// eof