var windowFocus=1;
var windowTitle="";
var winHeight;
var winWidth;
window.onblur=setWindowBlur;
window.onfocus=setWindowFocus;
function setWindowBlur(){
windowFocus=0;
}
function setWindowFocus(){
windowFocus=1;
}
function jojo(){
alert(windowFocus);
}
function sendData(friendId) {

	
	var message = document.getElementById("input_" + friendId).value;
	var currName = document.getElementById("displayName").value ;
	if(currName.length>15){
	currName=currName.substring(0,11)+"...";
	}
	currName = "<span id=\"current_Name_Font\" >" + currName + "</span>";
	//alert(currName);
	
	if (message != "") {
	if (document.getElementById("textArea_" + friendId).innerHTML == "") {
					document.getElementById("textArea_" + friendId).innerHTML = currName+":<span id=\"chat_date_font\">"+getClockTime()+"</span><br>"+insertSmileysToResponce(getNewLineString(message,15));
					document.getElementById("input_" + friendId).value = "";
					document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
				} else {
					document.getElementById("textArea_" + friendId).innerHTML = document.getElementById("textArea_" + friendId).innerHTML + "<br>" + currName+":<span id=\"chat_date_font\">"+getClockTime()+"</span><br>"+insertSmileysToResponce(getNewLineString(message,15));
					document.getElementById("input_" + friendId).value = "";
					document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
				}
				
				
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		var url = "chatConversation.do?message=" + message + "&friendId=" + friendId + "&currName=" + currName;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
			//alert(xmlHttp.responseText);
			
					
				
			}
		};
		xmlHttp.send(null);
	}
	return false;////for not submitting the form
}
function clear(friendId) {
//////************************************************  AJAX Starts *************************************************///////
//alert("in");
	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "ajaxChat.do?messageStatus=clearHistory&friendId=" + friendId;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			document.getElementById("textArea_" + friendId).innerHTML = "";
		}
	};
	xmlHttp.send(null);
		//////************************************************  AJAX Ends *************************************************///////
}
function getOnlineFriends() {
	if (document.getElementById("onLineFriendWindow").className == "firstNameList_visible") {
		document.getElementById("onLineFriendWindow").className = "firstNameList_nonvisible";
	} else {
	if (document.getElementById("notificationsDivContainer").className == "firstNameList_visible") {
		document.getElementById("notificationsDivContainer").className = "firstNameList_nonvisible";
		}
		document.getElementById("onLineFriendWindow").className = "firstNameList_visible";
		getOnLineBuddies();
		
	}
	
	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "ajaxSaveChatSession.do?type=gettingOnlineFriends&onLineFriendsWindowsClass=" + document.getElementById("onLineFriendWindow").className;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
		}
	};
	xmlHttp.send(null);
}
var totalChatWindows = 0;
var rightChatWindowsIndex = 0;
var leftChatWindowsIndex = 0;
var chatWindowsArray = [];
var chatCountArray=[];
var lastActive;
function openChatWindow(friendId,name) {


var src=document.getElementById("chatFriendImage_"+friendId).src;
var containerDiv = document.getElementById("chatWindowsList");



	//var divIdName = "div_" + divRef.id;
	//if (!document.getElementById(divIdName)) {

		//var picDiv = document.getElementById("pic_" + divRef.id).innerHTML;
		//var src = picDiv.substring(picDiv.indexOf("src=", 0) + 5, picDiv.indexOf("\"", picDiv.indexOf("src=", 0) + 5));
		
if(!document.getElementById("lowerDiv_"+friendId)){
		var workHtml;
		workHtml='<div id=\"lowerDiv_'+friendId+'\" style=\"float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div  id=\"lowerDiv_name_'+friendId+'\" name=\"lowerDiv_name_'+friendId+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\"  onclick=\"maximize(\''+friendId+'\');stopBlinking(\'lowerDiv_name_'+friendId+'\');\" >'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+friendId+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + friendId + "\" style=\"width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\" alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + friendId + "')\"></div>";
		
		//containerDiv.innerHTML = containerDiv.innerHTML + workHtml;
		//var upWindowContainer=document.getElementById("chatUpWindows");
		//var innerHTML;
		//innerHTML="";
		//alert(totalChatWindows);
		
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}
		
		
		
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(57)+"px;background-color:#111111;\">";
		workHtml = workHtml + "<div id=\"resultedPicDiv\" style=\"float:left;width:"+getResolutionWidth(45)+"px; \">";
		workHtml = workHtml + "<a href=\"profile.do?pid=" + friendId + "\"><img alt=\"\" src=\"" + src + "\" style=\"border:1px solid #2E2E2E;max-height: "+getResolutionHeight(170)+"px;\" width=\""+getResolutionWidth(35)+"\" border=\"0\"></a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div id=\"resultedNameDiv\" style=\"float:left;width:"+getResolutionWidth(130)+"px;height:"+getResolutionHeight(12)+"px;\"><a class=\"see_all\" style=\"font-size: "+getResolutionWidth(11)+"px;\" href=\"profile.do?pid=" + friendId + "\">" +name + "</a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" onclick=\"minmize(\'chatUpWindows_" +friendId+"\')\" src=\"images/Icons/minimizebutton.jpg\"  alt=\"-\" title=\"-\" ></div><div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + friendId + "')\"></div></div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(15)+"px;background-color:#222222;text-align:left;\"><a href=\"javascript:clear('" + friendId + "')\" class=\"see_all_chat\" style=\"font-size: "+getResolutionWidth(11)+"px;\" >Clear History</a></div>";
		workHtml = workHtml + "<div name=\"textArea_" + friendId + "\" id=\"textArea_" + friendId + "\" style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(158)+"px;overflow:auto;text-align:justify;color:#c1c1c1;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: "+getResolutionWidth(12)+"px;	border-bottom:"+getResolutionHeight(2)+"px solid #c1c1c1;\">";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(28)+"px;background-color:#111111;\">";
		
		workHtml = workHtml +"<div style=\"float:left;height:"+getResolutionHeight(26)+"px;width:"+getResolutionWidth(162)+"px;border-right:1px solid #FFFFFF;\">";
		workHtml = workHtml +"<form autocomplete=\"off\" style=\"margin-top:0px;margin-bottom:0px;width:"+getResolutionWidth(139)+"px;float:left;height:"+getResolutionHeight(27)+"px;\" name=\"form_" + friendId + "\" id=\"form_" + friendId + "\" onclick=\"stopBlinking(\'lowerDiv_name_"+friendId+"\');\" onsubmit=\"return sendData(\'"+friendId+"\')\">";
		workHtml = workHtml +"<input maxLength=1024 style=\"background-color:#111111;color:#c1c1c1;height:"+getResolutionHeight(22)+"px;width:"+getResolutionWidth(125)+"px;margin-top:"+getResolutionHeight(3)+"px;margin-bottom:"+getResolutionHeight(2)+"px;border: none;\" type=\"text\" id=\"input_" + friendId + "\" name=\"input_" + friendId + "\" >";
		workHtml = workHtml +"</form>";
		workHtml = workHtml +"<img border=0 alt=\"Emoticons\" title=\"Emoticons\" src=\"images/smileys/7th_smile.gif\" style=\"cursor:pointer;margin-top:"+getResolutionHeight(5)+"px;\" onclick=\"showChatSmileys(\'"+friendId+"\')\" width=\""+getResolutionWidth(17)+"\">";
		workHtml = workHtml +"</div>";
		workHtml = workHtml +"<div style=\"float:left;background-color:#000000;width:"+getResolutionWidth(52)+"px;height:"+getResolutionHeight(28)+"px;\"><img style=\"cursor:pointer;padding-top:"+getResolutionHeight(1)+"px;\" onclick=\"return sendData(\'"+friendId+"\')\"  border=0 width="+getResolutionWidth(49)+" src=\"images/Icons/chat-send.gif\"  alt=\"Send\" title=\"Send\"  ></div>";
		workHtml = workHtml +"<div id=\"chatSmileys_"+friendId+"\" style=\"position:relative;bottom:"+getResolutionHeight(630)+"%;left:0%;z-index:2;width:"+getResolutionWidth(90)+"%;height:"+getResolutionHeight(600)+"%;background-color:#FFFFFF;border:1px solid #00FF00;display:none;\"></div>";
		workHtml = workHtml +"</div>";
		workHtml = workHtml + "</div>";
		workHtml=workHtml+"</div></div>";
		
		
	
		

		if (document.getElementById(lastActive)) {
			minmize(lastActive);
		}
		lastActive = "chatUpWindows_" + friendId;
		
		
		
		

		chatWindowsArray[totalChatWindows] = friendId;
		chatCountArray[totalChatWindows]=0;
		leftChatWindowsIndex = totalChatWindows;
		var hasRightHidden;
		
		
		
		
		if (totalChatWindows >= 3) {
		//alert("1");
			rightChatWindowsIndex = totalChatWindows - 2;
			document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndex - 1]).style.display = "none";
			document.getElementById("right_but").className = "right_but_visible";
			hasRightHidden = chatWindowsArray[rightChatWindowsIndex - 1];
		}
		totalChatWindows = totalChatWindows + 1;

		//setWidthOfchatWindowsListContainer(totalChatWindows);
		//setTheLastThreeWindowsVisible();

		if (document.getElementById("left_but").className == "left_but_visible") {
			document.getElementById("left_but").className = "left_but_nonVisible";
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_641";
		}
		
		
		
		
		

		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		
		var onLineFriendsWindowsClass = document.getElementById("onLineFriendWindow").className;
		//var chatWindowsListContainer = document.getElementById("chatWindowsListContainer").className;
		///// ************************** presently i have fixed this to chatWindowsListContainer_675
		
		
		var url = "ajaxSaveChatSession.do?type=savingWindow&id=" + friendId + "&status=maximize&source=" + src + "&name=" + name;
		url = url + "&display=show";
		url = url + "&totalChatWindows=" + totalChatWindows + "&rightChatWindowsIndex=" + rightChatWindowsIndex + "&leftChatWindowsIndex=" + leftChatWindowsIndex + "&lastActive=" + lastActive;
		url = url + "&chatWindowsArray=" + chatWindowsArray;
		url = url + "&onLineFriendsWindowsClass=" + onLineFriendsWindowsClass; //+ "&chatWindowsListContainer=" + chatWindowsListContainer;
		url = url + "&left_but_class=" + document.getElementById("left_but").className + "&right_but_class=" + document.getElementById("right_but").className;
		if (hasRightHidden) {
			url = url + "&hasRightHidden=" + hasRightHidden;
		}
