/** Bradon Technologies Ltd.*/
/*
private void Page_Load(object sender, System.EventArgs e) { 
	this.PreRender += new System.EventHandler(this.Page_PreRender); 
} 

private void Page_PreRender(object sender, EventArgs e) {
	HtmlMeta metatag = new HtmlMeta();
	metatag.Attributes.Add("http-equiv", "X-UA-Compatible");
	metatag.Attributes.Add("content", "ID=EmulateIE7");
	Page.Header.Controls.AddAt(0,metatag);
}
*/
var myWorkplace;
var user_cat;
var istimeZoneSet = false;
var rootImg = "img/1F1159C3C1A31D5228326387864DF40B";
var pool;
var poolInterval = 4000;
var poolFile = "ext/ping.jsp";
var launcherObjName = "launcher"; 
var bitarray = new Array("user_list","user_list_pub","info_box","info_box_alert","event_status","my_events_content","my_events_content_alert","message","zone_admin_info","widget0_content","widget1_content","__event_start","__event_over","__host_live");
var avatar_relative = "CONTACT_LIST";

workplace = function () {
	this.workarea = "";
	this.obj = null;
	var subCat = "";
	
	this.init = function () {
		this.obj = (d("workplace_layer")) ? d("workplace_layer") : null;
	};
	this.setSubCategory = function(category) {
		subCat = category;
	};
	this.showPage = function(pagename) {
		this.showPageArgs(pagename, null);
	};
	this.showPageArgs = function(pagename, param) {
		if (this.obj == null) { return; }
		var ext = "";
		if (param != null) {
			ext = "?arg="+param;
		}
		if (subCat.length > 0) pagename = subCat+"/"+pagename; subCat = "";
		var request = new XMLRequest("ext/"+pagename+".jsp"+ext, this.obj.id);
		request.Do();
	};
	this.addContent = function(objName) {
		this.addContentArgs(objName, null);
	};
	this.addContentArgs = function(objName, param) {
		var ext = "";
		var pagename = objName;
		if (param != null) {
			ext = "?arg="+param;
		}
		if (subCat.length > 0) pagename = subCat+"/"+pagename; subCat = "";
		var request = new XMLRequest("ext/"+pagename+".jsp"+ext, objName);
		request.Do();
	};
	this.addContentArgsObj = function(pagename, objName, param) {
		var ext = "";
		if (param != null) {
			ext = "?arg="+param;
		}
		if (subCat.length > 0) pagename = subCat+"/"+pagename; subCat = "";
		var request = new XMLRequest("ext/"+pagename+".jsp"+ext, objName);
		request.Do();
	};
	this.reset = function() {
		var curLocation = window.location.href.replace('#','');
		window.location.href = curLocation + ((curLocation.indexOf("?") > 0) ? "&" : "?") + "action_01=login";
	};
	this.DoPOST = function(pagename, parameters) {
		this.DoPOSTObj(pagename, parameters, null);
	};
	this.DoPOSTObj = function(pagename, parameters, objName) {
		if (objName == null) objName = this.obj.id;
		// =================DEBUG==================
		//var request = new XMLRequest("servlet/bradon.scheduler.ShowParameters", this.obj.id);
		// ========================================
		if (subCat.length > 0) pagename = subCat+"/"+pagename; subCat = "";
		var request = new XMLRequest("ext/"+pagename+".jsp", objName);
		request.METHOD = "POST";
		request.PARAMETERS = parameters;
		request.Do();
	};
};

