$(document).ready(function(){
	$(".tbCloseBtn a").click(function(){tb_remove();});
});

function showSuccessMsg(){
	tb_show('', '#TB_inline?height=155&width=300&inlineId=hiddenSubmitReply&modal=true', null);
}
function showFailureMsg() {
	tb_show('', '#TB_inline?height=155&width=300&inlineId=hiddenSubmitFailure&modal=true', null);
}
function openQuickInfo() {
	tb_show('', 'http://164.109.45.99//quick-facts.aspx?keepThis=true&TB_iframe=true&height=500&width=860', null);
}

/////////////   Top Map and DropDownList-related Code    //////////////

//these chunks of xhtml are displayed in the right column of the form when a country is selected from the dropdown list

var baseCountryInfoString = "<div class='emph'>At Heinz, we look forward to hearing what's on the minds of our customers.</div><br/>";
var countryInfo = [];

countryInfo["United States"] = "<div><a href='#quick' onclick='openQuickInfo();'>Instant Answers</a></div><br/><div>We have listened and developed an extensive list of Frequently Asked Questions to help answer your questions immediately. </div><br/><div id='contact_us_faq_btn'></div><br/><div>For general consumer product questions, information about current promotions or suggestions, please contact <b>(800) 255 -5750</b>. You may also fill out the form below to email Consumer Affairs.</div>";
countryInfo["USA"] = "<div class='countryNm'>United States</div><p>1-800-255-5750</p>";
countryInfo["Canada"]  = "<div class='countryNm'>Canada</div><p>1-800-268-6641</p>";
countryInfo["Mexico"]  = "<div class='countryNm'>Mexico</div><p>0152-88630900</p>";
countryInfo["Venezuela"]  = "<div class='countryNm'>Venezuela</div><p>0 800 SRAROJAS</p><p>0 800 (77276527)</p>";

countryInfo["China"]  = "<div class='countryNm'>China</div><p>Heinz Baby Hotline Number</p><p>800 830 2181</p><p></p><p>Heinz Meiweiyuan Customer Service Number</p><p>(8620) 84696176 ext. 8200</p><p>Longfong Customer Service Number</p><p>Shanghai</p><p>8006202118</p><p>&nbsp;</p><p>Other Area</p><p>(8621) 6480 3898</p>";
countryInfo["Singapore"] = "<div class='countryNm'>Singapore</div><p>Consumer Affairs</p><p>+65 6347 1700</p>";
countryInfo["New Zealand"]  = "<div class='countryNm'>New Zealand</div><p>For baby Feeding Inquiries</p><p>1800 633 333</p><p>&nbsp;</p><p>Product Inquiries</p><p>1800 037 058</p>";
countryInfo["Japan"] = "<div class='countryNm'>Japan</div><p>0120-37065</p>";
countryInfo["Australia"] = "<div class='countryNm'>Australia</div><p>For baby Feeding Inquiries</p><p>1800 633 333</p><p>&nbsp;</p><p>Product Inquiries</p><p>1800 037 058</p>";

countryInfo["Netherlands"]  = "<div class='countryNm'>Netherlands</div><p>+31 (0)30-6973700</p>";
countryInfo["Italy"] = "<div class='countryNm'>Italy</div><p>+39 02 52561</p>";
countryInfo["United Kingdom"] = "<div class='countryNm'>U.K.</div><p>0800 528 5757</p>";

var flashMovie;