//alert(url);
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 //alert("sent");
			}
		};
		xmlHttp.send(null);
		containerDiv.innerHTML = containerDiv.innerHTML + workHtml;
		document.getElementById("input_" + friendId).focus();
		makeChatSmileys(friendId);
		get24HrMessages(friendId);		
		getOnlineFriends();/////hide the online friend window	
}
}


function rightNavigate() {
//alert(rightChatWindowsIndex);

	if (rightChatWindowsIndex != 0) {
		//document.getElementById("chatUpWindows_" + chatWindowsArray[rightChatWindowsIndex - 1]).style.display = "block";////no need of this coz in navigation we only show minimized
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		rightChatWindowsIndex = rightChatWindowsIndex - 1;
		leftChatWindowsIndex = leftChatWindowsIndex - 1;
		
		if (document.getElementById("left_but").className == "left_but_nonVisible") {
		
			document.getElementById("left_but").className = "left_but_visible";
			
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_675";
			///************************ no need of this
		}
		if (rightChatWindowsIndex == 0) {//////////////////********************************* here is where we will again do the setting
			document.getElementById("right_but").className = "right_but_nonVisible";
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_641";
			//////////**************** no need of this
		}
		
		
		
		///******************/////////////********************/////////////////***************
		
		
		//******************////////////*********************/////////////////***************
		
		
		
		var url = "ajaxSaveChatSession.do?type=rightNavigation&rightId=" + chatWindowsArray[rightChatWindowsIndex] + "&leftId=" + chatWindowsArray[leftChatWindowsIndex + 1];
		url = url + "&left_but_class=" + document.getElementById("left_but").className + "&right_but_class=" + document.getElementById("right_but").className;
		url = url + "&rightChatWindowsIndex="+rightChatWindowsIndex+"&leftChatWindowsIndex="+leftChatWindowsIndex;
		////url = url + "&chatWindowsListContainer=" + document.getElementById("chatWindowsListContainer").className;
		//////********************* no need of this
		//alert(url)
		
		
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 //alert("sent");
			}
		};
		xmlHttp.send(null);
		
		document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndex]).style.display = "block";
		document.getElementById("lowerDiv_" + chatWindowsArray[leftChatWindowsIndex+1]).style.display = "none";
		document.getElementById("chatUpWindows_" + chatWindowsArray[leftChatWindowsIndex+1]).style.display = "none";
		var fid=lastActive.substring(14,lastActive.length);
		setPosition(fid);
		document.getElementById('chatUpWindows_'+fid).style.display = "block";
		
		
		
	}
}
function leftNavigate() {

	if (leftChatWindowsIndex != totalChatWindows - 1) {
	var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		
		//////////////************* also check here wether this was originally in maximized form or not, if yes set its chatUpWindow to block
		
		
		leftChatWindowsIndex = leftChatWindowsIndex + 1;
		
		//////////////************* also check here wether this was originally in maximized form or not, if yes memorize it as block
		
		
		rightChatWindowsIndex = rightChatWindowsIndex + 1;
		if (document.getElementById("right_but").className == "right_but_nonVisible") {
			document.getElementById("right_but").className = "right_but_visible";
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_675";
			////********no need
		}
		if (leftChatWindowsIndex == totalChatWindows - 1) {
			document.getElementById("left_but").className = "left_but_nonVisible";
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_641";
			///**** no need
		}
		
		///******************/////////////********************/////////////////***************
		
	
		
		//******************////////////*********************/////////////////***************
		

		var url = "ajaxSaveChatSession.do?type=leftNavigation&rightId=" + chatWindowsArray[rightChatWindowsIndex - 1] + "&leftId=" + chatWindowsArray[leftChatWindowsIndex];
		url = url + "&left_but_class=" + document.getElementById("left_but").className + "&right_but_class=" + document.getElementById("right_but").className;
		url = url + "&rightChatWindowsIndex="+rightChatWindowsIndex+"&leftChatWindowsIndex="+leftChatWindowsIndex;
		//url = url + "&chatWindowsListContainer=" + document.getElementById("chatWindowsListContainer").className;
		///////    ****************************    no need
		//alert(url);
		
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 //alert("sent");
			}
		};
		xmlHttp.send(null);
		
		
		document.getElementById("lowerDiv_" + chatWindowsArray[leftChatWindowsIndex ]).style.display = "block";
		document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndex-1]).style.display = "none";
		var fid=lastActive.substring(14,lastActive.length);
		setPosition(fid);
		document.getElementById('chatUpWindows_'+fid).style.display = "block";
		
		
	}
}
function minmize(friendId) {
//alert(friendId.substring(14, friendId.length));
//alert(document.getElementById(friendId));
	//document.getElementById(divId).className = "upperDiv_nonVisible";
	//document.getElementById("div_" + divId.substring(9, divId.length)).style.border = "none";
	//document.getElementById("lowerDiv_" + divId.substring(9, divId.length)).className = "lowerDiv_minimize";
	

//////************************************************  AJAX Starts *************************************************///////
	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "ajaxSaveChatSession.do?type=minimizing&id=" + friendId.substring(14, friendId.length) + "&status=minimize";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
         																	 //alert("sent");
		}
	};
	xmlHttp.send(null);
	
