﻿


function showQuestionnaire(code, title, mesSource) {

    $("#dialogQuestionnaire").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 500,
        buttons: {
        提交并下载: function() {
        sendMessage('FREE', 'STEP3', $("#txtQuestionnaire").val());
                $(this).dialog('close');
                showDownloadInfo();
            }
        }
    });
    $("#dialogQuestionnaire").dialog('open');
   
}

function showDownloadInfo() {

    $("#dialogDownloadlinks").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 500,
        buttons: {
            关闭: function() {
                $(this).dialog('close');
            }
        }
    });
    $("#dialogDownloadlinks").dialog('open');
}



function showPro(mesSource) {
    $("#dialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 500,
        buttons: {
            关闭: function() {
                $(this).dialog('close');
            }
        }
    });
    $("#dialog").dialog('open');


    var title = "";
    if (document.getElementById("hidSolutionTitle")) {
        title = $("#hidSolutionTitle").val();
    }

    if (mesSource == null || mesSource == "") {
          mesSource = "0";
    }
    
   // sendMessage('ADTIME', title, mesSource)

}
function sendMessage(mesCode,mesTitle,mesOthers) {
    $.ajax({
        type: "POST",
        cache: false,
        url: "/Step.mvc/Step_Message/" + mesCode + "@" + mesTitle + "@" + mesOthers,
        success: function(msg) {
        }
    });
}


function panToMAP(mapID, lat, lng) {
    if (GBrowserIsCompatible()) {

        var mapX = mapList[mapID];
        mapX.setMapType(G_SATELLITE_MAP);
        mapX.setCenter(new GLatLng(lat, lng), 17)

    }
}
function initializeMainMap() {

    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("MapOne"));
        map.setCenter(new GLatLng(45.767522962149904, 12.2607421875), 4);
        map.setUIToDefault();

        //SET DEFAULT ICON
        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);

        function createMarker(point, index) {

            // Create a lettered icon for this point using our icon class
            var letteredIcon = new GIcon(baseIcon);
            letteredIcon.image = "http://www.eueueu.com/Images/erp/attMark/marker" + index + ".png";

            // Set up our GMarkerOptions object
            markerOptions = { icon: letteredIcon };
            var marker = new GMarker(point, markerOptions);
            return marker;
        }



        //Mark it
        var myArray = new Array();
        for (var i = 0; i < $(".hidCityInfo").length; i++) {
            var lat = $($(".hidCityInfo")[i]).attr("lat");
            var lng = $($(".hidCityInfo")[i]).attr("lng");
            var latlng = new GLatLng(lat, lng);
            if ($(".hidCityInfo").length != 1 && i == $(".hidCityInfo").length - 1 && $($(".hidCityInfo")[0]).val() == $($(".hidCityInfo")[i]).val()) {
                // same arrive and departure city
            }
            else {
                map.addOverlay(createMarker(latlng, i + 1));
            }
            // map.addOverlay(new GMarker(latlng));
            myArray.push(new GLatLng(lat, lng));

        }

        if(myArray.length>0){
            var polyline = new GPolyline(myArray, "#ff0000", 10);

            setTimeout(function() {
                map.addOverlay(polyline);
            }, 8000);

        }


        var lastLatlng = 0;
        var lastName = "";
        var distance = 0;
        var totoldesc = "";
        for (var i = 0; i < $(".hidCityInfo").length; i++) {
            var lat = $($(".hidCityInfo")[i]).attr("lat");
            var lng = $($(".hidCityInfo")[i]).attr("lng");
            var latlng = new GLatLng(lat, lng);
            if (lastLatlng == 0) {
                lastLatlng = latlng;
                lastName = $($(".hidCityInfo")[i]).attr("cityname");
            }
            else {
                var miledistance = latlng.distanceFrom(lastLatlng, 3959);
                var kmdistance = parseInt(miledistance * 1.609344);
                distance = parseInt(distance) + parseInt(kmdistance);
                totoldesc += lastName + "-" + $($(".hidCityInfo")[i]).attr("cityname") + ":&nbsp;" + kmdistance + "km&nbsp;&nbsp;|&nbsp;&nbsp;";
                lastLatlng = latlng;
                lastName = $($(".hidCityInfo")[i]).attr("cityname");
            }
        }
        $("#panelDistance").text(distance);
        $("#panelDistanceDesc").html(totoldesc);
        

    }

}