$(document).ready(function() {
    //fixes ie6 bug
    window.contactus_map = new Object();
    val = "a";
    //also necessary for ie6 fix, but throws an error in safari, so it needs to be in a try catch block
    try {
        document.forms[1].contactus_map.switchToEurope_fl = function(val) {
            string1 = "<invoke name=\"switchToEurope_fl\" returntype=\"javascript\"><arguments><string>" + val + "</string></arguments></invoke>"
            document.forms[1].contactus_map.CallFunction(string1)

        };
        document.forms[1].contactus_map.switchToAmericas_fl = function(val) {
            string1 = "<invoke name=\"switchToAmericas_fl\" returntype=\"javascript\"><arguments><string>" + val + "</string></arguments></invoke>"
            document.forms[1].contactus_map.CallFunction(string1)
        };
        document.forms[1].contactus_map.switchToAsia_fl = function(val) {
            string1 = "<invoke name=\"switchToAsia_fl\" returntype=\"javascript\"><arguments><string>" + val + "</string></arguments></invoke>"
            document.forms[1].contactus_map.CallFunction(string1)
        };
        document.forms[1].contactus_map.switchToPacific_fl = function(val) {
            string1 = "<invoke name=\"switchToPacific_fl\" returntype=\"javascript\"><arguments><string>" + val + "</string></arguments></invoke>"
            document.forms[1].contactus_map.CallFunction(string1)
        };
    }
    catch (ex) { }

    $("#ir_contact_form_V3_4_RegionList").val("null");
    $("fieldset").hide();
    $("#otherSubject").hide();

    ////set up the flash interface functionality
    try {
        flashMovie = thisMovie("contactus_map");
    }
    catch (ex) {//for browsers with js enabled but no flash 
    }

    function thisMovie(movieName) {

        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        return (isIE) ? document.getElementById(movieName) : document[movieName];

    }


    $("#ir_contact_form_V3_4_SubjectDropDownList").bind("change", function() {
        $("#ir_contact_form_V3_4_SubjectHiddenField").attr("value", this.value); //set invisible

        if (this.value == "Other") {
            $("#otherSubject").show("slow");
        }
        if (this.value != "Other") {
            $("#otherSubject").hide();
        }
    });

    $("#ir_contact_form_V3_4_RegionList").bind("change", function() {

        if (this.value != "null") {//use this.value to get value
            switch (this.value) {
                case "americas":
                    switchToAmericas();
                    break;
                case "europe":
                    switchToEurope();
                    break;
                case "asia": //ASIA PACIFIC;
                    switchToAsia();
                    break;
                case "pacific": //REST OF THE WORLD
                    switchToPacific();
                    break;
                case "null":
                    switchToNull();
                    break;
            }

        }

    });

});

/////// called when select menu item is changed ///////
function switchToPacific() {
    try {
        flashMovie.switchToPacific_fl();
    }
    catch (ex) { }
   addPacificCountries();
   $("fieldset").show("slow"); 
}
function switchToAsia() {
    try {
        flashMovie.switchToAsia_fl();
    }
    catch (ex) { }
   addAsianCountries();
   $("fieldset").show("slow"); 
}
function switchToEurope() {
    try {
        flashMovie.switchToEurope_fl();
    } catch (ex) { }
   addEuropeanCountries();
   $("fieldset").show("slow");   
}
function switchToAmericas() {
    try {
        flashMovie.switchToAmericas_fl();
    } catch (ex) { }
   addAmericanCountries();
   $("fieldset").show("slow");   
}
function switchToNull() {
    try {
        flashMovie.switchToNull_fl();
    } catch (ex) { }
   $("fieldset").hide("slow");
} 

/////these functions are called from flash,all they have to do is change select and show formTable////
function switchToEuropeSelect() {
   $("#ir_contact_form_V3_4_RegionList").val("europe");
   addEuropeanCountries();
   $("fieldset").show("slow");   
}
function switchToAmericasSelect() {
   $("#ir_contact_form_V3_4_RegionList").val("americas");
   addAmericanCountries();
   $("fieldset").show("slow");   
}
function switchToPacificSelect() {
   $("#ir_contact_form_V3_4_RegionList").val("pacific"); //ROTW
   addPacificCountries();
   $("fieldset").show("slow");   
}
function switchToAsiaSelect() {
   $("#ir_contact_form_V3_4_RegionList").val("asia"); //ASIA PACIFIC
   addAsianCountries();
   $("fieldset").show("slow"); 
}
function switchToNullSelect() {
   $("#ir_contact_form_V3_4_RegionList").val("null");
   $("fieldset").hide("slow");  
}


