
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars[hash[0]] = hash[1];
    }

    if(vars.bgcolor == null) {
        vars.bgcolor = "FFFFFF";
    }

    document.bgColor = vars.bgcolor;

    return vars;
}

function vfmFPoint(el) {
    if( document.all ) {
		return document.all(el);
	} else {
		return document.getElementById(el);
	}
}

function replaceExisitingValues(opt, rep) {
    for(var name in rep) {
        if(opt[name] != '') {
            opt[name] = rep[name];
        }
    }
    return opt;
}

var last_url;
var last_width;
var last_height;
var last_x;
var last_y;

function loadPanorama(url, width, height, x, y) {
	last_url = url;
	last_width = width;
	last_height = height;
	last_x = x;
	last_y = y;
    $('#IframeDiv').css('display', 'block');
    $('#IframeDiv').css('width', width);
    $('#IframeDiv').css('height', height);
    $('#IframeDiv').css('left', x);
    $('#IframeDiv').css('top', y);
    if($.browser.msie) {
        var frame = document.all('vrframe');
        $('#IframeDiv').css('width', width+1);
        $('#IframeDiv').css('height', height+1);
    } else {
        var frame = document.getElementById('vrframe');
    }

    frame.src = '/media/resource/viewer/panorama/panFrame.html?url='+url;
}

function reloadPanorama() {
	$('#IframeDiv').css('display', 'block');
    $('#IframeDiv').css('width', last_width);
    $('#IframeDiv').css('height', last_height);
    $('#IframeDiv').css('left', last_x);
    $('#IframeDiv').css('top', last_y);
    if($.browser.msie) {
        var frame = document.all('vrframe');
        $('#IframeDiv').css('width', last_width+1);
        $('#IframeDiv').css('height', last_height+1);
    } else {
        var frame = document.getElementById('vrframe');
    }

    frame.src = '/media/resource/viewer/panorama/panFrame.html?url='+last_url;
}

function unloadPanorama() {
    $('#IframeDiv').css('display', 'none');
    if($.browser.msie) {
        var frame = document.frames['vrframe'];
    } else {
        var frame = document.getElementById('vrframe');
    }

    frame.src = '/media/resource/viewer/panorama/panFrame.html';
}

function loadUrl(url){
    window.open(url);
}

function utf8_decode(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;
    }

