function getRegionsSpeed(obj, s_mi_id){
	var root = window.document;
	//alert("obj: "+obj+"obj.value: "+obj.value);
  if(obj.value == '-1' || obj == -1){
    root.getElementById('state_speed_id').style.display = 'none'; 
  } else {
    root.getElementById('state_speed_id').style.display=''; 
    var country_id = root.getElementById('country').value; 
    xajax_getRegions(country_id, 'speed_dating', 1);
  }
  
  //document.forms['std_register'].elements['state'].disabled=true;
  //xajax_getRegions(xajax.getFormValues('std_register'));
}
function getMaxAgeSpeed(obj){
	var root = window.document;
	//alert("obj: "+obj+"obj.value: "+obj.value);
  if(obj.value == '-1' || obj == -1){
    root.getElementById('ageMax').style.display = 'none'; 
  } else {
    root.getElementById('ageMax').style.display=''; 
    xajax_getMaxAge(obj);
  }
  
  //document.forms['std_register'].elements['state'].disabled=true;
  //xajax_getRegions(xajax.getFormValues('std_register'));
}
var step = 0;
var temp_period = 0;
function newSearchMember(period, step, temp_period) {
	//alert("period: "+period+", step: "+step+", temp_period: "+temp_period);
	var root = window.document;
	var temp_period = step + temp_period;
	if(period == temp_period) {
		//clearInterval(speedInterval);
		clearTimeout(speedInterval);
		var sexSelect = root.getElementById('sexSelect').value;
		var ageSelectMin = root.getElementById('ageMinSelect').value;
		var ageSelectMax = root.getElementById('ageMaxSelect').value;
		var countrySelect= root.getElementById('country').value;
		xajax_datingBegin(1, sexSelect, ageSelectMin, ageSelectMax, countrySelect);
	} else {
		//root.getElementById('speedResult').innerHTML = '';
		root.getElementById('speedResultBeeper').style.display = '';
		root.getElementById('speed_beeper').innerHTML = (period/1000)-(temp_period/1000);
		speedInterval = setTimeout("newSearchMember("+period+", "+step+", "+temp_period+");", step);
	}
	//speedInterval = setInterval(newSearchMember(period, step, temp_period), step);
}
//************************************************************************
function addreply(name) {
  window.document.getElementById('msg').value = '-'+name+'-, '+window.document.getElementById('msg').value;
  //mode = window.document.getElementById('mode');
  //mode.checked = true;
}
//************************************************************************
function msg(n,c,i,m,t,template_url, from, stype) {
  if(t==1) s='allmsg';
  else if(t==2) s='pmsg';
  else if(t==3) s='mymsg';
  else if(t==4) s='smsg';
  //alert("msg("+n+","+c+","+i+","+m+","+t+","+template_url+", "+from+", "+stype+"");
  var name = window.document.getElementById('hidden_name').value;
  var addevent = '';
  if (n != name && n != "--Daemon--") addevent = " onmouseover=this.style.cursor=\"pointer\"; onclick=top.addreply(\""+n+"\");";
  //var message = "<div class=\""+s+"\"><span class=\"nick_span\" id=\"span_"+i+"\"><b "+addevent+">"+n+"</b></span>"+m+"<input type=\"hidden\" id=\"cspan_"+i+"\" value=\""+c+"\"></div>";
  var message = "<div class=\""+s+"\"> "+m+" <input type=\"hidden\" id=\"cspan_"+i+"\" value=\""+c+"\"></div>";
  window.document.getElementById('body_chat').contentWindow.document.getElementById('chat_panel').innerHTML = message + window.document.getElementById('body_chat').contentWindow.document.getElementById('chat_panel').innerHTML;
  //color_status = window.document.getElementById('color_indicator').value;
  //color = window.document.getElementById('body_chat').contentWindow.document.getElementById('cspan_'+i).value;
  //if (color_status == 1) window.document.getElementById('body_chat').contentWindow.document.getElementById('span_'+i).style.color=color;
  //else window.document.getElementById('body_chat').contentWindow.document.getElementById('span_'+i).style.color='white';

  //time_status =  window.document.getElementById('time_indicator').value;
  //if (time_status == 1) window.document.getElementById('body_chat').contentWindow.document.getElementById('tspan_'+i).style.display='';
  //else window.document.getElementById('body_chat').contentWindow.document.getElementById('tspan_'+i).style.display='none';
  
  /*if(stype && window.document.getElementById('join_ring_indicator').value == 0) {
    window.document.getElementById('body_chat').contentWindow.document.getElementById('join_ring_img_'+i).innerHTML = '';
  } else {
  //alert (cid+"_"+window.document.getElementById('hidden_info').value)
    if (window.document.getElementById('hidden_info').value != from) {
      if(stype == 1) {
        if(window.document.getElementById('join_ring_counter').value == 0) {
          this.playsound(template_url, 2);
        }
        r_cnt = window.document.getElementById('join_ring_counter').value;
        window.document.getElementById('join_ring_counter').value  = parseInt(r_cnt) + 1;
      }
      else this.playsound(template_url, 0);
    }
  }*/
  waitInvitation(i, template_url); 
}
function waitInvitation(id, template_url) { 
  if (null !== window.document.getElementById('body_chat').contentWindow.document.getElementById('hidden_'+id)) {
    var buttonId = window.document.getElementById('body_chat').contentWindow.document.getElementById('hidden_'+id).innerHTML; 
    //alert(buttonId); 
    playrings(template_url, buttonId); 
  }
}
function playrings(template_url, bId) { 
  if (null !== window.document.getElementById('body_chat').contentWindow.document.getElementById('b_'+bId)) {
    //alert('a'); 
    if (window.document.getElementById('body_chat').contentWindow.document.getElementById('b_'+bId).style.display != 'none') {
      //alert('f'); 
      setTimeout("playrings('" + template_url + "', '" + bId + "');", 3000); 
      playsound(template_url, 1); 
    }
  }
}
//************************************************************************
function refreshSpeed(roomId) {
  var refreshSpeedInterval = setTimeout('xajax_crefreshSpeed(\''+roomId+'\');',3000);
}
//*************************************************************************
function send_msg_speed(){
  window.document.getElementById('speedResult').innerHTML= "";
  var obj = window.document;
  var msg = obj.getElementById('msg').value;
  var mid = obj.getElementById('mid').value;
  var m_type = obj.getElementById('m_type').value;
  var m_roomId = obj.getElementById('m_roomId').value;
  //alert("msg: "+msg+", mid: "+mid+", m_type: "+m_type+", m_roomId: "+m_roomId);
  if((msg != '')&&(obj.getElementById('sbut').disabled == false)) {
    obj.getElementById('sbut').disabled = true;
    obj.getElementById('sbut').value = "...";
    obj.getElementById('msg').value = "";
    window.document.getElementById('msg').focus();
    
    xajax_sendSpeed(msg, m_type, mid, m_roomId);
    
    var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
    var id = 'body_chat';
    var color = window.document.getElementById('hidden_color').value;
    var nick = window.document.getElementById('hidden_nick').value;
    var actualTime = window.document.getElementById('actual_time').value;
    var memId = window.document.getElementById('hidden_info').value;
    
    var font_face = window.document.getElementById('font_face_top').value;
    var font_size = window.document.getElementById('font_size_top').value;
    var font_color = window.document.getElementById('font_color_top').value;
    
    var text_style = "style=\"font-family:"+font_face+";font-size:"+font_size+"px; color:"+font_color+";font-weight:normal; \"";
    
    var message = "<span class='time_span' id='time_span_"+new Date().getTime()+"'>" + actualTime + "</span> <span style='color:" + color + "' class='nick_span' id=\""+new Date().getTime()+"\"><b>" + nick + "</b></span>: ";
    //xajax_addMessage(id, message, msg);
    //var n_message = "<span class=\"text_"+memId+"\" id=\"ftspan_"+new Date().getTime()+"\" "+text_style+">"+badWordsFilter(msg)+"</span>";
    var n_message = "<span class=\"text_"+memId+"\" id=\"ftspan_"+new Date().getTime()+"\" "+text_style+">"+msg+"</span>";
    var h_message = "<input id=\"c"+new Date().getTime()+"\" type=\"hidden\" value=\""+color+"\">";
    var cpanel = window.document.getElementById('body_chat').contentWindow.document.getElementById('chat_panel');
    cpanel.innerHTML = message + n_message + h_message +"<br>" + cpanel.innerHTML;
  }
}
function clearSpeed() {
  window.document.getElementById('body_chat').contentWindow.document.getElementById('chat_panel').innerHTML= "";
}

