var menuTimer;
var menuID;
var iFrameID;
var indexPage=false;
var boolBPMenuVisible = false;
var largerImage;

var strMainNavSeparatorSelector = ".separator";


//////////////////    Building products drop down  ////////////////////////////////////////////////
$(document).ready(function(){   
  $('#bpMenu').hide();
  $('.dropDownMenu').hide();
	  $('#bpControl, #bpLink').click(function(){
	//alert("$('#bpMenu').css('display') = " + $('#bpMenu').css('display'));
	        if ($('#bpMenu').css('display') == 'none'){
	            $('#bpMenuIframe').show();
	            $('#bpMenu').slideDown(800);            
	            $('#bpControl img').attr('src','/img/img_BP_control_open.gif');
	        }else{
	            $('#bpMenu').slideUp(600);
	            $('#bpMenuIframe').hide();
	            $('#bpControl img').attr('src','/img/img_BP_control_closed.gif');
	        }
	        $(this).blur();
	        return false;
	   });
  if (indexPage) {
    setTimeout("if ($('#bpMenu').css('display') == 'none'){$('#bpControl').click();}",3000);
  } else if(boolBPMenuVisible) {
   	$("#bpControl").click();
  }
});

    
//////////////////    Main Nav Drop downs  ////////////////////////////////////////////////
$(document).ready(function(){   
   $('#navMenu ul li a.dropDownLink').hover(
     function(){
        clearTimeout(menuTimer);
        $('.dropDownMenu').hide();        
        $('.dropDownMenu2').hide();        
        $('.dropDownIframe').hide();
        $('#' + $(this).attr('id').replace('Link','Menu')).show();
        $('#' + $(this).attr('id').replace('Link','MenuIframe')).show();
        $(this).parents('li').prev(strMainNavSeparatorSelector).css('background','#ffffff');
        $(this).parents('li').next(strMainNavSeparatorSelector).css('background','#ffffff');
     },function(){
        menuID = '#' + $(this).attr('id').replace('Link','Menu');        
        menuTimer = setTimeout("$('"+menuID+"').hide(); $('.dropDownIframe').hide();",10);
        if (!($(this).hasClass('selected'))){
          if (!($(this).parents('li').prev(strMainNavSeparatorSelector).hasClass('hide')))
            $(this).parents('li').prev(strMainNavSeparatorSelector).css('background','#6a9ad9');
          if (!($(this).parents('li').next(strMainNavSeparatorSelector).hasClass('hide')))
            $(this).parents('li').next(strMainNavSeparatorSelector).css('background','#6a9ad9');
        }
     }
   )
   $('.dropDownMenu').hover(
     function(){
       clearTimeout(menuTimer);
       $('#'+ $(this).attr('id').replace('Menu','Link')).addClass('menuHover');
       $('#navMenu ul li a.menuHover').parents('li').prev(strMainNavSeparatorSelector).css('background','#ffffff');
       $('#navMenu ul li a.menuHover').parents('li').next(strMainNavSeparatorSelector).css('background','#ffffff');
     },function(){
       $(this).hide();
       if(!($('#'+ $(this).attr('id').replace('Menu','Link')).hasClass('selected'))){
         if(!($('#navMenu ul li a.menuHover').parents('li').prev('.dropDownLink').hasClass('selected')))
         {
           if(!($('#navMenu ul li a.menuHover').parents('li').prev(strMainNavSeparatorSelector).hasClass('hide')))
             $('#navMenu ul li a.menuHover').parents('li').prev(strMainNavSeparatorSelector).css('background','#6a9ad9');
         }
         if(!($('#navMenu ul li a.menuHover').parents('li').next('.dropDownLink').hasClass('selected')))
         {
           if(!($('#navMenu ul li a.menuHover').parents('li').next(strMainNavSeparatorSelector).hasClass('hide')))
             $('#navMenu ul li a.menuHover').parents('li').next(strMainNavSeparatorSelector).css('background','#6a9ad9');
         }
       }
       $('#'+ $(this).attr('id').replace('Menu','Link')).removeClass('menuHover');
       $('.dropDownIframe').hide();       
     }
   );   
});


