this.getPage = function(page) {
    var pageName = '';

    switch (detail) {
        case 'zielgebiet':
            pageName = 'destination';
            break;
        case 'hotel':
            pageName = 'hotel';
            break;
        case 'termine':
            pageName = 'disponibilites';
            break;
        case 'buchung':
            pageName = 'reservation';
            break;
        //        case 'zahlung': 
        //            pageName = 'paiement'; 
        //            break; 
        //        case 'confirm': 
        //            pageName = 'confirmation'; 
        //            break; 
    }
    return pageName;
};


this.getBookingPath = function(port) {
    var bookingPath = '';

    switch (port) {
        case '650':
            bookingPath = 'derniere minute';
            break;
        case '651':
            bookingPath = 'loisirs';
            break;
        case '652':
            bookingPath = 'vols secs';
            break;
        case '653':
            bookingPath = 'hotel';
            break;
        case '654':
            bookingPath = 'sejour';
            break;
        case '655':
            bookingPath = 'locatif';
            break;
    }
    return bookingPath;
};

this.getMagic = function(str) {
    //alert(str);
};



this.getDestStats = function(customer, page,port,destination, departAirport, date, ttdays, duration, adults, child1, child2, child3, board, stars, roomtype, activity, to) {

    if (valeur == 1) {

        var wysi_page = getPage(page);
        var wysi_bookingpath = getBookingPath(port);
        var wysi_destination = getDest(destination);
        var wysi_from_airport = getValueFromArray(departAirport, TTAFH); //getAirportName(departAirport);
        var wysi_date = date;
        var wysi_flexibility = getValueFromArray(ttdays, optttdays);
        var wysi_duration = getValueFromArray(duration, TCoptDauer);
        var wysi_nbadults = getArrayLength(adults);
        var wysi_child_1_age = child1;
        var wysi_child_2_age = child2;
        var wysi_child_3_age = child3;
        var wysi_board = getValueFromArray(board, optVerpflegung); //board;
        var wysi_stars = getStarsInt(stars); //stars;
		var wysi_roomtype = '';
		//if (roomtype.count() > 0) {
		if (roomtype.length > 0) {
			wysi_roomtype = getArrayDefinedValue(roomtype, optZimmer); //roomtype;
		}
		var wysi_activity = '';
		//if (activity.count() > 0) {
		if (activity.length > 0) {
			wysi_activity = getArrayDefinedValue(activity, optSportangebot);
		}
        var wysi_tour_operator = getTO(to, port);


//        alert(
//	"customer= " + customer + "\n" +
//	"wysi_page= " + wysi_page + "\n" +
//	"wysi_bookingpath= " + wysi_bookingpath + "\n" +
//	"wysi_destination= " + wysi_destination + "\n" +
//	"wysi_from_airport= " + wysi_from_airport + "\n" +
//	"wysi_date= " + wysi_date + "\n" +
//	"wysi_flexibility= " + wysi_flexibility + "\n" +
//	"wysi_duration= " + wysi_duration + "\n" +
//	"wysi_nbadults= " + wysi_nbadults + "\n" +
//	"wysi_child_1_age= " + wysi_child_1_age + "\n" +
//	"wysi_child_2_age= " + wysi_child_2_age + "\n" +
//	"wysi_child_3_age= " + wysi_child_3_age + "\n" +
//	"wysi_board= " + wysi_board + "\n" +
//	"wysi_stars= " + wysi_stars + "\n" +
//	"wysi_roomtype= " + wysi_roomtype + "\n" +
//	"wysi_activity= " + wysi_activity + "\n" +
//	"wysi_tour_operator= " + wysi_tour_operator + "\n"
//	);



        var wysistat_thispage = wysi_page + "_" + wysi_bookingpath;

        var wysistat_param = wysistat_thispage
		+ ";" + wysi_destination
		+ "_" + wysi_from_airport
		+ "_" + wysi_date
		+ "_" + wysi_flexibility
		+ "_" + wysi_duration
		+ "_" + wysi_nbadults
		+ "_" + wysi_child_1_age
		+ "_" + wysi_child_2_age
		+ "_" + wysi_child_3_age
		+ "_" + wysi_board
		+ "_" + wysi_stars
		+ "_" + wysi_roomtype
		+ "_" + wysi_activity
		+ "_" + wysi_tour_operator
		;

        var wysistat_param2 = wysistat_thispage + "_destination;" + wysi_destination;
        var wysistat_param3 = wysistat_thispage + "_depart;" + wysi_from_airport;
        var wysistat_param4 = wysistat_thispage + "_date;" + wysi_date;
        var wysistat_param5 = wysistat_thispage + "_etoile;" + wysi_stars;
        var wysistat_param6 = wysistat_thispage + "_chambre;" + wysi_board;
        var wysistat_param7 = wysistat_thispage + "_activites;" + wysi_activity;
        var wysistat_param8 = wysistat_thispage + "_TO;" + wysi_tour_operator;

        // Construction of the global reporting parameter
        var wysistat_param_total = wysistat_param + ";" + wysistat_param2 + ";" + wysistat_param3 + ";" + wysistat_param4 + ";" + wysistat_param5 + ";" + wysistat_param6 + ";" + wysistat_param7 + ";" + wysistat_param8;

        // search tag	
        stat(customer, '', '', wysistat_param_total, '/' + wysistat_thispage + '/');

        // ROI tag
        stat(customer, '', '', '', '/destination/' + wysi_destination + '/', 'destination_selection');
    }

};

