function CPMap() {
	this.map = null;
	this.objLatLng = null;
	this.objDepMarker = null;
	this.objDesMarker = null;
	this.objGDirect = null;
	this.objPolyline = null;
	this.lineColor = "#ff0000";	
	this.journeyTime = null;	
	this.journeyDistance = null;
	this.jsonMatch = null;
	this.ojbDelMarker = null;
	this.statusFound = true;
	this.jsAllAboutContent = new Object();
	this.sizePopupAboutUs = null;
	this.forwardsave = null;
	this.objLatLngPopupAboutUs = null;
	this.objCurentLatLng = null;
}

CPMap.prototype.loadDefaultMap = function() {
	this.map = null;
	this.objLatLng = null;
	this.objDepMarker = null;
	this.objDesMarker = null;
	this.objGDirect = null;
	this.objPolyline = null;
	this.lineColor = "#ff0000";	
	this.journeyTime = null;	
	this.jsonMatch = null;
	this.ojbDelMarker = null;
	
	if (GBrowserIsCompatible()) {
		//this.map = new GMap2(document.getElementById("mainContent"));
		this.map = new google.maps.Map2(document.getElementById("mainContent"));
		this.objGDirect = new GDirections(this.map);
		
		//this.map.setCenter(new GLatLng(39.36827914916013, 14.765625), 2);// World map Lat Lng
		//this.map.setCenter(new GLatLng(-37.817, 144.967), 10);	// Melbourne Lat Lng	
		
		//google.load("maps", "2");
		//google.load("search", "1");
		if(google.loader.ClientLocation) {
	    	this.map.setCenter(new GLatLng(google.loader.ClientLocation.latitude , google.loader.ClientLocation.longitude), 10);
			this.objCurentLatLng = new GLatLng(google.loader.ClientLocation.latitude , google.loader.ClientLocation.longitude);	
		}
		else {
			this.map.setCenter(new GLatLng(39.36827914916013, 14.765625), 2);
			this.objCurentLatLng = new GLatLng(39.36827914916013, 14.765625);	
		}
		
		
      	this.map.addControl(new GLargeMapControl());
		//$("#idGoogleAds").html(google.loader.ClientLocation.longitude);
    }
   /*function initialize() {
	    objCPMap = new CPMap(); 
        objCPMap.map = new google.maps.Map2(document.getElementById("mainContent"));
		objCPMap.objGDirect = new GDirections(objCPMap.map);
        objCPMap.map.setCenter(new google.maps.LatLng(google.loader.ClientLocation.latitude , google.loader.ClientLocation.longitude ), 10);
		objCPMap.map.addControl(new GLargeMapControl());					
    }
   google.setOnLoadCallback(initialize);*/
}

CPMap.prototype.showAddress = function(address,iconType) {
	var objLatLng = null;
	geocoder = new GClientGeocoder();
	if(geocoder) {		
		geocoder.getLatLng(address,  function(point) {
			var objMarker = new GMarker(point, G_DEFAULT_ICON);											  
			objCPMap.map.addOverlay(objMarker);								  
			objLatLng = point;
			objCPMap.map.panTo(point);
		});
	}
}