///////////////////   "Tools" hover functions   ///////////////////////////////////////////
$(document).ready(function(){
		//var strBuildingResponsiblySrc;
		var strFindProSrc;
		var strWhereToBuySrc;
		
   	/*$(".toolBuildingResponsibly").hover(function(){
   		//strBuildingResponsiblySrc = "/img/img_building_resp_hover.gif";
   		strBuildingResponsiblySrc = $(this).attr("src").replace(".gif", "_hover.gif");
   		$(this).attr("src", strBuildingResponsiblySrc);
   	}, function() {
   		//strBuildingResponsiblySrc = "/img/img_building_responsibly.gif";
   		strBuildingResponsiblySrc = $(this).attr("src").replace("_hover.gif", ".gif");
   		$(this).attr("src", strBuildingResponsiblySrc);
   	});*/
   	
   	$("#toolProjectFolder").hover(function(){$(this).attr("src",$(this).attr("src").replace(".gif","_hover.gif"));},function(){$(this).attr("src",$(this).attr("src").replace("_hover.gif",".gif"));});
   	
   	$(".toolFindPro").hover(function() {
   		//strFindProSrc = "/img/img_find_a_pro_hover.gif";
   		strFindProSrc = $(this).attr("src").replace(".gif", "_hover.gif");
//console.log("strFindProSrc = " + strFindProSrc);
   		$(this).attr("src", strFindProSrc);
   	}, function() {
   		//strFindProSrc = "/img/img_find_a_pro.gif";
   		strFindProSrc = $(this).attr("src").replace("_hover.gif", ".gif");
//console.log("strFindProSrc = " + strFindProSrc);
   		$(this).attr("src", strFindProSrc);
   	});
   	
   	$(".toolWhereToBuy").hover(function() {
   		strWhereToBuySrc = $(this).attr("src").replace(".jpg", "_hover.jpg");
   		$(this).attr("src", strWhereToBuySrc);
   	}, function() {
   		strWhereToBuySrc = $(this).attr("src").replace("_hover.jpg", ".jpg");
   		$(this).attr("src", strWhereToBuySrc);
   	});
});

//////////////////   Design and Building Professionals link/dropdown    //////////////////////////////////
var strCustomLinkCookie = "customLink";
function setCustomLink(strType)
{
    //$.cookie("customLink", strType);
    $.cookie(strCustomLinkCookie, strType, {   path: "/" });
    $.cookie(strCustomLinkCookie, strType, {   path: "/es" });
    $.cookie(strCustomLinkCookie, strType, {   path: "/fr" });
    strType = strType.toLowerCase();
    window.location="professionalsLanding.aspx?type="+strType+"";
}
function unsetCustomLink(strType)
{
    //alert("professionalsLanding.aspx?type="+strType);
    //$.cookie(strCustomLinkCookie, null);
   $.cookie(strCustomLinkCookie, null, {   path: "/" });
   $.cookie(strCustomLinkCookie, null, {   path: "/es" });
   $.cookie(strCustomLinkCookie, null, {   path: "/fr" });
//alert("$.cookie(\"" + strCustomLinkCookie + "\") = " + $.cookie(strCustomLinkCookie));
    //strType = strType.toLowerCase();
    $("#cluetip").css("display","none");
    window.location=window.location;
}

//////////////////   Color selection functionality    //////////////////////////////////
$(document).ready(function(){
  $("ul#colorList li img").click(function(){
    if($(this).parent().parent().attr("class") == "selectable") {
    	$(this).parent().siblings().each(function() {	//	Deselect all others colors.
    		$(this).children().removeClass("selected");
    	});
    	$(this).addClass("selected");
    }
  });
});


/*
	Open a modal window containing fabrics for a particular ceiling finish.  Data is loaded via AJAX.
	@param strMGC the master grouping code
*/
/*function fCeilingsPopup(strMGC, strName) {
	var strModalWindowID = "finishesModal";
	var strAjaxTarget = strModalWindowID + "Content";
	document.getElementById(strModalWindowID).innerHTML = "<div class=\"closeButton\" style=\"width: 42px;\"><a href=\"#\" onclick=\"return fCloseModal('" + strModalWindowID + "');\" class=\"lnkClose\">close</a> <a href=\"#\" onclick=\"return fCloseModal('" + strModalWindowID + "');\"><img src=\"/img/buttons/btn_close.gif\" height=\"11\" width=\"11\" alt=\"close\" border=\"0\" class=\"btnClose\" style=\"float: right; top: -12px;\" /></a></div>";
	document.getElementById(strModalWindowID).innerHTML += "<div id=\"" + strAjaxTarget + "\"></div>";
//fAJAXRequest(strAjaxTarget, "modal.aspx", "cff", strMGC, strName, "");
	$.ajax({
		url: "/modal.aspx",
		data: "name=cff&value=" + escape(strMGC) + "&id=" + escape(strName),
		success: function(msg) {
			document.getElementById(strAjaxTarget).innerHTML = msg;
			fShow(strModalWindowID);
		}
	});
}*/