this.getHotelStats = function(customer, page, port, destination) {
    //alert("Hotel");

if (valeur==1){

    var wysi_page = getPage(page);
    var wysi_bookingpath = getBookingPath(port);
	var wysi_destination = getDest(destination);
	var wysi_subdestination = getReg(destination);
	
//	alert(
//	"wysi_page="+wysi_page+"\n"+
//	"wysi_bookingpath=" + wysi_bookingpath + "\n" +
//	"wysi_destination=" + wysi_destination + "\n" +
//	"wysi_subdestination=" + wysi_subdestination + "\n"
//	);	
	
	var wysistat_thispage = wysi_page + "_" + wysi_bookingpath;	

	// ROI tag
	stat(customer, '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/', 'destination_selection');
}


};

this.getAvailStats = function(customer, page,port, destination) {
    //alert("Avail");

if (valeur==1){

    var wysi_page = getPage(page);
	var wysi_bookingpath = getBookingPath(port);
	var wysi_destination = getDest(destination);
	var wysi_subdestination = getReg(destination);
	
//	alert(
//	"wysi_page=" + wysi_page + "\n" +
//	"wysi_bookingpath=" + wysi_bookingpath + "\n" +
//	"wysi_destination=" + wysi_destination + "\n" +
//	"wysi_subdestination=" + wysi_subdestination + "\n"
//	);
	
	
	var wysistat_thispage = wysi_page + "_" + wysi_bookingpath;	

	// ROI tag
	stat(customer, '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/', 'disponibilite');
}

};

this.getBookingStats=function(customer,page,port,destination,hotel){
    //alert("Booking");

if (valeur==1){

    var wysi_page = getPage(page);
	var wysi_bookingpath = getBookingPath(port);
	var wysi_destination = getDest(destination);
	var wysi_subdestination = getReg(destination);
    var wysi_productname = hotel;
	

//alert(
//	"wysi_page="+wysi_page+"\n"+
//	"wysi_bookingpath=" + wysi_bookingpath + "\n" +
//	"wysi_destination=" + wysi_destination + "\n" +
//	"wysi_subdestination=" + wysi_subdestination + "\n" +
//    "wysi_productname=" + wysi_productname+"\n"
//);
    var wysistat_thispage = wysi_page + "_" + wysi_bookingpath;	
	// ROI tag
    stat(customer, '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/' + wysi_productname, 'resa_step1');
}


};

