function CreateCarpool()
{
	objCPMap = new CPMap();
	objCPMap.loadDefaultMap();		
	this.arrErrors = null;
}

CreateCarpool.prototype.fillCreateCarpool = function()
{
	if(document.getElementById("rdDaily").checked) {
		this.displayScheduleDiv('divDaily','divDailyDep');
	}	

	if(document.getElementById("rdOnceOff").checked) {
		this.displayScheduleDiv('divOnceOff','divOnceOffDep');
	}	
	
	if(document.getElementById('rdRecurr').checked) {
		this.displayScheduleDiv('divRecurr','divRecurrDep');
	}
}

CreateCarpool.prototype.displayScheduleDiv = function(DisplayDivOneWay, DisplayDivReturn) {
	$("#idErrorMessages3").html(''); //Hide error Lnnam change 05/07/2008
	document.getElementById('divDaily').style.display = 'none';	
	document.getElementById('divOnceOff').style.display = 'none';
	document.getElementById('divRecurr').style.display = 'none';	
	document.getElementById(DisplayDivOneWay).style.display = '';
	if(document.getElementById('chkReturn').checked) {		
		if(DisplayDivReturn == 'divRecurrDep') {
			this.rdRecurr('');
		}
		else {
			document.getElementById(DisplayDivReturn).style.display = '';
		}				
		document.getElementById(DisplayDivOneWay + 'Title').style.display = '';
	}
	else {
		if(DisplayDivReturn == 'divRecurrDep') {
			this.rdRecurr('none');
		}
		else {
			document.getElementById(DisplayDivReturn).style.display = 'none';			
		}
		document.getElementById(DisplayDivOneWay + 'Title').style.display = 'none';
	}
}

CreateCarpool.prototype.clickReturn = function() {
	if(document.getElementById("rdDaily").checked) {
		this.displayScheduleDiv('divDaily','divDailyDep');
	}	

	if(document.getElementById("rdOnceOff").checked) {
		this.displayScheduleDiv('divOnceOff','divOnceOffDep');
	}	
	
	if(document.getElementById('rdRecurr').checked) {
		this.displayScheduleDiv('divRecurr','divRecurrDep');
	}
}

CreateCarpool.prototype.rdRecurr = function(display) {
	for(var i = 1; i < 8; i++) {
		document.getElementById('divRecurrDep' + i).style.display = display;
	}
}

CreateCarpool.prototype.showUnSaveMatches = function() {	
	/*hidden create carpool form*/	
	$('#idLeftSideBar').css({display:'none'});	
	$('#idUnsaveMatches').css({display:''});
	/*load content unsave matches*/
	/*$('#idUnsaveMatches').html("<br><div align='center' class='processing'><img src='images/loading_1.gif' width='20' height='20'>getting matches...</div>");	*/																		   
	loadJsonPage("LoadUnSaveCarpool", null, "idUnsaveMatches");	
	ajaxObj.format = "JSON";
	ajaxObj.method = "POST";	
	var form_vars = ajaxObj.getForm('formCreateCarpool');
	ajaxObj.call('action=LoadUnSaveMatches' + form_vars, function(resp) {		
		if(resp) {
			objCreateCarpool.showMatches(resp);
			$('#processing').css({display:'none'});
		}
		else { alert('error');}											   
	});
}