document.getElementById(friendId).style.display="none";
document.getElementById("lowerClose_" + friendId.substring(14, friendId.length)).style.display = "block";	
		
		
		
		//////************************************************  AJAX Ends *************************************************///////
}
function maximize(friendId) {
	if (document.getElementById('chatUpWindows_'+friendId).style.display == "none") {
	
	
	
		//document.getElementById("div_" + divId.substring(9, divId.length)).style.height = "220px";
		//document.getElementById("div_" + divId.substring(9, divId.length)).style.border = "1px solid #575757";
		//document.getElementById("lowerDiv_" + divId.substring(9, divId.length)).className = "lowerDiv_first";
		
		//stopBlinking('lowerDiv_name_'+divId.substring(9, divId.length));////for name div
		
		
		
		//alert(lastActive);
		
		
		
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		if (lastActive != 'chatUpWindows_'+friendId) {/////minimize the previous window
			if (document.getElementById(lastActive)) {
				minmize(lastActive);
			}
			lastActive = 'chatUpWindows_'+friendId;
		}
		var url = "ajaxSaveChatSession.do?type=minimizing&id=" + friendId + "&status=maximize&lastActive="+lastActive;
		//alert(url);
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 
			}
		};
		xmlHttp.send(null);
	setPosition(friendId);
	document.getElementById('chatUpWindows_'+friendId).style.display = "block";	
	document.getElementById("input_" + friendId).focus();
	var currentIndex=findCurrentIndex(friendId);
	document.getElementById("redChatCount_"+friendId).innerHTML=0;
	document.getElementById("redChatCount_"+friendId).style.display="none";
	chatCountArray[currentIndex]=0;
	document.getElementById("lowerClose_" + friendId).style.display = "none";	
		
		
		
		
	}else{
	minmize('chatUpWindows_'+friendId);
	
	}
}
function closeChatWindow(friendId) {
	if (document.getElementById("lowerDiv_" + friendId)) {
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}		
////////activating the left or right chat window acoordingly
		totalChatWindows = totalChatWindows - 1;
		var rightChatWindowsIndexDummy = rightChatWindowsIndex - 1;
		var leftChatWindowsIndexDummy = leftChatWindowsIndex;
		
		chatWindowsArray = removeItemFromArray(chatWindowsArray, friendId);
		
		if (document.getElementById("lowerDiv_" + chatWindowsArray[leftChatWindowsIndexDummy])) {
			
			document.getElementById("lowerDiv_" + chatWindowsArray[leftChatWindowsIndexDummy]).style.display = "block";
			if (leftChatWindowsIndexDummy <= chatWindowsArray.length) {
				leftChatWindowsIndex = leftChatWindowsIndexDummy;
			}
		} else {
			if (document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndexDummy])) {
				
				document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndexDummy]).style.display = "block";
				
				if (rightChatWindowsIndexDummy >= 0) {
					rightChatWindowsIndex = rightChatWindowsIndexDummy;
					leftChatWindowsIndex = leftChatWindowsIndex - 1;
				}
			}
		}
		
		
		
		//setWidthOfchatWindowsListContainer(totalChatWindows);
		//**************   ********** ne need of this now
		
	
	
		
		if (totalChatWindows <= 3) {
			document.getElementById("right_but").className = "right_but_nonVisible";
			document.getElementById("left_but").className = "left_but_nonVisible";
		}
		var url = "ajaxSaveChatSession.do?type=close&id=" + friendId;

		url = url + "&totalChatWindows=" + totalChatWindows + "&rightChatWindowsIndex=" + rightChatWindowsIndex + "&leftChatWindowsIndex=" + leftChatWindowsIndex + "&lastActive=" + lastActive;

		url = url + "&chatWindowsArray=" + chatWindowsArray;

		url = url + "&onLineFriendsWindowsClass=" + document.getElementById("onLineFriendWindow").className;//******* no need of this + "&chatWindowsListContainer=" + document.getElementById("chatWindowsListContainer").className;

		url = url + "&left_but_class=" + document.getElementById("left_but").className + "&right_but_class=" + document.getElementById("right_but").className;

		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 
			}
		};
		xmlHttp.send(null);
		document.getElementById("chatWindowsList").removeChild(document.getElementById("lowerDiv_" + friendId));
		
		
		
		
		
	}
	var fid=lastActive.substring(14,lastActive.length);
	setPosition(fid);
	if (rightChatWindowsIndex == 0 && totalChatWindows == 0) {//if the first window is discarded.... now if it is again opened from frnd list it will never be minimized
		lastActive = null;
	}
	
}
function removeItemFromArray(chatWindowsArray, divId) {
	var newArray = [];
	var i = 0;
	var j = i;
	for (i = 0; i < chatWindowsArray.length; i++) {
		if (chatWindowsArray[i] == divId) {
		} else {
			newArray[j] = chatWindowsArray[i];
			j = j + 1;
		}
	}
	return newArray;
}