CPMap.prototype.showDepDesLatLng = function(objDepLatLng,objDesLatLng,depIconType,desIconType, idCarpoolDetail) {
	this.objDepMarker = new GMarker(objDepLatLng, this.getIcon(depIconType));	
	this.objDesMarker = new GMarker(objDesLatLng, this.getIcon(desIconType));	
	this.drawPathLine(this.objDepMarker,this.objDesMarker);	
	if(idCarpoolDetail) {
		GEvent.addDomListener(document.getElementById(idCarpoolDetail), "click", function() { 		
			objCPMap.map.closeInfoWindow();																			 
			if(objCPMap.objPolyline) {
				   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
			}					
			objCPMap.objPolyline = new GPolyline([objDepLatLng, objDesLatLng], objCPMap.lineColor, 3, 1); 					    
			objCPMap.map.addOverlay(objCPMap.objPolyline);		
			var Html="<div style='width:350px;height:350px;' id='divCarpoolInfo' ></div>";
			objCPMap.map.openInfoWindow(objDesLatLng, Html);
			loadJsonPage("LoadCarpoolInfo", '', 'divCarpoolInfo');
		});		
	}
	else {
		GEvent.addListener(objCPMap.objGDirect, 'load', function() {
			if(objCPMap.objGDirect.getDuration()) 
			{
				if(objCPMap.objGDirect.getDuration().seconds) {
					var seconds = objCPMap.objGDirect.getDuration().seconds;
					var hour = parseInt(seconds/3600,10);
					var minus = hour > 0 ? parseInt((seconds - hour * 3600) / 60,10) : parseInt(seconds /60,10);
					objCPMap.journeyTime = (hour.toString().length == 1 ? '0' + hour.toString() : hour) + ':' + (minus.toString().length == 1 ? '0' + minus.toString() : minus);			
				}			
				if(objCPMap.objGDirect.getDistance().meters) {
					var intKm = Math.round(objCPMap.objGDirect.getDistance().meters / 1000);
					objCPMap.journeyDistance = intKm;
				}
			}
		});		
	}
}

CPMap.prototype.showDepDesAddress = function(address,iconType) {
	var objLatLng = null;	
	geocoder = new GClientGeocoder();
	if(geocoder) {		
		geocoder.getLatLng(address, function(point) {
			var objMarker = new GMarker(point, objCPMap.getIcon(iconType));											  
			if(iconType == 'DepType') {
				if(objCPMap.objDepMarker != null) {
					objCPMap.map.removeOverlay(objCPMap.objDepMarker);	
				}				
				objCPMap.objDepMarker = objMarker;
			}
			else if(iconType == 'DesType') {
				if(objCPMap.objDesMarker != null) {
					objCPMap.map.removeOverlay(objCPMap.objDesMarker);	
				}				
				objCPMap.objDesMarker = objMarker;
			}
			
			objCPMap.map.addOverlay(objMarker);								  
			objCPMap.objLatLng = point;
			objCPMap.map.panTo(point);
			
			// show path
			if(objCPMap.objDepMarker != null && objCPMap.objDesMarker != null) {
				objCPMap.drawPathLine(objCPMap.objDepMarker,objCPMap.objDesMarker);
			}
		});
	}
}

CPMap.prototype.drawPathLine = function(objDepMarker,objDesMarker) { 
	this.objLatLngPopupAboutUs = objDepMarker.getLatLng();
	var prepareAddress = String(objDepMarker.getLatLng()).substring(1,String(objDepMarker.getLatLng()).length-1) + " to " 
						 + String(objDesMarker.getLatLng()).substring(1,String(objDesMarker.getLatLng()).length-1);
	this.map.clearOverlays();
	this.objGDirect.clear();	
    this.objGDirect.load(prepareAddress); 		
}


CPMap.prototype.getLatLng = function(address, hidLat, hidLng, hidCheck, divMessage) {
	document.getElementById(divMessage).innerHTML = 'Please wating ......';				
	geocoder = new GClientGeocoder();
	if(geocoder) {		
		geocoder.getLatLng(address, function(point) {
			if(!point) {
				document.getElementById(hidCheck).value = 'false';	
				document.getElementById(divMessage).innerHTML = address + "  Not found .";
				document.getElementById(hidlat).value = '';
				document.getElementById(hidLng).value = '';			
			}
			else {				
				document.getElementById(hidCheck).value = 'true';								
				document.getElementById(divMessage).innerHTML = '';				
				objMaker=new GMarker(point, G_DEFAULT_ICON);
				objCPMap.map.addOverlay(objMaker);
				objCPMap.map.openInfoWindow(point, address);
				document.getElementById(hidlat).value = objMaker.getLatLng().lat();
				document.getElementById(hidLng).value = objMaker.getLatLng().lng();				
			}
		});
	}
}

