
// Metrics tracking for pathing, dwell time and drop off
//failing in IE, we need to pause execution before end
function metrics_end() {
	if(document.images['metrics']) {
		var endMetrics = new Image();
		endMetrics.src = document.images['metrics'].src.replace(/(page_id=)([^&]*)/, '$1$2&action=end');  ;
	}
	metrics_end_delay(endMetrics);
}
function metrics_end_delay(endMetrics) {
	return endMetrics.src;
}
// Rules Pop-Up
function rules() {
	window.open("index.tbapp?page=rules","rules","menu=no,toolbar=no,width=530,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

// FAQ Pop-Up
function faq() {
	window.open("index.tbapp?page=contact_form","faq","menu=no,toolbar=no,width=530,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=48,left=48");
}

// Survey Pop-Up
function pop_under_survey(email) {
	window.open("index.tbapp?method=ipp_survey_page&email="+email,"pop_under_survey","menu=no,toolbar=no,width=800,height=800,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
    window.focus();
}

// Prize Pop-Up
function prizepop() {
	window.open("index.tbapp?page=prizepop","prizepop","menu=no,toolbar=no,width=800,height=660,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

// game piece Pop-Up
function gamepiece() {
	window.open("index.tbapp?page=gamepiece","gamepiece","menu=no,toolbar=no,width=560,height=540,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

//Forgot password
function forgot(session_id) {
  window.opener.location="index.tbapp?page=forgot_form&session_id="+session_id;
  window.close(); 
}	

// Image Security Information Pop-Up
function img_security() {
	window.open("index.tbapp?page=img_security_info","imgsec","menu=no,toolbar=no,width=450,height=220,scrollbars=0,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=132,left=196");
}

// Generic Pop-Up
// ex: <a href="javascript:openThis('http://www.eprize.com');">Click here</a>
function openThis(URL) {
  window.open(URL);
}

// New Window

function openWindow(link) {
  window.open(link, '_blank', 'toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
}

// No Cookies Popups

function cookies_faq() {
	window.open("index.tbapp?page=cookies_faq","cookies_faq","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}


function toggle_expecting(value) {
	if($("#expecting_questions").is(":hidden") && ($("#expecting").attr('checked') || value == 'yes')) {
		$("#expecting_questions").slideDown("normal");
		$("#do_not_apply").attr('checked', '');
        $("#relationship_to_baby").attr('disabled', '');
        $("#feeding_plan").attr('disabled', '');
        $("#due_date").attr('disabled', '');
		toggle_do_not_apply();
	} else if(!$("#expecting").attr('checked') && !$("#expecting_questions").is(":hidden")) {
		$("#expecting_questions").slideUp("normal");
        $("#relationship_to_baby").attr('disabled', 'true');
        $("#feeding_plan").attr('disabled', 'true');
        $("#due_date").attr('disabled', 'true');
	}
};

function toggle_have_children(value) {
	if($("#have_children_questions").is(":hidden") && ($("#have_children").attr('checked') || value == 'yes')) {
		$("#have_children_questions").slideDown("normal");
		$("#do_not_apply").attr('checked', '');
        $("#num_children").attr('disabled', '');
		toggle_do_not_apply();
	} else if(!$("#have_children").attr('checked') && !$("#have_children_questions").is(":hidden")) {
		$("#have_children_questions").slideUp("normal");
        $("#num_children").attr('disabled', 'true');
        toggle_children_dob();
	}
};

function toggle_do_not_apply(value) {
	if($("#do_not_apply_questions").is(":hidden") && ($("#do_not_apply").attr('checked') || value == 'yes')) {
		$("#do_not_apply_questions").slideDown("normal");
		$("#expecting").attr('checked', '');
		$("#have_children").attr('checked', '');
        $("#other").attr('disabled', '');
		toggle_expecting();
		toggle_have_children();               
	} else if(!$("#do_not_apply").attr('checked') && !$("#do_not_apply_questions").is(":hidden")) {
		$("#do_not_apply_questions").slideUp("normal");
        $("#other").attr('disabled', 'true');
	}
};


function toggle_what_did_you_do(value) {
	if(value == 'yes' && $("#what_did_you_do").is(":hidden")) {
		$("#what_did_you_do").slideDown("normal");
        $(".what_did_you_do_radio").attr('disabled', '');
	} else if(value == 'no' && !$("#what_did_you_do").is(":hidden")) {
		$("#what_did_you_do").slideUp("normal");
        $(".what_did_you_do_radio").attr('disabled', 'true');
	}
};

function toggle_report(report_name) {
	if($("#"+report_name).is(":hidden")) {
		$("#"+report_name).slideDown("slow");
		$("#toggle_"+report_name).html('Collapse');
    } else if(!$("#"+report_name).is(":hidden")) {
   		$("#"+report_name).slideUp("slow");
		$("#toggle_"+report_name).html('Expand');
	}
};

function toggle_children_dob() {
    num_children = $("#num_children").val();

    if($("#num_children").attr('disabled') || !num_children) {
        num_children = 0;
    }
    
    for(var x = 1; x <= 6; x++) {
        if(x <= num_children) {
            if($("#child_dob_"+x).is(":hidden")) {
                $("#child_dob_"+x).slideDown('fast'); 
            }
        } else {
            if(!$("#child_dob_"+x).is(":hidden")) {
                $("#child_dob_"+x).slideUp('fast'); 
            }
        }
    }
}

function uncheck_all(prefix, num_optins, cur_checked) {
    // User checked none of the above 
    if(cur_checked == num_optins) {
        for(var x = 1; x < num_optins; x++) {
            $("#"+prefix+"_"+x).attr('checked', '');
        }
    } else { // anything else... 
            $("#"+prefix+"_"+num_optins).attr('checked', '');
    }
}

function uncheck_opp_gender(index) {
    if(index == 3) {
        opposite = 4;
    } else if(index == 4) {
        opposite = 3;
    }

    if(index != 3 && index != 4) {
        return false;
    }
    
    if($("#other_"+index).attr('checked')) {
        $("#other_"+opposite).attr('checked', '');
    }
}

function toggle_other(source, other_id) {
    disabled = true;
    if(source == 'Other') {
        disabled = '';
    }
    $("#"+other_id).attr('disabled', disabled);
}

function toggle_how_hear(answer) {
    disabled = true;
    if(answer == 'yes') {
        disabled = '';
    }
    $("#how_hear").attr('disabled', disabled);
}



function enfalert(msg) {
	alert (msg);
}

function enfapreview(pagetype, doc, question) {
	window.open("index.tbapp?page=enfapreview&pagetype="+pagetype+"&doc="+doc+"&question="+question+"","enfapreview","menu=no,toolbar=no,width=500,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

function nurserypreview() {
	window.open("index.tbapp?page=nurserypreview","enfapreview","menu=no,toolbar=no,width=600,height=420,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

var state = 'hidden';

function showhide(layer_ref) {
	if (state == 'visible') {
		state = 'hidden';
	} else {
		state = 'visible';
	}
	if (document.all) {
		eval( "document.all." + layer_ref + ".style.visibility = state");
	}
	if (document.layers) {
		document.layers[layer_ref].visibility = state;
	}
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.visibility = state;
	}
}

function delayBabyGame_ill()
{
	setTimeout("babyGame_ill()", 3000);
}

function delayHosp_ill()
{
	setTimeout("hosp_ill()", 6000);
}

function delayMomspark_ill()
{
	setTimeout("momspark_ill()", 6000);
}

function delayNewTstore_ill()
{
	setTimeout("newTstore_ill()", 3000);
}

function delaySchool_ill()
{
	setTimeout("school_ill()", 4000);
}

function delayTAF()
{
	setTimeout("showhide('showtaf');showhide('plswait');", 6000);
}

function babyGame_ill()
{
	window.location = "?page=advergame2_game";
}

function errorTAF()
{
	setTimeout("showhide('showtaf');showhide('plswait');", 1);
}

function hosp_ill() {
	window.location = "?page=hospital_code_entry";
}

function momspark_ill() {
	window.location = "?page=moms_park_talk";
}

function newTstore_ill()
{
	window.location = "?page=tstore_selection";
}

function school_ill() {
	window.location = "?page=school";
}

$(document).ready(function() {
	$("#client_optin_no").hover(
		function() {
			$("#offer_alert").show();
		},
		function() {
			$("#offer_alert").hide();
		}
	);
});

function getMyDate() {
	var today = new Date();
	var month = today.getMonth()+1;
	var year = today.getYear();
	var day = today.getDate();
	if(day<10) day = "0" + day;
	if(month<10) month= "0" + month ;
	if(year<1000) year+=1900;

	var myDate = (month + "/" + day + "/" + (year+"").substring(2,4));
	document.write(myDate);
}
