function removescpecialcharacters(obj){
var str = obj.value;
while((str.indexOf('"')!=-1))
str = str.replace('"',"''");
obj.value = str ;
}


function m_dn(a){
	document.getElementById('dm'+a).style.display='block';
	document.getElementById('tn'+a).className='active';
}
function m_up(a){
	document.getElementById('dm'+a).style.display='none';
	document.getElementById('tn'+a).className='';
}

function showforgetpass(){
	$.get("forgetpassword.php",function(data){
		$.blockUI({ message: data }); 
	});
	return false;
}

function registerThankyou(data){
	$.get("register_thanks.php",function(data){
		$.blockUI({ message: data }); 
	});
	return false;
}

function quickRegPopup(data){
	$.get("quick_reg_popup.php",function(data){
		$.blockUI({ message: data });
	});
	return false;
}

function chkusername(username,errordiv){
	$("."+errordiv).html("");
	if(username != ""){
		$.get("chkusername.php",{'username':username}, function(data){
			if(data == 2){
				$("."+errordiv).html("Username can not be less than 4 characters.");
				return false;
			}else if(data == 0){
				$("."+errordiv).html("Username already taken.");
				return false;
			}
		});
	}
}

var loginCallback;
function showLoginPopup(data){
	if(data){
	loginCallback = data.callback;
	}
	//alert(loginCallback);
	$.get("login_popup.php",function(data){
		$.blockUI({ message: data }); 
	});
	return false;
}

function closePostRide(){
	window.location.reload();
	
	/*if(loginCallback){
		$.unblockUI();	
		window.location.reload();
	}else{
		$.unblockUI();
	}*/
}


function reg_quick_validate(){
	$(".errRegQ").html("");
	if($("#reg_uname").val() == "" || $("#reg_pass").val() == "" || $("#reg_repass").val() == "" || $("#reg_email").val() == ""){
		$(".errRegQ").html("All the fields marked with * are required.");
		return false;	
	}
	
	if($("#reg_uname").val().length < 4){
		$(".errRegQ").html("Username can not be less than 4 characters.");
		return false;
	}
	
	if($("#reg_uname").val().length < 4){
		$(".errRegQ").html("Please Enter Password More the 5 characters.");
		return false;
	}
	if($("#reg_pass").val() != $("#reg_repass").val()){
		$(".errRegQ").html("Password dose not match with the Retype password.");
		return false;	
	}
	
	if(validateEmail($("#reg_email").val()) == false){
		$(".errRegQ").html("Please Enter Valid Email address.");
		$("#email").focus();
		return false;								 
	}
	
	var image = $("#reg_propic").val();
	if((image != "")&&(image.lastIndexOf(".jpg") == -1 && image.lastIndexOf(".gif") == -1 && image.lastIndexOf(".jpeg") == -1)){
		$(".errRegQ").html("Please Upload only .jpg, .gif, .jpeg files only.");
		return false;
	}
	
	var terms = $("#reg_terms").is(":checked");
	if(!terms){
		$(".errRegQ").html("Please click on terms & conditions.");
		return false;
	}
}

function login(){
	var username = $.trim($("#login_username").val());
	var password = $("#login_password").val();
	
	if(username == "" || username == "Enter your Username"){
		alert("Please Enter Username.");
		$("#login_username").focus();
		return false;
	}
	
	if(password == ""){
		alert("Please Enter Password.");
		$("#login_password").focus();
		return false;
	}
	
	$.post("login2db.php",{'username':username,'password':password},function(data){
		data = eval('('+data+')');
		if(data['status'] == "ERROR"){
			alert(data['msg']);	
			return false;
		}else if(data['status'] == "SUCCESS"){
			window.location.reload();
			return false;
		}  																		 
	});
}

//var dataArr = [];
function popupLogin(){
	
	var username = $.trim($("#popup_username").val());
	var password = $("#popup_password").val();
	
	if(username == "" || username == "Enter your Username"){
		alert("Please Enter Username.");
		$("#popup_username").focus();
		return false;
	}
	
	if(password == ""){
		alert("Please Enter Password.");
		$("#popup_password").focus();
		return false;
	}
	
	$.post("login2db.php",{'username':username,'password':password},function(data){
		data = eval('('+data+')');
		if(data['status'] == "ERROR"){
			alert(data['msg']);	
			return false;
		}else if(data['status'] == "SUCCESS"){
			if(loginCallback){
				//alert(loginCallback);
				loginCallback();
			}else{
				window.location.reload();
			}
			return false;
		}  																		 
	});
}

