// JavaScript Document - Contact Us
//Add new variables (should match the class name of the option tag, besides 'external') with new URLs if required. gotoPage() may need additions if added.

var partnerApplicationURL = "http://www.centurylink.com/business/partners/partner-application.html";
var agencyContact = "http://www.centurylinkfederalcontacts.com/lyam/";
var netContracts = "http://qwest.centurylink.com/networx/contactus/";

//Initialize variables
var blockContainer;
var isValids;
var catId; 
var tooltipContent;
var winWidth = $(window).width(); 
var winHeight = $(window).height();
var external = false;
var thisVal;
var count = 0;
var tipParentText;
var tooltipShown = false;
var formIsValid = true;
var abc;
var validator;
var isRadio = false;

////////////////////////////////////////
//WIP: check to see if a path exists and open a category onLoad
////////////////////////////////////////
function openCat(){
    log.info("openCat", "Calling openCat.", 5);
    //    var thisURL = document.location.href.toString();
    var refURL = document.referrer;
    log.info("openCat", "Document.refrerrer: " + thisURL, 3);
    var thisURL = document.location.href;
    var fedGovern = thisURL.indexOf("federalGovernment");
    var stateLocal = thisURL.indexOf("stateGovernment");
    var education = thisURL.indexOf("education");
    var largeBiz = thisURL.search("largeBusiness");
    
    var voipProd = refURL.search("http://www.centurylink.com/smallbusiness/");
    
    if (fedGovern != -1) {
        // $("div.bmg_contact_tab_off").trigger("click");
        
		//$("div#tab3a").find("div.catContent").slideDown("slow");
		$("div#tab3a").find("h2").trigger("click");
		
        $("div#tab3a").addClass("bmg_theme_action_call_wht_contact").removeClass("bmg_theme_action_call_wht_contact_off");
    }
    else 
        if (largeBiz != -1 || voipProd != -1) {
            // $("div.bmg_contact_tab_off").trigger("click");
			
            //$("div#tab1a").find("div.catContent").slideDown("slow");
			$("div#tab1a").find("h2").trigger("click");
			
			
            $("div#tab1a").addClass("bmg_theme_action_call_wht_contact").removeClass("bmg_theme_action_call_wht_contact_off");
        }
        else 
            if (stateLocal != -1 || education != -1) {
                // $("div.bmg_contact_tab_off").trigger("click");
                
				//$("div#tab2a").find("div.catContent").slideDown("slow");
				$("div#tab2a").find("h2").trigger("click");
				
                $("div#tab2a").addClass("bmg_theme_action_call_wht_contact").removeClass("bmg_theme_action_call_wht_contact_off");
            }
}


////////////////////////////////////////
//if class 'external' exists in the option, goes to URLs defined in the variables on top. If not defined, the option tag also needs to have a class with the same name as the variable, depending on where the URL points to)
////////////////////////////////////////
function gotoPage(n, thisOpt){
    log.info("gotoPage", "Calling gotoPage().", 5);
    external = true;
    try {
        if ($(thisOpt).hasClass('agencyContact')) {
            $(n).attr({
                "href": agencyContact,
                "target": "_blank"
            });
        }
        else 
            if ($(thisOpt).hasClass('netContracts')) {
                $(n).attr({
                    "href": netContracts,
                    "target": "_blank"
                });
            }
    } 
    catch (err) {
    }
}

////////////////////////////////////////
//Basic validation and setting of booleans, as well as routing to gotoPage() for external links
////////////////////////////////////////
function isValid(n, catId, blockContainer, valContainer, thisVal, actionURL){
    log.info("isValid", "Calling isValid", 5);
    var visBlocks = $(blockContainer).find("select").parent("div").filter(":visible");
    isValids = true;
    $(n).attr({
        "href": "#",
        "target": ""
    });
    $(visBlocks).children('select').find('option:selected').each(function(){
        thisVal = this.value;
        if ($(this).hasClass('external')) {
            gotoPage(n, this);
            isValids = false;
        }
        else {
            isValids = true;
            external = false;
        }
    });
    log.info("isValid", "All fields valid: " + isValids, 5);
    if (isValids) {
        sendValues(n, catId, blockContainer, valContainer, actionURL);
    }
    else {
        window.open($(n).attr('href'), 'newWindow', '', '');
    }
}