XMLRequest = function (url, target) {
	var XMLReq;
	var objTarget = d(target);
	this.METHOD = "GET";
	this.PARAMETERS = "";
	this.url = url;
	
	this.Do = function() {
		if (!objTarget) {
			return; 
		}
		var browser = navigator.userAgent.toUpperCase();
		if (window.ActiveXObject) {
			if(browser.indexOf("MSIE 5") < 0) {
	            XMLReq = new ActiveXObject("Msxml2.XMLHTTP");
	        } else {
	            XMLReq = new ActiveXObject("Microsoft.XMLHTTP");
	        }		
		} else if (window.XMLHttpRequest) {
			XMLReq = new XMLHttpRequest();
		}
		
		if (XMLReq) {
			XMLReq.onreadystatechange = function() {
				if (XMLReq.readyState == 4 && XMLReq.status == 200) { 
        			var result = XMLReq.responseText;
        			// ========= DEBUG =============
        			// ** Turn < and > into &lt; and &gt; for displaying on the page.
        			//if (objTarget.id == "zone_admin_info") {
        			//	result = result.replace(/\<([^!])/g, '&lt;$1');
        			//	result = result.replace(/([^-])\>/g, '$1&gt;');
        			//	result = "<pre>"+result+"</pre>";
        			//}
        			// =============================
        			objTarget.innerHTML = result;
				}
			};
			if (this.METHOD == "GET") {
	    		XMLReq.open("GET", this.url, true);
	    		XMLReq.send("");
    		} else if (this.METHOD == "POST") {
		        var now = "upid=" + new Date().getTime();
  				this.PARAMETERS += "&"+now;
             	XMLReq.open('POST', this.url, true);
                XMLReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                XMLReq.setRequestHeader("Content-length", this.PARAMETERS.length);
                XMLReq.setRequestHeader("Cache-Control", "no-cache");
                XMLReq.setRequestHeader("Pragma", "private");
                XMLReq.setRequestHeader("Expires", -1);
                if(browser.indexOf("WINDOWS NT 5.0") < 0) {
	                // IE, Windows 2000, does not work properly
                	XMLReq.setRequestHeader("Connection", "close");
                }
                XMLReq.send(encodeURI(this.PARAMETERS));
    		}
		}
	};
};

setImgRoot =  function (path) {
	rootImg = path;
};

imgHover = function (obj,flag) {
	obj.src=(flag) ? obj.src.replace('01','02') : obj.src.replace('02','01');
};

function formPOST(frmObj) {
  var str = "";
  var subcat = "";
  if (frmObj.subcategory) {
	  if (frmObj.subcategory.value.length > 0) subcat = frmObj.subcategory.value + "/";
  }
  var action_01 = subcat + frmObj.action_01.value;
  var target = (frmObj.target) ? frmObj.target.value : null;

  for (i=0; i<frmObj.getElementsByTagName("input").length; i++) {
     if (frmObj.getElementsByTagName("input")[i].type == "hidden") {
        str += frmObj.getElementsByTagName("input")[i].name + "=" + frmObj.getElementsByTagName("input")[i].value + "&";
     } else  if (frmObj.getElementsByTagName("input")[i].type == "text") {
         str += frmObj.getElementsByTagName("input")[i].name + "=" + frmObj.getElementsByTagName("input")[i].value + "&";
     } else  if (frmObj.getElementsByTagName("input")[i].type == "password") {
         str += frmObj.getElementsByTagName("input")[i].name + "=" + frmObj.getElementsByTagName("input")[i].value + "&";
     } else if (frmObj.getElementsByTagName("input")[i].type == "checkbox") {
        if (frmObj.getElementsByTagName("input")[i].checked) {
           str += frmObj.getElementsByTagName("input")[i].name + "=" + frmObj.getElementsByTagName("input")[i].value + "&";
        } else {
           str += frmObj.getElementsByTagName("input")[i].name + "=&";
        }
     } else if (frmObj.getElementsByTagName("input")[i].type == "radio") {
        if (frmObj.getElementsByTagName("input")[i].checked) {
           str += frmObj.getElementsByTagName("input")[i].name + "=" + frmObj.getElementsByTagName("input")[i].value + "&";
        }
     }
  }

  if (frmObj.getElementsByTagName("select")) {
	  for (i=0; i<frmObj.getElementsByTagName("select").length; i++) {
	      var sel = frmObj.getElementsByTagName("select")[i];
	      str += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	  }
  }  

  if (target != null) {
		myWorkplace.DoPOSTObj(action_01, str, target);
  } else {
		myWorkplace.DoPOST(action_01, str);
  }
  
}

