/////////////////TOOLS
var debugMode = false;
var autoScroll = true;
var supportEmail = 'view2gether@gmail.com';
var	newLine = "<br />";
var	newParagraph = newLine+newLine;
var maxSilentCapture = 30; //the maximum number of lines to capture while debug is disabled
var totalEvents = 0;

function toggleDebug (forceState) {

	if (debugMode == false || forceState == "on") {
		
		function toggleOn () {
			debugMode = true;
			setStyleSheet ("debug",true);
			document.getElementById('debugMenu').className='debugOn';
			document.getElementById('debugToggle').innerHTML = 'debug [on]';
			writeOutput ('debug', 'debug mode was enabled (total events: ' + totalEvents + ')', null, true)
		}
		
		if (forceState == "on") {
			toggleOn ();
		} else if (dialog(confirm,'Do you want to start debug mode?') == true) {
			toggleOn ();
		}
	
	}
	
	else if (debugMode == true || forceState == "off") {
		
		debugMode = false;
		showMenu('hide');
		setStyleSheet ("debug",false);		
		document.getElementById('debugMenu').className='debugOff';
		document.getElementById('debugToggle').innerHTML = 'debug [off]';

		if (forceState !== "off") {
			dialog(alert,'Debug mode has been disabled.');
		}

		trimDebug (true);

	}
	
}

function setStyleSheet(title, enable) {
   var i, stylesheet;
   for(i=0; (stylesheet = document.getElementsByTagName("link")[i]); i++) {
     if(stylesheet.getAttribute("rel").indexOf("style") != -1
        && stylesheet.getAttribute("title")) {
		stylesheet.disabled = true;
       if(stylesheet.getAttribute("title") == title && enable == true) stylesheet.disabled = false;
      else if(stylesheet.getAttribute("title") == title && enable == false) stylesheet.disabled = true;
     }
   }
}

function trimDebug (clearRange) {

		if (window.outputList == undefined || window.outputItems == undefined) {
			var outputList = document.getElementById('outputList');
			var outputItems = outputList.getElementsByTagName('li');	
		}
					
		if (clearRange == true) {
			
			beyondMax = outputItems.length - (maxSilentCapture);		
			
			for (var i = 0; i < beyondMax; i++) {
				outputList.removeChild(outputList.firstChild);
			}	
			
		} else if (outputItems.length > (maxSilentCapture -1)) {
			
			outputList.removeChild(outputList.firstChild);
			
		}
		
}

function toggleScroll (forceState) {
	
	if (forceState !== undefined) {
		autoScroll = forceState;
	} else {
		autoScroll =! autoScroll;
	}
	
	if (autoScroll == true) {
		document.getElementById('toggleScrollLink').innerHTML = "Pause Scrolling";
		document.getElementById('outputContainer').scrollTop = document.getElementById('outputContainer').scrollHeight;
	} else {
		document.getElementById('toggleScrollLink').innerHTML = "Resume Scrolling";
	}
	
}

function filterModeChange () {
	
	switch (document.getElementById('filterMode').value) {
		
		case "disabled":writeOutput ('debug', 'event filtering was [disabled]', null, true);
						document.getElementById('filterText').disabled = true;
						break;
		
		case "include": writeOutput ('debug', 'event filtering was set to [include mode]', null, true);
						document.getElementById('filterText').disabled = false;
						break;
						
		case "exclude": writeOutput ('debug', 'event filtering was set to [exclude mode]', null, true);
						document.getElementById('filterText').disabled = false;
						break;
						
					
	}
	
}

