

if(typeof com == "undefined")
{
	com = function(){};
}

if(typeof com.ixonos == "undefined")
{
	com.ixonos = function(){};
}

//package name
com.ixonos.changePIN = function(){};


com.ixonos.changePIN.onDeviceReady = function()
{
	//com.ixonos.fsc.addAjaxSend();
	com.ixonos.fsc.initBottomBar("");
	com.ixonos.changePIN.initHtml();
	com.ixonos.changePIN.bindEvent();
	
	fromTop= $(".changePINText")[0].offsetTop;
	fromLeft=$(".changePINText")[0].offsetLeft;
	height= $(".changePINText")[0].offsetHeight;
	width= $(".changePINText")[0].offsetWidth;
	
	$('.changePINTextFrame').css("position","absolute");
	$('.changePINTextFrame').css("top",fromTop);
	$('.changePINTextFrame').css("height",height);
	$('.changePINTextFrame').css("width",width);
	$('.changePINTextFrame').css("left",fromLeft);
	$('.changePINTextFrame').css("display","block");
	
	com.ixonos.fsc.addCover($('.changePINTextFrame')[0], $(".changePINText")[0]);
	
};

com.ixonos.changePIN.initHtml = function()
{
	
	//initialize morepage 
	
	html = '';
	html += '<div class="titleBar">';
	html +=		'<div class="logo"><img src="img/navigation/logo-header.png"/></div>';
	html +=		'<a class="deleteShadowButton"><div class="cancelButton">' + public.cancelText + '</div></a>';
	html +=		'<a class="deleteShadowButton"><div class="doneButton">' + public.doneText + '</div></a>';
	html +=	'</div>';
	//html += '<div class="subTitle">' + changePIN.subTitle + '</div>';
	html += '<div class="subTitle">' + changePIN.subTitleTips + '</div>';
	
	html += '<div class="changePINContent">';
	html +=   '<div class="changePINTips">' + changePIN.changePINTips + '</div>';
//	html +=   '<input type="text" class="changePINText" onblur="com.ixonos.fsc.moveToOriginal()"></input>';
	html +=   '<input type="password" class="changePINText" maxlength="20" onblur="com.ixonos.fsc.moveToOriginal()"></input>';
	html += '<div class="changePINTextFrame"></div>';
	html += '</div>';
	//html += 'about me content';
	
	$('#changePINPage').append(html);
	
};

com.ixonos.changePIN.bindEvent =  function()
{
	$('.cancelButton').click(function()
							 {
							 loadPage("html/editAccount.html","com.ixonos.editAccount.onDeviceReady");
							 
							 });
	$('.doneButton').click(function(){
						   var url = server.serverIp + "rest/memberServer/changePassword";
						   var pinStr, memberId; 
						   memberId = window.localStorage.getItem(loginUser.memberId);
						   pinStr = $('.changePINText').val();
						   
						   if(pinStr == "")
						   {
						   com.ixonos.fsc.alert(changePIN.nullPin, function(){}, public.messageTitle, public.okText);
						   }
						   else if(pinStr.length < 4)
						   {
						   com.ixonos.fsc.alert(register.statusPwToEasy,function(){},login.registerInfoText);
						   }
						   else
						   {
						   com.ixonos.fsc.loadPage("changePIN", 1);
						   $.getJSON(url,{currentMemberId:memberId, currentPin: pinStr},function(string){
									 
									 if(typeof string.status == 'undefined')
									 {com.ixonos.fsc.serverErrorAlert();}
									 else if(string.status == -100)
									 {
									 com.ixonos.fsc.requestHeaderError();
									 }
									 else
									 {
									 switch(string.status)
									 {
									 case 1:
									 loadPage("html/editAccount.html","com.ixonos.editAccount.onDeviceReady");
									 break;
									 case 2:
									 com.ixonos.fsc.alert(changePIN.status2, function(){}, public.messageTitle, public.okText);
									 break;
									 case 4:
									 com.ixonos.fsc.alert(changePIN.nullPin, function(){}, public.messageTitle, public.okText);
									 break;
									 case 3:
									 case 7:
									 com.ixonos.fsc.alert(changePIN.status3, function(){}, public.messageTitle, public.okText);
									 break;
									 default:
									 com.ixonos.fsc.serverErrorAlert();
									 break;
									 }}
									  com.ixonos.fsc.removeLoadPage();	
									 });
						   }
						   });
};


