﻿function setSubmitDetail(sender, TargetHiddenField)
{
    var btn;
    btn = sender;

    //alert('sender: ' + sender);

    var postedenbtn;
    //postedenbtn = document.getElementById('PostEdenButon');
    //postedenbtn = TargetHiddenField;
    postedenbtn = document.getElementById(TargetHiddenField); 


    //alert('postedenbtn: ' + postedenbtn);
    
    var seciliAracTipi = document.getElementById('SeciliAracTipi');
    var marka = document.getElementById('Marka');
    var model = document.getElementById('Model');
    
    if( marka != null )
    {
        if(document.getElementById('MarkaAdi') != null)
            document.getElementById('MarkaAdi').value = marka.options[marka.selectedIndex].text;
    }
    
    if( model != null )
    {
        if(document.getElementById('ModelAdi') != null)
            document.getElementById('ModelAdi').value = model.options[model.selectedIndex].text;    
    }
    
    if ( seciliAracTipi != null)
    {
        if (document.getElementById('SeciliAracTipiAdi') != null) {
            if (seciliAracTipi.options != null)
                document.getElementById('SeciliAracTipiAdi').value = seciliAracTipi.options[seciliAracTipi.selectedIndex].text;
        }
    }

    postedenbtn.value = btn.id;   
}


function setSubmitDetailExt(sender, TargetHiddenField)
{
    var btn = sender;
    var postedenbtn;
   
    postedenbtn = document.getElementById(TargetHiddenField);
        
    if ( !isValidModelYil() )
    {
        return false;
    }
    
    if ( !isValidKM() )
    {
        return false;
    }
    
    if ( !isValidBG() )
    {
        return false;
    }
    
    if ( !isValidCC() )
    {
        return false;
    }
    
    if ( !isValidFiyat() )
    {
        return false;
    }

    //alert('postedenbtn: ' + postedenbtn);
    
    var seciliAracTipi = document.getElementById('SeciliAracTipi');
    var marka = document.getElementById('Marka');
    var model = document.getElementById('Model');
    
    if( marka != null )
    {
        if(document.getElementById('MarkaAdi') != null)
            document.getElementById('MarkaAdi').value = marka.options[marka.selectedIndex].text;
    }
    
    if( model != null )
    {
        if(document.getElementById('ModelAdi') != null)
            document.getElementById('ModelAdi').value = model.options[model.selectedIndex].text;    
    }
    
    if ( seciliAracTipi != null)
    {
        if (document.getElementById('SeciliAracTipiAdi') != null) {
            if (seciliAracTipi.options != null)
                document.getElementById('SeciliAracTipiAdi').value = seciliAracTipi.options[seciliAracTipi.selectedIndex].text;
        }
    }

    postedenbtn.value = btn.id;
    return true;
}


function setSubmitDetailDaraltma(sender, TargetHiddenField) {
    var btn = sender;

    var postedenbtn;
    postedenbtn = TargetHiddenField;
    
    if ( !isValidModelYil() )
    {
        return false;
    }
    
    if ( !isValidKM() )
    {
        return false;
    }
    
    if ( !isValidBG() )
    {
        return false;
    }
    
    if ( !isValidCC() )
    {
        return false;
    } 
    postedenbtn.value = btn.id;
    return true;
}

function clearOnFocus(sender,defaultText)
{
    var control;
    control = sender;
    
    if(control.value == defaultText)
    {
        control.value = '';
    }
}

function replaceOnBlur(sender,defaultText)
{
    var control;
    control = sender;
    
    if(control.value=='')
    {
        control.value = defaultText;
    }
}

function swapCheckBox(checkBoxName)
{
    var control;
    control = document.getElementById(checkBoxName);
   
    if (control.checked)
        control.checked = false;
    else
        control.checked = true;
}

function enableTargetDropDown(sourceDropDown, targetDropDown)
{
    var controlSource;
    controlSource = sourceDropDown

    var controlTarget;
    controlTarget = targetDropDown
   
    if (controlSource.options[controlSource.selectedIndex].value==-1)
        controlTarget.disabled = true;
    else
    {
        controlTarget.disabled = false;
    }
    controlTarget.selectedIndex = 0;
}