function writeOutput (source, message, subsource, highlight) {
	
	if (source == "clear") {
		document.getElementById('outputList').innerHTML = "";
		writeOutput ('debug', 'output was cleared by the user (total events: ' + totalEvents + ')', null, true)
		return;
	}

	if (document.getElementById('filterMode').value !== "disabled" && source !== "clear" && source !== "debug") {

		switch (document.getElementById('filterMode').value) {

			case "include":	if (source !== document.getElementById('filterText').value) {
								return;
							}
							break;
							
			case "exclude":	if (source == document.getElementById('filterText').value) {
								return;
							}
							break;
							
		}
		
	}

	totalEvents++;

	if (debugMode == false) {		
		trimDebug();
	}

	var buildLine;
	
	if (source !== null && source !== undefined) {
		buildLine = unescape(source);
	}
	else {
		buildLine = "Unknown";
	}
	
	if (subsource !== null && subsource !== undefined) {
		buildLine += " (" + unescape(subsource) + ")" + ":";
	}
	else {
		buildLine += ":";
	}
	
	if (message !== null && message !== undefined) {
		buildLine += " " + unescape(message);
	}
	else {
		buildLine += " " + "writeOutput was invoked but no message parameter was sent";
	}

	var newListItem =  document.createElement('li');
	
	function encodeEntities(code){
		return code.replace(/[<>&"]/g, function(m0){
			return {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;'}[m0] || m0;
		});
	}
	
	buildLine = encodeEntities(buildLine);

	if (highlight == true) {
		newListItem.className = 'highlight';
		newListItem.innerHTML = "<code>" + buildLine + "</code>";
	} else {
		newListItem.innerHTML = "<code>" + buildLine + "</code>";
	}
	
	document.getElementById('outputList').appendChild (newListItem);
			
	if (autoScroll == true) {
		document.getElementById('outputContainer').scrollTop = document.getElementById('outputContainer').scrollHeight;
	}

}

function getPlatform () {
	
	function checkIt(s) {
		place = detect.indexOf(s) + 1;
		thestring = s;
		return place;
		}
		function wrapIt(s) {
		re=/;/g
		return s.replace(re, "; ")
	}

	var detect = navigator.userAgent.toLowerCase();
	var i_win;
	var v_win;
	var OS;
	var agt=navigator.userAgent.toLowerCase();
	
	if (agt.indexOf("win")!=-1 || agt.indexOf("16bit")!=-1)
		i_win = true;
		
	if (i_win) {
		if (agt.indexOf("win95")!=-1 || agt.indexOf("windows 95")!=-1)
			v_win = "Windows 95";
		if (agt.indexOf("win98")!=-1 || agt.indexOf("windows 98")!=-1)
			v_win = "Windows 98";
		if (agt.indexOf("win 9x 4.90")!=-1)
			v_win = "Windows ME";
		if (agt.indexOf("winnt")!=-1 || agt.indexOf("windows nt")!=-1)
			v_win = "Windows NT";
		if (agt.indexOf("windows nt 5.0")!=-1)
			v_win = "Windows 2000";
		if (agt.indexOf("windows nt 5.1")!=-1)
			v_win = "Windows XP";
		if (agt.indexOf("windows nt 6.0")!=-1)
			v_win = "Windows Vista";
		if (!v_win)
			v_win = "Unknown Windows";
	}
	
	if (!OS) {
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = undefined;
	}
	
	var operatingSystem;

	if (i_win == true) {
		return(v_win);
	} else if (navigator.oscpu !== 'undefined' && navigator.oscpu != "") {
		return(navigator.oscpu);
	}
	else {
		return(OS);
	}
}


function getFlashInfo() {
	
	
	if(navigator.appName.indexOf("Microsoft") != -1 && typeof flashInfoSwf == 'undefined') {
		flashInfoSwf = window.flashInfo;
	} else if (typeof flashInfoSwf == 'undefined') {
		flashInfoSwf = window.document.flashInfo;
	}

	var flashInfoObject = flashInfoSwf.returnFlashInfo();
		
	thisFlashInfo = escape("- Flash Player Capabilities -") + newParagraph;
	
	for(var key in flashInfoObject) {
		
		if (key !== "serverString") {
			thisFlashInfo += key + ": " + flashInfoObject[key] + newLine;
		}
		
	}
	
	return (thisFlashInfo); 
	
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
	var string_length = 6;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return (randomstring);
}

function sendReport () {
	
	emailSubject = "Bug Report";
	
	/*
	getComments = dialog(prompt,'Please tell us about the problem you are reporting:','',true)
	
	if (getComments == '') {
		userComments = "- User Comments -" + newParagraph + "[Please tell us about the problem you are reporting.]" + newParagraph;
	} else if (getComments == null) {
		return;
	} else {
		userComments = "- User Comments -" + newParagraph + getComments + newParagraph;
	}
	*/
	userComments = "";
	
	reportId = randomString();
	
	sessionInfo = escape("- Session Information -") + newParagraph;
	sessionInfo += "userName: " + userName + newLine;
	sessionInfo += "userId: " + userId + newLine;
	sessionInfo += "loungeId: " + loungeId + newLine;
	sessionInfo += "reportId: " + reportId;
		
	clientInfo = escape("- Client Information -") + newParagraph;
	clientInfo += "appName: " + ((navigator.appName !== undefined) ? navigator.appName : "Unavailable") + newLine;
	clientInfo += "appCodeName: " + ((navigator.appCodeName !== undefined) ? navigator.appCodeName : "Unavailable") + newLine;
	clientInfo += "appVersion: " + ((navigator.appVersion !== undefined) ? navigator.appVersion : "Unavailable") + newLine;
	clientInfo += "appMinorVersion: " + ((navigator.appMinorVersion !== undefined) ? navigator.appMinorVersion : "Unavailable") + newLine;
	clientInfo += "userAgent: " + ((navigator.userAgent !== undefined) ? navigator.userAgent : "Unknown") + newLine;
	clientInfo += "platform: " + ((getPlatform() !== undefined) ? getPlatform() : "Unavailable") + newLine;
	clientInfo += "resolution: " + ((screen.width !== undefined) ? screen.width : "Unknown") + "x" + ((screen.height !== undefined) ? screen.height : "Unknown") + newLine;
	clientInfo += "resolution (available): " + ((screen.availWidth !== undefined) ? screen.availWidth : "Unknown") + "x" + ((screen.availHeight !== undefined) ? screen.availHeight : "Unknown") + newLine;
	clientInfo += "color depth: " + ((screen.colorDepth !== undefined) ? screen.colorDepth : "Unknown") + " bits";
	
	flashInfo = ""//getFlashInfo();

	//sendDebugInfo = dialog(confirm,'Include debug information with your report?',null,true);
	sendDebugInfo = true;
	
	if (sendDebugInfo == true) {
		
		var debugInfo = escape("- Debug Output (") + document.getElementById('outputList').childNodes.length + escape(" of ") + totalEvents + escape(" events captured) -") + newParagraph;
		
		numItems = document.getElementById('outputList').childNodes.length;
		for(var i = 0; i < numItems; i++) {
			debugInfo += i + 1 + escape(". ") + escape(document.getElementById('outputList').childNodes[i].getElementsByTagName('code')[0].innerHTML) + newLine;
		}
	
		debugReport = userComments + sessionInfo + newParagraph + clientInfo  + newParagraph + flashInfo + newLine + debugInfo;

	} else {
		
		debugReport = userComments + clientInfo  + newParagraph + flashInfo;
	
	}

	//emailString = "mailto:"+escape(supportEmail)+"?subject="+escape(emailSubject)+"&body="+debugReport;	

	//document.location = emailString;
	
	debugSubject = "Debug Report (id: " + reportId + ")";
	
  var objHTTP, strResult;
  
  if (returnAgent() == "ie" || returnAgent() == "ieclassic") {
    objHTTP = new ActiveXObject('Microsoft.XMLHTTP');
  }
  else {
	objHTTP = new XMLHttpRequest(); 
  }

  objHTTP.open('POST',"http://www.view2gether.com/scripts/sendreport.asp",false);
  objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  //objHTTP.send("id=1&user="+txtUser.value+"&password="+txtPassword.value);  
  objHTTP.send("_recipients=" + supportEmail + "&_subject=" + escape(debugSubject) + "&body=" + debugReport);
  
  strResult=objHTTP.responseText;
  
  alert ("Your report has been submitted.\nFor future reference your report ID is " + reportId + "\n\nPlease send an email to support@view2gether.com with details about the problem you are having and include the report ID (" + reportId + ") in your subject.");
  
}


function toggleCode () {
		
	if (getStyle('codeBox','display') == 'none') {
		
		//reset values
		document.getElementById('codeEmbed').value = embed_clickToPlay;
		document.getElementById('clickToPlay').checked = "checked";
		
		//the codeBox is disabled - enable it
		document.getElementById('linkButton').className = 'linkButton_isDown';
		Effect.BlindDown('codeBox', {queue: {position: 'end', scope: 'codeBox'}});

		document.getElementById('inviteButton').className = '';	
		document.getElementById('inviteBox').style.display='none';


	} else {
		//the codeBox is enabled - disable it
		document.getElementById('linkButton').className = '';
		Effect.BlindUp('codeBox', {queue: {position: 'end', scope: 'codeBox'}});
	}
		
}
//////////////////////////////////

function toggleInvite () {
		
	if (getStyle('inviteBox','display') == 'none') {
		
		//the inviteBox is disabled - enable it
		document.getElementById('inviteButton').className = 'inviteButton_isDown';
		Effect.BlindDown('inviteBox', {queue: {position: 'end', scope: 'inviteBox'}});

		document.getElementById('linkButton').className = '';
		document.getElementById('codeBox').style.display='none';


	} else {
		//the inviteBox is enabled - disable it
		document.getElementById('inviteButton').className = '';
		Effect.BlindUp('inviteBox', {queue: {position: 'end', scope: 'inviteBox'}});
	}
		
}

//////////////////////////////////
function setEmbed (clickToPlay) {
	if (clickToPlay == true) {
		document.getElementById('codeEmbed').value = embed_clickToPlay;
	}
	else if (clickToPlay == false) {
		document.getElementById('codeEmbed').value = embed_autoPlay;
	}
} 

function addBookmark (title,url) {
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
	
}

function copyContents(inElement,alertMessage) {	
    
	var flashcopier = 'flashcopier';
    
	if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
	
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="flash/flashClipboard.swf" FlashVars="clipboard='+encodeURIComponent(document.getElementById(inElement).value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
	
	alert (alertMessage);
	
}

//----------------------------
//----------------------------
// Navigation
//
//----------------------------
//----------------------------
autoHideTimeout = null;
autoHideDelay = 3;
returnMenu = null;

function getStyle(element,styleProp) {
	var elementId = document.getElementById(element);
	if (elementId.currentStyle)
		var styleValue = elementId.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var styleValue = document.defaultView.getComputedStyle(elementId,null).getPropertyValue(styleProp);
	return styleValue;
}

function showMenu (command, menuId) {
		
	function autoHide (delay) {
		clearTimeout (autoHideTimeout)			
		autoHideTimeout = setTimeout ('showMenu("hide")', delay*1000);
	}

	if (command == 'show' || getStyle('feature_submenu','display') == 'none' && command == 'toggle' || getStyle('feature_submenu','display') == 'block' && command == 'toggle' && getStyle(menuId,'display') !== 'block') {
		
		clearTimeout (autoHideTimeout)
		
			//numMenus2 = document.getElementById('feature_submenu').getElementsByTagName('li').length;
			//document.getElementById('menu').getElementsByTagName('a')[i].id

		numMenus = document.getElementById('feature_submenu').childNodes.length;
				
		for(var i = 0; i < numMenus; i++) {
			if (document.getElementById('feature_submenu').childNodes[i].nodeType == 1 && document.getElementById('feature_submenu').childNodes[i].id !== document.getElementById(menuId).id) {
				document.getElementById('feature_submenu').childNodes[i].style.display='none';
			}
		}

		document.getElementById(menuId).style.display='block';
		document.getElementById('feature_submenu').style.display='block';
				
	} else if (getStyle('feature_submenu','display') == 'block' && command == 'hide' || getStyle('feature_submenu','display') == 'block' && command == 'toggle') {
		
		if (returnMenu !== null) {
			showMenu('show',returnMenu);
		}
		else {
			document.getElementById('feature_submenu').style.display='none';
		}
	
		clearTimeout (autoHideTimeout)			
		
	} else if (command == 'autoHide') {
		autoHide (autoHideDelay);
	} else if (command == 'cancelHide') {
		clearTimeout (autoHideTimeout)			
	}
	
}

//----------------------------
//----------------------------
// Dialogs
//
//----------------------------
//----------------------------
//show and hide the shade - set shade height to page height (px)
function shade (state,startEvent,finishEvent) {
	
	switch (state) {
		case "show":
			Effect.Appear('shade',{from:0, to: 0.75, duration: 0.5, beforeStart: startEvent, afterFinish: finishEvent})
			break;
		case "hide": 
			Effect.Fade('shade',{from:0.75, to: 0, duration: 0.5, beforeStart: startEvent, afterFinish: finishEvent})
			break;
		default:
			break;
	}
	
}

//check browser version
function returnAgent () {


	if (navigator.userAgent.indexOf("Safari")!=-1) {
		return ("safari");
	}

	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		return ("ff");
	}
	
	if (navigator.userAgent.indexOf("MSIE")!=-1) {
		
		if (parseInt(navigator.appVersion.split('MSIE')[1]) <= 6) {
			return ("ieclassic");
		}
		else {
			return ("ie");
		}
	}
	
	else {
		return ("unknown");
	}
	
}

