var H, W, Factor=1, B4=false, Warn=true;

function once()			// Executed only once.
{	if (B4) return;
	B4 = true;
	window.onresize=resize;
	resize();
}

// Match body font to size of window.

function Finc()			// Increase by 10%
{	Factor *= 1.1;
	if (Factor > 5) Factor = 5;
	resize();
}

function Fdec()			// Decrease by 10%
{	Factor *= .9;
	if (Factor < .5) Factor = .5;
	resize();
}

function Fset()			// Reset factor
{	Factor = 1;
	resize();
}


// Percent of width: Define the size of "1.0em"

function resize()	// Set font relative to window width.
{	if (window.innerWidth)
		W = window.innerWidth;
	else
		W = document.body.clientWidth;

//   P =  Math.floor (W/33);				// ca. 3 percent constant
	P =  Math.floor (Factor*(8+W/65));		// Linear function
	if (P<10)P=10;							// Smallest size.
	document.body.style.fontSize=P + 'px';

	show = document.getElementById('warning');
	Ratio = window.screen.availWidth/W;
	if (Warn && Ratio > 1.5)				// Show Warn?
		Warn = false;
	if (Warn)
		show.style.display = 'block';
	else
		show.style.display = 'none';
}

// Submit a form

function Submit(form)
{	document.getElementById(form).submit();
}

// Make a URL with '&amp;' usable.

function openwindow (url)	// Open in another tab/window
{	window.open(url.replace(/&amp;/g,'&'));
}

function openself()			// Open self in new window, keep referer
{	Q = '?';
	var url = '' + window.location;
	if (url.indexOf ('?')>0) Q = '&';
	openwindow (url+Q+"rfr="+referer);	//	referer must be defined earlier.
}

// Special ad
function openad()
{	window.open(adurl);
}

// find correct separator
function separator (string)
{	return (string.indexOf ('?') >=0 ) ? '&':'?';
}
// Open mail form
function openmail()
{	Q = separator (marketmail);
	window.open(marketmail+Q+'lang='+lang+'&'+'rfr='+referer);
}

// Open same in new language, keep referer and other query data.

function newlang(lang)
{	var first, newurl, url, prams, Q, l, str, code;
	newurl = url = new String(window.location);
	first = url.indexOf ('?');
	if (first>0)
	{	newurl = url.substring(0,first);
		prams = url.substring(first+1);
	}
	else
		prams = '';

	Q = '?';
	str = code = '';
	while (prams.length > 0)
	{	next = prams.indexOf ('&');
		if (next<0)
			prams = '';
		else
		{	str = prams.substring (0,next);
			prams = prams.substring (next+1);
//			alert ("str = "+str);
			l = str.indexOf ('=');
			if (l<0) l = str.length;
//			alert ("length: "+l);
			if (l>0)
			{	code = str.substring(0,l);
//				alert ("code = "+code);
				if (code != 'lang'
				&&  code != 'rfr')
				{	newurl += Q + str;
//					alert (newurl);
					Q = '&';
				}
			}
		}
	}
//	alert ("a: "+newurl);
	newurl += Q + 'lang=' + lang;
	if (referer) newurl += '&rfr=' + referer;
//	alert ("b: "+newurl);

	window.location.href = newurl;
}


