// JavaScript Document


$(document).ready(function(){
	
	// Unsubscribe
	$("#m6fbrp_submit").click(function() {
		var mobile = $("input[name$='m5fbrp__34']").val();
		var email = $("input[name$='m5fbrp__32']").val();
		
		if(mobile == "" && email == "") {
				$(".error_message").html("<ul><li>Please select email or your cell phone</li></ul>");
				return false;
		}

		if(mobile) {
			if(mobile.search(/\d{3}\-\d{3}\-\d{4}/)==-1) {
				$(".error_message").html("<ul><li>Please enter a valid cell phone number</li></ul>");
					return false; 	
			}
		
			mobil_email = mobile.replace(/\D/g,'');
		
		}
		$.post("unsubscribe-alerts.php", { e: email, m: mobile },
	   function(data){
	    		$(".RiderAlertSignup").html("<b>You have been unsubscribed to Rider Alerts</b>"); 	
	     	alert("Data Loaded: " + data);
	   });
	   
	   
		return false;
		
	});
	
	
	$("#alert_carrier").change(function() {
		var carrier = $("#alert_carrier").val(); 
		var mobile = $("input[name$='m5fbrp__20']").val();
		mobile = mobile.replace(/\D/g,'');

		$("input[name$='m5fbrp__27']").val(carrier);
		$("input[name$='m5fbrp__28']").val(mobile+"@"+carrier);
		
	});
	
	$("#m5fbrp_submit").click(function() {
		// Mobile Number
		var carrier = $("#alert_carrier").val(); 
		var mobile = $("input[name$='m5fbrp__20']").val();
		var email = $("input[name$='m5fbrp__18']").val();
		
		if(mobile == "" && email == "") {
				$(".error_message").html("<ul><li>Please select email or your cell phone</li></ul>");
				return false;
		}
		
		if(mobile != "") {
			mobile = mobile.replace(/\D/g,'');
		
			if(carrier == "") {
				$(".error_message").html("<ul><li>Please select a carrier</li></ul>");
				return false;
			}
			$("input[name$='m5fbrp__27']").val(carrier);
			$("input[name$='m5fbrp__28']").val(mobile+"@"+carrier);
		}
		
	});
	
	
	$(".FoldBoxHeader").click(function () {
		if ($(this).hasClass("Open")) {
			$(this).removeClass("Open");
			$(this).next(".FoldBoxContent").css("display","none");
			$(this).parent().find(".FoldBoxBottom").css("display","none");
			//$(this).(".FoldBoxContent").css("display", "none");
			//											$(this."FoldBoxContent").css("display", "none");
		}
		else { 
			$(this).addClass("Open");
			p = $(this).parent();
			
			$(this).next(".FoldBoxContent").css("display","block");
			$(this).parent().find(".FoldBoxBottom").css("display","block");
			//											$(this."FoldBoxContent").css("display", "block");
		}
	});
	
	$("#TextBig").click(function () {
		$("#MainContent").css("font-size", "18px");
	});
	$("#TextReg").click(function () {
		$("#MainContent").css("font-size", "14px");
	});
	$("#TextSmall").click(function () {
		$("#MainContent").css("font-size", "12px");
	});
});

jQuery.extend({
 
// If the desired param does not exist, null will be returned
// @example value = $.getURLParam("paramName");
 
getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;
 
	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});
