// Browser code for FireFox detection
var agt=navigator.userAgent.toLowerCase();
var brwsrFireFox=(agt.indexOf("firefox")!=-1);
var brwsrIE7=(agt.indexOf("msie 7.0")!=-1);
var brwsrIE8=(agt.indexOf("msie 8.0")!=-1);
var useModal=false;

var getBrandingVal = '';
var brandingText='MyWebSearch';
var askOnly=false;
var originCd='';
var langUrl = parseURL('l');
var filesUrl = parseURL('f');
var buzzUrl = parseURL('a');
var popUrl = parseURL('p');
var tUrl = parseURL('t');
var fwbUrl = parseURL('fwb');
var wbUrl = parseURL('wb');
var newUserUrl = parseURL('nu');
var lvUrl = parseURL('lv');
var themeUrl = parseURL('theme');

var pidVal=0;

//Get pid
var cobrand = '';
var pidVal = parseURL('partner');
if (pidVal=='') pidVal = parseURL('ptnrS');
if (pidVal=='' && (typeof getPFromTB=='function')) pidVal = getPFromTB();
if (pidVal.length > 2) {
    cobrand = pidVal.substring(0, 2).toUpperCase();
}
if (pidVal.length>8) {
	pidVal=pidVal.substring(8,10);
} else {
	pidVal="";
}
var sm_DefaultToolbar="";

var bd=new Array();
bd[100]="GG";
bd[102]="AW";
bd[103]="AJ";

var MexCVal=null;
var MexCErr=0;

var sm_Toolbar = new Toolbar();
var sm_ErrorLoadingSettings = false;

var bn=new Array();
bn[100]="Myway";
bn[101]="Altavista";
bn[102]="Alltheweb";
bn[103]="Askjeeves";
bn[104]="Looksmart";
bn[105]="Files";
bn[109]="Weatherbug";
bn[110]="Images";
bn[200]="MyMyWay";
bn[201]="Email";
bn[202]="Bookmarks";
bn[301]="MessageBoards";
bn[303]="Weather";
bn[400]="News";
bn[500]="Sports";
bn[501]="MySports";
bn[502]="MLB";
bn[503]="NFL";
bn[504]="NBA";
bn[505]="NHL";
bn[506]="CollegeFootball";
bn[600]="Cartoon";
bn[601]="Celebrities";
bn[602]="DailyPoll";
bn[603]="Fashion";
bn[605]="Games";
bn[606]="Horoscopes";
bn[607]="Lottery";
bn[608]="Movies";
bn[609]="Today";
bn[610]="Notables";
bn[611]="DailyPhotos";
bn[612]="Tidbits";
bn[613]="TV";
bn[614]="IWON";
bn[615]="NewGames";
bn[700]="WhitePages";
bn[701]="YellowPages";
bn[702]="MapsDirections";
bn[800]="Money";
bn[801]="MyMoney";
bn[802]="Portfolio";
bn[803]="MoneyNews";
bn[804]="Market";
bn[805]="Research";
bn[901]="Customize";
bn[900]="Highlight";
bn[1000]="PopSwatter";
bn[1001]="MailStamp";
bn[1002]="SmileyCentral";
bn[1003]="FunProducts";	
bn[1004]="MySignature";
bn[1005]="MyInfo";
bn[1006]="MyStationery";
bn[1007]="Spin4Dough";
bn[1008]="CursorMania";
bn[1009]="PopularScreenSavers";
bn[1010]="HistorySwatter";
bn[1011]="FunBuddyIcons";
bn[1012]="MyMailNotifier";
bn[1013]="MyFunCards";
bn[1014]="Smotos";
bn[1015]="Whiptones";
bn[1016]="SmileyToday";
bn[1017]="Avatar";
bn[1018]="Webfetti";
bn[1019]="Kazulah";
bn[1020]="Green";
bn[1021]="SmileyCreator";
bn[2000]="iwGames";
bn[2001]="iwSudoku";
bn[2002]="iwPrizes";
bn[2003]="iwSpeedSolitaire";
bn[2100]="wbGenerators";
bn[2101]="wbLayouts";
bn[2102]="wbGlitter";
bn[2103]="wbGames";
bn[2104]="webEntertainment";
bn[2105]="webFindAnswers";
bn[2106]="webGames";
bn[2107]="webHowTo";
bn[2108]="webNews";
bn[2109]="webShopping";
bn[2110]="webVideo";
bn[2111]="webWeather";
bn[2200]="Frogger";
bn[2201]="DoubleDribble";
bn[2202]="TrackField";
bn[2203]="DanceRevolution";
bn[2204]="AllGames";
bn[2205]="Konami";
bn[3000]="MindSpark";
bn[4000]="GirlSense";
bn[4001]="MyGSPortfolio";
bn[4002]="GirlSenseNotes";
bn[4003]="GirlSenseMyStats";
bn[4004]="FeaturedDesigners";
bn[4005]="Spotlights";
bn[4006]="HotAuctions";
bn[4007]="FacebookChat";
bn[4101]="RecipeSearch";
bn[4102]="FoodDrink";
bn[4103]="RecipeTop10";
bn[4104]="FoodVideo";
bn[4105]="DailyDinner";
bn[4106]="Coupons";
bn[4107]="CalorieCounter";
bn[4108]="eCookbooks";
bn[4200]="MyWebFace";

if (bucket == 'ZG' || bucket == '2H') {
bn[100010417]="ButtonTest2Social";
bn[100010425]="ButtonTest2Email";
bn[100010430]="ButtonTest2Highlight";
}

