// JavaScript Document

function printDocument() {
	window.print();	
}

sfHover = function() {
  var sfEls = document.getElementById("vpnavigation").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function tmt_winHistory(id,s){
	var d=eval(id)==null||eval(id+".closed");
	if(!d){eval(id+".history.go("+s+")");}
}

function rover (id, source) {
	document.getElementById(id).src = source;
}

// FAQ-Expand
function faq_expand(targetId){
	if (document.getElementById){
		target = document.getElementById('f_' + targetId);
		if (target.style.display == "") {
			target.style.display = "none";
		} else {
			target.style.display = "";			
			
			/*for (i=1;i<=anz_f;i++) {				
				if (i != targetId) {
					target = document.getElementById('f_' + i);
					if (target != null) {
						if (target.style.display == "") {
							target.style.display = "none";
						}			
					}
				}
			}*/
		}		
	}
}

/*------------------------------------------------------------
*  Function:  openPopupWindow
*  
*  Description:
*  opens a popup window of a passed width and height
*  and loads the passed URL in it
*  
*  Parameters:
*  url			string		page to load
*  w			integer		width of popup window
*  h			integer		height of popup window
*  features		string		window features - see below for defaults
*  
*  Return:
*  none
*------------------------------------------------------------*/
var popupWindow=null;

function openPopupWindow(url,w,h,features) {
	if (w == null || w=='') w = 400;
	if (h == null || h=='') h = 400;
	if (features == null) features = ",status=0,location=0,directories=0,resizable=1,scrollbars=1";
	
	if (url) {

		if ( (popupWindow!=null) && !popupWindow.closed && popupWindow.location ){
			popupWindow.location.href = url;
			popupWindow.focus();
		} else {
			popupWindow = window.open(url,'popupWindow','width='+w+',height='+h+features);
			popupWindow.focus();
			if (!popupWindow.opener) popupWindow.opener = self;
		}

	}
}

/*------------------------------------------------------------
*  Function:  hide
*  
*  Description:
*  hides an object from display
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide(which) {
	var obj = getObject(which);
	if (obj) obj.style.visibility = "hidden";
}

/*------------------------------------------------------------
*  Function:  getObject
*  
*  Description:
*  accepts an object reference or a string, returns an object reference
*  
*  Parameters:
*  which	string or object	ID of HTML dom entity, or reference to an object
*  
*  Return:
*  obj		object				reference to named or passed DOM object
*------------------------------------------------------------*/
function getObject(which) {
	var obj;
	if (typeof(which) == "object") {
		obj = which;
	} else if (typeof(which) == "string") {
		obj = document.getElementById(which);
	} else {
		obj = null;
	}
	
	return obj;
}

/*------------------------------------------------------------
*  Function:  hide_select_fields_for_email_this_page
*  
*  Description:
*  
*  
*  
*  Parameters:
*  visible_style = visible or hidden
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide_select_fields_for_email_this_page(visible_style)
{

	var emailUA = navigator.userAgent.toLowerCase();
	var emailIsIE = ( (emailUA.indexOf("msie") != -1) && (emailUA.indexOf("opera") == -1) && (emailUA.indexOf("webtv") == -1) );
	if(emailIsIE)
	{
		var emailVer = parseFloat(navigator.appVersion); 

		// correct version number for IE4+ 
		if (emailVer >= 4)
			emailVer = parseFloat( emailUA.substring( emailUA.indexOf('msie ') + 5 ) );

		if (emailVer < 7)
		{
			var select_tag_items = document.getElementsByTagName('select');
			for (var i = 0; i < select_tag_items.length; i++)
				select_tag_items[i].style.visibility = visible_style;
		}
	}

}

/*------------------------------------------------------------
*  Function:  show
*  
*  Description:
*  shows an object, if not nested in a hidden object
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function show(which) {
	var obj = getObject(which);
	if (obj) obj.style.visibility = "inherit";
}


/*=========================================================================================
	email this page			// BUGFIX ID 7
==========================================================================================*/

var emailFormTop;									// integer used to track position of email form
var emailFormObject;								// html object reference - value is set later
var emailFormID = "emailThisPage";					// html ID of email form
var emailViewerID = "emailThisPageViewer";				// html ID of viewer div surrounding email form
var emailFormInterval;								// timeout variable
var emailScrollIncrements = new Array(40,10,3,1);	// array of scroll increments to create an 'ease out' effect. last item should always be '1'
var emailScrollIncrement = 0;						// index variable to step through the above array


/*------------------------------------------------------------
*  Function:  emailThisPage
*  
*  Description:
*  sets position of email form and calls scrolling function
*  called when user clicks email this page button in page tools module
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function emailThisPage(page_url, page_name, property_name, language) {
	// only run if email form isn't already showing

	if (getObject(emailViewerID).style.visibility != "inherit") 
	{

		// Using prototype.js framework to retrieve confirmation page.
		var ajaxUpdater = new Ajax.Updater(
			getObject(emailViewerID),
			"form.php",
			{
				method:		'get',
				onComplete:	gotEmailForm,
				parameters:     "page_url=" + escape(page_url) + "&page_name=" + escape(page_name) + "&property_name=" + escape(property_name) + "&language=" + escape(language)
			}
		);
		hide_select_fields_for_email_this_page("hidden");

	}
}


/*------------------------------------------------------------
*  Function:  gotEmailForm
*  
*  Description:
*  Event handler for successful completion of call to
*  AJAX.Updater that loads the email form into the emailThisPage div. 
*  
*
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function gotEmailForm() 
{
	emailFormObject = getObject(emailFormID);
	
	// RALPH: Bestimmung der Höhe des Browserfensters
	myHeight = window.innerHeight;
	if (!myHeight) {
		myHeight = document.body.clientHeight;
	}		
	
	//move email form upward out of view
	emailFormTop =  0 - (emailFormObject.offsetHeight + 10);
	emailFormObject.style.top = emailFormTop + "px";	

	// line below sets height of viewer div to 10px larger than email form
	// may need to increase this value if error messages are inserted into the form
	// or push it out to a separate function that can be called by the error display function
	getObject(emailViewerID).style.height = (emailFormObject.offsetHeight + 100) + "px";
	show(emailViewerID);

	// set email button to selected state and freeze it to prevent rollovers
	//imgOn('ptm_email');
	//rollovers['ptm_email'].frozen = true;
	//getObject('ptm_email').className = FROZEN_CLASS;

	// stuff document URL into hidden field and into form display for user feedback
//	if(getObject('pageURL'))
//		getObject('pageURL').value = document.location.href;
//	if(getObject('pageURLdisplay'))
//		getObject('pageURLdisplay').innerHTML = document.location.href.substring(0,80);

	scrollEmailForm();

	
}


/*------------------------------------------------------------
*  Function:  scrollEmailForm
*  
*  Description:
*  does the work of scrolling the email form
*  uses an array of scroll increments, defined above, to create an ease-out effect
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function scrollEmailForm() {		
	
	/*var distance = 0 - emailFormTop;
	
	// if distance is less than 3 x current scroll increment, use next increment
	if (distance < emailScrollIncrements[emailScrollIncrement] * 3) {
		emailScrollIncrement++;
	}
	// make sure we don't exceed the bounds
	if (emailScrollIncrement >= emailScrollIncrements.length) emailScrollIncrement = emailScrollIncrements.length - 1;

	
	// Only scroll down if top edge is hidden
	if (emailFormTop < 0) {
		emailFormTop += emailScrollIncrements[emailScrollIncrement];

		// make sure we don't go past zero
		if (emailFormTop > 0) emailFormTop = 0;
		emailFormObject.style.top = emailFormTop + "px";

		// Wait to see if flag is reset. Otherwise, keep scrolling
		emailFormInterval = setTimeout("scrollEmailForm()", 10);
	} else {

		// stop scrolling
		clearTimeout(emailFormInterval);
		emailScrollIncrement = 0;
	}*/

	
	var distance = 0 - emailFormTop;
	
	// if distance is less than 3 x current scroll increment, use next increment
	if (distance < emailScrollIncrements[emailScrollIncrement] * 3) {
		emailScrollIncrement++;
	}
	// make sure we don't exceed the bounds
	if (emailScrollIncrement >= emailScrollIncrements.length) emailScrollIncrement = emailScrollIncrements.length - 1;

	
	// Only scroll down if top edge is hidden
	if (emailFormTop < 0) {
		emailFormTop += emailScrollIncrements[emailScrollIncrement];

		// make sure we don't go past zero
		if (emailFormTop > 0) emailFormTop = 0;
		emailFormObject.style.top = emailFormTop + "px";

		// Wait to see if flag is reset. Otherwise, keep scrolling
		emailFormInterval = setTimeout("scrollEmailForm()", 10);
	} else {

		// stop scrolling
		clearTimeout(emailFormInterval);
		emailScrollIncrement = 0;
	}	
}