CPMap.prototype.showPairOfMatches = function(idIcon, idViewDetail, objDepLatLng, objDesLatLng, iconType, iconNumber, carpoolKey, jMatch, matchCategoryDesc, srceenname ,rating, ojbMatches, action) {  
	//var objIcon = this.getIcon(iconType, iconNumber);	
	var objMarker = new Array()	;
	objMarker[0] = new GMarker(objDepLatLng, G_DEFAULT_ICON);											  
	objMarker[1] = new GMarker(objDesLatLng, G_DEFAULT_ICON);											  
	this.map.addOverlay(objMarker[0]);		
	this.map.addOverlay(objMarker[1]);	
	GEvent.addDomListener(document.getElementById(idViewDetail), "click", function() { 																				
		objCPMap.map.closeInfoWindow();																			 
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}	
		objCPMap.objPolyline = new GPolyline([objDepLatLng, objDesLatLng], objCPMap.lineColor, 3, 1); 					    
		objCPMap.map.addOverlay(objCPMap.objPolyline);		
		
		var objGSize = objCPMap.map.getSize();	  //Lnnam change outo width 27/06/2008
		var intWidth;		
		if(objGSize.width <= 624) {
			//alert(objGSize.width);
			intWidth = objGSize.width - 150;
		}
		if(objGSize.width > 624)  intWidth = objGSize.width - 300;
		if(objGSize.width > 874)  intWidth = 874 - 300;
		
		objCPMap.map.openInfoWindowHtml(objDepLatLng, "<div style='width:" + intWidth + "px' id=idMatchDetail class=poupMatchDetailScrollBar><img src='images/loading_line.gif' style='width:100px; height:13px'></div>");		
	
		CPMap.prototype.DelayShow = function() {
			loadJsonPage(action + "&srceenname="+ srceenname +"&rating="+ rating +"&matchCategoryDesc="+ matchCategoryDesc +"&carpoolKeyMatch="+ carpoolKey +"&idIcon="+ iconNumber +"&DriverPassengerEither="+ ojbMatches.DriverPassengerEither +"&MessagesSent="+ ojbMatches.MessagesSent  +"&MessagesReceived="+ ojbMatches.MessagesReceived +"", '', 'idMatchDetail');
		}
		setTimeout('objCPMap.DelayShow()', 1000);
		//clearTimeout();
		objCPMap.jsonMatch = jMatch;
		objCPMap.ojbDelMarker = objMarker[0];
	});

	/* 
	Date 16/04/2008
	Lnnam comment to fix bug :
	"When users click on "more info", the match pop up box appears. However it disappears as soon as the mouse is removed from the "more info" link"
	*/
	
/*	GEvent.addDomListener(document.getElementById("outer_" + idViewDetail), "mouseover", function() { 																						
		objCPMap.map.closeInfoWindow();																								  
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}	
		objCPMap.objPolyline = new GPolyline([objDepLatLng, objDesLatLng], objCPMap.lineColor, 3, 1); 					    
		objCPMap.map.addOverlay(objCPMap.objPolyline);
	});
		
	GEvent.addDomListener(objMarker[0], "mouseover", function() { 		
		objCPMap.map.closeInfoWindow();																			 
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}	
		objCPMap.objPolyline = new GPolyline([objDepLatLng, objDesLatLng], objCPMap.lineColor, 3, 1); 					    
		objCPMap.map.addOverlay(objCPMap.objPolyline);
	});

	GEvent.addDomListener(objMarker[1], "mouseover", function() { 		
		objCPMap.map.closeInfoWindow();																			 
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}	
		objCPMap.objPolyline = new GPolyline([objDepLatLng, objDesLatLng], objCPMap.lineColor, 3, 1); 					    
		objCPMap.map.addOverlay(objCPMap.objPolyline);
	});

	GEvent.addDomListener(objMarker[0], "mouseout", function() { 		
		objCPMap.map.closeInfoWindow();																			 
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}				
	});	
	
	GEvent.addDomListener(objMarker[1], "mouseout", function() { 		
		objCPMap.map.closeInfoWindow();																			 
		if(objCPMap.objPolyline) {
			   objCPMap.map.removeOverlay(objCPMap.objPolyline);		
		}				
	});
*/
}