///////change the countries in country selection box depending on selected region///////
var europeArr = new Array("Italy", "Netherlands", "United Kingdom", "France", "Ireland", "Spain", "Portugal", "Greece", "Poland", "Russia", "Germany", "Belgium");  
var naArr = new Array("United States", "Canada", "Mexico", "Argentina", "Aruba", "Bolivia", "Brazil", "Chile", "Columbia", "Costa Rica", "Cuba", "Dominican Republic", "Ecuador", "El Salvador", "French Guiana", "Guadeloupe", "Guatemala", "Haiti", "Honduras", "Martinique", "Nicaragua", "Panama", "Paraguay", "Peru", "Puerto Rico", "Saint Barthelemy", "Saint Martin", "Saint Pierre and Miquelon", "Uruguay", "Venezuela");
var naValArr = new Array("USA", "Canada", "Mexico", "Argentina", "Aruba", "Bolivia", "Brazil", "Chile", "Columbia", "Costa Rica", "Cuba", "Dominican Republic", "Ecuador", "El Salvador", "French Guiana", "Guadeloupe", "Guatemala", "Haiti", "Honduras", "Martinique", "Nicaragua", "Panama", "Paraguay", "Peru", "Puerto Rico", "Saint Barthelemy", "Saint Martin", "Saint Pierre and Miquelon", "Uruguay", "Venezuela");
var asiaPacArr = new Array("New Zealand", "Australia", "Japan", "China", "South Korea", "Indonesia", "Singapore", "Thailand", "Philippines", "India");
var rotwArr = new Array("Antilles", "Middle East & Africa", "Egypt", "Israel", "Haifa-Tirat Carmel", "Botswana", "Zimbabwe", "South Africa");
var subjectArr = new Array("Annual Report", "Stock Purchase", "Dividend Reinvestment", "Stock Transfer", "Web Site Feedback", "Company Information", "Investor Information", "School Project","Product Feedback", "Other");
var subjectNorthArr = new Array("Annual Report", "Stock Purchase", "Dividend Reinvestment", "Stock Transfer", "Web Site Feedback", "Company Information", "Investor Information", "School Project", "Product Feedback", "Ketchup Pin", "Other");
var subjectAsiaArr = new Array("Annual Report", "Stock Purchase", "Dividend Reinvestment", "Stock Transfer", "Web Site Feedback", "Company Information", "Investor Information", "School Project", "Product Feedback", "Other");
var subjectRotwArr = subjectAsiaArr;
var subjectEuropeArr = subjectAsiaArr;

var opts = $( 'option', "#ir_contact_form_V3_4_CountryDropDownList");

///////the right box html for each right content box///////
var europeRtContent = "<table>                        <tr><td><b>Europe Contacts</b></td></tr>                        <tr><td>UK</td><td>0800-0213-33-40</td></tr>                        <tr><td>Italy</td><td>0800-0213-33-40</td></tr>                        <tr><td>Netherlands</td><td>0800-0213-33-40</td></tr>                        </table> ";

var americasRtContent = "      <p>At Heinz, we look forward to hearing what\'s on the minds of our customers.</p>      <p><b>Instant Answers</b><br/>We have listened and developed an exensive list of Frequently Asked Questions      to help answer your questions immediately.</p>      <div id=\"FAQ_Btn\">Frequently Asked Questions</div>      <p>For general consumer product questions, information about current promotions or suggestions, please contact      <b>(800) 255-5750.</b> You may also fill out the form below to email Consumer Affairs.</p> ";

var pacificRtContent = "<table>                        <tr><td><b>Pacific Contacts</b></td></tr>                        <tr><td>Product Inquiries</td><td>1800-037-058</td></tr>                        <tr><td>For Baby Feeding Inquiries</td><td>1800-633-333</td></tr>                        </table> ";

var asiaRtContent = "<table>                        <tr><td><b>Asia Contacts</b></td></tr>                        <tr><td>Product Inquiries</td><td>1800-037-058</td></tr>                        <tr><td>For Baby Feeding Inquiries</td><td>1800-633-333</td></tr>                        </table> ";


function addEuropeanCountries() {
   $("#ir_contact_form_V3_4_CountryDropDownList > option").remove();
   $("#ir_contact_form_V3_4_SubjectDropDownList > option").remove();
   for(i = 0; i<europeArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + europeArr[i] + '\">'+ europeArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_CountryDropDownList")[0] ); 
   }
   for(i = 0; i<subjectEuropeArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + subjectArr[i] + '\">'+ subjectArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_SubjectDropDownList")[0] ); 
   }
   //change right content box to info on first country in region's dropdown list
   setCountryListBehavior();
   var selItm= $("#ir_contact_form_V3_4_CountryDropDownList option:first").val();   
   $("#ir_contact_form_V3_4_CountryHiddenField").attr("value", selItm);//set invisible field w/property for data submission
   
   var subtm= $("#ir_contact_form_V3_4_SubjectDropDownList option:first").val();
   $("#ir_contact_form_V3_4_SubjectHiddenField").attr("value", subtm);//set invisible subject field
   
   setCountryInfo(selItm);
   
}