function scrolldown(objDiv) {
	var test1 = objDiv.scrollHeight;
	var test2 = objDiv.offsetHeight;
	if (test1 > 0) 	{
		objDiv.scrollTop = objDiv.scrollHeight;
	} else 	{
		objDiv.scrollTop = objDiv.offsetHeight;
	}	
}

function headMsg(msg) {
	var headMsgDiv = d('headmessage');
	if (headMsgDiv) {
		headMsgDiv.innerHTML = msg;
	}
}

function ismaxlength(obj){
	var mlength=obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
	}
}

function isEnter(field,event) {
	var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	return (theCode == 13);
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true; 
	} else {
		return false;
	}
}

function isPhone(str) {
	var phone2 = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/; 
	if (str.match(phone2)) {
   		return true;
 	} else {
 		return false;
 	}
}

function IsNumeric(data){
    return parseFloat(data)==data;
}

function IsEAC(data){
	var res = false;
	var maxLength = 7;
	if (parseInt(data) == data) {
		if (data.length == maxLength) {
			res = true;
		}
	}
    return res;
}

function validateEACPage(frm) {
	  var value = '';
	  var _qfMsg = '';
	  var maxLength = 7;
	  value = frm.elements['eac'].value;
	  if (!IsEAC(value)) {
	    _qfMsg = _qfMsg + '\n - Event Access Code is incorrect.\t';
	  }
	  if (_qfMsg != '') {
	    _qfMsg = 'Invalid information entered.\n' + _qfMsg;
	    errorMessage("<pre>"+_qfMsg+"</pre>",'JS-1005');
	    return false;
	  }
	  return true;
}

function validate_email(value) {
	  var _qfMsg = '';
	  if (!isEmail(value)) {
		    _qfMsg = _qfMsg + '\n - Email Address is not valid.\t';
		  }
	  if (_qfMsg != '') {
	    _qfMsg = 'Invalid information entered.\n' + _qfMsg;
	    errorMessage("<pre>"+_qfMsg+"</pre>",'JS-1005');
	    return false;
	  }
	  return true;
}

function validateProfileForm(frm) {
	  var value = '';
	  var value2 = '';
	  var _qfMsg = '';
	  value = frm.elements['fname'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '<br> - First name field is empty.';
	  }
	  value = frm.elements['lname'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '<br> - Last name field is empty.';
	  } 
	  value = frm.elements['nickname'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '<br> - Preferred Name field is empty.';
	  }
	  value = frm.elements['uname'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '<br> - Email address field is empty.';
	  } else {
		  if (!isEmail(value)) {
			_qfMsg = _qfMsg + '<br> - Incorrect email address.';
		  }
	  }
	  if (frm.elements['upass']) {
		  value = frm.elements['upass'].value;
		  value2 = frm.elements['upass2'].value;
		  if (value.length > 0 && value.length < 8) {
				_qfMsg = _qfMsg + '<br> - Password field is short. Minimum 8 symbols.';
		  } else if (value != value2) {
		    _qfMsg = _qfMsg + '<br> - Password strings do not match.';
		  }
	  }
	  if (_qfMsg != '') {
		_qfMsg = '<b>Invalid information entered:</b><br>' + _qfMsg+'<br><br>';
	    //errorMessage("<pre>"+_qfMsg+"</pre>",'JS-1001.1');
	    errorMessage(_qfMsg,'JS-1001.1');
	    return false;
	  }
	  return true;
}

function validate_contactForm(frm) {
	  var value = '';
	  var _qfMsg = '';
	  
	  value = frm.elements['cname'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '\n - Your name was not entered.\t';
	  }
	  value = frm.elements['email'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '\n - Your email address is empty.\t';
	  } else {
		  fd = frm.elements['email'];
		  if (fd) {
			  value = fd.value;
			  if ( value != '' && !isEmail(value) ) {
				_qfMsg = _qfMsg + '\n - Incorrect email address.\t';
			  }
		  }
	  }
	  value = frm.elements['subject'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '\n - The subject field is empty.\t';
	  }
	  value = frm.elements['message'].value;
	  if (value == '') {
	    _qfMsg = _qfMsg + '\n - Your message is empty.\t';
	  }
	  if (_qfMsg != '') {
		    _qfMsg = 'Invalid information entered.\n' + _qfMsg;
	    errorMessage("<pre>"+_qfMsg+"</pre>",'JS-1004');
	    return false;
	  }
	  return true;
}