CPMap.prototype.showPairOfUnSaveMatches = function(objDepLatLng, objDesLatLng, iconType, iconNumber) {  
	var objIcon = this.getIcon(iconType, iconNumber);
	var objMarker = new Array()	;
	objMarker[0] = new GMarker(objDepLatLng, objIcon);											  
	objMarker[1] = new GMarker(objDesLatLng, objIcon);											  
	this.map.addOverlay(objMarker[0]);		
	this.map.addOverlay(objMarker[1]);		
}

//--Nam 13/12/2007-----------

CPMap.prototype.showPairOfLatLng = function(idDomLine, idDomDel, ojbPointDep, ojbPointDes, urlIconDep, urlIconDes, colorLine) {
   var objIcon1 = this.getIcon();
   objIcon1.image = urlIconDep;
   Icon1 = { icon:objIcon1};
   var objIcon2 = this.getIcon();
   objIcon2.image = urlIconDes;
   Icon2 = { icon:objIcon2};
   var objMarker = new Array()	
   objMarker[0] = new GMarker(ojbPointDep, Icon1);											  
   objMarker[1] = new GMarker(ojbPointDes, Icon2);											  
   this.map.addOverlay(objMarker[0]);		
   this.map.addOverlay(objMarker[1]);			 
   var polyline = new GPolyline([ojbPointDep , ojbPointDes], colorLine, 3,1);
   GEvent.addListener(objMarker[0], "click", function() { 		 				 
						 objCPMap.map.addOverlay(polyline);
					  });
   GEvent.addListener(objMarker[1], "click", function() {
						 objCPMap.map.addOverlay(polyline);
					  });   
   GEvent.addDomListener(document.getElementById(idDomLine), "click", function() { 		 			
						 objCPMap.map.addOverlay(polyline);
					  });
   GEvent.addDomListener(document.getElementById(idDomDel), "click", function() { 		 			
						 objCPMap.map.removeOverlay(polyline);
						 objCPMap.map.removeOverlay(objMarker[0]);
						 objCPMap.map.removeOverlay(objMarker[1]);
					  }); 
   
  
   
  GEvent.addDomListener(document.getElementById('idtap'), "click", function() { 		 									
						var tabList = [new GInfoWindowTab("Personal Detail", "<div style='width:450px;height:150px;' id='divPersonalDetail' >Personal Detail</div>"), 
									   new GInfoWindowTab("Schedule", "<div style='width:450px;height:150px;' id='divSchedule'>Schedule</div>"),
									   new GInfoWindowTab("Send Message", "<div style='width:450px;height:150px;' id='divSendMessage'>Send Message</div>"), 
									   new GInfoWindowTab("Feedback", "<div style='width:450px;height:150px;' id='divFeedback'>Feedback</div>"), 
									   new GInfoWindowTab("All Comment", "<div style='width:450px;height:150px;' id='divAllcomment'>Feedback</div>")
									   ];
						var opts = { selectedTab : 0 };
						objCPMap.map.openInfoWindowTabsHtml(ojbPointDep, tabList, opts);
					  });
}									 

//-------------------------------------

