
/**
 * 
 * @param vStep
 * @return void
 */
function showStep ( vStep ) {
	
	var div = "divStep" + vStep;
	var divToolBar = "rrhh-btn-step" + vStep;
	
	// set the new step
	document.getElementById("step").value = vStep;
	
	// First hide all
	document.getElementById("divStep1").style.display = "none";
	document.getElementById("divStep2").style.display = "none";
	document.getElementById("divStep3").style.display = "none";
	document.getElementById("divStep4").style.display = "none";
	document.getElementById("divStep5").style.display = "none";
	
	document.getElementById("rrhh-btn-step1").className = "rrhh-step-button-over";
	document.getElementById("rrhh-btn-step2").className = "rrhh-step-button-over";
	document.getElementById("rrhh-btn-step3").className = "rrhh-step-button-over";
	document.getElementById("rrhh-btn-step4").className = "rrhh-step-button-over";
	document.getElementById("rrhh-btn-step5").className = "rrhh-step-button-over";
	
	document.getElementById(div).style.display = "";
	document.getElementById(divToolBar).className = "rrhh-step-button";
	
}

/**
 * 
 * @return void
 */
function validateApplicantData ( ) {
	
	var err = "";
	
	if ( document.getElementById("nationality").value.length < 3 ) err = err + "* Debe especificar una nacionalidad válida. \n";
	
	if ( document.getElementById("birth_day").value == 0 || 
			document.getElementById("birth_month").value == 0 || 
			document.getElementById("birth_year").value == 0 ) {
		err = err + "* Debe especificar una fecha de nacimiento válida. \n";
	}
	
	if ( document.getElementById("gender").value == 0 ) err = err + "* Debe especificar su genero. \n";

	if ( document.getElementById("marital_status").value == 0 ) err = err + "* Debe especificar su estado civil. \n";

	if ( document.getElementById("address").value.length < 5 ) err = err + "* Debe especificar un domicilio válido. \n";

	if ( document.getElementById("zip_code").value.length < 3 ) err = err + "* Debe especificar un código postal válido. \n";
	
	if ( document.getElementById("state_id").value == 0 ) err = err + "* Debe especificar una provincia. \n";
	
	if ( document.getElementById("city_id").value == 0 ) err = err + "* Debe especificar una localidad válida. \n";	
	
	if ( document.getElementById("phone_home").value =="" && document.getElementById("phone_mobile").value == "" ) {
		err = err + "* Debe especificar al menos un número de teléfono. \n";
	}
	
	if ( document.getElementById("picture").value != "" && ! checkPhoto() ) {
		err = err + "* El tipo de foto no es válido. Solo puede utilizar imagenes JPG. \n";
	}
	
	if ( err == "" ) {
		document.frmApplicantData.submit();
	} else {
		alert ( err );
	}
	
}

/**
 * 
 * @return boolean
 */
function checkPhoto() {
	
	 var imagePath = document.getElementById("picture").value;
	 var pathLength = imagePath.length;
	 var lastDot = imagePath.lastIndexOf(".");
	 var fileType = imagePath.substring(lastDot,pathLength);
	 if( (fileType == ".jpg") || (fileType == ".jpeg") ) {
	  return true;
	 } else {
	  return false;
	 }
}


/**
 * 
 * @param object element
 * @return void
 */
function fad ( e ) {
	
	//element.class = "rrhh-btn-over";
	document.getElementById(e).className = "rrhh-btn-over";
	
}

/**
 * 
 * @param object element
 * @return void
 */
function foc ( e ) {
	
	document.getElementById(e).className = "rrhh-btn";
	
}

/**
 * 
 * @param object element
 * @return void
 */
function fadToolbar ( e ) {
	
	//element.class = "rrhh-btn-over";
	document.getElementById(e).className = "rrhh-step-button-over";
	
}

/**
 * 
 * @param object element
 * @return void
 */
function focToolbar ( e ) {
	
	document.getElementById(e).className = "rrhh-step-button";
	
}

/**
 * returns true of the key pressed on hte evnt is a numeric key
 * @param event
 * @return bool
 */
function is_numeric_key(event)
{

	var charCode = (event.which) ? event.which : event.keyCode

	if (charCode < 48 || charCode > 57){
		if (charCode == 8){
			return true;
		}
		alert( 'Solo puede ingresar valores numéricos.' )
		return false;
	}
	return true;
}



function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

// Populates the country selected with the counties from the country list

/**
 * @param string defaultState
 * @param string id
 * @param string lang
 */
function populateState(defaultState, idStateSel, lang) {
 
  var StateLineArray = State.split('|');  // Split into lines
  var selObj = document.getElementById(idStateSel);
  if(lang == 'sp') {
  	selObj.options[0] = new Option('Seleccione una Provincia','');
  } else {
  	selObj.options[0] = new Option('Select State','');
  }
  
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < StateLineArray.length; loop++) {
    lineArray = StateLineArray[loop].split(':');
    StateCode  = TrimString(lineArray[0]);
    StateName  = TrimString(lineArray[1]);
    if ( StateCode != '' ) {
      selObj.options[loop + 1] = new Option(StateName, StateCode);
    }
    if ( defaultState == StateCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
  
}


/**
 * @param string idStateSel
 * @param string idCitySel
 */
function populateCity(idStateSel, idCitySel, lang, defaultState, defaultCity) {
  var selObj = document.getElementById(idCitySel);
  selObj.style.display = '';
  var foundCity = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    if(lang == 'sp') {
    	selObj.options[0] = new Option('Seleccione una Ciudad','');
    } else {
    	selObj.options[0] = new Option('Select City','');
    }
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with Citys from the selected State
  var CityLineArray = City.split("|");  // Split into lines
  var optionCntr = 1;
  for (var loop = 0; loop < CityLineArray.length; loop++) {
    lineArray = CityLineArray[loop].split(":");
    StateCode  = TrimString(lineArray[0]);
    CityCode    = TrimString(lineArray[1]);
    CityName    = TrimString(lineArray[2]);
  if (document.getElementById(idStateSel).value == StateCode && StateCode != '' ) {
      if ( CityCode != '' ) {
        selObj.options[optionCntr] = new Option(CityName, CityCode);
      }
      // See if it's selected from a previous post
      if ( CityCode == defaultCity && StateCode == defaultState ) {
        selObj.selectedIndex = optionCntr;
      }
      foundCity = true;
      optionCntr++;
    }
  }
}


function show_div( div ) {

	document.getElementById( div ).style.display = "";

}

function hide_div( div ) {
	
	document.getElementById( div ).style.display = "none";
	
}

