/// <summary>
/// Resets a field
/// </summary>
/// <param name="field">element id to reset</param>
function doReset(field)
{
	var elem;
	try
	{
		elem = document.getElementById(field);
		elem.value = "";
	}
	catch(e)
	{
	}
}


function cleanForm(form)
{
	var elem;
	try
	{
		elem = document.getElementById(form);
		elem.reset();
		var i;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i]);
    }
		
		
	}
	catch(e)
	{
	}
}

function authorityInterventionInit()
{
	if (document.getElementById('YesIntervention').checked)
	{
		document.getElementById('interventionRow').style.display = "";
		document.getElementById('RequiredStationValidator').enabled = true;
	}
	else
	{
		document.getElementById('interventionRow').style.display = "none";
		document.getElementById('RequiredStationValidator').enabled = false;
	}
}

function authorityInterventionShow()
{
	document.getElementById('interventionRow').style.display = "";
	document.getElementById('RequiredStationValidator').enabled = true;
}

function authorityInterventionHide()
{
	document.getElementById('interventionRow').style.display = "none";
	document.getElementById('RequiredStationValidator').enabled = false;
}

function mudaTerceiros() {
	var nterceiros = document.getElementById("ThirdPartyQuestionDDL").options[document.getElementById("ThirdPartyQuestionDDL").selectedIndex].value;
	var personTerc = "";
	var vehicleTerd = "";
	var emailValidator = "";
	var vehicleRegistrationValidator = "";
	
	//Coloca visiveis os nterceiros primeiros
	for (i=1;i<=nterceiros;i++)
	{
		personTerc = "tpp" + i;
		document.getElementById(personTerc).style.display = "";
		vehicleTerd = "tpv" + i;
		document.getElementById(vehicleTerd).style.display = "";
		
		emailValidator = "RegularEmailTP" + i + "Validator";
		document.getElementById(emailValidator).enabled = true;
		emailValidator = "RegularVehicleRegistrationTP" + i + "Validator";
		document.getElementById(emailValidator).enabled = true;
	}
	
	//Esconde o restante
	for (i=5;i>nterceiros;i--)
	{
		personTerc = "tpp" + i;
		document.getElementById(personTerc).style.display = "none";
		vehicleTerd = "tpv" + i;
		document.getElementById(vehicleTerd).style.display = "none";
		
		emailValidator = "RegularEmailTP" + i + "Validator";
		document.getElementById(emailValidator).enabled = false;
		emailValidator = "RegularVehicleRegistrationTP" + i + "Validator";
		document.getElementById(emailValidator).enabled = false;
	}
}


function validaData (source,arguments) {

	var checkstr = "0123456789";
	var Datevalue = "";
	var DateTemp = "";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	Datevalue = arguments.Value;
	
	/* Apaga todos os caracteres except0 0..9 */
	for (i = 0; i < Datevalue.length; i++) {
		if (checkstr.indexOf(Datevalue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + Datevalue.substr(i,1);
		}
	}

	Datevalue = DateTemp;
	if (Datevalue.length != 8) {
		  err = 1;
	}
   
	/* ano erro se for igual a 0000 */
	year = Datevalue.substr(4,4);
	if (year == 0) {
		err = 1;
	}
   
	/* validacao do mes */
	month = Datevalue.substr(2,2);
	if ((month < 1) || (month > 12)) {
		err = 1;
	}
	
	/* valicação do dia*/
	day = Datevalue.substr(0,2);
	if (day < 1) {
		err = 1;
	}

	/* valicação do mês de fevereiro (ano bissexto ou não) */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
		err = 1;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
		err = 1;
	}
	/* validação dos dias dos meses (30 ou 31) */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		err = 1;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		err = 1;
	}
	
	/* se não existe qualquer tipo de erro (err=0) a data é valida */
	if (err == 0) {
		arguments.IsValid = true;
	}
	/* data inválida */
	else {
		arguments.IsValid = false;
	}
}

function CheckMaskValue(maskControl, evt)
{
      var strText = maskControl.value;
      if ((evt.keyCode < 48) || (evt.keyCode > 57))
      {
            evt.keyCode = 0;
      }
}