//return dimensions of current viewport
function getViewport (dimension) {
	if (self.innerHeight) // all except Explorer
	{
		viewportWidth = self.innerWidth;
		viewportHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		viewportWidth = document.documentElement.clientWidth;
		viewportHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		viewportWidth = document.body.clientWidth;
		viewportHeight = document.body.clientHeight;
	}
	
	if (dimension == 'width') {
		return (viewportWidth);
	} else if (dimension == 'height') {
		return (viewportHeight);
	}
	
}

//modal dialog with shade
function dialog (type, message, defaultText, noShade) {
	
	//adjust strings received from ExternalInterface
	if (typeof(type) == "string") {
		switch (type) {
			case "alert":
				type = alert;
				break;
			case "confirm":
				type = confirm;
				break;
			case "prompt":
				type = prompt;
				break;
		}
	}
	
	if (typeof(noShade) == "string") {
		switch (noShade) {
			case "true":
				noShade = true;
				break;
			case "false":
				noShade = false;
				break;
		}
	}
	
	
	if (noShade == true) {
		if (defaultText !== null || defaultText !== undefined) {
			result = type(message,defaultText);
		} else {
			result = type(message);
		}
	} else if (returnAgent() == "ff") {	
		shade("show");
		if (defaultText !== null || defaultText !== undefined) {
			result = type(message,defaultText);
		} else {
			result = type(message);
		}
		shade("hide");
	}
	else if (returnAgent() == "ie" || returnAgent() == "ieclassic") {
		document.getElementById("shade").style.display='block';
		document.getElementById("shade").style.height = getViewport('height') + "px";	
		document.getElementById("shade").style.width = getViewport('width') + "px";	
		document.getElementById("shade").style.filter = "alpha(opacity='75')";
		if (defaultText !== null || defaultText !== undefined) {
			result = type(message,defaultText);
		} else {
			result = type(message);
		}
		shade("hide");
	} else {
		//safari and all others - use opacity property but set shade "show" immediately
		document.getElementById("shade").style.display='block';
		document.getElementById("shade").style.height = getViewport('height') + "px";	
		document.getElementById("shade").style.width = getViewport('width') + "px";	
		document.getElementById("shade").style.opacity = 0.75;
		if (defaultText !== null || defaultText !== undefined) {
			result = type(message,defaultText);
		} else {
			result = type(message);
		}
		shade("hide");
	}
	
	return (result);

}