function fCeilingsPopup(productID, strName, IsNew) {
	var strModalWindowID = "finishesModal";
	var strAjaxTarget = strModalWindowID + "Content";
	document.getElementById(strModalWindowID).innerHTML = "<div class=\"closeButton\" style=\"width: 42px;\"><a href=\"#\" onclick=\"return fCloseModal('" + strModalWindowID + "');\" class=\"lnkClose\">close</a> <a href=\"#\" onclick=\"return fCloseModal('" + strModalWindowID + "');\"><img src=\"/img/buttons/btn_close.gif\" height=\"11\" width=\"11\" alt=\"close\" border=\"0\" class=\"btnClose\" style=\"float: right; top: -12px;\" /></a></div>";
	document.getElementById(strModalWindowID).innerHTML += "<div id=\"" + strAjaxTarget + "\"></div>";
//fAJAXRequest(strAjaxTarget, "modal.aspx", "cff", strMGC, strName, "");
	$.ajax({
		url: "/modal.aspx",
		data: "name=cffnew&pid=" + escape(productID) + "&id=" + escape(strName),
		success: function(msg) {
			document.getElementById(strAjaxTarget).innerHTML = msg;
			fShow(strModalWindowID);
		}
	});
}

$(function (){
    $('.imageViewLarger').click(function(){
        fViewLargerPopupwithtext($(this).attr('href'),$(this).attr('rel'));
        return false;
    }); 
    $('.swatchViewLarger').click(function(){
        fViewLargerPopupwithtext($(this).attr('href'),$(this).attr('rel'));
        return false;
    });   
    $('#viewLargerModal .closeButton a').click(function(){
        $('#viewLargerModal').hide();
    });    
});

function fViewLargerPopup(imagePath){
//alert("escape(\"" + imagePath + "\") = " + escape(imagePath) + "\nescape(\" +\") = " + escape(" +") + "\encodeURIComponent(\"" + imagePath + "\") = " + encodeURIComponent(imagePath) + "\n");
    var resizeModal = $.ajax({
                              type: "GET",
                              url: "/modal.aspx?name=image&value=" + encodeURIComponent(imagePath),
                              error:function(xhr,err,e){ alert( "Error: " + err ); },
                              success: function(msg){
                                var imageDimensions=msg.split(";");
                                $('#viewLargerImageContent').html("<img src='"+imagePath+"' />");
                                var width = parseInt(imageDimensions[0])+parseInt($('#viewLargerModal').css('padding-left'))+parseInt($('#viewLargerModal').css('padding-right'));                                
                                $('#viewLargerModal').css("width",width).show(); 
                              }
                            });      
}

function fViewLargerPopupwithtext(imagePath,imageText){

//alert("escape(\"" + imagePath + "\") = " + escape(imagePath) + "\nescape(\" +\") = " + escape(" +") + "\encodeURIComponent(\"" + imagePath + "\") = " + encodeURIComponent(imagePath) + "\n");
    var resizeModal = $.ajax({
                              type: "GET",
                              url: "/modal.aspx?name=image&value=" + encodeURIComponent(imagePath),
                              error:function(xhr,err,e){ alert( "Error: " + err ); },
                              success: function(msg){
                                $('#viewText').html(imageText);
                                var imageDimensions=msg.split(";");
                                $('#viewLargerImageContent').html("<img src='"+imagePath+"' />");
                                var width = parseInt(imageDimensions[0])+parseInt($('#viewLargerModal').css('padding-left'))+parseInt($('#viewLargerModal').css('padding-right'));                                
                                $('#viewLargerModal').css("width",width).show(); 
                              }
                            });      
}