CPMap.prototype.getIcon = function(iconType, number) {
	var objGIcon = new GIcon();	
	var urlImage = "http://www.google.com/mapfiles/icon_green.png";
	switch(iconType) {
		case 'DepPassenger':
			/*objGIcon.image = "icon/people_start_icon.gif";
			G_START_ICON.image = "icon/people_start_icon.gif";
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_START_ICON.image = urlImage;			
			G_START_ICON.iconSize = new GSize(24, 38);
			break;
		case 'DesPassenger':
			/*objGIcon.image = "icon/people_stop_icon.gif";		
	        G_END_ICON.image = "icon/people_stop_icon.gif";
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_END_ICON.image = urlImage;				
			G_END_ICON.iconSize = new GSize(24, 38);			
			break;			
		case 'DepDriver':
			/*objGIcon.image = "icon/car_stop_icon.gif";		
			G_START_ICON.image = "icon/car_stop_icon.gif";
			G_START_ICON.iconSize = new GSize(40, 60);
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_START_ICON.image = urlImage;				
			G_START_ICON.iconSize = new GSize(24, 38);			
			break;
		case 'DesDriver':
			/*objGIcon.image = "icon/car_start_icon.gif";
			G_END_ICON.image = "icon/car_start_icon.gif";
			G_END_ICON.iconSize = new GSize(40, 60);
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_END_ICON.image = urlImage;				
			G_END_ICON.iconSize = new GSize(24, 38);			
			break;	
		case 'DepBoth':
			/*objGIcon.image = "icon/car_people_icon_start.gif";
			G_START_ICON.image = "icon/car_people_icon_start.gif";
			G_START_ICON.iconSize = new GSize(40, 60);
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_START_ICON.image = urlImage;				
			G_START_ICON.iconSize = new GSize(24, 38);			
			break;
		case 'DesBoth':
			/*objGIcon.image = "icon/car_people_icon_stop.gif";
			G_END_ICON.image = "icon/car_people_icon_stop.gif";
			G_END_ICON.iconSize = new GSize(40, 60);
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_END_ICON.image = urlImage;				
			G_END_ICON.iconSize = new GSize(24, 38);			
			break;				
		case 'MatchPassenger':
			/*objGIcon.image = "icon/people_match" + number + ".gif";
			objGIcon.iconSize = new GSize(20, 34);*/
			break;							
		case 'MatchDriver':
			/*objGIcon.image = "icon/car_match" + number + ".gif";
			objGIcon.iconSize = new GSize(40, 60);*/
			break;
		case 'MatchBoth':
			/*objGIcon.image = "car_people_icon.gif";
			objGIcon.iconSize = new GSize(40, 60);*/			
			break;			
		case 'DepType':
			/*objGIcon.image = "icon/start_icon.gif";		
			G_START_ICON.image = "icon/start_icon.gif";
			G_START_ICON.iconSize = new GSize(20, 34);
			objGIcon.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_START_ICON.image = urlImage;		
			G_START_ICON.iconSize = new GSize(24, 38);			
			break;			
		case 'DesType':
			/*objGIcon.image = "icon/stop_icon.gif";		
	        G_END_ICON.image = "icon/stop_icon.gif";			
			G_END_ICON.iconSize = new GSize(20, 34);*/
			objGIcon.image = urlImage;
			G_END_ICON.image = urlImage;			
			G_END_ICON.iconSize = new GSize(24, 38);			
			break;						
		default:
			objGIcon.image = urlImage;
			/*objGIcon.image = "icon/people_start_icon.gif";
			objGIcon.iconSize = new GSize(20, 34);*/
			break;
	}	
	
	objGIcon.iconSize = new GSize(24, 38);
	objGIcon.shadowSize = new GSize(37, 34);
	objGIcon.iconAnchor = new GPoint(9, 34);
	objGIcon.infoWindowAnchor = new GPoint(9, 2);
	objGIcon.infoShadowAnchor = new GPoint(18, 25);		

	return objGIcon;
}

CPMap.prototype.getMarker = function(address,point,addressType,objIcon) {}

CPMap.prototype.verifyPersonalAddress = function(address, iconType, errorid, hidcheckid, hidlatid, hidlngid, callback, parameter) {
	document.getElementById(errorid).innerHTML = "Please wating ...";	
	objCPMap.map.closeInfoWindow();
	geocoder = new GClientGeocoder();
	if(geocoder) {		
		geocoder.getLatLng(address,  function(objLatLng) {														  
			if(!objLatLng) 
			{
				document.getElementById(hidcheckid).value='false';
				$('#' + errorid).html('');
				$('#' + errorid).html("Address is invalid");
				
				if(iconType == 'DepType' && objCPMap.objDepMarker) {					
					objCPMap.map.removeOverlay(objCPMap.objDepMarker);
					objCPMap.objDepMarker = null;
				}
				else if(objCPMap.objDesMarker) {
					objCPMap.map.removeOverlay(objCPMap.objDesMarker);
					objCPMap.objDesMarker = null;
				}
				callback(parameter);				
			}
			else {
				document.getElementById(errorid).innerHTML = "";
				if(hidlatid)
					document.getElementById(hidlatid).value = objLatLng.lat();
				if(hidlngid)
					document.getElementById(hidlngid).value = objLatLng.lng();
				document.getElementById(hidcheckid).value = 'true';
				objCPMap.showDepDesAddress(address, iconType);
				callback(parameter);				
			}
		});
	}
}


