﻿// ets.js v3.4.1 Copyright (c) 2006-2010 by BT-Group (info@bt-group.lt)
// All Rights Reserved.

var __key_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function etsAddEvent(obj,event_name,callback) {
	if ( document.addEventListener )
              obj.addEventListener( event_name,callback,false );	
	else if ( document.attachEvent )
              obj.attachEvent( "on" + event_name,callback );
    return true;
}

function etsEncode(input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
                input = input.replace(/\r\n/g,"\n");
		var tmp = "";
		for (var n = 0; n < input.length; n++) {
			var c = input.charCodeAt(n);
			if (c < 128) {
				tmp += String.fromCharCode(c);
			} else if((c > 127) && (c < 2048)) {
				tmp += String.fromCharCode((c >> 6) | 192);
				tmp += String.fromCharCode((c & 63) | 128);
			} else {
				tmp += String.fromCharCode((c >> 12) | 224);
				tmp += String.fromCharCode(((c >> 6) & 63) | 128);
				tmp += String.fromCharCode((c & 63) | 128);
			}
		}
                input = tmp;
		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 + __key_str.charAt(enc1) + __key_str.charAt(enc2) + __key_str.charAt(enc3) + __key_str.charAt(enc4);
		}
		return output;
	}
        
function getParam( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var results = new RegExp( "[\\?&]"+name+"=([^&#]*)" ).exec( window.location.href );
	if( results == null ) return "";
	else return results[ 1 ];
}

function etsParentIframeResize() {
      var height = getParam('height');	
      window.parent.parent.etsResizeIframe(height);
      return true;
}

function etsResizeIframe(h) {
	var j;
        if( j = document.getElementById('ets_frame') )
            j.height = parseInt(h) + 20;
        return true;
}

function etsRedirect() {	
	var hash = location.hash;
	if( hash )
	{
		var regexS = /^#ets:/;		
		var regex = new RegExp( regexS );
		if( regex.test( hash ) ) 
		{
			var j,p;
			p = hash.split( '@' );
			hash = p[ 0 ];
			if( j = document.getElementById( 'ets_frame' ) )
				j.src = j.src + '/?ets_redirect_hash=' + etsEncode( hash ) + '&ets_sc=1&ac=redirect' + ( p.length > 1 ? ( '&ets_page=' + p[ 1 ] ) : '' );
			return true;
		} // if
	} // if
	return false;
}