function announce (message) {

	if (message == false && getStyle('announcement','display') == 'block') {
		
		Effect.BlindUp('announcement');
		
	} else if (message !== false) {
		document.getElementById("announcementMessage").innerHTML = message;
	
		if (getStyle('announcement','display') == 'none') {
			Effect.BlindDown('announcement');
		}
		
	}
	
}
/////////////////FORMS
var formId = 'aspnetForm';
var confirmShown = false;

function clearDefaultText (fieldId, defaultText) {
	if (document.getElementById(fieldId).value == defaultText) {
		document.getElementById(fieldId).value = "";
	}
}

function showConfirm () {
	if (confirmShown == false) {
		confirmShown = true;
		Effect.BlindDown('signUp_passwordConfirm');
	}
}

function showPassphrase (show) {
	if (show == true && getStyle('newLounge_passphrase','display') == 'none') {
		Effect.BlindDown('newLounge_passphrase');
	} else if (show == false && getStyle('newLounge_passphrase','display') == 'block') {
		Effect.BlindUp('newLounge_passphrase');
	}
}

function checkEmail(formId,fieldId) {
	
	var regularExpression = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var emailAddress = document.forms[formId].elements[fieldId].value;
	
	if(regularExpression.test(emailAddress) == true) {
		return true;
	} else {
		return false;
	}
	
}