function hidetimeSpeed(template_url) {
  var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
  var cpanel = window.document.getElementById('body_chat').contentWindow.document;//.getElementById('chat_panel');
  var status = window.document.getElementById('time_indicator').value;
  //alert (status);
  if (status == 1) {
    this.showClass(cpanel, 'time_span', '', false);
    window.document.getElementById('time_indicator').value=0;
    window.document.getElementById('time_img').src= template_url+"/images/clock-off.gif";
    window.document.getElementById('time_img').alt="Show message time";
    window.document.getElementById('time_img').title="Show message time";
  } else {
    this.showClass(cpanel, 'time_span', '', true);
    window.document.getElementById('time_indicator').value=1;
    window.document.getElementById('time_img').src= template_url+"/images/clock-on.gif";
    window.document.getElementById('time_img').alt="Hide message time";
    window.document.getElementById('time_img').title="Hide message time";
  }
}
function hidecolorSpeed(template_url) {
  var id = 'chat_frame_'+window.document.getElementById('id_chat').value; 
  var cpanel = window.document.getElementById('body_chat').contentWindow.document;//.getElementById('chat_panel');
  var status = window.document.getElementById('color_indicator').value;
  //alert (status);
  if (status == 1) {
    this.showColor(cpanel, 'nick_span', '', false);
    window.document.getElementById('color_indicator').value=0;
    window.document.getElementById('color_img').src= template_url+"/images/color-off.gif";
    window.document.getElementById('color_img').alt="Show nickname colors";
    window.document.getElementById('color_img').title="Show nickname colors";
  } else {
    this.showColor(cpanel, 'nick_span', '', true);
    window.document.getElementById('color_indicator').value=1;
    window.document.getElementById('color_img').src= template_url+"/images/color-on.gif";
    window.document.getElementById('color_img').alt="Hide nickname colors";
    window.document.getElementById('color_img').title="Hide nickname colors";
  }
}

