Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;

function sendForm(elem, lang){
	obkt = {
		from		: { ob : elem.fromAddress_text, val : elem.fromAddress_text.value },
		to		: { ob : elem.toAddress_text, val : elem.toAddress_text.value },
		trip	: { ob : elem.trip, val : elem.trip.value },
		trip1	: { ob : elem.trip1, val : elem.trip1.value },
		trip2	: { ob : elem.trip2, val : elem.trip2.value },
		car		: { ob : elem.car, val : elem.car.value},
		monitor	: { ob : elem.monitor, val : elem.monitor.value }
}

	$(obkt).each(function(){
		if ($(this).val) {
			$(this.ob).addClass("error");
		}
	});

	if ( ( !obkt.from.val ) || ( !obkt.to.val) ){
		errorshow("One of more parametrs values are not set, please set and try again!");
	} else {
	setDirections(obkt.from.val, obkt.to.val, lang)
	}
}

function prep(id){

    if (( !Drupal.settings.locat ) && (id == "from")) {
        return Drupal.settings.locat.from
    }
    if (( !Drupal.settings.locat ) && (id == "to")){
        return Drupal.settings.locat.to
    }
    } else {jQuery.extend(Drupal.settings, { "basePath": "/", "page": "routecalc", "lang": "en" });
       if( id == "from" ){ return Drupal.t("@start",trans) }
       if( id == "to"){ return Drupal.t("@endt",trans) }
    }
}

function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.addControl(new GSmallMapControl());
        map.enableScrollWheelZoom();
		map.setMapType(G_NORMAL_MAP);
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "addoverlay", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        setDirections(prep("from"), prep("to"), Drupal.t("@la",trans));
      }
}

function setDirections(fromAddress, toAddress, locale) {
	gdir.locale
      fromAddress +=",Ma";
      toAddress +=",Ma";
      gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale });
}

function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     errorshow("<p>Unfortunately, the system can not find the desired value, Possible reasons:</p><p>1. The specified point is located outside the state Masachussets.</p><p>2. Google map system is not known to the requested location.</p>");
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     errorshow("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     errorshow("Your request contains an empty field direction.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEOgetIcon().image_BAD_KEY)
     errorshow("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     errorshow("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
   else errorshow("An unknown error occurred.");
}

function convert_mile(metr){
		mile = (metr/parseInt("1609,344"));
		mile = mile.toFixed(1);
		return mile;
}

function addinput(e) {
	 text = $(e).parent("li").attr('val')
		if ( $(e).parent("li").hasClass("autocom from") ){
		$("#fromAddress").val(text);
		$("div.autocomplete").remove();
		}
		if ( $(e).parent("li").hasClass("autocom to") ){
		$("#toAddress").val(text);
		$("div.autocomplete").remove();
		}
}

function onGDirectionsLoad(){
	if ( $("#geo-error").length !== 0 ){
		$("#geo-error").remove();
		}
		var metr = gdir.getDistance().meters;
		var direct = "";
		direct += "<div id=distance>'.$rast.'"+ convert_mile(metr) +" '.$mil.' ( "+ metr/parseInt(1000) +" '.$km.')</div>";
		direct += "<div id=price></div>";
		$("div[jsvalues=\"$routeId:$index;$Route:$AllRoutes[$index]\"]").empty().append(direct);
		var trip = $("#trip input:radio:checked").val();
		var from = gdir.B.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName
		var fromall = $("#fromAddress").val();
		var to 	 = gdir.B.Placemark[1].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName
		var toall = $("#toAddress").val();
		var monitor = $("#monitor:checked").length;
		var time1 = $("#trip1 input:radio:checked").val();
		var time2 = $("#trip2 input:radio:checked").val();
		var car  = $("#car option:selected").val();
		$("#p_submit input").removeAttr("disabled");
		$.post("/routecalc/price",{"from":from,"to":to, "trip":trip, "monitor":monitor, "time1":time1, "time2":time2, "car":car, "miles": convert_mile(metr) }, function(data) {
		if ( data.otvet != null ){
		$("#price").html("<span>Price: <b>"+data.otvet+"<b>$<span>");

		if ( data.otvet != 0 ) {
			if (metr != 0){
		$("#price").after('<input id="adcart" type="submit" value="Add to Cart" />');
			$("#adcart").click(function(){
		$(this).attr("disabled","disabled");
			$.post("/routecalc/addcart",{"from":from,"to":to,"fromall":fromall,"toall":toall,"trip":trip,"monitor":monitor,"time1":time1, "time2":time2, "car":car, "miles": convert_mile(metr), price: data.otvet }, function(d,suc){
			if (suc == "success"){
			if ( $("#cart").length == 0 ){
$("#p_submit").after("<div id='cart'><div id='trips'>Trips:"+d.trips+"</div><div id='allpr'>Price:"+d.allprice+" $<p><a href='/routecalc/addcart'>"+Drupal.settings.t.сheckout+"</a></p></div></div>");
			} else {
$("#cart").empty().append("<div id='trips'>Trips:"+d.trips+"</div><div id='allpr'>Price:"+d.allprice+" $<p><a href='/routecalc/addcart'>сheckout</a></p></div>");
			}
			$("#adcart").removeAttr("disabled");
			}
			},"json");
		});
		}
		}
		}
		},"json");

}

function errorshow(err){
	$("#geo-error").remove();
	$("#directions").before('<div id="geo-error">'+err+'</div>');
}
</script>