CreateCarpool.prototype.showMatches = function(resp) {
	var depLatLng = resp.depLatLng.split(',');		  		
	var desLatLng = resp.desLatLng.split(',');
	var arrMatches = resp.Matches;
	var idContentMatches = document.getElementById("contentMatches");
	var matchCategory = "contentMatches";
	//objCPMap.map.clearOverlays();	
	idContentMatches.innerHTML = ""; 
	
	//if no match
	if(!resp.Matches) {
		//$("#processing-loadmatch").html('');
		document.getElementById('processing-loadmatch').style.display = 'none';
		return;
	}	
	
	for(var i = 0; i < arrMatches.length; i++) {
		var strMessage = '';
		if(arrMatches[i].MessagesSent || arrMatches[i].MessagesReceived) {
			strMessage += "<div class='title'>(" + arrMatches[i].MessagesSent;
			if(arrMatches[i].MessagesReceived)												
				strMessage += (arrMatches[i].MessagesSent ? ", " : "") + arrMatches[i].MessagesReceived;
			strMessage += ")</div>";				
		}
		
		idContentMatches.innerHTML += "<div class='listMatch'>"
									  + "<div id='outer_" + matchCategory + "_ViewDetail" +  (i+1) + "'>" 
									  + (i+1) + ". " 
									  + arrMatches[i].ScreenName + " " 									  
									  + arrMatches[i].DriverPassengerEither + " " 									  

									  + (arrMatches[i].Rating ? ", " : "") + arrMatches[i].Rating + "</div>"
									  + strMessage
									  + "<div><a href='##' id='" + matchCategory + "_ViewDetail" +  (i+1) + "' class='color_green'>more info</a></div></div>";					  
	}			

	for(var i = 0; i < arrMatches.length; i++) {
		objCPMap.showPairOfMatches(matchCategory + "_Icon" +  (i+1), matchCategory + "_ViewDetail" +  (i+1), new GLatLng(arrMatches[i].PickupLat, arrMatches[i].PickupLong), new GLatLng(arrMatches[i].DesLat, arrMatches[i].DesLong), "Match" + arrMatches[i].DriverPassengerEither, (i+1), arrMatches[i].CarpoolKeyMatch, arrMatches[i], arrMatches[i].MatchCategoryDesc, arrMatches[i].ScreenName, arrMatches[i].Rating, arrMatches[i], "LoadUnSaveMatcheDetail");							
	}
	document.getElementById('processing-loadmatch').style.display = 'none';
}

function validateCreateCarpool(isSave) {
	$('#processing').css({display:''});
	if($("#selOnceOffArr").val()){ objCreateCarpool.stepSaveCarpool(4, false);}
	var sErrors = '';
	objCreateCarpool.validateAddress();
	sErrors = objCreateCarpool.stepSaveCarpool(3);		
	if(sErrors){ $('#processing').css({display:'none'}); return };
	sErrors = objCreateCarpool.stepSaveCarpool(4,true);			
	if(sErrors){ $('#processing').css({display:'none'}); return };
	sErrors = objCreateCarpool.stepSaveCarpool(5);
	if(sErrors){ $('#processing').css({display:'none'}); return };	
	if(isSave)
		saveCreateCarpool('SaveCreateCarpool','javascript/createcarpool.js');								
	else 
		objCreateCarpool.showUnSaveMatches();
}


CreateCarpool.prototype.validateAddress = function() 
{
	var objDepCountry = $("#selDepartureCountry").val().split(':');	
	var objDesCountry = $("#selDestinationCountry").val().split(':');	
	strDeparttureAddress = $("#txtDepartureAdd").val() + ',' + objDepCountry[0];
	strDestinationAddress = $("#txtDestinationAdd").val() + ',' + objDesCountry[0];
	
	if(!trim($("#txtDepartureAdd").val())) {
		$('#idErrorMessages20').removeClass("errorMessagesHide");
		$('#idErrorMessages20').addClass("errorMessages");				
		$('#idErrorMessages20').html(this.arrErrors[0]);
		$('#processing').css({display:'none'});
		return ;
	}	
	if(!trim($("#txtDestinationAdd").val())) {
		$('#idErrorMessages20').html('');
		$('#idErrorMessages21').removeClass("errorMessagesHide");
		$('#idErrorMessages21').addClass("errorMessages");				
		$('#idErrorMessages21').html(this.arrErrors[0]);
		$('#processing').css({display:'none'});
		return ;
	}
			
	objCPMap.verifyAddress(strDeparttureAddress, 'DepType','idErrorMessages20','hidCheckDep','hidLatDep','hidLngDep', this.arrErrors[0], 'idProcessCues_Address');								
	objCPMap.verifyAddress(strDestinationAddress, 'DesType','idErrorMessages21','hidCheckDest','hidLatDest','hidLngDest', this.arrErrors[0], 'idProcessCues_Address');	
		
}
//edit by ttson 05/06/08

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
//edit by ttson 05/06/08
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

//edit by ttson 05/06/08
function checkTime(getStatus, s) { 
	var trimmed = s.replace(/^\s+|\s+$/g, '') ;
	var timetext;
	if (trimmed.length == 11)
	{
		timetext = Left(trimmed,8);
	}
	else {
		timetext = Left(trimmed,7);
	}
	var values = timetext.split(":");
	if (getStatus == 0)
	{
		return values[0];
	}
	if (getStatus == 1)
	{
		//return values[1];
		return String(trimmed).substring(3, 5); //Lnnam fix 27/09/2008
	}
	if (getStatus == 2)
	{
		return Right(trimmed,2);
	}
}

