<!--
String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

function chatMsgSend(e, chatId){
	var keynum
	var keychar
	var numcheck
	
	if(window.event){ // IE
		keynum = e.keyCode
	}else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which
	}
	//alert(keynum);
	var boxID = document.getElementById("message_input_" + chatId);
	var msg = boxID.value;
	
	countStringLength(msg, 300);
	if(keynum == 13){	
		boxID.value = "";
		if(countStringLength(msg, 300)){
			msg = msg.replace(/[\s]+$/, "");
			msg = msg.trim();
			if(msg == ""){ // if blank entered
				return;
			}
			msgDiv = document.getElementById("my_message_" + chatId);
			msg = msg.replace(/</i, "&lt;");
			msgDiv.innerHTML = msgDiv.innerHTML + "<B>me : </B>" + msg + "<BR>";
			msgDiv.scrollTop = msgDiv.scrollHeight;
			var x = new runAjax(urlCircular + '?action=msgSend&msgTo='+ chatId +'&message='+ msg +'&tmpId=' +Math.random(), 'im_msg_send');
			return false;
		}
	}

	keychar = String.fromCharCode(keynum)
	//numcheck = /\d/
	//return !numcheck.test(keychar)
	return keychar;
}

function countStringLength(str, limit){
	strCount = str.split("");
	if(strCount.length > limit){
		alert('Message is over ' + limit + ' characters');
		return false;
	}
	return true;
}

function toggleMaxMin(chatId){
	var divName1 = "wrapper_" + chatId;
	var divId1 = document.getElementById(divName1);
	var maxMinMoleId = document.getElementById("maxMinMole_" + chatId);
	if(divId1.style.display == "block" || divId1.style.display == ""){
		divId1.style.display = "none";
		maxMinMoleId.src = urlBase + "/images/maximize_mole.gif";
		maxMinMoleId.alt = "Maximize";
		maxMinMoleId.title = "Maximize";
	}else{
		divId1.style.display = "block";
		maxMinMoleId.src = urlBase + "/images/minimize_mole.gif";
		maxMinMoleId.alt = "Minimize";
		maxMinMoleId.title = "Minimize";
		msgDiv = document.getElementById("my_message_" + chatId);
		msgDiv.scrollTop = msgDiv.scrollHeight;
		msgInputDiv = document.getElementById("message_input_" + chatId);
		msgInputDiv.focus();
	}
	var chatTitleDiv = document.getElementById("chatTitle_" + chatId);
	chatTitleDiv.style.backgroundColor = "#73A6FF";
	var moleCloseDiv = document.getElementById("closeMole_" + chatId);
	moleCloseDiv.src = urlBase + "/images/close_mole.gif";
	return false;
}

function closeThisChat(id){
	var closeId = document.getElementById("chatMaster_" + id);
	closeId.style.display = "none";
	return false;
}

function changeCursor(id){
	var titleId = document.getElementById("chatTitle_" + id);
	titleId.style.cursor = "move";
}

var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e){
	if (isdrag){
		dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
		dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
		//return false;
	}
}

function selectmouse(e){
	var fobj       = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";

	//alert(fobj.nodeName);
	var tmp = fobj.id;
	tmp = tmp.split("_");
	if(tmp.length > 2){
		return;
	}
	while (fobj.tagName != topelement && fobj.className != "dragme"){
		fobj = nn6 ? fobj.parentNode : fobj.parentElement;
	}
	if (fobj.className=="dragme"){
		isdrag = true;
		dobj = fobj;
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		x = nn6 ? e.clientX : event.clientX;
		y = nn6 ? e.clientY : event.clientY;
		document.onmousemove=movemouse;
		//return false;
	}
}


