// JavaScript Document

var max_msg = 200;
var messages = new Array("I recently came across this article and thought of you. It said that family history accounts for 30% of all breast cancer cases. Because I care about you, I wanted to send you this reminder to schedule your yearly mammogram today. It's important.","I found this today and wanted to pass it along. It said that a yearly mammogram was the key to early detection and survival. I thought it was important and wanted to share with you. Talk soon!");
var start_msg = messages[0];
var swf_loaded = false;
var movie = null;



function init(){
	
	if (navigator.appName.indexOf("Microsoft") > -1) {
		var d = document.getElementById("fx");
		ds = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"550\" height=\"400\" id=\"card\" align=\"middle\">";
		
		ds += "<param name=\"allowScriptAccess\" value=\"always\" />";
		ds += "<param name=\"allowFullScreen\" value=\"false\" />";
		ds += "<param name=\"wmode\" value=\"transparent\" />";
		ds += "<param name=\"movie\" value=\"card.swf\" />";
		ds += "<param name=\"quality\" value=\"high\" />";
		ds += "<embed src=\"card.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"550\" height=\"400\" name=\"card\" align=\"middle\" allowScriptAccess=\"always\" wmode=\"transparent\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
		ds += "</object>";
		
		d.innerHTML = ds;
		movie = thisMovie("card");
		window.setTimeout(swf_check, 500);
	}else{
		movie = thisMovie("flash_ctr");
		swf_init();
	}
	
}

function swf_alert(){
	swf_loaded = true;
	//alert('swf_loaded');
}

function swf_check(){
	var t = 'X';
	if(!swf_loaded){
		t = 'N';
		window.setTimeout(swf_check, 500);
	}else{
		t = 'Y';
		swf_init();	
	}
}

function swf_init(){
	
	document.mammo_form.reset();
	document.mammo_form.message_txt.value = start_msg;
	
	updateCard(document.mammo_form.message_txt.value);
	updateTo(document.mammo_form.to_mail.value);
	updateFrom(document.mammo_form.from_mail.value);
	updateToName(document.mammo_form.to_name.value);
	updateFromName(document.mammo_form.from_name.value);
}

function message_bg(o){
	var btns = document.getElementById("message_btns");	
	btns.className = "";
	btns.className = o;
	
	if(o=="msg1"){
		document.mammo_form.message_txt.value = messages[0];
		updateCard(messages[0]);
	}else{
		document.mammo_form.message_txt.value = messages[1];
		updateCard(messages[1]);
	}
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function updateCard(msg) {
	movie.sendCardUpdate(msg);
}

function updateTo(msg) {
	var l = msg.length >= 14 ? 14 : msg.length;
	if(msg.substr(0,l)!="e-mail address".substr(0,l)){
		movie.sendCardUpdateTo(msg);
	}else{
		movie.sendCardUpdateTo("");
	}
}

function updateFrom(msg) {
	var l = msg.length >= 14 ? 14 : msg.length;
	if(msg.substr(0,l)!="e-mail address".substr(0,l)){
		movie.sendCardUpdateFrom(msg);
	}else{
		movie.sendCardUpdateFrom("");
	}
}

function updateToName(msg) {
	var l = msg.length >= 4 ? 4 : msg.length;
	if(msg.substr(0,l)!="name".substr(0,l)){
		movie.sendCardUpdateToName(msg);
	}else{
		movie.sendCardUpdateToName("");
	}
}

function updateFromName(msg) {
	var l = msg.length >= 4 ? 4 : msg.length;
	if(msg.substr(0,l)!="name".substr(0,l)){
		movie.sendCardUpdateFromName(msg);
	}else{
		movie.sendCardUpdateFromName("");
	}
}

function testMsg(){
	if(document.mammo_form.message_txt.value.length > max_msg){
		document.mammo_form.message_txt.value = document.mammo_form.message_txt.value.substr(0,max_msg);
	}
}