var rev_popupStatus = "offline";
var rev_popupHasNotBeenVisited = true;
var rev_popupRevationServer="";
var rev_popupPresenceId="";
var rev_popupIntervalId;
var rev_statusIntervalId;
var rev_positionIntervalId;

function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.allrev_(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
	} else {
		return false;
	}
} 
function show(objectId) {
	changeObjectVisibility(objectId,"visible");
}
function hide(objectId) {
	changeObjectVisibility(objectId,"hidden");
}
function changeObjectVisibility(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId,document);
	if(styleObject){
		styleObject.visibility=newVisibility;
		return true;
	}
	return false;
} 
function rwc_statusUpdated(pid,status){
	rev_popupStatus = status;
}
function rev_initializePopupLayer(server,im,posTimeout,staTimeout,popTimeout) {
	rev_popupRevationServer=server;
	rev_popupPresenceId = im;
	rev_updateStatus();
	rev_positionIntervalId=setInterval("rev_positionLayers()",posTimeout);
	rev_statusIntervalId=setInterval("rev_updateStatus()",staTimeout);
	rev_popupIntervalId=setInterval("rev_showPopupLayer()",popTimeout);	
}
function rev_showPopupLayer() {
	if (rev_popupHasNotBeenVisited && rev_popupStatus == "online") {
		show("rev_popup_layer");
	}
}
function rev_closePopupLayer() {
	rev_popupHasNotBeenVisited = false;
	hide("rev_popup_layer");
	clearInterval(rev_popupIntervalId);
}
function rev_positionPopupLayer() {
	//define universal dsoc left point
	var dsocleft=document.all? document.body.scrollLeft : pageXOffset
	//define universal dsoc top point
	var dsoctop=document.all? document.body.scrollTop : pageYOffset
	//define universal browser window width
	var window_width=document.all? document.body.clientWidth : window.innerWidth
	//define universal browser window height
	var window_height=document.all? document.body.clientHeight : window.innerHeight

	var popupobj = document.getElementById("rev_popup_layer");
	var popup_width=popupobj.clientWidth;
	var popup_height=popupobj.clientHeight;
	var obj = getStyleObject("rev_popup_layer");
	if (obj) {
		//if the user is using IE 4+ or NS6+
		if (document.all||document.getElementById){
			if (parseInt(window_width) <= parseInt(popup_width)) {
				obj.left = parseInt(dsocleft);
			} else {
				obj.left = parseInt(dsocleft) + ((parseInt(window_width) - parseInt(popup_width))/2);
			}
			if (parseInt(window_height) <= parseInt(popup_height)) {
				obj.top = parseInt(dsoctop);
			} else {

			obj.top= parseInt(dsoctop) + ((parseInt(window_height) - parseInt(popup_height))/2);
			}
		}
	
		//else if the user is using NS 4
		else if (document.layers) {
			obj.left= dsocleft
			obj.top=dsoctop
		}
	}
}
function rev_positionLayers() {
	rev_positionPopupLayer();
}
function rev_updateStatus(){
	var head=document.getElementsByTagName('head').item(0);
	var script=document.createElement('script');
	script.type='text/javascript';
	script.id='myscript';
	script.defer=true;
	script.src='https://'+rev_popupRevationServer+'/status/js/script.js?im='+rev_popupPresenceId;
	head.appendChild(script);
}
function rev_chatPopupWindow() {
	rev_closePopupLayer();
	var chatUrl;
	var chatWindow;
	chatUrl="https://"+rev_popupRevationServer+"/?im="+rev_popupPresenceId+"&pres=0";
	chatWindow = window.open(chatUrl,"rev_chatPopupWindow","scrollbars=no,menubar=no,status=no,resizable=no,location=no,width=450,height=452,left=200,top=100");
}