
var MyAccount = {}
MyAccount.UserData = "";
MyAccount.ShowContent = function(UserData)
{
	MyAccount.UserData = UserData;
	var Data = MyAccount.MakeForm();
	document.getElementById("Content").innerHTML = Data;
}


MyAccount.MakeForm = function()
{

	UserData = MyAccount.UserData;
	UserData = UserData.split(";;;");
	
	var Html = "";
	
	Html = Html + "<h1 style='padding-left:20px;'>Change user info</h1>";
	
	Html = Html + "<form action='' method='post'/>";
	
	Html = Html + "<div style='text-align:left; padding-left:20px;'>";
	Html = Html + "<div style='margin-bottom:8px;margin-top:17px;' id='UserNameLabel'>";
	Html = Html + "Username:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='text' value='"+UserData[1]+"'  onfocus=\"SignForm.FieldClear('UserName');\" style='width:270px;padding:2px;font-size:16px;' id='UserName' name='username' autocorrect='off' autocapitalize='off' placeholder='Username'/>";
	Html = Html + "</div>";
	
	
	Html = Html + "<div class='label' id='EmailLabel' style=' margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Email:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='text' value='"+UserData[2]+"' onfocus=\"SignForm.FieldClear('Email');\" style='width:270px;padding:2px; border-color:#373737;  font-size:16px;' id='Email' name='email' autocorrect='off' autocapitalize='off' placeholder='Email'/>";
	Html = Html + "</div>";	
	
	Html = Html + "<div id='CountryLabel' class='label' style=' margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Country:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input  type='text' value='"+UserData[3]+"' onfocus=\"SignForm.FieldClear('Country');\" style='width:270px;padding:2px; border-color:#373737;  font-size:16px;' id='Country' name='country' autocorrect='off' autocapitalize='off' placeholder='Country'/>";
	Html = Html + "</div>";	

	Html = Html + "<div id='ZipCodeLabel' class='label' style=' border-color:#373737;  margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Zipcode:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='text' value='"+UserData[4]+"' onfocus=\"SignForm.FieldClear('ZipCode');\" style='width:270px;padding:2px; border-color:#373737; font-size:16px;' id='ZipCode' name='zipcode' autocorrect='off' autocapitalize='off' placeholder='Zipcode'/>";
	Html = Html + "</div>";

	Html = Html + "<div><img src='/images/btm_save.png' onclick=\"MyAccount.ChangeUserData('load'); return false;\" style='cursor:pointer; width:214px; height:37px; margin-top:6px;'/><div id='LostPasswordResult' style='color:#e50000;'></div></div>";			
	Html = Html + "<div style='color:#f60000; padding-top:4px; padding-left:3px; text-align:left;' id='ResultForm'></div>";	
	Html = Html + "</div>";
	Html = Html + "</form>";	
	
	
	// Password
	
	Html = Html + "<br/><br/><h1 style='padding-left:20px; '>Change password</h1>";
	
	Html = Html + "<form action='' method='post'/>";
	Html = Html + "<div style='text-align:left; padding-left:20px;'>";	
	Html = Html + "<div class='label' id='OldPasswordLabel' style=' margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Old password:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='password'  onfocus=\"SignForm.FieldClear('OldPassword');document.getElementById('ResultFormPassword').innerHTML ='';\"  style='width:270px;padding:2px;border-color:#373737;  font-size:16px;' id='OldPassword' name='password' autocorrect='off' autocapitalize='off' placeholder='Old password'/>";
	Html = Html + "</div>";
	
	Html = Html + "<div class='label' id='PasswordLabel' style=' margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Password:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='password'  onfocus=\"SignForm.FieldClear('Password'); document.getElementById('ResultFormPassword').innerHTML ='';\" style='width:270px;padding:2px;border-color:#373737;  font-size:16px;' id='Password' name='password' autocorrect='off' autocapitalize='off' placeholder='Password'/>";
	Html = Html + "</div>";
	
	Html = Html + "<div class='label' id='Password2Label' style=' margin-bottom:8px;  padding-right:120px; margin-top:17px;'>";
	Html = Html + "Confirm password:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='password' onfocus=\"SignForm.FieldClear('Password2'); document.getElementById('ResultFormPassword').innerHTML ='';\" style='width:270px;padding:2px; border-color:#373737;  font-size:16px;' id='Password2' name='password2' autocorrect='off' autocapitalize='off' placeholder='Confirm password'/>";
	Html = Html + "</div>";	

	Html = Html + "<div><img src='/images/btm_save.png' onclick=\"MyAccount.ChangePassword('load'); return false;\" style='cursor:pointer; width:214px; height:37px; margin-top:6px;'/><div id='LostPasswordResult' style='color:#e50000;'></div></div>";			
	Html = Html + "<div style='color:#f60000; padding-top:4px; padding-left:3px; text-align:left;' id='ResultFormPassword'></div>";	
	Html = Html + "</div>";
	Html = Html + "</form>";	
	return Html;
}