CPMap.prototype.verifyAddress = function(address, iconType, errorid, hidcheckid, hidlatid, hidlngid, error, idprocesscues) {					
	if(idprocesscues) { $('#' + idprocesscues).html("<img src='images/loading_1.gif'>");}
	geocoder = new GClientGeocoder();	
	if(geocoder) {		
		geocoder.getLatLng(address,  function(objLatLng) {			
			if(!objLatLng) 
			{
				document.getElementById(hidcheckid).value='false';
				$('#' + errorid).removeClass("errorMessagesHide");
				$('#' + errorid).addClass("errorMessages");				
				$('#' + errorid).html('');
				$('#' + errorid).html(error);
				
				if(idprocesscues) { $('#' + idprocesscues).html('');}
				
				if(iconType == 'DepType' && objCPMap.objDepMarker) {					
					objCPMap.objGDirect.clear();
					objCPMap.map.removeOverlay(objCPMap.objDepMarker);
					objCPMap.objDepMarker = null;
				}
				else if(objCPMap.objDesMarker) {
					objCPMap.objGDirect.clear();					
					objCPMap.map.removeOverlay(objCPMap.objDesMarker);
					objCPMap.objDesMarker = null;
				}
				objCPMap.journeyTime = null;
				objCPMap.journeyDistance = null;
			}
			else {
				$('#' + errorid).removeClass("errorMessages");
				$('#' + errorid).addClass("errorMessagesHide");				
				$('#' + errorid).html('');						
				if(idprocesscues) { $('#' + idprocesscues).html('');}
				
				$('#' + hidlatid).val(objLatLng.lat());					
				$('#' + hidlngid).val(objLatLng.lng());					
				$('#' + hidcheckid).val('true');					
				
				if(iconType == 'DepType') {
					if(objCPMap.objDepMarker != null && objCPMap.objDepMarker.getLatLng().lat() == objLatLng.lat() && objCPMap.objDepMarker.getLatLng().lng() == objLatLng.lng()) {
						if(objCPMap.objDepMarker && objCPMap.objDesMarker) {
							objCreateCarpool.stepSaveCarpool(3);
						}
						//return;
					}				
				}
				else if(iconType == 'DesType') {
					if(objCPMap.objDesMarker != null && objCPMap.objDesMarker.getLatLng().lat() == objLatLng.lat() && objCPMap.objDesMarker.getLatLng().lng() == objLatLng.lng()) {
						if(objCPMap.objDepMarker && objCPMap.objDesMarker) {
							objCreateCarpool.stepSaveCarpool(3);
						}
						//return;
					}				
				}				
				
				objCPMap.showDepDesAddress(address, iconType);	
				
				$('#divTimeDistance').html('');	
				$('#idErrorMessages2').html('');
				$('#idErrorNotFoundRoute').html('');
				$('#idErrorNotFoundRoute').css({display:''});
				$('#idErrorMessages2').css({display:''});
				
				$('#txtJourneyTime').val('');	
				$('#txtJourneyDistance').val('');	
				
				setTimeout("$('#idErrorNotFoundRoute').html('"+ objCreateCarpool.arrErrors[14] +"')", 3000);					
				
				GEvent.addListener(objCPMap.objGDirect, 'load', function() {	
					
					$('#idErrorNotFoundRoute').css({display:'none'});
					
					if(objCPMap.objGDirect.getDuration())																 
					{
						if(objCPMap.objGDirect.getDuration().seconds) 
						{																		 
								var seconds = objCPMap.objGDirect.getDuration().seconds;
								var hour = parseInt(seconds/3600,10);
								var minus = hour > 0 ? parseInt((seconds - hour * 3600) / 60,10) : parseInt(seconds /60,10);
								if(minus > 0 && minus <= 15) minus = 15;
								else if(minus > 15 && minus <= 30) {
									minus = 30;
								}
								else if(minus > 30 && minus <= 45) minus = 45;
								else if(minus > 45) {
									minus = 00;
									++hour;
								}
								else { minus = 00; }															
								objCPMap.journeyTime = (hour.toString().length == 1 ? '0' + hour.toString() : hour) + ':' + (minus.toString().length == 1 ? '0' + minus.toString() : minus);									
								if(objCPMap.journeyTime) {									
									$('#txtJourneyTime').val(objCPMap.journeyTime);								
								}
						}						
						if(objCPMap.objGDirect.getDistance().meters) {			
							var intKm = Math.round(objCPMap.objGDirect.getDistance().meters / 1000);
							$('#txtJourneyDistance').val(intKm);												
							objCPMap.journeyDistance = intKm;
							$('#hidDistance').val(intKm);
						}
						
						objCPMap.showInforDistanceTime('divTimeDistance', intKm, objCPMap.journeyTime); //lnnam create 28/06/2008
					}
					if(objCPMap.objDepMarker && objCPMap.objDesMarker)
						objCreateCarpool.stepSaveCarpool(3);	
				});		
			}		
		});	
	}		
}