jQuery.validator.addMethod("selectNone", function(value, element){
    if (element.value == "" || element.value == "select" || element.value == "--- Select Area of Interest ---" || element.value == "--- Select Contract ---" || element.value == "--- Select Metro Area for MAA ---") {
        return false;
    }
    else 
        return true;
}, "<span class='abc'></span>Please select an option.");

var clickedCategory;
function validateFields(n){
    if (typeof n == 'undefined') {
        clickedCategory = $(".catBlock:eq(1)");
        n = clickedCategory.find("a.bmg_arrow_icon_grLt");
        //n.find("span").text("abc")
        //$(n).parents().find(".bmg_errorContainer").show()
    }
    
    validator = $("#bmg_mainForm").bind("invalid-form.validate", function(){
        clickedCategory.find(".bmg_errorContainer").html("<span><h3>" + validator.numberOfInvalids() + " required field(s) missing and highlighted below. </h3></span>");
    }).validate({
        onfocusout: false,
        onsubmit: true,
        onchange: false,
        ignore: ".hidden",
        errorElement: "div",
        errorContainer: clickedCategory.find(".bmg_errorContainer"),
        rules: {
            pubPriInterestArea: {
                required: true,
                selectNone: true
            },
            pubPriState: {
                required: true,
                selectNone: true
            },
            stateLocalInterestArea: {
                required: true,
                selectNone: true
            },
            stateLocalState: {
                required: true,
                selectNone: true
            },
            fedGovInterestArea: {
                required: true,
                selectNone: true
            },
            fedGovContractQuest: {
                required: true,
                selectNone: true
            },
            fedGovContractQuestMAA: {
                required: true,
                selectNone: true
            },
            quesType: {
                required: true
            }
        },
        messages: {
            pubPriInterestArea: {
                required: "<p><label for='pubPriInterestArea'> Select an Area of Interest.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select an Area of Interest.</label></p>"
            },
            pubPriState: {
                required: "<p> <label for='pubPriState'> Select a State/Province.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select a State/Province.</label></p>"
            },
            
            stateLocalInterestArea: {
                required: "<p><label for='stateLocalInterestArea'> Select an Area of Interest.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select an Area of Interest.</label></p>"
            },
            stateLocalState: {
                required: "<p> <label for='stateLocalState'> Select a State/Province.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select a State/Province.</label></p>"
            },
            fedGovInterestArea: {
                required: "<p><label for='fedGovInterestArea'> Select an Area of Interest.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select an Area of Interest.</label></p>"
            },
            fedGovContractQuest: {
                required: "<p> <label for='fedGovContractQuest'> Select a Contract.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select a Contract.</label></p>"
            },
            fedGovContractQuestMAA: {
                required: "<p><label for='fedGovContractQuestMAA'> Select a Metro Area.</label></p>",
                selectNone: "<p><label for='pubPriInterestArea'> Select a Metro Area.</label></p>"
            },
            quesType: {
                required: "<p><label for='quesType'>  Select any one CenturyLink Channel</label></p>"
            }
        }
    });
    
}