/*------------------------------------------------------------
*  Function:  hideEmailThisPage
*  
*  Description:
*  hides email form when user clicks close window or cancel button
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hideEmailThisPage() {
	hide(emailViewerID);
	
	// unfreeze email button
	//getObject('ptm_email').className = UNFROZEN_CLASS;
	//rollovers['ptm_email'].frozen = false;
	//imgOff('ptm_email');

	hide_select_fields_for_email_this_page("visible");

}

/* begin BUGFIX ID 7 */
var pageURL = "";		// Placeholder for URL of page being e-mailed

/*------------------------------------------------------------
*  Function:  submitEmail
*  
*  Description:
*  Submit handler for E-mail this page form.  Provides
*  temporary simulation of an e-mail confirmation.  To be
*  replaced with proper form validation and submission.
*  
*  Parameters:
*  which	object	the e-mail form being submitted
*  formPage	object	the E-mail this form page
*  
*  Return:
*  none
*------------------------------------------------------------*/
function submitEmail(which, formPage) {
	// Retrieve the URL of the page being emailed.
	//pageURL = document.getElementById("pageURL").value;
	
	if(!(the_form = $(emailFormID)))
	{
		alert("Submission failed.\nCould not find form object");
		return;
	}
	
	params = Form.serialize(the_form);
	
	// Using prototype.js framework to retrieve confirmation page.
	var ajaxUpdater = new Ajax.Updater(
		formPage,
		"tellafriend_submit.php",
		{
			method:		'post',
			onComplete:	displayURL,
			parameters:     params
		}
	);
}



/*------------------------------------------------------------
*  Function:  displayURL
*  
*  Description:
*  Event handler for successful completion of call to
*  AJAX.Updater. Updates URL display in E-mail this page form
*  confirmation based on hidden input field.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function displayURL() {
	// Display the page being emailed.
	getObject('pageURLdisplay').innerHTML = pageURL;
	
	return true;
}	
/* end BUGFIX ID 7 */

/*=========================================================================================
	end email this page library
==========================================================================================*/