function checkPassword (formId, fieldId) {
	var password = document.forms[formId].elements[fieldId].value;
	
	return validatePassword (password, {
										length:   [4, Infinity],
										badWords: ["password"],
										badSequenceLength: 6
										});
		
}

function highlightField(fieldId,clear) {
		
	borderDefault = "#d7e2ec";
	borderHighlight = "#fffda9";

	if (clear == true) {
		document.forms[formId].elements[fieldId].style.borderColor = borderDefault;
	} else {
		document.forms[formId].elements[fieldId].style.borderColor = borderHighlight;
	}
	
}

function checkSignup () {
	
	var formValid = true;
			
	//check if any required fields are empty
	if (document.forms[formId].elements['signUp_email'].value == "") {
		//highlight email
		formValid = false;
		dialog (alert,'Please fill in the email box.')
		highlightField ('signUp_email');
		return false;
	} else {
		highlightField ('signUp_email',true);
	}
	
	if (checkEmail(formId,'signUp_email') == false) {
		//highlight email field
		formValid = false;
		dialog (alert,'The email you provided is not valid.')
		highlightField ('signUp_email');
		return false;
	} else {
		highlightField ('signUp_email',true);
	}
	
	if (document.forms[formId].elements['signUp_passwordA'].value == "") {
		//highlight passwordA
		formValid = false;
		dialog (alert,'Please fill in the password box.')
		highlightField ('signUp_passwordA');
		return false;
	} else {
		highlightField ('signUp_passwordA',true);
	}
	
	if (document.forms[formId].elements['signUp_passwordB'].value == "") {
		//highlight passwordB
		formValid = false;
		dialog (alert,'Please fill in the second password box.')
		showConfirm();		
		highlightField ('signUp_passwordB');
		return false;
	} else {
		highlightField ('signUp_passwordB',true);
	}
	
	if (document.forms[formId].elements['signUp_passwordA'].value !== document.forms[formId].elements['signUp_passwordB'].value) {
		//highlight both passwords fields!
		formValid = false;
		dialog (alert,'Sorry. The passwords you typed do not match.\nPlease correct and try again.')
		highlightField ('signUp_passwordA');
		highlightField ('signUp_passwordB');
		return false;
	} else {
		highlightField ('signUp_passwordA',true);
		highlightField ('signUp_passwordB',true);
	}
	
	if (checkPassword(formId,'signUp_passwordA') == false || checkPassword(formId,'signUp_passwordB') == false || document.forms[formId].elements['signUp_passwordA'].value == document.forms[formId].elements['signUp_email'].value) {
		//highlight email field
		formValid = false;
		dialog (alert,'Sorry. The password you picked is not allowed.\nPlease select a different password and try again.')
		highlightField ('signUp_passwordA');
		highlightField ('signUp_passwordB');
		return false;		
	} else {
		highlightField ('signUp_passwordA',true);
		highlightField ('signUp_passwordB',true);
	}
	
	if (formValid == true) {
		//document.forms[formId].submit();
		return true;
	}
			
}