function scaleImage (imgURI, imgObj, MaxImageWidth, MaxImageHeight) {
	var Ratio = 1.0;
	var now = new Date();
	var nImg = new Image();
	nImg.onload = function () {
		var iWidth = this.width;
		var iHeight = this.height;
		if (iWidth && iHeight) {
			if (iWidth > MaxImageWidth || iHeight > MaxImageHeight)	{
				Ratio = iWidth / iHeight;
				if (iWidth > MaxImageWidth) { 
					iWidth = MaxImageWidth; 
					iHeight = parseInt(iWidth / Ratio);
				}
				if (iHeight > MaxImageHeight) { 
					iHeight = MaxImageHeight; iWidth = parseInt(iHeight * Ratio);
				}
			}
		}  
		imgObj.onload = null;	// kill the loop
		imgObj.src = this.src;
		imgObj.style.width = iWidth+'px';
		imgObj.style.height = iHeight+'px';
	};

	nImg.src = imgURI;
	imgObj.style.display = "inline";
	imgObj.style.visibility = "visible";
}

function updateProfileForm() {
	var frm = d('profilef2');
	if (frm) formPOST(frm);
}

function notImplemented() {
	errorMessage("This feature is not implemented yet!", 'JS-1001');
	return false;
}

function showInfoPage(page) {
	if (myWorkplace.obj == null) {
		window.location.href = "session.jsp?act="+page;
	} else {
		myWorkplace.showPage(page);
	}
	
}

function showAbout(part) {
	myWorkplace.setSubCategory("about");
	myWorkplace.addContentArgsObj(part,'about_workarea',null);
	return false;
}

function isDaySavingTime() {
	var tObject = new Date();
	return (((tObject.getTimezoneOffset()/60)*(-1)) != getStandardTimezoneOffset(tObject)) ? 1 : 0;
}

function getTimezoneOffset() {
	var now = new Date();
	var timeDiff = (now.getTimezoneOffset()/60)*(-1);
	return timeDiff;
}

function getStandardTimezoneOffset() {
	var now = new Date();
	var date1 = new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0);
	var temp = date1.toGMTString();
	var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
	var timeDiff = parseInt(hoursDiffStdTime,10);
	return timeDiff;
}

function getTimeZoneMask(timeDiff) {
	if (isNaN(timeDiff)) return timeDiff;
	var tMask = (timeDiff < 0) ? "-" : "+";
	var tmpLen = Math.abs(timeDiff).toString().length;
	if (Math.abs(timeDiff) > 0 && Math.abs(timeDiff) < 1) {
		tMask += "00" + (Math.abs(timeDiff) * 100);
	} else if (tmpLen > 0 && tmpLen < 4) {
		tMask += "0" + (Math.abs(timeDiff) * 100);
	} else if (tmpLen == 4) {
		tMask += (Math.abs(timeDiff) * 100);
	}
	return tMask;
}

function DSTdates(){
	this.startDate;
	this.endDate;
	this.start;
	this.end;
	
    this.init = function() {
        var now = new Date();
        var febFirst= new Date(now.getFullYear(), 1, 1, 0, 0, 0, 0); 	//start Feb first
        var nHoursInYear = (365 * 24);
		var nStandardGMToffset = getStandardTimezoneOffset();
        var bDSTstartDateFound = false;
        for(var i=0;i<nHoursInYear;i++){ 				
            var dSampleDate = new Date(febFirst); 	
            dSampleDate.setHours(i);
			var cSampleTemp = dSampleDate.toGMTString();            
            var dSampleDateGMT = new Date(cSampleTemp.substring(0,cSampleTemp.lastIndexOf(" ")-1));
            var nCurrentGMToffset = (dSampleDate.getTimezoneOffset()/60)*(-1);
            if(nCurrentGMToffset != nStandardGMToffset && !bDSTstartDateFound) { 
                this.startDate = dSampleDate.getFullYear()+"-"+sInt(dSampleDate.getMonth()+1)+"-"+sInt(dSampleDate.getDate())+" "+sInt(dSampleDate.getHours()-1)+":00:00.0";
                this.start = dSampleDate.getMonth()*1000000+dSampleDate.getDate()*10000+(dSampleDate.getHours()-1)*100;
                nStandardGMToffset = nCurrentGMToffset; 
                bDSTstartDateFound = true; 
                continue;
            }else if(nCurrentGMToffset != nStandardGMToffset){ 
                this.endDate = dSampleDate.getFullYear()+"-"+sInt(dSampleDate.getMonth()+1)+"-"+sInt(dSampleDate.getDate())+" "+sInt(dSampleDate.getHours()+1)+":00:00.0";
                this.end = dSampleDate.getMonth()*1000000+dSampleDate.getDate()*10000+(dSampleDate.getHours()+1)*100;
                break;
            }
        }
        return bDSTstartDateFound;
	};
}

