var configActionTab = {
    sensitivity: 3,
    interval: 200,
    over: openTab,
    timeout: 800,
    out: closeTab
};

function openTab() {
    /* IEPNGFix.update(); */
    $(this).animate(
		{
		    marginBottom: "-85px",
		    height: "140px",
		    top: "-85px"
		},
		200
	);
    /* IEPNGFix.update(); */
}

function closeTab() {
    /* IEPNGFix.update(); */
    $(this).animate(
		{
		    marginBottom: "0px",
		    height: "55px",
		    top: "0px"
		},
		200
	);
    /* IEPNGFix.update(); */
}

function hcpSubmitIt() {
    var destination = "howyoplusworks_hp_submit.aspx";
    var payload = $("#hcpForm").serialize();

    try {
        $.ajax({
            type: "POST",
            url: destination,
            data: payload,
            success: function(data, textStatus) {
                /*alert( "Data Saved: " + data);*/
                $("#hcpSuccess").show();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                /*alert( "Data Lost: " + textStatus + " " + errorThrown );*/
            }
        });
    } catch (e) {
        alert("XSS Call was prevented by your browser!");
    }

    /* alert(payload); */
    return true;
}

function tafSubmitIt() {
    var destination = "taf_submit.aspx";
    var payload = $("#tafForm").serialize();

    try {
        $.ajax({
            type: "POST",
            url: destination,
            data: payload,
            success: function(data, textStatus) {
                /*alert( "Data Saved: " + data);*/
                window.location = 'taf_submit.aspx';
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                /*alert( "Data Lost: " + textStatus + " " + errorThrown );*/
            }
        });
    } catch (e) {
        alert("XSS Call was prevented by your browser!");
    }
    /* alert(payload); */
    return true;
}