this.getPaymentStats = function(customer, port, zip, lname, fname, purchaseId, bookingId, bookingInfo, hotelPrice, insuranceName, insurancePrice, destination, departAirport, info) {
    //alert("Payment");

    var wysi_bookingpath = getBookingPath(port);

    var wysi_id_achat = getPurchaseId(zip,lname,fname);
    var wysi_tt_bookingnumber = bookingId;
    var wysi_total_price = getTotalPrice(bookingInfo);
    var wysi_productname = getHotelInfo(info);
    var wysi_hotelprice = getHotelPrice(hotelPrice, bookingInfo);
    var wysi_insurance_name = getInsuranceName(insuranceName);
    var wysi_insurance_price = getInsurancePrice(insurancePrice);
    var wysi_from_airport = getValueFromArray(departAirport, TTAFH);//departAirport;
    var wysi_payment = "RAS";
    var wysi_destination = getPaymentDest(info);
    var wysi_tour_operator = getPaymentTO(bookingInfo);
    var wysi_subdestination = getPaymentSubDest(info);

//    alert(
//    "wysi_bookingpath=" + wysi_bookingpath + "\n" +
//	"wysi_id_achat=" + wysi_id_achat + "\n" +
//	"wysi_tt_bookingnumber=" + wysi_tt_bookingnumber + "\n" +
//	"wysi_total_price=" + wysi_total_price + "\n" +
//	"wysi_productname=" + wysi_productname + "\n" +
//	"wysi_hotelprice=" + wysi_hotelprice + "\n" +
//	"wysi_insurance_name=" + wysi_insurance_name + "\n" +
//	"wysi_insurance_price=" + wysi_insurance_price + "\n" +
//	"wysi_from_airport=" + wysi_from_airport + "\n" +
//	"wysi_payment=" + wysi_payment + "\n" +
//	"wysi_destination=" + wysi_destination + "\n" +
//	"wysi_tour_operator=" + wysi_tour_operator + "\n" +
//	"wysi_subdestination=" + wysi_subdestination + "\n"
//	);

    var wysi_id_achat2 = wysi_tt_bookingnumber + "-" + wysi_id_achat;

    var wysistat_purchase = "ACHAT/"
		+ wysi_total_price
		+ "/" + wysi_productname + "=" + wysi_hotelprice + "=1=" + wysi_bookingpath + "!"
		+ wysi_insurance_name + "=" + wysi_insurance_price + "=1=assurance/"
		+ wysi_id_achat
		;

    var wysistat_purchase2 = "ACHAT/"
		+ wysi_total_price
		+ "/" + wysi_from_airport + "=" + wysi_total_price + "=1=aeroport!"
		+ wysi_payment + "=" + wysi_total_price + "=1=canal!"
		+ wysi_destination + "=" + wysi_total_price + "=1=pays!"
		+ wysi_tour_operator + "=" + wysi_total_price + "=1=to/"
		+ wysi_id_achat
		;


    stat(customer, 'PV', '', 'relation;' + wysi_id_achat2, '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/' + wysi_productname + '/achat/', wysistat_purchase);
    stat(customer + '2', '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/' + wysi_productname + '/achat/', wysistat_purchase2);


};