function d(a) {
	var dd = (document.getElementById) ? document.getElementById(a) : (document.all) ? document.all[a] : eval('document.'+a);
	return dd;
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function sInt(val) {
	if(val<10) {
		return '0'+val;
	} else {
		return val;
	}
}

function errorMessageDIV(errdesc, objID) {
	var errorBox = d(objID);
	if (errorBox) {
		errorBox.innerHTML = errdesc;
		setTimeout("d(\""+objID+"\").innerHTML=\"&nbsp;\";", 5000);
	}
}

function showPreLaunchBox(divObj) {
	var Y = 160;
	grayOut(true); 
	scrXY = getScrollXY();
	divObj.style.left = "50%";
	divObj.style.top  = (scrXY[1]+Y)+'px';
	divObj.style.marginLeft = "-" + parseInt(divObj.offsetWidth / 2, 10) + "px";
	divObj.style.visibility='visible'; 
	actionTrigger();	
}

function errorMessage(errdesc, errcode) {
	var Y = 200;
	var errorBox = d("errMessage");
	if (errorBox) {
		scrXY = getScrollXY();
		errorBox.getElementsByTagName("div")[0].innerHTML = "Error Message: " + errcode;
		errorBox.getElementsByTagName("p")[0].innerHTML = errdesc;
		errorBox.style.left = "50%";
		errorBox.style.top  = (scrXY[1]+Y)+'px';
		errorBox.style.marginLeft = "-" + parseInt(errorBox.offsetWidth / 2, 10) + "px";
		errorBox.style.visibility = "visible";
		setTimeout("d(\"errMessage\").style.visibility=\"hidden\";", 5000);
	}
}

function errorMessageExtended(errdesc, errcode, errcode_extended) {
	var errorBox = d("errMessage");
	var code = errcode;
	if(errcode_extended != "") { code += "-" + errcode_extended.substring(0, errcode_extended.length-1 ) ; }
	if (errorBox) {
		errorBox.getElementsByTagName("div")[0].innerHTML = "Error Message: " + code;
		errorBox.getElementsByTagName("p")[0].innerHTML = errdesc;
		errorBox.style.left = "50%";
		errorBox.style.marginLeft = "-" + parseInt(errorBox.offsetWidth / 2, 10) + "px";
		errorBox.style.visibility = "visible";
		setTimeout("d(\"errMessage\").style.visibility=\"hidden\";", 5000);
	}
}

function grep(str) {
	 var ar = new Array();
	 var arSub = 0;
	 for (var i in this) {
		 if (typeof(this[i]) != "function" && parseInt(this[i].indexOf(str),10) != -1) {
			ar[arSub] = this[i];
			arSub++;
		 }
	 }
	 return ar;
}

function key(xVar) {
	var arSub = 0;
	for (var i in this) {
		if (typeof(this[i]) != "function" && this[i] == xVar) {
			return true;
	 	}
 	}
 	return false;
}

function dec2bin(dec) {
	var hit = "";
	for(j=dec;j>=1;j=j/2){
		hit += parseInt(j%2,10);
	}
	return hit;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function change_invite_status(invite_id, status) {
	if (document.getElementsByName) {
		var st = document.getElementsByName(invite_id);
		if (st) {
			var isArray = (typeof(st.length) == "undefined") ? false : (st.length > 0) ? true : false;
			var maxItem = (typeof(st.length) == "undefined") ? 1 : (st.length > 0) ? st.length : 1;
			var delivery_status = (status == "1") ? "checked" : "unchecked";
			var delivery_title = (status == "1") ? "Invitation Sent" : "Delivery Not Confirmed";
			for (i=0; i<maxItem; i++) {
				var obj = (isArray) ? st[i] : st;
				obj.innerHTML="<img src='"+rootImg+"/icon/"+delivery_status+".gif' title='"+delivery_title+"'>&nbsp;&nbsp;<i>"+delivery_title+"</i>";
			}
		}
	}
}

function change_user_presence_status_text(user_id, status) {
	if (!d('P'+user_id)) return;
	if (document.getElementsByName) {
		var st = document.getElementsByName('P'+user_id);
		if (st) {
			var isArray = (typeof(st.length) == "undefined") ? false : (st.length > 0) ? true : false;
			var maxItem = (typeof(st.length) == "undefined") ? 1 : (st.length > 0) ? st.length : 1;
			var presence_status = (status == "1") ? "online" : "offline";
			for (i=0; i<maxItem; i++) {
				var obj = (isArray) ? st[i] : st;
				if (obj) {
					var child = obj.childNodes[0];
					if (child.tagName.toUpperCase() == "A") {
						child.className = "c_"+presence_status;
					}
				}
			}
		}
	}
}

function change_user_precence_status(user_id, relation, status) {
	if (!d('U'+user_id)) return;
	if (document.getElementsByName) {
		var st = document.getElementsByName('U'+user_id);
		if (st) {
			var isArray = (typeof(st.length) == "undefined") ? false : (st.length > 0) ? true : false;
			var maxItem = (typeof(st.length) == "undefined") ? 1 : (st.length > 0) ? st.length : 1;
			var presence_status = (status == "1") ? "online" : "offline";
			for (i=0; i<maxItem; i++) {
				var obj = (isArray) ? st[i] : st;
				if (typeof(obj.innerHTML) != "undefined") {
					var imgObj = obj.getElementsByTagName("img");
					if (imgObj) {
						for (k=0;k<imgObj.length; k++) {
							var imageSource = imgObj[k].src;

							if(imageSource.indexOf("avatar") > 0) {
								if (relation == avatar_relative) {
									var ext = (imgObj[k].className.indexOf("_small") > 1) ? "_small" : "";
									imgObj[k].className = presence_status+ext;
									imgObj[k].title = presence_status;
									change_user_presence_status_text(user_id, status);
								}
							} else {
								imageSource = (status == "1") ? imageSource.replaceAll("offline",presence_status) : imageSource.replaceAll("online",presence_status);
								if (imageSource.indexOf("?")>0) imageSource = imageSource.substring(0,imageSource.indexOf("?"));
						        var now = "upid=" + new Date().getTime();
								imgObj[k].src = imageSource + "?"+now; 
								imgObj[k].title = presence_status;
							}
						}
					}
				}
			}
		}
	}
}

function showDIVBox(boxWidth,boxHeight,TopPosition,LeftPosition,content,subcategory) {
	showDIVBoxArgs(boxWidth,boxHeight,TopPosition,LeftPosition,content,subcategory,null);
}

function showDIVBoxArgs(boxWidth,boxHeight,TopPosition,LeftPosition,content,subcategory,param) {
	var launcherNode = 'node_launcher';
	var lobj=d(launcherNode);
	if (!lobj) {
		lobj = document.createElement("DIV");
		lobj.setAttribute("id", launcherNode);
		lobj.setAttribute("name", launcherNode);
		lobj.onmouseover = function () { this.onmousedown = dragIsDown; };
		lobj.ondragstart = function () { return false; };
		lobj.onselectstart = function () { return false;	};
		
		if (navigator.userAgent.indexOf("MSIE 9.0")>0) {
			document.documentElement.appendChild(lobj);
		} else {
			document.body.appendChild(lobj);
		}
	}
	if (lobj) {
		lobj.innerHTML = "&nbsp;";
		var wide = window.screen.availWidth;
		var high = window.screen.availHeight;
		if( typeof( window.innerWidth ) == 'number' ) { LeftPosition = parseInt((window.innerWidth-boxWidth)/2); }
		lobj.style.position = 'absolute';
		lobj.style.height = boxHeight+"px";
		lobj.style.width = boxWidth+"px";
		lobj.style.top = TopPosition+"px";
		lobj.style.left = LeftPosition+"px";
		lobj.style.background = "url("+rootImg+"/message/bg_whitedot.gif)";
		lobj.style.visibility='visible';
		lobj.style.zIndex = "20";
		subcategory = (subcategory == null) ? "" : subcategory;
		myWorkplace.setSubCategory(subcategory);
		myWorkplace.addContentArgsObj(content,launcherNode,param);
	}
}

function download() {
	window.location.href = "install/BradonParticipantSetup.exe";
}

function reloadWidgetContent(id, cnt) {
	var showContent = false;
	var contentTag = "widget"+id+"_content";
	var wContent = d(contentTag);
	var wHref = d("widget"+id+"_href");
	var wIcon = d("widget"+id+"_icon");
	var localWorkplace = new workplace();
	localWorkplace.init();
	localWorkplace.addContentArgsObj("widget",contentTag,"&cnt="+cnt);
	if (wHref) wHref.innerHTML = "hide";
	if (wIcon) {
		wIcon.src = wIcon.src.replace("plus","minus");
		wIcon.title = "hide";
	}
	wContent.style.display = "inline";
	wContent.style.display = "block";
}

function widgetAction(id, cnt) {
	var showContent = false;
	var contentTag = "widget"+id+"_content";
	var wContent = d(contentTag);
	var wHref = d("widget"+id+"_href");
	var wIcon = d("widget"+id+"_icon");
	showContent = (wIcon) ? (wIcon.title == "show") : (wHref) ? (wHref.innerHTML == "show") : false;
	if (wContent) {
		if (showContent) {
			var localWorkplace = new workplace();
			localWorkplace.init();
			localWorkplace.addContentArgsObj("widget",contentTag,"&cnt="+cnt);
			if (wHref) wHref.innerHTML = "hide";
			if (wIcon) {
				wIcon.src = wIcon.src.replace("plus","minus");
				wIcon.title = "hide";
			}
			wContent.style.display = "inline";
			wContent.style.display = "block";
		} else {
			wContent.innerHTML = "";
			wContent.style.display = "none";
			if (wHref) wHref.innerHTML = "show";
			if (wIcon) { 
				wIcon.src = wIcon.src.replace("minus","plus");
				wIcon.title = "show";
			}
		}
	}
}

function saveWidgetStatus(widget_id, flag) {
	var status = (flag) ? 1 : 0;
	myWorkplace.addContentArgsObj('update_wstatus','launcher','&widget_id='+widget_id+'&status='+status);
}

var restoreWorkplaceCounter = 0;
function restoreWorkplace(p) {
	myWorkplace = new workplace();
	myWorkplace.init();
	if (myWorkplace.obj == null) {
		restoreWorkplaceCounter++;
		if (restoreWorkplaceCounter < 20) {
			setTimeout("restoreWorkplace('"+p+"');",300);
		} else {
			restoreWorkplaceCounter = 0;
		}
	} else {
		restoreWorkplaceCounter = 0;
		myWorkplace.showPage(p);
	}
}

function joinEvent() {
	var frm = d('eventLauncher');
	if (frm) {
		formPOST(frm);
	}
}

function registerPublicEvent() {
	var frm = d('eventRegister');
	if (frm) {
		formPOST(frm);
	}
}

function onOnetimerStart() {
	var ot = d('onetimer');
	if (ot) {
		parent.setTimeout( new function() {
			if(d('onetimer')) d('onetimer').style.visibility='hidden'; 
			grayOut(false);
		}, 2000);
	}
	parent.setTimeout('actionTrigger();',1000);	
}

function showPhoneInfo() {
	var participantNickName = "";
	var nn = d('nickname');
	if (nn) {
		if (nn.value.length > 0) {
			participantNickName = nn.value;
		}
	}
	myWorkplace.addContentArgs('event_advanced_5','&nickname='+participantNickName);
}

function grayOut(flag) {
    var pageWidth='100%';
    var pageHeight='100%';
	var grayOutObj=document.getElementById('grayOutScrObj');
	if (!grayOutObj && flag) {
		
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			pageWidth = document.body.scrollWidth+'px';
			pageHeight = (document.body.scrollHeight+200)+'px';
	    } else if( document.body.offsetWidth ) {
	    	pageWidth = document.body.offsetWidth+'px';
	    	pageHeight = (document.body.offsetHeight+200)+'px';
	    }
		var tnode = document.createElement('img');
		tnode.src=rootImg+"/blackdot.gif";
		tnode.id='grayOutScrObj';
		tnode.className = "grayOut";
		tnode.style.width= pageWidth;
		tnode.style.height= pageHeight;

		if (navigator.userAgent.indexOf("MSIE 9.0")>0) {
			document.documentElement.appendChild(tnode);
		} else {
			document.body.appendChild(tnode);
		}
		
	} else if (grayOutObj && !flag) {
		if (navigator.userAgent.indexOf("MSIE 9.0")>0) {
			document.documentElement.removeChild(grayOutObj);
		} else {
			document.body.removeChild(grayOutObj);
		}
	}
}

function initLauncher() {
	var lobj = document.createElement("DIV");
	lobj.setAttribute("id", launcherObjName);
	lobj.setAttribute("name", launcherObjName);
	lobj.style.position = 'absolute';
	lobj.style.height = "1px";
	lobj.style.width = "1px";
	lobj.style.top = "1px";
	lobj.style.left = "1px";
	lobj.style.visibility='hidden';
	if (navigator.userAgent.indexOf("MSIE 9.0")>0) {
		document.documentElement.appendChild(lobj);
	} else {
		document.body.appendChild(lobj);
	}
}

function warningSkypeAddOn() {
	poolTimerAllowed = false;
	var wrnObj = "skype_add_on_warning_message";
	var lobj = document.createElement("DIV");
	lobj.setAttribute("id", wrnObj);
	lobj.setAttribute("name", wrnObj);
	lobj.className = "skypeAddOnMessage";
	lobj.style.width= "500px";
	lobj.style.height= "240px";
	lobj.style.left = (parseInt(document.body.clientWidth/2, 10) - 250) + "px";
	if (navigator.userAgent.indexOf("MSIE 9.0")>0) {
		document.documentElement.appendChild(lobj);
	} else {
		document.body.appendChild(lobj);
	}
	myWorkplace.addContentArgsObj('message_skype', wrnObj, null);
}


function checkSkypeAddOn() {
	var browser = navigator.userAgent.toUpperCase();
	if(browser.indexOf("FIREFOX") > 0) {
		window.setTimeout(function() {
			var spanEl = document.getElementsByTagName("span");
			if (spanEl) {
				if (spanEl.length > 0) {
					for (i=0; i<spanEl.length; i++) {
						if(spanEl[i].className == 'skype_pnh_print_container') {
							grayOut(true);
							warningSkypeAddOn();
							break;
						}
					}
				}
			}
		},2000);
	}
}


function onLoadWindow() {
	myWorkplace = new workplace();
	myWorkplace.init();
	checkSkypeAddOn();
	
	if (typeof(initLauncher) == 'function') { initLauncher(); }
	if (typeof(initParticipant) == 'function') { initParticipant(); }
	if (typeof(initHost) == 'function') { initHost(); }
	if (typeof(initZoneAdmin) == 'function') { initZoneAdmin(); }
	if (typeof(soundManagerInit)== 'function') { soundManagerInit(); }

}


Array.prototype.grep = grep;
Array.prototype.keyExist = key;
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); };
//String.prototype.replaceAll = function(find, replace) { return this.replace(/find/g,replace); };
String.prototype.replaceAll = function(s1, s2) {return this.replace(new RegExp(s1,"g"), s2);};

window.onload = onLoadWindow;

