function changeDropoffAirport() {
	for(i=0;i<document.getElementById('drpPickUp_Airport').length;++i)
	if(document.getElementById('drpPickUp_Airport').options[i].selected == true)
	document.getElementById('drpDropoff_Airport').options[i].selected = true;
}
function changeDropoffCity() {
	for(i=0;i<document.getElementById('drpPickup_City').length;++i)
	if(document.getElementById('drpPickup_City').options[i].selected == true)
	document.getElementById('drpDropoff_City').options[i].selected = true;
}
function changeTime () {
	for(i=0;i<document.getElementById('drpPickup_Time').length;++i)
	if(document.getElementById('drpPickup_Time').options[i].selected == true)
	document.getElementById('drpDropoff_Time').options[i].selected = true;
}


function ChangePickup(id,c_dropoff_also) { // can  be removed

    //alert(id);

    var PCITY = document.getElementById('rowPickup_City');
    var DCITY = document.getElementById('rowDropOff_City');
    var PAIR = document.getElementById('rowPickUpAirport');
    var DAIR = document.getElementById('rowDropoffAirport');
    var radDropAir = document.getElementById('radDropOffType_0');
    var radDropCity = document.getElementById('radDropOffType_1');
    
    //alert(radDropAir);
    
    if(c_dropoff_also == true) {
        if(id == 1) { //city
            PCITY.style.display = "";
            DCITY.style.display = "";
            PAIR.style.display = "none";
            DAIR.style.display = "none";
            radDropAir.checked = false;
            radDropCity.checked = true;
        }
        if(id == 2) { //airport
            PCITY.style.display = "none";
            DCITY.style.display = "none";
            PAIR.style.display = "";
            DAIR.style.display = "";    
            radDropAir.checked = true;
            radDropCity.checked = false;            
        }    
    }
    if(c_dropoff_also == false) {
        if(id == 1) { //city
            DCITY.style.display = "";
            DAIR.style.display = "none";
        }
        if(id == 2) { //airport
            DCITY.style.display = "none";
            DAIR.style.display = "";    
        }    
    }
}

function addlist(listField,newText, newValue) {var len = listField.length++; listField.options[len].value = newValue; listField.options[len].text = newText;}
function fillDate() {

    var now = new Date();
    var PickUp = new Date();
    var DropOff = new Date();
    var PDay,DDay,PMonth,DMonth,PYear,DYear;
    
    var PickField = document.getElementById('txtPickupDate');
    var DropField = document.getElementById('txtDropOffDate');

    PickUp.setDate(now.getDate() + 7); 
    DropOff.setDate(now.getDate() + 21); 

    PDay = PickUp.getDate();
    DDay = DropOff.getDate();
    if(PDay < 10) { PDay = '0' + PDay}
    if(DDay < 10) { DDay = '0' + DDay}
    PMonth = PickUp.getMonth() + 1;
    DMonth = DropOff.getMonth() + 1;
    if(PMonth < 10) { PMonth = '0' + PMonth}
    if(DMonth < 10) { DMonth = '0' + DMonth}
    PYear = PickUp.getFullYear();
    DYear = DropOff.getFullYear();

    PickField.value = PDay + '.' + PMonth + '.' + PYear;
    DropField.value = DDay + '.' + DMonth + '.' + DYear;
    
    for (i = 0; i <= 23; i++) {
        for (j= 0; j <= 3; j++) {
        hour = i;
        minute = '' + 15 * j;
        if (j < 1) minute = '00';
        hour = hour +':' + minute;
        if (i <= 9) hour = '0' + hour; 
        addlist(document.getElementById('drpPickup_Time'),hour,hour);
        addlist(document.getElementById('drpDropoff_Time'),hour,hour);
        }
    }
    
    now = new Date();
    now.setHours(now.getHours());
    hour = now.getHours();
    document.getElementById('drpPickup_Time').options[48].selected = true;
    document.getElementById('drpDropoff_Time').options[48].selected = true;
}

function change_dropoff_date(id,value) {
    //alert(value);
    if(value.length != 10) {
        alert("Falsches Datumsformat. (TT.MM.JJJJ)");
        return false;
    }
    var Day = value.substr(0,2);
    var Month = value.substr(3,2);
    var Year = value.substr(6,4);
    
    var myDate = new Date();
    myLastYear = (eval(myDate.getFullYear()) + 2);
    
    if(Day < 1 || Day > 31) {
        alert("Falsches Datum!");
        return false;
    }
    if(Month < 1 || Month > 12) {
        alert("Falsches Datum!");
        return false; 
    }
    if(Year < myDate.getFullYear() || Year > myLastYear) {
        alert("Falsches Datum!");
        return false;
    }
    
    var PickUp = new Date();
    var DropOff = new Date();
    var DDay,DMonth,DYear;
    var PLimit = new Date();
    var DropField = document.getElementById('txtDropOffDate');

    PickUp.setTime(Date.parse(Month + '/' + Day + '/' + Year));
    DropOff = PickUp;

    DropOff.setDate(DropOff.getDate() + 7);

    if ($find("CalExDropOffDate") != null) {
        $find("CalExDropOffDate").set_selectedDate(DropOff);
    }

}