////////////////////////////////////////
//Builds the validation - rules and messages, manipulates error container/messages and routes to  sendValues() to builds args
////////////////////////////////////////
function validateThis(n, valContainer, actionURL){
    log.info("validateThis", "Calling validateThis", 5);
    blockContainer = $(n).parents(".catBlock");
    $(blockContainer).siblings().find("select, input").addClass("hidden");
    $(blockContainer).find("div:hidden").children("select, input").addClass("hidden");
    $(blockContainer).find("select").each(function(i){
        $("option:first", this).val("select");
    });
    var hasChoices = $(blockContainer).find("input:radio").length;
    //$(blockContainer).find("select").removeClass("hidden");
    catId = $(blockContainer).find("h2.catName").attr('id');
    $('select').change(function(){
        if ($(this).valid()) {
        }
        else {
        }
    });
    validateFields(n);
    $(blockContainer).siblings().find("div.bmg_errorContainer").filter(":not:empty").css("border", "1px solid red");
    if ($("form#bmg_mainForm").valid()) {
        isValid(n, catId, blockContainer, valContainer, thisVal, actionURL);
        formIsValid = true;
    }
    else {
        $(blockContainer).siblings().find("div.bmg_errorContainer").hide();
        $(blockContainer).find("div.bmg_errorContainer").show();
        formIsValid = false;
        if (hasChoices >= 0) {
            $(blockContainer).find("input:radio:first").parent("p").prev("p").after($("div.error"))
        }
    }
}


////////////////////////////////////////
//Builds args, and submits forms only if the select option does not route to an external link
////////////////////////////////////////
function sendValues(n, catId, blockContainer, valContainer, actionURL){
    log.info("sendValues", "Calling sendValues", 5);
    var catNameIndex = $("form[name=bmg_mainForm]").find("h2.catName").index($(blockContainer).find("h2"));
    catNameIndex = catNameIndex + 1;
    args = "";
    baseURL = "";
    $(valContainer).value = "";
    if ($(blockContainer).find("select.interest").length > 0) {
        if (catNameIndex == 1) {
            args += "Public/Private Company~" + $("div:visible", blockContainer).children("select:first").val() + "~" + $("div:visible", blockContainer).children("select:first").find("option:selected").attr("dbid") + ";";
        }
        else 
            if (catNameIndex == 2) {
                args += "State/Local Gov/Education~" + $("div:visible", blockContainer).children("select:first").val() + "~" + $("div:visible", blockContainer).children("select:first").find("option:selected").attr("dbid") + ";";
            }
            else 
                if (catNameIndex == 3) {
                    var thisText;
                    var visSelLen = $("div:visible", blockContainer).children("select").length;
                    $("div:visible", blockContainer).children("select:last").find("option:selected").each(function(){
                        thisText = $(this).text();
                        thisDbid = $(this).attr("dbid");
                        if (visSelLen == 1) {
                            args += "Federal~" + thisText + "~" + thisDbid + ";";
                        }
                        else 
                            if (visSelLen == 2) {
                                args += "Federal Contract~" + thisText + "~" + thisDbid + ";";
                            }
                            else 
                                if (visSelLen == 3) {
                                    args += "Federal MAA~" + thisText + "~" + thisDbid + ";";
                                }
                    });
                }
        // 	args+=catId+"|";
        args += (catNameIndex) + ",";
    }
    
    if ($(blockContainer).find("input[name=quesType]").is(":checked")) {
        args += catId + "~";
        args += $(blockContainer).find("input[name=quesType]:checked").next().text() + "~-1;";
        args += (catNameIndex) + ",";
        args += $(blockContainer).find("input[name=quesType]:checked").attr("id") + ";";
        args += $(blockContainer).find("input[name=quesType]:checked").val() + ";";
        args += $("form[name=bmg_mainForm]").find("input[name=quesType]").index($(blockContainer).find("input[name=quesType]:checked")) + 1 + ",";
    }
    if ($(blockContainer).find("div").hasClass("intState")) {
        if ($(blockContainer).find("select.interest").length > 0) {
            args += $(blockContainer).find("select.interest").children("option:selected").attr("id") + ";";
            args += $(blockContainer).find("select.interest").val() + ";";
            args += $(blockContainer).find("select.interest").get(0).selectedIndex + ",";
        }
        
        if ($(blockContainer).find("select.state").length > 0) {
            args += "-1" + ";";
            args += $(blockContainer).find("select.state").children("option:selected").val() + ";";
            args += $(blockContainer).find("select.state").children("option:selected").attr("region") + ";";
            args += $(blockContainer).find("select.state").get(0).selectedIndex + ",";
        }
    }
    
    if ($("div.fedGov", blockContainer).find("select").parent("div").is(":visible")) {
        $("div:visible", blockContainer).children("select").find("option:selected").each(function(){
            args += $(this).attr("id") + ";";
            args += $(this).val() + ";";
            args += $(this).parent("select").get(0).selectedIndex + 1 + ",";
        });
    }
    
    if (!external) {
        $(valContainer).val(args);
        hiddenParams = $(valContainer).val();
        
        if (isRadio && ($("input[name=quesType]:checked").hasClass("alliance"))){
			baseURL = partnerApplicationURL;
			//document.bmg_mainForm.action = baseURL;
		}
        else {
			baseURL += actionURL + "?&parameters=" + hiddenParams;
        }
         $("#bmg_mainForm").attr("action", baseURL)
        //alert(actionURL)
        log.info("sendValues", "Form action: " + $("form[name=bmg_mainForm]").attr("action"), 3);
        log.info("sendValues", "Value in hidden field: " + hiddenParams, 3);
        // baseURL=actionURL;
        $("form[name=bmg_mainForm]").submit();
        //return false;
    }
}

