<script type="text/javascript"> 
$(document).ready(function(){ 
var b = $("#b"); 
var overFlow = $("#over"); 
b.click(function(){ 
overFlow.fadeIn(); 
$("#mask").css("background","#111"); 
$("#mask").css("opacity","0.5"); 
}); 
$("#close").click(function(){ 
overFlow.fadeOut(); 
$("#mask").css("background","#fff"); 
$("#mask").css("opacity","1"); 
}); 
drag($("#over"),$("#title")); 
}); 
</script>
<link rel="stylesheet" type="text/css" href="facebox/facebox.css" />
<script language="javascript" src="jquery.js"></script>
<script language="javascript" src="facebox/facebox.js"></script>
<script language="javascript">
$(document).ready(function() {
    $('a[rel*=facebox]').facebox();
})
</script>
<script type="text/javascript">
	function checkCurrent(current){
	
	if(current.length==0){
		 document.getElementById("check").innerHTML=""
	}else{	
	
	
	xmlHttp=GetXmlHttpObject()
	if(xmlHttp==null)
	{
		alert("Browser does not support HTTP Request")
		return
	}
	var url="checkCurrent.php"
	url=url+"<?php echo"?user=$user";?>&q="+current
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 value=xmlHttp.responseText
  
 if(value==true){
 document.getElementById("check").innerHTML="OK"
 myObj=document.getElementById("check");
 myObj.style.color = "green";
 }
 if(value==false){
 myObj2=document.getElementById("check");
 myObj2.style.color = "red";
 document.getElementById("check").innerHTML="*Wrong current password"
 
 }
}
}//end function
//-----------------http Object---------------------//
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
//--------------------------------------------------//


function newPass(str,str2){
	if(str.length==0){
		 document.getElementById("new").innerHTML=""
	}	
	if(str.length<3 && str.length!=0){
		document.getElementById("new").innerHTML="*Password too short"
		myObj=document.getElementById("new");
		myObj.style.color = "red";
	}
	if(str.length>=3){
		document.getElementById("new").innerHTML="OK"
		myObj2=document.getElementById("new");
		myObj2.style.color = "green";
	}
	if(str!=str2 && str2!=""){
		document.getElementById("aaa").innerHTML="*No match password"
		myObj2=document.getElementById("aaa");
		myObj2.style.color = "red";
	}
	if(str==str2 && str2!=""){
		document.getElementById("aaa").innerHTML="OK"
		myObj2=document.getElementById("aaa");
		myObj2.style.color = "green";
	}

}
function confirm(str1,str2){
	
	if (str1==str2){
	document.getElementById("aaa").innerHTML="OK"
	myObj2=document.getElementById("aaa");
	myObj2.style.color = "green";
	
	}else{
	document.getElementById("aaa").innerHTML="*No match password"
	myObj2=document.getElementById("aaa");
	myObj2.style.color = "red";
	}
	
	if(str2.length==0){
	document.getElementById("aaa").innerHTML="";
	}
}
</script> 
<table border=0 width=100% cellspacing=1 cellpadding=3 class=corners2>
		<tr>
			<td colspan=2 align=left>
			</td>
			</tr>
		<tr>
			<th>User :</th>
			<th>Admin</th>
			</tr>
		<tr>
			<td colspan=2>
				<br/>
				<p class="flip" id="setting"><img src="../images/setting.png" width=14 height=14 border=none />
					&nbsp;Setting</p>
				
					<a href="#" id="b"><p class="flipS">Change password</p></a>
					<a href="<?php echo "loginRecord.php";?>" rel="facebox">
						<p class="flipS2">Login History</p></a>
					
				
			</td>
			</tr>
		<tr>
			<td colspan=2 align=center><br/><a href="../logout.php">Logout</a><br/><br/></td>
			</tr>
	</table>
<!---------------------------Change Password----------------------------->
<div id="over"> 
<div id="title">
	<table border=0 width=680>
	<tr>
		<td><span id="t"><b>Change Password</b></span></td>
		<td align=right><span id="close" >[ x ]</span></td>
		</tr>
	</table>
	</div> 
<div id="content"> 
<form name="form1" onsubmit="return finalCheck();" action="<?php echo"editing.php?user=$user";?>" method=post>
<br/>
<table cellpadding=8 cellspacing=3 width="80%" align=center>
<tr >
	<td class=menu align=center>Current	password:</td>
	<td class=menu2><input type="password" name=current onchange="checkCurrent(this.value)" id="old"/><div id="check"></div></td>
	</tr>
<tr >
	<td class=menu align=center>New	password:</td>
	<td class=menu2><input type="password" name=pass1 onchange="newPass(this.value,pass2.value)" id="new1"/><div id="new"></div></td>
	</tr>
<tr >
	<td class=menu align=center>Retype New password:</td>
	<td class=menu2><input type="password" name=pass2 onchange="confirm(pass1.value,this.value)" id="new2"/><div id="aaa"></div></td>
	</tr>
<tr>
	<td colspan=2><hr width=100%/>	</td>
	</tr>
<tr>
	<td colspan=2 align=center>
	<input type="button" value="Save Changes" onclick="finalCheck2(pass1.value);" />
	<input type="reset" value="Reset" onClick="empty()"></td>
	</tr>
</table>
</form>
</div> 
</div>
<!------End password-------> 
<script type="text/javascript">
function finalCheck2(pass){

var error = 0;

var div1 = document.getElementById("check");
var div2 = document.getElementById("new");
var div3 = document.getElementById("aaa");

if(div1.innerHTML!="OK"){
	document.form1.current.value="";	
	error++;
	alert('Please fill correct current password');
	return;
}

if(div2.innerHTML!="OK"){
	document.form1.pass1.value="";
	error++;
	alert('New password can not less than 3 character');
	return;
}

if(div3.innerHTML!="OK"){
	document.form1.pass2.value="";
	error++;
	alert('No match password with new password');
	return;
}

if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var ans=xmlhttp.responseText;
				alert("Change password Successful");
				document.getElementById('check').innerHTML="";
				document.getElementById('new').innerHTML="";
				document.getElementById('aaa').innerHTML="";
				document.getElementById('old').value="";
				document.getElementById('new1').value="";
				document.getElementById('new2').value="";
			}
		}
  
		xmlhttp.open('GET','editing.php?pass='+pass,true);

		xmlhttp.send();


}
function empty(){
document.getElementById("check").innerHTML="";
document.getElementById("new").innerHTML="";
document.getElementById("aaa").innerHTML="";

}

</script>