/*---------------
dekalb.js
- Core js
----------------*/
jQuery(document).ready(function() {
	
	/*-------------------------------------------
	assign new window funct to external links
	-Allows removal of nonstandard target="_blank"
	--------------------------------------------*/
	var extLinks = $('a');
	 for (var i=0; i<extLinks.length; i++) {
	   var extLink = extLinks[i];
	   if ($(extLink).attr("href") && $(extLink).attr("rel") == "external") {
		extLink.target = "_blank";
		}
	 }
	
	/*-------------------------------------------------------------------------------------------------------------
	=assign form onSubmit event handler -> this will hijack the default submit action when submit button pressed
	-------------------------------------------------------------------------------------------------------------*/
	
	/*request-quote box*/
	$('#raForm').submit(function(e) {
	  formSubmit($(this));
	  e.preventDefault();
	  return false;
	});
	
	/*quick-connect*/
	$('#ctaCol form').submit(function(f) {
	  formSubmit($(this));
	  f.preventDefault();
	  return false;
	});
	
	/*contact page form*/
	$('#contactForm').submit(function(g) {
	  formSubmit($(this));
	  g.preventDefault();
	  return false;
	});
	
	
	
	/*----------------------------------
	=RequestQuoteBox
	-----------------------------------*/
	
	/*Initial align request quote box horiztonally*/
	var width = document.body.clientWidth;
	$("#reqQuoteBox").css("marginLeft",(width-878)/2);
	
	//change position whenever window resize event fires
	$(window).resize(function() {
		//var width = document.body.clientWidth;
		$("#reqQuoteBox").css("marginLeft",(document.body.clientWidth-878)/2);

	});
	
	
	/* open box button event assignment  */
	var rqLink = $('#courtesynav li.request a');
	if(rqLink) {
		$(rqLink).attr('href', 'javascript:void(0);');
		$(rqLink).bind('click',function(){
		    $('#reqQuoteBox').toggle();
		    return false;
		 });
	}
	
	/* close box button [on form] */
	$("#reqQuoteBox p a").attr('href', 'javascript:void(0);');
	$("#reqQuoteBox p a").bind('click',function(){
		$('#reqQuoteBox').css('display','none');
	});
	
	/*------------------
	=ctaform expand/col
	-------------------*/
	//test if ctaForm present in page
	if($('#ctaCol form').length != 0) {
		//profilebox exists on this page so hide the form immediately
		$('#ctaCol form').css("display","none");
		
		//assign expand/col event to link controlling show/hide form
		var link = $('#ctaCol h3');
		if(link) {
			$(link).attr('href', 'javascript:void(0);');
			$(link).bind('click',function(){
			    $('#ctaCol form').toggle();
			    return false;
			 });
			$(link).css("cursor","pointer");
		}else{
		}
	}
	
});

/*-----------------------
formField on focus clear
------------------------*/
function clearField(inputObj) {
     if (inputObj.value == inputObj.defaultValue || inputObj.value == "Required") {
         inputObj.value = "";
     }
}

/*-----------------------------------------------------------------------------
generic google event tracker function to then call actual trackPageView Method()
------------------------------------------------------------------------------*/

function gaPageTrackCall(param1,param2) {
	pageTracker._trackEvent(param1,param2);
	//alert(param1+" "+param2);
}