//Get the basic tooltip structure ready
var tooltipCont = "<div class='tf_toolTip tf_tool'><div class='tf_toolTip_container'><div class='tf_toolTip_title tf_toolTip_title_smaller'><div><h3 class='headingAlign'></h3></div></div><div class='tf_toolTip_cont'><p class='preSale'></p><div class='bmgCL_clear'></div></div></div></div>"

function genTooltip(n){
    log.info("genTooltip", "Calling genTooltip", 5);
    $("div.tf_tool").remove();
    tooltipShown = true;
    blockContainer = $(n).parents(".tooltip_block_container");
    var thisIndex = $("a.tooltip", blockContainer).index(n) + 1; // the index from all the tooltip trigger links
    var thisWidth = $(n).width();
    var thisHeight = $(n).height();
    var thisPos = $(n).position();
    var thisOffset = $(n).offset();
    var $this = $(n);
    log.info("genTooltip", "Tooltip xml: " + xmlURL, 2);
    try {
        if (productLanding) {
            xmlURL = "/qptcms/qCmsRepository/Global/largeBusiness/xml/tooltipProducts.xml"; // load the products landing xml
            //tipParentText = $(n).text();
            //  tipParentText = $(n).text();
        }
        else 
            if (contactUs) {
                xmlURL = "/qptcms/qCmsRepository/Global/largeBusiness/xml/tooltip.xml"; //load the contact-us landing page xml
                tipParentText = $(n).prev().text();
            }
    } 
    catch (err) {
        log.error("genTooltip", "JS: Error: " + err);
    }
    $.ajax({
        type: "GET",
        url: xmlURL,
        cache: true,//use the cached XML for subsequent calls
        dataType: "xml",
        success: function(xml){
            log.info("genTooltip", "Tooltip xml loaded successfully: " + xmlURL, 2);
            var tipContent;
            var tipTitle;
            $(xml).find('tooltipContainer tooltip').each(function(){
                var tipId = $(this).attr('id');
                tipContent = $(this).parent('tooltipContainer').children("tooltip[id=tooltip_" + thisIndex + "]").find('content').text();
                tipTitle = $(this).parent().children("tooltip[id=tooltip_" + thisIndex + "]").find('title').text();
                tipParentText = $(this).parent().children("tooltip[id=tooltip_" + thisIndex + "]").find('title').text();
            });
            //inject the tooltip into the DOM
            $("body").append(tooltipCont);
            var winWidth1 = $(window).width(); // new tooltip width
            var winHeight1 = $(window).height(); // new tooltip height
            var tooltip = $("div.tf_tool"); //the tooltip container
            var tooltipWidth = $(tooltip).width();
            var tooltipHeight = $(tooltip).height();
            var tooltipPos = $(tooltip).position();
            var tooltipLeft = tooltipPos.left;
            //the default positioning of the tooltip
            $(tooltip).css({
                height: tooltipHeight,
                left: (thisOffset.left) + (thisWidth),
                top: thisOffset.top - 35
            });
            //insert content into the tooltip 
            $(tooltip).find("div.tf_toolTip_cont p").append(tipContent);
            if (productLanding) {
                $(tooltip).find("div.tf_toolTip_title h3").append(tipParentText);
            }
            
            else 
                if (contactUs) {
                    $(tooltip).find("div.tf_toolTip_title h3").append(tipTitle);
                }
            log.info("genTooltip", "Tooltip Title:  " + tipTitle, 5)
            log.info("genTooltip", "Tooltip content: " + tipContent, 5)
            
            //new tooltip dimensions after content feed
            var newTooltipHeight = $("div.tf_toolTip").height();
            var newTooltipWidth = $("div.tf_toolTip").width();
            // get the browser-agnostic scrollTop and scrollLeft positions
            if (document.documentElement && (document.documentElement.scrollTop)) {
                browserTopY = document.documentElement.scrollTop;
            }
            else {
                browserTopY = document.body.scrollTop;
            }
            
            if (document.documentElement && (document.documentElement.scrollLeft)) {
                browserLeftX = document.documentElement.scrollLeft;
            }
            else {
                browserLeftX = document.body.scrollLeft;
            }
            
            var thisOffset1 = $(n).offset(); //new offset iof the tooltip trigger
            var thisPosition1 = $(n).position();
            //calculate the space for the 4 areas
            var leftSpace = thisOffset1.left - browserLeftX;
            var rightSpace = winWidth1 - ((thisOffset1.left + thisWidth) - browserLeftX);
            var topSpace = thisOffset1.top - browserTopY;
            var bottomSpace = winHeight1 - (thisOffset1.top - browserTopY);
            //get booleans per area
            var isRight = (newTooltipWidth <= rightSpace);
            var isLeft = (newTooltipWidth <= leftSpace);
            var isTop = (newTooltipHeight <= topSpace);
            var isBottom = (newTooltipHeight <= bottomSpace);
            
            if (isRight && (newTooltipHeight <= winHeight1 - ($(tooltip).offset().top - browserTopY)) && (topSpace > 35)) {
                //alert("1");
                $(tooltip).addClass('tf_toolTip').removeClass('tf_toolTip3, tf_toolTip1, tf_toolTip2')
                $(tooltip).css({
                    left: (thisOffset1.left + thisWidth)
                });
            }
            else 
                if (isLeft && ((newTooltipHeight <= winHeight1 - ($(tooltip).offset().top - browserTopY))) && (topSpace > 35)) {
                    //alert("2");
                    $(tooltip).addClass('tf_toolTip1').removeClass('tf_toolTip, tf_toolTip3, tf_toolTip2')
                    $(tooltip).css({
                        left: (thisOffset1.left) - (tooltipWidth)
                    });
                }
                else 
                    if (isTop && ($(tooltip).offset().left - (tooltipWidth / 2) - (thisWidth / 2) - browserLeftX >= 0) && (rightSpace >= tooltipWidth / 2 - thisWidth / 2)) {
                        //alert("3");
                        $(tooltip).addClass('tf_toolTip3').removeClass('tf_toolTip, tf_toolTip1, tf_toolTip2')
                        //alert(tooltipHeight);
                        $(tooltip).css({
                            left: (thisOffset1.left - ((tooltipWidth / 2) - (thisWidth / 2))),
                            top: (thisOffset1.top - newTooltipHeight - 5)
                        });
                    }
                    else 
                        if (isBottom && ($(tooltip).offset().left - (tooltipWidth / 2) - (thisWidth / 2) - browserLeftX >= 0) && (rightSpace >= tooltipWidth / 2 - thisWidth / 2)) {
                            //alert("4");
                            $(tooltip).addClass('tf_toolTip2').removeClass('tf_toolTip, tf_toolTip1, tf_toolTip3');
                            $(tooltip).css({
                                left: (thisOffset1.left - (tooltipWidth / 2) + (thisWidth / 2)),
                                top: (thisOffset1.top + thisHeight)
                            });
                        }
                        else {
                            //alert("5")
                            window.resizeBy(tooltipWidth + 20, thisHeight + tooltipHeight + 20);
                            $(tooltip).css({
                                left: (thisOffset1.left + (thisWidth))
                            });
                            
                            $(tooltip).addClass('tf_toolTip').removeClass('tf_toolTip3, tf_toolTip1, tf_toolTip2')
                        	//$(tooltip).find("div.tf_toolTip_title h3").html("Browser Window Size")
                        	//$(tooltip).find("div.tf_toolTip_cont p").html("<span style='color:#ff0000'>Resizing the browser to enable viewing this content.<br> Please hover over the link again.</span>");
                        }
        },
        failure: function(msg){
            log.error("", "Ajax failure: " + msg)
        }
    });
}

