// JavaScript Document
/**
 * Registration.js
 *
 * @version		0.0
 * @author		Ben J. Milander
 * @copyright	Classic Chevy Reno
 */

function startLogin(){
/*$(id) equivalent to document.getElementById(id) from prototyp library. */  
    $('hl_login_form').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'visible';
	  $('hl_msg').style.visibility = 'hidden';
      $('hl_reg_message').style.visibility = 'hidden';

      return true;
}
function sendPassword(){
	  $('hl_pw_message').style.visibility = 'visible';
 	  $('hl_forgot_pw').style.visibility = 'hidden';
      $('hl_reg_message').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'hidden';
      return true;
}

function startLogout(){
      $('hl_loggingout').style.visibility = 'visible';
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_reg_message').style.visibility = 'hidden';
		return true;
}
function DoRegister(){
	  $('hl_register').style.visibility = 'hidden';
      $('hl_reg_message').style.visibility = 'visible';
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'hidden';
		return true;
}

function ShowLogin(){
      $('hl_logoutMbr').style.visibility = 'hidden';
	  $('hl_logoutAssoc').style.visibility = 'hidden';
	  $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'visible';
	  $('hl_fpw_result').style.visibility = 'hidden';
	  $('hl_forgot_pw').style.visibility = 'hidden';
	  $('hl_register').style.visibility = 'hidden';
      $('hl_loggingout').style.visibility = 'hidden';
	  $('hl_change_pw').style.visibility = 'hidden';
}

function ShowLogoutMember(){
	  $('hl_logoutAssoc').style.visibility = 'hidden';
      $('hl_logoutMbr').style.visibility = 'visible';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  $('hl_fpw_result').style.visibility = 'hidden';
	  $('hl_forgot_pw').style.visibility = 'hidden';
	  $('hl_register').style.visibility = 'hidden';
      $('hl_loggingout').style.visibility = 'hidden';
	  $('hl_change_pw').style.visibility = 'hidden';
	  
}
function showAdminPanel(){
      $('hl_logoutMbr').style.visibility = 'hidden';
	  $('hl_logoutAdmin').style.visibility = 'visible';
}

function ShowLogoutAssociate(){
	  $('hl_logoutAssoc').style.visibility = 'visible';
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  $('hl_fpw_result').style.visibility = 'hidden';
	  $('hl_forgot_pw').style.visibility = 'hidden';
	  $('hl_register').style.visibility = 'hidden';
      $('hl_loggingout').style.visibility = 'hidden';
	  $('hl_change_pw').style.visibility = 'hidden';
	  
}


function ShowForgotPW(){
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  $('hl_forgot_pw').style.visibility = 'visible';
	  $('hl_register').style.visibility = 'hidden';
	  $('hl_change_pw').style.visibility = 'hidden';
}
function ShowChangePW(){
	  $('hl_change_pw').style.visibility = 'visible';
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_logoutAssoc').style.visibility = 'hidden';
}

function ShowRegister(){
      $('hl_logoutMbr').style.visibility = 'hidden';
      $('hl_msg').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  $('hl_forgot_pw').style.visibility = 'hidden';
	  $('hl_register').style.visibility = 'visible';
	  $('hl_change_pw').style.visibility = 'hidden';
}