function req_showdate2(val){
	if(val == "" || val == "no"){
		$("#req_date2").hide();
		$("#req_date1 label").html("Date");
		$("#req_ride_date2").val('');
	}else{
		$("#req_date1 label").html("Date Range From/To");
		$("#req_date2").show();
	}
}

function post_showdate2(val){
	if(val == "" || val == "no"){
		$("#post_date2").hide();
		$("#post_date1 label").html("Date");
		$("#post_ride_date2").val('');
	}else{
		$("#post_date1 label").html("Date Range From/To");
		$("#post_date2").show();
	}
}

function find_showdate2(val){
	if(val == "" || val == "no"){
		$("#find_date2").hide();
		$("#find_date_label").html("Date");
		$("#find_ride_date2").val('');
	}else{
		$("#find_date_label").html("Date Range From/To");
		$("#find_date2").show();
	}
}

function pasgr_showdate2(val){
	if(val == "" || val == "no"){
		$("#pasgr_date2").hide();
		$("#pasgr_date2_lbl").html("Date");
		$("#pasgr_date2").val('');
	}else{
		$("#pasgr_date2_lbl").html("Date Range From/To");
		$("#pasgr_date2").show();
	}
}

var post_Arr = [];
function post_a_ride(){
	if($("#post_criteria").val() == ""){
		alert("Please Select ride criteria.");
		return false;
	}	
	
	/*if($("#post_criteria").val() == '6' || $("#post_criteria").val() == '7'){
		if($("#post_evecri").val() == ""){ 
			alert("Please Select Event Category.");
			return false;
		}
		
		if($("#post_evename").val() == ""){ 
			alert("Please Select Event.");
			return false;
		}
	}
	*/
	if($("#post_from").val() == ""){
		alert("Please Enter Ride From Location.");
		return false;
	}	
	
	if($("#post_to").val() == ""){
		alert("Please Enter Ride To Location.");
		return false;
	}
	
	if($("#seats_req").val()==""){
		alert("Please Select Number Of Seats Available ..");
		return false;
	}
	
	//if($("#post_criteria").val() != '6' && $("#post_criteria").val() != '7'){
	/*if($("#post_flexible").val() == ""){
		alert("Please Select Flexiblity of Ride.");
		return false;
	}*/
	
	if($("#post_ride_date").val() == ""){
		alert("Please Enter Ride Date.");
		return false;
	}
	
	/*if($("#post_flexible").val() == "yes"){
		if($("#post_ride_date").val() == ""){
		alert("Please Enter Ride flexible Date.");
		return false;
		}
	}*/
	//}
	
	geocoder = new google.maps.Geocoder(); // creating a new geocode object
	
	// finding out the coordinates
	if (geocoder) 
	{
		geocoder.geocode( { 'address': $("#post_from").val()}, function(results, status) 
		{
			if (status == google.maps.GeocoderStatus.OK) 
			{
				//location of first address (latitude + longitude)
				post_Arr['from_lat'] = results[0].geometry.location.lat();
				post_Arr['from_lng'] = results[0].geometry.location.lng();
				
				$.each(results[0].address_components, function(index, value) { 
					if(value.types[0] == "country"){
						post_Arr['from_country'] = value.long_name;
					}
				});
				
			} else 
			{
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
		geocoder.geocode( { 'address': $("#post_to").val()}, function(results, status) 
		{
			if (status == google.maps.GeocoderStatus.OK) 
			{
				post_Arr['to_lat'] = results[0].geometry.location.lat();
				post_Arr['to_lng'] = results[0].geometry.location.lng();
				$.each(results[0].address_components, function(index, value) { 
					if(value.types[0] == "country"){
						post_Arr['to_country'] = value.long_name;
					}
				});
				
				/*$.getJSON("http://maps.googleapis.com/maps/api/directions/json?origin="+$("#post_from").val()+"&destination="+$("#post_to").val()+"&sensor=false",function(data){
				alert(data)
				});*/
				
				var request = {
					origin:$("#post_from").val(), 
					destination:$("#post_to").val(),
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				directionsService = new google.maps.DirectionsService();
				directionsService.route(request, function(response, status) 
				{
					if (status == google.maps.DirectionsStatus.OK) 
					{
						distance = response.routes[0].legs[0].distance.text;
						//distance += "<br/>The aproximative driving time is: "+response.routes[0].legs[0].duration.text;
						$.blockUI({message: '<h1><img src="images/wait.gif"  align="center"/> Please wait...</h1>',
                                                           css: { border: 'none', 
                                                                  backgroundColor: '#000', 
                                                                  '-webkit-border-radius': '10px', 
                                                                  '-moz-border-radius': '10px', 
                                                                  opacity: .4, 
                                                                  color: '#fff' 
                                                } }); 
						datastring = "from_lat="+post_Arr['from_lat']+"&from_lng="+post_Arr['from_lng']+"&from_country="+post_Arr['from_country']+"&to_lat="+post_Arr['to_lat']+"&to_lng="+post_Arr['to_lng']+"&to_country="+post_Arr['to_country']+"&distance="+distance;
				        datastring += "&"+$("#post_ride").serialize();
						$.post("post_ride2db.php",datastring,function(data){
							$.unblockUI();
							//alert(data);
							if(data == 0){
								var callback = {callback : post_a_ride};
								
								showLoginPopup(callback);
								//alert("You Must Be Login To Post a Ride.");
							}else if(data == 1){
								alert("Some Error Occured, Please Try Again.");	
							}else{
								$.blockUI({ message: data, css : { top: '5%'} }); 
								document.post_ride.reset();
							}
						});
						//alert(datastring);
					}else if(status == 'ZERO_RESULTS'){
						alert("Zero Results found for Entered Route.");
					}
				});
				
				
				
			} else 
			{
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
	
	//alert(gmapArr);
	
}

var req_Arr = [];
function req_a_ride(){
	if($("#req_criteria").val() == ""){
		alert("Please Select ride criteria.");
		return false;
	}	
	
	/*if($("#req_criteria").val() == '6' || $("#req_criteria").val() == '7'){
		if($("#req_evecri").val() == ""){ 
			alert("Please Select Event Category.");
			return false;
		}
		
		if($("#reeq_evename").val() == ""){ 
			alert("Please Select Event.");
			return false;
		}
	}*/
	
	if($("#req_from").val() == ""){
		alert("Please Enter Ride From Location.");
		return false;
	}	
	
	if($("#req_to").val() == ""){
		alert("Please Enter Ride To Location.");
		return false;
	}
	
	
	if($("#req_seats_req").val() == ""){
		alert("Please Select Number Of Seats Required.");
		return false;
	}
	
	//if($("#req_criteria").val() != '6' && $("#req_criteria").val() != '7'){

	/*if($("#req_flexible").val() == ""){
		alert("Please Select Flexiblity of Ride.");
		return false;
	}*/
	
	if($("#req_ride_date").val() == ""){
		alert("Please Enter Ride Date.");
		return false;
	}
	
/*	if($("#req_flexible").val() == "yes"){
		if($("#req_ride_date2").val() == ""){
		alert("Please Enter Ride flexible Date.");
		return false;
		}
	}
	}*/
	
	geocoder = new google.maps.Geocoder(); // creating a new geocode object
	
	// finding out the coordinates
	if (geocoder) 
	{
		geocoder.geocode( { 'address': $("#req_from").val()}, function(results, status) 
		{
			if (status == google.maps.GeocoderStatus.OK) 
			{
				//location of first address (latitude + longitude)
				req_Arr['from_lat'] = results[0].geometry.location.lat();
				req_Arr['from_lng'] = results[0].geometry.location.lng();
				
				$.each(results[0].address_components, function(index, value) { 
					if(value.types[0] == "country"){
						req_Arr['from_country'] = value.long_name;
					}
				});
				
			} else 
			{
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
		geocoder.geocode( { 'address': $("#req_to").val()}, function(results, status) 
		{
			if (status == google.maps.GeocoderStatus.OK) 
			{
				req_Arr['to_lat'] = results[0].geometry.location.lat();
				req_Arr['to_lng'] = results[0].geometry.location.lng();
				$.each(results[0].address_components, function(index, value) { 
					if(value.types[0] == "country"){
						req_Arr['to_country'] = value.long_name;
					}
				});
				
				/*$.getJSON("http://maps.googleapis.com/maps/api/directions/json?origin="+$("#req_from").val()+"&destination="+$("#req_to").val()+"&sensor=false",function(data){
				alert(data)
				});*/
				
				var request = {
					origin:$("#req_from").val(), 
					destination:$("#req_to").val(),
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				directionsService = new google.maps.DirectionsService();
				directionsService.route(request, function(response, status) 
				{
					if (status == google.maps.DirectionsStatus.OK) 
					{
						distance = response.routes[0].legs[0].distance.text;
						//distance += "<br/>The aproximative driving time is: "+response.routes[0].legs[0].duration.text;
						$.blockUI({message: '<h1><img src="images/wait.gif"  align="center"/> Please wait...</h1>',
                                                           css: { border: 'none', 
                                                                  backgroundColor: '#000', 
                                                                  '-webkit-border-radius': '10px', 
                                                                  '-moz-border-radius': '10px', 
                                                                  opacity: .4, 
                                                                  color: '#fff' 
                                                } }); 
						datastring = "from_lat="+req_Arr['from_lat']+"&from_lng="+req_Arr['from_lng']+"&from_country="+req_Arr['from_country']+"&to_lat="+req_Arr['to_lat']+"&to_lng="+req_Arr['to_lng']+"&to_country="+req_Arr['to_country']+"&distance="+distance;
				
						datastring += "&"+$("#req_ride").serialize();
						$.post("req_ride2db.php",datastring,function(data){
							$.unblockUI();
							//alert(data);
							if(data == 0){
								var callback = {callback : req_a_ride};
								
								showLoginPopup(callback);
								//alert("You Must Be Login To req a Ride.");
							}else if(data == 1){
								alert("Some Error Occured, Please Try Again.");	
							}else{
								$.blockUI({ message: data, css : { top: '5%'} }); 
								document.req_ride.reset();
							}
						});
						//alert(datastring);
					}
				});
				
				
				
			} else 
			{
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
	
	//alert(gmapArr);
	
}

function show_find_loc(val,flag){
	if(val != ""){
		criteria = $("#find_criteria").val();
		criteria_text = $("#find_criteria option:selected").text().split("to");
		if(criteria == 6 || criteria == 7){	
			criteria_text[0] = criteria_text[0]+" Location";
			criteria_text[1] = criteria_text[1]+" Location";
		}else{
			$("#find_to_cont").show();
			$("#find_frm_cont").show();
			$("#findeventCri").hide();
			$("#find_to_event_country").hide();
			$("#find_from_event_country").hide();
			$("#findeventCountry").hide();
			if(flag == 'cri'){
				$("#find_frmctry").html('<option value="">Select From Country</option>');
				$("#find_toctry").html('<option value="">Select To Country</option>');	
			}
			eventCat = $("#find_evecri").val(''); 
		}
		eventCat = $("#find_evecri").val(); 
		
		$.get("get_find_location.php",{'search' : val, criteria : criteria ,flag : flag, eventCat : eventCat},function(data){
			data = eval('('+data+')');
			if(data.flag == 'cri'){
				
				$("#find_frmctry").attr("disabled","disabled");
				$("#find_toctry").attr("disabled","disabled");
				$("#find_frmctry").html('<option value="">Select From Country</option>');
				$("#find_toctry").html('<option value="">Select To Country</option>');
				$("#find_frmloc_cont").html("");
				$("#find_toloc_cont").html("");
				if(data.from_count > 0){
					$.each(data.from_country, function(index, value){
						$("#find_frmctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#find_frmctry").attr("disabled","");
				}
				
				if(data.to_count > 0){
					$.each(data.to_country, function(index, value){
						$("#find_toctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#find_toctry").attr("disabled","");
				}
				
				if(data.from_count == 0){
					$("#find_frmctry").html('<option value="">No postings...Post a request</option>');
					$("#find_frmctry").attr("disabled","disabled");
					$("#find_toctry").attr("disabled","disabled");
				}
				
				if(data.to_count == 0){
					$("#find_toctry").html('<option value="">No postings...Post a request</option>');
					$("#find_frmctry").attr("disabled","disabled");
					$("#find_toctry").attr("disabled","disabled");
				}
				
				if(criteria == 6 || criteria == 7){	
					$("#find_evecri").val('');
					getFindEventName();
					
					/*$.get("getEventCat.php",{criteria : criteria, ridetype : 'post'},function(data2){
						data2 = eval('('+data2+')');
						if(data2.eventcatCount > 0){
							$("#find_evecri").html('');
							$("#find_evecri").append('<option value="">Select Event Category</option>');
							$.each(data2.event_cat, function(index, value){
								$("#find_evecri").append('<option value="'+value.catid+'">'+value.catname+'</option>');
							});
							$("#findeventCri").show();
						}else{
							$("#findeventCri").hide();
							alert("No Ride Posted.");
							return false;
						}
					});*/
					
					$("#find_to_cont").show();
					$("#find_frm_cont").show();
					$("#find_to_event_country").hide();
					$("#find_from_event_country").hide();
					$("#findeventCountry").hide();
					$("#find_frmctry").attr("disabled","disabled");
					$("#find_toctry").attr("disabled","disabled"); 
				}else{
					$("#find_evename").val('');
					$("#find_frmctry").val('');
					$("#findeventCri").hide();	
					$("#findeventName").hide();
				}
			}else if(data.flag == 'frm_ctr'){
				$("#find_frmloc_cont").html("");
				if(data.from_loc_count > 0){
					$("#find_frmloc_cont").html(' <select class="select" name="find_frmloc" id="find_frmloc"><option value="">Select '+criteria_text[0]+'</option></select>');
					$.each(data.from_location, function(index, value){
						$("#find_frmloc").append('<option value="'+value+'">'+value+'</option>');
					});
				}
				
				if(data.to_count > 0 && criteria != 6 && criteria != 7){
					$("#find_toctry").html("");
					$("#find_toctry").html('<option value="">Select To Country</option>');
					$.each(data.to_country, function(index, value){
						$("#find_toctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#find_toctry").attr("disabled","");
				}
				
				
				
			}else if(data.flag == 'to_ctr'){
				$("#find_toloc_cont").html("");
				if(data.to_loc_count > 0){
					$("#find_toloc_cont").html('<select class="select" name="find_toloc" id="find_toloc"><option value="">Select '+criteria_text[1]+'</option></select>');
					$.each(data.to_location, function(index, value){
						$("#find_toloc").append('<option value="'+value+'">'+value+'</option>');
					});
				}
				
			}
			
		});
	}else{
		if(flag == "cri"){
			$("#find_to_cont").show();
			$("#find_frm_cont").show();
			$("#findeventCri").hide();
			$("#find_to_event_country").hide();
			$("#find_from_event_country").hide();
			$("#findeventCountry").hide();
			$("#find_frmctry").attr("disabled","disabled");
			$("#find_toctry").attr("disabled","disabled");
			$("#find_frmctry").html('<option value="">Select From Country</option>');
			$("#find_toctry").html('<option value="">Select To Country</option>');
		}
		$("#find_evecri").val('');
		$("#find_frmloc_cont").html("");
		$("#find_toloc_cont").html("");
	}
}

function showFindEvens(cat){
	if(cat != ""){
		postCri = $("#find_criteria").val();
		$.get("getEvents.php",{cat:cat, flag : 'findFrom', criteria : postCri},function(data){
			data = eval('('+data+')');
			$("#find_eventcountry").html('');
			$("#find_eventcountry").html('<option value="">Select Event Country</option>');
			if(data.countryCount > 0){
				$.each(data.event_country, function(index, value){
					$("#find_eventcountry").append('<option value="'+value.country+'">'+value.country+'</option>');
				});
				//$("#find_frmctry").attr("disabled","");
				/*if(postCri == 6){
					$("#find_eventcountry").attr("onchange","show_find_loc(this.value,'to_ctr')");
				}else{
					$("#find_eventcountry").attr("onchange","show_find_loc(this.value,'frm_ctr')")
				}*/
				$("#findeventCountry").show();
			}else{
				//$("#findeventName").hide();
				alert("No Ride Posted for Selected Category.");
			}
		});
	}
}

function reqshowFindEvens(cat){
	if(cat != ""){
		postCri = $("#req_find_criteria").val();
		$.get("getEvents.php",{cat:cat, flag : 'findFrom', criteria : postCri, ride_flag : 'req_ride'},function(data){
			data = eval('('+data+')');
			$("#req_find_eventcountry").html('');
			$("#req_find_eventcountry").html('<option value="">Select Event Country</option>');
			if(data.countryCount > 0){
				$.each(data.event_country, function(index, value){
					$("#req_find_eventcountry").append('<option value="'+value.country+'">'+value.country+'</option>');
				});
				//$("#find_frmctry").attr("disabled","");
				/*if(postCri == 6){
					$("#find_eventcountry").attr("onchange","show_find_loc(this.value,'to_ctr')");
				}else{
					$("#find_eventcountry").attr("onchange","show_find_loc(this.value,'frm_ctr')")
				}*/
				$("#req_findeventCountry").show();
			}else{
				//$("#findeventName").hide();
				alert("No Ride Posted for Selected Category.");
			}
		});
	}
}

function getFindEventName(value){
	postCri = $("#find_criteria").val();
	eventCat = $("#find_evecri").val();
	eventCat = "";
	$.get("getEventsName.php",{ criteria : postCri, country : value , eventCat : eventCat },function(data){
		data = eval('('+data+')');
		var str = "";
		if(data.eventCount > 0){
			
			str = '<select class="select" name="find_to_event_name" id="find_to_event_name" onchange="findSelectLoc(this.value);" style="margin-bottom:6px;"><option selected="selected">Select Event</option>';
			$.each(data.event_detail, function(index, value){
				str += '<option value="'+value.event_name+'" loc="'+value.event_location+'">'+value.event_name+'</option>';
			});
			str += "</select>";
			
			if(postCri == 6){
				$("#find_to_event_country_selc").html(str);
				$("#find_to_cont").hide();
				$("#find_frm_cont").show();
				$("#find_to_event_country").show();
				$("#find_toctry").val(value);
				$("#find_frmctry").attr("disabled","");
			}else if(postCri == 7){
				$("#find_to_cont").show();
				$("#find_frm_cont").hide();
				$("#find_from_event_country_selc").html(str);
				$("#find_from_event_country").show();
				$("#find_frmctry").val(value);
				$("#find_toctry").attr("disabled","");
				
			}
		}
		
	});
}

function reqgetFindEventName(value){
	postCri = $("#req_find_criteria").val();
	eventCat = $("#req_find_evecri").val();
	eventCat = '';
	$.get("getEventsName.php",{ criteria : postCri, country : value , eventCat : eventCat, ridetype : 'req_ride' },function(data){
		data = eval('('+data+')');
		var str = "";
		if(data.eventCount > 0){
			
			str = '<select class="select" name="find_to_event_name" id="req_find_to_event_name" onchange="reqfindSelectLoc(this.value);" style="margin-bottom:6px;"><option selected="selected">Select Event</option>';
			$.each(data.event_detail, function(index, value){
				str += '<option value="'+value.event_name+'" loc="'+value.event_location+'">'+value.event_name+'</option>';
			});
			str += "</select>";
			
			if(postCri == 6){
				$("#req_find_to_event_country_selc").html(str);
				$("#req_find_to_cont").hide();
				$("#req_find_frm_cont").show();
				$("#req_find_to_event_country").show();
				$("#req_find_toctry").val(value);
				$("#req_find_frmctry").attr("disabled","");
			}else if(postCri == 7){
				$("#req_find_to_cont").show();
				$("#req_find_frm_cont").hide();
				$("#req_find_from_event_country_selc").html(str);
				$("#req_find_from_event_country").show();
				$("#req_find_frmctry").val(value);
				$("#req_find_toctry").attr("disabled","");
				
			}
		}
		
	});
}

function findSelectLoc(value){
	postCri = $("#find_criteria").val();
	loc = $("#find_to_event_name option:selected").attr('loc');
	if(postCri == 6){
		$("#find_toloc_cont").html("<input type='hidden' name='find_toloc' id='find_toloc' value='"+loc+"'");
	}else if(postCri == 7){
		$("#find_frmloc_cont").html("<input type='hidden' name='find_frmloc' id='find_frmloc' value='"+loc+"'");
	}
}

function reqfindSelectLoc(value){
	postCri = $("#req_find_criteria").val();
	loc = $("#req_find_to_event_name option:selected").attr('loc');
	if(postCri == 6){
		$("#req_find_toloc_cont").html("<input type='hidden' name='find_toloc' id='req_find_toloc' value='"+loc+"'");
	}else if(postCri == 7){
		$("#req_find_frmloc_cont").html("<input type='hidden' name='find_frmloc' id='req_find_frmloc' value='"+loc+"'");
	}
}

function showFindLoc(value){
	$.get("getEventsLoc.php",{eventId:value},function(data){
		
		data = eval('('+data+')');
		$("#find_frmctry").html('<option value="">Select From Country</option>');
		$.each(data.event_country, function(index, value){
			$("#find_frmctry").append('<option value="'+value.from+'">'+value.from+'</option>');
		});
		$("#find_frmctry").attr("disabled","");
	});
}

function validate_find(){
	if($("#find_criteria").val() == ""){
		alert("Please Select Criteria.");	
		return false;
	}
	
	return true;
}

function req_show_find_loc(val,flag){
	if(val != ""){
		criteria = $("#req_find_criteria").val();
		criteria_text = $("#req_find_criteria option:selected").text().split("to");
		
		if(criteria == 6 || criteria == 7){	
			criteria_text[0] = criteria_text[0]+" Location";
			criteria_text[1] = criteria_text[1]+" Location";
		}else{
			$("#req_find_to_cont").show();
			$("#req_find_frm_cont").show();
			$("#req_findeventCri").hide();
			$("#req_find_to_event_country").hide();
			$("#req_find_from_event_country").hide();
			$("#req_findeventCountry").hide();
			if(flag == 'cri'){
				$("#req_find_frmctry").html('<option value="">Select From Country</option>');
				$("#req_find_toctry").html('<option value="">Select To Country</option>');	
			}
			eventCat = $("#req_find_evecri").val(''); 
		}
		eventCat = $("#req_find_evecri").val(); 
		
		$.get("get_find_location.php",{'search' : val, criteria : criteria, flag : flag, type : 'req_ride', eventCat : eventCat},function(data){
			data = eval('('+data+')');
			if(data.flag == 'cri'){
				$("#req_find_frmctry").attr("disabled","disabled");
				$("#req_find_toctry").attr("disabled","disabled");
				$("#req_find_frmctry").html('<option value="">Select From Country</option>');
				$("#req_find_toctry").html('<option value="">Select To Country</option>');
				$("#req_find_frmloc_cont").html("");
				$("#req_find_toloc_cont").html("");
				if(data.from_count > 0){
					$.each(data.from_country, function(index, value){
						$("#req_find_frmctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#req_find_frmctry").attr("disabled","");
				}
				
				if(data.to_count > 0){
					$.each(data.to_country, function(index, value){
						$("#req_find_toctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#req_find_toctry").attr("disabled","");
				}
				
				if(data.from_count == 0){
					$("#req_find_frmctry").html('<option value="">No postings...Post a request</option>');
					$("#req_find_frmctry").attr("disabled","disabled");
					$("#req_find_toctry").attr("disabled","disabled");					
				}
				
				if(data.to_count == 0){
					$("#req_find_toctry").html('<option value="">No postings...Post a request</option>');
					$("#req_find_frmctry").attr("disabled","disabled");
					$("#req_find_toctry").attr("disabled","disabled");
				}
				
				if(criteria == 6 || criteria == 7){	
					$("#req_find_evecri").val('');
					reqgetFindEventName();
					/*$.get("getEventCat.php",{criteria : criteria, ridetype : 'req'},function(data2){
						data2 = eval('('+data2+')');
						if(data2.eventcatCount > 0){
							$("#req_find_evecri").html('');
							$("#req_find_evecri").append('<option value="">Select Event Category</option>');
							$.each(data2.event_cat, function(index, value){
								$("#req_find_evecri").append('<option value="'+value.catid+'">'+value.catname+'</option>');
							});
							$("#req_findeventCri").show();
						}else{
							$("#req_findeventCri").hide();
							alert("No Ride Posted.");
							return false;
						}
					});*/
					
					$("#req_find_to_cont").show();
					$("#req_find_frm_cont").show();
					$("#req_find_to_event_country").hide();
					$("#req_find_from_event_country").hide();
					$("#req_findeventCountry").hide();
					$("#req_find_frmctry").attr("disabled","disabled");
					$("#req_find_toctry").attr("disabled","disabled"); 
				}else{
					$("#req_find_evename").val('');
					$("#req_find_frmctry").val('');
					$("#req_findeventCri").hide();	
					$("#req_findeventName").hide();
				}
			}else if(data.flag == 'frm_ctr'){
				$("#req_find_frmloc_cont").html("");
				if(data.from_loc_count > 0){
					$("#req_find_frmloc_cont").html(' <select class="select" name="find_frmloc" id="req_find_frmloc"><option value="">Select '+criteria_text[0]+'</option></select>');
					$.each(data.from_location, function(index, value){
						$("#req_find_frmloc").append('<option value="'+value+'">'+value+'</option>');
					});
				}
				
				if(data.to_count > 0 && criteria != 6 && criteria != 7){
					$("#req_find_toctry").html("");
					$("#req_find_toctry").html('<option value="">Select To Country</option>');
					$.each(data.to_country, function(index, value){
						$("#req_find_toctry").append('<option value="'+value+'">'+value+'</option>');
					});
					$("#req_find_toctry").attr("disabled","");
				}
				
			}else if(data.flag == 'to_ctr'){
				$("#req_find_toloc_cont").html("");
				if(data.to_loc_count > 0){
					$("#req_find_toloc_cont").html('<select class="select" name="find_toloc" id="req_find_toloc"><option value="">Select '+criteria_text[1]+'</option></select>');
					$.each(data.to_location, function(index, value){
						$("#req_find_toloc").append('<option value="'+value+'">'+value+'</option>');
					});
				}
				
			}
			
		});
	}else{
		if(flag == "cri"){
			$("#req_find_to_cont").show();
			$("#req_find_frm_cont").show();
			$("#req_findeventCri").hide();
			$("#req_find_to_event_country").hide();
			$("#req_find_from_event_country").hide();
			$("#req_findeventCountry").hide();
			$("#req_find_frmctry").attr("disabled","disabled");
			$("#req_find_toctry").attr("disabled","disabled");
			$("#req_find_frmctry").html('<option value="">Select From Country</option>');
			$("#req_find_toctry").html('<option value="">Select To Country</option>');
		}
		$("#req_find_evecri").val('');
		$("#req_find_frmloc_cont").html("");
		$("#req_find_toloc_cont").html("");
		
		/*$("#req_find_frmctry").attr("disabled","disabled");
		$("#req_find_toctry").attr("disabled","disabled");
		$("#req_find_frmctry").html('<option value="">Select From Country</option>');
		$("#req_find_toctry").html('<option value="">Select To Country</option>');
		$("#req_find_frmloc_cont").html("");
		$("#req_find_toloc_cont").html("");*/
	}
}

function req_validate_find(){
	if($("#req_find_criteria").val() == ""){
		alert("Please Select Criteria.");	
		return false;
	}
	
	return true;
}
function validateEmail(elementValue){
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue);
 }
 
 function editRide(id){
	$.get("editride.php",{id : id},function(data){
		$.blockUI({ message: data, 
				  	css: { top: '25%', left : '35%' } ,
				  });
	});
}

	<!--
	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_swapImage() { //v3.0
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	//-->
