function chat(u,c)
{	D = document.getElementById(u);if(D)D.style.display='block';
	else { 
	if(c)c = confirm(u+ 'Would like to chat with you.Click yes to chat with employer or click no to ignore employer');else c = true;
	if(!c)return false;
	D = document.createElement("div");D.id = u;
	D.innerHTML = '<div style="position:fixed;bottom:1px;right:1px;height:200px;width:200px;border:2px solid #999999; background-color:#FFFFFF"><h1 style="background:#999999;color:#FFFFFF;font-size:14px;padding:1px 4px;margin:0;">Chat with '+(u.length>10?u.substr(0,10)+'..':u)+'<span style="color:green;font-size:25px;position:absolute;left:190px;top:-10px;cursor:pointer;" onclick="this.parentNode.parentNode.parentNode.style.display=\'none\'" >&#8226;</span></h1><div style="list-style:none; margin:4px; height:110px; overflow:auto;font-size:12px;"><ul></ul></div><textarea rows="2" style="width:180px; margin:7px; border:2px solid #CCCCCC; position:absolute; bottom:1px;" onkeyup="send(this,\''+u+'\')"></textarea></div>';
	document.body.appendChild(D); 	
	}
}
function send(a,b)
{	
	
v=a.value;if(v.charAt((v.length-1))=='\n')
	{	msg('me',v,b);a.value='';
	
		G=xmlHttp();G.open('GET','http://'+window.location.host+'/veejobs/myfriend/myfriend?a=b&c='+v+'&d='+b,true);
		G.send(null);setTimeout("recive()",1500); 
	}
}
function xmlHttp()
{	if (window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
	else if (window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
	return xmlhttp;
}
function recive()
{	G=xmlHttp();G.open('GET','http://'+window.location.host+'/veejobs/myfriend/myfriend?a=b',true);
	G.onreadystatechange=function(){if(G.readyState==4 && G.status==200){eval('('+G.responseText+')');setTimeout("recive()",500);}}
	G.send(null); 
}
function msg(a,b,c)
{	chat(c,true);Li = document.createElement("li"); Li.innerHTML='<strong>'+(a.length>10?a.substr(0,10)+'..':a)+': </strong>'; 
	Li.appendChild(document.createTextNode(b));document.getElementById(c).getElementsByTagName('ul')[0].appendChild(Li);
	Li.style.color=a=='me'?'#999999':'#333333';Li.focus();
}window.onload=recive;

