
var SignForm={}

SignForm.Show = function()
{
	Html = "";
	Html = Html + "<form action='' method='post' onsubmit=\"SignForm.Register(); return false;\"/>";
	
	Html = Html + "<div style='text-align:left; padding-left:20px;'>";
	Html = Html + "<div style='margin-bottom:8px;' id='UserNameLabel'>";
	Html = Html + "Username:";
	Html = Html + "</div>";
	Html = Html + "<div>";
	Html = Html + "<input type='text'  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='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');\" 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');\" 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 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' 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' 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' 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/signup.png' onclick='SignForm.Register(); 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 style='margin-top:5px; text-align:left;'>This is a free trial account for 7 days</div>";
	Html = Html + "</div>";
	Html = Html + "</form>";
	
	document.getElementById("Content").innerHTML = Html;
	
	var chx = new IPhoneCheckboxes();


}

SignForm.FieldInvalid = function(ResultDiv,Id,Message)
{
	document.getElementById(Id).style.borderColor="#f60000";
	//document.getElementById(Id+"Label").style.color="#f60000";
	document.getElementById(ResultDiv).innerHTML = Message;
}

SignForm.FieldClear = function(Id)
{
	document.getElementById(Id).style.borderColor="#373737";
	document.getElementById(Id+"Label").style.color="#fff";
	document.getElementById("ResultForm").innerHTML = '';
}

SignForm.Register = function()
{
	var UserName = document.getElementById("UserName").value;
	var Email = document.getElementById("Email").value;
	var Password = document.getElementById("Password").value;
	var Password2 = document.getElementById("Password2").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(Password==''){		SignForm.FieldInvalid("ResultForm","Password","Password is invalid");	Stop ++;	}		
	if(Password2==''){		SignForm.FieldInvalid("ResultForm","Password2","Password is not confirmed");	Stop ++;	}		
	if(Password2!=Password){		SignForm.FieldInvalid("ResultForm","Password2","Password is not confirmed");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("ResultForm","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);
	Password = encodeURIComponent(Password);
	Country = encodeURIComponent(Country);
	ZipCode = encodeURIComponent(ZipCode);
	
	document.getElementById("ResultForm").innerHTML = "Loading, please wait";
	
	post_data = "?ajax=2&Action=ReisterUser&UserName="+UserName+"&Password="+Password+"&ZipCode="+ZipCode+"&Country="+Country+"&Email="+Email;
	loadHTML("POST", "iphone.php", post_data, "SignForm.SignUpResult(response)");
}



SignForm.SignUpResult = function(Data)
{
	document.getElementById("ResultForm").innerHTML = "";
	if(Data=="Username")
		SignForm.FieldInvalid("ResultForm","UserName","Username exists in database");
	if(Data=="Email")
		SignForm.FieldInvalid("ResultForm","Email","Email exists in database");
	if(Data=="1")
		CallbackExecuteJavascript('ShowLogin');
		
}