$(document).ready(function() {
    // preload images
    img1 = new Image();
    img2 = new Image();
    img3 = new Image();
    img4 = new Image();

    img1.src = "../images/coupon-try-on.gif";
    img2.src = "../images/bt-coupon-on.jpg"
    img3.src = "../images/button-submit-on.gif"
    img4.src = "../images/button-download-on.gif"





    $("#hcpSuccess").hide();

    $("#actionSend").hoverIntent(configActionTab);
    $("#actionSignup").hoverIntent(configActionTab);
    $("#actionTalk").hoverIntent(configActionTab);

    $("#actionSend").click(function() {
        window.location = 'taf.aspx';
    });

    $("#homeClick").click(function() {
        window.location = 'default.aspx';
    });

    $("#contactUs").click(function() {
        window.open("http://consumercontacts.generalmills.com/ConsolidatedContact.aspx?page=http://www.generalmills.com/corporate", "", "width=700,height=600,status=no,toolbar=no,menubar=no,scrollbars=yes");
    });

    $("#actionSignup").click(function() {
        window.open("http://www.yoplait.com/NewsletterForm.aspx", "", "width=525,height=600,status=no,toolbar=no,menubar=no,scrollbars=yes");
    });
    $("#actionTalk").click(function() {
        window.location = 'survey.aspx';
    });

    $("dd").hide();
    //$("dd:not(:first)").hide();
    $("dt a").click(function() {
        $("dd:visible").slideUp("slow");
        $(this).parent().next().slideDown("slow");
        return false;
    });

    if ($("#privacyGmEmail").length > 0) {
        $("#privacyGmEmail").click(function() {
            window.open("http://consumercontacts.generalmills.com/ConsolidatedContact.aspx?page=http://www.generalmills.com/corporate", "", "width=700,height=600,status=no,toolbar=no,menubar=no,scrollbars=yes");
        });
    };

    if ($("#hcpForm").length > 0) {
        $("#errorContainer").hide();
        $("#thp_other").hide();
        $("#hear_other").hide();
        $("#materials_other").hide();

        $("#hcpType").change(function() {
            if (this.options[this.selectedIndex].value == 'Other') {
                $("#thp_other").show();
            } else {
                $("#thp_other").hide();
            }
        });

        $("#howhear").change(function() {
            if (this.options[this.selectedIndex].value == 'Other') {
                $("#hear_other").show();
            } else {
                $("#hear_other").hide();
            }
        });

        $("#pem_8").change(function() {
            if (this.checked == true) {
                $("#materials_other").show();
            } else {
                $("#materials_other").hide();
            }
        });

        $("#hcpForm").validate({
            errorLabelContainer: "#errorContainer",
            errorContainer: "#errorContainer",
            wrapper: "li",
            onfocusout: false,
            onkeyup: false,
            onclick: false,
            onsubmit: true,
            debug: true,
            errorClass: "invalid",
            submitHandler: hcpSubmitIt
        });
        $("#Email_address2").rules("add", {
            equalTo: "#Email_address"
        });


    }

    if ($("#tafForm").length > 0) {
        $("#errorContainer").hide();
        $("#tafForm").validate({
            errorLabelContainer: "#errorContainer",
            errorContainer: "#errorContainer",
            wrapper: "li",
            onfocusout: false,
            onkeyup: false,
            onclick: false,
            onsubmit: true,
            debug: true,
            errorClass: "invalid",
            submitHandler: tafSubmitIt
        });
    }

    if ($("#coupon1").length > 0) {
        $("#coupon1").hover(function() {
            $(this).addClass('coupon1-hover');
        }, function() {
            $(this).removeClass('coupon1-hover');
        });

        $("#coupon1").click(function() {
            window.location = 'guarantee.aspx';
        });
    }

    if ($("#coupon2").length > 0) {
        $("#coupon2").hover(function() {
            $(this).addClass('coupon2-hover');
        }, function() {
            $(this).removeClass('coupon2-hover');
        });

        $("#coupon2").click(function() {
            //	window.open("http://bricks.coupons.com/bstart.asp?o=57800&ci=1&c=GM&p=4XeBjIEi",
            window.open("http://freeyoplus.yoplait.com/YoPlus2010/Default.aspx",
				"COUPON", "width=820,height=600,scrollbars=yes,status=no,toolbar=no,menubar=no");
            window.location = 'coupon_thanks.aspx';
        });
    }

    if ($("#smCoupon").length > 0) {
        $("#smCoupon").hover(function() {
            $(this).addClass('smCoupon-hover');
        }, function() {
            $(this).removeClass('smCoupon-hover');
        });

        $("#smCoupon").click(function() {

            //if passed code then concatanate to coupon link
            var urlQuery = window.location.search.substring(1);
            var url = "http://freeyoplus.yoplait.com/YoPlus2010/"
            if (getParams("WT.mc_id") != "x") {
                url = url + "?" + urlQuery;
            }

            window.open(url,
				"COUPON", "width=820,height=600,scrollbars=yes,status=no,toolbar=no,menubar=no");
            window.location = 'coupon_thanks.aspx';
        });
    }

    if ($("#button-coupon").length > 0) {
        $("#button-coupon").hover(function() {
            $(this).addClass('button-coupon-hover');
        }, function() {
            $(this).removeClass('button-coupon-hover');
        });

        $("#button-coupon").click(function() {

            //if passed code then concatanate to coupon link
            var urlQuery = window.location.search.substring(1);
            var url = "http://www.yoplus.com/coupons/coupon_gateway.aspx?targetCoupon=yoplus"
            if (getParams("WT.mc_id") != "x") {
                url = url + "?" + urlQuery;
            }

            //	window.open("http://bricks.coupons.com/bstart.asp?o=57800&ci=1&c=GM&p=4XeBjIEi",
            window.open(url,
				"COUPON", "width=820,height=600,scrollbars=yes,status=no,toolbar=no,menubar=no");
            window.location = 'coupon_thanks.aspx';
        });
    }


    function getParams(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return "x";
    }



    if ($("#hcpDownloadButton").length > 0) {
        $("#hcpDownloadButton").hover(function() {
            $(this).addClass('downloadButton-hover');
        }, function() {
            $(this).removeClass('downloadButton-hover');
        });

        $("#hcpDownloadButton").click(function() {
            window.location = 'HPS.pdf';
        });
    }

    if ($("#loveitDownloadFormButton").length > 0) {
        $("#loveitDownloadFormButton").hover(function() {
            $(this).addClass('loveitDownloadFormButton-hover');
        }, function() {
            $(this).removeClass('loveitDownloadFormButton-hover');
        });

        $("#loveitDownloadFormButton").click(function() {
            window.location = 'RebateForm.pdf';
        });
    }

    if ($("#tafThanksSendButton").length > 0) {
        $("#tafThanksSendButton").hover(function() {
            $(this).addClass('tafThanksSendButton-hover');
        }, function() {
            $(this).removeClass('tafThanksSendButton-hover');
        });

        $("#tafThanksSendButton").click(function() {
            window.location = 'taf.aspx';
        });
    }

    if ($("#ctl00_ContentPlaceHolder1_btnSubmit").length > 0) {
        $("#ctl00_ContentPlaceHolder1_btnSubmit").hover(function() {
            $(this).addClass('submitButton-hover');
        }, function() {
            $(this).removeClass('submitButton-hover');
        });
    }

    if ($("#surveyThanksSendButton").length > 0) {
        $("#surveyThanksSendButton").hover(function() {
            $(this).addClass('surveyThanksSendButton-hover');
        }, function() {
            $(this).removeClass('surveyThanksSendButton-hover');
        });
    }

    if ($("#ctl00_ContentPlaceHolder1_btnSubmit").length > 0) {
        $("#ctl00_ContentPlaceHolder1_btnSubmit").hover(function() {
            $(this).addClass('submitButton-hover');
        }, function() {
            $(this).removeClass('submitButton-hover');
        });

        $("#hcpSubmitButton").click(function() {
            $("#hcpForm").submit();
        });
    }

    if ($("#ctl00_ContentPlaceHolder1_SubmitImageButton").length > 0) {
        $("#ctl00_ContentPlaceHolder1_SubmitImageButton").hover(function() {
            $(this).addClass('submitButton-hover');
        }, function() {
            $(this).removeClass('submitButton-hover');
        });

        $("#tafSubmitButton").click(function() {
            $("#tafForm").submit();
        });
    }

    try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }


}); // close document.ready

swfobject.embedSWF("swfs/howitworks.swf", "howYoWorksSwfContent", "430", "250", "9.0.0");
swfobject.embedSWF("swfs/yoplus.swf", "productsSwfContent", "740", "420", "9.0.0");