//edit by ttson 05/06/08
function getJourneyTime(getStatus, s)
{
	var trimmed = s.replace(/^\s+|\s+$/g, '') ;
	var values = trimmed.split(":");	
	if (getStatus ==0)
		return values[0]
	else if (getStatus ==1)
		return values[1];
}

CreateCarpool.prototype.stepSaveCarpool = function(intStep, isGoStept4) {
	var sErrors = '';
	var sErrorAdd = this.arrErrors[0];
	var sErrorLeast1 = this.arrErrors[1];
	var sErrorArr = this.arrErrors[2];
	var sErrorDep = this.arrErrors[3];
	var sErrorGTJourneyTime = this.arrErrors[4];
	var sErrorArrLTDepTime = this.arrErrors[5];
	var sErrorsJourneyDistance = this.arrErrors[6];
	var sErrorsRecJourneyTime = this.arrErrors[7];
	var sErrorsRecJourneyDistance = this.arrErrors[8];
	var sErrorStartDateBlank = this.arrErrors[9];
	var sErrorStartDateInvalid = this.arrErrors[10];
	var sErrorStartDateLTOld = this.arrErrors[11];
	var sErrorStartDateLTCur = this.arrErrors[12];
	var sErrorCarpoolName = this.arrErrors[13];
	var arrDay = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
	switch(intStep) {		
		case 3:						
			if($("#hidCheckDep").val() == 'false' || $("#hidCheckDest").val() == 'false') {				
				return;															
			}
			else {				
				$('#idJourney').removeClass('hideScroll');
				//if(isNaN($("#txtJourneyDistance").val()) || $("#txtJourneyDistance").val() == '') sErrors += sErrorsJourneyDistance;
				if($("#txtJourneyDistance").val() == '') 
					sErrors += sErrorsJourneyDistance; //Lnnam change 28/06/2008
				else {
					
					if(!objCPMap.journeyTime || !objCPMap.journeyDistance) {
						$("#txtJourneyTime").val('');
						$("#txtJourneyDistance").val('')
						sErrors +=   sErrorsJourneyDistance; //lnnam change 27/06/2008
						$('#processing').css({display:'none'}); //Lnnam change  20/06/2008									
					}
					else
					{
						var fltCurrentJourneyDistance = parseFloat($("#txtJourneyDistance").val());
						var fltJourneyDistance = parseFloat(objCPMap.journeyDistance);
						var ftlJourneyDisMin = fltJourneyDistance - parseFloat($("#hidParJourneyDistance").val()) * fltJourneyDistance;
						var fltJourneyDisMax = fltJourneyDistance + parseFloat($("#hidParJourneyDistance").val()) * fltJourneyDistance;
						if(fltCurrentJourneyDistance < ftlJourneyDisMin || fltCurrentJourneyDistance > fltJourneyDisMax)
							sErrors += sErrorArrLTDepTime;
					}
				}
			}			
			if(!sErrors) $("#idGo").html('');
			break;		
		case 4:
			// if go in step 4 is click and single date is selected
			if(document.getElementById("rdOnceOff").checked)
			{
				
				/*if(isGoStept4 && document.getElementById("rdOnceOff").checked && document.getElementById('idTblSingleDate').rows.length < 2) {
					sErrors += sErrorLeast1;
					break;
				}
				else if(isGoStept4 && document.getElementById("rdOnceOff").checked && document.getElementById('idTblSingleDate').rows.length >= 2) {
					break;
				}*/
				if(isGoStept4 && document.getElementById("rdOnceOff").checked && document.getElementById('idTblSingleDate').rows.length >= 2) break;
				// validate date
				if($('#txtStartDate').val() == "") {
					sErrors += sErrorStartDateBlank;
				}
				else {
					if(!isDate($('#txtStartDate').val()))
						sErrors += sErrorStartDateInvalid;
					else { 
						if(typeof $('#hidDepartureAddKey').val() != 'undefined' 
							&& typeof $('#hidDestinationAddKey') != 'undefined') {				
							if(!isDateGE($('#txtStartDate').val(),$('#txtStartOldDate').val()))
								sErrors += sErrorStartDateLTOld;					
						}
						else if(!isGreaterThanCurrentDate($('#txtStartDate').val()))			
							sErrors += sErrorStartDateLTCur;				
					}
				}
				
			} 
			
			// atleast 1  input time
			if(document.getElementById("rdDaily").checked) {
				
				if(isTimeEntryAllBlank('selDailyArr') || isTimeEntryBlank('selDailyArr'))			
					sErrors += sErrorArr;
				if(document.getElementById('chkReturn').checked && (isTimeEntryAllBlank('selDailyDep') || isTimeEntryBlank('selDailyDep')))
					sErrors += sErrorDep;
				if(document.getElementById('chkReturn').checked && !isTimeEntryAllBlank('selDailyArr') && !isTimeEntryAllBlank('selDailyDep')) {
					/*var arrArrTime = [parseInt($('#selDailyArr').val(),10),parseInt($('#selDailyArr').val(),10),$('#selDailyArr').val()];
					var arrDesTime = [parseInt($('#selDailyDep').val(),10),parseInt($('#selDailyDep').val(),10),$('#selDailyDep').val()];*/
					//edit by ttson 05/06/08
					var arrArrTime = [checkTime(0,$('#selDailyArr').val()),checkTime(1,$('#selDailyArr').val()),checkTime(2,$('#selDailyArr').val())];
					var arrDesTime = [checkTime(0,$('#selDailyDep').val()),checkTime(1,$('#selDailyDep').val()),checkTime(2,$('#selDailyDep').val())]; 
					//var arrJouTime = [parseInt($('#selJourneyTime').val(),10),parseInt($('#selJourneyTime').val(),10)];
					var arrJouTime = [parseInt(getJourneyTime(0,$('#txtJourneyTime').val()),10),parseInt(getJourneyTime(1,$('#txtJourneyTime').val()),10)];
					if(!isValidArrDepTime(arrArrTime,arrDesTime)) {
						sErrors += sErrorArrLTDepTime;											
					}
					else if(!isGTJourneyTime(arrArrTime,arrDesTime,arrJouTime)) {
						sErrors += sErrorGTJourneyTime;
						break;																
					}
				}					
			}	
			else if(document.getElementById("rdOnceOff").checked) {
				if(isTimeEntryAllBlank('selOnceOffArr') || isTimeEntryBlank('selOnceOffArr'))			
					sErrors += sErrorArr;
				if(document.getElementById('chkReturn').checked && (isTimeEntryAllBlank('selOnceOffDep') || isTimeEntryBlank('selOnceOffDep')))
					sErrors += sErrorDep;
				if(document.getElementById('chkReturn').checked && !isTimeEntryAllBlank('selOnceOffArr') && !isTimeEntryAllBlank('selOnceOffDep')) {
					/*var arrArrTime = [parseInt($('#selOnceOffArr').val(),10),parseInt($('#selOnceOffArr').val(),10),$('#selOnceOffArrAMPM').val()];
					var arrDesTime = [parseInt($('#selOnceOffDep').val(),10),parseInt($('#selOnceOffDep').val(),10),$('#selOnceOffDepAMPM').val()];*/
					//edit by ttson 05/06/08
					var arrArrTime = [checkTime(0,$('#selOnceOffArr').val()),checkTime(1,$('#selOnceOffArr').val()),checkTime(2,$('#selOnceOffArr').val())];
					var arrDesTime = [checkTime(0,$('#selOnceOffDep').val()),checkTime(1,$('#selOnceOffDep').val()),checkTime(2,$('#selOnceOffDep').val())]; 
					var arrJouTime = [parseInt(getJourneyTime(0,$('#txtJourneyTime').val()),10),parseInt(getJourneyTime(1,$('#txtJourneyTime').val()),10)];
					
					if(!isValidArrDepTime(arrArrTime,arrDesTime)) {
						sErrors += sErrorArrLTDepTime;											
					}
					else if(!isGTJourneyTime(arrArrTime,arrDesTime,arrJouTime)) {
						sErrors += sErrorGTJourneyTime;
						break;																
					}
				}					
			}	
			else if(document.getElementById('rdRecurr').checked) {
				//all blank
				var isAllBlank = true;
				for(var i = 0; i < arrDay.length; i++) {
					if(!isTimeEntryAllBlank('selRecurr' + arrDay[i] + 'Arr')) {
						isAllBlank = false;						
						break;
					}		
						
					if(document.getElementById('chkReturn').checked && !isTimeEntryAllBlank('selRecurr' + arrDay[i] + 'Dep')) {
						isAllBlank = false;						
						break;						
					}
				}
				
				if(isAllBlank)
					sErrors += sErrorLeast1;				
				else {	// 1 compobox is blank
					for(var i = 0; i < arrDay.length; i++) {
						//Lnnam fixed bug 5/7/2008
						/*if(isTimeEntryBlank('selRecurr' + arrDay[i] + 'Arr')) {
							sErrors += sErrorArr;
							break;
						}		
							
						if(document.getElementById('chkReturn').checked && isTimeEntryBlank('selRecurr' + arrDay[i] + 'Dep')) {
							sErrors += sErrorDep;
							break;						
						}*/
						
						if(document.getElementById('chkReturn').checked && !isTimeEntryAllBlank('selRecurr' + arrDay[i] + 'Arr') && !isTimeEntryAllBlank('selRecurr' + arrDay[i] + 'Dep')) {
						/*	var arrArrTime = [parseInt($('#selRecurr' + arrDay[i] + 'Arr').val(),10),parseInt($('#selRecurr' + arrDay[i] + 'Arr').val(),10),$('#selRecurr' + arrDay[i] + 'Arr').val()];
							var arrDesTime = [parseInt($('#selRecurr' + arrDay[i] + 'Dep').val(),10),parseInt($('#selRecurr' + arrDay[i] + 'Dep').val(),10),$('#selRecurr' + arrDay[i] + 'Dep').val()];
							*/
							//edit by ttson 05/06/08
						
						var arrArrTime = [checkTime(0,$('#selRecurr' + arrDay[i] + 'Arr').val()),checkTime(1,$('#selRecurr' + arrDay[i] + 'Arr').val()),checkTime(2,$('#selRecurr' + arrDay[i] + 'Arr').val())];
						var arrDesTime = [checkTime(0,$('#selRecurr' + arrDay[i] + 'Dep').val()),checkTime(1,$('#selRecurr' + arrDay[i] + 'Dep').val()),checkTime(2,$('#selRecurr' + arrDay[i] + 'Dep').val())];
						var arrJouTime = [parseInt(getJourneyTime(0,$('#txtJourneyTime').val()),10),parseInt(getJourneyTime(1,$('#txtJourneyTime').val()),10)];
							
							if(!isValidArrDepTime(arrArrTime,arrDesTime)) {
								sErrors += sErrorArrLTDepTime;			
								break;
							}
							else if(!isGTJourneyTime(arrArrTime,arrDesTime,arrJouTime)) {
								sErrors += sErrorGTJourneyTime;
								break;																
								
							}
						}
					}
				}
			}			
			// validate with journey time
			break;		
		case 5:
			if($('#txtCarpoolName').val() == "")
				sErrors += sErrorCarpoolName;
			break;
	}
	
	/*if(sErrors == '') {
		$("#idCCStep" + intStep).removeClass('hideScroll');			
	}*/
	if(sErrors == '') {
		$('#idErrorMessages' + (intStep-1)).removeClass("errorMessages");		
		$('#idErrorMessages' + (intStep-1)).addClass("errorMessagesHide");
		$('#idErrorMessages' + (intStep-1)).html('');		
		if(intStep == 4 && isGoStept4 == false) {
			this.addSingleDay();			
		}
		else {
			if(intStep == 4 && isGoStept4 == true) {
				document.getElementById('idGoStep4').style.display = 'none';
			}
			$("#idCCStep" + intStep).removeClass('hideScroll');			
		}
	}
	else {
		$('#idErrorMessages' + (intStep-1)).removeClass("errorMessagesHide");
		$('#idErrorMessages' + (intStep-1)).addClass("errorMessages");
		$('#idErrorMessages' + (intStep-1)).html('');
		$('#idErrorMessages' + (intStep-1)).html(sErrors);	
		
	}		
	return sErrors;
}
//edit by ttson 08/06/11
CreateCarpool.prototype.addSingleDay = function() {
	$('#hidEdit').val('add'); 
	if(document.getElementById('chkReturn').checked == false)
	{
		$('#selOnceOffDep').val('');
		
	}
	<!--lnnam create proccess cue 20/06/2008-->	
	$("#processing_singleday").html("<img src='images/loading_4.gif'>");
	postForm('formCreateCarpool', 'AddSingleDay', 'divListDate', 'processing_singleday');		
}