function chatWindow(id, /* optional */ memberName, /* optional */ msg, /* optional */ msgId) {		
	var divId = document.getElementById("chatMaster_" + id);
	if(divId == null){	
		createChatWindow(id);
	}else{
		divId.style.display = "block";
		var moleDiv = document.getElementById("maxMinMole_" + id);
		var moleStatus = moleDiv.getAttribute("alt");
		if(moleStatus == "Maximize"){
			moleDiv.src = urlBase + "/images/maximize_mole_orange.gif";
			var moleCloseDiv = document.getElementById("closeMole_" + id);
			moleCloseDiv.src = urlBase + "/images/close_mole_orange.gif";
			var chatTitleDiv = document.getElementById("chatTitle_" + id);
			chatTitleDiv.style.backgroundColor = "#FF8E5D";
		}else{ // get focus on window if not minimized.
			window.focus();
			window.innerWidth = screen.width;
			window.innerHeight = screen.height;
			window.screenX = 0;
			window.screenY = 0;			
		}
	}
	if(msg != undefined){
		msgDiv = document.getElementById("my_message_" + id);
		msgDiv.innerHTML = msgDiv.innerHTML + msg + "<br>";
		msgDiv.scrollTop = msgDiv.scrollHeight;
	}
	if(memberName != null){
		var chatTitleTxt = document.getElementById("chatTitleTxt_" + id);
		chatTitleTxt.innerHTML = "Talk with " + memberName;
	}	
	var msgInputDiv = document.getElementById("message_input_" + id);
	if(msgInputDiv != null){
		msgInputDiv.focus();
	}

	if(msgId != "" && msgId != null){		
		var y = new runAjax(urlCircular + '?action=flushmsg&msgId='+ msgId +'&tmpId=' +Math.random(), 'flushmsg');
	}
}

function createChatWindow(id){
	/*
	var chatWindowDiv = document.getElementById("chatWindow");
	if(chatWindowDiv == null){
		alert('chat window not found');
		return;
	}
	*/
	var masterDiv = document.createElement('DIV');
	masterDiv.setAttribute("id", "chatMaster_" + id);
	masterDiv.style.width = "420px";
	masterDiv.style.height = "300px";
	masterDiv.style.display = "block";
	masterDiv.style.position = "absolute";
	masterDiv.setAttribute("className", "dragme");
	masterDiv.setAttribute("class", "dragme");
	var chatTitleDiv = document.createElement('DIV');
	chatTitleDiv.setAttribute("id", "chatTitle_" + id);
	chatTitleDiv.style.backgroundColor = "#73A6FF";
	chatTitleDiv.style.height = "18px";
	chatTitleDiv.setAttribute("onMouseOver", "changeCursor('" + id + "')");
	chatTitleDiv.onmouseover = function changeCursorx() { var titleId = document.getElementById("chatTitle_" + id);	titleId.style.cursor = "move";};
	var chatTitleTxtDiv = document.createElement('DIV');
	chatTitleTxtDiv.setAttribute("id", "chatTitleTxt_" + id);
	chatTitleTxtDiv.setAttribute("class", "simple_text");
	chatTitleTxtDiv.setAttribute("className", "simple_text");
	chatTitleTxtDiv.style.position = "absolute";
	chatTitleTxtDiv.style.paddingLeft = "5px";
	chatTitleTxtDiv.style.paddingTop = "3px";
	chatTitleTxtDiv.style.fontWeight = "bold";
	chatTitleTxtDiv.style.color = "#FFFFFF";
	chatTitleTxtDiv.innerHTML = "Talk with Sushma Rajkarnikar";
	chatTitleDiv.appendChild(chatTitleTxtDiv);
	var mmMoleDiv = document.createElement('DIV');
	mmMoleDiv.setAttribute("align", "right");
	mmMoleDiv.innerHTML = '<a href="#" onClick="return toggleMaxMin(' + id + ');"><img id="maxMinMole_' + id + '" alt="Minimize" title="Minimize" src="' + urlBase + '/images/minimize_mole.gif" width="15" height="15" border="0"></a><a href="#" onClick="return closeThisChat('+ id +');"><img id="closeMole_'+ id +'" src="' + urlBase + '/images/close_mole.gif" width="15" height="15" border="0" alt="Close" title="Close"></a>';
	chatTitleDiv.appendChild(mmMoleDiv);
	masterDiv.appendChild(chatTitleDiv);
	
	var chatWrapperDiv = document.createElement('DIV');
	chatWrapperDiv.setAttribute("id", "wrapper_" + id);
	chatWrapperDiv.setAttribute("class", "chatWrapper");
	chatWrapperDiv.setAttribute("className", "chatWrapper");
	
		var chatMyMessageDiv = document.createElement('DIV');
		chatMyMessageDiv.setAttribute("id", "my_message_" + id);
		chatMyMessageDiv.setAttribute("class", "chatMyMessage");
		chatMyMessageDiv.setAttribute("className", "chatMyMessage");		
		chatWrapperDiv.appendChild(chatMyMessageDiv);
		
		var chatPhoto = document.createElement('IMG');
		chatPhoto.src = urlBase + '/images/md_' + id + '_1.jpg';
		chatPhoto.height = 180;
		chatPhoto.width = 150;
		chatPhoto.setAttribute("class", "chatPhoto");
		chatPhoto.setAttribute("className", "chatPhoto");
		chatWrapperDiv.appendChild(chatPhoto);
		
		var chatBlockUnblockDiv = document.createElement('DIV');
		chatBlockUnblockDiv.setAttribute("class", "chatBlockUnblock");
		chatBlockUnblockDiv.setAttribute("className", "chatBlockUnblock");
		chatBlockUnblockDiv.innerHTML = '<img id="block_unblock" alt="Block" title="Block" src="' + urlBase + '/images/im_block.gif" width="150" height="30" onClick="toggleBlockUnblock(' + id + ', null);">';
		chatWrapperDiv.appendChild(chatBlockUnblockDiv);
		
		var chatMsgInputDiv = document.createElement('DIV');
		chatMsgInputDiv.setAttribute("align", "center");
		chatMsgInputDiv.innerHTML = '<textarea class="chatMsgInput" rows="2" id="message_input_'+ id +'" onKeyPress="return chatMsgSend(event, '+ id +');"></textarea>';
		chatWrapperDiv.appendChild(chatMsgInputDiv);
	
	masterDiv.appendChild(chatWrapperDiv);
	
	if(document.body){
		document.body.appendChild(masterDiv);
	}else{
		document.documentElement.appendChild(masterDiv);
	}		
	var positionIt = positionWindow();	
	masterDiv.style["top"] = positionIt.y; 
	masterDiv.style["left"] = "200px";	
	masterDiv.style.zIndex = "500";
}


