IsignyPUB = function(){return{
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	protocol: "http",
	host: "pub.isigny.org",
	path: "/services/",
	module: "regie",
	ip_width: 0,
	ip_height: 0,	
	ip_model: '',
	parametres: {},

	selectModel:function () {
		switch(this.ip_model) {
			case "SmallSquare":
				this.ip_width=140;
				this.ip_height=103;
			break;
			case "TMediumRectangle":
				this.ip_width=312;
				this.ip_height=265;
			break;			
			case "TSquarePopUp":
				this.ip_width=262;
				this.ip_height=265;
			break;
			case "TVerticalRectangle":
				this.ip_width=252;
				this.ip_height=415;
			break;
			case "TLargeRectangle":
				this.ip_width=348;
				this.ip_height=295;
			break;			
			case "TRectangle":
				this.ip_width=192;
				this.ip_height=165;
			break;			
			case "T13Rectangle":
				this.ip_width=312;
				this.ip_height=115;
			break;
			case "TPopUnder":
				this.ip_width=732;
				this.ip_height=315;
			break;			
			case "TFullBanner":
				this.ip_width=480;
				this.ip_height=75;
			break;
			case "THalfBanner":
				this.ip_width=246;
				this.ip_height=75;
			break;
			case "TMicroBar":
				this.ip_width=100;
				this.ip_height=46;
			break;			
			case "TButton1":
				this.ip_width=132;
				this.ip_height=105;
			break;				
			case "TButton2":
				this.ip_width=132;
				this.ip_height=75;
			break;			
			case "TVerticalBanner":
				this.ip_width=132;
				this.ip_height=255;
			break;
			case "TSquareButton":
				this.ip_width=137;
				this.ip_height=140;
			break;			
			case "TLeaderboard":
				this.ip_width=740;
				this.ip_height=105;
			break;
			case "TWideSkyscraper":
				this.ip_width=172;
				this.ip_height=615;
			break;
			case "TSkyscraper":
				this.ip_width=132;
				this.ip_height=615;
			break;			
			case "THalfPageAd":
				this.ip_width=312;
				this.ip_height=615;
			break;	
			case "IMediumRectangle":
				this.ip_width=312;
				this.ip_height=265;
			break;			
			case "ISquarePopUp":
				this.ip_width=262;
				this.ip_height=265;
			break;
			case "IVerticalRectangle":
				this.ip_width=252;
				this.ip_height=415;
			break;
			case "ILargeRectangle":
				this.ip_width=348;
				this.ip_height=295;
			break;			
			case "IRectangle":
				this.ip_width=192;
				this.ip_height=165;
			break;			
			case "I13Rectangle":
				this.ip_width=312;
				this.ip_height=115;
			break;
			case "IPopUnder":
				this.ip_width=732;
				this.ip_height=315;
			break;			
			case "IFullBanner":
				this.ip_width=480;
				this.ip_height=75;
			break;
			case "IHalfBanner":
				this.ip_width=246;
				this.ip_height=75;
			break;
			case "IMicroBar":
				this.ip_width=100;
				this.ip_height=46;
			break;			
			case "IButton1":
				this.ip_width=132;
				this.ip_height=105;
			break;				
			case "IButton2":
				this.ip_width=132;
				this.ip_height=75;
			break;			
			case "IVerticalBanner":
				this.ip_width=132;
				this.ip_height=255;
			break;
			case "ISquareButton":
				this.ip_width=137;
				this.ip_height=140;
			break;			
			case "ILeaderboard":
				this.ip_width=740;
				this.ip_height=105;
			break;
			case "IWideSkyscraper":
				this.ip_width=172;
				this.ip_height=615;
			break;
			case "ISkyscraper":
				this.ip_width=132;
				this.ip_height=615;
			break;			
			case "IHalfPageAd":
				this.ip_width=312;
				this.ip_height=615;
			break;				
			default: 
				this.ip_width=140;
				this.ip_height=103;
		}		
	}, 
	
	writeFrame:function(){
		document.write('<iframe width="'+this.ip_width+'" height="'+this.ip_height+'"id="isigny-pub-data" name="isigny-pub-data" style="display: block" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no"></iframe>');
	}, 
	
	writeForm:function(){
		document.write('<form style="display: none;" method="post" id="isigny-pub-form" action="'+this.protocol+'://'+this.host+this.path+this.module+'.php'+'" target="isigny-pub-data"><input type="submit"/></form>');
	},
	
	addParametre:function(key, val){
		this.parametres[key]=val;
	},
	
	addParametres:function(h){
		for(i in h) this.addParametre(i,h[i]);
	},
	
	getParametres:function(){
		var out="";
		for(i in this.parametres) {
			out += this.encode64(i+"="+this.parametres[i])+"/";
		}
		out = "/"+out.substr(0,out.length-1);
		return out;
	},	
	
	initialize:function(x) {
		this.ip_model=x.model;
		this.ip_akey=x.akey;
		this.selectModel();
		this.writeFrame();
		this.writeForm();
		
		this.addParametres(x);
		
		this.addParametre('colorDepth',window.screen.colorDepth);
		this.addParametre('screenWidth',window.screen.width);
		this.addParametre('screenHeight',window.screen.height);
		
		this.addParametre('fromcode','1');
		this.addParametre('get','');	
		
		Event.observe($(window),'load', function(e) {
			$('isigny-pub-form').action+=ip.getParametres();
			$('isigny-pub-form').submit();
		}, false);
	},
	
	encode64:function(input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        input = this._utf8_encode(input);
        while (i < input.length) {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }
        return output;
    },

    // public method for decoding
    decode64 : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < input.length) {
            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
        }
        output = this._utf8_decode(output);
        return output;

    },

    _utf8_encode:function(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    },

    _utf8_decode:function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while ( i < utftext.length ) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    }
}};

ip = new IsignyPUB();
ip.initialize(config);