function hideOnLineFriendsWindow() {
	if (document.getElementById("onLineFriendWindow").className == "firstNameList_visible") {
		document.getElementById("onLineFriendWindow").className = "firstNameList_nonvisible";
		
		//////************************************************  AJAX Starts *************************************************///////
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		var url = "ajaxSaveChatSession.do?type=gettingOnlineFriends&onLineFriendsWindowsClass=" + document.getElementById("onLineFriendWindow").className;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
         																	 //alert("sent");
			}
		};
		xmlHttp.send(null);
		//////************************************************  AJAX Ends *************************************************///////
	}
}


function getGlobalSessionValues(totalChatWindowsFromSession, rightChatWindowsIndexFromSession, leftChatWindowsIndexFromSession, lastActiveFromSession) {


//alert(totalChatWindowsFromSession);
//alert(rightChatWindowsIndexFromSession);
//alert(leftChatWindowsIndexFromSession);
//alert(lastActiveFromSession);

	totalChatWindows = totalChatWindowsFromSession;
	rightChatWindowsIndex = rightChatWindowsIndexFromSession;
	leftChatWindowsIndex = leftChatWindowsIndexFromSession;
	lastActive = lastActiveFromSession;
}
function saveGloabalValuesToSession(xmlHttp) {
	var onLineFriendsWindowsClass = document.getElementById("onLineFriendWindow").className;
//alert(onLineFriendsWindowsClass);
	var chatWindowsListContainer = document.getElementById("chatWindowsListContainer").className;
//alert(chatWindowsListContainer);
	var url = "ajaxSaveChatSession.do?type=global&onLineFriendsWindowsClass=" + onLineFriendsWindowsClass + "&chatWindowsListContainer=" + chatWindowsListContainer;
	url = url + "&totalChatWindows=" + totalChatWindows + "&rightChatWindowsIndex=" + rightChatWindowsIndex + "&leftChatWindowsIndex=" + leftChatWindowsIndex + "&lastActive=" + lastActive;
	url = url + "&chatWindowsArray=" + chatWindowsArray;
		//alert(url);
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
				
				
				//alert("GlobalsSaved");
		}
	};
	xmlHttp.send(null);
}
function saveChatArray(index, element) {
//alert("index "+index+"    element "+element);
	chatWindowsArray[index] = element;
	chatCountArray[index]=0;
//alert('element Value='+chatWindowsArray[index]);
}
function createChatArrays(id, status, src, name, display) {

		//document.getElementById("textArea_" + id).scrollTop = document.getElementById("textArea_" + id).scrollHeight;



var containerDiv = document.getElementById("chatWindowsList");
if(!document.getElementById("lowerDiv_"+id)){


var style;
		if (display == "show") {
		
			if (status == "maximize") {
			
				workHtml='<div id=\"lowerDiv_'+id+'\" style=\"float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div  id=\"lowerDiv_name_'+id+'\" name=\"lowerDiv_name_'+id+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\"  onclick=\"maximize(\''+id+'\');stopBlinking(\'lowerDiv_name_'+id+'\');\">'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+id+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + id + "\" style=\"display:none;width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\"  alt=\"x\" title=\"x\"  alt=\"x\" title=\"x\"  alt=\"x\" title=\"x\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + id + "')\"></div>";
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}	
		setPosition(id);	
			} else {
			
				workHtml='<div id=\"lowerDiv_'+id+'\" style=\"float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div  id=\"lowerDiv_name_'+id+'\" name=\"lowerDiv_name_'+id+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\"  onclick=\"maximize(\''+id+'\');stopBlinking(\'lowerDiv_name_'+id+'\');\">'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+id+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + id + "\" style=\"width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + id + "')\"></div>";
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}	
			
			}
		} else {
		
			if (status == "maximize") {
			
				workHtml='<div id=\"lowerDiv_'+id+'\" style=\"display:none;float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div  id=\"lowerDiv_name_'+id+'\" name=\"lowerDiv_name_'+id+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\"  onclick=\"maximize(\''+id+'\');stopBlinking(\'lowerDiv_name_'+id+'\');\">'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+id+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + id + "\" style=\"display:none;width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + id + "')\"></div>";
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}
		setPosition(id);
			} else {
			
				workHtml='<div id=\"lowerDiv_'+id+'\" style=\"display:none;float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div  id=\"lowerDiv_name_'+id+'\" name=\"lowerDiv_name_'+id+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\"  onclick=\"maximize(\''+id+'\');stopBlinking(\'lowerDiv_name_'+id+'\');\">'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+id+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + id + "\" style=\"width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + id + "')\"></div>";
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+id+"\" style=\"display:none;position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}
			}
		}





		var workHtml;
		
		
		
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(57)+"px;background-color:#111111;\">";
		workHtml = workHtml + "<div id=\"resultedPicDiv\" style=\"float:left;width:"+getResolutionWidth(45)+"px; \">";
		workHtml = workHtml + "<a href=\"profile.do?pid=" + id + "\"><img alt=\"\" src=\"" + src + "\" style=\"border:1px solid #2E2E2E;max-height: "+getResolutionHeight(170)+"px;\" width=\""+getResolutionWidth(35)+"\" border=\"0\"></a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div id=\"resultedNameDiv\" style=\"float:left;width:"+getResolutionWidth(130)+"px;height:"+getResolutionHeight(12)+"px;\"><a class=\"see_all\" style=\"font-size: "+getResolutionWidth(11)+"px;\" href=\"profile.do?pid=" + id + "\">" +name + "</a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" onclick=\"minmize(\'chatUpWindows_" +id+"\')\" src=\"images/Icons/minimizebutton.jpg\"   alt=\"-\" title=\"-\" ></div><div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + id + "')\"></div></div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(15)+"px;background-color:#222222;text-align:left;\"><a href=\"javascript:clear('" + id + "')\" class=\"see_all_chat\" style=\"font-size: "+getResolutionWidth(11)+"px;\"  >Clear History</a></div>";
		workHtml = workHtml + "<div name=\"textArea_" + id + "\" id=\"textArea_" + id + "\" style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(158)+"px;overflow:auto;text-align:justify;color:#c1c1c1;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: "+getResolutionWidth(12)+"px;	border-bottom:"+getResolutionHeight(2)+"px solid #c1c1c1;\">";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(28)+"px;background-color:#111111;\">";
		
		workHtml = workHtml +"<div style=\"float:left;height:"+getResolutionHeight(26)+"px;width:"+getResolutionWidth(162)+"px;border-right:1px solid #FFFFFF;\">";
		workHtml = workHtml +"<form autocomplete=\"off\" style=\"margin-top:0px;margin-bottom:0px;width:"+getResolutionWidth(139)+"px;float:left;height:"+getResolutionHeight(27)+"px;\" name=\"form_" + id + "\" id=\"form_" + id + "\" onclick=\"stopBlinking(\'lowerDiv_name_"+id+"\');\" onsubmit=\"return sendData(\'"+id+"\')\">";
		workHtml = workHtml +"<input maxLength=1024 style=\"background-color:#111111;color:#c1c1c1;height:"+getResolutionHeight(22)+"px;width:"+getResolutionWidth(125)+"px;margin-top:"+getResolutionHeight(3)+"px;margin-bottom:2px;border: none;\" type=\"text\" id=\"input_" + id + "\" name=\"input_" + id + "\" >";
		workHtml = workHtml +"</form>";
		workHtml = workHtml +"<img border=0 alt=\"Emoticons\" title=\"Emoticons\" src=\"images/smileys/7th_smile.gif\" style=\"cursor:pointer;margin-top:"+getResolutionHeight(5)+"px;\" onclick=\"showChatSmileys(\'"+id+"\')\" width=\""+getResolutionWidth(17)+"\">";
		workHtml = workHtml +"</div>";
		workHtml = workHtml +"<div style=\"float:left;background-color:#000000;width:"+getResolutionWidth(52)+"px;height:"+getResolutionHeight(28)+"px;\"><img onclick=\"return sendData(\'"+id+"\')\"  border=0  style=\"cursor:pointer;padding-top:"+getResolutionHeight(1)+"px;\" width="+getResolutionWidth(49)+"  src=\"images/Icons/chat-send.gif\"  alt=\"Send\" title=\"Send\"  ></div>";
		workHtml = workHtml +"<div id=\"chatSmileys_"+id+"\" style=\"position:relative;bottom:"+getResolutionHeight(630)+"%;left:0%;z-index:2;width:"+getResolutionWidth(90)+"%;height:"+getResolutionHeight(600)+"%;background-color:#FFFFFF;border:1px solid #00FF00;display:none;\"></div>";
		workHtml = workHtml +"</div>";
		workHtml = workHtml + "</div>";
		workHtml=workHtml+"</div></div>";
		containerDiv.innerHTML = containerDiv.innerHTML + workHtml;
		if (status == "maximize") {
		setPosition(id);
		}
		if(browserName!="IE7"){
		document.getElementById("input_" + id).focus();
		}
		makeChatSmileys(id);
		get24HrMessages(id);
		document.getElementById("textArea_" + id).scrollTop = document.getElementById("textArea_" + id).scrollHeight;
}
}