MyAccount.ChangePassword = function(Data)
{
	if(Data!="load")
	{
		document.getElementById("ResultFormPassword").innerHTML = Data;
		return false;
	}
	
	UserData = MyAccount.UserData;
	UserData = UserData.split(";;;");	


	var OldPass = document.getElementById("OldPassword").value;
	var Pass = document.getElementById("Password").value;
	var ConfPass = document.getElementById("Password2").value;
	var Stop = 0;
	if(OldPass=='')	{ SignForm.FieldInvalid("ResultFormPassword","OldPassword","Old password is invalid");	Stop ++; }
	if(Pass==''){		SignForm.FieldInvalid("ResultFormPassword","Password","New password is invalid");	Stop ++;	}		
	if(ConfPass==''){		SignForm.FieldInvalid("ResultFormPassword","Password2","Password confirmation is invalid");	Stop ++;	}		
	
	if(Stop>1)
		document.getElementById("ResultFormPassword").innerHTML = "You need to fill in all fields";
	if(Stop>0) return false;	

	OldPass = encodeURIComponent(OldPass);
	Pass = encodeURIComponent(Pass);
	ConfPass = encodeURIComponent(ConfPass);
	
	document.getElementById("ResultFormPassword").innerHTML = "Loading, please wait";
	
	post_data = "?ajax=2&Action=ChangeUserPassword&OldPassword="+OldPass+"&Password="+Pass+"&Password2="+ConfPass+"&UserId="+UserData[0];
	loadHTML("POST", "iphone.php", post_data, "MyAccount.ChangePassword(response)");	
}
MyAccount.ChangeUserData = function(Data)
{
	if(Data!="load")
	{
		document.getElementById("ResultForm").innerHTML = Data;
		return false;
	}
	UserData = MyAccount.UserData;
	UserData = UserData.split(";;;");
	
	var UserName = document.getElementById("UserName").value;
	var Email = document.getElementById("Email").value;
	var Country = document.getElementById("Country").value;
	var ZipCode = document.getElementById("ZipCode").value;
	Stop = 0;
	
	if(UserName=='')	{ SignForm.FieldInvalid("ResultForm","UserName","Username is invalid");	Stop ++; }
	if(Email==''){		SignForm.FieldInvalid("ResultForm","Email","Email is invalid");	Stop ++;	}		
	if(Country==''){		SignForm.FieldInvalid("ResultForm","Country","Country is invalid");	Stop ++;	}		
	if(ZipCode==''){		SignForm.FieldInvalid("ResultForm","ZipCode","Zipcode is invalid");	Stop ++;	}		
	
	Ok = 0;
	if(Email.match("@"))
	{
		Email2 = Email.split(".");
		if(Email2[1])
			Ok = 1;
		else 
			Ok = 0;
	}
	
	if(Ok == 0)
	{
		SignForm.FieldInvalid("Email","Email is invalid");		
		Stop++;
	}
	
	if(Stop>1)
		document.getElementById("ResultForm").innerHTML = "You need to fill in all fields";
	if(Stop>0) return false;
	
	
	UserName = encodeURIComponent(UserName);
	Country = encodeURIComponent(Country);
	ZipCode = encodeURIComponent(ZipCode);
	
	document.getElementById("ResultForm").innerHTML = "Loading, please wait";
	
	post_data = "?ajax=2&Action=ChangeUserData&UserName="+UserName+"&ZipCode="+ZipCode+"&Country="+Country+"&Email="+Email+"&UserId="+UserData[0];
	loadHTML("POST", "iphone.php", post_data, "MyAccount.ChangeUserData(response)");
}


