// common js functions
// 
// Copyright (c) 2004 Tribal DDB Canada
// James Marshall www.tribalddb.ca
// 
// v3.01

// image swapping
function swap( imgName, fileName ) {
	if ( document.images ) {
		document[imgName].src = "/personalinvest/retirementyourway/images/" + fileName;
	}
}

function isName( string ) {
	if ( string.match(/^[A-Za-z\'\- ]+$/) )
		return true;
	return false;
}

function isEmail( string ) {
	if ( string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1 ) {
		return true;
	} else {
		return false;
	}
}

function isEmailMulti( string ) {
	// email addresses separated by commas
	if ( string.search(/^(\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+(,( )?)?)+$/) != -1 ) {
		return true;
	} else {
		return false;
	}
}

function isDate(year, month, day) {
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	var tempDate = new Date(year,month,day);
	if( (tempDate.getYear() == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isPhone( phone ) {
	// 3+3+4 digit
	if( phone.match(/^\d\d\d\-\d\d\d\-\d\d\d\d$/) )
		return true;
	return false;
}

function fixPhone( phone ) {
	var num = phone.value;
	var newnum = "";
	var output = "";
	// strip out non-numbers
	for ( var i = 0; i < num.length; i++ )
		if ( num.charAt( i ).match(/\d/) )
			newnum += num.charAt( i );
	if ( newnum ) {
		// rebuild number with hyphen
		for ( var i = 0; i < newnum.length; i++ ) {
			if ( i == 3 || i == 6 )
				output += "-";
			else if ( i == 10 )
				output += " ";
			output += newnum.charAt( i )
		}
	}
	// return value
	phone.value = output;
}

function isZip( zip ) {
	// 5 digit zips
	if( zip.match(/^\d\d\d\d\d$/) )
		return true;
	// 5+4 digit zips
	if( ( zip.match(/^\d\d\d\d\d\d\d\d\d$/) ) || ( zip.match(/^\d\d\d\d\d\-\d\d\d\d$/) ) )
		return true;
	return false;
}

function isPostalCode( pc ) {
	// canadian postal codes (6 or 7 characters)
	if( ( pc.match(/^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$/) ) || ( pc.match(/^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/) ) )
		return true;
	return false;
}

function fixPostalCode( pc ) {
	var newpc = "";
	var output = "";
	// strip out non-alphanumeric
	for ( var i = 0; i < pc.value.length; i++ )
		if ( pc.value.charAt( i ).match(/\w/) )
			newpc += pc.value.charAt( i );
	if ( newpc ) {
		// rebuild number with space
		for ( var i = 0; i < 6; i++ ) {
			output += newpc.charAt( i )
			if ( i == 2 )
				output += " ";
		}
	}
	// return value in uppercase
	pc.value = output.toUpperCase();
}

// popup windows
function popup( url, name, w, h ) {
	var x = (screen.width - w) / 2;
	var y = (screen.availHeight - h) / 2;
	var page = window.open(url,name,"toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=" + w + ",height=" + h + ",screenX=" + x + ",screenY=" + y + ",top=" + y + ",left=" + x + "");
	page.focus();
}

// launch flash bmo tool
function launch() {
	popup('/retirementyourway/newretire_en.asp','tool',818,590);
}

function launch_book() {
	popup('http://bmo.trbv.com/ryw/indexFlash.htm','book',818,590);
}

function podcastFaq()
{
	window.open('/retirementyourway/PodcastsFaq.asp', 'FAQ', 'width=800, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizeable=no');
}

function launch_midlife()
{
	window.open('/retirementyourway/midlife.asp?WT.ac=a1271_Ade_RYW', 'FAQ', 'width=817, height=318, toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizeable=no');
}


function toggle_visibility(obj) {
		var i = document.getElementById(obj);
		i.style.display = (i.style.display != 'none' ? 'none' : 'inline' );
		obj2 = obj + "_image";
		var j = document.getElementById(obj2);
		j.src = (i.style.display != 'none' ? '../personalinvest/retirementyourway/images/minus.JPG': '../personalinvest/retirementyourway/images/plus.JPG');

}


function customTrack(tag) {
	var xmlpath = "/personalinvest/tracker.xml?" + tag;
	bmoTracker(xmlpath, tag);
}


function bmoTracker(xmlpath, url) 
{
 	if (window.ActiveXObject)
 	{
 		btracker=new ActiveXObject("Microsoft.XMLDOM");
		btracker.async=false;
 		btracker.load(xmlpath);
	}
	else if (document.implementation && document.implementation.createDocument)
 	{
 		btracker= document.implementation.createDocument("", "", null);
 		btracker.async=false;
		btracker.load(xmlpath);
 	}
else 
	{
		//alert('Your browser does not allow this script.'); 
	}
}