function getChatMessages() {
	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "ajaxChat.do";
//alert(url);
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			if (!xmlHttp.responseText) {
			
			} else {
			
				var responceText = xmlHttp.responseText;
         																	//alert(responceText);
         		if(responceText.search("startOfLoop")!=-1){	
				responceText = responceText.substring(responceText.indexOf("startOfLoop", 0) + 13, responceText.indexOf("endOfLoop", 0) - 2);
         																	//alert("1");
				getFriendWindowsRecursively(responceText);
				//getChatMessages();//send again to the server		
			}
			}
		}
	};
	xmlHttp.send(null);
}
function getFriendWindowsRecursively(responceText) {
//alert("recursive");
	var idOfFriend = responceText.substring(responceText.indexOf("startOfFriend", 0) + 15, responceText.indexOf("idOfFriend", 0) - 2);
         																	//alert("start"+idOfFriend+"end");
	var src = responceText.substring(responceText.indexOf("idOfFriend", 0) + 12, responceText.indexOf("picsrc", 0) - 2);
         						//alert("src-----"+src);
	var name = responceText.substring(responceText.indexOf("picsrc", 0) + 8, responceText.indexOf("name", 0) - 2);
         						//alert("name-----"+name);
	var messages = responceText.substring(responceText.indexOf("chatMessagesStart", 0) + 19, responceText.indexOf("chatMessagesStop", 0) - 2);
         						//alert("messages-----"+messages);
	var chatCount=responceText.substring(responceText.indexOf("chatMessagesStop", 0) + 18, responceText.indexOf("sizeOfChats", 0) - 2);
	//alert(messages);
	//alert(chatCount);
	createReceiverChatWindow(src, name, idOfFriend, messages,chatCount);
         						//alert(responceText.indexOf("startOfFriend",0));
         						//alert(responceText.indexOf("endOfFriend",0));
	responceText = responceText.substring(responceText.indexOf("startOfFriend", 0) + 15 + responceText.indexOf("endOfFriend", 0) - 2, responceText.length);
         						//alert("123123"+responceText);
	if (responceText.length > 20) {
		getFriendWindowsRecursively(responceText);
	}
}
function createReceiverChatWindow(src, name, friendId, messages,chatCount) {
	//alert(name);
	chatCount=chatCount*1;
	var containerDiv = document.getElementById("chatWindowsList");
	if (messages != "") {
	messages=insertSmileysToResponce(messages);
		if(!document.getElementById("lowerDiv_"+friendId)){
		var workHtml;
		workHtml='<div id=\"lowerDiv_'+friendId+'\" style=\"float:right;width:'+getResolutionWidth(216)+'px;border: 1px solid #999999;background-color:#666666;\" ><div id=\"lowerDiv_name_'+friendId+'\" name=\"lowerDiv_name_'+friendId+'\" style=\"text-decoration: none;text-align:left;width:'+getResolutionWidth(180)+'px;height:'+getResolutionHeight(20)+'px;float:left;margin-top:'+getResolutionHeight(5)+'px;color:#CCCCCC;font-size:'+getResolutionWidth(12)+'px;font-weight:bold;cursor:pointer;margin-left:0px;\" onclick=\"maximize(\''+friendId+'\');stopBlinking(\'lowerDiv_name_'+friendId+'\');\">'+name+'</div>';
		workHtml=workHtml+"<div id=\"redChatCount_"+friendId+"\" style=\"width:"+getResolutionWidth(10)+"px;float:left;background-color:#FF0000;color:#FFFFFF;font-size:"+getResolutionWidth(14)+"px;margin-top:"+getResolutionHeight(3)+"px;font-weight:bold;display:none;\"></div>";
		workHtml=workHtml+"<div id=\"lowerClose_" + friendId + "\" style=\"display:none;width:"+getResolutionWidth(20)+"px;float:right;display:block;cursor:pointer;\"><img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + friendId + "')\"></div>";
		
		if(totalChatWindows==0){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(202)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==1){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(420)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows==2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(638)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}else if(totalChatWindows>2){
		workHtml=workHtml+"<div id=\"chatUpWindows_"+friendId+"\" style=\"position:fixed;float:right;bottom:"+getResolutionHeight(27)+"px;right:"+getResolutionWidth(658)+"px;width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(260)+"px;border: 1px solid #999999;background-color:#333333;\">";////add 15% on adding each window
		}
		
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(57)+"px;background-color:#111111;\">";
		workHtml = workHtml + "<div id=\"resultedPicDiv\" style=\"float:left;width:"+getResolutionWidth(45)+"px; \">";
		workHtml = workHtml + "<a href=\"profile.do?pid=" + friendId + "\"><img alt=\"\" src=\"" + src + "\" style=\"border:1px solid #2E2E2E;max-height: "+getResolutionHeight(170)+"px;\" width=\""+getResolutionWidth(35)+"\" border=\"0\"></a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div id=\"resultedNameDiv\" style=\"float:left;width:"+getResolutionWidth(130)+"px;height:"+getResolutionHeight(12)+"px;\"><a class=\"see_all\" style=\"font-size: "+getResolutionWidth(11)+"px;\" href=\"profile.do?pid=" + friendId + "\">" +name + "</a>";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" onclick=\"minmize(\'chatUpWindows_" +friendId+"\')\" src=\"images/Icons/minimizebutton.jpg\"   alt=\"-\" title=\"-\" ></div><div style=\"float:left;	width:"+getResolutionWidth(18)+"px;	cursor:pointer;	height:"+getResolutionHeight(13)+"px;\"><img width=\""+getResolutionWidth(16)+"\" src=\"images/Icons/closebutton.jpg\"  alt=\"x\" title=\"x\" onclick=\"closeChatWindow('" + friendId + "')\"></div></div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(15)+"px;background-color:#222222;text-align:left;\"><a href=\"javascript:clear('" + friendId + "')\" class=\"see_all_chat\" style=\"font-size: "+getResolutionWidth(11)+"px;\" >Clear History</a></div>";
		workHtml = workHtml + "<div name=\"textArea_" + friendId + "\" id=\"textArea_" + friendId + "\" style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(158)+"px;overflow:auto;text-align:justify;color:#c1c1c1;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: "+getResolutionWidth(12)+"px;	border-bottom:"+getResolutionHeight(2)+"px solid #c1c1c1;\">";
		workHtml = workHtml + "</div>";
		workHtml = workHtml + "<div style=\"width:"+getResolutionWidth(216)+"px;height:"+getResolutionHeight(28)+"px;background-color:#111111;\">";
		
		workHtml = workHtml +"<div style=\"float:left;height:"+getResolutionHeight(26)+"px;width:"+getResolutionWidth(162)+"px;border-right:1px solid #FFFFFF;\" >";
		workHtml = workHtml +"<form autocomplete=\"off\" style=\"margin-top:0px;margin-bottom:0px;width:"+getResolutionWidth(139)+"px;float:left;height:"+getResolutionHeight(27)+"px;\" name=\"form_" + friendId + "\" id=\"form_" + friendId + "\" onclick=\"stopBlinking(\'lowerDiv_name_"+friendId+"\');\" onsubmit=\"return sendData(\'"+friendId+"\')\">";
		workHtml = workHtml +"<input maxLength=1024 style=\"background-color:#111111;color:#c1c1c1;height:"+getResolutionHeight(22)+"px;width:"+getResolutionWidth(125)+"px;margin-top:3px;margin-bottom:"+getResolutionHeight(2)+"px;border: none;\" type=\"text\" id=\"input_" + friendId + "\" name=\"input_" + friendId + "\" >";
		workHtml = workHtml +"</form>";
		workHtml = workHtml +"<img border=0 alt=\"Emoticons\" title=\"Emoticons\" src=\"images/smileys/7th_smile.gif\" style=\"cursor:pointer;margin-top:"+getResolutionHeight(5)+"px;\" onclick=\"showChatSmileys(\'"+friendId+"\')\" width=\""+getResolutionWidth(17)+"\">";
		workHtml = workHtml +"</div>";
		workHtml = workHtml +"<div style=\"float:left;background-color:#000000;width:"+getResolutionWidth(52)+"px;height:"+getResolutionHeight(28)+"px;\"><img onclick=\"return sendData(\'"+friendId+"\')\"  border=0 style=\"cursor:pointer;padding-top:"+getResolutionHeight(1)+"px;\" width="+getResolutionWidth(49)+"  src=\"images/Icons/chat-send.gif\"  alt=\"Send\" title=\"Send\"  ></div>";
		workHtml = workHtml +"<div id=\"chatSmileys_"+friendId+"\" style=\"position:relative;bottom:"+getResolutionHeight(630)+"%;left:0%;z-index:2;width:"+getResolutionWidth(90)+"%;height:"+getResolutionHeight(600)+"%;background-color:#FFFFFF;border:1px solid #00FF00;display:none;\"></div>";
		workHtml = workHtml +"</div>";
		workHtml = workHtml + "</div>";
		workHtml=workHtml+"</div></div>";
		containerDiv.innerHTML = containerDiv.innerHTML + workHtml;
		document.getElementById("input_" + friendId).focus();
		
		
		if (document.getElementById(lastActive)) {
			minmize(lastActive);
		}
		lastActive = "chatUpWindows_" + friendId;
		
			chatWindowsArray[totalChatWindows] = friendId;
			chatCountArray[totalChatWindows]=0;
		leftChatWindowsIndex = totalChatWindows;
		var hasRightHidden;
		if (totalChatWindows >= 3) {
		//alert("1");
			rightChatWindowsIndex = totalChatWindows - 2;
			document.getElementById("lowerDiv_" + chatWindowsArray[rightChatWindowsIndex - 1]).style.display = "none";
			document.getElementById("right_but").className = "right_but_visible";
			hasRightHidden = chatWindowsArray[rightChatWindowsIndex - 1];
		}
		totalChatWindows = totalChatWindows + 1;
		

		if (document.getElementById("left_but").className == "left_but_visible") {
			document.getElementById("left_but").className = "left_but_nonVisible";
			//document.getElementById("chatWindowsListContainer").className = "chatWindowsListContainer_641";
		}
		var xmlHttp;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		var onLineFriendsWindowsClass = document.getElementById("onLineFriendWindow").className;
		var url = "ajaxSaveChatSession.do?type=savingWindow&id=" + friendId + "&status=maximize&source=" + src + "&name=" + name;
		url = url + "&display=show";
		url = url + "&totalChatWindows=" + totalChatWindows + "&rightChatWindowsIndex=" + rightChatWindowsIndex + "&leftChatWindowsIndex=" + leftChatWindowsIndex + "&lastActive=" + lastActive;
		url = url + "&chatWindowsArray=" + chatWindowsArray;
		url = url + "&onLineFriendsWindowsClass=" + onLineFriendsWindowsClass; //+ "&chatWindowsListContainer=" + chatWindowsListContainer;
		url = url + "&left_but_class=" + document.getElementById("left_but").className + "&right_but_class=" + document.getElementById("right_but").className;
		if (hasRightHidden) {
			url = url + "&hasRightHidden=" + hasRightHidden;
		}
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
			}
		};
		xmlHttp.send(null);			
		//removed by fawad to comment the session messaging
		//get24HrMessages(friendId, name + ":" + messages);
		//end of commented session messages
		makeChatSmileys(friendId);
		get24HrMessages(friendId);
		document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
		} else {
			if (document.getElementById("textArea_" + friendId).innerHTML != "") {
				if (messages != "") {
					document.getElementById("textArea_" + friendId).innerHTML = document.getElementById("textArea_" + friendId).innerHTML + "<br>" + "<span id=\"chat_Name_Font\">"+name+"</span>" + ":" + messages;
					document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
					if(document.getElementById("chatUpWindows_" + friendId).style.display=="none"){
					document.getElementById("redChatCount_"+friendId).style.display="block";
					var currentIndex=findCurrentIndex(friendId);
					document.getElementById("redChatCount_"+friendId).innerHTML=chatCountArray[currentIndex]+chatCount;
					chatCountArray[currentIndex]=chatCountArray[currentIndex]+chatCount;
					}
				}
			} else {
				if (messages != "") {
					document.getElementById("textArea_" + friendId).innerHTML = "<span id=\"chat_Name_Font\">"+name+"</span>" + ":" + messages;
					document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
					if(document.getElementById("chatUpWindows_" + friendId).style.display=="none"){
					document.getElementById("redChatCount_"+friendId).style.display="block";
					var currentIndex=findCurrentIndex(friendId);
					document.getElementById("redChatCount_"+friendId).innerHTML=chatCountArray[currentIndex]+chatCount;
					chatCountArray[currentIndex]=chatCountArray[currentIndex]+chatCount;
					}
				}
			}
		}
		//document.getElementById("lowerDiv_name_" + friendId).style.text.decoration="blink";
		windowTitle=document.title;
		titlebar(0);
	}
}