function changeColorSpeed(clsName, face, size, color) {
	//alert("clsName: "+clsName+" face: "+face+" size: "+size+" color: "+color);
	window.document.getElementById('font_face_top').value = face;
  window.document.getElementById('font_size_top').value = size;
  window.document.getElementById('font_color_top').value = color;
  
  //var chat_id = window.document.getElementById('id_chat').value;
  var cpanel = window.document.getElementById('body_chat').contentWindow.document;
  
  var elts = this.getElementsByClassName(cpanel, clsName, '');
  //alert('elts.length: '+elts.length);
  for(var i = 0; elts.length > i; i++) {
    //alert('elts[i]: '+elts[i]);
    cpanel.getElementById(elts[i]).style.fontFamily = face;
    cpanel.getElementById(elts[i]).style.fontSize = size;
    cpanel.getElementById(elts[i]).style.color = color;
    //alert("cpanel.getElementById(elts[i]).style.fontFamily: "+cpanel.getElementById(elts[i]).style.fontFamily);
  }
}
function sendSpeedDelay(uid, type, user_name) {
  var btn_private = window.document.getElementById('speed_with_'+uid);
  btn_private.style.display = "none";
  xajax_speedChatBegin(uid);
  this.inviteToSpeed();
  var speedDelay = setInterval("activateSpeedBtn('"+uid+"','"+type+"','"+user_name+"');",5000);
}
function inviteToSpeed() {
    var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
    var color = window.document.getElementById('hidden_color').value;
    var nick = window.document.getElementById('hidden_nick').value;
    var actualTime = window.document.getElementById('actual_time').value;
    var message = "<span class='time_span'>" + actualTime + "</span> <span style='color:" + color + "' class='nick_span'><b>" + nick + "</b></span>: <font color='red'>Sending invitation to speed chat.</font><br>";
    var cpanel = parent.frames[id].document.getElementById('chat_panel');
    cpanel.innerHTML = message + cpanel.innerHTML;
}
function activateSpeedBtn(enc_id, type,user_name) {
  var btn_private = window.document.getElementById('speed_with_'+enc_id);
  if(null !== btn_private) btn_private.style.display = "";
}
function tospeed(model, user, button1, button2, ad) {
//button1.disabled="disabled";
//button2.disabled="disabled";
  window.document.getElementById('body_chat').contentWindow.document.getElementById(button1).style.display = 'none'; 
  window.document.getElementById('body_chat').contentWindow.document.getElementById(button2).style.display = 'none'; 
  xajax_memberSpeedStart(model, user, ad);
}
//************************************************************************
function stopRefreshSpeed() {
	//alert("refreshSpeedInterval1: "+refreshSpeedInterval);
  clearTimeout(refreshSpeedInterval);
  //alert("refreshSpeedInterval2: "+refreshSpeedInterval);
}
function disp_confirm(model, user){
	var r = confirm("Please, push 'OK' to add the member to Favorities or 'Cancel' to add him to Ignor list.");
	if (r == true)  {
	  xajax_memberAddTofavorite(model, user, 1);
	}
	else {
	  xajax_memberAddTofavorite(model, user, 0);
	}
}
function updateMembers(){
	var root = window.document;
	var sexSelect = root.getElementById('sexSelect').value;
	var ageSelectMin = root.getElementById('ageMinSelect').value;
	var ageSelectMax = root.getElementById('ageMaxSelect').value;
	var countrySelect= root.getElementById('country').value;
	xajax_updateMembers(sexSelect, ageSelectMin, ageSelectMax, countrySelect);
}
function getActiveMembers(){
	var if_members = window.document.getElementById('member_cnt').value;
	//alert("if_members: "+if_members);
	xajax_showChatSteream(if_members);
}