CreateCarpool.prototype.editSingleDay = function(SingleDate, TimeDestination, TimeLeaveOnReturnTrip, remove) {
	$("#processing_singleday").html("<img src='images/loading_4.gif'>");							
	$('#hidEdit').val('edit'); 
	$('#txtStartDate').val(SingleDate);
	$('#selOnceOffArr').val(TimeDestination);
	if(TimeLeaveOnReturnTrip)
	{			
		document.getElementById('divOnceOffTitle').style.display = '';	
		document.getElementById('divOnceOffDep').style.display = '';
		document.getElementById('chkReturn').checked = true ;		
		$('#selOnceOffDep').val(TimeLeaveOnReturnTrip);
	}
	else 
		{		
			document.getElementById('divOnceOffDep').style.display = 'none';
			document.getElementById('chkReturn').checked = false;
			$('#selOnceOffDep').val('');
		}
	if(remove == 'true') {
		$('#selOnceOffDep').val('');
		$('#selOnceOffArr').val('');
		$('#hidRemove').val('true');
	} else $('#hidRemove').val('false');
	postForm('formCreateCarpool', 'AddSingleDay', 'divListDate', 'processing_singleday');		
}

function changeLeftMenu(idSelected) {
	$("#idCreateCommute, #idMenuMyCarpool, #idMyAccount").removeClass("color_lightgreen");
	$("#idCreateCommute, #idMenuMyCarpool, #idMyAccount").addClass("color_white_bold");
	$("#" + idSelected).removeClass("color_white_bold");
	$("#" + idSelected).addClass("color_lightgreen");
	if(idSelected == 'idCreateCommute') {$("#idCreateCommute").html("Cancel Commute");}
	else{$("#idCreateCommute").html("Create Commute");}
}