function getOnLineBuddies() {
	var onLineFriendsContainer = document.getElementById("onLineFriendWindow");
//////************************************************  AJAX Starts *************************************************///////
//alert("in");
	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "getOnlineFriends.do?screenWidth="+winWidth+"&screenHeight="+winHeight;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			var responceText = xmlHttp.responseText;
			if (!responceText) {
			} else {
				onLineFriendsContainer.innerHTML = responceText;
				getOnlineCount();
			}
         document.getElementById("div_0").scrollTop = document.getElementById("div_0").scrollHeight;
         //alert("ready");
		}
	};
	xmlHttp.send(null);
		//////************************************************  AJAX Ends *************************************************///////
}
function getOnlineCount(){
var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "getOnlineFriends.do?count=yes";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			var responceText = xmlHttp.responseText;
			document.getElementById("chatOnLineCount").innerHTML="Chat ("+responceText+")";
			}
	};
	xmlHttp.send(null);
}
function MM_openBrWindow(theURL, winName, features) { //v2.0
	window.open(theURL, winName, features);
}
function get24HrMessages(friendId) {
//////************************************************  AJAX Starts *************************************************///////

	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "ajaxChat.do?messageStatus=24hrMessages&friendId=" + friendId;
	
	///removed by fawad for commenting session work
	//if (newMessage != null) {
		//url = url + "&newMessage=" + newMessage;
	//}
	//////end of session commented code by fawad
	
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			var responceText = xmlHttp.responseText;
			if (!responceText) {
			} else {
         																
         																
				document.getElementById("textArea_" + friendId).innerHTML = insertSmileysToResponce(responceText);
				document.getElementById("textArea_" + friendId).scrollTop = document.getElementById("textArea_" + friendId).scrollHeight;
			}
		}
	};
	xmlHttp.send(null);
		//////************************************************  AJAX Ends *************************************************///////
}
function stopBlinking(divId){
if(document.getElementById(divId)){
//document.getElementById(divId).style.text.decoration="none";
}
}
function findCurrentIndex(friendId){
//alert(friendId);
//alert("chatWindowsArray-------"+chatWindowsArray);
for (var i=0;i<totalChatWindows;i=i+1){
var index;
if(chatWindowsArray[i]==friendId){
index=i;
}
}
return index;
}
function setPosition(friendId){

if(document.getElementById('chatUpWindows_'+friendId)){
	var currentIndex=findCurrentIndex(friendId);
	if(document.getElementById("right_but").className=="right_but_visible"){
	if(currentIndex==leftChatWindowsIndex){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(659)+"px";
	}else if(currentIndex==rightChatWindowsIndex){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(223)+"px";
	}else{
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(441)+"px";
	}
	
	
	}else{
	//alert('currentIndex-----------'+currentIndex);
	//alert('leftChatWindowsIndex-----------'+leftChatWindowsIndex);
	//alert('rightChatWindowsIndex-----------'+rightChatWindowsIndex);
	
	if(currentIndex==0){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(202)+"px";
	}else if(currentIndex==1){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(420)+"px";
	}else if(currentIndex==leftChatWindowsIndex){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(638)+"px";
	}else if(currentIndex==rightChatWindowsIndex){
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(202)+"px";
	}else{
	document.getElementById('chatUpWindows_'+friendId).style.right = ""+getResolutionWidth(420)+"px";
	}
	
	}
	}
}
function makeChatSmileys(friendId){
//alert(friendId);
var smileyDiv=document.getElementById("chatSmileys_"+friendId);
//alert(smileyDiv);
if(smileyDiv){
var chatPathArray = ['7th_smile.gif', '7th_wink.gif', '7th_angry.gif','7th_speechlesssmiley.gif','7th_cool.gif','7th_blush.gif','7th_biggrin.gif','7th_smileywithtongueout.gif','7th_giggle.gif',
				'7th_evilgrin.gif','7th_devil.gif','7th_call.gif','7th_kiss.gif','7th_itwasntme.gif','7th_brokenheart.gif','7th_heart.gif','7th_muscle.gif','7th_handshake.gif',
				'7th_drama.gif','7th_clap.gif','7th_banghead.gif','7th_flaminggrin.gif','7th_king.gif'];
var chatNameArray = ['smile', 'wink', 'angry','speechlesssmiley','cool','blush','biggrin','smileywithtongueout','giggle',
				'evilgrin','devil','call','kiss','itwasnotme','brokenheart','heart','muscle','handshake',
				'drama','clap','banghead','flaminggrin','king'];
var chatCodeArray = [':)',';)',':@',':|','8D',':8)',':D',':P',':giggle:',
				']:)',':devil:',':call:',':*',':wasntme:',':u:',':h:',':flex:',':handshake:',
				':drama:',':clap:',':bh:',':fg:',']:)']; 
var innerHtml="<div style=\"height:15%;width:100%;background-color:#000000;\">";
if(browserName=="IE7"){
innerHtml=innerHtml+"<img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\" style=\"float:right;position:relative;bottom:0%;cursor:pointer;\" onclick=\"showChatSmileys(\'"+friendId+"\')\"></div>";
}else{
innerHtml=innerHtml+"<img width="+getResolutionWidth(16)+" src=\"images/Icons/closebutton.jpg\" style=\"float:right;position:relative;bottom:100%;cursor:pointer;\" onclick=\"showChatSmileys(\'"+friendId+"\')\"></div>";
}
innerHtml=innerHtml+"<div style=\"height:80%;width:100%;background-color:#FFFFFF;\">";
for (var i=0;i<=22;i=i+1)
{
innerHtml=innerHtml+'<div onclick=\"addToChatTextArea(\''+friendId+'\',\''+chatCodeArray[i]+'\')\"  style=\"float:left;padding-left:1%;padding-top:3%;cursor:pointer;\"><img  width='+getResolutionWidth(19)+' alt=\"'+chatNameArray[i]+'  '+chatCodeArray[i]+'\" title=\"'+chatNameArray[i]+'  '+chatCodeArray[i]+'\" src=\"images/smileys/'+chatPathArray[i]+'\" /> </div>';
}
innerHtml=innerHtml+"</div>";

smileyDiv.innerHTML=innerHtml;
}
}
function showChatSmileys(friendId){

var smileyDiv=document.getElementById("chatSmileys_"+friendId);
if(smileyDiv){
if(smileyDiv.style.display=="block"){
smileyDiv.style.display="none";
}else{
smileyDiv.style.display="block";
}
}
}

