//
var isReadTC = false;
var is18YOld = false;
var isOpen = false;
var whichIsOpen = 'none';
var isRememberMe = false;
var isUnderAge = false;
var wDeactivate = 1;
var wlcmAcion = null;
var wlcmUserName = null;

var flgPrivacy = null;
var flgShout = null;
var flgNotify = null;
var flgEvents = null;

//
function addOnloadEvent(fnc)
{
	if (typeof window.addEventListener != "undefined"){
		window.addEventListener("load", fnc, false);
	} else if (typeof window.attachEvent != "undefined") {
		window.attachEvent( "onload", fnc );
	} else {
		if (window.onload != null) {
			var oldOnload = window.onload;
			window.onload = function (e) {
				oldOnload( e );
				window[fnc]();
			};
		} else {window.onload = fnc;}
	}
}

function testPassword(passwd){
	var intScore   = 0;
	var strVerdict = "weak";
	var strLog     = "";
	
	// PASSWORD LENGTH
	if (passwd.length<1){
		intScore = intScore;
	}else if (passwd.length<5){
		intScore = (intScore+3);
	}else if (passwd.length>4 && passwd.length<8){
		intScore = (intScore+6);
	}else if (passwd.length>7 && passwd.length<16){
		intScore = (intScore+12);
	}else if (passwd.length>15){
		intScore = (intScore+18);
	}
	
	// - Must be at least 10 characters (EVAL...)
	// - Must contain at least one one lower case letter, one upper case letter, one digit and one special character
	// - Valid special characters are - @#$%^&+=
	// ^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
	
	// [verified] at least one lower case letter
	if (passwd.match(/[a-z]/)){
		intScore = (intScore+1);
	}
	
	// [verified] at least one upper case letter
	if (passwd.match(/[A-Z]/)){
		intScore = (intScore+5);
	}
	
	// NUMBERS
	// [verified] at least one number
	if (passwd.match(/\d/)){
		intScore = (intScore+5);
	}
				
	// SPECIAL CHAR
	// [verified] at least one special character
	if (passwd.match(/[@#$%^&+=]/)){
		intScore = (intScore+10);
	}
	
	// COMBOS
	// [verified] at least two special together
	if (passwd.match(/([@#$%^&+=]{2,})/)){
		intScore = (intScore+4);
	}
	
	// [verified] at least two numbers together
	if (passwd.match(/\d{2}/)){
		intScore = (intScore+5);
	}
	
	// [verified] alphanumeric character
	if (passwd.match(/(\d)|([a-z])|([A-Z])/)){
		intScore = (intScore+4);
	}
		
	// [verified] letters, numbers, and special characters
	if (passwd.match(/(\d)|([a-z])|([A-Z])|([@#$%^&+=])/)){
		intScore = (intScore+4);
	}
	
	if(intScore < 1){
	   $('shwPasswStrength').className = 'empty';
	}else if(intScore < 14){
	   $('shwPasswStrength').className = 'weak';
	}else if (intScore > 15 && intScore < 25){
	   $('shwPasswStrength').className = 'weak';
	}else if (intScore > 24 && intScore < 35){
	   $('shwPasswStrength').className = 'fair';
	}else if (intScore > 34 && intScore < 45){
	   $('shwPasswStrength').className = 'good';
	}else if (intScore > 46){
	   $('shwPasswStrength').className = 'strong';
	}
}

var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]\{\}^& ]/;
var emailFilter = /^.+@.+\..{2,3}$/;

function validateUserName(uname)
{
	if (uname.length < 3) {
		$('errName').update('<p>please enter your username</p>');
		$('errName').show();
		return false;
 	}else if (illegalChars.test(uname)) {
		$('errName').update('<p>please remove illegal characters</p>');
		$('errName').show();
		return false;
 	}else{
 		$('errName').hide();
 	}
 	
 	return true;
}

function validateEmail(email)
{
	if (email.length < 1) {
		$('errEmail').update('<p>please enter your email</p>');
		$('errEmail').show();
		return false;
 	}else if (!emailFilter.test(email)) {
		$('errEmail').update('<p>please enter a valid email</p>');
		$('errEmail').show();
		return false;
 	}else if(illegalChars.test(email)){
		$('errEmail').update('<p>please remove illegal characters</p>');
		$('errEmail').show();
		return false;
 	}else{
 		$('errEmail').hide();
 	}
	
	return true;
}

function validatePassword(pass,pass2)
{
	if (pass.length < 3) {
		$('errPassw').update('<p>please enter your password</p>');
		$('errPassw').show();
		return false;
 	}else if(illegalChars.test(pass)){
		$('errPassw').update('<p>please remove illegal characters</p>');
		$('errPassw').show(); 
		return false;
 	}else{
 		$('errPassw').hide();
 	}
 	
 	if (pass2.length < 3) {		
		$('errRPassw').update('<p>please retype your password</p>');
		$('errRPassw').show();
		return false;
 	}else if(illegalChars.test(pass2)){
 		$('errRPassw').update('<p>please remove illegal characters</p>');
		$('errRPassw').show(); 
		return false;
 	}else{
 		$('errRPassw').hide();
 	}
		
	if(pass != pass2){
		$('errRPassw').update('<p>passwords need to match</p>');
		$('errRPassw').show();
		$('errRPasswIcon').show();
		return false;
	}else{
		$('errRPassw').hide();
		$('errRPasswIcon').hide();
	}
	
	return true;
}

function validateVIN(vin)
{
	if (vin.length < 1) {
		$('errVIN').update('<p>please enter your VIN number</p>');
		$('errVIN').show();
		return false;
 	}else{
 		$('errVIN').hide();
 	}
 	
 	return true;
}

function validateBirthdate(day, month, year)
{
	//
}

function validateZipCode(zip)
{
	if (zip.length < 5) {
		$('errZip').update('<p>please enter your zip code</p>');
		$('errZip').show();
		return false;
 	}else{
 		$('errZip').hide();
 	}
 	
 	return true;
}

function validate18Y()
{
	if(!is18YOld){
		$('err18Older').show();
		return false;
	}
	
	$('err18Older').hide();
	return true;
}

function validateTC()
{
	if(!isReadTC){
		$('errTC').show();
		return false;
	}
	
	$('errTC').hide();
	return true;
}

function agreeTC()
{
	isReadTC = true;
	TermsCond.hide();	
}

accountManager = function() 
{
			
	function commonField(id,name,error,disabled,index,max,events)
	{
		//log('commonField:'+name);
		var options = '';
		if(disabled==true)options+='class="disabled" disabled="disabled" ';
		if(name=='password')options+='type="password" onkeyup="testPassword(this.value);" ';
		if(name=='password2')options+='type="password" ';
		if(max!='null')options+=' maxlength="'+max+'"';
		if(events!='')options+=' '+events;
		
		var fld='';
		fld+='<div class="frm-field">';
		fld+='<label for="fld'+id+'" id="lb'+id+'"></label><input id="fld'+id+'" tabindex="'+index+'" name="'+name+'" '+options+'>';
		//fld+='<!--[if IE 6]><iframe></iframe><![endif]-->'
		fld+='<div id="err'+id+'" class="frm-error" style="display:none;"><p>'+error+'</p></div>';
		fld+='<div id="err'+id+'Icon" class="frm-error-icon" style="display:none;"></div>';
		fld+='</div>';
		
		return fld;
	}
	
	function createFrmContainer(cdHtml,id,isShow)
	{
		isOpen = true;
		whichIsOpen = id;
		var display = '';
		var id = id;
		var isShow = isShow;
		if(!isShow) display = 'display:none';
		
		var html='';
		html+='<div id="'+id+'" class="float-box-container" style="'+display+'">';
		html+='<div id="formLayout">';
		html+='<div id="colA" class="floatl"></div>';
		html+='<div id="colB" class="floatl rounded">';
		html+='<div class="frm-container">';
		html+='<form id="Frm'+id+'" method="POST" onsubmit="return false;">';
		html+=cdHtml;
		html+='</form>';
		html+='</div>';
		html+='</div>';
		html+='<div id="colC" class="floatl"></div>';
		//html+='<div class="floatl" style="width:30px; height:10px;"><img src="/img/reg-form-rgtshdw.png" alt="" /></div>';
		//html+='<br clear="left">';		
		html+='</div>';
		html+='</div>';
		
		//return ;
		//$('formContainer').show();
		$('formContainer').update(html);
		
		//if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '6') alert(BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS);
		
		//log('createFrmContainer -> ready');
		
		//if(!isShow) 
		Effect.SlideDown(id,{
			afterFinish:function(){
			//beforeStart:function(){
			
				log('cookie:'+readCookie('loginScion'));
				log('isOpen:'+isOpen);
				log('whichIsOpen:'+whichIsOpen);
				//log('user.data:'+user.data);				
								
				if(whichIsOpen == 'REG'){
					//				
				}
				
				if(readCookie('loginScion') && readCookie('loginScionPssw') && isOpen && whichIsOpen == 'LG'){
					var form = $('FrmLG');
					var email = form['username'];
					var passw = form['password'];
					$(email).value = readCookie('loginScion');
					$(passw).value = readCookie('loginScionPssw');
					$('chRemember').checked = true;
					
					isRememberMe = true;
				}
				
				if(isOpen && whichIsOpen == 'WUSER' && user.data!=null){
					log('oSessionData:'+Object.toJSON(oSessionData));
					log('oGarageData:'+Object.toJSON(oGarageData));
					log('user.data:'+Object.toJSON(user.data));
				
					wlcmUserName = user.data.username;
					var nnei = parseInt(user.data.nei);
							
					if(user.data.flagprivacy=='Y') {
						$('rbPrivacyF').checked = true;
						flgPrivacy = 'Y';
					}else{
						$('rbPrivacyE').checked = true;
						flgPrivacy = 'N';
					}
					
					if(user.data.flagshout=='Y'){
						$('chEmailNotiShouts').checked = true;
						flgShout = 'Y';
					}else{
						$('chEmailNotiShouts').checked = false;
						flgShout = 'N';
					}
					
					if(user.data.flagnotify==true || user.data.flagnotify=='Y'){
						$('chEmailNotiFriendReq').checked = true;
						flgNotify = 'Y';
					}else{
						$('chEmailNotiFriendReq').checked = false;
						flgNotify = 'N';
					}
					
					if(user.data.flagevents=='Y'){
						$('chEmailNotiEvntsInvt').checked = true;
						flgEvents = 'Y';						
					}else{
						$('chEmailNotiEvntsInvt').checked = false;
						flgEvents = 'N';						
					}
					
					$('slcNeighborhood').selectedIndex = (nnei-1);
					
					log('WU > flgPrivacy:'+flgPrivacy);
					log('WU > flgShout:'+flgShout);
					log('WU > flgNotify:'+flgNotify);
					log('WU > flgEvents:'+flgEvents);

					
					$('hdWELCOME').update('WELCOME '+wlcmUserName+'!<p>Get started quickly by creating your garage (your personal profile)<br>and selecting a few privacy settings.</p>');
				}
				
				if(isOpen && whichIsOpen == 'AS' && user.data!=null){
					log('oSessionData:'+Object.toJSON(oSessionData));
					log('oGarageData:'+Object.toJSON(oGarageData));
					log('user.data:'+Object.toJSON(user.data));
					var form = $('FrmAS');
					var uname = form['name'];
					var unameh = form['nameh'];
					var email = form['email'];
					var zip = form['zip'];
					var fname = form['firstname'];
					var lname = form['lastname'];
					var vin = form['vin'];
					var nnei = parseInt(user.data.nei);
					
					log('nnei:'+nnei);
					
					$(uname).value = user.data.username;
					$(unameh).value = user.data.username;
					$(email).value = user.data.email;
					$(zip).value = user.data.zipcode;
					$(fname).value = user.data.firstname;
					$(lname).value = user.data.lastname;
					$(vin).value = user.data.vin;
					$('slcNeighborhood').selectedIndex = (nnei-1);	
					
					/*set new vars */
					if(user.data.flagprivacy=='Y') flgPrivacy = 'Y';
					else flgPrivacy = 'N';
						
					if(user.data.flagshout=='Y')flgShout = 'Y';
					else flgShout = 'N';
					
					if(user.data.flagnotify==true || user.data.flagnotify=='Y') flgNotify = 'Y';
					else flgNotify = 'N';
					
					if(user.data.flagevents=='Y') flgEvents = 'Y';						
					else flgEvents = 'N';
					
					log('flgPrivacy:'+flgPrivacy);
					log('flgShout:'+flgShout);
					log('flgNotify:'+flgNotify);
					log('flgEvents:'+flgEvents);
					
					
					if(user.data.flagprivacy=='Y') {
						$('rbPrivacyF').checked = true;
						flgPrivacy = 'Y';
					}else{
						$('rbPrivacyE').checked = true;
						flgPrivacy = 'N';
					}
					
					if(user.data.flagshout=='Y'){
						$('chEmailNotiShouts').checked = true;
						flgShout = 'Y';
					}else{
						$('chEmailNotiShouts').checked = false;
						flgShout = 'N';
					}
					
					if(user.data.flagnotify==true || user.data.flagnotify=='Y'){
						$('chEmailNotiFriendReq').checked = true;
						flgNotify = 'Y';
					}else{
						$('chEmailNotiFriendReq').checked = false;
						flgNotify = 'N';
					}
					
					if(user.data.flagevents=='Y'){
						$('chEmailNotiEvntsInvt').checked = true;
						flgEvents = 'Y';						
					}else{
						$('chEmailNotiEvntsInvt').checked = false;
						flgEvents = 'N';						
					}
					
					//fake passw
					var passw = form['password'];
					var passw2 = form['password2'];
					$(passw).value = '---------------';
					$(passw2).value = '---------------';
					
				}
				
				Custom.init();
			}
		})
		//}else{$(id).show();};				
	}
	
	function createContainer(cdHtml,id,isShow)
	{
		isOpen = true;
		whichIsOpen = id;
		var display = '';
		var id = id;
		var isShow = isShow;
		if(!isShow) display = 'display:none';
		
		var html='';
		html+='<div id="'+id+'" class="float-box-container" style="'+display+'">';
		html+='<div id="formLayout">';
		html+='<div id="colA" class="floatl"></div>';
		html+='<div id="colB" class="floatl rounded">';
		html+='<div class="frm-container">';
		html+=cdHtml;
		html+='</div>';
		html+='</div>';
		html+='<div id="colC" class="floatl"></div>';
		html+='<br clear="left">';
		html+='</div>';
		html+='</div>';
		
		//return ;
		//$('formContainer').show();
		$('formContainer').update(html);				
		
		if(!isShow) Effect.SlideDown(id); //
	}
	
	function bldLogin(show)
	{
		var isShow = show;
		var html = '';
		
		html+='<div id="optLogin" class="floatl">';
		html+='<h1 id="hdLOGIN"></h1>';
		html+=commonField('Name','username','please enter a username',false,'1','15','');
		html+=commonField('Passw','password','please enter a password',false,'2','20','');
		html+='<div class="frm-subopt prelative noborder" style="margin:0; padding:0;">';
		html+='<label for="chRemember">Remember me</label>';
		html+='<input type="checkbox" class="styled" id="chRemember">';
		html+='<div id="btLogIn"><a href="/" onClick="accountManager.onLogin(); return false;"></a></div>';
		html+='<p><a href="/" onClick="accountManager.goForgot(); return false;">forgot your password?</a></p>';
		html+='<div id="shwPasswStrength" style="display:none;"></div>'
		html+='</div>';
		//html+='<br clear="left">';
		html+='</div>';

		
		html+='<div id="optForgot" class="floatl" style="display:none;">';
		html+='<h1 id="hdFORGOT"></h1>';
		html+='<div class="forgot-mssg">Enter your email below and we\'ll send you your password or <a href="/" onClick="accountManager.backLogin(); return false;">try again</a></div>';
		html+=commonField('Email','email','please enter a email',false,'0','50','');
		html+='<div class="frm-subopt prelative noborder" style="margin:0; padding:0;">';
		html+='<div id="btForgot"><a href="/" onClick="accountManager.onForgot(); return false;"></a></div>';
		html+='</div>';
		//html+='<br clear="left">';
		html+='</div>';
		
		
		html+='<div id="optRegister" class="floatl">';
		html+='<h1 id="hdREG"></h1>';
		html+='<p id="hdREGRsm"></p>';
		html+='<div id="btRegister"><a href="/" onClick="accountManager.goRegister(\'LG\'); return false;"></a></div>';
		//html+='<br clear="left">';
		html+='</div>';
		
		html+='<br clear="left">';
		html+='<div class="align-cntr" style="margin:15px 0 0 -5px;"><a href="/" onClick="accountManager.onCancel(\'LG\'); return false;">close</a></div>';
		
		createFrmContainer(html,'LG',isShow);
		
		$('chRemember').onclick = function(e){
			if(isRememberMe)isRememberMe = false;
			else isRememberMe = true;
			
			log('isRememberMe:'+isRememberMe);
		}
		
		//releases memory
		//delete bldLogin;
	}
	
	function bldWelcome(show)
	{
		var isShow = show;
		var html='';
		//options
		html+='<div class="frm-mainopt prelative" style="width:250px;">'; // style="margin:0 auto; border:none; width:260px;"
		html+='<div id="btRegister" class="floatl" style="margin:0 20px 0 0;"><a href="/" onClick="accountManager.goRegister(\'WLCM\'); return false;"></a></div>';
		html+='<div id="btLogIn" class="floatl"><a href="/" onClick="accountManager.goLogin(\'WLCM\'); return false;"></a></div>';
		html+='<br clear="left">';
		html+='<div id="msgWelcomeToScion"></div>';
		html+='<div class="align-cntr"><a href="/" onClick="accountManager.closeMe(\'WLCM\'); return false;">close</a></div>';
		html+='</div>';	
		
		createFrmContainer(html,'WLCM',isShow);
		
		//releases memory
		delete bldWelcome;
	}
	
	function bldRegistration(show)
	{
		var isShow = show;
		var html='';
		html+='<div id="hdREGISTRATION"></div>';
		html+='<p class="frm-subinfo pnormal">Mingle, connect and learn about the latest mods. Scion City keeps you plugged into the Scion community and insider news.</p>';
		html+='<p class="frm-subinfo plow spvert20px">All Fields are required</p>';
		
		//name
		html+=commonField('Name','name','error name',false,'1','15','');
	
		//email
		html+=commonField('Email','email','error email',false,'2','50','');
		
		//password
		html+=commonField('Passw','password','error passwd',false,'3','20','');
		
		//password strength 
		html+='<div class="frm-field">';
		html+='<div id="shwPasswStrength" class="empty"></div>';
		html+='</div>';
		
		//re-password 
		html+=commonField('RPassw','password2','error passwd',false,'4','20','');
				
		//VIN 
		html+='<div class="frm-field">';		
		html+='<label for="fldVIN" id="lbVIN"></label><input id="fldVIN" tabindex="5" name="vin" value="">';
		html+='<p class="frm-tip" style="font-style:normal;">Enter your VIN to become a certified owner and get access to special owners-only content. Your VIN is a long string of numbers and letters that you can find on the front driver&#8217;s side interior dash, viewable through your windshield.</p>';
		html+='<div class="frm-error" style="display:none;" id="errVIN"><p>error VIN Number</p></div>';
		html+='<div id="errVINIcon" class="frm-error-icon" style="display:none;"></div>';
		html+='</div>';		
		
		//age
		html+='<div class="frm-field">';
		html+='<label for="slcMonth" id="lbAge"></label>';
		html+='<select id="slcMonth" name="month" tabindex="6" class="floatl" style="width:50px; margin:0 10px 0 0px;">';
		for(var i=1;i<13;i++){
			if(i<10) mnt = '0'+i;
			else mnt = i;
			html+='<option value="'+mnt+'">'+mnt+'</option>';
		}
		html+='</select>';
		
		html+='<select id="slcDay" name="day" tabindex="7" class="floatl" style="width:50px; margin:0 10px 0 0;">';
		for(var i=1;i<32;i++){
			if(i<10) day = '0'+i;
			else day = i;
			html+='<option value="'+day+'">'+day+'</option>';
		}
		html+='</select>';	
		
		html+='<select id="slcYear" name="year" tabindex="8" class="floatl" style="width:75px; margin:0;">';
		var exd = new Date();
		var nLastYear = exd.getFullYear();//-18;
		for (var i=nLastYear;i>1900;i--){
			html+='<option value="'+i+'">'+i+'</option>';
		}
		html+='</select>';
		html+='<br clear="left">';
		//<input id="fldAge" tabindex="6" name="age" value="" maxlength="2" style="width:20px!important;">';
		//html+='<div class="pabsolute" style="color:#FFF; left:155px; top:5px;">Years Old.</div>';
		//html+='<div class="frm-error" style="display:none;" id="errAge"><p>empty</p></div>';
		html+='</div>';
		html+='<!--[if gte IE 6]><br clear="left"><![endif]-->';
		
		//zip
		html+=commonField('Zip','zip','error zip',false,'9','5','');
		
		//T&C
		html+='<div class="frm-subopt prelative noborder" style="margin:25px 0 25px 82px;">';
		html+='<label for="chYearsOld">I certified that I am at least 18 years old and<br/><span>I agree to the<a href="/" onClick="TermsCond.build(); return false;">TERMS AND CONDITIONS</a></span></label>';
		html+='<input type="checkbox" class="styled" id="chYearsOld">';
		html+='<div id="err18Older" class="frm-error" style="display:none;"><p>Please certify that you are at<br>least 18 years old and agree to the<br>Terms and Conditions<br></p></div>'; //
		html+='<div id="errTC" class="frm-error" style="display:none;"><p>Please read the Terms and Conditions</p></div>'; //
		//html+='<div id="okTCIcon" class="frm-okb-icon" style="display:none;"></div>';
		html+='<br clear="left">';

		html+='</div>';
		
		//options
		html+='<div class="frm-end prelative noborder" style="padding-top:15px; margin-left:110px;">';
		html+='<div id="btRegister" class="floatl" style="margin:0 45px 0 23px;"><a href="/" onClick="accountManager.onRegister(); return false;"></a></div>';
		html+='<div id="btCancel" class="floatl"><a href="/" onClick="accountManager.onCancel(\'REG\'); return false;"></a></div>';
		html+='<br clear="left">';
		html+='</div>';
		
		createFrmContainer(html,'REG',isShow);
		
		$('chYearsOld').onclick = function(e){
			if(is18YOld)is18YOld = false;
			else is18YOld = true;
			
			log('is18YOld:'+is18YOld);
		}
	}
	
	function bldWelcomeUsr(show)
	{
		var isShow = show;
		var html='';
		//estructure for each field in the form
		html+='<div id="hdWELCOME">';
		html+='WELCOME!<p>Get started quickly by creating your garage (your personal profile)<br>and selecting a few privacy settings.</p>';
		html+='</div>';
				
		//neighborhood
		html+='<div class="frm-field" style="">';
		html+='<label for="slcNeighborhood" id="lbNeighborhood"></label>';
		html+='<select id="slcNeighborhood" name="nei" tabindex="1">';
		html+='<option value="1">El Centro</option>';
		html+='<option value="2">The Wharf</option>';
		html+='<option value="3">Gravity Hill</option>';
		html+='<option value="4">Vista Valley</option>';
		html+='<option value="5">Box District</option>';		
		html+='</select>';
		html+='<div class="frm-tip">Where do you hail from? Pick your kind of neighborhood to customize your garage or go explore other garages.</div>'
		html+='<div class="frm-error" style="display:none;"><p>error A</p></div>';
		html+='</div>';
		
		//Privacy 
		html+='<div class="frm-subopt prelative noborder">';
		html+='<p id="hdPrivacy"></p>';
		html+='<label for="rbPrivacyE">Everyone</label><input type="radio" class="styled" id="rbPrivacyE" tabindex="2" name="privacy" checked="checked">'; //
		html+='<label for="slcNeighborhood">Friends</label><input type="radio" class="styled" id="rbPrivacyF" tabindex="3" name="privacy">'; //
		html+='</div>';
		
		//Notifications
		html+='<div class="frm-subopt prelative noborder">';
		html+='<p id="hdNotifications"></p>';
		html+='<label for="chEmailNotiShouts">Shouts</label><input type="checkbox" class="styled" id="chEmailNotiShouts" tabindex="4" checked="checked">';
		html+='<label for="chEmailNotiFriendReq">Friend requests and personal messages</label><input type="checkbox" class="styled" id="chEmailNotiFriendReq" tabindex="5" checked="checked">';
		html+='<label for="chEmailNotiEvntsInvt">Scion event invitations and news</label><input type="checkbox" class="styled" id="chEmailNotiEvntsInvt" tabindex="6" checked="checked">';
		html+='</div>';
		
		//options
		html+='<div class="frm-end prelative" style="padding-top:15px;">';
		html+='<div id="btSaveAndGoProfile" class="floatl" style="margin:0 40px 0 0;"><a href="/" onClick="accountManager.saveAndGo(\'profile\'); return false;"></a></div>';
		html+='<div id="btSaveAndGoHome" class="floatl"><a href="/" onClick="accountManager.saveAndGo(\'home\'); return false;"></a></div>';
		html+='<br clear="left">';
		html+='</div>';
		//end
		
		createFrmContainer(html,'WUSER',isShow);
		
		$('rbPrivacyE').onclick = function(e){
			flgPrivacy = 'N';
			log('flgPrivacy:'+flgPrivacy);
		}
		
		$('rbPrivacyF').onclick = function(e){
			flgPrivacy = 'Y';
			log('flgPrivacy:'+flgPrivacy);
		}
		
		$('chEmailNotiShouts').onclick = function(e){
			if(flgShout=='Y') flgShout = 'N';
			else flgShout = 'Y';
			log('flgShout:'+flgShout);
		}
		
		$('chEmailNotiFriendReq').onclick = function(e){
			if(flgNotify=='Y') flgNotify = 'N';
			else flgNotify = 'Y';
			log('flgNotify:'+flgNotify);
		}
		
		$('chEmailNotiEvntsInvt').onclick = function(e){
			if(flgEvents=='Y') flgEvents = 'N';
			else flgEvents = 'Y';
			log('flgEvents:'+flgEvents);
		}
	}
	
	function bldAccountSettings(show)
	{
		var isShow = show;
		var html='';
		//estructure for each field in the form
		html+='<div id="hdACCOUNTSETTINGS"></div>';
		
		//name
		html+=commonField('Name','name','error name',true,'1','10',''); //username => prepopulate
		html+='<input id="fldNameH" type="hidden" name="nameh">';
		
		//email
		html+=commonField('Email','email','error email',false,'2','50','');
		
		//password
		html+=commonField('Passw','password','error passwd',false,'3','20','');
		
		//password strength 
		html+='<div class="frm-field">';
		html+='<div id="shwPasswStrength" class="empty"></div>';
		html+='</div>';
		
		//re-password 
		html+=commonField('RPassw','password2','error passwd',false,'4','20','');
		
		//zip
		html+=commonField('Zip','zip','error zip',false,'5','5','');
				
		//name 
		html+=commonField('FName','firstname','error firstname',false,'6','15','');
		
		//last-name
		html+=commonField('LName','lastname','error lastname',false,'7','20','');
		
		//VIN number
		html+=commonField('VIN','vin','error vinnumber',false,'8','','');
		
		//neighborhood
		html+='<div class="frm-field">';
		html+='<label for="slcNeighborhood" id="lbNeighborhood"></label>';
		html+='<select id="slcNeighborhood" name="nei" tabindex="9">';
		html+='<option value="1">El Centro</option>';
		html+='<option value="2">The Wharf</option>';
		html+='<option value="3">Gravity Hill</option>';
		html+='<option value="4">Vista Valley</option>';
		html+='<option value="5">Box District</option>';
		html+='</select>';
		html+='<div class="frm-tip">Where do you hail from? Pick your kind of neighborhood to customize your garage or go explore other garages.</div>'
		html+='<div class="frm-error" style="display:none;"><p>error A</p></div>';
		html+='</div>';
		
		//Privacy 
		html+='<div class="frm-subopt prelative">';
		html+='<p id="hdPrivacy"></p>';
		html+='<label for="rbPrivacyE">Everyone</label><input type="radio" class="styled" id="rbPrivacyE" tabindex="10" name="privacy" checked="checked">'; //
		html+='<label for="slcNeighborhood">Friends</label><input type="radio" class="styled" id="rbPrivacyF" tabindex="11" name="privacy">'; //
		html+='</div>';
		
		//Notifications
		html+='<div class="frm-subopt prelative">';
		html+='<p id="hdNotifications"></p>';
		html+='<label for="chEmailNotiShouts">Shouts</label><input type="checkbox" class="styled" id="chEmailNotiShouts" tabindex="12" checked="checked" name="na" value="a">';
		html+='<label for="chEmailNotiFriendReq">Friend requests and personal messages</label><input type="checkbox" class="styled" id="chEmailNotiFriendReq" tabindex="13" checked="checked" name="nb" value="b">';
		html+='<label for="chEmailNotiEvntsInvt">Scion event invitations and news</label><input type="checkbox" class="styled" id="chEmailNotiEvntsInvt" tabindex="14" checked="checked" name="nc" value="c">';
		html+='</div>';
		
		//options
		html+='<div class="frm-end prelative" style="padding-top:15px;">';
		html+='<div id="btCloseAccount" class="floatl"><a href="" onClick="accountManager.goDeactivate(\'DA\'); return false;">DEACTIVATE MY ACCOUNT</a></div>';
		html+='<div id="btSave" class="floatl" style="margin:0 15px 0 125px;"><a href="/" onClick="accountManager.onUpdateAccount(); return false;"></a></div>';
		html+='<div id="btCancel" class="floatl"><a href="/" onClick="accountManager.onCancel(\'AS\'); return false;"></a></div>';
		html+='<br clear="left">';
		html+='</div>';
		//end
		
		createFrmContainer(html,'AS',isShow);
		
		$('rbPrivacyE').onclick = function(e){
			flgPrivacy = 'N';
			log('flgPrivacy:'+flgPrivacy);
		}
		
		$('rbPrivacyF').onclick = function(e){
			flgPrivacy = 'Y';
			log('flgPrivacy:'+flgPrivacy);
		}
		
		$('chEmailNotiShouts').onclick = function(e){
			if(flgShout=='Y') flgShout = 'N';
			else flgShout = 'Y';
			log('flgShout:'+flgShout);
		}
		
		$('chEmailNotiFriendReq').onclick = function(e){
			if(flgNotify=='Y') flgNotify = 'N';
			else flgNotify = 'Y';
			log('flgNotify:'+flgNotify);
		}
		
		$('chEmailNotiEvntsInvt').onclick = function(e){
			if(flgEvents=='Y') flgEvents = 'N';
			else flgEvents = 'Y';
			log('flgEvents:'+flgEvents);
		}
	}
	
	function bldDeactivateAccount(show)
	{
		var isShow = show;
		var html='';
				
		html+='<div id="hdDEACTIVATEACCOUNT"></div>';
		html+='<p class="frm-subinfo phigh spvert30px tgcenter">Are you sure you want to deactivate your account?<br>Your contacts will no longer be able to keep in touch with you.<br>Why are you deactivating?</p>';
		
		//T&C
		html+='<div class="frm-subopt prelative noborder" style="margin-left:-25px;">';
		html+='<label class="fnt11px" for="chToManyEmails">I get too many emails, invitations, and requests from Scion City</label><input type="radio" class="styled" id="chToManyEmails" name="deactivate" checked="checked" value="y">';
		html+='<label class="fnt11px" for="chDntSafe">I don\'t feel safe on Scion City</label><input type="radio" class="styled" id="chDntSafe" name="deactivate" value="y">';
		html+='<label class="fnt11px" for="chDntLifeStyle">I don\'t find Scion City fits my lifestyle</label><input type="radio" class="styled" id="chDntLifeStyle" name="deactivate" value="y">';
		html+='<label class="fnt11px" for="chDificulty">I don\'t understand how to use this network</label><input type="radio" class="styled" id="chDificulty" name="deactivate" value="y">';
		html+='<label class="fnt11px" for="chSpendTime">I spend too much time using Scion City</label><input type="radio" class="styled" id="chSpendTime" name="deactivate" value="y">';
		html+='<label class="fnt11px" for="chOther"><strong>Other</strong></label><input type="radio" class="styled" id="chOther" name="deactivate" value="y">';
		html+='<p class="frm-tip">Please explain further:</p>';
		html+='<div class="frm-field"><textarea name="otherr" rows="5"></textarea></div>';
		html+='<div class="frm-error" style="display:none;" id="errDAOther"><p></p></div>';
		html+='</div>';
		
		//options
		html+='<div class="frm-end prelative noborder" style="padding-top:15px; margin-left:110px;">';
		html+='<div id="btDeactMyAccount" class="floatl" style="margin:0 20px 0 0;"><a href="/" onClick="accountManager.onDeactivate(); return false;"></a></div>';
		html+='<div id="btCancel" class="floatl"><a href="/" onClick="accountManager.onCancel(\'DA\'); return false;"></a></div>';
		html+='<br clear="left">';
		html+='<p class="frm-btn-tip">Clicking Deactivate My Account<br>will permanently remove your account.</p>';
		html+='</div>';
		
		createFrmContainer(html,'DA',isShow);
		
		$('chToManyEmails').onclick = function(e){
			wDeactivate = 1;
		}
		
		$('chDntSafe').onclick = function(e){
			wDeactivate = 2;
		}
		
		$('chDntLifeStyle').onclick = function(e){
			wDeactivate = 3;
		}
		
		$('chDificulty').onclick = function(e){
			wDeactivate = 4;
		}
		
		$('chSpendTime').onclick = function(e){
			wDeactivate = 5;
		}
		
		$('chOther').onclick = function(e){
			wDeactivate = 0;
		}
	}	
	
	function shwREGConfirmation(show)
	{
		var isShow = show;
		var html='';
		//options
		html+='<div>';
		html+='<h1 id="hdSuccess"></h1>';
		html+='<div id="msgSuccess"></div>';
		html+='<div class="align-cntr"><a href="/" onClick="accountManager.onCancel(\'CONF\'); return false;">close</a></div>';
		html+='</div>';	
		
		createContainer(html,'CONF',isShow);
		
		//releases memory
		delete shwREGConfirmation;
	}
	
	function shwDAConfirmation(show)
	{
		var isShow = show;
		var html='';
		//options
		html+='<div>';
		html+='<h1 id="hdDEACTIVATEACCOUNT"></h1>';
		html+='<div id="msgDeactivate"></div>';
		html+='<div class="align-cntr" style="margin-top:15px;"><a href="/" onClick="accountManager.onCancel(\'DAC\'); return false;">close</a></div>';
		html+='</div>';	
		
		createContainer(html,'DAC',isShow);
		
		//releases memory
		delete shwDAConfirmation;
	}
		
	function shwUAConfirmation(show)
	{
		var isShow = show;
		var html='';
		//options
		html+='<div>';
		html+='<h1 id="hdUnderAge"></h1>';
		html+='<div id="msgUnderAge"></div>';
		html+='</div>';	
		
		createContainer(html,'UA',isShow);
		
		//releases memory
		delete shwUAConfirmation;
	}
		
	function bldDeactivateConf(arr)
	{
		for(var i=0,j=arr.length;i<j;i++){
			$(arr[i]).hide();
		}
	}
	
	function hideErrMsg(arr)
	{
		for(var i=0,j=arr.length;i<j;i++){
			$(arr[i]).hide();
		}
	}
	
	function hideErrIcon(arr)
	{
		for(var i=0,j=arr.length;i<j;i++){
			$(arr[i]).hide();
		}
	}
	
	function closeMe(id)
	{		
		Effect.SlideUp(id,{
			afterFinish:function()
			{
				/*if(swfName!='header') mySWF(swfName).closeMenuOption();
				else mySWF(swfName).showIniMenu();*/
				
				//$('formContainer').setStyle({height: '0px'});
				$('formContainer').update('');
				
				isOpen = false;
				
				if(id=='REG' && swfName=="home"){
					//$('formContainer').show();
					accountManager.initWLCM(false);
				}
				
				/*
				if(id=='DAC' && swfName=="home"){
					user.Logout()
				}
				*/
			}
		});
	}
	
	function goRegister(id)
	{
		Effect.SlideUp(id,{
			afterFinish:function()
			{
				log('finishAnimation');
				$('formContainer').update('');
				//register
				bldRegistration(false);
			}
		});
	}
	
	function goLogin(id)
	{
		Effect.SlideUp(id,{
			afterFinish:function()
			{
				log('finishAnimation');
				$('formContainer').update('');
				//register
				bldLogin(false);
			}
		});
	}
	
	function backLogin()
	{
		$('errEmail').hide();
		$('hdREGRsm').setOpacity(1);
		$('optForgot').hide();
		$('optLogin').show();		
	}
	
	function goForgot()
	{
		$('errName').hide();
		$('errPassw').hide();
		$('hdREGRsm').setOpacity(1);
		$('optLogin').hide();
		$('optForgot').show();
	}
	
	function goDeactivate()
	{
		Effect.SlideUp('AS',{
			afterFinish:function()
			{
				log('finishAnimation');
				$('formContainer').update('');
				//register
				bldDeactivateAccount(false);
			}
		});
	}
	
	function onCancel(id)
	{
		closeMe(id);
	}
	
	function onLogin()
	{
		$('btLogIn').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		var isValid = false;
		var form = $('FrmLG').serialize(true);
		var uname = form['username'];
		var passw = form['password'];
		
		var aErr = ['errName','errPassw'];
		hideErrMsg(aErr);
		
		//validtae
		if(uname==''){
			$('btLogIn').update('<a href="/" onClick="accountManager.onLogin(); return false;"></a>');
			$('hdREGRsm').setOpacity(0);
			$('errName').update('<p>please enter a username</p>');
			$('errName').show();
			isValid = false;
		}else{
			$('hdREGRsm').setOpacity(1);
			$('errName').hide();
			$('errName').update('<p>please enter a username</p>');
			isValid = true;
		} 
		
		if(passw==''){
			$('btLogIn').update('<a href="/" onClick="accountManager.onLogin(); return false;"></a>');
			$('hdREGRsm').setOpacity(0);
			$('errPassw').show();
			isValid = false;	
		}else{
			$('hdREGRsm').setOpacity(1);
			$('errPassw').hide();
			isValid = true;
		} 
		
		if(isRememberMe){
			createCookie('loginScion',uname,356);
			createCookie('loginScionPssw',passw,356);
		}else{
			eraseCookie('loginScion');
			eraseCookie('loginScionPssw');
		}
		
		if(isValid){
			isLoginForm = true;
			user.Login(uname,passw);
		}
	}
	
	function onForgot()
	{
		$('btForgot').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		var isValid = false;
		var form = $('FrmLG').serialize(true);
		var email = form['email'];
		
		//var aErr = ['errEmail'];
		//hideErrMsg(aErr);
		
		$('hdREGRsm').setOpacity(1);
		$('errEmail').hide();
		$('errEmail').update('<p>please enter a email</p>');
		
		if(validateEmail(form['email'])){
			scion.forgotPassword(email);
		}else{
			$('hdREGRsm').setOpacity(0);
			$('btForgot').update('<a href="/" onClick="accountManager.onForgot(); return false;"></a>');
		} 
	}
	
	function onRegister()
	{
		$('btRegister').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		var isValid = false;
		var form = $('FrmREG').serialize(true);	
		
		var aErr = ['errName','errEmail','errPassw','errRPassw','errVIN','errZip','err18Older','errTC'];
		var aErrIcon = ['errNameIcon','errEmailIcon','errPasswIcon','errRPasswIcon','errVINIcon','errZipIcon'];
		hideErrMsg(aErr);
		hideErrIcon(aErrIcon);

		log('dBirthdate:'+form['day']+'/'+form['month']+'/'+form['year']);//dBirthdate = '26/01/1973';
		
		if(validateUserName(form['name'])
		&& validateEmail(form['email'])
		&& validatePassword(form['password'], form['password2'])
		&& validateVIN(form['vin'])
		&& validateZipCode(form['zip'])
		&& validate18Y()
		&& validateTC()
		){
			log('sending reg...')
			var obj = {
				username:form['name'],
				email:form['email'],
				password:form['password'],
				password2:form['password2'],
				vin:form['vin'], //4N0000000R0123456
				birthdate:form['day']+'/'+form['month']+'/'+form['year'],
				zipcode:form['zip']
			}
			
			scion.Register(obj);
		}else{
			$('btRegister').update('<a href="/" onClick="accountManager.onRegister(); return false;"></a>');
		}
		//*/
	}
	
	function alertUA(){
		Effect.SlideUp('REG',{
			afterFinish:function()
			{
				$('formContainer').update('');
				isOpen = false;
				
				shwUAConfirmation(false);
			}
		});
	}
	
	function regSuccess()
	{
		Effect.SlideUp('REG',{
			afterFinish:function()
			{
				$('formContainer').update('');
				isOpen = false;
				
				shwREGConfirmation(false);
			}
		});
	}
	
	function deactivateSuccess()
	{
		Effect.SlideUp('DA',{
			afterFinish:function()
			{
				$('formContainer').update('');
				isOpen = false;
				
				shwDAConfirmation(false);
			}
		});
	}
	
	function onUpdateAccount()
	{
		$('btSave').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		var isValid = false;
		var isValidPassw = false;
		var form = $('FrmAS').serialize(true);	
				
		var aErr = ['errName','errEmail','errPassw','errRPassw','errVIN','errZip'];
		var aErrIcon = ['errNameIcon','errEmailIcon','errPasswIcon','errRPasswIcon','errVINIcon','errZipIcon'];
		hideErrMsg(aErr);
		hideErrIcon(aErrIcon);
		
		var frmPassw = form['password'];
		var frmPassw2 = form['password2'];
		
		if(frmPassw == '---------------'){
			frmPassw = '';
			frmPassw2 = '';
			isValidPassw = true;
		}else{
			isValidPassw = validatePassword(form['password'], form['password2']);
		}
		
		//globalUName=form['nameh'];
		
		if(validateUserName(form['nameh'])
		&& validateEmail(form['email'])
		&& isValidPassw
		&& validateVIN(form['vin'])
		&& validateZipCode(form['zip'])
		){
			var update = {
				username:form['nameh'],
				email:form['email'],
				password:frmPassw,
				password2:frmPassw2,
				zipcode:form['zip'],
				firstname:form['firstname'],
				lastname:form['lastname'],
				vin:form['vin'], //4N0000000R0123456
				nei:form['nei'],
				flagprivacy:flgPrivacy,
				flagshout:flgShout,
				flagnotify:flgNotify,
				flagevents:flgEvents
			}
			
			log('UserProfileEdit:'+Object.toJSON(update));
			user.UserProfileEdit(update);			
		}else{
			$('btSave').update('<a href="/" onClick="accountManager.onUpdateAccount(); return false;"></a>');
		}
	}
	
	function onDeactivate()
	{
		$('btDeactMyAccount').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		var mssg = '';
		var form = $('FrmDA').serialize(true);
		mssg = form['otherr'];
		
		if(wDeactivate!=0) mssg = ''; 
		
		log('deactivate:'+wDeactivate+'/'+mssg);
		user.deactivate(wDeactivate, mssg);
	}
	
	function saveAndGo(opt)
	{
		$('btSaveAndGoProfile').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		$('btSaveAndGoHome').update('<img class="spinner" src="/img/loadinfo.net.gif" alt="loading" />');
		wlcmAcion = opt;
		var form = $('FrmWUSER').serialize(true);
		log('saveAndGo -> nei:'+form['nei']+' / flgPrivacy:'+flgPrivacy+' / flgShout:'+flgShout+' / flgNotify:'+flgNotify+' / flgEvents:'+flgEvents)
		user.garagewelcome(form['nei'], flgPrivacy, flgShout, flgNotify, flgEvents);
	}
	
	return{
		initLG:bldLogin,
		initWLCM:bldWelcome,
		initREG:bldRegistration,
		initWUSER:bldWelcomeUsr,
		initAS:bldAccountSettings,		
		initDA:bldDeactivateAccount,
		//
		initUA:shwUAConfirmation,
		//initDAConf:shwDAConfirmation,
		//iniCONF:shwREGConfirmation,
		//
		closeMe:closeMe,
		goRegister:goRegister,
		goLogin:goLogin,
		goForgot:goForgot,
		goDeactivate:goDeactivate,
		saveAndGo:saveAndGo,
		//
		onCancel:onCancel,
		onLogin:onLogin,
		onForgot:onForgot,
		onRegister:onRegister,
		onUpdateAccount:onUpdateAccount,
		onDeactivate:onDeactivate,
		//
		regSuccess:regSuccess,
		deactivateSuccess:deactivateSuccess,
		alertUA:alertUA,
		backLogin:backLogin
	}	

}();

function getIsUnderAge()
{
	return isUnderAge;
}

function callFromFlash(frm)
{
	log('callFromFlash:'+frm);
	switch(frm){
		case 'LG':
			if(!isUnderAge) accountManager.initLG(false);
			else accountManager.initUA(false);
			break;
		case 'WLCM':
			if(typeof(openvinreg_show) == 'undefined') {
				return;
			}

			if(openvinreg_show==0){
				if(thisSection=='HOME' && !isOnSession){
					if(!isUnderAge) accountManager.initWLCM(false);
					else accountManager.initUA(false);
				}
			}
			break;
		case 'REG':
			if(!isUnderAge) accountManager.initREG(false);
			else accountManager.initUA(false);
			break;
		case 'AS':
			if(!isUnderAge) accountManager.initAS(false);
			else accountManager.initUA(false);
			break;
		case 'UA':
			if(!isUnderAge) accountManager.initUA(false);
			else accountManager.initUA(false);
			break;
		default:
			$('formContainer').update('');
			break;
	}
}
//window.addEventListener('load', accountManager.initWLCM, false);
addOnloadEvent(function(){	
	/* DEBUG */
	//if(swfName != "home") accountManager.iniCONf(false);
	//if(swfName != "home") accountManager.initWUSER(false);
	//if(swfName != "home") accountManager.initDAConf(false);
	/* END DEBUG */
});

document.observe('dom:loaded', function () {
	Element.insert('SCION', {top:'<div id="formContainer" style="height:1px; display:inline;"></div>'});
	new Ajax.Request('/index/checkifunderage', {
		method: 'get',
		onSuccess: function(transport) {
			if (transport.responseText == 1){
				isUnderAge = true;
				accountManager.initUA(false);
			}else{
				isUnderAge = false;
			}
			
			log('isUnderAge:'+isUnderAge);
		}
	});
	
	if(typeof(openvinreg_show) == 'undefined') {
		return;
	}
	if(openvinreg_show==1){
		accountManager.initREG(false);
		var form = $('FrmREG');
		var email = form['email'];
		var vinn = form['vin'];
		var zip = form['zip'];
		$(email).value = openvinreg_email;
		$(vinn).value = openvinreg_vin;
		$(zip).value = openvinreg_zip;
	}
});

/**
* user.Login
*/
/*
user.SessionLoaded = function()
{
	//accountManager.closeMe('LG');
};
*/
user.LoginFailed = function(errors)
{
	$('btLogIn').update('<a href="/" onClick="accountManager.onLogin(); return false;"></a>');
	if(errors == 'Invalid username'){
		$('hdREGRsm').setOpacity(0);
		$('errName').hide();
		$('errName').update('<p>invalid username</p>');
		$('errName').show();
	}else if(errors == 'Invalid username or password'){
		$('hdREGRsm').setOpacity(0);
		$('errName').hide();
		$('errName').update('<p>invalid username or password</p>');
		$('errName').show();	
	}else if(errors == 'No user'){
		$('hdREGRsm').setOpacity(0);
		$('errName').hide();
		$('errName').update('<p>invalid username</p>');
		$('errName').show();
	}else if(errors == 'Deleted user'){
		$('hdREGRsm').setOpacity(0);
		$('errName').hide();
		$('errName').update('<p>this user has been blocked</p>');
		$('errName').show();
	}else{
		$('hdREGRsm').setOpacity(1);
		$('errName').hide();
	}
	//log('user.LoginFailed -> '+errors);
};

/**
* scion.Register
*/
scion.RegisterSent = function()
{
	log('scion.RegisterSent');
	$('errNameIcon').hide();
	$('errVINIcon').hide();
	accountManager.regSuccess();
}

scion.RegisterFailed = function(errors)
{
	$('btRegister').update('<a href="/" onClick="accountManager.onRegister(); return false;"></a>');
	log('scion.RegisterFailed -> '+errors);
	
	if(/ERROR_UNDERAGE/.match(errors)){
		//accountManager.alertUA(false);		
		new Ajax.Request('/index/checkifunderage', {
			method: 'get',
			onSuccess: function(transport) {
				if (transport.responseText == 1){
					isUnderAge = true;
					accountManager.alertUA(false);
				}else{
					isUnderAge = false;
				}
				
				log('isUnderAge:'+isUnderAge);
			}
		});
	}
	
	if(/username/.match(errors)){
		$('errName').update('<p>this username is already in use</p>');
		$('errName').show();
		$('errNameIcon').show(); 
		
		$('fldName').onfocus = function(e){
			$('errNameIcon').hide();
		}
	}
	
	if(/Invalid username/.match(errors)){
		$('errName').update('<p>this username is invalid</p>');
		$('errName').show();
		$('errNameIcon').show(); 
		
		$('fldName').onfocus = function(e){
			$('errNameIcon').hide();
		}
	}
	
	if(/VIN/.match(errors)){
		$('errVIN').update('<p>this VIN number is not valid</p>');
		$('errVIN').show();
		$('errVINIcon').show();
		
		$('fldVIN').onfocus = function(e){
			$('errVINIcon').hide();
		}
	}
	
	if(/BAD_ZIPCODE/.match(errors)){
		$('errZip').update('<p>this zipcode is not valid</p>');
		$('errZip').show();
		$('errZipIcon').show();
		
		$('fldZip').onfocus = function(e){
			$('errZipIcon').hide();
		}
	}
	
	if(/email is already/.match(errors)){
		$('errEmail').update('<p>this email is already in use</p>');
		$('errEmail').show();
		$('errEmailIcon').show();
		
		$('fldEmail').onfocus = function(e){
			$('errEmailIcon').hide();
		}
	}
	
	if(/USERS_ERROR_BAD_EMAIL/.match(errors)){
		$('errEmail').update('<p>this email is misspelled</p>');
		$('errEmail').show();
		$('errEmailIcon').show();
		
		$('fldEmail').onfocus = function(e){
			$('errEmailIcon').hide();
		}
	}

}

/**
* ser.UserProfileEdit
*/
user.UserProfileEditSucceeded = function()
{
	log('user.UserProfileEditSucceeded');
	accountManager.closeMe('AS');
	//thisgarage.Load(user.data.username);
}

user.UserProfileEditFailed = function(errors)
{
	$('btSave').update('<a href="/" onClick="accountManager.onUpdateAccount(); return false;"></a>');
	log('user.UserProfileEditFailed -> '+errors);
	
	if(/username/.match(errors)){
		$('errName').update('<p>this username is already in use</p>');
		$('errName').show();
		$('errNameIcon').show(); 
		
		$('fldName').onclick = function(e){
			$('errNameIcon').hide();
		}
	}
	
	if(/VIN/.match(errors)){
		$('errVIN').update('<p>this VIN number is not valid</p>');
		$('errVIN').show();
		$('errVINIcon').show();
		
		$('fldVIN').onclick = function(e){
			$('errVINIcon').hide();
		}
	}
	
	if(/BAD_ZIPCODE/.match(errors)){
		$('errZip').update('<p>this zipcode is not valid</p>');
		$('errZip').show();
		$('errZipIcon').show();
		
		$('fldZip').onclick = function(e){
			$('errZipIcon').hide();
		}
	}
	
	if(/email is already/.match(errors)){
		$('errEmail').update('<p>this email is already in use</p>');
		$('errEmail').show();
		$('errEmailIcon').show();
		
		$('fldEmail').onclick = function(e){
			$('errEmailIcon').hide();
		}
	}
	
	if(/USERS_ERROR_BAD_EMAIL/.match(errors)){
		$('errEmail').update('<p>this email is misspelled</p>');
		$('errEmail').show();
		$('errEmailIcon').show();
		
		$('fldEmail').onclick = function(e){
			$('errEmailIcon').hide();
		}
	}

}

/**
* user.deactivate
*/
user.deactivateSucceeded = function()
{
	log('user.deactivateSucceeded');
	accountManager.deactivateSuccess();	
}


user.deactivateFailed = function(errors)
{
	$('btDeactMyAccount').update('<a href="/" onClick="accountManager.onDeactivate(); return false;"></a>');
	log('user.deactivateFailed -> '+errors);
	//$('errDAOther').update('<p>need to explain way</p>')
	//$('errDAOther').show();
}

/**
* user.garagewelcome
*/
user.garagewelcomeSucceeded = function()
{
	log('user.garagewelcomeSucceeded');	
	if(wlcmAcion=='home') {
		window.location="/whatsnew/";
	}else{
		//user.data = oSessionData;
		accountManager.closeMe('WUSER');		
	}
}

user.garagewelcomeFailed = function(errors)
{
	$('btSaveAndGoProfile').update('<a href="/" onClick="accountManager.saveAndGo(\'profile\'); return false;"></a>');
	$('btSaveAndGoHome').update('<a href="/" onClick="accountManager.saveAndGo(\'home\'); return false;"></a>');
	log('user.garagewelcomeFailed -> '+errors);
	//$('errDAOther').update('<p>need to explain way</p>')
	//$('errDAOther').show();
}

/**
* scion.forgotPassword
*/
scion.forgotPasswordSuccess = function()
{
	log('scion.forgotPasswordSuccess');
	$('errEmail').hide();
	$('hdREGRsm').setOpacity(1);
	$('optForgot').hide();
	$('optLogin').show();
	//if(swfName == "home") mySWF(swfName).showIniMenu();
	//accountManager.closeMe('LG');
}

scion.forgotPasswordFailed = function(error)
{
	log('scion.forgotPasswordFailed:'+error);
	$('hdREGRsm').setOpacity(0);
	$('btForgot').update('<a href="/" onClick="accountManager.onForgot(); return false;"></a>');
	
	if(/email is not/.match(error)){
		$('errEmail').update('<p>this email is not register in scionowners</p>');
		$('errEmail').show();
		
		$('fldEmail').onclick = function(e){
			$('errEmail').hide();
		}
	}
}