/*
	Open a modal window For the larger Image.  Data is loaded via AJAX.
	@param 

function fViewLargerPopup(image) {
	var strModalWindowID = "viewLargerModal";
	var strAjaxTarget = strModalWindowID + "Content";
	document.getElementById(strModalWindowID).innerHTML = "<div class=\"closeButton\"><a href=\"javascript:fCloseModal('" + strModalWindowID + "');\" class=\"lnkClose\">close</a> <a href=\"javascript:fCloseModal('" + strModalWindowID + "');\"><img src=\"img/buttons/btn_close.gif\" height=\"11\" width=\"11\" alt=\"close\" border=\"0\" class=\"btnClose\" /></a></div>";
	document.getElementById(strModalWindowID).innerHTML += "<div id=\"" + strAjaxTarget + "\"></div>";
	fAJAXRequest(strAjaxTarget, "modal.aspx", "image", image, "", "");
	fShow(strModalWindowID);
}
*/
/*
	Hide a modal window.  If no id is passed, the generic class for modal windows is hidden instead of using a specific id.  JQuery is required to use this function.
	@param strID the id of the div to hide.
*/
function fCloseModal(strID) {
	if(strID == undefined) {
		$(".modalWindow").hide();
		//$(".modalWindow").attr("visibility", "hidden");
	} else {
		fHide(strID);
	}
	return false;
}

/*
	Update the source of the main photo gallery image with the provided image 
	filename.  Also, remove class "cssActive" from all thumbnails, and then add 
	that class to the thumbnail that was clicked.  JQuery is required.
	@param strImgFilename the image filename
	@param strThumbID the id attribute of the link that was clicked
*/
function fDisplayGalleryImg(strImgFilename, strThumbID) {
//alert("fDisplayGalleryImg('" + strImgFilename + "', '" + strThumbID + "') called.");
	var strPath = "img/gallery/";
	$("#photoGalleryMain img").attr("src", strPath + strImgFilename);
	$("#galleryThumbs li").removeClass("cssActive");
	$("#" + strThumbID).parent().addClass("cssActive");
//alert('$("#" + ' + strThumbID + ') = ' + $("#" + strThumbID));
//alert('$("#galleryThumbs").css("top") = ' + $("#galleryThumbs").css("top"));
	$("#galleryThumbs").css({	top: "7px"	});	//	hack to fix wierd IE 6 positioning bug
	return false;
}


/*
  Return the prefix appended to the beginning of a .NET web control by the 
  server.  The supplied string represents a classname that has been applied to 
  one of the web controls.  Using jquery, we can obtain the id attribute of a 
  form element with that class name, strip out the server-appended prefix and 
  return it.
  @param strFieldClassName the class attribute of one of the form fields
*/
function fGetDotNetPrefix(strFieldClassName) {
var debug = "";

debug += "fGetDotNetPrefix(\"" + strFieldClassName + "\") called.\n";
//alert(debug);
  var strResponse = $("." + strFieldClassName).attr("id");
debug += "strResponse = " + strResponse + "\n";
  if(strResponse == undefined) {
		strResponse = "";
  } else {
		var intIndex = strResponse.lastIndexOf("_");
		if(intIndex == -1) {
			strResponse = "";
		} else {
			strResponse = strResponse.substr(0, intIndex + 1);
debug += "strResponse = " + strResponse + "\n";
		}
  }
  
//alert(debug);
  return strResponse;
}

function fUpdateSwatch(strImage, strName, strText, strLarger) {

	var strHTML = "";
	if(strText != undefined) {
		strHTML = strText;
		if(strHTML != "") {
			strHTML += "<br />";
		}
	}
	$('.listingThumbnail').attr('src',strImage);
	if (strLarger != ""){
	  $('.swatchViewLarger').attr('href', strLarger);
	  $('.swatchViewLarger').attr('rel', strName);
	
	  $('.swatchViewLarger').show(); 
	}else{
	  $('.swatchViewLarger').attr('href','');
	   $('.swatchViewLarger').attr('rel', '');
	  $('.swatchViewLarger').hide(); 
	}	
	document.getElementById('divSwatchName').innerHTML = strName;
	return false;
}

function fUpdateFinish(strImage, strText, boolLarger) {
	var strHTML = "";
	if(strText != undefined) {
		strHTML = strText;
		if(strHTML != "") {
			strHTML += "<br /><img src=\"img/shim.gif\" height=\"3\" width=\"1\" alt=\"\" border=\"0\" /><br />";
		}
	}
	$('.listingThumbnail').attr('src',strImage);
	if (boolLarger != "0"){
	  $('.swatchViewLarger').attr('href', strImage);
	  $('.swatchViewLarger').show(); 
	}else{
	  $('.swatchViewLarger').attr('href','');
	  $('.swatchViewLarger').hide(); 
	}	
	document.getElementById('divFinishName').innerHTML = strText;
}