var icons = new Array();
icons[0] = 'http://ak.imgfarm.com/images/speedbar/icons/Generic2.png';
icons[1] = 'http://ak.imgfarm.com/images/speedbar/finger.gif';
icons[2] = 'http://ak.imgfarm.com/images/speedbar/coffee.gif';
icons[3] = 'http://ak.imgfarm.com/images/speedbar/gift.gif';
icons[4] = 'http://ak.imgfarm.com/images/speedbar/bag.gif';
icons[5] = 'http://ak.imgfarm.com/images/speedbar/referee.gif';
icons[6] = 'http://ak.imgfarm.com/images/speedbar/camera.gif';
icons[7] = 'http://ak.imgfarm.com/images/speedbar/megaphone.gif';
icons[8] = 'http://ak.imgfarm.com/images/speedbar/money.gif'; 
icons[9] = 'http://ak.imgfarm.com/images/speedbar/storm.gif';
icons[10] = 'http://ak.imgfarm.com/images/speedbar/home.gif';
icons[11] = 'http://ak.imgfarm.com/images/speedbar/folder.gif';
icons[12] = 'http://ak.imgfarm.com/images/speedbar/hearts.gif';
icons[13] = 'http://ak.imgfarm.com/images/speedbar/envelope.gif';
icons[14] = 'http://ak.imgfarm.com/images/speedbar/computer.gif';
icons[15] = 'http://ak.imgfarm.com/images/speedbar/moviereel.gif';
icons[16] = 'http://ak.imgfarm.com/images/speedbar/music.gif';
icons[17] = 'http://ak.imgfarm.com/images/speedbar/paper.gif';
icons[18] = 'http://ak.imgfarm.com/images/speedbar/mag_glass.gif';
icons[103] = 'http://ak.imgfarm.com/images/speedbar/icons/Generic2.png';
icons[200] = 'http://ak.imgfarm.com/images/speedbar/icons/my4f.png'
icons[201] = 'http://ak.imgfarm.com/images/speedbar/icons/email4.png';
icons[301] = 'http://ak.imgfarm.com/images/speedbar/icons/forums4.png';
icons[303] = 'http://ak.imgfarm.com/images/speedbar/icons/weather4.png'
icons[400] = 'http://ak.imgfarm.com/images/speedbar/icons/news4.png';
icons[500] = 'http://ak.imgfarm.com/images/speedbar/icons/sport4.png'
icons[501] = 'http://ak.imgfarm.com/images/speedbar/icons/my4d.png';
icons[502] = 'http://ak.imgfarm.com/images/speedbar/icons/mlb4.png';
icons[503] = 'http://ak.imgfarm.com/images/speedbar/icons/nfl4.png';
icons[504] = 'http://ak.imgfarm.com/images/speedbar/icons/nbs4.png';
icons[505] = 'http://ak.imgfarm.com/images/speedbar/icons/nhl4.png';
icons[506] = 'http://ak.imgfarm.com/images/speedbar/icons/nfl4.png';
icons[600] = 'http://ak.imgfarm.com/images/speedbar/icons/cartoons4.png';
icons[601] = 'http://ak.imgfarm.com/images/speedbar/icons/celeb4.png';
icons[602] = 'http://ak.imgfarm.com/images/speedbar/icons/survey4.png';
icons[603] = 'http://ak.imgfarm.com/images/speedbar/icons/fashion4.png';
icons[605] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbgames4a.png';
icons[606] = 'http://ak.imgfarm.com/images/speedbar/icons/horoscopes4.png';
icons[607] = 'http://ak.imgfarm.com/images/speedbar/icons/lotto4.png';
icons[608] = 'http://ak.imgfarm.com/images/speedbar/icons/movies4.png';
icons[609] = 'http://ak.imgfarm.com/images/speedbar/icons/today4.png';
icons[610] = 'http://ak.imgfarm.com/images/speedbar/icons/notables4.png';
icons[611] = 'http://ak.imgfarm.com/images/speedbar/icons/photos4.png';
icons[612] = 'http://ak.imgfarm.com/images/speedbar/icons/tidbits4.png';
icons[613] = 'http://ak.imgfarm.com/images/speedbar/icons/tv4.png';
icons[700] = 'http://ak.imgfarm.com/images/speedbar/icons/whitepgs4.png';
icons[701] = 'http://ak.imgfarm.com/images/speedbar/icons/yellowpages4.png';
icons[702] = 'http://ak.imgfarm.com/images/speedbar/icons/maps4.png';
icons[801] = 'http://ak.imgfarm.com/images/speedbar/icons/my4e.png';
icons[802] = 'http://ak.imgfarm.com/images/speedbar/icons/portfolio4.png';
icons[803] = 'http://ak.imgfarm.com/images/speedbar/icons/news4.png';
icons[804] = 'http://ak.imgfarm.com/images/speedbar/icons/markets4.png';
icons[805] = 'http://ak.imgfarm.com/images/speedbar/icons/research4.png';
icons[900] =  'http://ak.imgfarm.com/images/speedbar/icons/highlight4b.png'
icons[901] = 'http://ak.imgfarm.com/images/speedbar/icons/customize4a.png';
icons[900] = 'http://ak.imgfarm.com/images/speedbar/icons/highlight4b.png';
icons[1000] = 'http://ak.imgfarm.com/images/speedbar/icons/popswatter.png';
icons[1002] = 'http://ak.imgfarm.com/images/speedbar/icons/13433AE5.png';//smiley central
icons[1004] = 'http://ak.imgfarm.com/images/speedbar/icons/signature4.png';
icons[1003] = 'http://ak.imgfarm.com/images/speedbar/icons/funtools4.png';
icons[1008] = 'http://ak.imgfarm.com/images/speedbar/icons/13433BD0.png';	//cursor mania
icons[1010] = 'http://ak.imgfarm.com/images/speedbar/icons/histswat4.png';
icons[1013] = 'http://ak.imgfarm.com/images/speedbar/icons/MFC_.png'; //MFC
icons[1017] = 'http://ak.imgfarm.com/images/speedbar/icons/avatar4.png'; //Zwinky
icons[1009] = 'http://ak.imgfarm.com/images/speedbar/icons/13433B62.png'; //popular screensavers	
icons[1018] = 'http://ak.imgfarm.com/images/speedbar/icons/wfHeart.png';//webfetti
icons[1019] = 'http://ak.imgfarm.com/images/speedbar/icons/Kazulahfavicon_.png'	//Kazulah
icons[1020] = 'http://ak.imgfarm.com/images/speedbar/icons/13432654.png' //green
icons[1021] = 'http://ak.imgfarm.com/images/speedbar/icons/ezIcon.gif' //smileycreator
icons[2000] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbgames2a.png';
icons[2002] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbprizes2a.png';
icons[2003] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbsolitare.png';
icons[2104] = 'http://ak.imgfarm.com/images/speedbar/icons/entertainment3.png'; 
icons[2105] = 'http://ak.imgfarm.com/images/speedbar/icons/answers3.png'; 
icons[2106] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbgames4a.png';
icons[2107] = 'http://ak.imgfarm.com/images/speedbar/icons/howto3.png';
icons[2108] = 'http://ak.imgfarm.com/images/speedbar/icons/news3.png';
icons[2109] = 'http://ak.imgfarm.com/images/speedbar/icons/shopping3.png';
icons[2110] = 'http://ak.imgfarm.com/images/speedbar/icons/video3.png';
icons[2111] = 'http://ak.imgfarm.com/images/speedbar/icons/weather3.png'; 
icons[2200] = 'http://ak.imgfarm.com/images/download/retrogamer/icon_frogger.png';
icons[2201] = 'http://ak.imgfarm.com/images/download/retrogamer/icon_dd.png';
icons[2202] = 'http://ak.imgfarm.com/images/download/retrogamer/icon_track.png';
icons[2203] = 'http://ak.imgfarm.com/images/download/retrogamer/icon_ddr.png';
icons[2204] = 'http://ak.imgfarm.com/images/download/retrogamer/icon_iwon.png';
icons[2205] = 'http://ak.imgfarm.com/images/speedbar/icons/Generic2.png';
icons[2001] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbsudoku2a.png';
icons[3000] = 'http://ak.imgfarm.com/images/speedbar/icons/fwbmindspark2a.png';

var bReceivedShortFormat = false;
if (document.layers)
	navigator.plugins.refresh(false);
	
function SettingsControl_OnShortFormat(theVal) {
	if (! bReceivedShortFormat) {
		bReceivedShortFormat = true;
		MexCVal = theVal;
		createToolbar();
	}
}

function NetscapeReady() {
	if (document.layers)
		document.embeds["SettingsControl"].ExecPlugin("RequestShortFormat","");
}