function addPacificCountries() {
   $("#ir_contact_form_V3_4_CountryDropDownList > option").remove();
   $("#ir_contact_form_V3_4_SubjectDropDownList > option").remove();
   for(i = 0; i<rotwArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + rotwArr[i] + '\">'+ rotwArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_CountryDropDownList")[0] ); 
   }
   for(i = 0; i<subjectRotwArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + subjectArr[i] + '\">'+ subjectArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_SubjectDropDownList")[0] ); 
   }
   //change right content box tp info on first country in region's dropdown list
   setCountryListBehavior();
   var selItm= $("#ir_contact_form_V3_4_CountryDropDownList option:first").val();  
   $("#ir_contact_form_V3_4_CountryHiddenField").attr("value", selItm);//set invisible field w/property for data submission  
   
   setCountryInfo(selItm);  
}

function addAsianCountries() {
   $("#ir_contact_form_V3_4_CountryDropDownList > option").remove();
   $("#ir_contact_form_V3_4_SubjectDropDownList > option").remove();
   for(i = 0; i<asiaPacArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + asiaPacArr[i] + '\">'+ asiaPacArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_CountryDropDownList")[0] ); 
   } 
   for(i = 0; i<subjectAsiaArr.length; i++){//add all the eu countries from array
      opts = opts.add( $('<option value=\"' + subjectArr[i] + '\">'+ subjectArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_SubjectDropDownList")[0] ); 
   }
   
   //change right content box tp info on first country in region's dropdown list
   setCountryListBehavior();   
   var selItm= $("#ir_contact_form_V3_4_CountryDropDownList option:first").val(); 
   $("#ir_contact_form_V3_4_CountryHiddenField").attr("value", selItm);//set invisible field w/property for data submission        
   setCountryInfo(selItm);
}

function addAmericanCountries() {
   $("#ir_contact_form_V3_4_CountryDropDownList > option").remove();
   $("#ir_contact_form_V3_4_SubjectDropDownList > option").remove();
   for(i = 0; i<naArr.length; i++){//add all the eu countries from array
       opts = opts.add($('<option value=\"' + naValArr[i] + '\">' + naArr[i] + '</option>').appendTo("#ir_contact_form_V3_4_CountryDropDownList")[0]);
  }
   
   
   for(i = 0; i<subjectNorthArr.length; i++){//add all the na countries from array
      opts = opts.add( $('<option value=\"' + subjectNorthArr[i] + '\">'+ subjectNorthArr[i] +'</option>').appendTo("#ir_contact_form_V3_4_SubjectDropDownList")[0] ); 
   }
   
   //change right content box tp info on first country in region's dropdown list
   setCountryListBehavior();   
   var selItm= $("#ir_contact_form_V3_4_CountryDropDownList option:first").val(); 
   $("#ir_contact_form_V3_4_CountryHiddenField").attr("value", selItm);//set invisible field w/property for data submission   
   
   setCountryInfo(selItm);
}



function setCountryListBehavior(){
    $("#ir_contact_form_V3_4_CountryDropDownList").bind("change", function() {
        if (this.value != "null") {//use this.value to get value
            $("#ir_contact_form_V3_4_CountryHiddenField").attr("value", this.value); //set invisible field w/property for data submission
            setCountryInfo(this.value);
        }

        //if this.value=usa, add pickle pin option. if not, make sure pickle pin option isn't on list
        if (this.value == "USA") {
            if ($("#ir_contact_form_V3_4_SubjectDropDownList > option[value='Ketchup Pin']").length < 1) {
                $("#ir_contact_form_V3_4_SubjectDropDownList").append('<option value=\"Ketchup Pin\">Ketchup Pin</option>');
            }
        }
        else {
            $("#ir_contact_form_V3_4_SubjectDropDownList > option[value='Ketchup Pin']").remove();
        }
    });

}

function setCountryInfo(country){
	if(countryInfo[country] == undefined) {
		$("#theRightContentBox").html(baseCountryInfoString);   	
	}
	else {
	$("#theRightContentBox").html(baseCountryInfoString + countryInfo[country]); 
	}
}