this.getConfirmStats = function(customer, port, zip, lname, fname, purchaseId, bookingId, bookingInfo, hotelPrice, insuranceName, insurancePrice, destination, departAirport, payment, info) {
    //alert("Confirmation");

    var wysi_bookingpath = getPaymentDest(info); //getBookingPath(port);
    var wysi_id_achat = getPurchaseId(zip, lname, fname);

    var wysi_tt_bookingnumber = bookingId;

    var wysi_id_achat2 = wysi_tt_bookingnumber + "-" + wysi_id_achat;

    var wysi_total_price = getTotalPrice(bookingInfo);
    var wysi_productname = getHotelInfo(info);
    var wysi_hotelprice = getHotelPrice(hotelPrice);
    var wysi_insurance_name = getInsuranceName(insuranceName);
    var wysi_insurance_price = getInsurancePrice(insurancePrice);
    var wysi_from_airport = getAirport(bookingInfo);
    var wysi_payment = getMeanPayment(payment);
    var wysi_destination = getPaymentDest(info);
    var wysi_tour_operator = getPaymentTO(bookingInfo);
    var wysi_subdestination = getPaymentSubDest(info);







//    alert(
//	    "wysi_bookingpath=" + wysi_bookingpath + "\n" +
//	"wysi_id_achat=" + wysi_id_achat + "\n" +
//	"wysi_tt_bookingnumber=" + wysi_tt_bookingnumber + "\n" +
//	"wysi_id_achat2=" + wysi_id_achat2 + "\n" +
//	"wysi_total_price=" + wysi_total_price + "\n" +
//	"wysi_productname=" + wysi_productname + "\n" +
//	"wysi_hotel_price=" + wysi_hotel_price + "\n" +
//	"wysi_insurance_name=" + wysi_insurance_name + "\n" +
//	"wysi_insurance_price=" + wysi_insurance_price + "\n" +
//	"wysi_from_airport=" + wysi_from_airport + "\n" +
//	"wysi_payment=" + wysi_payment + "\n" +
//	"wysi_destination=" + wysi_destination + "\n" +
//	"wysi_tour_operator=" + wysi_tour_operator + "\n" +
//	"wysi_subdestination=" + wysi_subdestination + "\n"
//	);


    var wysi_id_achat2 = wysi_tt_bookingnumber + "-" + wysi_id_achat;

    var wysistat_purchase2 = "ACHAT/"
		+ wysi_total_price
		+ "/" + wysi_payment + "=" + wysi_total_price + "=1=canal/"
		+ wysi_id_achat
		;


    var wysi_hotel_price = "";
    var wysistat_purchase3 = "ACHAT/"
		+ wysi_total_price
		+ "/" + wysi_productname + "=" + wysi_hotel_price + "=1=sejour!"
		+ wysi_insurance_name + "=" + wysi_insurance_price + "=1=assurance/"
		+ wysi_id_achat2
		;


    if (valeur == 1) {
        stat(customer, '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/' + wysi_productname + '/achat/confirmation');
        stat(customer + '3', '', '', '', '/destination/' + wysi_destination + '/' + wysi_subdestination + '/disponibilite/' + wysi_productname + '/achat/confirmation', wysistat_purchase2);
    }

    if (valeur_ext == 1) { stat_ext(wysistat_purchase3); }


};


this.getErrorStats = function(customer, wysi_productname, wysi_date, departAirport) {
wysi_productname = getDest(wysi_productname);
    wysi_from_airport = getValueFromArray(departAirport, TTAFH);

    //alert(customer + " erreur_recherche;" + wysi_productname + "-" + wysi_date + "-" + wysi_from_airport);
    if (valeur == 1) {
        var message_erreur = "erreur_recherche;" + wysi_productname + "-" + wysi_date + "-" + wysi_from_airport;
        stat(customer, 'PV', '', message_erreur, '/moteur_recherche/erreur/');
    }

};

this.getNotFoundStats = function(customer, wysi_productname, wysi_date, departAirport) {
//alert(departAirport);
    wysi_from_airport = getValueFromArray(departAirport, TTAFH);

    //alert(customer + " erreur_recherche;" + wysi_productname + "-" + wysi_date + "-" + wysi_from_airport);

    if (valeur == 1) {
        var message_erreur = "erreur_disponibilite;" + wysi_productname + "-" + wysi_date + ";erreur_disponibilite2 ;" + wysi_productname;
        stat(customer, 'PV', '', message_erreur, '/disponibilite/erreur/');
    }


};

this.getDest = function(str) {
    destLbl = str.split("0tt0")[0];
    return destLbl;
};

this.getReg = function(str) {
regLbl = str.split("0tt0")[1];
    return regLbl;
};

this.getValueFromArray = function(code, arr) {
    for (i in arr) {
        arrArr = arr[i].split(";");
        if (arrArr[1] == code) {
            return arrArr[0];
        }
    }
};

this.getArrayLength = function(arr) {
    arrArr = arr.split(";")
    return arrArr.length;
};