function toggleSignIn (showForm) {
	
	switch (showForm) {
		case 'member':  //document.getElementById("logInMember").style.display = 'block';
						//document.getElementById("logInGuest").style.display = 'none';
						document.getElementById("logInMember").className = 'displayBlock';
						document.getElementById("logInGuest").className = 'displayNone';
						document.forms.item(0).hdToggle.value = 'Member';
						//alert(document.forms.item(0).hdToggle.value );
						break;
		case 'guest':  	//document.getElementById("logInMember").style.display = 'none';
						//document.getElementById("logInGuest").style.display = 'block';
						document.getElementById("logInMember").className = 'displayNone';
						document.getElementById("logInGuest").className = 'displayBlock';
						document.forms.item(0).hdToggle.value = 'Guest';
						//alert(document.forms.item(0).hdToggle.value );
						break;
	}
	
	//getStyle('logInGuest','display');
	//alert ('x');
	//document.getElementById("xxx").style.backgroundImage = 'url(images/page/button_backgroundRight_default.png)';
	
	
}

function validatePassword (password, options) {
	// default options (allows any password)
	var o = {
		lower:    0,
		upper:    0,
		alpha:    0, /* lower + upper */
		numeric:  0,
		special:  0,
		length:   [0, Infinity],
		custom:   [ /* regexes and/or functions */ ],
		badWords: [],
		badSequenceLength: 0,
		noQwertySequences: false,
		noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (password.length < o.length[0] || password.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((password.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce word ban (case insensitive)
	for (i = 0; i < o.badWords.length; i++) {
		if (password.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
			return false;
	}

	// enforce the no sequential, identical characters rule
	if (o.noSequential && /([\S\s])\1/.test(password))
		return false;

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + password.slice(0, start);
		for (i = start; i < password.length; i++) {
			seq = seq.slice(1) + password.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}

	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(password))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(password))
				return false;
		}
	}

	// great success!
	return true;
}