function changeNews(direction, count) {  

    var show = eval(document.getElementById('news_shown').value);
     
    if(direction == 'next') {
        if(show == (count -1)) {
            show = (count -1);
        }else {show = show + 1;}        
    }
    
    if(direction == 'previous') {
        if(show == 0) {
            show = 0;
        }else {show = show - 1;}        
    }    
    
    document.getElementById('news_shown').value = show;
    
    //alert(show);
    
    if(show > -1 && show < count) {
        for(i=0;i<count;++i) {
            var Item = document.getElementById('divNews'+i);
            var myItem = document.getElementById('divNews'+show);
            Item.style.display = "none";
            if(i==show) {
                myItem.style.display = "block";
            }
        }    
    }
}


// -------- customer saved 08/2009 ----------
function MNCustomerSaved(langId) {
    this.countries = [3, 1, 8, 9, 12, 13]; // list of country IDs we're getting the stats for
    this.speed = 9000; // how long to show one stat - in milliseconds
    
    this.$el = $("#CustomerSaved");
    this.langId = langId;
    
    this.responseObjSavings = null;
    
    this.responseObjStats = null;
    this.count = 0; // number of items in statistics response
    this.$statDivs = []; // empty array, later replaced by jQuery object; we need the length=0 property
    
    this.intervalPlay = null; // object returned by setInterval()
    this.currentPos = 0; // zero-based - cur. position when iterating
    
    this.start();
}


(function(C) {


	// start()
    C.prototype.start = function() {
        this.showCustomerSavings();
    }

    
    // showCustomerSavings()
    C.prototype.showCustomerSavings = function() {
		var thisRef = this;
        
        var getCustomerSavedCallBack = function(data) {
            thisRef.responseObjSavings = data;
            thisRef.$el.html(unescape("%3Cdiv class=\"displayNone customerSavings\"%3E") + data.d.Text + unescape("%3C/div%3E"));
            $("div.displayNone.customerSavings", thisRef.$el).fadeIn();
            setTimeout(function() {
                thisRef.showStats();
            }, thisRef.speed); // after x seconds show country stats
        }
        
        if (this.responseObjSavings == null) {
			// get them:
			var url = "webServices/WsCustomerSaved.asmx/getCustomerSaved?LanguageId=" + this.langId;
			$.ajax({
				url: url,
				type: "GET",
				dataType: "json",
				beforeSend: function(xhr) { xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); },
				contentType: "application/json; charset=utf-8",
				success: getCustomerSavedCallBack
			});
        } else {
			getCustomerSavedCallBack(this.responseObjSavings)
        }
    }
    
    
    // showStats()
    C.prototype.showStats = function() { // get stats and play them

        var thisRef = this;
        
        var getStatsCallBack = function(data) {
            thisRef.responseObjStats = data;
            var c = parseInt(data.d.Count, 10);
            if (isNaN(c)) c = 0;
            thisRef.count = c;
            if (c > 0) {
                thisRef.$el.html(data.d.Text);
                thisRef.$statDivs = $("div.DbStatisticDiv", thisRef.$el);
                thisRef.play();
            }
        }
        
        if (!this.responseObjStats) {
			var encodedCountries = escape("[" + this.countries.join(",") + "]");
			var url = "webServices/WsCustomerSaved.asmx/getDBStatistics?LanguageId=" + this.langId + "&myCountries=" + encodedCountries;
			
			$.ajax({
				url: url,
				type: "GET",
				dataType: "json",
				beforeSend: function(xhr) { xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); },
				contentType: "application/json; charset=utf-8",
				success: getStatsCallBack
			});
        } else {
			getStatsCallBack(this.responseObjStats)
        }
        
    }
    
    
    // play()
    C.prototype.play = function() { // iterate over the stats items (and show them)
        var thisRef = this;
        var i = 0;
        if (this.count > 0) {
            this.showStatNum(0);
            this.intervalPlay = setInterval(function() {
				if (thisRef.currentPos + 1 < thisRef.count) {
					thisRef.showNext();
				} else {
					thisRef.stop();
					thisRef.showCustomerSavings();
				}
            }, this.speed);
        }
    }
    
    
    // stop()
    C.prototype.stop = function() {
        clearInterval(this.intervalPlay);
    }
    
    
    // isIteratorValid()
    C.prototype.isIteratorValid = function(val) {
        if (this.count <= 0) return false;
        if (val >= 0 && val < this.count) return true;
        return false;
    }
    
    
    // getNextIterator()
    C.prototype.getNextIterator = function() {
        if (!this.count) return NaN;
        var nextPos = this.currentPos + 1;
        if (this.isIteratorValid(nextPos)) return nextPos;
        return 0;
    }
    
    
    // showNext()
    C.prototype.showNext = function() {
        var nextPos = this.getNextIterator();
        if (!isNaN(nextPos)) {
            this.showStatNum(nextPos);
        }
    }
    
    
    // showStatNum()
    C.prototype.showStatNum = function(num) { // = "show statistics number: num"; zero-based
        if (!this.isIteratorValid(num)) return false;
        this.currentPos = num;
        this.$statDivs.hide().eq(num).fadeIn();
    }
    
    C.run = function(langId) {
		var myLangId = langId;
		$().ready(function() {
			new C(myLangId);
		})
		
    }

})(MNCustomerSaved);