function getDocumentSize(doc) { // getting a real size document with scrolling
								// etc.
	var r = {
		width : 0,
		height : 0
	};

	var width1 = 0, width2 = 0, width3 = 0, width4 = 0, maxWidth = 0;
	var height1 = 0, height2 = 0, height3 = 0, height4 = 0, maxHeight = 0;

	if (doc.width)
		maxWidth = doc.width;
	if (doc.body) {
		if (doc.body.scrollWidth)
			width1 = doc.body.scrollWidth;
		if (doc.body.offsetWidth)
			width2 = doc.body.offsetWidth;
	}
	if (doc.documentElement) {
		width3 = doc.documentElement.scrollWidth;
		width4 = doc.documentElement.clientWidth;
	}

	maxWidth = Math.max(Math.max(Math.max(width1, width2), Math.max(width3,
			width4)), maxWidth);

	if (doc.height)
		maxHeight = doc.height;
	if (doc.body) {
		if (doc.body.scrollHeight)
			height1 = doc.body.scrollHeight;
		if (doc.body.offsetHeight)
			height2 = doc.body.offsetHeight;
	}
	if (doc.documentElement) {
		height3 = doc.documentElement.scrollHeight;
		height4 = doc.documentElement.clientHeight;
	}
	maxHeight = Math.max(Math.max(Math.max(height1, height2), Math.max(height3,
			height4)), maxHeight);

	r.width = maxWidth;
	r.height = maxHeight;

	return r;
}

function show_calc(A) {
	var body = document.getElementsByTagName('BODY')[0];

	var div = document.createElement('DIV');
	div.name = 'insurance_top';
	div.id = 'insurance_top';
	div.style.position = 'absolute';
	div.style.top = '0px';
	div.style.width = '600px';
	// body.appendChild(div);

	var div = document.createElement('DIV');
	div.name = 'insurance';
	div.id = 'insurance';
	div.style.position = 'absolute';
	div.style.top = '0';
	div.style.left = '0';
	div.style.width = '100%';
	div.style.height = getDocumentSize(document).height + 'px';
	div.style.background = '#fff';
	div.style.textAlign = 'center';
	div.style.zIndex = '1000';
	if (typeof div.style.filter == 'string') {
		div.style.filter = 'alpha(opacity=50)';
	}
	if (typeof div.style.opacity == 'string') {
		div.style.opacity = 0.5;
	}
	if (typeof div.style.MozOpacity == 'string') {
		div.style.MozOpacity = 0.5;
	}

	var iframe = document.createElement('IFRAME');

	iframe.frameBorder = '0';
	iframe.scrolling = 'No';
	iframe.src = A.href;

	iframe.id = 'insurance_iframe';
	iframe.style.position = 'absolute';
	iframe.style.top = '5%';
	iframe.style.left = '35%';
	iframe.style.border = '1px solid #000';
	iframe.style.width = '450px';
	iframe.style.height = '700px';
	iframe.style.margin = '0';
	iframe.style.padding = '0';
	iframe.style.zIndex = '2000';

	body.appendChild(div);
	body.appendChild(iframe);

	self.location = '#insurance';

	return false;
}

function init_calc() {

	var a1 = false;

	var a = document.getElementsByTagName('A');
	var l = a.length;

	for ( var i = 0; i < a.length; i++) {
		if (a[i].className == 'insurance') {
			a[i].target = '_blank';
			a[i].onclick = function() {
				return show_calc(this);
			}

			if (!a1) {
				a1 = a[i];
			}
		}
	}
	
	return a1;
}

function urlencode( str ) {

    var hash_map = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';

    ret = encodeURIComponent(ret);

    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No
        // regexing
    }

    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}

function serialize(array) {
    var str = new String('?');
    for (i in array) {
        str += urlencode(i)+'='+urlencode(array[i])+'&';
    }
    str = str.substr(0, str.length-1);
    
    return str;
    
}
