////
// Shadowbox Init
////
Shadowbox.init({
	handleOversize: "drag",
	modal: true,
	overlayOpacity: 0.8
});

////
// Shadowbox Setups
////
jQuery(document).ready(function() {	
	Shadowbox.setup('a[title="Excessive Fuel Report"]', {
		height: 600,
		width: 800,
		flashVars: {
			clip_id: "10967111",
			autoplay: "1"
		}
	});
	
	Shadowbox.setup('a[title="Real Time Tracking"]', {
		height: 600,
		width: 800,
		flashVars: {
			clip_id: "10966511",
			autoplay: "1"
        }
	});
	
	Shadowbox.setup('a[title="PlusNav"]', {
		height: 600,
		width: 800,
		flashVars: {
			clip_id: "10967615",
			autoplay: "1"
        }
    });
    
    Shadowbox.setup('a[title="FieldLogix Notifications"]', {
    	height: 600,
    	width: 800,
    	flashVars: {
    		clip_id: "10987347",
    		autoplay: "1"
        }
	});
	
	Shadowbox.setup('a[title="FieldLogix Reports"]', {
		height: 600,
		width: 800,
		flashVars: {
			clip_id: "10986423",
			autoplay: "1"
        }
	});
	
	Shadowbox.setup('a[title="Maintenance Alerts"]', {
		height: 600,
		width: 800,
		flashVars: {
			clip_id: "10967334",
			autoplay: "1"
        }
    });
    
    Shadowbox.setup('a[title="Admin Settings"]', {
    	height: 600,
        width: 800,
        flashVars: {
        	clip_id: "10967788",
        	autoplay: "1"
        }
	});
});

////
// Slidedown
////
function side_contact_slide() {
	if(jQuery("#side_checkdemo").attr("checked") == true || jQuery("#side_checkquote").attr("checked") == true) {
		jQuery("#side_requestform").slideDown('fast', function() {});
	} else {
		jQuery("#side_requestform").slideUp('fast', function() {});
	}
}

////
// Side Contact Validate
////
function side_contact_validate() {	
	if(!jQuery("#side_full_name, #side_email_address").isEmpty() && jQuery("#side_email_address").isEmail()) {
		jQuery("#side_submit").val("Please Wait...");
		
		return true;
	}
	
	return false;
}

////
// Main Contact Validate
////
function main_contact_validate() {
	if(!jQuery("#full_name, #phone_number, #email_address").isEmpty() && jQuery("#email_address").isEmail()) {
		jQuery("#contact_send").val("Please Wait...");
		
		return true;
	}
	
	return false;	
}

////
// Demo Contact Validate
////
function demo_contact_validate() {
	if(!jQuery("#full_name, #phone_number, #email_address").isEmpty() && jQuery("#email_address").isEmail()) {
		jQuery("#contact_send").val("Please Wait...");
		
		return true;
	}
	
	return false;	
}

////
// Promo Piece Validate
////
function promo_contact_validate() {	
	if(jQuery("#promo_email_address").isEmail()) {
		_gaq.push(['_trackPageview', '/promo-widget/request.php']);
		return true;
	}
	
	return false;
}

/***********************************************/
/*              AJAX Request Object            */
/***********************************************/
var Request = {
	//// Test if an object is empty
	isEmptyObject: function(obj) {
		for(var i in obj) {
			return false;
		}
		return true;
	},
	//// Make an ajax request
	// p_server_side_page: Ajax page to call
	// p_parameters: Arguments to pass to the server side page
	// p_callback: Handler to call on success
	// p_options (Optional): Additional configuration options 
	//   -- dataType:{"xml","html","script","json","jsonp","text"} Data type of return object
	//   -- type:{"POST","GET"} Request type
	//   -- timeout:{int} Timeout in milliseconds before fail
	//   -- cache:{true/false} Whether to allow caching or not
	//   -- async:{true/false} Whether to send the request asynchronous, if you need synchronous set to false.
	ajax: function(p_server_side_page, p_parameters, p_callback, p_options) {
		// Set defaults
		var data_type = "text";
		var type = "post";
		var timeout = 30000;
		var cache = false;
		var async = true;

		// Check option parameters
		if (typeof p_options != "undefined") {
			if (typeof (p_options.dataType) != "undefined") {
				data_type = p_options.dataType;
			}

			if (typeof (p_options.type) != "undefined") {
				type = p_options.type;
			}

			if (typeof (p_options.timeout) != "undefined") {
				timeout = p_options.timeout;
			}

			if (typeof (p_options.cache) != "undefined") {
				cache = p_options.cache;
			}

			if (typeof (p_options.async) != "undefined") {
				async = p_options.async;
			}
		}
		
		//Force a `GET` request, if the parameters is null, undefined, or empty.
		if(typeof p_parameters == "undefined" || p_parameters == null) {
			type = "get";					
		} else {
			if(this.isEmptyObject(p_parameters)) {
				type = "get";
			}
		}

		// Make ajax request
		jQuery.ajax({ url: p_server_side_page,
			data: p_parameters,
			success: p_callback,
			dataType: data_type,
			type: type,
			timeout: timeout,
			cache: cache,
			async: async,
			error: function(XMLHttpRequest, textStatus, errorThrown) { /*NOTHING*/ }
		});
	}
}

/***********************************************/
/*           jQuery Custom Extensions          */
/***********************************************/
// Check for jQuery
if (jQuery) (function() {
	// Extend the functions for elements
	jQuery.extend(jQuery.fn, {
		isEmpty: function() {
			var empty = false;
			
			jQuery(this).each(function() {
				// Select
				if(this.tagName == "SELECT") {
					if(jQuery(this).children("option").length > 0 && jQuery(this).val().length > 0) {
						jQuery(this).removeClass("error");
					} else {
						jQuery(this).addClass("error");
						empty = true;
					}	
				} 
				// Text
				else {
					if(jQuery(this).val().length > 0) {
						jQuery(this).removeClass("error");
					} else {
						jQuery(this).addClass("error");
						empty = true;
					}
				}
			});
			
			return empty;
		},
		isEmail: function() {
			var email = true;
			
			jQuery(this).each(function() {
				var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{1,5})$/;
				
				if(reg.test(jQuery(this).val()) == false) {
					jQuery(this).addClass("error");
					email = false;
				} else {
					jQuery(this).removeClass("error");
				}
			});
			
			return email;
		},
		isChecked: function() {
			var checked = false;
			
			jQuery(this).each(function() {
				if(jQuery(this).attr("checked")) {
					jQuery(this).parent().removeClass("error");
					checked = true;	
				} else {
					jQuery(this).parent().addClass("error");
				}
			});
			
			return checked;
		},
		upperCase: function() {
			jQuery(this).each(function() {
				var obj = this;
				
				jQuery(this).bind("keyup", function() {
					jQuery(obj).val(jQuery(element.val().toUpperCase()));
				});
			});
		}
	});
})(jQuery);


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_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_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];}
}