CPMap.prototype.showInforDistanceTime = function(div, Distance, Time) {
	var strTimeDistance = '';
	if(Distance && Time) {
		strTimeDistance += Distance + " km ";
		var arrTime = Time.split(':');
		if(arrTime[0] != '00') strTimeDistance += arrTime[0] + ' hours ';
		if(arrTime[1]) strTimeDistance += arrTime[1] + ' minutes ';
		$('#' + div).html(strTimeDistance);								
	}
}

CPMap.prototype.showHelp = function(tabNum) {
	opened = 'yes';
	var objLatLng = this.map.getBounds().getSouthWest();
	var tempLatLng = this.objCurentLatLng;		
	//var objLatLngCenter = this.map.getCenter();
	
	tempLatLng = new GLatLng(objLatLng.lat()-0.01, tempLatLng.lng()-0.1);
	
	var objGSize = this.map.getSize();	
	this.jsAllAboutContent.tabNum = tabNum;	
	if(objGSize.width > 764) {
		if(this.sizePopupAboutUs == null) this.sizePopupAboutUs = 764;		
	} else {
		if(this.sizePopupAboutUs == null) this.sizePopupAboutUs = objGSize.width;		
	}
	
	if(this.objLatLngPopupAboutUs == null)		this.objLatLngPopupAboutUs = tempLatLng;
	
	if(!document.getElementById('idWelcome')) {
			
		objCPMap.map.openInfoWindowHtml(this.objLatLngPopupAboutUs, "<div style='width:" + (this.sizePopupAboutUs - 150) + "px;height:340px;' ><div class='font_allabout_title'>About Us</div><div class='breakline_orange_allabout'></div> <div id='idWelcome'><br/><img src='images/loading_line.gif' style='width:100px; height:13px'></div></div>" );		
		setTimeout('objCPMap.loadAllAboutCommute()', 2000);
		
	}
    	
	if(this.jsAllAboutContent.minContent != undefined) {
		$("#idWelcome").html(this.jsAllAboutContent.minContent);
		changeAboutUSMenu(tabNum);
	}
}

CPMap.prototype.loadAllAboutCommute = function() {	
	if(!ajaxObj) {
		ajaxObj = new XMLHTTP("lib/mybic_server.php");
	}	
	ajaxObj.format = "TEXT";
	ajaxObj.method = "GET";		
	ajaxObj.call('action=LoadAllAboutCarpool&tabNum=0', function (resp) {						 
		if(resp) {		
			if(objCPMap.jsAllAboutContent.minContent) return; // Lnnam fixed bugs 28/07/2008
			objCPMap.jsAllAboutContent.minContent = resp;
			if(document.getElementById("idWelcome") != null) {
				document.getElementById("idWelcome").innerHTML = resp;
			}
			else if(document.getElementById("idAllAboutCarpool") != null) {
				document.getElementById("idAllAboutCarpool").innerHTML = resp;
			}			
		} else {
			alert('error');
		}												   
	});	
}