/*$(function(){
  $('.swatchViewLarger').click(function(){
    var image = $('#divSwatchImage img').attr('src');
    largerImage = window.open (image,"larger","scrollbars=1,width=500,height=300");
    if(window.focus){largerImage.focus();}
  });
});*/

function fShow(strDiv) {
	document.getElementById(strDiv).style.visibility = "visible";
	document.getElementById(strDiv).style.display = "block";
}

function fHide(strDiv) {
	document.getElementById(strDiv).style.visibility = "hidden";
	document.getElementById(strDiv).style.display = "none";
}


function fToggle(strID) {
	if(document.getElementById(strID).style.visibility == "hidden") {
		fShow(strID);
	} else {
		fHide(strID);
	}
}

function bindColorviewLinks(){
//alert("HERE");
  $('.colorViewLink').click(function(){
    window.open("/colorViewLanding.aspx","colorviewWin","location=no,menubar=no,scrollbars=no,status=no,resizable=no,width=950,height=720,directories=no");
    return false;
  });
}

$(function(){
  bindColorviewLinks();
});


function closeBubble()
{
    $("#cluetip").hide();
    $("#fapMenuIframe").hide();
}
/*POP UP Functions */
//function for Colorview PopUp
function popUpScroll(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=690');");
eval("page" + id + ".moveTo(0,0);");
}
//function for pop up photoLibrary in Design Professionals
function popUpScrollLibrary(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=600,height=690');");
eval("page" + id + ".moveTo(0,0);");
}

//function for pop up photoLibrary in Design Professionals
function popUpScrollLibraryCulture(URL, culture) {
    
if(culture != "") 
    URL = getCultureURL(URL, culture);
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=600,height=690');");
eval("page" + id + ".moveTo(0,0);");
}

function getCultureURL(URL, culture){
    var tmpUrl = URL.replace("_es", "").replace("_fr", "");
    tmpUrl = tmpUrl.replace(".", "_" + culture.substring(0, 2) + ".");
    tmpUrl = tmpUrl.replace("_en", "");
    return tmpUrl;
}

//Function for pop up for additionalresources
function popUpScrollAdditionalResources(URL){
day = new Date();
id = day.getTime();


eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=600,height=690');");
eval("page" + id + ".moveTo(0,0);");
return;
}

//Function for pop up for Qualifications 
function popUpScrollQual(URL){
day = new Date();
id = day.getTime();


eval("page" + id + " = window.open(URL, '" + id + "', 'height=700,width=755,top=100,left=100,scrollbars=1,resizable=1');");
eval("page" + id + ".moveTo(0,0);");
return;
}
//FUNCTION for pop up in Pro Pages the siding Calculators
function popUpProArea(URL){
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'height=305,width=500,top=100,left=100,scrollbars=0,resizable=0');");
eval("page" + id + ".moveTo(0,0);");
}

function popUpProSoffit(URL){
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'height=230,width=500,top=100,left=100,scrollbars=0,resizable=0');");
eval("page" + id + ".moveTo(0,0);");
}

function popUpFile(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'height=630,width=500,top=100,left=100,scrollbars=0,resizable=0');");
eval("page" + id + ".moveTo(0,0);");
}

function popUpEnergySearch(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'height=930,width=710,top=100,left=100,scrollbars=1,resizable=0,menubar=no,toolbar=no');");
eval("page" + id + ".moveTo(0,0);");
$("page"+id).children("#header").hide();
//alert("page"+id);
//$("#header").hide();
}
/*End Pop Up Functions */

/*
left side Menu  toggler for Building Profesionals Architects/Builders/Contractors/Distributors/Engineers
gID = ID of Group of Links to display;
imgID = ID of Parent Image ( collapse or expand);
lID    = link ID;
*/
function menuToggler(gID,imgID,lID)
{
   // alert("IMGID: "+imgID);
    image = $("#"+imgID).attr("src");
   // alert(gID+"  OK");
  
    //alert("IMAGE:" +image);
    if(image == "img/professionals/btn_collapse.gif")
    {
        // alert("COL");
        $("#"+imgID).attr("src","img/professionals/btn_expand.gif");
        $("#"+gID).css("display","none"); 
    }
    if(image == "img/professionals/btn_expand.gif")
    {
       //alert("EXP");
        $("#"+imgID).attr("src","img/professionals/btn_collapse.gif");
        $("#"+gID).css("display","block"); 
        //showLinks(gID,lID);
        $("#"+lID).addClass("selected");
    }
   
   
}
/*SHOWS Content Associated to that link*/
function showLinks(gID,lID)
{
    //alert("SHOW LINK: "+gID+"_"+lID);
     $("#"+gID+"_"+lID).css("display","block");
     $("#"+lID).addClass("selected");
}
/*
END Functions Menu Toggler
*/

