var currentPage = 'anasayfa';
var containerWidth = 900;
var _marginLeft = 30;
var solSlideTimeout = 5000;
var sagSlideTimeout = 5000;
var s_anasayfa=0;
var s_tesislerimiz=1;
var s_kalitemiz = 2;
var s_urunlerimiz = 3;
var s_pompa_fiyatlari=4;
var s_bayilerimiz = 5;
var s_hakkimizda = 6;
var s_iletisim = 7;
var s_musteri_hizmetleri=8;
var locked = false;
var showEuro = true;

$(document).ready(function() {
    $(document).pngFix();
    BindBayiResim();
    EuroSlide();
    var mersin = $('.tesis1').html();
    var elisa = $('.tesis10').html();
    var mersinEN = $('.tesis7').html();
    var elisaEN = $('.tesis13').html();
    $('.tesis1').html(mersin + '<br/><br/>' + elisa + '<br/><br/>');
    $('.tesis7').html(mersinEN + '<br/><br/>' + elisaEN + '<br/><br/>');
});

function PompaFiyatlari(guncel) {
    if (guncel) {
        $('#pf_guncel').show();
        $('#pf_arsiv').hide();
    }
    else {
        $('#pf_guncel').hide();
        $('#pf_arsiv').show();
    }
}

function EuroSlide() {
    if (showEuro) {
        showEuro = false;
        $('div.euro').animate({
            marginTop: -20,
            opacity: 0
        }, 500, function() {
            $('div.dolar').css({ 'marginTop': '20px', 'opacity': '0' }).animate({
                marginTop: 0,
                opacity: 1
            }, 500);
        });
        
    }
    else {
        showEuro = true;
        $('div.dolar').css({ 'marginTop': '0px', 'opacity': '1' }).animate({
            marginTop: -20,
            opacity: 0
        }, 500, function() { 
            $('div.euro').css({ 'marginTop': '20px', 'opacity': '0' }).animate({
                marginTop: 0,
                opacity: 1
            }, 500);
        });
        
    }
    setTimeout('EuroSlide()', 5000);
}

function BindBayiResim() {
    $('.gridBayi a').each(function() {
        $(this).lightBox();
    });
}

function GetContent(c1,c2){
    $(c1).html($(c2).html());
    $('#tesislerimiz .text .gallery a').lightBox();
}

function GetPage(id){
	if(currentPage==id)	return;
	if(locked) return;
	locked = true;
	
	var sCurrent=0;
	var sNew=0;
	
	sCurrent = eval('s_'+currentPage);
	sNew = eval('s_'+id);
		
	var content1First = _marginLeft;
	var content1Second = _marginLeft - screen.width;
	var content2First = _marginLeft + screen.width;
	var content2Second = _marginLeft;
	
	if(sCurrent>sNew)
	{
		content1First = _marginLeft; 
		content1Second = _marginLeft + screen.width;
		content2First = _marginLeft - screen.width;
		content2Second = _marginLeft;
	}
	
	$('#'+currentPage).show().css({'marginLeft':content1First+'px'});
	$('#'+id).show().css({'marginLeft':content2First+'px'});
	
	$('#'+currentPage).animate({
		marginLeft: content1Second + "px"
	},800)
	$('#'+id).animate({
		marginLeft:content2Second + "px"
	},800, function() {
		$('#'+currentPage).hide();
		currentPage = id;
		locked = false;
	})
	
	if(id == 'hakkimizda')
	    GetContent('#hakkimizda .text', '.hiddenContent .hakkimizda');

	if (id == 'tesislerimiz') {
	    var funcName = $('#tesislerimiz .header a:eq(0)').attr('href').replace('javascript:', '');
	    eval(funcName);
	}

	if (id == 'musteri_hizmetleri') {
	    MHTemizle();
	    $('#MusteriHizmetleri1_lblMHFormMessage').hide();
	    $('#MusteriHizmetleri1_pnlMHForm').show();
	    $('#MusteriHizmetleri1_UpdateProgress1_pnl1').css('marginTop', '-35px');
	}

	if (id == 'bayilerimiz') {
	    BindBayiResim();
	}
	    
	if (id == 'kalitemiz') {
	    GetContent('#kalitemiz .text', '.hiddenContent .kalitepolitikamiz');
	}

	if (id == 'pompa_fiyatlari') {
	    PompaFiyatlari(1);
	}
}

