/* pop up windows */

function popIt(URL,width,height) {
	var attr;
	/* make a 10px border so images don't get resized */
	var width = width+20;
	var height = height+20;
	var URL = escape(URL)
	attr = "width="+width+",height="+height+",location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no";
	
	newWindow = window.open(URL, 'Popo', attr);
	newWindow.moveTo(20,20);
	newWindow.focus();	
	
}

function popWindow(URL,width,height) {
	var attr;
	/* make a 10px border so images don't get resized */
	var width = width+20;
	var height = height+20;
	attr = "width="+width+",height="+height+",location=yes, menubar=no, resizable=no, scrollbars=yes, status=no, toolbar=no";
	
	newWindow = window.open(URL, 'Popo', attr);
	newWindow.moveTo(20,20);
	newWindow.focus();	
	
}

/* guestbook form */
function validateMe() {
	// change the form action to the right page
	document.getElementById('guestbook-form').action = "contact.php";
	// submit the form
	document.getElementById('guestbook-form').submit();	
}

/* add events to the load event of window object */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, false);
   return true;
 } else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
 } else {
   return false;
 } 
}

/* if it's the contact page, add the submit form function */
function checkGuestbook() {
	var x = document.getElementById('guestbook-button');
	if (x) {
		x.onclick=validateMe;
	} else {
		return;
	}
}
/* trigger these functions on page load */
addEvent(window, 'load', checkGuestbook);

/* put in the link to the other language version of this page */
function thisPage(pageName,language) {
	/* get the filename out of the window.location.pathname variable that is passed into the function */
	page = pageName.substring(pageName.lastIndexOf('\/')+1);
	var link;
	link = '<a href="../';
	link += (language=='zh') ? 'zh/'+page+'" title="中文">' : 'en/'+page+'" title="English language">';
	link += (language=='zh') ? '中文' : 'English';
	link += '</a>';
	document.write(link);
	
}

