// Page Load Initialization
$(document).ready(function(){
						   
	$('a[rel=external]').attr('target','_blank');
	
	// Automatic image and input[type=image] roll-over initiation
	// Grabs all <img> tags and <input type="image"> tags with the "rollOver" class
	// and sets up rollOver and active states. Image name syntaxing:
	// image_i.gif : (_i) idle image
	// image_o.gif : (_o) over image
	// image_a.gif : (_a) active image
	$('img.rollOver, input[type=image].rollOver').mouseover(function(){
		src = $(this).attr('src');
		$(this).attr('src',src.replace('_i.','_o.'));
		
	}).mouseout(function(){
		preSrc = '_o.';
		src = $(this).attr('src');
		if($(this).attr('src').indexOf('_a.') != -1) {
			preSrc = '_a.';
		}
		$(this).attr('src',src.replace(preSrc,'_i.'));
	}).not('img').mousedown(function(){
		src = $(this).attr('src');
		$(this).attr('src',src.replace('_o.','_a.'));
	}).mouseup(function(){
		src = $(this).attr('src');
		$(this).attr('src',src.replace('_a.','_i.'));
	});
	
	$('form.validatethis').each(function(){
				ID = $(this).attr("id");
				initValidator(ID);				
	});
	
	$('li.radioList input[type=checkbox]').click(function(){														 
		checkAllValid('#form_advertiser');		
	});

		
		
});		



function contactFadeIn() {
	$('div#form_contact').fadeIn("slow");
}
function contactFadeOut() {
	$('div#form_contact').fadeOut("slow");
}


function submitter(){
	$('#id_submit').attr({src:'http://www.getmorebang.com/images/btn_submit_sending.gif'});
	$('#id_submit').attr('disabled','disabled');
	
	$.post(SITE_ROOT+"/contact.php",
		{
			name: $('#id_name').val(),
			email: $('#id_email').val(),
			comments: $('#id_comments').val(),
			submit: 'yes',
			ajax: "yes"
		},
		function(data){
			if(data == "<ul id='form_errors'></ul>"){
				$('#form_Form1').slideUp("slow");
				$('#mail_response').html("<p>Thanks for contacting BANG! We will get back to you soon.</p>").slideDown("slow");
				$('#mail_response').fadeOut(6000);
				$('#thanks_response').html("<p>Thanks for taking the time to contact us.  We will be in touch soon.</p>").slideDown("slow");
			}else{
				$('#form_Form1').fadeOut("slow");
				$('#mail_response').css("background-color","#fcc").html("<p>OOPS! It looks like we had an error, please try again later or contact us directly at <a href='mailto:info@getmorebang.com'>info@getmorebang.com</a></p>").slideDown("slow");
			}
		}
	);
	return false;
}

function submitter_publisher(){
	
	$('#id_submit').attr({src:'http://www.getmorebang.com/images/btn_submit_sending.gif'});
	
	$('#id_submit').attr('disabled','disabled');
	
	//console.log('ajax');
	$.post(SITE_ROOT+"/audit/publisher",
		{
			name: $('#id_name').val(),
			email: $('#id_email').val(),
			phone: $('#id_phone').val(),
			uniques: $('#id_uniques').val(),
			uniques_USA: $('#id_uniques_USA').val(),
			uniques_UK: $('#id_uniques_UK').val(),
			uniques_AUS: $('#id_uniques_AUS').val(),
			pageviews: $('#id_pageviews').val(),
			url: $('#id_url').val(),
			pageviews_USA: $('#id_pageviews_USA').val(),
			pageviews_UK: $('#id_pageviews_UK').val(),
			pageviews_AUS: $('#id_pageviews_AUS').val(),
			competitors: $('#id_competitors').val(),
			sponsors: $('#id_sponsors').val(),
			submit: 'yes',
			ajax: "yes"
		},
		function(data){
			if(data == "<ul id='form_errors'></ul>"){
				$('#form_Form1').slideUp("slow");
				$('#mail_response').html("<p>Your audit form was submitted succesfully.</p>").slideDown("slow");
				$('#mail_response').fadeOut(6000);
				$('#thanks_response').html("<p>Thanks for taking the time to fill out the audit.  We will review your information and be in touch soon.</p>").slideDown("slow");
			}else{
				$('#form_Form1').fadeOut("slow");
				$('#mail_response').css("background-color","#fcc").html("<p>OOPS! It looks like we had an error, please try again later or contact us directly at <a href='mailto:sales@getmorebang.com'>sales@getmorebang.com</a></p>").slideDown("slow");
			}
		}
	);
	return false;
}







function getUpdates(){
	$('#form_Form1').attr("action","javascript:void(null);");
	$('#form_contact').hide();
	$('#form_Form1').before('<a href="javascript:contactFadeOut();">X</a>');
	$('.copyright').before('<li class="contact"><a href="javascript:contactFadeIn();" id="btn_clickhere">click here</a><span class="highlight">Sign up for updates &amp; notifications</span></li>');
	$('#form_contact').css({
		position: "absolute",
		bottom: "60px",
		left: "498px"
	});
	$('#formHelp').remove();
	$('#contact_title').remove();
}


function getCheckboxState(ID){
		state = $(ID).attr('checked');
		if(state==true){
			return "on";
		}else{
			return "off";
		}
	}
	
// Replace input field with default value on blur if nothing was entered
function clearField(thefield,onOff) {

	if(onOff == 'off') {

		if (thefield.defaultValue==thefield.value) {

			thefield.value = "";

			thefield.style.color = '#000000';

		}

	} else {

		if (thefield.value=="") {

			thefield.value = thefield.defaultValue;

			thefield.style.color = '#AAAAAA';

		}

	}

}