CPMap.prototype.loadJourneyTime = function(id) {
		GEvent.addListener(this.objGDirect, 'load', function(){
		var seconds = objCPMap.objGDirect.getDuration().seconds;
		var hour = parseInt(seconds/3600,10);
		var minus = hour > 0 ? parseInt((seconds - hour * 60) / 60,10) : parseInt(seconds /60,10);
		objCPMap.journeyTime = (hour.toString().length == 1 ? '0' + hour.toString() : hour) + ':' + (minus.toString().length == 1 ? '0' + minus.toString() : minus);
		if(id)
			$("'#" + id + "'").val(objCPMap.journeyTime);
	});	
}

CPMap.prototype.showUploadPhoto = function() {
	objCPMap.map.closeInfoWindow(); 
	var functionName = "loadJsonPage(\"LoadFormPhoto\", \"javascript/photo.js\", \"idPhoto\")"
	objCPMap.map.openInfoWindowHtml(this.objCurentLatLng, "<div style='width:400px;height:320px;'><div class='font_allabout_title'>Manage Photos</div><div class='breakline_orange_allabout'></div><div id='idPhoto'><br/><img src='images/loading_line.gif' style='width:100px; height:13px' onload='"+ functionName +"'></div></div>" );		
}

CPMap.prototype.showUploadPhotoLogin = function() {
	objCPMap.map.closeInfoWindow(); 	
	objCPMap.map.openInfoWindowHtml(this.objCurentLatLng, "<div style='width:400px;height:320px;'><div class='font_allabout_title'>Add Photos</div><div class='breakline_orange_allabout'></div><div id='idPhoto'><br/><img src='images/loading_line.gif' style='width:100px; height:13px' onload=' loadJsonPage(\"LoadFormPhotoLogin\", \"javascript/photo.js\", \"idPhoto\")'></div></div>" );		
}

CPMap.prototype.showPrivacy = function() {	
	objCPMap.map.closeInfoWindow(); 	
	var objGSize = this.map.getSize();	
	if(objGSize.width > 764) {
		if(this.sizePopupAboutUs == null) this.sizePopupAboutUs = 764;		
	} else {
		if(this.sizePopupAboutUs == null) this.sizePopupAboutUs = objGSize.width;		
	}
	var functionName = "loadJsonPage(\"LoadPrivacyContent\", null, \"idPrivacy\")";
	objCPMap.map.openInfoWindowHtml(this.objCurentLatLng, "<div style='width:" + (this.sizePopupAboutUs - 140) + "px;height:320px;' ><div id='idPrivacy'><br/><img src='images/loading_line.gif' style='width:100px; height:13px' onload='"+ functionName +"'></div></div>" );		
}

CPMap.prototype.showCarbonCalculator= function() {
	objCPMap.map.closeInfoWindow(); 		
	var functionName = "loadJsonPage(\"LoadCarbonCalculator\", null, \"idCarbonCalculator\")";
	var strLoadFormCarbon = "<br/><img src='images/loading_line.gif' style='width:100px; height:12px' onload='"+ functionName +"'>";
	objCPMap.map.openInfoWindowHtml(this.objLatLngPopupAboutUs, "<div id=idCarbonCalculator style='width:514px;height:320px;' >"+ strLoadFormCarbon +"</div>" );		
}

/*Lnnam create 11/05/2009 */
CPMap.prototype.mapPopup = function(LatLng, width, height, action, url) {
	objCPMap.map.closeInfoWindow(); 		
	var opts = { onOpenFn  : tfn()}; //fix problem happen while internet so slow
	function tfn() { 
		if(action) setTimeout('loadJsonPage("'+action+'", null, "idMapPopup")',2000);
		if(url) setTimeout('loadPage("'+url+'", "idMapPopup")',2000);
	}
	objCPMap.map.openInfoWindowHtml(LatLng, "<div id=idMapPopup style='width:"+width+"px;height:"+height+"px' ><img src='images/loading_line.gif' style='width:100px; height:12px' /></div>",opts);		

}