function InitCreateToolbar() {
	try {
		if (document.getElementById) {
			MexCVal = document.getElementById('SettingsControl').ShortFormat;
		} else if (document.all) {
			MexCVal = document.all.SettingsControl.ShortFormat;
		}
	} catch(ee){
	}		
	createToolbar();
}

function getVerForX() {
	if (document.all && (typeof document.all.SettingsControl.getVersion("mwsbar.dll")) != 'undefined') {
		var userVersion = document.all.SettingsControl.getVersion("mwsbar.dll");
		var aUserVersion = userVersion.split('.');
		var validVersion = '2.0.2.3';
		var aValidVersion = validVersion.split('.');
		var exceptVersion = '2.0.3.0';
		var aExceptVersion = exceptVersion.split('.');
		for (var n=0;n<aValidVersion.length;n++) {
		if (aUserVersion[n].length == 1) aUserVersion[n] = "0" + aUserVersion[n];			
		if (aValidVersion[n].length == 1) aValidVersion[n] = "0" + aValidVersion[n];	
		if (aExceptVersion[n].length == 1) aExceptVersion[n] = "0" + aExceptVersion[n];
		}									
		userVersion = aUserVersion.join("");
		userVersion = userVersion - 0;
		validVersion = aValidVersion.join("");
		validVersion = validVersion - 0;
		exceptVersion = aExceptVersion.join("");
		exceptVersion = exceptVersion - 0;
		if (userVersion > validVersion && userVersion!=exceptVersion) {
			useModal = true;
		} else {
			useModal = false;
		}			
	} else if (brwsrFireFox) {
		useModal=true;
	}
}

function UserLink() {
	this.GetURL=mGetURL;
	this.SetURL=mSetURL;
	this.GetTitle=mGetTitle;
	this.SetTitle=mSetTitle;
	this.m_url="";
	this.m_title="";
}

function UserButton() {
	this.StreamIn=mUBStrmIn;
	this.StreamOut=mUBStrmOut;
	this.GetURL=mGetURL;
	this.SetURL=mSetURL;
	this.GetTitle=mGetTitle;
	this.SetTitle=mSetTitle;
	this.GetIcon=mUBGetIcon;
	this.SetIcon=mUBSetIcon;
	this.GetLinkCount=mUBGetLinkCount;
	this.GetLink=mUBGetLink;
	this.ClearLinks=mUBClearLinks;
	this.AppendLink=mUBAppendLink;
	this.RemoveLink=mUBRemoveLink;
	this.SwitchLinks=mUBSwitchLinks;
	this.m_url="";
	this.m_title="";
	this.m_icon=0;
	this.m_links=new Array();
	this.m_type="u";
}

function WidgetButton() {
	this.StreamIn=mWBStrmIn;
	this.StreamOut=mWBStrmOut;
	this.GetURL=mGetURL;
	this.SetURL=mSetURL;
	this.GetTitle=mGetTitle;
	this.SetTitle=mSetTitle;
	this.GetIcon=mWBGetIcon;
	this.SetIcon=mWBSetIcon;
	this.GetStyle=mWBGetStyle;
	this.SetStyle=mWBSetStyle;
	this.GetWidth=mWBGetWidth;
	this.SetWidth=mWBSetWidth;
	this.GetHeight=mWBGetHeight;
	this.SetHeight=mWBSetHeight;
	this.m_url="";
	this.m_title="";
	this.m_icon=0;
	this.m_style=0;
	this.m_width=0;
	this.m_height=0;
	this.m_type="w";
}

function Toolbar() {
	this.StreamIn=mTbStrmIn;
	this.StreamOut=mTbStrmOut;
	this.GetFlags=mTbGetFlags;
	this.SetFlags=mTbSetFlags;
	this.GetDefaultProvider=mTbGetDefProvider;
	this.SetDefaultProvider=mTbSetDefProvider;
	this.ClearButtons=mTbClearBttns;
	this.AddButton=mTbAddBttn;
	this.AddOrRemoveButton=mTbAddOrRemoveBttn;
	this.SwitchButtons=mTbSwitchBttns;
	this.SetButtons=mTbSetBttns;
	if(document.layers){
		this.HasButton=mTbHasBttnNs;
		this.RemoveButton=mTbRemoveBttnNs;
	}else{
		this.RemoveButton=mTbRemoveBttn;
		this.HasButton=mTbHasBttn;
	}
	this.GetButtonCount=mTbGetBttnCount;
	this.GetButton=mTbGetBttn;
	this.GetButtons=mTbGetBttns;
	this.SetUserButton=mTbSetUserBttn;
	this.GetUserButton=mTbGetUserBttn;
	this.m_bttns="";
	this.m_userBttns=new Array();
	this.m_flags=0;
	this.m_defProvider="";
	this.m_widgetOffset=50;
	this.SetWidgetButton=mTbSetWidgetBttn;
	this.GetWidgetButton=mTbGetWidgetBttn;
	this.FindWidgetButtonData=mTbFindWidgetBttnData;
	this.FindWidgetButtonID=mTbFindWidgetBttnID;
	this.m_widgetBttns=new Array();
}

function smTrim(str){return str.replace(/^\s*/,"").replace(/\s*$/,"");}
function smRemove(ar,ii){
	if(0<=ii&&ii<ar.length) {
		if (0==ii)
			ar=ar.slice(1);
		else if(ar.length-1==ii)
			ar=ar.slice(0,-1);
		else{
			var ll=new Array();
			ar=ll.concat(ar.slice(0,ii),ar.slice(ii+1));
		}
	}
	return ar;
}
function smSwitch(ar,aa,bb){
	if(aa!=bb&&0<=aa&&aa<ar.length&&0<=bb&&bb<ar.length){
		var tt=ar[aa];ar[aa]=ar[bb];ar[bb]=tt;
	}
}