function displayLoginErrors(submitted, error, member, associate, result){
      var thisresult = "";
	  thisresult = result;
	  
	  $('hl_logoutMbr').style.visibility = 'hidden';
	  $('hl_logoutAssoc').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'hidden';
	  $('hl_login_form').style.visibility = 'visible';
	  
	  if ((submitted == 1) && (error == 1)) {
	      Dialog.alert(thisresult, 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
		  return false;   

		} else {
                if (submitted == 0) {
                  Dialog.alert("No form was submitted", 
                 {width:300, height:100, okLabel: "close", 
                  ok:function(win) {debug("validate alert panel"); return true;}});
                      return false;
			} else {
					if (member == '1') {
					  $('loginSuccess').innerHTML = thisresult;
					  $('hl_logoutMbr').style.visibility = 'visible';
					  $('hl_login_form').style.visibility = 'hidden';
					  return true;
					 } else {
					 	if (associate == '1') {
							$('loginSuccessA').innerHTML = thisresult;
						    $('hl_logoutAssoc').style.visibility = 'visible';
						    $('hl_login_form').style.visibility = 'hidden';
					  		return true;
						} else {
							 $('hl_login_form').style.visibility = 'visible';
							 return false;
							}   
						}
					}
				}
}

function displayChangePWErrors(submitted, error, member, associate, dest, result){
      var thisresult = "";
	  thisresult = result;
	  $('hl_logging').style.visibility = 'hidden';
	  $('hl_loggingout').style.visibility = 'hidden';
	  $('hl_login_form').style.visibility = 'hidden';
	  
	  if ((submitted == 1) && (error == 1)) {
	      Dialog.alert(thisresult, 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
		  return false;   

		} else {
                if (submitted == 0) {
                  Dialog.alert("No form was submitted", 
                 {width:300, height:100, okLabel: "close", 
                  ok:function(win) {debug("validate alert panel"); return true;}});
                      return false;
			} else {
				if (member ==1) {
					if (dest == 1) {	/*Go to login page*/	
						Dialog.alert(thisresult, 
						{width:300, height:100, okLabel: "close", 
						ok:function(win) {debug("validate alert panel"); return true;}});
						$('hl_login_form').style.visibility = 'hidden';
						$('hl_change_pw').style.visibility = 'hidden';
						$('hl_logoutMbr').style.visibility = 'hidden';
						return false;   
					} else {
						Dialog.alert(thisresult, 
						{width:300, height:100, okLabel: "close", 
						ok:function(win) {debug("validate alert panel"); return true;}});
						$('hl_login_form').style.visibility = 'hidden';
						$('hl_change_pw').style.visibility = 'hidden';
						$('hl_logoutMbr').style.visibility = 'visible';
						return true;
					}
				} else {
						if (dest == 1) {	/*Go to login page*/	
							Dialog.alert(thisresult, 
							{width:300, height:100, okLabel: "close", 
							ok:function(win) {debug("validate alert panel"); return true;}});
							$('hl_login_form').style.visibility = 'hidden';
							$('hl_change_pw').style.visibility = 'hidden';
							$('hl_logoutAssoc').style.visibility = 'hidden';
							return false;   
						} else {
							Dialog.alert(thisresult, 
							{width:300, height:100, okLabel: "close", 
							ok:function(win) {debug("validate alert panel"); return true;}});
							$('hl_login_form').style.visibility = 'hidden';
							$('hl_change_pw').style.visibility = 'hidden';
							$('hl_logoutAssoc').style.visibility = 'visible';
							return true;   
						}
				}
			}
		}
}

function displayLogoutErrors(submitted, error, result){
      var thisresult = "";
	  thisresult = result;
	  $('hl_logoutMbr').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'hidden';
	  $('hl_loggingout').style.visibility = 'hidden';
	  $('hl_login_form').style.visibility = 'visible';
	  
	      Dialog.alert(thisresult, 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
			  
}

function display_fpw_Errors(submitted, error, result){
      var thisresult = "";
	  thisresult = result;
	  $('hl_forgot_pw').style.visibility = 'visible';
	  $('hl_logoutMbr').style.visibility = 'hidden';
	  $('hl_logging').style.visibility = 'hidden';
	  $('hl_pw_message').style.visibility = 'hidden';
	  
	  if ((submitted == 1) && (error == 1)) {
	      Dialog.alert(thisresult, 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
		  return false;   

		} else {
					if (submitted == 0) {
					Dialog.alert("No form was submitted", 
					 {width:300, height:100, okLabel: "close", 
					  ok:function(win) {debug("validate alert panel"); return true;}});
					  return false;
			} else {
				if (error == 0) {
					Dialog.alert(thisresult, 
					 {width:300, height:100, okLabel: "close", 
					  ok:function(win) {debug("validate alert panel"); return true;}});

					  $('hl_login_form').style.visibility = 'visible';
					  $('hl_forgot_pw').style.visibility = 'hidden';
					  return true;
				} else {
					  Dialog.alert(thisresult, 
						 {width:300, height:100, okLabel: "close", 
						  ok:function(win) {debug("validate alert panel"); return true;}});
					return false;   
				}
			}
		}
} 
function display_reg_Errors(submitted, error, result){
      var thisresult = "";
	  thisresult = result;
      $('hl_reg_message').style.visibility = 'hidden';
      $('hl_login_form').style.visibility = 'hidden';
	  
	  if ((submitted == 1) && (error == 1)) {
		  Dialog.alert(thisresult, 
			 {width:300, height:100, okLabel: "close", 
			  ok:function(win) {debug("validate alert panel"); return true;}});
		  	  $('hl_login_form').style.visibility = 'visible';
		  return false;   

		} else {
					if (submitted == 0) {
					Dialog.alert("No form was submitted", 
					 {width:300, height:100, okLabel: "close", 
					  ok:function(win) {debug("validate alert panel"); return true;}});
					  $('hl_register').style.visibility = 'hidden';
					  return false;
			} else {
				if (error == 0) {
					  Dialog.alert(thisresult, 
						 {width:300, height:100, okLabel: "close", 
						  ok:function(win) {debug("validate alert panel"); return true;}});
					  	$('hl_register').style.visibility = 'hidden';
      					$('hl_login_form').style.visibility = 'visible';

					  return true;
				} else {
					  Dialog.alert(thisresult, 
						 {width:300, height:100, okLabel: "close", 
						  ok:function(win) {debug("validate alert panel"); return true;}});
					  $('hl_register').style.visibility = 'hidden';
					return false;   
				}
			}
		}
}
function adminAuthorized(error, name, status, result){
      var thisresult = "";
	  thisresult = result;
	  
	  if (error == 1) {		/*detected and error*/
	      Dialog.alert(thisresult, 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
			$('hl_logoutAdmin').style.visibility = 'hidden';
		  	return false;   
		} else {
			if (status == 1) {  /*no error and administrator true*/
	      Dialog.alert(name + ' is an authorized Administrator' , 
             {width:300, height:100, okLabel: "close", 
              ok:function(win) {debug("validate alert panel"); return true;}});
			  $('hl_logoutAdmin').style.visibility = 'visible';
			  $('adminAuthSuccess').innerHTML = thisresult;

			  return true;
			} else {	/*No error but not administrator*/
				Dialog.alert(name + " not a recognized Administrator", 
				 {width:300, height:100, okLabel: "close", 
				  ok:function(win) {debug("validate alert panel"); return true;}});
				  $('hl_logoutAdmin').style.visibility = 'hidden';
				  return false;
			}
		}
} 

function showInfo() {
/*      $('hl_login_form').style.visibility = 'hidden';
*/
	
	Dialog.alert({url: "member_info_panel.html", options: {method: 'get'}}, {className: "alphacube", width:540, okLabel: "Close", top:300, left:100} );

}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


