<?
require_once('includes/configure.php');
require_once "../admin/include/function.php";
require_once "includes/$lang/chgpwd.php";
require_once "includes/formvalidator.php";

if(isset($_POST['btnUpdate'])){

    $validator = new FormValidator();
//    $validator->addValidation("userid","req",REQUIRED_USERID);
//	$validator->addValidation("pwd","req",ERROR_PASSWORD);	
//	if($newpwd){
		$validator->addValidation("newpwd","minlen=6",ERROR_PASSWORD);	
		$validator->addValidation("newpwd","regexp=/^[a-zA-Z0-9]+$/",ERROR_PASSWORD);		
		$validator->addValidation("conpwd","eqelmnt=newpwd",ENTRY_PASSWORD_ERROR_NOT_MATCHING);		
//	}
	if($validator->ValidateForm())
    {
		$sql="UPDATE `ivc_members` SET  im_pwd='".md5($newpwd)."'";
		$sql.="where im_id='".$_SESSION["egoMemberID"]."'";

		@mysql_query($sql) or die(mysql_error());
		$ainfo=RECORD_UPDATED;
		print("<script type='text/javascript'>location.href='index.php?ai=$ainfo'</script>");	
	}else {
	    $action_msg= "<br><B>Validation Errors:</B><br>";

        $error_hash = $validator->GetErrors();
        foreach($error_hash as $inpname => $inp_err)
        {
           $action_msg.= "$inp_err<br>";
        }        
    }
}else{
	$sql="select im_userid from ivc_members where im_id='".$_SESSION["egoMemberID"]."'";
	$result=mysql_query($sql);	
	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		$userid=$myrow["im_userid"];
	}	

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?= HTML_PARAMS ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= CHARSET ?>" />
<title><?=TITLE?></title>
<!-- SmartMenus 6 config and script core files -->
<? if($_SESSION["egoLang"]=="ENG"){ ?>
<script type="text/javascript" src="c_config.js"></script>
<? }else if($_SESSION["egoLang"]=="CH"){ ?>
<script type="text/javascript" src="ch_config.js"></script>
<? } ?>
<script type="text/javascript" src="c_smartmenus.js"></script>

<!-- SmartMenus 6 config and script core files -->


<link rel="stylesheet" type="text/css" href="../styles.css" >
</head>

<body>
<table width="1000" height="600" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  <tr>
    <td height="82" background="../images/iconic_01.jpg"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="91%" height="30" align="right" valign="bottom" class="topmenu"><? include_once "includes/topmenu.php"; ?></td>
        <td width="9%" rowspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td height="4"></td>
      </tr>
      <tr>
        <td height="14" align="right">
          <? include_once "includes/menu.php"; ?>
</td>
        <td height="29" rowspan="2"></td>
      </tr>
      <tr>
        <td height="3" align="right"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="500" valign="top" background="../images/memberlogin_bg.jpg" style="background-repeat:no-repeat">

      <table width="76%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="789" height="340" valign="bottom" class="title1"><?=CHANGE_PWD;?></td>
      </tr>
      
      <tr>
        <td >
		<form name="form" method="post" action="<?=$PHP_SELF ?>" >
	   <table width="820" height="250" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>
        
        <td valign="top">
<!--        <div class="scroll"> -->
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
  
  <tr>
    <td colspan="2" valign="bottom" class="require" ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
  </tr>
  <tr>
    <td width="24%" height="30" class="text1"><?=NEW_PWD; ?> : <span class="require">*</span></td>
    <td width="76%" height="30" class="text1"><input name="newpwd"  type="password" value="<? echo $newpwd ?>" size="30" />
      <span class="subItem"><?=MIN_PWD?></span></td>
  </tr>
  <tr>
    <td height="30" class="text1"><?=CONFIRM_PWD; ?> : <span class="require">*</span></td>
    <td height="30" class="text1"><input name="conpwd"  type="password" value="<? echo $conpwd ?>" size="30" /></td>
  </tr>
  <tr>
    <td height="30" colspan="2"><span class="require">
      <?=FORM_REQUIRED_INFORMATION?>
    </span></td>
  </tr>
  <tr>
    <td height="40" colspan="2" class="TextH1"><input name="btnUpdate" type="submit" class="btn" id="btnUpdate" value="<?=BUTTON_UPDATE;?>" /></td>
  </tr>
</table>
</td>
      </tr>
    </table>
		</form>		</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><? include_once "includes/bottom.php" ?></td>
  </tr>
</table>
</body>
</html>