
function playTheVideo( vid ) {
	getFlashMovieObject("flashVideo").SetVariable("/:videotag",vid);
	getFlashMovieObject("flashVideo").TCallLabel("/jsfunc","doPlay");
}

function getFlashMovieObject(movieName) {
	// Safari: Mac OS X
	if ( navigator.userAgent.indexOf("Safari") != -1 )
		return document[movieName];
	else {
		// Firefox, Netscape: mac, win
		if ( document.embeds[movieName] )
			return document.embeds[movieName];
		
		// MSIE: Win
		else		
			return document[movieName];
	}
}

function setElementClass( inID, inClass ) {
	var elt = document.getElementById( inID );
	if ( elt )
		elt.className = inClass;
}

function login_remind() {
	document.forms["login"].a.value = "password";
	document.forms["login"].submit();
}
function login_showForgot() {
	var obj = document.getElementById( "passwordpanel" );
	if ( obj ) {
		obj.style.display = "block";
		document.forms["login"].a.value = "password";
		document.forms["login"].email_pswd.focus();
		document.forms["login"].email_pswd.select();
		isForgotVisible = true;
	}
	obj = document.getElementById( "loginpanel" );
	if ( obj ) {
		obj.style.display = "none";
	}
}
function login_hideForgot() {
	var obj = document.getElementById( "passwordpanel" );
	if ( obj ) {
		obj.style.display = "none";
		isForgotVisible = false;
	}
	obj = document.getElementById( "loginpanel" );
	if ( obj ) {
		obj.style.display = "block";
		document.forms["login"].a.value = "login";
		document.forms["login"].email_login.focus();
		document.forms["login"].email_login.select();
	}
}

function validateForm( inFormName, inFields ) {
	var form = document.forms[ inFormName ];
	var emailRE = /^((?:(?:(?:\w[\.\-\+]?)*)\w)+)\@((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.(\w{2,6})$/;
	var dateRE = new RegExp("^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})$");

	var missing = false;
	var errors = "";
	var confirm = [];
	

	var validateField = function( fld ) {
		var validated = true;
		if ( form[fld.id] && form[fld.id].value.length > 0 ) {
			if ( fld.validate == "email" ) {
				if ( !form[fld.id].value.match(emailRE) ) {
					ok = false;
					validated = false;
					errors += "Your email address is invalid. ";
				}
			}
			else if ( fld.validate == "date" ) {
				var valid = false;
				var matches = dateRE.exec( form[fld.id].value );
				if ( matches ) {
					var date = new Date( matches[3], (matches[1] - 1), matches[2] );
					valid = ((date.getMonth() == (matches[1] - 1)) && (date.getDate() == matches[2]) && (date.getFullYear() == matches[3]));
				}
				if ( !valid ) {
					ok = false;
					validated = false;
					errors += fld.label + " is invalid. ";
				}
			}
			else if ( fld.validate == "zip" ) {
				if ( form[fld.id].value == "0" ) {
					ok = false;
					validated = false;
					errors += fld.label + " is invalid. ";
				}
			}
		}
		else {
			ok = false;
			missing = true;
			validated = false;
		}
		return validated;
	}
	
	for ( var n = 0; n < inFields.length; n++ ) {
		var f = inFields[ n ];
		var ok = true;
		if ( f.either && f.or ) {
			var hase = true;
			for ( var e = 0; e < f.either.length; e++ ) {
				if ( form[f.either[e].id] && form[f.either[e].id].value.length == 0 )
					hase = false;
			}
			var haso = true;
			for ( var o = 0; o < f.or.length; o++ ) {
				if ( form[f.or[o].id] && form[f.or[o].id].value.length == 0 )
					haso = false;
			}
			var has = hase || haso;
			for ( var e = 0; e < f.either.length; e++ )
				setElementClass( f.either[e].id, has ? "verified" : "incorrect" );
			for ( var o = 0; o < f.or.length; o++ )
				setElementClass( f.or[o].id, has ? "verified" : "incorrect" );
			if ( !has ) {
				errors += f.msg;
				ok = false;
			}
			else {
				if ( hase ) {
					for ( var e = 0; e < f.either.length; e++ )
						setElementClass( f.either[e].id, validateField(f.either[e]) ? "verified" : "incorrect" );
				}
				if ( haso ) {
					for ( var o = 0; o < f.or.length; o++ )
						setElementClass( f.or[o].id, validateField(f.or[o]) ? "verified" : "incorrect" );
				}
			}
		}
		else {
			if ( f.reqd ) {
				validateField( f );
			}
			if ( f.confirm ) {
				confirm.push( {a:f.id, b:f.confirm, l:f.label} );
			}
			setElementClass( f.id, ok ? "verified" : "incorrect" );
		}
	}
	
	if ( missing )
		errors += "Some required fields are empty. ";
	
	for ( var n = 0; n < confirm.length; n++ ) {
		var c= confirm[ n ];
		if ( form[c.a] && form[c.b] && form[c.a].value.length > 0 && form[c.a].value != form[c.b].value ) {
			setElementClass( c.a, "incorrect" );
			setElementClass( c.b, "incorrect" );
			errors += ( "Your " + c.l + " and " + c.l + " confirmation don't match. " );
		}
	}
	if ( errors.length > 0 ) {
		errors += "Please correct this and try again.";
		alert( errors );
	}
	else
		return true;
			
	return false;
}

function numbersOnly(e) {
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8) { //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
			return false //disable key press
	}
	return true;
}

function tellAFriend() {
	var title = document.title;
	var path = window.location;
	var url = "/servlet/tellafriend?t=" + escape(title) + "&p=" + escape(path);
	var wind = window.open( url, "itltellafriend", "width=600,height=600" );
	if ( wind != null && !wind.closed )
		wind.focus();
}
function tellAFriendEvent() {
	var title = document.title;
	var path = window.location;
	var url = "/servlet/tellafriend?t=" + escape(title) + "&p=" + escape(path);
	var wind = window.open( url, "itltellafriend_event", "width=600,height=600" );
	if ( wind != null && !wind.closed )
		wind.focus();
}


function checkSearch() {
	var el = document.getElementById( "search_inp" );
	if ( el ) {
		if ( el.showingInstruction || el.value == "" ) {
			alert( "Please enter something to search for" );
			return false;
		}
	}
	return true;
}

function showMore( id ) {
	var el = document.getElementById( id );
	if ( el ) {
		el.className = "strans_less";
	}
}

function showLess( id ) {
	var el = document.getElementById( id );
	if ( el ) {
		el.className = "strans_more";
	}
}

function wireInputInstructions( id, instruction ) {
	var el = document.getElementById( id );
	if ( el ) {
		el.instructionText = instruction;
		if ( el.value == "" ) {
			el.value = instruction;
			el.style.color = "#999999";
			el.showingInstruction = true;
		}
		else {
			el.style.color = "#000000";
			el.showingInstruction = false;
		}
		el.onfocus = function() {
			if ( this.showingInstruction ) {
				this.value = "";
				this.showingInstruction = false;
				this.style.color = "#000000";
			}
		}
		el.onblur = function() {
			if ( this.value == "" ) {
				this.showingInstruction = true;
				this.style.color = "#999999";
				this.value = this.instructionText;
			}
		}
	}
	else {
		//alert(id + " not found");
	}
}

var onLoadFunctions = new Array();

function loaded() {
	wireInputInstructions( 'search_inp', "Search" );
	for ( var n = 0; n < onLoadFunctions.length; n++ )
		onLoadFunctions[ n ]();
}

window.onload = loaded;