function saveCreateCarpool(action,scripturl) {	
	ajaxObj.format = "TEXT";
	ajaxObj.method = "POST";		
	var form_vars = ajaxObj.getForm('formCreateCarpool');
	ajaxObj.call('action=SaveCreateCarpool' + form_vars, function(resp) {	
		$('#processing').css({display:'none'});
		if(resp == 'false')
		{
			loadPage('pages/joining/tpl/checkemail.tpl','sidecontent');
			objCPMap.loadDefaultMap();
		}
		else {
			if(resp != 'true') {
				objMyCarpool.loadListCarpool(true, resp);
			}
			else {
				objMyCarpool.loadListCarpool(true);
			}
		}
	});	
}

/*function findValue(li) {
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
}

function selectItem(li) {
	findValue(li);
}
*/

function genTimeEntry(idHTML, idControl, arrValue, arrDropTime) 
{		
	
	/*if(arrDropTime)
	{
		
		if(arrValue == 'null') arrValue = '';
			$('#' + idControl ).timePicker(); 
	}*/
	
}

/*End Change Time Picker*/

var bCallHelp = false;

if(!objCreateCarpool) { bCallHelp = true; }

var objCreateCarpool = objCreateCarpool ? objCreateCarpool : new CreateCarpool();

if(!objCPMap) objCPMap = new CPMap(); 

