/*----------------------
Author: Visual Blaze
Client: hjl
----------------------*/

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";
		}
	 }
	
	/*---------------------------------------------------------
	logic or profileBox exp/col - only used on profile pages
	----------------------------------------------------------*/
	//test if profile box present
	if($('#profileBox').length != 0) {
		//profilebox exists on this page so hide the form immediately
		$('#profileBox form').css("display","none");
		
		//assign expand/col event to link controlling show/hide form
		var link = $('#proEmail');
		if(link) {
			$(link).attr('href', 'javascript:void(0);');
			$(link).bind('click',function(){
			    $('#profileBox form').toggle();
			    return false;
			 });
		}else{
		}
	}
	
	/*-------------------------------------------------------------------------------------------------------------
	=assign form onSubmit event handler -> this will hijack the default submit action when submit button pressed
	-------------------------------------------------------------------------------------------------------------*/
	
	/*request-quote box*/
	$('#ctaForm form').submit(function(e) {
	  formSubmit($(this));
	  e.preventDefault();
	  return false;
	});
	
	/*quick-connect*/
	$('#profileBox form').submit(function(f) {
	  formSubmit($(this));
	  f.preventDefault();
	  return false;
	});	
	
	/*click event for adoption box -> avoid nonstandard blocks in inline ele*/
	var adoptEle = $('#adoptionCol div');
	if(adoptEle) {
		$(adoptEle).click(function(){
			window.location = $('#adoptionCol div a').attr('href');
		});
	}
	
	/*cta form referral field 'other' interaction -> shows/hides other field on dropdown select*/
	
	//hide other field onload
	$('.referral-other').hide();
	$('select[name="referral"]').change(function(){
		if($(this).children("option:selected").attr("value") == "Other") {
			$('.referral-other').show();
		}else{
			$('.referral-other').hide();
		}
	})
	
});

/*-----------------------
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);
}
