function startmychatCheck() {
	
	var pe = new PeriodicalExecuter(checkMyChat, 10);

}

function checkMyChat() {
	
	
	var myAjax = new Ajax.Request("http://artmate.se/chat/check.php", 
	{
		method: 'post', 
		onComplete: respondMyChat
	});
}



function respondMyChat(originalRequest) {
	var result = originalRequest.responseXML;
	//var result1 = result;
	var req = result.getElementsByTagName("request");
	if(req != null) {
		
		frm = req[0].getElementsByTagName("from");
		
		if(frm != null && frm.length > 0) {
			//for( var i=0; i< frm.length;i++) {
				//alert(frm[0].firstChild);
			  if(frm[0].firstChild != null) {
				valueObj = frm[0].firstChild.nodeValue ;
				$("_mychat_id").value = frm[0].getAttribute("id");
				//alert(valueObj);
				$('_mychat_div_user').innerHTML = valueObj;
				//$('_mychat_div').style.left = (document.body.clientWidth + document.body.scrollLeft)/2 -10;
				//$('_mychat_div').style.top = (document.body.clientHeight + document.body.scrollTop)/2;
				
				
				//$('_mychat_div').style.display='block';
				showWindow1('_mychat_div','Chattförfrågan');
				
				//alert(valueObj);
			    }
			//}
		}
	}
	
	var res = result.getElementsByTagName("response"); 
	//alert(res);
	if(res != null) {
		t = res[0].getElementsByTagName("to");
		//alert("hello");
		//alert(t.length );
		if(t != null && t.length > 0) {
			
			valueObj = t[0].firstChild.nodeValue ;
			
			$("_mychat_response_id").value = t[0].getAttribute("id");
			$('_mychat_response_div_user').innerHTML = valueObj;
			//alert(valueObj);
			if(t[0].getAttribute("action") == 'G') {
			
				$('_mychat_response_div_message').innerHTML = '&nbsp; avböjer din inbjudan';
				
			}
			
			if(t[0].getAttribute("action")== 'X') {
				$('_mychat_response_div_message').innerHTML = '&nbsp; har stängt chatt fönstret';
							
			}
			
			
			//$('_mychat_response_div').style.display='block';
			
			showWindow1('_mychat_response_div','');
		}
	
	}
	
	
}


function hideMychatRequest(response) {
	
	//$('_mychat_div').style.display='none';
	Windows.closeAll();
	
	var url = 'http://artmate.se/chat/close.php';
	var pars = 'id=' + $("_mychat_id").value +"&response="+response;

	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: nouse
	});
	
	
}

function openChat() {

	//$('_mychat_div').style.display='none';
	Windows.closeAll();
	
	var url = 'http://artmate.se/chat/close.php';
		var pars = 'id=' + $("_mychat_id").value +"&response=D";
	
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: pars, 
				onComplete: nouse
		});
	
	
	
}

function deleteMychatResponse() {
	
	var url = 'http://artmate.se/chat/close.php';
	var pars = 'id=' + $("_mychat_response_id").value +"&response=D";

	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: nouse
	});
	//$('_mychat_response_div').style.display='none';
	Windows.closeAll();
}


//For Movable window..

function nouse() {

}

var win1c;

function showWindow1(cnt,ttl) {
	
	Windows.closeAll();
	
	win1c = new Window({className: "alphacube", title: ttl,
				      width:400, height:250,
				       showEffectOptions: {duration:1.5}});
	//alert(win1c);			 
	win1c.setContent(cnt,false,false);
	win1c.showCenter();

}