function mGetURL(){return this.m_url.replace(/ /g,"|");}
function mSetURL(str){
	var url=str.toString().replace(/\s|\"|#/g,"").replace(/\|/g," ");
	if(0<url.length&&0!=url.indexOf("http://")&&0!=url.indexOf("https://")&&0!=url.indexOf("ftp://")&&0!=url.indexOf("javascript:"))
		this.m_url="http://"+url;
	else
		this.m_url=url;
}
function mGetTitle(){return this.m_title;}
function mSetTitle(str){this.m_title=smTrim(str.toString().replace(/\||\"|#/g,""));}

function mUBGetIcon(){return this.m_icon;}
function mUBSetIcon(ii){this.m_icon=smTrim(ii.toString());}
function mUBGetLinkCount(){return this.m_links.length;}
function mUBGetLink(ii){return (0 <= ii && ii < this.m_links.length)?this.m_links[ii]:null;}
function mUBClearLinks(){this.m_links=new Array();}
function mUBAppendLink(ll){this.m_links[this.m_links.length]=ll;}
function mUBRemoveLink(ii){this.m_links=smRemove(this.m_links,ii);}
function mUBSwitchLinks(aa,bb){smSwitch(this.m_links,aa,bb);}
function mUBStrmIn(attribs,links,flag){
	var aa='';
	if (2==flag) {
	  var bb=attribs.split(',');
	  this.m_type=bb[0];
	  aa=bb[1].split('|');	  
	} else {
	  aa=attribs.split('|');
	}
	var ll=links.split('|');
	if(3==aa.length&&(1==ll.length||(0==(ll.length%2)&&ll.length<91))){
		this.m_url=aa[0];
		this.m_title=aa[1];
		this.m_icon=smTrim(aa[2]);
		var al;
		if(1 < ll.length)
			for(var ii=0;ii<ll.length;ii+=2){
				al=new UserLink;
				al.m_url=ll[ii];
				al.m_title=ll[ii+1];
				this.AppendLink(al);
			}
		return true;
	}
	return false;
}
function mUBStrmOut(sep,flag){
	var res='';
	if (2==flag) res=this.m_type+',';
	res+=this.m_url+'|'+this.m_title+'|'+this.m_icon+sep;
	var ll;
	for(var ii=0;ii<this.m_links.length&&ii<45;ii++) {
		if (0<ii)
			res+='|';
		ll=this.m_links[ii];
		res+=ll.m_url+'|'+ll.m_title;
	}
	return res;
}

function mWBGetIcon(){return this.m_icon;}
function mWBSetIcon(ii){this.m_icon=smTrim(ii.toString());}
function mWBGetStyle(){return this.m_style;}
function mWBSetStyle(ii){this.m_style=smTrim(ii.toString());}
function mWBGetWidth(){return this.m_width;}
function mWBSetWidth(ii){this.m_width=ii;}
function mWBGetHeight(){return this.m_height;}
function mWBSetHeight(ii){this.m_height=ii;}
function mWBStrmIn(attribs,links,flag){
	var aa='';
	if (2==flag) {
	  var bb=attribs.split(',');
	  this.m_type=bb[0];
	  aa=bb[1].split('|');	  
	} else {
	  aa=attribs.split('|');
	}
	var ll=links.split('|');
	if(6==aa.length&&(1==ll.length||(0==(ll.length%2)&&ll.length<91))){
		this.m_url=aa[0];
		this.m_title=aa[1];
		this.m_icon=smTrim(aa[2]);
		this.m_style=aa[3];
		this.m_width=aa[4];
		this.m_height=aa[5];
		return true;
	}
	return false;
}
function mWBStrmOut(sep,flag){
	var res=this.m_type+','+this.m_url+'|'+this.m_title+'|'+this.m_icon+'|'+this.m_style+'|'+this.m_width+'|'+this.m_height+sep;
	return res;
}

function mTbGetFlags(){return this.m_flags;}
function mTbSetFlags(ff){this.m_flags=ff;}
function mTbGetDefProvider(){return this.m_defProvider;}
function mTbSetDefProvider(bb){this.m_defProvider=bb.toString();}
function mTbClearBttns(){this.m_bttns="";}
function mTbAddBttn(bb){
	if(0<this.m_bttns.length) {
		if(this.HasButton(bb))
			return;
		this.m_bttns+="|";
	}
	this.m_bttns+=bb.toString().replace(/\s/g,"");
}
function mTbRemoveBttn(bb){
	this.m_bttns=this.m_bttns.replace(new RegExp("\\|"+bb+"\\|"),"|");
	this.m_bttns=this.m_bttns.replace(new RegExp("(^|\\|)"+bb+"(\\||$)"),"");
}
function mTbRemoveBttnNs(bb){
	var str="|"+bb+"|";
	var bttns="|"+this.m_bttns+"|";
	var ii=bttns.indexOf(str);
	if(0<=ii){
		bttns=bttns.substr(0,ii+1)+bttns.substr(ii+str.length);
		this.m_bttns=bttns.slice(1,-1);
	}
}
function mTbAddOrRemoveBttn(bAdd, bb){if(bAdd)this.AddButton(bb);else this.RemoveButton(bb);}
function mTbSwitchBttns(aa,bb){var ar=this.GetButtons();smSwitch(ar,aa,bb);this.SetButtons(ar);}
function mTbSetBttns(bbs){this.m_bttns=bbs.join("|").replace(/\s/g,"");}
function mTbHasBttn(bb){return 0<=this.m_bttns.search(new RegExp("(^|\\|)"+bb+"(\\||$)"));}
function mTbHasBttnNs(bb){return 0<=("|"+this.m_bttns+"|").indexOf("|"+bb+"|");}
function mTbGetBttnCount(){return this.GetButtons().length;}
function mTbGetBttn(ii){return (this.GetButtons())[ii];}
function mTbGetBttns(){return (0<this.m_bttns.length)?this.m_bttns.split("|"):new Array();}
function mTbGetUserBttn(ii){return (0<=ii&&ii<this.m_userBttns.length)?this.m_userBttns[ii]:null;}
function mTbSetUserBttn(ii,bb){if(0<=ii)this.m_userBttns[ii]=bb;}
function mTbGetWidgetBttn(ii){return (0<=ii&&ii<this.m_widgetBttns.length)?this.m_widgetBttns[ii]:null;}
function mTbSetWidgetBttn(ii,bb){if(0<=ii)this.m_widgetBttns[ii]=bb;}
function mTbFindWidgetBttnData(str){
	var url=str.toString().replace(/\s|\"|#/g,"").replace(/\|/g," ");
	for(var jj=0;jj<this.m_widgetBttns.length&&jj<50;jj++) {
		bb=this.m_widgetBttns[jj];
		if(url==bb.m_url)
			return bb;
	}
	return null;	
}
function mTbFindWidgetBttnID(str){
	var url=str.toString().replace(/\s|\"|#/g,"").replace(/\|/g," ");
	for(var jj=0;jj<this.m_widgetBttns.length&&jj<50;jj++) {
		bb=this.m_widgetBttns[jj];
		if(url==bb.m_url)
			return jj;
	}
	return null;	
}
function mTbStrmIn(strm){
	var vv=strm.split("|| ");
	if(1==(vv.length%2)){
		var bb;
		var delim=vv[0].indexOf('|');
		if(0>delim){
			this.m_flags=vv[0];
			this.m_bttns="";
		}else{
			this.m_flags=vv[0].substr(0,delim);
			if(delim+1>=vv[0].length)
				this.m_bttns="";
			else
				this.m_bttns=vv[0].substr(delim+1);
		}
		delim=this.m_flags.indexOf(',');
		if(0>delim||delim+1>=this.m_flags.length){
			this.m_defProvider="";
		}else{
			this.m_defProvider=this.m_flags.substr(delim+1);
			this.m_flags=this.m_flags.substr(0,delim);
		}
		if (2>this.m_flags && vv.length>12) {return false;}
		var ubs = new Array();
		var wbs = new Array();
		for(var ii=1;ii<vv.length;ii+=2) {		
			var getBtnTypeArr='';
			var getBtnType='';
			if (2==this.m_flags) {
				getBtnTypeArr=vv[ii].split(',');;
				getBtnType=getBtnTypeArr[0];
			}
			if (getBtnType=='w') {
				bb = new WidgetButton();
				if(!bb.StreamIn(vv[ii],vv[ii+1],this.m_flags))
					return false;
				wbs[wbs.length]=bb;
			} else {
				bb = new UserButton();
				if(!bb.StreamIn(vv[ii],vv[ii+1],this.m_flags))
					return false;
				ubs[ubs.length]=bb;
			}

		}
		this.m_userBttns=ubs;
		this.m_widgetBttns=wbs;
		if(this.StreamOut()!=strm) {
			alert("Logic bug:"+this.StreamOut());
			alert(this.m_defProvider);
		}
		return true;
	}
	return false;
}
function mTbStrmOut(){
	var res=this.m_flags;
	if(0<this.m_defProvider.length)
		res+=","+this.m_defProvider;
	res+="|"+this.m_bttns;
	var bb;
	for(var ii=0;ii<this.m_userBttns.length&&ii<5;ii++) {
		res += "|| ";
		bb=this.m_userBttns[ii];
		if(null==bb)
			bb=this.m_userBttns[ii]=new UserButton();
		res += bb.StreamOut("|| ",this.m_flags);
	}
	for(var jj=0;jj<this.m_widgetBttns.length&&jj<50;jj++) {
		res += "|| ";
		bb=this.m_widgetBttns[jj];
		if(null==bb)
			bb=this.m_widgetBttns[jj]=new WidgetButton();
		res += bb.StreamOut("|| ",this.m_flags);
	}
	return res;
}

var sm_DefaultToolbar="";
function setDefToolbar() {
	var intlDef='100';

	//Set default search
	if (bucket == 'XV' || bucket == 'XX' || bucket == 'YH' || bucket == 'YI') {
		if (langUrl=='9' || (typeof(navigator.userLanguage) != 'undefined' && navigator.userLanguage.substring(0,2).toLowerCase() == "en")) {
			intlDef='103';
		} else {
			intlDef='100';
		}
	}
	
    if (cobrand == 'GS' || webToolsUrl == 'gs') {
        sm_DefaultToolbar = "1,103|4001|4002|4003|4004|4005|4006|4007|1002";
    } else if (cobrand == 'LF' || webToolsUrl == 'lf') {
        sm_DefaultToolbar = "1,103|4101|4102|4103|4104|4105|4106|4107|4108";
    } else if (cobrand == 'GR' || webToolsUrl == 'gr') {
        sm_DefaultToolbar = "1,103|4200|1018|1017|2000|4000|1002";
    } else if (filesUrl == '1') {
		sm_DefaultToolbar = "2|100|102|103|104|105|901|0|900";
	} else if (popUrl == '1') {
		sm_DefaultToolbar = "2|100|102|103|104|1000|901|0|900";
	} else if (wbUrl == '2') {	
		sm_DefaultToolbar = "0|103|900|109";
	} else if (webToolsUrl == 'p') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1002|1008|1009|1013";
	} else if (webToolsUrl == 'm') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1001|1002|1013";
	} else if (webToolsUrl == 's') {
		sm_DefaultToolbar = "2|"+intlDef+"|1002|1009|1008|1000|1013";
	} else if (webToolsUrl == 'g') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1004|1002|1008|1009|1013";
	} else if (webToolsUrl == 'i') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1003|1005";
	} else if (webToolsUrl == 't') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1006|1002|1008|1009|1013";
	} else if (webToolsUrl == 'c') {
		sm_DefaultToolbar = "2|"+intlDef+"|1008|1002|1009|1013";
	} else if (webToolsUrl == '0') {
		sm_DefaultToolbar = "2|"+intlDef+"|1002|1009|1008|1013";
	} else if (webToolsUrl == 'r') {
		sm_DefaultToolbar = "2|"+intlDef+"|1009|1002|1008|1013";
	} else if (webToolsUrl == 'h') {
		sm_DefaultToolbar = "2|"+intlDef+"|1010|1002|1009|1008|1013";
	} else if (webToolsUrl == 'b') {
		sm_DefaultToolbar = "2|"+intlDef+"|1002|1009|1008|1011|1013";
	} else if (webToolsUrl == 'w') {
		sm_DefaultToolbar = "2|"+intlDef+"|1000|1003";
	} else if (webToolsUrl == 'f') {
		sm_DefaultToolbar = "2|"+intlDef+"|1012|1002|1009|1008|1013";
	} else if (webToolsUrl == 'u') {
		sm_DefaultToolbar = "2|"+intlDef+"|1013|1002|1009|1008";
	} else if (webToolsUrl == 'a') {
		sm_DefaultToolbar = "2|"+intlDef+"|1014|1002|1009|1008|1013";
	} else if (webToolsUrl == 'e') {
		sm_DefaultToolbar = "2|"+intlDef+"|1015|1002|1009|1008|1013";
	} else if (webToolsUrl == 'j') {
		sm_DefaultToolbar = "2|"+intlDef+"|1017|1002|1009|1008|1013";
		if (bucket == 'ZG' || bucket == '2H') { 
			sm_DefaultToolbar = "2,100|"+intlDef+"|1017|100010417|0|100010425|100010430";
		}
	} else if (webToolsUrl == 'k') {
		sm_DefaultToolbar = "2|"+intlDef+"|1018|1002|1009|1008|1013";
		if (bucket == 'VY') {
			sm_DefaultToolbar = "2|"+intlDef+"|1018|1002|1008|1013|2106";
		} else if (bucket == 'VZ') {
			sm_DefaultToolbar = "2|"+intlDef+"|1018|2111|2104|2110|2108|2109|2105|2107";
		} else if (bucket == 'WA') {
			sm_DefaultToolbar = "2|"+intlDef+"|1018|1002|1008|1013|2106|2111|2108|2105|2104|2110|2109";
		} else if (bucket == 'WC') {
			sm_DefaultToolbar = "2|"+intlDef+"|1018|1002|1008|1013|2106";				
		} else if (bucket == 'WD') { 
			sm_DefaultToolbar = "2|"+intlDef+"|1018|1002|1008|1013|2106";	
		} else if (bucket == 'ZG' || bucket == '2H') { 
			sm_DefaultToolbar = "2,100|"+intlDef+"|1018|100010417|0|100010425|100010430";
		}
	} else if (webToolsUrl == 'l') {
		sm_DefaultToolbar = "2|"+intlDef+"|2000|2001|2002|1002|1013";
	} else if (webToolsUrl == 'v') {
		sm_DefaultToolbar = "2|"+intlDef+"|2000|2001|2003|1002|1013";
	} else if (webToolsUrl == 'q') {
		sm_DefaultToolbar = "2|"+intlDef+"|1019|1018|1002|1009";
	} else if (webToolsUrl == 'y') {
		sm_DefaultToolbar = "2|"+intlDef+"|1020|1002|1009|1008|1013";
	} else if (webToolsUrl == 'rg') {
		if (themeUrl == 'dd' || themeUrl == 'epdd') {
		sm_DefaultToolbar = "2|"+intlDef+"|2201|2200|2202|2203|2204|1002|2205";	
		} else if (themeUrl == 'ddr' || themeUrl == 'epddr') {
		sm_DefaultToolbar = "2|"+intlDef+"|2203|2200|2201|2202|2204|1002|2205";	
		} else if (themeUrl == 'track' || themeUrl == 'eptrack') {
		sm_DefaultToolbar = "2|"+intlDef+"|2202|2200|2201|2203|2204|1002|2205";	
		} else {
		sm_DefaultToolbar = "2|"+intlDef+"|2200|2201|2202|2203|2204|1002|2205";		
		}
	} else if (webToolsUrl == 'ez') {
		sm_DefaultToolbar = "2|"+intlDef+"|1021|1002|1013|1008";
	} else {
		sm_DefaultToolbar = "2|"+intlDef+"|1002|1009|1008|1000|1013";
	}
}
setDefToolbar();

function GenerateConfiguration(toolbar) {
	var todayName="Today";
	
	var defBtn=toolbar.GetDefaultProvider();
	var bbs=toolbar.GetButtons();
	
	if(0==bbs.length&&null==bn[defBtn])
		return "\n";
	
	if (null==bn[defBtn]) {
		defBtn = 100;
		if (bucket == 'XV' || bucket == 'XX' || bucket == 'YH' || bucket == 'YI') {
			if (langUrl=='9' || (typeof(navigator.userLanguage) != 'undefined' && navigator.userLanguage.substring(0,2).toLowerCase() == "en")) defBtn=103;
		}
	}
	var buttonList;
	var buttonListBB='';
	var buttonCountAB=0;
	var buttonListAB='';
	var buttonCountBB=0;
	if(null!=bn[defBtn]){
		buttonList="d0="+bn[defBtn]+"DefEdt\nd1="+bn[defBtn]+"DefBtn\n";
		buttonListAB="d0="+bn[defBtn]+"DefEdt\nd1="+bn[defBtn]+"DefBtn\n";
		buttonCountAB=2;
	}else{
		buttonList="s0=3\nu0=#20#\ns1=0x4000\nt1=Search\nu1=#20#\n";
	}
	var buttonCount=2;
	if(0<bbs.length){
		var buttonDetails="";
		for(var ii=0;ii<bbs.length;ii++){
			if(0<=bbs[ii]&&5>bbs[ii]){
				var btnNum=parseInt(bbs[ii])+1;
				buttonList+="d"+buttonCount+"=userButton"+bbs[ii]+"Btn\n";
				buttonCount++;
				buttonListBB+="d"+buttonCountBB+"=userButton"+bbs[ii]+"Btn\n";
				buttonCountBB++;
				buttonDetails+="[userButton"+bbs[ii]+"Btn]\nc0=userButton"+bbs[ii]+"\n";
				var linkDetails="";
				var linkCount=0;
				var uBtn=toolbar.GetUserButton(bbs[ii]);
				if(null==uBtn){
					buttonDetails+="b0=#19#ubutton1.bin\ns0=0x1800\nt0=My Button "+btnNum+"\n";
				}else{
					if(0==uBtn.GetTitle().length&&(0>=uBtn.GetIcon()||18<uBtn.GetIcon())){
						buttonDetails+="t0=My Button "+btnNum+"\n";
					}else{
						if(0<uBtn.GetTitle().length)
							buttonDetails+="t0="+uBtn.GetTitle()+"\n";
						if (bucket == 'ZG' || bucket == '2H') {
							buttonDetails+="b0=#19#"+uBtn.GetIcon()+".bin\ns0=0x1000\n";
						} else {
						if(0<uBtn.GetIcon()&&18>=uBtn.GetIcon())
							buttonDetails+="b0=#19#ubutton"+uBtn.GetIcon()+".bin\ns0=0x1800\n";
						}
						if(0<uBtn.GetURL().length)
							buttonDetails+="u0="+uBtn.GetURL()+"\n";
					}
					if(0<uBtn.GetLinkCount()){
						for(var jj=0;jj<uBtn.GetLinkCount();jj++){
							var uLink=uBtn.GetLink(jj);
							if(null!=uLink){
								if(0<uLink.GetTitle().length){
									linkDetails+="t"+linkCount+"="+uLink.GetTitle()+"\n";
									if(0<uLink.GetURL().length)
										linkDetails+="u"+linkCount+"="+uLink.GetURL()+"\n";
									linkCount++;
								}
							}
						}
						if(0<linkCount){
							linkDetails+="s"+linkCount+"=4\n";
							linkCount++;
						}
					}
				}

				var apUrl = '';
				if (popUrl == '1') {
					if (filesUrl == '1' && buzzUrl == '1') {
						apUrl = '&f=1&a=1&p=1';
					} else if (filesUrl == '1') {
						apUrl = '&f=1&p=1';
					} else if (buzzUrl == '1') {
						apUrl = '&a=1&p=1';
					} else {
						apUrl = '&p=1';
					}
				} else {
					if (filesUrl == '1' && buzzUrl == '1') {
						apUrl = '&f=1&a=1';
					} else if (filesUrl == '1') {
						apUrl = '&f=1';
					} else if (buzzUrl == '1') {
						apUrl = '&a=1';
					}	
				}
				if (webToolsUrl != '') {
					apUrl += '&w='+webToolsUrl;
				}			
				var tmpPtnrSUrl=parseURL('ptnrS')
				if (tmpPtnrSUrl != '') {
					apUrl += '&ptnrS='+tmpPtnrSUrl;
				}
				if (askOnly) {
					apUrl += '&or='+sOriginCd+'&lv='+lvUrl;
				}
				var tmpBRUrl=parseURL('br');
				if (tmpBRUrl != '') {
					apUrl += '&br='+tmpBRUrl;
				}
				
				linkDetails+="t"+linkCount+"="+sAddThisSite+"\n";
				//	linkDetails+="u"+linkCount+"=javascript:window.open('#17#?u='+escape(document.location.href)+'&t='+escape(document.title)+'&b="+bbs[ii]+"','MySearch_AddLink','screenX=0,screenY=0,left=0,top=0,scrollbars,resizable,width=320,height=250').focus()\n";
				getVerForX();
				if (useModal) {
					linkDetails+="s"+linkCount+"=0x1a\n";
					if (bucket == 'ZG' || bucket == '2H') {
						linkDetails+="u"+linkCount+"=#17#?t=#1#&ptnrS=#3#&u=#8#&ti=#9#&b="+bbs[ii]+"\n";
					} else {
						linkDetails+="u"+linkCount+"=#17#?u=#8#&t=#9#&b="+bbs[ii]+apUrl+"\n";
					}
					linkDetails+="p"+linkCount+"=scrollbars=1,resizable=1,help=0,dialogwidth=320px,dialogheight=250px\n";
				} else {	
					if (bucket == 'ZG' || bucket == '2H') {
						linkDetails+="u"+linkCount+"=javascript:window.open('#17#?t=#1#&ptnrS=#3#&u='+escape(document.location.href)+'&ti='+escape(document.title)+'&b="+bbs[ii]+"','mysal','scrollbars,resizable,width=320,height=250').focus()\n";
					} else {
						linkDetails+="u"+linkCount+"=javascript:window.open('#17#?u='+escape(document.location.href)+'&t='+escape(document.title)+'&b="+bbs[ii]+apUrl+"','mysal','scrollbars,resizable,width=320,height=250').focus()\n";
					}					
				}
				linkCount++;
				linkDetails+="t"+linkCount+"="+sEditThisSite+"\n";
				if (bucket == 'ZG' || bucket == '2H') {
					linkDetails+="u"+linkCount+"=#21#?t=#1#&ptnrS=#3#&btn="+bbs[ii]+"\n";
				} else {
					linkDetails+="u"+linkCount+"=#21#?btn="+bbs[ii]+apUrl+"\n";
				}
				buttonDetails+="\n[userButton"+bbs[ii]+"]\nn="+(linkCount+1)+"\n"+linkDetails+"\n";
			}else if(50<=bbs[ii]&&100>bbs[ii]){
				var widgetNum=parseInt(bbs[ii]);
				var widgetNumWithOffset=bbs[ii]-toolbar.m_widgetOffset;				
				buttonList+="d"+buttonCount+"=widgetButton"+bbs[ii]+"Btn\n";
				buttonCount++;
				buttonListBB+="d"+buttonCountBB+"=widgetButton"+bbs[ii]+"Btn\n";
				buttonCountBB++;
				buttonDetails+="[widgetButton"+bbs[ii]+"Btn]\n";
				var linkDetails="";
				var linkCount=0;
				var wBtn=toolbar.GetWidgetButton(widgetNumWithOffset);
				if(null==wBtn){
					buttonDetails+="s0=0x189a\nt0=Widget "+widgetNum+"\n";
				}else{
					if(0<wBtn.GetTitle().length)
						buttonDetails+="t0="+wBtn.GetTitle()+"\n";
					if(0<wBtn.GetIcon().length)
						buttonDetails+="b0="+wBtn.GetIcon()+".bin\n";
					if(0<wBtn.GetStyle().length)
						buttonDetails+="s0="+wBtn.GetStyle()+"\n";
					if(0<wBtn.GetURL().length)
						buttonDetails+="u0="+wBtn.GetURL()+"\n";
					if(0<wBtn.GetWidth().length && 0<wBtn.GetHeight().length)
						buttonDetails+="p0=scrollbars=1,resizable=1,dialogwidth="+wBtn.GetWidth()+"px,dialogheight="+wBtn.GetHeight()+"px\n";
					buttonDetails+="\n";
				}
			}else if(defBtn!=bbs[ii]&&null!=bn[bbs[ii]]){
				buttonList+="d"+buttonCount+"="+bn[bbs[ii]]+"Btn\n";
				buttonCount++;
				if ((bbs[ii]<100||bbs[ii]>104)&&bbs[ii]!=110) {
					buttonListBB+="d"+buttonCountBB+"="+bn[bbs[ii]]+"Btn\n";
					buttonCountBB++;
				}
			}
		}
		if (wbUrl == '2') {
			buttonCount+=3;
			buttonList+="d4=ConditionsBtn\ns5=4\nd6=ForecastBtn\n";
		}
		buttonList=buttonList+"\n"+buttonDetails;
	}

    var baseConfig = "\n[customButtons]\nn=" + buttonCount + "\nt=1\n" + buttonList;
    if (cobrand == 'GS' || cobrand == 'LF') {
        return baseConfig;
    }
    
	return baseConfig+"\n[customABButtons]\nn="+buttonCountAB+"\nt=1\n"+buttonListAB+"\n[customBBButtons]\nn="+buttonCountBB+"\nt=1\n"+buttonListBB+"\n[customeditorbuttons]\nn=3\nt=1\nd0=MailStamp2Btn\nd1=MySignature2Btn\nd2=MyStationery2Btn\n\n[customsmalleditorbuttons]\nn=3\nt=1\nd0=MailStampSmallBtn\nd1=MySignatureSmallBtn\nd2=MyStationerySmallBtn\n";
}

function saveSettings() {
	var newSettings = sm_Toolbar.StreamOut();
	if (! sm_ErrorLoadingSettings && newSettings != MexCVal && (0 < MexCVal.length || newSettings != sm_DefaultToolbar)) {
		if (document.layers){
			document.embeds["SettingsControl"].ExecPlugin("ShortFormat","\"" + newSettings + "\"");
			document.embeds["SettingsControl"].ExecPlugin("ConfigFormat","\""+ GenerateConfiguration(sm_Toolbar) + "\"");
		} else {
			if (document.getElementById) {
				document.getElementById('SettingsControl').ShortFormat=newSettings;
				document.getElementById('SettingsControl').ConfigFormat=GenerateConfiguration(sm_Toolbar);
			} else if (document.all) {
				document.all.SettingsControl.ShortFormat=newSettings;
				document.all.SettingsControl.ConfigFormat=GenerateConfiguration(sm_Toolbar);
			}
		}
	}
}

function finished() {
	var gotoHomeURL=sSearchHomeUrl;
	if (askOnly) {
		if ((typeof(navigator.userLanguage) != 'undefined'&& navigator.userLanguage.length>=5 && navigator.userLanguage.substring(3,5).toLowerCase() == "gb")) {
			gotoHomeURL='http://uk.ask.com?o='+sOriginCd+'&l='+lvUrl;
		} else {
			gotoHomeURL='http://www.ask.com?o='+sOriginCd+'&l='+lvUrl;
		}
	}	
	saveChanges(gotoHomeURL);
}

function saveChanges(newURL,cn,cv) {
	saveSettings();
	
	if ((typeof cn) == 'undefined') cn=''; 
	if ((typeof cv) == 'undefined') cv='';

	if (cn != '' && cv != '') {
		window.location.href='http://speedbar.myway.com/redir.html?ru='+escape(newURL)+'&cn='+cn+'&cv='+cv;
	} else {
		window.location.href=newURL;
	}
}

function saveChangesForced(newURL,cn,cv,bSettings) {
	if (bSettings) {
		var newSettings = sm_Toolbar.StreamOut();
		if (! sm_ErrorLoadingSettings) {
			if (document.layers){
				document.embeds["SettingsControl"].ExecPlugin("ShortFormat","\"" + newSettings + "\"");
				document.embeds["SettingsControl"].ExecPlugin("ConfigFormat","\""+ GenerateConfiguration(sm_Toolbar) + "\"");
			} else {
				if (document.getElementById) {
					document.getElementById('SettingsControl').ShortFormat=newSettings;
					document.getElementById('SettingsControl').ConfigFormat=GenerateConfiguration(sm_Toolbar);
				} else if (document.all) {
					document.all.SettingsControl.ShortFormat=newSettings;
					document.all.SettingsControl.ConfigFormat=GenerateConfiguration(sm_Toolbar);
				}
			}
		}
	}
	if (newURL != null) {
		if (cn == null) cn='';
		if (cv == null) cv='';
	
		if (cn != '' && cv != '') {
			window.location.href='http://speedbar.myway.com/redir.html?ru='+escape(newURL)+'&cn='+cn+'&cv='+cv;
		} else {
			window.location.href=newURL;
		}
	}
}

function loadDefault(){
	sm_ErrorLoadingSettings = ! sm_Toolbar.StreamIn(sm_DefaultToolbar);
}

function createToolbar() {
	
	if (typeof MexCVal == "undefined" || MexCVal == null || MexCVal == null || 0 != MexCErr) {
		sm_ErrorLoadingSettings = true;
	} else if (0 == MexCVal.length) {
		loadDefault();
	} else if (! sm_Toolbar.StreamIn(MexCVal)) {
		sm_ErrorLoadingSettings = true;
	} else {
		if (sm_Toolbar.GetFlags() == '0') {
			if (sm_Toolbar.HasButton(200)) {
				sm_Toolbar.RemoveButton(200);
				sm_Toolbar.AddButton(900);
			}
			if (sm_Toolbar.HasButton(201)) {
				sm_Toolbar.RemoveButton(201);
				sm_Toolbar.AddButton(901);
			}
			sm_Toolbar.SetFlags('1');
		}
		if (sm_Toolbar.GetFlags() == '1') {
			sm_Toolbar.SetFlags('2');
		}
		if (sm_Toolbar.HasButton(101)) {
			sm_Toolbar.RemoveButton(101);
			sm_Toolbar.AddButton(102);
		}
		var getDefSelection = readDefCookie('d');
		if (sm_Toolbar.GetDefaultProvider()=='101' || getDefSelection=='AV') {
			setDefCookie('d','AW','Wed, 29 Dec 2199 23:23:59 GMT','/','.mywebsearch.com');
			sm_Toolbar.SetDefaultProvider(102);
		}

		if (sm_Toolbar.HasButton(104)) {
			sm_Toolbar.RemoveButton(104);
			sm_Toolbar.AddButton(103);
		}
		if (sm_Toolbar.GetDefaultProvider()=='104' || getDefSelection=='LS') {
			setDefCookie('d','AJ','Wed, 29 Dec 2199 23:23:59 GMT','/','.mywebsearch.com');
			sm_Toolbar.SetDefaultProvider(103);
		}
		if (askOnly) {
			setDefCookie('d','AJ','Wed, 29 Dec 2199 23:23:59 GMT','/','.mywebsearch.com');
			sm_Toolbar.SetDefaultProvider(103);
			if (sm_Toolbar.HasButton(100)) {
				sm_Toolbar.RemoveButton(100);
			}
			if (sm_Toolbar.HasButton(102)) {
				sm_Toolbar.RemoveButton(102);
			}
		}		
	}
}

function determineBrAndSearch() {
	if (!sm_ErrorLoadingSettings) {
		try {
			if (document.getElementById) {
				getBrandingVal=document.getElementById('SettingsControl').Branding;
			} else if (document.all) {
				getBrandingVal=document.all.SettingsControl.Branding;
			}
		} catch(ee){
		}		
	}
	getBrandingVal='MWS';

	// START: Determine Branding
	if (bucket == 'TT' || bucket == 'VJ' || bucket == 'VK' || bucket == 'VL' || bucket == 'WG' || bucket == 'WS' || bucket == 'WV' || bucket == 'WZ') {
		brandingText='Mindspark';
	}
	// END: Determine Branding

	return false;
}

function determineProdCd() {
	if (lvUrl=='') {
		var prodCdParam='omws';
		var ptnrS = '';
		if (ptnrS=='') {
			try {
				if (document.getElementById) {
					ptnrS=document.getElementById('SettingsControl').GetVal("pid");
				} else if (document.all) {
					ptnrS=document.all.SettingsControl.GetVal("pid");
				}
			} catch(ee){
			}
		}
		if (ptnrS=='') ptnrS = parseURL('partner');
		if (ptnrS=='') ptnrS = parseURL('ptnrS');
		try {
			ptnrS=ptnrS.substring(0,2).toLowerCase();
		} catch(ee){
		}	
		if (ptnrS=='zn') {
			prodCdParam='zn';
		} else if (ptnrS=='zu') {
			prodCdParam='zu';
		} else if (ptnrS=='zj') {
			prodCdParam='zj';
		} else if (ptnrS=='zr') {
			prodCdParam='zr';
		} else if (ptnrS=='zc') {
			prodCdParam='zc';
		} else if (ptnrS=='zs') {
			prodCdParam='zs';
		} else if (ptnrS=='zk') {
			prodCdParam='zk';
		} else if (ptnrS=='zl') {
			prodCdParam='zl';
		} else if (ptnrS=='gs') {
			prodCdParam='gs';
		} else if (ptnrS=='lf') {
			prodCdParam='lf';
		}
		return prodCdParam;
	} else {
		return lvUrl;
	}
}

function trackClick(ckStr) {
	if (!ckStr) ckStr = "/clicks/null_click_string";
	if (typeof(urchinTracker) == "function") {
		urchinTracker(ckStr);
	}
}

function getNextWidgetIndex(){
	if (sm_Toolbar.m_widgetBttns.length==0) {
		return 0;
	} else {
		for(var i=0; i<sm_Toolbar.m_widgetBttns.length; i++){		
			if(!sm_Toolbar.HasButton(i+sm_Toolbar.m_widgetOffset)) {
				return i;	
			}
		}
	} 
	return sm_Toolbar.m_widgetBttns.length;
}

function showWidget(btnNum) {
	var state=4;
	try {
		var btnNumWithOffset=btnNum+sm_Toolbar.m_widgetOffset;
		if(!sm_Toolbar.HasButton(btnNumWithOffset)) {
			if (sm_Toolbar.GetButtonCount()<20) {
				sm_Toolbar.AddButton(btnNumWithOffset);
			}
			state=1;
		} else {
			state=2;
		}
	} catch(ee){
	}	
	return state;
}

function addWidget(title,url,icon,style,width,height) {
	var state=4;

	try {
		var iWidgetBttnNum=sm_Toolbar.FindWidgetButtonID(url);
		var oWidgetBttn=null;
		if (iWidgetBttnNum!=null) {
			oWidgetBttn=sm_Toolbar.GetWidgetButton(iWidgetBttnNum);
		}		
		if (oWidgetBttn!=null) {
			//alert('Your toolbar already contains this widget');
			state=showWidget(iWidgetBttnNum);
			saveSettings();
		} else {
			if (sm_Toolbar.GetButtonCount()<20) {
				//add button to toolbar
				var iNewWidgetBttnArrNum = parseInt(getNextWidgetIndex());	
				state=showWidget(iNewWidgetBttnArrNum);
	
				//Save the Widget Button
				oWidgetBttn = new WidgetButton();
				sm_Toolbar.SetWidgetButton(iNewWidgetBttnArrNum, oWidgetBttn);
				oWidgetBttn.SetTitle(title);
				oWidgetBttn.SetIcon(icon);
				oWidgetBttn.SetURL(url);
				oWidgetBttn.SetStyle(style);
				oWidgetBttn.SetWidth(width);
				oWidgetBttn.SetHeight(height);
	
				saveSettings();
			} else {
				//alert("Cannot add more than 20 buttons.");
				state=3;
			}
		}
	} catch(ee){
	}
	return state;	
}

