




FS = {
    Handlers: new Array(),
    SiteID: '40',
    SiteCode: '' };

FS.setCSS = function() {

    var s = document.createElement('link');
    s.setAttribute('rel','stylesheet');
    s.setAttribute('type','text/css');
    s.setAttribute('href','http://www.findsavings.com/widgets/WApp/css/default.css');
    document.getElementsByTagName("head").item(0).appendChild(s);
}
    
FS.getCodeFromServer = function(url) {

    var id = 'fs_WorkSpace'

    // Fetch the element pointed to by the id. If it exists, we destroy it so we can create a new one.
    oScript = document.getElementById(id);

    // Point at the script tag, if it exists
    if (oScript) {
        if (oScript.readyState != 'loaded' && oScript.readyState != 'complete' ) {
            id = 'fs_Workspace2';
            oScript = document.getElementById(id);
        }
    }
    if (oScript) {
        if (oScript.readyState != 'loaded' && oScript.readyState != 'complete' ) {
            id = 'fs_Workspace3';
            oScript = document.getElementById(id);
        }
    }
    if (oScript) {
        if (oScript.readyState != 'loaded' && oScript.readyState != 'complete' ) {
            id = 'fs_Workspace4';
            oScript = document.getElementById(id);
        }
    }

    var p 
    if (oScript) {
        p = oScript.parentNode;
        p.removeChild(oScript);
    } else {
        p = document.getElementsByTagName("head").item(0);
    }

    // Create the new script tag
    oScript = document.createElement("script");

    // Add a random variable to the url so that it is unique to prevent cacheing
    if (url.indexOf('?') > 0) {
        url += '&junk=' + Math.random()
    } else {
        url += '?junk=' + Math.random()
    }
    // Setup the src attribute of the script tag
    oScript.setAttribute("src", url);

    // Set the id attribute of the script tag
    oScript.setAttribute("id",id);
    

    // Create the new script tag which causes the proxy to be called
    p.appendChild(oScript);

    scroll(0,0);
}

   
FS.handler = function (name, event, action) {
	this.name = name;
	this.event = event;
	this.action = action;
}

FS.HandleEvent = function(e,args) {
	for (i=0; i<FS.Handlers.length; i++) { 
		if (FS.Handlers[i].event == e) { 
		    if (FS.Handlers[i].action.substring(0,4).toUpperCase() == 'HTTP') {
		        FS.HandleServerEvent(e, FS.Handlers[i].action, args);
		    } else {
			    FS.Handlers[i].action(e, args);
			};
		};
	};
};

FS.HandleServerEvent = function(e, url, args) {
    var uOut = url;
    if (uOut.indexOf('?') == -1 ) { uOut += '?'; } else { uOut += '&'; };
    uOut += 'e=' + e;
    uOut += '&SiteID=' + FS.SiteID;
    for (var p in args) { uOut += '&' + p + '=' + args[p]; };
    
    FS.getCodeFromServer(uOut);
        
}

FS.RegisterHandler = function (handler) {
	var found = false;
	for (i=0; i<FS.Handlers.length; i++) { if (FS.Handlers[i].name == handler.name && FS.Handlers[i].event == handler.event) { found=true; }};
	if (!found) { FS.Handlers[FS.Handlers.length] = handler; }
}

  
  
FS.setCSS();
  
  
  
  
  
    
  
  
  
  
  
  
