$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// toggle script start
$(document).ready(function(){
	
	$(".toggle_container").hide();

	$("h2.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle(350);
	});

});


$(document).ready(function(){
	
	$(".toggle_container2").hide();

	$("h2.trigger2").click(function(){
		$(this).toggleClass("active2").next().slideToggle(350);
	});

});

//--Toggle Accrordation Script

$(document).ready(function(){
	
//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
		//$(this).toggleClass('active').previous().slideUp(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
	
	}else{
		$(this).toggleClass('active').next().slideUp();
	}
	return false; //Prevent the browser jump to the link anchor
});

});


$(document).ready(function(){
	
//Set default open/close settings
$('.acc_container2').hide(); //Hide/close all containers
//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger2').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger2').removeClass('active2').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
		$(this).toggleClass('active2').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
	
	}else{
		$(this).toggleClass('active2').next().slideUp();
	}
	return false; //Prevent the browser jump to the link anchor
});

});
//toggle script end

//Contact Form Widget
	jQuery('form#contactFormWidget').submit(function() {
		
		// assign dynamic div height to footer
		var $h = jQuery("#footer").height();
		jQuery("#footer").css({height: $h});
		
		// assign dynamic div height to secondary
		var $sb_h = jQuery("#secondary").height();
		jQuery("#secondary").css({height: $sb_h});
		
		jQuery('form#contactFormWidget .error').remove();
		var hasError = false;
		jQuery('.requiredField').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				//jQuery(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					var labelText = jQuery(this).prev('label').text();
					//jQuery(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
					jQuery(this).addClass('inputError');
					hasError = true;
				}
			}
		});
	
		if(!hasError) {
			jQuery('form#contactFormWidget .button').fadeOut('normal', function() {
				if ( jQuery(this).hasClass("in_footer") ) {
					jQuery('.loadingImgWidgetFt').css({display:"block"});
				}else{
					jQuery('.loadingImgWidgetSb').css({display:"block"});
				}
			});
			var formInput = jQuery(this).serialize();
			jQuery.post(jQuery('#submitUrlWidget').val(),formInput, function(data){
				jQuery(this).delay(1500,function() {
				jQuery('form#contactFormWidget').fadeOut('fast', function() {		   
					jQuery(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent.</p>');
					});
				});
			});
		}
	
		return false;
	
	});

	//Contact Form
	jQuery('form#contact_form').submit(function() {
		
		// assign dynamic div height to body_block
		var $h = jQuery("#body_block").height();
		jQuery("#body_block").css({height: $h});
		
		jQuery('form#contact_form .error').remove();
		var hasError = false;
		jQuery('.requiredFieldContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				//jQuery(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					var labelText = jQuery(this).prev('label').text();
					//jQuery(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
					jQuery(this).addClass('inputError');
					hasError = true;
				}
			}
		});
	
		if(!hasError) {
			jQuery('form#contact_form .button').fadeOut('normal', function() {
				jQuery('.loadingImg').css({display:"block"});
			});
		
			var formInput = jQuery(this).serialize();
			jQuery.post(jQuery('#submitUrl').val(),formInput, function(data){
				jQuery(this).delay(1500,function() {
				jQuery('form#contact_form').fadeOut('fast', function() {		   
					jQuery(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent.</p>');
					});
				});
			});
		}
	
		return false;
	
	});
	// add printer icon to coupons
	$(document).ready(function(){
		
		$('.disclaimer').append('<div class="coupon-print">');

		//On Click
		$('.disclaimer .coupon-print').click(function(){
			$(this).parent().parent().html();

			// ASSERT: At this point, we know that the current jQuery
			// collection (as defined by THIS), contains only one
			// printable element.
		 
			// Create a random name for the print frame.
			var strFrameName = ("printer-" + (new Date()).getTime());
		 
			// Create an iFrame with the new name.
			var jFrame = $( "<iframe name='" + strFrameName + "'>" );
		 
			// Hide the frame (sort of) and attach to the body.
			jFrame
				.css( "width", "1px" )
				.css( "height", "1px" )
				.css( "position", "absolute" )
				.css( "left", "-9999px" )
				.appendTo( $( "body:first" ) )
			;
		 
			// Get a FRAMES reference to the new frame.
			var objFrame = window.frames[ strFrameName ];
		 
			// Get a reference to the DOM in the new frame.
			var objDoc = objFrame.document;
		 
			// Grab all the style tags and copy to the new
			// document so that we capture look and feel of
			// the current document.
		 
			// Create a temp document DIV to hold the style tags.
			// This is the only way I could find to get the style
			// tags into IE.
			var jStyleDiv = $( "<div>" ).append(
				$( "style" ).clone()
				);
		 
			// Write the HTML for the document. In this, we will
			// write out the HTML of the current element.
			objDoc.open();
			objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
			objDoc.write( "<html>" );
			objDoc.write( "<head>");
			objDoc.write("<link href='http://www.allproautorepair.com/wp-content/themes/ultrawebstudio/style.css' rel='stylesheet'>" );
			objDoc.write("<link href='http://www.allproautorepair.com/wp-content/themes/ultrawebstudio/css/red/style.css' rel='stylesheet'>" );
			objDoc.write( "<title>" );
			objDoc.write( document.title );
			objDoc.write( "</title>" );
			objDoc.write( jStyleDiv.html() );
			objDoc.write( "</head><body><div class='white_box' style='margin:10px; border:4px dashed black;'><div class='white_box_top'><div class='white_box_bottom'>" );
			objDoc.write( $(this).parent().parent().html() );
			objDoc.write( "</div></div></div></body>" );
			objDoc.write( "</html>" );
			objDoc.close();
		 
			// Print the document.
			objFrame.focus();
			objFrame.print();
		 
			// Have the frame remove itself in about a minute so that
			// we don't build up too many of these frames.
			setTimeout(
				function(){
					jFrame.remove();
				},
				(60 * 1000)
				);
		});

	});
	
	