function initializeSubMaps() {

    mapList = new Array();


    var numberOfCities = $(".map").length;

    if (GBrowserIsCompatible()) {

        for (var jj = 0; jj < numberOfCities; jj++) {


            var map = new GMap2(document.getElementById("map" + jj));
            mapList[jj] = map;
            var mapValue1 = eval('(' + document.getElementById("mapValue" + jj).value + ')');

            //SET CENTER
            var lat = mapValue1.cityLocation.substring(0, mapValue1.cityLocation.indexOf(','));
            var lng = mapValue1.cityLocation.substring(mapValue1.cityLocation.indexOf(',') + 1);
            map.setCenter(new GLatLng(lat, lng), 11);
            map.setUIToDefault();

            //SET DEFAULT ICON
            var baseIcon = new GIcon(G_DEFAULT_ICON);
            baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
            baseIcon.iconSize = new GSize(20, 34);
            baseIcon.shadowSize = new GSize(37, 34);
            baseIcon.iconAnchor = new GPoint(9, 34);
            baseIcon.infoWindowAnchor = new GPoint(9, 2);

            // Creates a marker whose info window displays the letter corresponding
            // to the given index.
            function createMarker(point, index, isHotel) {
                // Create a lettered icon for this point using our icon class
                var letteredIcon = new GIcon(baseIcon);
                if (isHotel) {
                    letteredIcon.image = "http://www.eueueu.com/Images/erp/hotelMark/marker" + index + ".png";
                }
                else {
                    letteredIcon.image = "http://www.eueueu.com/Images/erp/attMark/marker" + index + ".png";
                }


                // Set up our GMarkerOptions object
                markerOptions = { icon: letteredIcon };
                var marker = new GMarker(point, markerOptions);
                return marker;
            }


            // Add attraction markers to the map 
            for (var i = 0; i < mapValue1.attractions.length; i++) {

                var lat = mapValue1.attractions[i].attLocation.substring(0, mapValue1.attractions[i].attLocation.indexOf(','));
                var lng = mapValue1.attractions[i].attLocation.substring(mapValue1.attractions[i].attLocation.indexOf(',') + 1);
                var latlng = new GLatLng(lat, lng);
                map.addOverlay(createMarker(latlng, i + 1));
            }

            // Add hotel markers to the map 
            for (var i = 0; i < mapValue1.hotels.length; i++) {

                var lat = mapValue1.hotels[i].hotelLocation.substring(0, mapValue1.hotels[i].hotelLocation.indexOf(','));
                var lng = mapValue1.hotels[i].hotelLocation.substring(mapValue1.hotels[i].hotelLocation.indexOf(',') + 1);
                var latlng = new GLatLng(lat, lng);
                map.addOverlay(createMarker(latlng, i + 1, "iamhotel"));
            }


        }
    }


}

function verifyCode() {
    var code = $("#cardNo").val();
    var day = $("#hidTotalDays").val();
    var myUrl = $("#solutionURL").val();
    if (code == "") {
        $("#tdMsg").text("* 请输入卡号");
        return;
    }

    $.ajax({
        type: "POST",
        cache: false,
        url: "../VerifyCode/" + code + "_" + day + "URL" + myUrl,
        success: function(msg) {
            $("#tdMsg").html(msg);
        }
    });
}

function GoToStepTwo() {
    window.location.replace("/Step.mvc/StepTwo/" + $("#privousStepCode").val());
}
function GoToStepOne() {
    window.location.replace("/Step.mvc/StepOne/" + $("#solutionURL").val());
}
