var location1;
	var location2;
	
	var address1;
	var address2;

	var latlng;
	var geocoder;
	var map;
	
	var distance;
	var toplama;
	// $('#target').attr("disabled", true);   jquer 
	function initialize()
	{
		
		geocoder = new google.maps.Geocoder(); // creating a new geocode object
		
		// getting the two address values
		var es = document.getElementById("country");
		var strUsers = es.options[es.selectedIndex].text;
		
		var esb = document.getElementById("city");
		var strUsersb = esb.options[esb.selectedIndex].text;
		
		var e = document.getElementById("countryb");
		var strUser = e.options[e.selectedIndex].text;
		
		var et = document.getElementById("cityb");
		var strUsere = et.options[et.selectedIndex].text;
		
		address1 = strUsers+","+strUsersb;
		address2 = strUser+","+strUsere;
		//alert(address1);
		//alert(address2);
		// finding out the coordinates
		$("#flash").show();
		$("#flash").fadeIn(400).html('<img src="ajax.gif" align="absmiddle"> <span class="loading">Bekleyiniz ...</span>');
		if (geocoder) 
		{
			geocoder.geocode( { 'address': address1}, function(results, status) 
			{
				if (status == google.maps.GeocoderStatus.OK) 
				{
					//location of first address (latitude + longitude)
					location1 = results[0].geometry.location;
					//showMap();
				} else 
				{
					alert("Geocode was not successful for the following reason: " + status);
				}
			});
			geocoder.geocode( { 'address': address2}, function(results, status) 
			{
				if (status == google.maps.GeocoderStatus.OK) 
				{
					//location of second address (latitude + longitude)
					location2 = results[0].geometry.location;
					// calling the showMap() function to create and show the map 
					showMap();
					$("#flash").hide();
					$('#diger').show('slow');
					
				} else 
				{
					alert("Geocode was not successful for the following reason: " + status);
				}
			});
		}
		
		
		
	}
		
	function metre()
	{
	    var metreh = document.getElementById("metre");
		var metrehesap = metreh.options[metreh.selectedIndex].value;
		document.getElementById("oda").innerHTML = " + Evinizin Toplam Oda Sayısının Taşıma Fiyatı " + metrehesap +"TL";
		if(isNaN(metrehesap)){document.getElementById("ot").value=0;
		gtoplam();
		}else{
			document.getElementById("ot").value=metrehesap;
			gtoplam();
			}
	    
	
		
	}
	function usta1c(){
		
		
		if(document.getElementById("usta1").checked == true)
          {
		    document.getElementById("mobilya").innerHTML = " + Mobilya Marangoz Ustası + 100 TL"; 
			document.getElementById("u1").value=100;
			gtoplam();
		  }
	    if(document.getElementById("usta1").checked == false)
          {
			 var Node1 = document.getElementById("mobilya");
             Node1.removeChild(Node1.childNodes[0]); 
			document.getElementById("u1").value=0;
			gtoplam();
		  }
	}
	
	function usta1d(){
		
		
		if(document.getElementById("usta2").checked == true)
          {
		    document.getElementById("Tesisat").innerHTML = " + Tesisat(beyaz eşya vs) Ustası + 100 TL"; 
			document.getElementById("u2").value=100;
			gtoplam();
		  }
	    if(document.getElementById("usta2").checked == false)
          {
			 var Node1 = document.getElementById("Tesisat");
             Node1.removeChild(Node1.childNodes[0]); 
			 document.getElementById("u2").value=0;
			 gtoplam();
		  }
	}
	
	function usta1e(){
		
		
		if(document.getElementById("usta3").checked == true)
          {
		    document.getElementById("Elektrik").innerHTML = " + Elektrik Ustası + 100 TL"; 
			document.getElementById("u3").value=100;
			gtoplam();
		  }
	    if(document.getElementById("usta3").checked == false)
          {
			 var Node1 = document.getElementById("Elektrik");
             Node1.removeChild(Node1.childNodes[0]); 
			 document.getElementById("u3").value=0;
			 gtoplam();
		  }
	}
	
    function usta1f(){
		
		
		if(document.getElementById("usta4").checked == true)
          {
		    document.getElementById("kutulama").innerHTML = " + kutulama ambalajlama yapılsın + 100 TL"; 
			document.getElementById("u4").value=100;
			gtoplam();
		  }
	    if(document.getElementById("usta4").checked == false)
          {
			 var Node1 = document.getElementById("kutulama");
             Node1.removeChild(Node1.childNodes[0]); 
			 document.getElementById("u4").value=0;
			 gtoplam();
		  }
	}
	
	function gtoplam()
	{
		
	   var gt;
	   var cevir;
	   cevir=document.getElementById("kmt").value.replace(".", "");
	   gt=parseInt(cevir)+parseInt(document.getElementById("ot").value)+parseInt(document.getElementById("u1").value)+parseInt(document.getElementById("u2").value)+parseInt(document.getElementById("u3").value)+parseInt(document.getElementById("u4").value);
		  
		    document.getElementById("topl").innerHTML ="TOPLAM "+ gt.toString() + " TL"; 
			
	
	}
	function iletisimiac()
	{
		//$('#adresdoldur').show('slow');
		//$('#diger').hide('slow');
		$('#ekistek').show('slow');
		
		$('#ilkadim').hide('slow');
		
	}
	function odemebilgisi()
	{
		$('#adresdoldur').show('slow');
		//$('#diger').hide('slow');
		//$('#ekistek').show('slow');
		$('#ikinciadim').hide('slow');
		
	}


	// creates and shows the map
	function showMap()
	{
		// center of the map (compute the mean value between the two locations)
		latlng = new google.maps.LatLng((location1.lat()+location2.lat())/2,(location1.lng()+location2.lng())/2);
		
		// set map options
			// set zoom level
			// set center
			// map type
		var mapOptions = 
		{
			zoom: 1,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.HYBRID
		};
		
		// create a new map object
			// set the div id where it will be shown
			// set the map options
		map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
		
		// show route between the points
		directionsService = new google.maps.DirectionsService();
		directionsDisplay = new google.maps.DirectionsRenderer(
		{
			suppressMarkers: true,
			suppressInfoWindows: true
		});
		directionsDisplay.setMap(map);
		var request = {
			origin:location1, 
			destination:location2,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		directionsService.route(request, function(response, status) 
		{
			if (status == google.maps.DirectionsStatus.OK) 
			{
				directionsDisplay.setDirections(response);
				distance = "Taban fiyatımız belirlendi : "+parseFloat(response.routes[0].legs[0].distance.text) +"TL<br/>Teslim Süresi : "+response.routes[0].legs[0].duration.text;
				 
				document.getElementById("distance_road").innerHTML = distance;
				toplama=parseFloat(response.routes[0].legs[0].distance.text);
				document.getElementById("kmt").value=toplama;
				gtoplam();
				//alert(document.getElementById("kmt").value);
				 //document.getElementById("address1").value=response.routes[0].legs[0].distance.text.replace("km","");
	//			document.getElementById("address2").value=response.routes[0].legs[0].duration.text;
			}
		});
		
		// show a line between the two points
		var line = new google.maps.Polyline({
			map: map, 
			path: [location1, location2],
			strokeWeight: 7,
			strokeOpacity: 0.8,
			strokeColor: "#FFAA00"
		});
		
		// create the markers for the two locations		
		var marker1 = new google.maps.Marker({
			map: map, 
			position: location1,
			title: "First location"
		});
		var marker2 = new google.maps.Marker({
			map: map, 
			position: location2,
			title: "Second location"
		});
		
		// create the text to be shown in the infowindows
		var text1 = '<div id="content">'+
				'<h1 id="firstHeading">First location</h1>'+
				'<div id="bodyContent">'+
				'<p>Coordinates: '+location1+'</p>'+
				'<p>Address: '+address1+'</p>'+
				'</div>'+
				'</div>';
				
		var text2 = '<div id="content">'+
			'<h1 id="firstHeading">Second location</h1>'+
			'<div id="bodyContent">'+
			'<p>Coordinates: '+location2+'</p>'+
			'<p>Address: '+address2+'</p>'+
			'</div>'+
			'</div>';
		
		// create info boxes for the two markers
		var infowindow1 = new google.maps.InfoWindow({
			content: text1
		});
		var infowindow2 = new google.maps.InfoWindow({
			content: text2
		});

		// add action events so the info windows will be shown when the marker is clicked
		google.maps.event.addListener(marker1, 'click', function() {
			infowindow1.open(map,marker1);
		});
		google.maps.event.addListener(marker2, 'click', function() {
			infowindow2.open(map,marker1);
		});
		
		// compute distance between the two points
		var R = 6371; 
		var dLat = toRad(location2.lat()-location1.lat());
		var dLon = toRad(location2.lng()-location1.lng()); 
		
		var dLat1 = toRad(location1.lat());
		var dLat2 = toRad(location2.lat());
		
		var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
				Math.cos(dLat1) * Math.cos(dLat1) * 
				Math.sin(dLon/2) * Math.sin(dLon/2); 
		var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
		var d = R * c;
		
		//document.getElementById("distance_direct").innerHTML = "<br/>The distance between the two points (in a straight line) is: "+d;
	}
	
	function toRad(deg) 
	{
		return deg * Math.PI/180;
	}
