function initButtonsSignUp(){
if($("#btn_accept_sign_up").exists()){
initEventsFormSignUp();
$("#btn_accept_sign_up").click(function(e){
e.preventDefault();
hideMsgErrorSignUp();
if($("#termsOfService:checked").length > 0){
$("#error_sign_up_terms").slideUp(function(){
var inputs; //if company
if($("#comboUser:checked").length > 0){
inputs = getCompanyNormalInputsSingUp();
if ($("#lCode").val() == "") {
$("#lCode").val($("#lCode").attr('placeholder'));
}
} else {
inputs = getUserNormalInputsSingUp();
}
validate(inputs, getMailInputsSingUp(), getEncryptInputsSingUp(), getIqualInputsSingUp(), showMsgErrorSignUp, bbddErrorSignUp, '/base/php/scripts/register.php', bbddSuccesSignUp);
});
} else {
$("#error_sign_up_terms").slideDown();
}
});
}
}
//Detect Event Copy Paste
function initEventsFormSignUp(){
//$("#smail #rmail").bind('copy', function(e) {console.info('hi'); });
//$("input:text").bind('cut', function(e) { });
$("#rmail").bind('paste', function(e) { e.preventDefault(); });
$("#spass").bind('paste', function(e) { e.preventDefault(); });
$("#rpass").bind('paste', function(e) { e.preventDefault(); });
$("#fname").bind('paste', function(e) { e.preventDefault(); });
$("#lname").bind('paste', function(e) { e.preventDefault(); });
$("#comboUser").change(function(){
if($("#comboUser:checked").length > 0){
$("#fielSetCompany").slideDown();
} else {
$("#fielSetCompany").slideUp();
}
});
initComboboxesLocation();
//initComboboxLanguage();
//initComboboxCurrencies();
}
//Function Comboboxes
function initComboboxesLocation(){
//document.getElementById("comboCountry").disabled = true;
document.getElementById("comboProvince").disabled = true;
document.getElementById("comboTown").disabled = true;
//loadCountries();
$("#comboCountry").change(function() {
document.getElementById("comboTown").disabled = true;
$("#comboTown").empty();
$("#comboProvince").empty();
$("#comboTown").append($('').val("").html('Select town...'));
if($("#comboCountry").val() != '') {
$("#comboProvince").empty();
loadProvinces($("#comboCountry").val());
} else {
document.getElementById("comboProvince").disabled = true;
$("#comboProvince").append($('').val("").html('Select province...'));
}
});
$("#comboProvince").change(function() {
document.getElementById("comboTown").disabled = true;
$("#comboTown").empty();
if($("#comboProvince").val() != '') {
loadTowns($("#comboProvince").val());
} else {
$("#comboTown").append($('').val("").html('Select town...'));
}
});
}
//Contries_Functions
/*function loadCountries(){
sendRequest({}, '/base/php/omnilus/locations/getCountries.php', loadCountrieSucces, loadCountrieFail);
}
function loadCountrieSucces(data) {
$("#comboCountry").append($('').val("").html("Select Country..."));
$.each(data.countries, function(id, text) {
$("#comboCountry").append($('').val(text.id).html(text.name));
});
document.getElementById("comboCountry").disabled = false;
}
function loadCountrieFail() {
$("#comboProvince").append($('').val('').html("Fail load"));
}*/
//Provinces_Functions
function loadProvinces(idCountry){
var data = {};
data["countryId"] = idCountry;
sendRequest(data, '/base/models/provinces.php', loadProvincesSucces, loadProvincesFail);
}
function loadProvincesSucces(data) {
var text = 'Select province...';
$("#comboProvince").append($('').val("").html(text));
$.each(data.provinces, function(id, text) {
$("#comboProvince").append($('').val(text.id).html(text.name));
});
document.getElementById("comboProvince").disabled = false;
}
function loadProvincesFail() {
var text = 'Fail load';
$("#comboProvince").append($('').val('').html(text));
}
//Towns_Functions
function loadTowns(idProv){
var data = {};
data["provinceId"] = idProv;
sendRequest(data, '/base/models/towns.php', loadTownsSucces, loadTownsFail);
}
function loadTownsSucces(data) {
var text = 'Select town...';
$("#comboTown").append($('').val("").html(text));
$.each(data.towns, function(id, text) {
$("#comboTown").append($('').val(text.id).html(text.name));
});
document.getElementById("comboTown").disabled = false;
}
function loadTownsFail() {
var text = 'Fail load';
$("#comboTown").append($('').val("").html(text));
}
//Other functions
function validateNames(e, el) {
hideMsgErrorSignUp();
removeInvalid(el);
tecla = (document.all) ? e.keyCode : e.which;
if (tecla==8) return true;
patron =/[A-Za-zñ áéíóúÁÉÍÓÚüïÜÏàèìòùÀÈÌÒÙ]/;
te = String.fromCharCode(tecla);
return patron.test(te);
}
//Iputs
function getCompanyNormalInputsSingUp() {
return ["#fname", "#lname", "#smail", "#spass", "#lCode", "#cName", "#comboCountry", "#comboProvince", "#comboTown", "#comboLang", "#comboMetrics", "#comboUser", "#input_captcha", "#comboMoney"];
}
function getMailInputsSingUp() {
return ["#smail", "#rmail"];
}
function getEncryptInputsSingUp() {
return ["#spass", "#rpass"];
}
function getIqualInputsSingUp() {
return [["#smail", "#rmail"],["#spass", "#rpass"]];
}
function getUserNormalInputsSingUp() {
return ["#fname", "#lname", "#smail", "#spass", "#comboLang", "#comboUser", "#comboMetrics", "#input_captcha", "#comboMoney"];
}
//Show and hide errors
function showMsgErrorSignUp (){
$("#error_fields_sign_up").slideDown();
}
function hideMsgErrorSignUp() {
$("#error_fields_sign_up").slideUp();
$("#error_bbdd_sign_up").slideUp();
}
function bbddErrorSignUp(msg) {
deleteValue(["#input_captcha"]);
deleteValue(getEncryptInputsSingUp());
$("#text_error_bbdd_sign_up").html(msg);
$("#error_bbdd_sign_up").slideDown();
document.getElementById('captcha').src="/base/php/captcha/captcha.php?"+Math.random();
}
function msgSuccesSignUp(msg) {
$("#text_error_bbdd_sign_up").html(''+msg+'');
$("#error_bbdd_sign_up").slideDown();
}
function bbddSuccesSignUp () {
var user = $("#smail").val();
t = setTimeout(function(){ loadNextStep(user); }, 800);
msgSuccesSignUp('All right. Redirecting...');
}
function loadNextStep(user){
sendRequest(getData(["#smail", "#spass"]), '/base/php/scripts/access.php', bbddSuccesLoguin, bbddErrorSignUp);
}