document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");

function toggleBlockUnblock(membId, status){
	var blockUnblockDiv = document.getElementById("block_unblock");	
	if(status == null){		
		if(blockUnblockDiv.getAttribute("alt") == "Block"){
			status = 1;
		}else{
			status = 0;
		}
	}	
	var y = new runAjax(urlCircular + '?action=blockUnblock&membId='+ membId +'&status='+ status +'&tmpId=' +Math.random(), 'blockUnblock');
	if(status == 0){
		blockUnblockDiv.src = urlBase + "/images/im_block.gif";
		blockUnblockDiv.setAttribute("alt", "Block");
		blockUnblockDiv.setAttribute("title", "Block");
	}else{
		blockUnblockDiv.src = urlBase + "/images/im_unblock.gif";
		blockUnblockDiv.setAttribute("alt", "Unblock");
		blockUnblockDiv.setAttribute("title", "Unblock");
	}
}

function positionWindow()
{
	var topY = 200;
	var winwidth = 200;
	var winheight = 200;
	
	if (document.compatMode && document.compatMode != "BackCompat"){
		var winwidth = document.documentElement.clientWidth;
		var winheight = document.documentElement.clientHeight;
	}else{
		var winwidth = document.body.clientWidth;
		var winheight = document.body.clientHeight;
	}	

	if (document.documentElement && document.documentElement.scrollTop){
		topY=document.documentElement.scrollTop;
	}else {
		topY=document.body.scrollTop;
	}

	if(topY<200){
		var top=200;
	}else{
		var top=topY+50;
	}

	if(winwidth>800){
		var left=300;
	}else{
		var left=20;
	}
		
	return {x:left, y:top};
}

//-->// JavaScript Document