function init(){
	f = document.signup;
	
	if (f){
	
		changeInputType($('pw'),'text','Entre 6 y 16 caracteres',false,true); // prepare to change the password input type
		
		//f.loginName.onchange = writeToURL; // synchronize activity between login input and custom URL
		
		if (f.birthDate.value){ // Checking for submitting birthdate and make the selects to go those options
			dob = f.birthDate.value.split('/');
			if (dob.length == 3){
				_m = dob[0]; _d = dob[1]; _y = dob[2];
				_bdm = f.bdMonth; _bdd = f.bdDate; _bdy = f.bdYear;
				jumpToOpt(_bdm, _m); jumpToOpt(_bdd, _d); //jumpToOpt(_bdy, _y);
				_bdy.value = _y;
			}
		}
	
	}
	
}

function jumpToOpt(sel, v){
	for (i = 0; i < sel.length; i++) {
		if (sel.options[i].value == v) sel.options[i].selected = true;
	}
}

function signupContinue(){
	f = document.signup;
	formValidate(f);
}

function formValidate(f){
	if (!checkEmail(f)){ return promptError(f.email,'El email es inválido o las direcciones no corresponden. Por favor intenta de nuevo.'); }
	else if (f.loginName.value == ''){ return promptError(f.loginName, 'Por favor elige la dirección para tu página.') }
	else if ($('pw').value == '' || $('pw').value == 'Entre 6 y 16 caracteres'){ return promptError($('pw'),'Por favor elige tu password.'); }
	else if (f.passwordConfirm.value == ''){ return promptError(f.passwordConfirm,'Por favor ingresa tu password nuevamente para confirmar.'); }
	else if ($('pw').value != f.passwordConfirm.value){ return promptError($('pw'),'Los passwords no coinciden, por favor intenta de nuevo.'); }
	else if (f.displayName.value == ''){ return promptError(f.displayName,'Por favor ingresa el nombre de tu Banda.'); }
	else if (f.city.value == ''){ return promptError(f.city,'Por favor, ingresa tu ciudad.'); }
	else if (f.countryId.value == ''){ return promptError(f.countryId,'Por favor selecciona tu país.'); }
	else if (!checkBirthDate(f)){ return promptError(f.bdMonth,'Por favor selecciona tu fecha de nacimiento.'); }
	else if (!f.agreeToTerms.checked){ return promptError(f.agreeToTerms,'Debes estar de acuerdo con nuestros términos y condiciones para continuar.');}
	//else if ($('bandPhoto').value == ''){ return promptError($('bandPhoto'),'Please upload a band photo.');}
	else{ 
		f.displayName.value = charConversion(f.displayName.value);
		f.submit();
	}

}

function promptError(field,msg){
	alert(msg);
	//olGeneral.populate("<div id=\"overlayContainer\"><strong>"+msg+"</strong></div>");
	//olGeneral.show(false);
	//scroll(0,0);
	field.focus();
	return false;
}
function checkBirthDate(f){
	_m = f.bdMonth.options[f.bdMonth.selectedIndex].value;
	_d = f.bdDate.options[f.bdDate.selectedIndex].value;
	//_y = f.bdYear.options[f.bdYear.selectedIndex].value;
	_y = f.bdYear.value;
	
	if (_y == '' || isNaN(parseInt(_y)) || parseInt(_y) < 1900 ) _y = false;
	
	if (_m!='none' && _d!='none' && _y){
		f.birthDate.value = _m + '/' + _d + '/' + _y;
		return true;
	}
	else
		return false;
}

function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

function changeInputType2(){
  var allowInputTypeChange = true;
  var fld1 = $('pw');
  if(document.getElementById) {
    try { // to keep IE from showing errors.
      fld1.type = 'text';
      if(fld1.type == 'text') fld1.value = 'password';
      else allowInputTypeChange = false;
    } catch(e) { allowInputTypeChange = false; }
  }
  if(allowInputTypeChange) {
    fld1.onfocus = function() {
      var tempVal = this.value; // NS6 fix.
      var iType = this.type; // Opera 7 fix.
      if(this.type != 'password') this.type = 'password';
      this.value = tempVal; // NS6 fix.
      if(this.value.toLowerCase()=='password')
        this.value = '';
      if(window.opera && iType != 'password') this.focus();
    }
    fld1.onblur = function() {
      if(this.type == 'password')
      if(this.value=='' || this.value.toLowerCase()=='password') {
        this.type = 'text';
        this.value = 'password';
      }
    }
  }
}


function writeToURL(){
	$('acctBandURL').innerHTML = document.signup.loginName.value;
}