this.getStarsInt = function(stars) {
    if (stars) {
        var strStars = getValueFromArray(stars, optKategorie);
        if (strStars == "Indifférente")
        { intStars = '-1'; }
        else
        { intStars = strStars.substr(0, 1); }

    } else
    { intStars = '-1'; }

    return intStars;
};


this.getTO = function(toCode, port) {
    arrTo = window['arrMarke_' + port];
    var strTO = getValueFromArray(toCode, arrTo);
    tO = getDefinedValue(strTO);
    return tO;
};

this.getArrayDefinedValue = function(val, arr) {
    var strDefinedVal = getValueFromArray(val, arr);
	//alert(val);
	//alert(arr);
    if (strDefinedVal.substr(0, 11) == "Indifférent")
    { strDefinedVal = "-1"; }
    return strDefinedVal;
};

this.getDefinedValue = function(val) {
if (val == '' || val == undefined)
    { val = "-1"; }
    return val;
};

this.getPurchaseId = function(zip, lname,fname) {//
    purchaseId = zip + '_' + lname+'_'+fname.substr(0,2); //;
    return purchaseId;
};

this.getTotalPrice = function(bookingInfo) {

if (typeof(bookingInfo)!= 'undefined')
{
    if (bookingInfo != "")
    {
      arrBookingInfo = bookingInfo.split("|");
      arrPriceInfo = arrBookingInfo[7].split(";");
      totalPrice = arrPriceInfo[arrPriceInfo.length - 1];
      return totalPrice;
    }
    else
    {
    
      return "0";
    }
}
else
{
  return "0";
}
  
};

this.getPaymentTO = function(str) {
    toCode = str.split(";")[2];
    toLbl = "";
    switch (toCode) {
        case "AQT":
            toLbl = "Aquatour";
            break;
        case "ASIA":
            toLbl = "Asia";
            break;
        case "FRAM":
            toLbl = "Fram";
            break;
        case "JETN":
            toLbl = "Jet Tours Nurvis";
            break;
        case "JET":
            toLbl = "Jet Tours";
            break;
        case "KUO":
            toLbl = "Kuoni";
            break;
        case "LOOK":
            toLbl = "Look Voyage";
            break;
        case "MAR":
            toLbl = "Marmara";
            break;
        case "MARS":
            toLbl = "Marsans";
            break;
        case "TCF":
            toLbl = "Thomas Cook";
            break;
            }
            return toLbl;
        };

        this.getAirport = function(str) {

            var airport = str.split("|")[1];
            switch (airport) {
                case 'PAR','CDG','ORY':
                    airportLbl = "Paris"
                    break;
                default:
                    airportLbl = getValueFromArray(airport, TTAFH);
            }
            return airportLbl;
        };

this.getPaymentDest = function(str) {
    destCode = str.split(";")[4];
    return destCode;
};

this.getPaymentSubDest = function(str) {
    destCode = str.split(";")[3];
    return destCode;
};

this.getHotelInfo = function(str) {
    hotelInfo = str.split(";")[0];
    return hotelInfo;
};

this.getMeanPayment = function(int) {
    switch (int) {
        case '1':
            paymentStr = "CB 100%";
            break;
        case '2':
            paymentStr = "phone";
            break;
        case '3':
            paymentStr = "agency";
            break;
        case '4':
            paymentStr = "CB 30%";
            break;
    }
    return paymentStr;
};

this.getHotelPrice = function(hotelPrice, str) {
    if (hotelPrice == '')
    { hotelPrice = getTotalPrice(str); }
    return hotelPrice;
};
this.getInsuranceName = function(insuranceName) {
    if (insuranceName == '')
    { insuranceName = 'assurance'; }

};
this.getInsurancePrice = function(insurancePrice) {
if (insurancePrice == '')
    { insurancePrice='0'; }
};

this.repl = function(str) {
str = str.replace(/_/g, " ");
str = str.replace(/;/g, ",");
str = str.replace(/\//g, " ");
str = str.replace(/\'/g, " ");
str = str.replace(/\"/g, " ");
return str;
};