/******************************************************************************************
* Browser-specific feature detection
******************************************************************************************/
var w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && !document.all)? true: false;

/******************************************************************************************
* Element offsets
******************************************************************************************/
function getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

/******************************************************************************************
* Serialisation and deserialisation
******************************************************************************************/
function isUndefined(a) {
    return typeof a == 'undefined';
} 

quote = ((ns4) ? function (x) {
    return x = x.replace(/(["\\])/g, function (s) {return '\\' + s;});
    return x = x.replace(/\n/g, function (s) {return '\r'});
    return x = x.replace(/\r/g, function (s) {return '\n'});
    return '"'+x+'"';
} : function (x) {
    x = x.replace(/(["\\])/g, '\\$1');
    x = x.replace(/\n/g, '\\n');
    x = x.replace(/\r/g, '\\r');
    return '"'+x+'"';
});

function serialise(arg) {
    var i, o, v;

    switch (typeof arg) {
    case 'object':
        if (arg) {
            if (arg.constructor == Array) {

                o = '[';
                for (i = 0; i < arg.length; ++i) {
                    v = serialise(arg[i]);
                    if (v != 'function' && !isUndefined(v)) {
                        o += (o != '[' ? ',' : '') + v;
                    } else {
                        o += ',';
                    }
                }
                return o + ']';
            } else if (typeof arg.toString != 'undefined') {
                o = '{';
                for (i in arg) {
                    v = serialise(arg[i]);
                    if (v != 'function' && !isUndefined(v)) {
                        o += (o != '{' ? ',' : '') + 
                            quote(i) + ':' + v;
                    }
                }
                return o + '}';
            } else {
                return;
            }
        }
        return 'null';
    case 'unknown':
    case 'undefined':
        return;
    case 'string':
        return quote(arg);
    case 'function':
        return 'function';
    default:
        return String(arg);
    }
}

function deserialise(arg) {
	return eval('var o='+arg+'; o');
}

/******************************************************************************************
* BOSI Utility code - mouse over/out's
******************************************************************************************/

function stdMI(e) {
	e.style.backgroundColor = '#dee7ec';
}

function stdMO(e) {
	e.style.backgroundColor = '#ffffff';
}

/******************************************************************************************
* Image zoom (browser)
******************************************************************************************/
function bosizoom(id,isOut,quickmode) {
	image = window.frames['preview'].document.getElementById('preview_image');
	if(isOut && image.width < 1600) {
		if(quickmode) {
			image.width = image.width * 1.5;
		} else {
			document.getElementById('preview').src = './view3_preview?imageid=' + id + '&setwidth=' + Math.floor(image.width*1.5);
		}
	} else if (!isOut && image.width > 40){
		if(quickmode) {
			image.width = image.width * 0.75;
		} else {
			document.getElementById('preview').src = './view3_preview?imageid=' + id + '&setwidth=' + Math.floor(image.width*0.75);
		}
	}
}

/******************************************************************************************
* Child window handling for popups
******************************************************************************************/
var bosichild = null;

function BOSI_onunload(e) {
	if(bosichild != null)
		bosichild.close();
}

window.attachEvent("onunload", BOSI_onunload);

function openchild(URL,name,options) {
	if(!name) { name = 'BOSIChild'; }
	if(!options) { options = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left=240,top=212'; }
	if(bosichild != null) { bosichild.close(); }
	bosichild = window.open(URL,name,options);
}

/******************************************************************************************
* MISC
******************************************************************************************/
// Fix for bug in IE6.0 float handling (don't ask, don't tell ;)
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
function fixWinIE() {
    try {
        document.getElementById('content').style.display = 'block';
    } catch(er) {}
}
// Push and pop for arrays is not implemented in Internet Explorer
if (!Array.prototype.push) {
	Array.prototype.push = function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
}
if (!Array.prototype.pop) {
	Array.prototype.pop = function array_pop() {
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
}

/******************************************************************************************
* Form sumbission (for login form)
******************************************************************************************/
function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
		myfield.form.submit();
		return false;
	} else {
		return true;
	}
}