function desTooltip(n){
    log.info("desTooltip", "Calling desTooltip", 5);
    $("div.tf_toolTip, div.tf_toolTip1,div.tf_toolTip2, div.tf_toolTip3").remove();
    tooltipShown = false;
}

var nextCatContent;
var accordOpened = false;


function openAccord(n){
	//alert($("form#bmg_mainForm").valid());
	clickedCategory = $(n).parents(".catBlock:first");
	clickedCategory.find(".bmg_errorContainer").hide().empty();
    //remove the class 'hidden' to enable validation
    try {
        validator.resetForm();
        validator.prepareForm();
        validator.hideErrors();
    }
    catch (e) {
		//alert(e.message);
	}
    $(n).parents(".catBlock").find("select, input").removeClass("hidden");
    log.info("openAccord", "Calling openAccord", 5);
    nextCatContent = $(n).next("div.catContent");
    $(n).parents("div.catBlock").siblings().find("div.initHidden").hide(); //hide the selects that are initially hidden
    //reset selects to defaults
    $(n).parents("div.catBlock").siblings().find("select").each(function(){
        $("option:first", this).attr("selected", "selected");
        
    });
    //reset radio buttons to default
    $(n).parents("div.catBlock").siblings().find("input:radio").each(function(){
        $(this).attr("checked", false);
    });
    
    if (nextCatContent.is("visible")) {
        accordOpened = true;
    }
    $("form[id=bmg_mainForm]").find("div.catContent").not(nextCatContent).each(function(i){
        $(this).slideUp("fast");
    });
	
    $(n).parents("div.catBlock").siblings().removeClass("bmg_theme_action_call_wht_contact").addClass("bmg_theme_action_call_wht_contact_off")
    $(n).next("div.catContent").slideDown("fast");
    $(n).parents(".catBlock").find("select, input").filter(function(){
        return $(this).is(":hidden");
    }).addClass("hidden");
    log.info("openAccord", "Is the form Valid: " + formIsValid, 5);

    //isRadio = true;

    if (!formIsValid) {
        try {
            $('#bmg_mainForm')[0].reset();
            validator.resetForm();
            //bmg_mainForm.submit = {};
            $(n).parents("div.catBlock").siblings().find("div.initHidden").hide();
        } 
        catch (err) {
            log.error("Error: " + err.message);
        }
    }
}