function CheckDecimal(sender, e) {
    var c = e.keyCode;

    var value = sender.value;

    var length = value.length;

    var virgulKonum = value.indexOf(',');

    var virgulVar = virgulKonum != -1;

    var precision = virgulVar ? value.substr(0, virgulKonum) : value;

    var precisionLength = precision.length;

    var scale = virgulVar ? value.substr(virgulKonum + 1) : '';

    var scaleLength = scale.length;

    var bos = value == '';

    var numeric = (c > 47 && c < 58) || (c > 95 && c < 106);

    var virgul = (c == 110 || c == 188);

    var izinVerilenler = numeric || c == 8 || c == 9 || c == 16 || c == 17 || c == 37 || c == 39 || c == 46 || virgul;

    if (!izinVerilenler)
        e.returnValue = 0;

    if (virgul && (virgulVar || bos))
        e.returnValue = 0;

    if (virgul && precisionLength > 16)
        e.returnValue = 0;

    if (numeric && virgulVar && virgulKonum < length - 2)
        e.returnValue = 0;

    if (!virgulVar && numeric && precisionLength == 16)
        e.returnValue = 0;

    if (virgulVar && numeric && precisionLength + scaleLength == 18)
        e.returnValue = 0;
}

function MHTemizle() {
    $('.form input').val('');
    $('.form textarea').val('');
}

function MHReset(a) {
    if (a == 1) {
        MHTemizle();
        $('.form').show();
        $('#MusteriHizmetleri1_lblMHFormMessage').hide();
    }
    else {
        setTimeout('MHReset(1)', 5000);
    }
}

function IKTemizle() {
    $('.form :input').each(function() {
        switch (this.type) {
            case 'password':
            case 'select-multiple':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
                break;
            case 'select-one':
                this.selectedIndex = 0;
        }
    });
    $('#ddlIKYil')[0].selectedIndex = 82;
    $('.form textarea').val('');
}

function IKReset(a) {
    if (a == 1) {
        IKTemizle();
        $('#pnlIKForm').show();
        $('#lblIKMesaj').hide();
    }
    else {
        setTimeout('IKReset(1)', 5000);
    }
}

function IKFormIsValid() {
    var _isvalid = true;
    var hata = "";
    var re = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    
    $('#txtIKAdSoyad_Validation').hide();
    $('#txtIKEmail_Validation').hide();
    $('#txtIKTelefon_Validation').hide();
    $('#txtIKCepTelefonu_Validation').hide();
    $('#txtIKAdres_Validation').hide();
    if ($('#ikform1_txtIKAdSoyad').val() == '') {
        $('#txtIKAdSoyad_Validation').show();
        _isvalid = false;
        hata += "Ad Soyad belirtilmedi\n";
    }
    if ($('#ikform1_txtIKEmail').val() == '') {
        $('#txtIKEmail_Validation').show();
        _isvalid = false;
        hata += "E-Posta belirtilmedi\n";
    }
    else if (!re.test($('#ikform1_txtIKEmail').val())) {
        $('#txtIKEmail_Validation').show();
        _isvalid = false;
        hata += "Email adresi hatalı\n";
    }
    if ($('#ikform1_txtIKTelefon').val() == '') {
        $('#txtIKTelefon_Validation').show();
        _isvalid = false;
        hata += "Telefon belirtilmedi\n";
    }
    if ($('#ikform1_txtIKAdres').val() == '') {
        $('#txtIKAdres_Validation').show();
        _isvalid = false;
        hata += "Adres belirtilmedi\n";
    }
    if (!_isvalid)
        alert(hata);
        
    return _isvalid;
}

function IKForm() {
    window.open('IK.aspx', 'IK', 'width=900,height=600,scrollbars=1,resizable=1');
    return 0;
}

function HRForm() {
    window.open('HR.aspx', 'IK', 'width=900,height=600,scrollbars=1,resizable=1');
    return 0;
}

function BBForm() {
    window.open('BayiBasvuruFormu.aspx', 'BB', 'width=750,height=600,scrollbars=1,resizable=1');
    return 0;
}

function Kur(id) {
    $('.usd').hide();
    $('.euro1').hide();
    $('.petrol').hide();
    $('.' + id).show();
}

function BottomSize() {
    var _winheight = $(window).height();
    if (_winheight < 650) {
        var diff = 650 - _winheight;
        if (diff > 55)
            diff = 55;
        var _h = 489 - diff;
        if (diff > 19) {
            $('.logo').hide();
            _h += 35;
        }
        else {
            $('.logo').show();
        }
        $('tr.main_center').css('height', _h + 'px');
    }
    else {
        $('.logo').show();
        $('html,body').css('overflow', 'hidden');
    }
}