/*
    Add the class "selected" to an item in the site's main navigation.
    @param anID the ID attribute of the link to apply the class to
*/
function fSelectMainNavLink(anID) {
    var strSelector = "#" + anID;
    $(strSelector).addClass('selected');
    $(strSelector).parents('li').prev(strMainNavSeparatorSelector).css('background','#ffffff').addClass('hide');
    $(strSelector).parents('li').next(strMainNavSeparatorSelector).css('background','#ffffff').addClass('hide');
}

/*
    Use jquery to split the following HTML structure (which is generated by .NET by default from, for example, every <asp:CheckBox>
    object):
    <input type="checkbox" id="bla" text="bla" /><label for="bla">Bla</label>
    into a tabular structure that looks like this.
    <table id="bla_tbl">
    <tr>
        <td class="inputCol"><input type="checkbox" id="bla" text="bla" /></td>
        <td class="labelCol"><label for="bla">Bla</label></td>
    </tr>
    </table>
    This will prevent the text in the label from wrapping down below the checkbox or radio button.
*/
function fSplitInputAndLabelIntoColumns(anInputID) {
    var strInputSelector;
    var strLabelID;
    var strTableID;
    var strTableSelector;
    var strCheckBoxColClass = "inputCol";
    var strLabelColClass = "labelCol";
    
    strInputSelector = "#" + anInputID;
    strLabelID = anInputID + "_lbl";
    strTableID = anInputID + "_tbl";
    strTableSelector = "#" + strTableID;
//alert("anInputID = " + anInputID + "\nstrInputSelector = " + strInputSelector + "\nstrLabelID = " + strLabelID + "\nstrTableSelector = " + strTableSelector + "\n");
    //$(strInputSelector).siblings("label").wrap("<div class=\"cssLabelContainer\"></div>");
    $(strInputSelector).before("<table id=\"" + strTableID + "\"><tr><td class=\"" + strCheckBoxColClass + "\"></td><td class=\"" + strLabelColClass + "\"> </td></tr></table>");
    //$(strInputSelector).before("Testing");
    $(strInputSelector).next("label").attr("id", strLabelID);
    $(strTableSelector).children().children().children("." + strCheckBoxColClass).append(document.getElementById(anInputID));
    $(strInputSelector).parent().next("." + strLabelColClass).append(document.getElementById(strLabelID));
    $(strTableSelector).next("br").remove();
}

// ===============================================================================
// Will change the current class of a div (whose parent div = "connectRight")
// to a new class
// ===============================================================================
function ToggleConnectWithCertainteedDivClass(prevClassName, newClassName)
{           
    var myDiv = document.getElementById("connectRight");
    var divs = myDiv.getElementsByTagName('div');

    for (var i = 0; i < divs.length; i++) 
    {
        var div = divs[i];
        var divClassName = divs[i].className;
                
        if(divClassName == newClassName)
        {
            // Nothing to do - class is what we need it to be
            return;
        }
        
        if (divClassName.indexOf(prevClassName) >= 0) 
        {
            // Change the class of the div tag to the one passed
            div.className = newClassName;
                
            // The div containing the social title also contains an anchor for the text
            // that also needs to have its class changed
            if(prevClassName == 'socialTitle' || prevClassName == 'socialTitleSpanishFrench')
            {
                var myAnchors = div.getElementsByTagName('a');
                for (var j = 0; j < myAnchors.length; j++) 
                {                   
                    var anchor =  myAnchors[j];
                    var anchorClassName = myAnchors[j].className;
                                        
                    if(anchorClassName.indexOf('socialLinkSpanishFrench') >= 0) 
                    { 
                        anchor.className = 'socialLink';
                    }
                    else if(anchorClassName.indexOf('socialLink') >= 0) 
                    {
                        anchor.className = 'socialLinkSpanishFrench';
                    }
                }
            }
        }           
    }
}