/*************************************
** Supporting functions for ANTA site
**
** Author: Min Liu
** Date: 20/01/09
**
** (C) Min Liu 2009
**************************************/
 
/**
 * function which obfuscates email addresses
 * can display a optional mailto and optional subject
 * NOTE: uses the vis-link style when displaying mailto's
 *
 * param mb			the mailbox name of the email
 * param ext		the domain extension of the email (optional: uses 2009wccm as default)
 * param mailto		provides the mailto link as well
 * param subject	defines the subject for mailto
 *
 * returns the full email address
 */
function show_email(mb,ext,mailto,subject) {
	if (typeof ext == 'undefined') ext='australiannaturaltherapistsassociation.com.au';
	if (typeof mailto == 'undefined') mailto=true;
	if (mailto) {
		if (typeof subject == 'undefined') {
			subject_str = '';
		} else {
			subject_str = '?subject='+subject;
		}
		document.write('<a href="mailto:'+mb+'@'+ext+subject_str+'" class="vis-link">'+mb+'@'+ext+'</a>');
	} else {
		document.write(mb+'@'+ext);
	}
}

/* var that keeps track of current open modal */
var modal_opened;

/**
 * function which pops up a element such as a DIV and centers it on screen
 * also can fade the background according to the fade-screen CSS style
 *
 * popup	the name of the object to popup
 * w		the width of the panel
 * h		the height of the panel
 * doFade	true or false
 */
function modal_popup(popup,w,h,doFade) {
	var panel = document.getElementById(popup);
	var top;
	var left;
	
	/* calculate center co-ords */
	if (typeof window.innerHeight != 'undefined') {
		top = Math.round((window.innerHeight-h)/2);
		left = Math.round((window.innerWidth-w)/2);
	} else {
		top = Math.round((document.body.clientHeight-h)/2);
		left = Math.round((document.body.clientWidth-w)/2);
	}
	
	/* show the panel */
	window.modal_opened = panel;
	panel.style.top = top + 'px';
	panel.style.left = left + 'px';
	panel.style.display = 'block';
	
	/* fade the background */
	if (doFade) {
		document.getElementById('fade-screen').style.display = '';
	}
}

/**
 * hides the modal popup and the fade screen
 * uses the modal_opened var to close the modal popup
 */
function modal_hide() {
	document.getElementById('fade-screen').style.display = 'none';
	window.modal_opened.style.display = 'none';
}

/**
 * displays the register note (modal popup) only on first visit
 */
function showRegisterNote() {
	if (!getRegisterNoteShown()) {
		/* show is */
		modal_popup('register-panel',350,300,true);
		setRegisterNoteShown();
	}
}

/**
 * checks to see if the register note has been shown already
 */
function getRegisterNoteShown() {
	if (document.cookie.indexOf('australiannaturaltherapistsassociation-registernote=shown') != -1) {
		return true;
	} else {
		return false;
	}
}

/**
 * sets a cookie to define that the register note has been shown
 */
function setRegisterNoteShown()
{
	document.cookie="australiannaturaltherapistsassociation-registernote=shown";
}