var defWinWidth;
function showHover(n){
    var isVisible = $(n).find("div.catContent").is(":visible");
    if (!isVisible) {
        $(n).removeClass("bmg_theme_action_call_wht_contact_off");
        $(n).addClass("bmg_theme_action_call_wht_contact");
    }
    else {
        $(n).removeClass("bmg_theme_action_call_wht_contact_off");
        $(n).addClass("bmg_theme_action_call_wht_contact");
    }
}

function hideHover(n){
    var isVisible = $(n).find("div.catContent").is(":visible")
    if (!isVisible) {
        $(n).removeClass("bmg_theme_action_call_wht_contact");
        $(n).addClass("bmg_theme_action_call_wht_contact_off");
    }
    else {
        $(n).removeClass("bmg_theme_action_call_wht_contact_off");
        $(n).addClass("bmg_theme_action_call_wht_contact");
    }
}
/*
 * Temporary addition for teaLeafSess.
 */
if(typeof teaLeafSess == 'undefined'){var teaLeafSess=""}

$(document).ready(function(){
    var actionURL = $("form[name=bmg_mainForm]").attr("action");
    var valContainer = $("form[name=bmg_mainForm]").find("input:hidden");
    $("div.fedGov select").each(function(){
        $("option", this).each(function(){
            if ($(this).val() == "Contact CenturyLink team for your agency") {
                $(this).addClass("external agencyContact");
            }
            if ($(this).val() == "Networx") {
                $(this).addClass("external netContracts");
            }
        });
    });
	$("a.popup").click(function(e, n){
		e.preventDefault();
	});

    $("h2.catName").bind("click", function(n){
		if ($(this).children().text() == "Public/ Private Companies") {
			location.href = "/business/contact-us-v1b.html";
		}
        else {
			openAccord(this);
        }
    });

	$("a.tooltip").hoverIntent(function(n){
		if (!tooltipShown) {
			genTooltip(this);
		}
    }, function(){
        desTooltip(this);
    });
    $("a.bmg_arrow_icon_grLt").click(function(){
        var valContainer = $("form[name=bmg_mainForm]").find("input:hidden");
        //	$(valContainer).value="";
        
        if($(this).hasClass("bmgCL_partners")){
        	isRadio = true;
        }
        else {
        	isRadio = false;
        }
        validateThis(this, valContainer, actionURL);
    });
    $("div.catBlock").hover(function(n){
        showHover(this);
    }, function(n){
        hideHover(this);
    });
    $("div.catBlock").bind("click", function(n){
        showHover(this);
    }, function(n){
        hideHover(this);
    });
    
	///////1 
    $("#fedGovInterestArea").bind("change", function(){
        if ($("option:selected", this).index() == 0) {
            $("#FG_content_Contract, #FG_content_MAA").hide().find("select").each(function(){
                $(this).val($(this).children("option:last").val());
                //$(this).valid();
            })
			//if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();			
        }
		else if($("option:selected", this).index() == 5){
			$("#FG_content_Contract").show().find("select").removeClass("hidden");
				$("#FG_content_Contract").find("select").each(function(){
			    	$(this).val($(this).children("option:first").val());
               	 //$(this).valid();
            	})
			if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();
		}
        else {
			 $("#FG_content_Contract,#FG_content_MAA").hide().find("select").addClass("hidden"); 
			$("#FG_content_MAA, #FG_content_Contract").find("select").each(function(){
				$(this).val($(this).children("option:last").val());
				$(this).valid();
			})
			if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();
        }
    })
	////////2
    $("#fedGovContractQuest").bind("change", function(i,n){
		$("#FG_content_MAA").hide().find("select").addClass("hidden");
        if ($("option:selected", this).index() == 0) {
            $("#FG_content_MAA").find("select").each(function(){
                //set a valid value
                $(this).val($(this).children("option:last").val());
                //$(this).valid();
            })
			//if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();			
        }
		else if($("option:selected", this).index() == 5){
			$("#FG_content_MAA").show().find("select").removeClass("hidden");
			$("#FG_content_MAA").find("select").each(function(){
                //set a valid value
                $(this).val($(this).children("option:first").val());
                //$(this).valid();
            })
			if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();			
		}
		
        else {
			$("#FG_content_MAA").hide().find("select").addClass("hidden");
			$("#FG_content_MAA").find("select").each(function(){
                //set a valid value
                $(this).val($(this).children("option:last").val());
                //$(this).valid();
            })
			if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();			
        }
    }) 
	///////3....#FG_content_MAA
    $("#fedGovContractQuestMAA").bind("change", function(){
        $("#FG_content_MAA").find("select").each(function(){
        	//alert('')
			if($(this).valid()){
				clickedCategory.find(".bmg_errorContainer").hide().empty();
			}		
        })
    })
	 $("input:radio").bind("change", function(){
		if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();
	})
	//if($(this).valid())	clickedCategory.find(".bmg_errorContainer").hide().empty();
    validateFields();
	    openCat();
});