function addToChatTextArea(friendId,code){
if(document.getElementById("input_"+friendId)){
document.getElementById("input_"+friendId).value=document.getElementById("input_"+friendId).value+" "+code+" ";
//document.getElementById("chatSmileys_"+friendId).innerHTML="";
document.getElementById("chatSmileys_"+friendId).style.display="none";
document.getElementById("input_" + friendId).focus();
}
}



function titlebar(val)
{
	var msg  = "New Message";
	var speed = 1000;
	var pos = val;

	var msg1  = "    "+msg+" ";
	var msg2  = windowTitle;

	if(pos == 0){
		masg = msg1;
		pos = 1;
	}
	else if(pos == 1){
		masg = msg2;
		pos = 0;
	}

	
	if(windowFocus==0){
	document.title = masg;
	timer = window.setTimeout("titlebar("+pos+")",speed);
	}else{
	document.title =windowTitle;
	}
}

function changeArrow(id,src){
if(document.getElementById(id)){

document.getElementById(id).src="images/Icons/"+src;

}
}



//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///
//////*********************************************************************************************************************************************************///

function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=
document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
winHeight=windowHeight;


}
function getWindowWidth() {
var windowWidth=0;
if (typeof(window.innerWidth)=='number') {
windowWidth=window.innerWidth;
}
else {
if (document.documentElement&&
document.documentElement.clientWidth) {
windowWidth=
document.documentElement.clientWidth;
}
else {
if (document.body&&document.body.clientWidth) {
windowWidth=document.body.clientWidth;
}
}
}

winWidth=windowWidth;


}
function getResolutionWidth(w){
var originalWidth=1440.0;
if(browserName=="IE7"){

originalWidth=1419;
}
return (w/1440.0)*winWidth;
}
function getResolutionHeight(h){
var originalHeight=1440.0;

if(browserName=="IE7"){
originalHeight=649;
}
return (h/678.0)*winHeight;
}
function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +

                    " " +
                    ap;
   return timeString;
}
function getNewLineString(str,limit){
var spaceArray=[];
if(!str){
		return "";
		}
		//StringBuilder finalStr=new StringBuilder();
		var finalStr="";

		//s=s.replaceAll("<br>", "");/// if the data is copied from a seventhbillion wallpost which contains breaks... the breaks will be replaced with ""
		str=str.replace(/<br>/g, "");
		
		
		//StringTokenizer st=new StringTokenizer(s);
		//st.setDelimiters(" ","\n");
		spaceArray=str.split(" ");
		for(var i=0;i<spaceArray.length;i++){
		var token=spaceArray[i];
		
		while(token.length>limit){
		finalStr=finalStr+token.substring(0,limit)+"\n";
		token = token.substring(limit);
		}
		finalStr=finalStr+token+" ";
		
		}
finalStr=finalStr.replace(/\n/g, "<br>");
return( finalStr);


}
function getNotifications(){

if (document.getElementById("notificationsDivContainer").className == "firstNameList_visible") {
		document.getElementById("notificationsDivContainer").className = "firstNameList_nonvisible";
	} else {
	if (document.getElementById("onLineFriendWindow").className == "firstNameList_visible") {
		document.getElementById("onLineFriendWindow").className = "firstNameList_nonvisible";
		}
		getNewNotifications();
		document.getElementById("notificationsDivContainer").className = "firstNameList_visible";
	}
	
	//var xmlHttp;
	//if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		//xmlHttp = new XMLHttpRequest();
	//} else {
		//if (window.ActiveXObject) { // IE
			//xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		//}
	//}
	//var url = "ajaxSaveChatSession.do?type=gettingOnlineFriends&onLineFriendsWindowsClass=" + document.getElementById("onLineFriendWindow").className;
	//xmlHttp.open("POST", url, true);
	//xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//xmlHttp.onreadystatechange = function () {
		//if (xmlHttp.readyState == 4) {
		//}
	//};
	//xmlHttp.send(null);
}
function getNewNotifications(){
var notificationsContainer = document.getElementById("notificationsDivContainer");
//////************************************************  AJAX Starts *************************************************///////

	var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "getNotifications.do?screenWidth="+winWidth+"&screenHeight="+winHeight;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			var responceText = xmlHttp.responseText;
			if (!responceText) {
			} else {
				notificationsContainer.innerHTML = responceText;
				getNotificationsCount();
			}
         //document.getElementById("div_0").scrollTop = document.getElementById("div_0").scrollHeight;
         
		}
	};
	xmlHttp.send(null);
		//////************************************************  AJAX Ends *************************************************///////
}
function deleteNotification(notificationId){

var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "getNotifications.do?type=delete&id="+notificationId;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
		document.getElementById("notify_"+notificationId).innerHTML="";
			document.getElementById("notify_"+notificationId).style.display="none";
         
		}
	};
	xmlHttp.send(null);
}
function getNotificationsCount(){



var xmlHttp;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { // IE
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "getNotifications.do?type=count";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
		
			document.getElementById("notificationsCount").innerHTML="("+xmlHttp.responseText+")";
         
		}
	};
	xmlHttp.send(null);
	
}