//replace scripts.js

function setCatField(){
	var company=document.getElementById('customfields-tf-3-tf');
	$.ajax({type:"POST",url:"http://freestuffresource.com/ajaxForm.php",data:"cat="+company.value,success:function(msg){
		document.getElementById('tdcat').value=msg;}});}
			function changeme(id,action){
				if(action=="hide"){
					document.getElementById(id).style.display="none";}
				if(action=="show"){
					document.getElementById(id).style.display="block";}};
					
function handleChange(selectCtrl,hiddenField){
	hiddenField.value=selectCtrl.value;
		if(selectCtrl.value=="coupon-code"){
			changeme('code','show');}
		else {changeme('code','hide');}};
		
function setCat(selectCtrl,hiddenField){
	hiddenField.value=selectCtrl.value}
	
$(function(){
	$("#block-menu-secondary-links .content .menu li a").each(function(){
		$(this).click(function(){if(pageTracker!=undefined){pageTracker._trackEvent('Outbound','Click',$(this).attr("href"));}});});});
		
var BASE64_DATA=/^data:.*;base64/i;
var base64Path="http://freestuffresource.com/wp-content/themes/ck-two-column/base64.php";
		
function fixBase64(img){
	if(BASE64_DATA.test(img.src)){img.src=base64Path+"?"+img.src.slice(5);}};onload=function(){
		for(var i=0;i<document.images.length;i++){
			fixBase64(document.images[i]);}};




/**
 * Miscellaneous JavaScript functions live here
 */


/**
 * Returns boolean true if the form on the sidebar is been filled out successfully,
 * or false otherwise.
 * 
 * @return bool success                 True on success, false on failure
 */
function validateSideBar(){
    //save the error message
    var error_message = '';
    
    //capture the form values
    var email = $('#signup_inline_email').val();
    var name  = $('#signup_inline_name').val();
    
    //check for blanks
    if(name == '' || name == 'Enter your name...' || email == ''){
        error_message += "Please specify your name and email address.\n";
    }
    
    //check for a valid email address
    var reg = new RegExp(/^[0-9a-zA-Z\.]+@[0-9a-zA-Z\-]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$/);
    if(!reg.test(email) && email != ''){
 		error_message += "The email address specified appears to be invalid.\n";
    }
    
    //return as appropriate
    if(error_message != ''){
        alert(error_message);
        return false;
    } else {
        return true;
    }
}


/**
 * Permanently hides the inline email signup form at the top of the
 * text trough on every page.
 */
function hideInlineSignUp(){
    $('#signup_inline').fadeOut();
    $.cookie('hide_inline_signup', 'true');
}

function hideMeerkatSignup(){
    $('#meerkat').fadeOut();
    $.cookie('hide_meerkat_signup', 'true');
}

// Hide the welcome message on homepage

function hideNotice1st(){
    $('.notice_1st').fadeOut();
    $.cookie('hide_notice_1st', 'true');
}

function hideNoticeIndex(){
    $('.notice_index').fadeOut();
    $.cookie('hide_notice_index', 'true');
}

function hideCouponMatchupNotice(){
    $('.coupon_matchup_notice').fadeOut();
    $.cookie('hide_coupon_matchup_notice', 'true');
}

function hideNoticeExtremeCouponing(){
    $('.notice_extreme_couponing').fadeOut();
    $.cookie('hide_notice_extreme_couponing', 'true');
}

function hideCreditCardNotice(){
    $('.credit_card_notice').fadeOut();
    $.cookie('hide_credit_card_notice', 'true');
}

function hideCreditCardBadCreditNotice(){
    $('.credit_card_bad_credit_notice').fadeOut();
    $.cookie('hide_credit_card_bad_credit_notice', 'true');
}

function welcomeMoreButton() {
	$('.welcome_more_message').slideDown();
	$('#welcome_more_area').fadeOut();
}

// Enable tablesorter jequery plugin on credit card tableLayout
$(document).ready(function(){ 
    $("#credit_cards_main").tablesorter(); 
//    $("#sortable_coupon_list").sortable();
}); 





// determine the number of printable and online coupons
number_of_online_coupons    = $('.coupon_list_online_coupon').length;
number_of_printable_coupons = $('.coupon_list_printable_coupon').length;


function archiveShowOnlineCoupons() {
    // clone the elements we're going to momentarily remove from the DOM    
    if(number_of_online_coupons == 0){
        alert("Sorry - there a no online coupons available at this time.");
    } else {
        items = $('.coupon_list_online_coupon').clone(true, true);
        $('.coupon_list_online_coupon').remove();
        $(items).prependTo('ul#sortable_coupon_list');
    }
}


function archiveShowPrintableCoupons() {
    if(number_of_printable_coupons == 0){
        alert("Sorry - there a no printable coupons available at this time.");
    } else {
        // clone the elements we're going to momentarily remove from the DOM
        items = $('.coupon_list_printable_coupon').clone(true, true);
        $('.coupon_list_printable_coupon').remove();
        $(items).prependTo('ul#sortable_coupon_list');
    }
}


// Load signup path welcome message
$(document).ready(function(){
    $("#signupWelcome").fadeIn();
});


