﻿// JScript File
function toggleInput(id , disable, imgId)
{
	document.getElementById(id).disabled=disable;
	if(disable == true)
		document.getElementById(id).style.backgroundColor = '#DEDEDD';
	else
	{
		document.getElementById(id).style.backgroundColor = 'white';
		document.getElementById(id).focus()
	}
	var img = document.getElementById(imgId);
    img.className = 'default';
} 

function  checkVagonItem(ddlId, spanId, txtId, imgId)
{
    var ddl = document.getElementById(ddlId);
    var span = document.getElementById(spanId);
    var txt = document.getElementById(txtId);
   
    var img = document.getElementById(imgId);
    if(ddl.options[ddl.selectedIndex].value == 'other')
    {
        span.style.display='block';
        txt.style.display='inline';
        img.className = 'default';
    }
    else
    {
        span.style.display='none';
        txt.style.display='none';
        img.className = 'default';
    }
}


function validateForm()
{
    var isFormValid = true;
    isFormValid = validateRequired('txtMarfa') && isFormValid;
    isFormValid = validateRequired('txtStatieIn') && isFormValid;
    isFormValid = validateRequired('txtStatieOut') && isFormValid;
    if(document.getElementById('radTeritoriuSpecific').checked) 
        isFormValid = validateRequired('txtCotatie') && isFormValid;
        
    if(document.getElementById('cbxVagon').options[document.getElementById('cbxVagon').selectedIndex].value == 'other')
        isFormValid = validateRequired('txtTipVagon') && isFormValid;
        
    isFormValid = validateRequired('txtNumeFirma') && isFormValid;
    isFormValid = validateRequired('txtTelefon') && isFormValid;
    isFormValid = validateRequired('txtPersoanaContact') && isFormValid;
    isFormValid = validateRequired('txtEmail') && isFormValid;
    
    if(!isFormValid)
        document.getElementById('errorNote').style.display='block';
    else
        document.getElementById('errorNote').style.display='none';
                
    return isFormValid;
}


function validateContactForm()
{
    var isFormValid = true;
    isFormValid = validateRequired('txtNume') && isFormValid;
    isFormValid = validateRequired('txtEmail') && isFormValid;
    isFormValid = validateRequired('txtTelefon') && isFormValid;
    isFormValid = validateRequired('txtMesaj') && isFormValid;
    
    if(!isFormValid)
        document.getElementById('errorNote').style.display='block';
    else
        document.getElementById('errorNote').style.display='none';
                
    return isFormValid;
}

function validateGuranteeForm()
{
    var isFormValid = true;
    isFormValid = validateRequired('txtMarfa') && isFormValid;
    isFormValid = validateRequired('txtStatieIn') && isFormValid;
    isFormValid = validateRequired('txtStatieOut') && isFormValid;
    isFormValid = validateRequired('txtValoare') && isFormValid;
        
    isFormValid = validateRequired('txtNumeFirma') && isFormValid;
    isFormValid = validateRequired('txtTelefon') && isFormValid;
    isFormValid = validateRequired('txtPersoanaContact') && isFormValid;
    isFormValid = validateRequired('txtEmail') && isFormValid;
    
    if(!isFormValid)
        document.getElementById('errorNote').style.display='block';
    else
        document.getElementById('errorNote').style.display='none';
                
    return isFormValid;
}

function validateRequired(ctrlId)
{
   var txt = document.getElementById(ctrlId);
   var img = document.getElementById('img_' + ctrlId);
   if(img == null)
   alert(ctrlId);
   if(txt.value == '')
   {
        img.className = 'incorrect';
        return false;
   }
   else
   {
        img.className = 'default';
        return true;
   }
}

function clearContactForm()
{
    document.getElementById('txtNume').value = '';
    document.getElementById('txtTelefon').value = '';
    document.getElementById('txtFax').value = '';
    document.getElementById('txtEmail').value = '';
    document.getElementById('txtMesaj').value = '';
}
