﻿    /* FSA Client-side tool classes
     *
     * By Julian Vallis (Publicis Dialog) 2007
     * Requires Prototype 1.5.1 (http://www.prototypejs.org)
     */

    var FSATool = Class.create();
    FSATool.prototype = {
	    partner: '',
	    tool: '',
	    divid: '',
	    initialize: function(_partner,_tool,_divid) {
		    this.partner = _partner;
		    this.tool = _tool;
		    this.divid = _divid;
            if (this.partner != '' && this.tool != '' && this.divid != '') {
			    this.request();
            }
	    },
	    request: function() {
		    new Ajax.Request('http://localhost/partners.aspx?Headers=true&Partner=' + this.partner + '&Tool=' + this.tool, {
			    method: 'get',
				onSuccess: function(transport) {
					var d = new FSAWriter(this.divid, transport.responseText);
					return true;
				},
				onFailure: function(transport) {
					var d = new FSAWriter(this.divid, '<h1>Error ' + transport.status + '</h1>');
					return false;
				}
		    });
	    }
    }
    
    var FSAWriter = Class.create();
    FSAWriter.prototype = {
	    initialize: function(_id,_html) {
		    if (_id == null) {
		        d = "<div id=" + _id + ">"
		        if(_html == null)
    			    return;
		        d += _html;
		        d += "</div>\n";
		        document.write(d);
		    }  
		    else
		        document.getElementById(_id).innerHTML = _html;
		    return true;
	    }
	}
    
	var Popup = Class.create();
	Popup.prototype = {
		initialize: function() {
			if (!document.getElementsByTagName){ return; }
			var anchors = document.getElementsByTagName('a');
	
			// loop through all anchor tags
			for (var i=0; i<anchors.length; i++) {
				var anchor = anchors[i];
				
				var relAttribute = String(anchor.getAttribute('rel'));
				
				// use the string.match() method to catch 'lightbox' references in the rel attribute
				if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('popup'))) {
					anchor.onclick = function () { myPopup.Start(this); return false; }
				}
			}
		},
		Start: function(popupLink) {
			if (!document.getElementsByTagName){ return; }
			var props = popupLink.getAttribute('rel').substring(5,popupLink.getAttribute('rel').length);
			var properties = [];
			if (props.charAt(0) == '[')
				var properties = eval(props);
			window.open(popupLink.getAttribute('href'),"Popup","width="+properties[0]+",height="+properties[1],"menubar=no,toolbar=no,location=no,directories=no,personalbar=no,scrollbars=yes,dependent=no");
			return;
		}
	}
	var myPopup;

	Event.observe(window, "load", function() {
		myPopup = new Popup();
	});

