<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #

##################################################################
#               Developed On:   03-23-2009                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("classes/misc.class.php");
require_once ("classes/userside.class.php");

$message	= "";
$scripts	= "";
$arrElements= array();
$vNewPa		= isset($_POST['vNewPa'])	?	stripslashes(trim($_POST['vNewPa']))	:	"";
$vNewConPa	= isset($_POST['vNewConPa'])?	stripslashes(trim($_POST['vNewConPa']))	:	"";
$lengthpass=strlen($vNewPa);
if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objM		= new misc($objDB);
	$objU		= new userside($objDB);	
	
	if (isset($_POST['CNP'])) {
		if ($vNewPa == "") {
			$message	.= "Please enter new password.<br>";
			$arrElements[]	= "vNewPa";
		}
		if ($vNewConPa == "") {
			$message	.= "Please confirm new password.<br>";
			$arrElements[]	= "vNewConPa";
		}

                if ($lengthpass <6) {
                $message	.= "Password should be atleast 6 characters long.<br>";
                }
		if ($vNewPa <> $vNewConPa) {
			$message	.= "Mismatch of passwords.<br>";
			$arrElements[]	= "vNewPa";
			$arrElements[]	= "vNewConPa";
		}
		if (!empty($arrElements)) {
			$scripts	= '<script language="javascript">';
			foreach ($arrElements as $key=>$value) {
				$scripts	.= 'document.frmTell.'.$value.'.className = "errorinput";';
			}
			$scripts	.= '</script>';
		}
		$message	.= $scripts;
		if ($message == "")
			$message	= $objM->change_password($_SESSION['user_id'], $vNewPa);
		if ($message == "")
			$message	= "<font color='green'>Your password has been successfully changed.</font><br>";
	}
	
	$scripts	= $objM->get_script($message);
	$message	= $objM->remove_script($message);
}
include_once ("title.inc.php");
include_once ("tophtml.inc.php");
?>
<script language="javascript" type="text/javascript">
function changeCSS(obj, type)
{
	if (type == 'text') {
		obj.className = 'textbox txt-bx01';
	} else if (type == 'textarea') {
		obj.className = 'textbox_textarea';
	} else if (type == 'select') {
		obj.className = 'textbox txt-bx01';
	} else {
		obj.className = 'textbox txt-bx01';
	}
}
function validate()
{
	var frm = document.frmTell;
	if (frm.vNewPa.value == "") {
		alert("Please enter new password.");
		frm.vNewPa.focus();
		frm.vNewPa.className ='textbox txt-bx01';
		return false;
	}
	if (frm.vNewConPa.value == "") {
		alert("Please confirm new password.");
		frm.vNewConPa.focus();
		frm.vNewConPa.className ='textbox txt-bx01';
		return false;
	}

          if ($('#vPass').val().length<6 ) {
            	alert("Password should be atleast 6 characters long.");
		frm.vPass.focus();
		frm.vPass.className ='textbox commononetextbox';
		return false;
	}


}
</script>

<div class="row">
	<div class="eight columns">
		<div class="search-rslts">
			<div class="row"><div class="inenr-hd"><h2>Change Password</h2></div></div>
			<div class="row">
				<h2 class="headings2">Change Your Password Now</h2>
			</div>
			<div class="row">
				<form name="frmTell" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onSubmit="return validate();">
					<div class="newdesignforinput maintext1">
						<?php if(isset($message) && trim($message)!='')
							  {
						?>
						<div class="full_row">
							<div class="maintext1 warning"><?php echo $message;?></div>
						</div>
						<?php }//end if?>
						
						<div class="full_row">
							<div class="three columns">New Password</div>
							<div class="five columns margin_R_200">
								<input name="vNewPa" type="password" class="textbox txt-bx01" size="25" maxlength="100" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Confirm Password</div>
							<div class="five columns margin_R_200">
								<input name="vNewConPa" id="vNewConPa"  type="password" class="textbox txt-bx01" size="25" maxlength="100" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">&nbsp;</div>
							<div class="five columns margin_R_200">
								<input name="CNP" type="submit" class="loginbutton" value="Change Now">
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="four columns right search_result_R">
		<?php include_once ("left.inc.php");?>
	</div>
</div>

<?php include_once('bottomhtml.inc.php');?>