//objCPMap.loadDefaultMap();
opened = 'no';

if(bCallHelp) {
	var url = window.location;	
	if(StatusLogin == false) //Lnnam change 25/06/2008
		setTimeout("delayPopupAboutUS()", 9000);
//	window.location = "http://www.thedailycommute.com.au/##";	
}

function delayPopupAboutUS() {
	if(opened == 'no') objCPMap.showHelp(0);
	return;
}
//Lnnam create 07/07/2008
function getCountryKeyfromAddress(strAddress, arrAddress, arrCountryKey) {
	for(i = 0; i < arrAddress.length; i++) {
		var temp = trim(strAddress.toLowerCase());
		if(temp == arrAddress[i].toLowerCase())
			return arrCountryKey[i];
	}
}

function loadCountryfromAddres(strAddress, arrAddress, arrCountryKey, idSelect) {
	var intCountryKey = getCountryKeyfromAddress(strAddress, arrAddress, arrCountryKey);
	if(!intCountryKey) return;
	//var selbox = document.forms['formCreateCarpool'].selDepartureCountry;
	var selbox = document.getElementById(idSelect);
    for(i = 0; i < selbox.length; i++)
    {	
		var intCountryKeyTemp = selbox.options[i].value.split(':');
		if(intCountryKey == intCountryKeyTemp[1]) {
			selbox.options[i].selected = true;
		}
   }
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}