function dynCSSCookie(){
  
  this.sCookieID = "dcssc";
  
  this.sDefaultFlavor = "default";
  this.reDefaultFlavor = new RegExp( this.sDefaultFlavor, "gim" );
  this.saFlavors = [];
  this.saFlavors[ this.sDefaultFlavor ] = this.sDefaultFlavor;
  this.saFlavors[ "new" ] = "new";
  
  this.getCookieRE = function(){ return new RegExp( this.sCookieID + "=[^;]+", "gim" ); }
  this.getContentRE = function( sContent ){ return new RegExp( sContent + "~[^\|]+", "gim" ); }
  this.getCookie = function( sIn ){
    var sCookie = String( document.cookie );
    var mCookie = sCookie.match( this.getCookieRE() );
    var sOut = mCookie? String( mCookie ): "";
    return sOut;
  }
  this.getContentCookie = function( sIn ){
    var sCookie = this.getCookie( sIn );
    var reItem = null;
    var mItem = null;
    var sOut = "";
    reItem = this.getContentRE( sIn )
    mItem = String( sCookie ).match( reItem );
    sOut = mItem? String( mItem ): "";
    return sOut;
  }
  this.getPersistedFlavor = function( sContent ){ 
    var sCookie = this.getContentCookie( sContent );
    return sCookie.replace( /^[^~]+~/gim, "" ); 
  }
  this.bPersistFlavor = function( sContent, sFlavor ){ 
    var sPersistedFlavor = this.getPersistedFlavor( sContent );
    return sPersistedFlavor == sFlavor || sPersistedFlavor == ""; 
  }
  this.shouldShowFlavor = function( bPopulationOK, sContent, sFlavor ){ 
    return ( bPopulationOK && this.bPersistFlavor( sContent, sFlavor ) ) ||
           ( !bPopulationOK && this.getPersistedFlavor( sContent ) == sFlavor ); 
  }
  this.updateCookie = function( sContent, sFlavor ){
    var sContentCookie = this.getContentCookie( sContent );
    var sCookie = this.getCookie( sFlavor );
    var sOutCookie = "";
    if ( !sContentCookie ){
      var dt = new Date();
      var sExpiration = "";
      dt.setDate( dt.getDate() + 90 );
      sExpiration = ( dt.getMonth() + 1 ) + "/" + dt.getDate() + "/" + dt.getFullYear();
      dt = new Date( sExpiration );
      sExpiration = dt.toGMTString();
      sOutCookie = ( sCookie == ""? this.sCookieID + "=": "" ) +
                   sCookie + ( sCookie == ""? "": "|" ) + sContent + "~" + sFlavor + 
                   ";expires=" + sExpiration + 
                   ";path=/;"; //domain=;";
      document.cookie = sOutCookie; 
    }
  }
}

//add the dynCSS('xxx'); function to the javascript in the HEADER so that it creates the CSS link without a flicker
function dynCSS(sheetOption) {
	var head = document.getElementsByTagName("head")[0];
	var oCookie = new dynCSSCookie();
	if (head) {		
		var whichSheet;
		var elementID;
		var cookieID = "";
		var elementCategory;
		var percent = Math.random();
		
		switch (sheetOption){
		case 'llc':
			var filenameOnly = filenameFromURL();
			var filenameLower = filenameOnly.toLowerCase();
			elementIDFirstPart = (filenameLower.indexOf("pricing") == -1) ?  "OVERVIEW-" : "PRICING-";
			
            if ( oCookie.shouldShowFlavor( (percent < 0.33), 'llc', "CONTROL" ) ){
				whichSheet = "/lib/atraffic.css"; //Shows only divs with class convA and hides convB and convC
				cookieID = "CONTROL";
				elementID = elementIDFirstPart + cookieID;
				elementCategory = "TEST-LZ-NOT-LAW-FIRM";
			} else if ( oCookie.shouldShowFlavor( ( percent >= 0.34 && percent < 0.66 ), 'llc', "NOT LAW FIRM" ) ){
				whichSheet = "/lib/btraffic.css";//Shows only divs with class convB and hides convA and convC 
				cookieID = "NOT LAW FIRM";
				elementID = elementIDFirstPart + cookieID;
				elementCategory = "TEST-LZ-NOT-LAW-FIRM";
			} else {
				whichSheet = "/lib/ctraffic.css";//Shows only divs with class convC and hides convA and convB
				cookieID = "NOT LAW FIRM-NO SVGS";
				elementID = elementIDFirstPart + cookieID;
				elementCategory = "TEST-LZ-NOT-LAW-FIRM";
			}		
			break;
		case 'lt':
            if ( oCookie.shouldShowFlavor( (percent > 0.5), 'lt', "default" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "default";
				elementCategory = "lt-overview";
			} else {
				whichSheet = "/lib/btraffic.css";
				elementID = "new";
				elementCategory = "lt-overview";
			}	
			break;
		case 'lwt':
            if ( oCookie.shouldShowFlavor( (percent > 0.5), 'lwt', "default" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "default";
				elementCategory = "lwt-overview";
			} else {
				whichSheet = "/lib/btraffic.css";
				elementID = "new";
				elementCategory = "lwt-overview";
			}	
			break;	
		case 'dba':
            if ( oCookie.shouldShowFlavor( (percent > 0.5), 'dba', "default" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "default";
				elementCategory = "dba-overview";
			} else {
				whichSheet = "/lib/btraffic.css";
				elementID = "new";
				elementCategory = "dba-overview";
			}	
			break;	
		case 'tm':
            if ( oCookie.shouldShowFlavor( (percent < 0.4), 'tm', "default" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "default";
				elementCategory = "tm-overview";
			} else if ( oCookie.shouldShowFlavor( ( percent >= 0.4 && percent < 0.7 ), 'tm', "diffTestimonial" ) ){
				whichSheet = "/lib/btraffic.css";
				elementID = "diffTestimonial";
				elementCategory = "tm-overview";
			} else {
				whichSheet = "/lib/ctraffic.css";
				elementID = "sameTestimonial";
				elementCategory = "tm-overview";
			}		
			break;
		case 'inc':
            if ( oCookie.shouldShowFlavor( (percent < 0.5), 'inc', "default" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "default";
				elementCategory = "incorp-overview";
			} else {
				whichSheet = "/lib/btraffic.css";
				elementID = "onecolumn";
				elementCategory = "incorp-overview";
			} 
			break;	
		case 'signin':
            if ( oCookie.shouldShowFlavor( (percent < 0.5), 'signin', "CONTROL" ) ){
				whichSheet = "/lib/atraffic.css";
				elementID = "CONTROL";
				elementCategory = "TEST-SIGNIN-NO-SECURITY-QUESTION";
			} else {
				whichSheet = "/lib/btraffic.css";
				elementID = "NO-QUESTION";
				elementCategory = "TEST-SIGNIN-NO-SECURITY-QUESTION";
			} 
			break;	
		default:	
		}
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = whichSheet;
		head.appendChild(scriptStyles);
		
		if (cookieID == "") {cookieID = elementID}; //If the cookie ID is not specified, use the default CM element ID
		
		//cmCreatePageElementTag(elementID, elementCategory);
        oCookie.updateCookie( sheetOption, cookieID );
	}
}
