// Code written by MJA Visser, for more info: mjavisserREMOVETHIS@hotmail.com

//globals
is_nav4up=top.window.is_nav4up;

function errorReport(text) {
	document.write("An internal error has occured while viewing this site. Please report this error to info@www.amicale.nl. We are sorry for any inconvenience.<br><br>");
	document.write("The error was: " + text);
	return false;
}

function whatLanguage() {
	if (is_nav4up) var language = navigator.language;
	else var language = navigator.userLanguage;	
	if (language.indexOf('nl') > -1) return 'nl';
	else if (language.indexOf('fr') > -1) return 'fr';
	else if (language.indexOf('en') > -1) return 'en';
	else return 'nl';
}

function findObj( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return false;
}

function checkLang(lang) {
	if(lang == 'nl' || lang == 'fr' || lang == 'en') {
		return true;
	} else {
		errorReport('language "' + lang + '" is currently not supported');
		return false;
	}
}

function whatDocroot(lang) {
	if(!checkLang(lang)) return false;
	switch(lang) {
		case 'nl': return "dutch/"; 
		case 'fr': return "french/";
		case 'en': return "english/";
		default: return "english/";
	}
	return false;
}

function createTitle(lang) {
	if(!checkLang(lang)) return false;
	switch(lang) {
		case 'nl': document.title = "Luxe villa te huur in Zuid-Frankrijk"; break;
		case 'fr': document.title = "Une villa luxueuse a louer dans le Sud de la France"; break;
		case 'en': document.title = "Luxurious villa for rent in the South of France"; break;
		default: errorReport('language "' + lang + '" not supported');
	}
	return false;
}

function checkItemID(itemID) {
	if(itemID == 'home' || itemID == 'villa' || itemID == 'indeling' || itemID == 'zwembad' || itemID == 'dorp' ||
	   itemID == 'stjalle' || itemID == 'nyons' || itemID == 'buis' || itemID == 'aktiviteiten' || 
	   itemID == 'prijzen' || itemID == 'voorwaarden' || itemID == 'reserveren' || itemID == 'kosten' || 
	   itemID == 'koopjes' || itemID == 'reactie' || itemID == 'taal' || itemID == 'weer' ||
	   itemID == 'slideshowPlay' || itemID == 'slideshowStop' || itemID == 'slideshowWait')  {
		return true;
	} else {
		errorReport('There is no menu item named "' + itemID + '"');
		return false;
	}
}

function welcomeStatus(lang) {
	if(!checkLang(lang)) return false;
	switch(lang) {
		case 'nl': window.status='Welkom op www.amicale.nl'; break;
		case 'fr': window.status='Bienvenue a www.amicale.nl'; break;
		case 'en': window.status='Welcome to www.amicale.nl'; break;
	}
	return true;
}

function link() {
	//left void on purpose
}

function createImageHref(lang, src, linkText, width, height, mouseOverText, base) {
	//optional attributes
	if(!mouseOverText) var mouseOverText="";
	if(!base) var base="";
	var text=""; //the text to write
	//first calculate the dimensions of the popup
	var closebutton = 50; // height of the close button
	var widthTotal=width;
	var heightTotal=parseInt(height)+closebutton;
	//get a good screen position
	var screenX = (screen.width - widthTotal) / 2;
	var screenY = (screen.height - heightTotal) / 2;

	text += '<a href="javascript:top.window.link();" ';
	text += 'onclick="window.open(\'' + base + 'templates/image.html?lang=' + lang + '&src=' + src + '&width=';
	text += width + '&height=' + height + '\', \'\', ';
	text += '\'resizable=yes, location=no, menubar=no, scrollbars=no, status=no, toolbar=no, ';
	text += ' width=' + widthTotal + ', height=' + heightTotal + ', screenX=' + screenX + ', left=';
	text += screenX + ', screenY=' + screenY + ', top=' + screenY + '\', true); return true;" ';
	text += 'onmouseover="window.status=\'' + mouseOverText + '\';return true;" ';
	text += 'onmouseout="top.window.welcomeStatus(\'' + lang + '\');">';
	text += linkText + '</a>';

	return text;
}

function createPageHref(lang, src, linkText, mouseOverText) {
	//optional attributes
	if(!mouseOverText) var mouseOverText="";
	var text=""; //the text to write
	//first calculate the dimensions of the popup
	var menu = 150;
	var spacingX = 40;
	var spacingY= 10;
	var menubar = 200;
	widthTotal=screen.width-menu-spacingX;
	heightTotal=screen.height-menubar-spacingY;
	//get a good screen position
	var screenX = menu;
	var screenY = menubar / 2;
	text += '<a href="javascript:top.window.link();" ';
	text += 'onclick="window.open(\'../templates/page_frameset.html?lang=' + lang + '&src=' + src + '\',\'\',';
	text += '\'resizable=yes, location=no, menubar=no, scrollbars=no, status=no, toolbar=no, ';
	text += ' width=' + widthTotal + ', height=' + heightTotal + ', screenX=' + screenX + ', left=';
	text += screenX + ', screenY=' + screenY + ', top=' + screenY + '\', true); return true;" ';
	text += 'onmouseover="window.status=\'' + mouseOverText + '\';return true;" ';
	text += 'onmouseout="top.window.welcomeStatus(\'' + lang + '\');">';
	text += linkText + '</a>';
	return text;
}