function enableDigerTextbox(sourceCheckBox, targetTextbox)
{
    var controlSource;
    controlSource = document.getElementById(sourceCheckBox);

    var controlTarget;
    controlTarget = document.getElementById(targetTextbox);

    //alert(controlSource.options[controlSource.selectedIndex].value);
    //alert(controlTarget.disabled);

    if (controlSource.checked)
    {
        controlTarget.disabled = false;
        controlTarget.focus();
    }
    else
    {
        controlTarget.disabled = true;
    }
}

function updateSelectedCheckBoxGroup(ChangedCheckBox,TargetHiddenField)
{
    //alert('');
    var control;
    control = document.getElementById(ChangedCheckBox);
    
    var hidden;
    hidden = document.getElementById(TargetHiddenField);
    
    var splitChar = '#';
    if (control.checked)
    {
        //Target Hidden field içine ekle...
        hidden.value += splitChar + control.value + splitChar;
    }
    else
    {
        //Target Hidden field içinden çıkart...
        var temp = hidden.value;
        hidden.value = temp.replace(splitChar + control.value + splitChar,'');
    }
}

function MM_openBrWindow(theURL,winName,features) 
{ 
    //v2.0
    //onclick="MM_openBrWindow('xxx.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=600,top=120,left=150')"
    window.open(theURL, winName, features);    
}

 function isValidModelYil()
{
    var alts = document.getElementById('YilAltSinir');
    var usts = document.getElementById('YilUsttSinir');
    
    if( alts != null && usts != null)
    {
        if(alts.value.length > 0 && usts.value.length > 0)
        {
            if(parseInt(alts.value) > parseInt(usts.value))
            {
                 alert('2. model yılı 1. model yılından büyük yada 1. ile 2. model yılı aynı olmalıdır.');  
                 return false;                       
            }
        }
    } 
    
    return true;
}

function isValidKM()
{
    var alts = document.getElementById('KmAltSinir');
    var usts = document.getElementById('KmUstSinir');
    
    if( alts != null && usts != null)
    {
        if(alts.value.length > 0 && usts.value.length > 0)
        {
            if(parseInt(alts.value) > parseInt(usts.value))
            {
                 alert('Araç KM aralığında ilk değer ikincisinden küçük olmalıdır.');
                 return false;
            }
        }
    }
    
    return true;
}

function isValidBG()
{
    var alts = document.getElementById('MotorGucuAltSinir');
    var usts = document.getElementById('MotorGucuUstSinir');
    
    if( alts != null && usts != null)
    {
        if(alts.value.length > 0 && usts.value.length > 0)
        {
            if(parseInt(alts.value) > parseInt(usts.value))
            {
                 alert('Motor gücü aralığında ilk değer ikincisinden küçük olmalıdır.');
                 return false;
            }
        }
    }   
    return true;
}

function isValidCC()
{
    var alts = document.getElementById('SilindirHacmiAltSinir');
    var usts = document.getElementById('SilindirHacmiUstSinir');
    
    if( alts != null && usts != null)
    {
        if(alts.value.length > 0 && usts.value.length > 0)
        {
            if(parseInt(alts.value) > parseInt(usts.value))
            {
                 alert('Silindir hacmi aralığında ilk değer ikincisinden küçük olmalıdır.');
                 return false;
            }
        }
    }
    
    return true;
} 

function isValidFiyat()
{
    var alts = document.getElementById('FiyatAltSinir');
    var usts = document.getElementById('FiyatUstSinir');
    
    if( alts != null && usts != null)
    {
        if(alts.value.length > 0 && usts.value.length > 0)
        {
            if(parseInt(alts.value) > parseInt(usts.value))
            {
                 alert('Fiyat aralığında ilk değer ikincisinden küçük olmalıdır.');
                 return false;
            }
        }
    }
    
    return true;
}     


