var main_support_interval;
var interval;
var updatingNow = 0; //needed to do not show wait cursor during updating lists
var multi_model_id = 0;  // using on refresh
var blink_mail;
var blink_mail_t;

function send_msg(obj){
  document.getElementById('error_message').innerHTML="";
  msg = obj.msg.value;
  mid = obj.mid.value;
  if((msg!='')&&(obj.sbut.disabled==false)) {
    obj.sbut.disabled=true;
    obj.sbut.value="...";
    obj.msg.value="";
    window.document.getElementById('msg').focus();
    if(obj.mode.checked==true){
    type=2;
    } else {
    type=1;
    }
    xajax_send(msg, type, mid);
    xajax_parseUrlsAndPushMessage(msg); 
  }
}
  
function insertMessage(msgHTML) {
    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 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 hideTime = ""; 
  var timeStatus = window.document.getElementById('time_indicator').value;
  if (timeStatus == "0") hideTime = "display:none;"; 
  var message = "<span class='time_span' style='"+hideTime+"' id='time_span_"+actualTime+"'>" + 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(msgHTML)+"</span>";
  var h_message = "<input id=\"c"+new Date().getTime()+"\" type=\"hidden\" value=\""+color+"\">";
      
  var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
  var cpanel = parent.frames[id].document.getElementById('chat_panel');
  cpanel.innerHTML = message + n_message + h_message +"<br>" + cpanel.innerHTML;
}
function badWordsFilter(msg) {
  var bwLen = chatBadWords.length;
  var gwLen = chatReplacements.length;
  var rand = new Date();
  var rEl=(rand.getSeconds())%gwLen;
  for (var i=0; i<bwLen; i++) {
    before = msg;
    after = msg.replace(chatBadWords[i]);
    if (before != after) {
      msg = chatReplacements[rEl];
      break;
    }
  }
  return msg;
}
function pushToFrame(msg, id) {
  var cpanel = parent.frames[id].document.getElementById('chat_panel');
  cpanel.innerHTML = msg + cpanel.innerHTML;
}
function inviteToPrivate() {
    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 private.</font><br>";
    var cpanel = parent.frames[id].document.getElementById('chat_panel');
    cpanel.innerHTML = message + cpanel.innerHTML;
}
function append(str, cid, msgid, template_url){
  id = 'chat_frame_'+window.document.getElementById('id_chat').value;
  cpanel = parent.frames[id].document.getElementById('chat_panel');
  if (window.document.getElementById('hidden_info').value != cid) {
    this.playsound(template_url);
    cpanel.innerHTML = str + cpanel.innerHTML;
  }
  color_status = window.document.getElementById('color_indicator').value;
  color = parent.frames[id].document.getElementById('cspan_'+msgid).value;
  if (color_status == 1) parent.frames[id].document.getElementById('span_'+msgid).style.color=color;
  else parent.frames[id].document.getElementById('span_'+msgid).style.color='black';
  var timeStatus = window.document.getElementById('time_indicator').value;
  if (timeStatus == '0') setTimeout("parent.frames['"+id+"'].document.getElementById('time_span_"+msgid+"').style.display = 'none';", 50);
}
//function refresh_member_act(){
//  xajax_updateMemberActivity();
//}
function refresh() {
  //alert("refresh("+uid+");");
  updatingNow = 1;
    var flObject = window.document.getElementById('lSubscriber');
  var tmpObject = window.document.getElementById('temp_value');
  //alert(flObject + "___" + tmpObject);
  if (null !== flObject && null !== tmpObject && multi_model_id != 0) {
    xajax_crefresh(multi_model_id);
  } else return false;
  updatingNow = 0;
}

function generate(a){
  if (a!=0) xajax_generateProfile(a);
  else window.location="/";
  return false;
}
function pause(ifunc){
  setTimeout("startCheck('"+ifunc+"');",1000);
}
function startCheck(ifunc){
  interval = setInterval("top."+ifunc+"();",100);
}
function cwindow(cid) {
  frameid = 'chat_frame_'+cid;
  parent.frames[frameid].document.getElementById('chat_panel').innerHTML="";
}

function checkLogin(uid) {
  xajax_memberLogoutByAdmin(uid,0);
  setTimeout("checkLogin('"+uid+"');",60000);
}

function inprivate() {
  checkbox = window.document.getElementById('mode');
  checkbox.checked = true;
  checkbox.disabled = "disabled";
  checkbox.type = 'hidden';
  prv_text = window.document.getElementById('prv_text');
  prv_text.innerHTML = "";
}
//**********************
function smile(template_url) {
  div = window.document.getElementById('smiles');
  if(div.style.display=='none') {
    if (div.innerHTML=='') xajax_addsmile();
    div.style.display='block'; 
    window.document.getElementById('smile_img').src = template_url + "/images/smiley-off.gif";
    window.document.getElementById('smile_img').alt="Hide smiles";
    window.document.getElementById('smile_img').title="Hide smiles"
  } else {
    //div.innerHTML='';
    div.style.display='none'; 
    window.document.getElementById('smile_img').src = template_url + "/images/smiley-on.gif";
    window.document.getElementById('smile_img').alt="Show smiles";
    window.document.getElementById('smile_img').title="Show smiles"
  }
}
//*********************
function showprofile(smid) {
  check = window.document.getElementById('check_profile');
  div = window.document.getElementById('gallery');
  if (check==null) xajax_generateModelProfile(smid);
  else div.innerHTML=null;
}
//********************
var smilesArr =new Array(":D", ":)", ":(", ":heap:", ":ooi:", ":so:", ":surp:", ":ag:", ":ir:", ":oops:", ":P", ":cry:", ":rage:", ":B", ":roll:", ":wink:", ":yes:", 
                                  ":bot:", ":z)", ":arrow:", ":vip:", ":Heppy:", ":think:", ":bye:", ":roul:", ":pst:", ":o", ":closed:", ":cens:", ":tani:", 
                                   ":appl:", ":idnk:", ":sing:", ":shock:", ":tgu:", ":res:", ":alc:", ":lam:", ":box:", ":tom:", ":lol:", ":vill:", ":idea:", ":oops:", 
                                   ":E", ":sex:", ":horns:", ":love:", ":poz:", ":roza:", ":meg:", ":dj:", ":rul:", ":offln:", ":sp:", ":stapp:", ":girl:", ":heart:", ":kiss:", 
                                   ":spam:", ":party:", ":ser:", ":eam:", ":gift:", ":adore:", ":pie:", ":egg:", ":cnrt:", ":oftop:", ":foo:", ":mob:", ":hoo:", ":tog:", 
                                   ":pnk:", ":pati:", ":-({|=:", ":haaw:", ":angel:", ":kil:", ":died:", ":cof:", ":fruit:", ":tease:", ":evil:", ":exc:", ":niah:", ":Head:", 
                                   ":gl:", ":granat:", ":gans:", ":user:", ":ny:", ":mvol:", ":boat:", ":phone:", ":cop:", ":smok:", ":bic:", ":ban:", ":bar:"); 
function addsmiles(smile) {
  var toadd = smilesArr[(Number(smile)-1)]; 
  text = window.document.getElementById('msg');
  text.value = text.value + toadd;
}
//**************
function schedule(day, hour) {
  select1 = window.document.getElementById('day_select');
  select2 = window.document.getElementById('hour_select');
  day = select1.value;
  hour = select2.value;
 //alert(day + '___' + hour);
  xajax_showSchedule(0, day, hour);
  window.document.getElementById('sel_model').value = "0";
}
//********************
function clearMail() {
  type = window.document.getElementById('mail_type_select_0');
  select = window.document.getElementById('model_select_0');
  subject = window.document.getElementById('subject_input');
  textarea = window.document.getElementById('message_area');
  //type.selected=true;
  if (select != null) select.selected=true;
  subject.value='';
  textarea.value='';
}
function sendMail(uid) {
  type = window.document.getElementById('mail_type_select');
  if (type.value == 0) select = window.document.getElementById('model_select').value;
  else select = 1;
  subject = window.document.getElementById('subject_input');
  textarea = window.document.getElementById('message_area');
  button = window.document.getElementById('btn_send');
  if (select == 0) {
    alert("The recipient must be selected");
  } else {
    button.disabled=true;
    xajax_sendMail(uid, type.value, select, subject.value, textarea.value);
  }
}
function mark(what) {
  j=true;
  i=0;
  while(j==true) {
    checkbox = window.document.getElementById('check_'+i);
    if(checkbox) {
      if(what == 0) checkbox.checked = false;
      if(what == 1) checkbox.checked = true;
      i++;
    } else {
      j=false;
    }
  }
}
function deleteMessages(path) {
  j=true;
  i=0;
  var messages=new Array();
  while(j==true) {
    checkbox = window.document.getElementById('check_'+i);
    hidden = window.document.getElementById('hide_'+i);
    if(checkbox) {
      if(checkbox.checked==true) messages[i]=hidden.value;
      i++;
    } else {
      j=false;
    }
  }
  xajax_moveMail(messages, path, 0);
}
function usePromoCode() {
  input = window.document.getElementById('code_input').value;
  xajax_usePromoCode(input);
}
function freelogin() {
  chatname = window.document.getElementById('chat_name_txt').value;
  if (chatname == '') alert("Input name!");
  else xajax_loginForFree(chatname);
}

function clearSupport() {
  window.document.getElementById('text_mail').value = "";
  window.document.getElementById('text_phone').value = "";
  window.document.getElementById('text_name').value = "";
  window.document.getElementById('text_company').value = "";
  window.document.getElementById('text_question').value = "";
  window.document.getElementById('text_subject').value = "";
}
function sendSupport(uid) {
  mail = window.document.getElementById('text_mail').value;
  phone = window.document.getElementById('text_phone').value;
  name = window.document.getElementById('text_name').value;
  company = window.document.getElementById('text_company').value;
  subject = window.document.getElementById('text_subject').value;
  question = window.document.getElementById('text_question').value;
  if (mail == '') alert("Enter your e-mail address!");
  else {
    if (subject == '') alert("Enter subject!");
    else {
      if (question == '') alert("Enter your question!");
      else xajax_sendToSupport(uid, mail, phone, name, company, subject, question);
    }
  }
}
function vopen(imgf,name,imgW,imgH){
  var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  var maxW = screen.availWidth;
  var maxH = screen.availHeight;

  centerW=(maxW-imgW)/2;
  centerH=(maxH-imgH)/2;
  if(isIE) centerH -=20;
  imgWindow=window.open(imgf, 'v', 'top='+centerH+',left='+centerW+',width='+imgW+',height='+imgH+',resizable=0');
  imgWindow.focus();
}
function iopen(imgf,name,imgW,imgH,next,prev,first,sshow){
  var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  var maxW = screen.availWidth;
  var maxH = screen.availHeight;
  var pscroll='0';
  var centerW=(maxW-imgW)/2;
  var centerH=(maxH-imgH)/2;
  if(isIE) centerH -=20;
  ((imgW>maxW || imgH>maxH))? pscroll='1' : pscroll='0';
  imgWindow=window.open('/e/fimage.php?p='+imgf+'&n='+name+'&iw='+imgW+'&ih='+imgH+'&img_n='+next+'&img_p='+prev+'&img_f='+first+'&sshow='+sshow, 'i', 'top='+centerH+',left='+centerW+',width='+imgW+',height='+imgH+',resizable=1,scrollbars='+pscroll);
  imgWindow.focus();
}
function show_video(encodedId,encodedResourceId) {
  generate(encodedResourceId);
  show_video_pause(encodedId, encodedResourceId);
}
function show_video_pause(encodedId,encodedResourceId){
  setTimeout("top.xajax_preview('"+encodedId+"', '2', '"+encodedResourceId+"');",500);
}

  /**
   * Returns a list of elements on root which have a clsName class
   */
function getElementsByClassName ( root, clsName, clsIgnore )
  {
    var i, matches = new Array();
    var els = root.getElementsByTagName('*');
    var rx1 = new RegExp('.*'+clsName+'.*');
    var rx2 = new RegExp('.*'+clsIgnore+'.*');
    for(i=0; i<els.length; i++) {
      if(els.item(i).className.match(rx1) && (clsIgnore == '' || !els.item(i).className.match(rx2))) {
	      matches.push(els.item(i).id);
      }
    }
    return matches;
  }

function showClass(root, clsName, clsIgnore, show)
  {
    var elts = this.getElementsByClassName(root, clsName, clsIgnore);
    for(var i = 0; elts.length > i; i++) {
      //alert (elts[i]);
      if (show) root.getElementById(elts[i]).style.display = "inline";
      else root.getElementById(elts[i]).style.display = "none";
    }
  }

function showColor(root, clsName, clsIgnore, show)
  {
    //var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
    var elts = this.getElementsByClassName(root, clsName, clsIgnore);
    for(var i = 0; elts.length > i; i++) {
      colorf = 'c'+elts[i];
      //alert('colorf: '+colorf);
      if (show) root.getElementById(elts[i]).style.color = root.getElementById(colorf).value;
      else root.getElementById(elts[i]).style.color = 'black';
    }
  }
function hidecolor(template_url) {
  var id = 'chat_frame_'+window.document.getElementById('id_chat').value; 
  var cpanel = parent.frames[id].document;
  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 hidetime(template_url) {
  var id = 'chat_frame_'+window.document.getElementById('id_chat').value;
  var cpanel = parent.frames[id].document;
  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 switchsound(template_url) {
  ison = window.document.getElementById('sound_indicator').value;
  if (ison == 1) {
    document.getElementById('sound_container').innerHTML = '';
    window.document.getElementById('sound_indicator').value = 0;
    window.document.getElementById('sound_img').src = template_url + "/images/sound-off.gif";
    window.document.getElementById('sound_img').alt="Enable sound notifications";
    window.document.getElementById('sound_img').title="Enable sound notifications";
  } else {
    window.document.getElementById('sound_indicator').value = 1;
    window.document.getElementById('sound_img').src = template_url + "/images/sound-on.gif";
    window.document.getElementById('sound_img').alt="Disable sound notifications";
    window.document.getElementById('sound_img').title="Disable sound notifications";
  }
}
function playsound(template_url) {
      // plays the sound, if it's switched on
    var soundcontainer = document.getElementById('sound_container');
    var toplay = document.getElementById('sound_indicator').value;
    if (toplay == 1)
    {
      var flash = "<object style='visibility:hidden' classid='clsid:D27CDB6E-AE6D-11CF-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' width='0' height='0'>";
      flash += "<param name='movie' value='" + template_url+"/swf/sound.swf'>";
      flash += "<param name='quality' value='High'>";
      flash += "<embed style='visibility:hidden' src='"+template_url+"/swf/sound.swf' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='0' height='0' />";
      flash += "</object>";
      soundcontainer.innerHTML = flash;
    } else {
      soundcontainer.innerHTML = "";
    }
}
function checkChanges() {
  var online = window.document.getElementById('hidden_online');
  if (null === window.document.getElementById('hidden_online')) { clearInterval(refreshInt); return; }
  else xajax_checkChanges(online.value);
  //alert(online);
}
function sendPrivateDelay(enc_id, type, user_name) {
  var btn_private = window.document.getElementById('btn_private_td');
  btn_private.innerHTML="";
  xajax_generateGallery(enc_id,type);
  this.inviteToPrivate();
  var privateDelay = setInterval("activatePrivateBtn('"+enc_id+"','"+type+"','"+user_name+"');",30000);
}
function activatePrivateBtn(enc_id, type,user_name) {
  var btn_private = window.document.getElementById('btn_private_td');
  if(null !== btn_private) btn_private.innerHTML="<a id=\"btn_private\" onclick=\"sendPrivateDelay('"+enc_id+"',"+type+");return false;\" class=\"cams\">Take "+user_name+" into private 1 on 1 show</a>";
}
function createMail(a, b, c) {
  var subject = window.document.getElementById('subject_input').value;
  var body = window.document.getElementById('message_area').value;
  xajax_createMail(a, b, c, subject, body);
}
// Free chat
function showLoginOrChangeForm(type) {
  var free_chat_change = window.document.getElementById('free_chat_change');
  var free_chat_login = window.document.getElementById('free_chat_login');

  if(free_chat_change && free_chat_login) {
    if(type == 1) {
      // Login form
      free_chat_change.style.display='none';
      free_chat_login.style.display='';
    } else {
      // Change form
      free_chat_change.style.display='';
      free_chat_login.style.display='none';
    }
  }
}
function login_to_pay(max) {
  var email = window.document.getElementById('email_toPay').value;
  var pass = window.document.getElementById('pass_toPay').value;
  if (null !== window.document.getElementById('amountToPay') && window.document.getElementById('amountToPay').value != 0) {
    var amount = window.document.getElementById('amountToPay').value; 
  } else {
    var amount = 0;
    for (var i=1; i<=max; i++) {
      //var checked = false;
      if (window.document.getElementById('amount_'+i).checked==true) amount = window.document.getElementById('amount_'+i).value;
    }
    var paymethod = 0;
  }
  if (null !== window.document.getElementById('payment_method')) paymethod = window.document.getElementById('payment_method').value;
  if (amount == 0) alert("You have to select amount.");
  else xajax_checkLoginForPay(email, pass, amount, paymethod);
}
function payLater() {
  var check = window.document.getElementById('pay_later_check').checked;
  for (var i=1; i<5; i++) {
    window.document.getElementById('amount_'+i).disabled = check;
  }
}
function updateTime(suffix) {
  if (null !== document.getElementById('timeInput'+suffix)) {
    var ddate = document.getElementById('timeInput'+suffix).value;
    ddate = parseInt(ddate) + 1000;
    var adate = new Date("month day year hours:minutes:seconds");
    adate.setTime(ddate);
    var hhmmss = adate;
    document.getElementById('clock'+suffix).innerHTML = hhmmss;
    document.getElementById('timeInput'+suffix).value = ddate;
    if (suffix != "" && null !== document.getElementById('timeView'+suffix)) { //using in booking
      //window.document.getElementById('timeDiff'+suffix).value = (adate.getTimezoneOffset() / 60) * -1; 
      var month = adate.getMonth() + 1; 
      var ddate = adate.getDate(); 
      var year = adate.getYear(); 
      
      var hh = adate.getHours();
      if (hh < 10) hh = "0" + hh; 
      //window.document.getElementById('hh'+suffix).value = hh; 
      var mm = adate.getMinutes(); 
      if (mm < 10) mm = "0" + mm; 
      //window.document.getElementById('mm'+suffix).value = mm; 
      var ss = adate.getSeconds();
      if (ss < 10) ss = "0" + ss; 
      //window.document.getElementById('ss'+suffix).value = ss;  
      window.document.getElementById('timeView'+suffix).innerHTML = ddate + "/" + month + "/" + (Number(year)+1900) + "  <b>" + hh + ":" + mm + "</b>:" + ss;  
      if (null !== window.document.getElementById('bookingTimeControls')) {
        window.document.getElementById('bookingTimeControls').style.display = ''; 
      }
      //window.document.getElementById('timeView'+suffix).innerHTML = hhmmss;  
    }
    var updateTimeInterval = setTimeout("updateTime('" + suffix + "');",1000);
  }
}
function changeTime(value, suffix) {
  if (null !== window.document.getElementById('timeInput' + suffix)) {
    var newTime = Number(window.document.getElementById('timeInput' + suffix).value) + Number(value * 60000); 
    window.document.getElementById('timeInput' + suffix).value = newTime; 
    if (null !== window.document.getElementById('timeDiff'+suffix)) {
      window.document.getElementById('timeDiff'+suffix).value = Number(window.document.getElementById('timeDiff'+suffix).value) + Number(value); 
    }
  }
}
function updateModels() {
  updatingNow = 1; 
    if (null !== document.getElementById('invitations_result')) {
      invitation = 3;  
    } else {
      invitation = 0;  
    }
    xajax_checkNewInvitations();

  if ((null !== document.getElementById('update_filter'))&&(null !== document.getElementById('update_filter_s'))&&(null !== document.getElementById('update_filter_h'))&&(null !== document.getElementById('update_filter_r'))&&(null !== document.getElementById('update_filter_a'))&&(null !== document.getElementById('update_filter_height'))&&(null !== document.getElementById('update_filter_weight'))&&(null !== document.getElementById('update_filter_profession'))&&(null !== document.getElementById('update_filter_language'))&&(null !== document.getElementById('update_filter_h_cntry'))&&(null !== document.getElementById('update_filter_h_state'))&&(null !== document.getElementById('update_filter_cntry'))&&(null !== document.getElementById('update_filter_state'))&&(null !== document.getElementById('update_adv_search'))&&(null !== document.getElementById('update_page'))&&(null !== document.getElementById('update_filter_eye'))) {
    var to = document.getElementById('update_filter').value; 
    var tos = document.getElementById('update_filter_s').value;
		var toh = document.getElementById('update_filter_h').value;
    var tor = document.getElementById('update_filter_r').value;
    var toa = document.getElementById('update_filter_a').value;
    
    var to_eye = document.getElementById('update_filter_eye').value;
    var to_he = document.getElementById('update_filter_height').value;
    var to_we = document.getElementById('update_filter_weight').value;
    var to_pr = document.getElementById('update_filter_profession').value;
    var to_lang = document.getElementById('update_filter_language').value;
    var to_hc = document.getElementById('update_filter_h_country').value;
    var to_hs = document.getElementById('update_filter_h_state').value;
    var to_c = document.getElementById('update_filter_country').value;
    var to_s = document.getElementById('update_filter_state').value;
    
    var to_adv = document.getElementById('update_adv_search').value;
    var to_pg = document.getElementById('update_page').value;
    if (to !== "false" && tos !== "false" && toh !== "false" && tor !== "false" && toa !== "false" && to_he !== "false" && to_we !== "false" && to_pr !== "false" && to_lang !== "false" && to_hc !== "false" && to_hs !== "false" && to_c !== "false" && to_s !== "false" && to_adv !== "false" && to_pg !== "false") {
    	xajax_checkChanges(to, tos, toh, tor, toa, invitation, to_adv, to_pg, to_eye, to_he, to_we, to_pr, to_lang, to_hc, to_hs, to_c, to_s);  
    }
  } else {
    if (null !== document.getElementById('top_rating_table')) {
      xajax_checkChanges(0,0,0,0,0,1);  
    }                   
    if (null !== document.getElementById('favorites_table')) {
      xajax_checkChanges(0,0,0,0,0,2);  
    }    
  }
  updatingNow = 0; 
}
function countOnline() {
  updatingNow = 1;
  var browser=navigator.appName;
  var b_version=navigator.appVersion;
  var version=parseFloat(b_version);
  var forOldIE = 0;
  if (null !== window.document.getElementById('forOldIE')) forOldIE = window.document.getElementById('forOldIE').value;
  if (browser == "Microsoft Internet Explorer" && version == 4 && forOldIE == 1) {} //we are on profile/photo(video), so do nothing, IE 6.0 is a BigBug
  else {
    //alert("updating");
    xajax_countOnline();
  }
  //setTimeout("countOnline();", 3000);
  updatingNow = 0;
}
function createSwf(id, flashVars, resUrl, thW, thH) {
  var filter = window.document.getElementById('update_filter').value;
  if (filter != "false") {
    if (null !== window.document.getElementById('temp_value')) window.document.getElementById('temp_value').value = filter;
    if (null !== window.document.getElementById('update_filter')) window.document.getElementById('update_filter').value = "false";
  }
  if (null !== window.document.getElementById("check_div_" + id)) {
    var swf = new flash ();
    if (thW > 0) {} else thW = 100; 
    if (thH > 0) {} else thH = 100; 
    swf.setSWF (resUrl + '/thPlayer.swf', thW, thH, 8);
    swf.setParam ('bgcolor', '#000000');
    swf.setParam ('quality', 'high');
    swf.setParam ('flashvars', flashVars);
    var out = swf.display ();
    insFlashTimeout = setTimeout("top.insertFlash('"+out+"', '"+id+"');", 1000); 
  }
}
function insertFlash(out, id) {
  var td = window.document.getElementById('mdiv_' + id);
  td.innerHTML=out;  
}
function fromFlashStreamThumb(id) {
}
function changeBack() {
  clearTimeout(insFlashTimeout); 
  var filter = window.document.getElementById('temp_value').value;
  window.document.getElementById('update_filter').value = filter;
}
function createVideoThumb(id, resUrl, flashVars) {
  var swf = new flash ();
  swf.setSWF (resUrl + '/thPlayer_video.swf', 100, 100, 8);
  swf.setParam ('wmode', 'transparent');
  swf.setParam ('bgcolor', '#000000');
  swf.setParam ('quality', 'high');
  swf.setParam ('flashvars', flashVars);
  var out = swf.display ();
  var td = window.document.getElementById("tdv_"+id);
  if (null !== td) td.innerHTML = out;
}
function fromFlashVideoThumb(id, resType, resId) {
  //alert(id + "_" + resId);
  xajax_preview(id, resType, resId);
}
function changeContent(id) {
  var src = window.document.getElementById("tdv_hidden_"+id);
  var destination = window.document.getElementById("tdv_"+id);
  destination.innerHTML = src.innerHTML;
}
//
// Creeping line functions
// --->
function scrollmarquee(){

  str = document.getElementById("creeping_line_span").innerHTML;
  if(str != "" && document.getElementById("creeping_line_span").offsetWidth) {

    if(!start) populate();
    actualwidth=document.all? creeping_line_span.offsetWidth : document.getElementById("creeping_line_span").offsetWidth
    if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8)) {
      cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
    } else {
      cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
      if(lefttime) {
        clearInterval(lefttime);
        lefttime=0;
      }
    }
  } else {
    start = 0;
    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
    cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
  }
}

function populate(){
  if(!lefttime) {
    start = 1;
    str = document.getElementById("creeping_line_span").innerHTML;
    cross_marquee=document.getElementById("iemarquee");
    cross_marquee.innerHTML=str;
    cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
    if(window.navigator.userAgent.indexOf ("Gecko") >= 0 )  lefttime=setInterval("scrollmarquee()",40)
    else lefttime=setInterval("scrollmarquee()",20)
  }
}
// <---
// Creeping line functions
//
function setPaypalAmount(amount, credit, item_name) {
  form = document.getElementById("paypal_form");
  form.amount.value = amount;
  form.credit.value = credit;
  form.item_name.value = item_name;
  form.submit();
}

function addToFavorites (url, title) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	}
}
function checkMethod(frmId) {
  if (null !== window.document.getElementById('payment_method')) {
    window.document.getElementById('formName_' + frmId).value = window.document.getElementById('payment_method').value;
  }
}

function enableButtonFun(formId, buttonId, str){
  var btn=window.document.getElementById(formId).elements[buttonId];
  btn.disabled=false;
  btn.value=str;  
}
function disableButtonFun(formId, buttonId, str){
  var btn=window.document.getElementById(formId).elements[buttonId];
  btn.disabled=true;
  btn.value=str;
}
function saveProfile(uid, obj, type) {
  var formId = obj.elements['formId'].value;
  disableButtonFun(formId, 'submitEditModel'+uid, "Processing...");
  xajax_saveProfile(uid, top.xajax.getFormValues(formId), type);
}

function inviteToPrivateFromMain(encUid){
  var formItem = "toprivate_" + encUid;
  var formToSubmit = window.document.forms["m_" + encUid];
  window.document.getElementById(formItem).value='1';
  formToSubmit.submit();
  return false;
}
function reloadPlayer(encId) {
  window.document.getElementById("player").style.height = 224; 
  //window.document.getElementById("player").innerHTML = encId; 
  xajax_reloadPlayer(encId); 
}
function reloadThumb(encId) {
  xajax_reloadThumb(encId); 
}
function addChatInfo(memb,data) {
  info = document.getElementById(memb+'_moneyinfo').innerHTML;
  if(null !== document.getElementById('stream_closed')) {
  document.getElementById('stream_closed').innerHTML = data;
  } else {
    document.getElementById(memb+'_moneyinfo').innerHTML = info+'<div id=\'stream_closed\'>'+data+'</div>';
  }
}
function checkPlaying() { //PPEV
  //alert(window.document.getElementById('showNow')); 
  if (null !== window.document.getElementById('showNow')) {
    var playValue = window.document.getElementById('showNow').value; 
    if (playValue != "") xajax_checkPPEVTime(playValue); 
  }
}
var ppmInterval = 0; 
function checkPPM(stop) {
  if (stop != 1) {
    if (null !== window.document.getElementById('showNow')) {
      var playValue = window.document.getElementById('showNow').value; 
      if (playValue != "") xajax_checkPPM(playValue); 
    }
  } else clearInterval(ppmInterval); 
}
function checkVersion(requiredMajorVersion, requiredMinorVersion, requiredRevision, containerId, flashVars, toCheck, swf, root, objW, objH) {
  var hasReqestedVersion; 
  if (toCheck==1) hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  else hasReqestedVersion = true; 
  //alert("required: " + hasReqestedVersion); 
  if (hasReqestedVersion) {
	  // if we've detected an acceptable version
	  // embed the Flash Content SWF when all tests are passed
	  var object = AC_FL_RunContent(
	  	"wmode", "transparent",
		  "src", root+"/"+swf,
			"width", objW,
			"height", objH,
			"align", "middle",
			"id", swf,
			"quality", "high",
			"bgcolor", "#000000",
			"name", swf,
			"allowScriptAccess","always",
			"type", "application/x-shockwave-flash",
			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
			"pluginspage", "http://www.adobe.com/go/getflashplayer", 
			'flashVars', ""+flashVars+"", 
			'allowFullScreen', 'true'
	  );
	  //alert("OK: " + object); 
	  window.document.getElementById(containerId).innerHTML = object; 
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = "<div align='center' style='height:"+objH+"px;width:"+objW+"px;background-color:#000000;padding-top:50px;color:#FFFFFF;align:center;'>"
    + "This content requires the Adobe Flash Player " + requiredMajorVersion + "." + requiredMinorVersion + "." + requiredRevision + " (or later).<br>"
    + "<a href='http://www.adobe.com/go/getflash/' target='_blank' class='cams'>Get Flash</a></div>"
	  window.document.getElementById(containerId).innerHTML = alternateContent;  // insert non-flash content
	  
  }  
}
function getRegions(obj, s_mi_id){
	var root = window.document;
  if(obj.value=='-1'){
    root.getElementById('state_holder_id').style.display='none'; 
  } else {
    root.getElementById('state_holder_id').style.display=''; 
    xajax_getRegions(top.xajax.getFormValues('edit_model_rprof2_'+s_mi_id), 'edit_model_rprof2_'+s_mi_id);
  }
  
  //document.forms['std_register'].elements['state'].disabled=true;
  //xajax_getRegions(xajax.getFormValues('std_register'));
}
var overRate = 0; 
var lines = 0; 
var items = 0; 
function rateOnMove(enc, line, num) {
  //alert(lines+"_"+items+"_"+line+"_"+num); 
  //alert(overRate);
  if (overRate==1) {
    for (var ln=1;ln<=lines;ln++) {
      //for (var i=1;i<=num;i++) {
      for (var i=1;i<=items;i++) {
        //if (line == ln) {
        if (line == ln && i<=num) {
          window.document.getElementById(enc+'container_'+ln+'_'+i).style.display="none";  
          window.document.getElementById(enc+'push_'+ln+'_'+i).style.display="";  
        } else {
          window.document.getElementById(enc+'container_'+ln+'_'+i).style.display="";  
          window.document.getElementById(enc+'push_'+ln+'_'+i).style.display="none";            
        }
      }
    }
  } else {
    for (var i=1;i<=num;i++) {
      window.document.getElementById(enc+'container_'+line+'_'+i).style.display="";  
      window.document.getElementById(enc+'push_'+line+'_'+i).style.display="none";  
    }  
  }
}
var speed = 0;
function textFormat(speed) {
  div = window.document.getElementById('textFormat');
  //alert('div :'+div.innerHTML);
  if(div.innerHTML == '') top.xajax_tFormatWww(speed);
  else div.innerHTML='';
}

var d=window.document;
var Columns=16;
function drawPalette(p){
	s=d.getElementById(p).value;
  a=s.match(/#(\w{6})/ig);    //for  hex- #CCCCCC,#999999,#666666,...
  j=0;s2='<table bgColor=black>';
  while(a[j]){
  	s2+='<tr>';
    for(i=0;i<Columns;i++)if(a[j])s2+='<td'
    	+'  style=\"font-size:4px;cursor:pointer;background-color:'+a[j++]+';\" width=\"4\" height=\"5\" onclick=\"selectColor(this);change_all();\"></td>';
      s2+='</tr>';
  }
  //d.body.innerHTML+=s2+'</table>';
   d.getElementById("palette").innerHTML += s2+'</table>';
}
// selectColor
function selectColor(div) {
	 var color = div.style.backgroundColor;
	 //alert("color: "+color+"div: "+div);
	 color = rgbNormal(color);
	 window.document.getElementById("font_color").value = color;
}
function rgbNormal(color) {
	 color = color.toString();
	 var re = /rgb\((.*?)\)/i;
	 if(re.test(color)) {
		 compose = RegExp.$1.split(",");
		 var hex = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
		 var result = "#";
		 for (var i = 0; i < compose.length; i++) {
			 rgb = parseInt(compose[i]);
			 result += hex[parseInt(rgb / 16)] + hex[rgb % 16];
		 }
		 return result;
	 } else return color;
}
	function change_all()
{
	window.document.getElementById("text_example").innerHTML = '<span style=\"font-family:'+window.document.getElementById("font_face").value+';font-size:'+window.document.getElementById("font_size").value+'px; color:'+window.document.getElementById("font_color").value+';font-weight:normal; \">>>>Your text in chat<<<</span>';
}
function changeColor(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('chat_frame_'+chat_id).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);
  }
  cpanel.getElementById('chat_panel').style.fontSize = size;
}
function ssopen(ssf,name,imgW,imgH){
  var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  var maxW = screen.availWidth;
  var maxH = screen.availHeight;

  centerW=(maxW-imgW)/2;
  centerH=(maxH-imgH)/2;
  if(isIE) centerH -=20;
  imgWindow=window.open(ssf, name, 'top='+centerH+',left='+centerW+',width='+imgW+',height='+imgH+',resizable=1,scrollbars=1');
  imgWindow.focus();
}
//*************
function swapColor(id, bgcolor, color) {
if (bgcolor != '') { document.getElementById(id).style.backgroundColor = bgcolor; }
if (color != '') { document.getElementById(id).style.color = color; }
}
//*************
function addComment(encResId, comment, comm_type) {
 	xajax_addCommentHON(encResId, comment, comm_type);
}
//*************
function save_blog(modelId, post_id) {
  mood = window.document.getElementById('mood_other');
  preview = window.document.getElementById('mood_preview_td');
  music = window.document.getElementById('music_input');
  post = window.document.getElementById('post_body');
  subject = window.document.getElementById('subject_input');
  location1 = window.document.getElementById('location');
  access = window.document.getElementById('can_see').value;
  keys = window.document.getElementById('key_input').value;
  xajax_modelBlogSave(modelId, subject.value, mood.value, music.value, post.value, location1.value, post_id, access, keys);  
}
//*************
function clear_blog() {
  mood = window.document.getElementById('mood_other');
  preview = window.document.getElementById('mood_preview_td');
  music = window.document.getElementById('music_input');
  post = window.document.getElementById('post_body');
  subject = window.document.getElementById('subject_input');
  location1 = window.document.getElementById('location');
  keys = window.document.getElementById('key_input');
  mood.value="";
  subject.value = "";
  music.value = "";
  post.value = "";
  keys.value = "";
  location1.value = "";
}
function showVideoDesc(id, desc, from_prof){
	var coords = top.getCoords(window.document.getElementById(id));
	var div = window.document.getElementById('vd_top_div');
	var isMSIE = /*@cc_on!@*/false;
	
  if (from_prof) {
  	div.style.left = (coords['left']+25) + 'px';
  	if(isMSIE) div.style.top = (coords['top']+80) +'px';
  	else div.style.top = (coords['top']+80) +'px';
  } else {
  	div.style.left = (coords['left']+25) + 'px';
  	if(isMSIE) div.style.top = (coords['top']+100) +'px';
  	else div.style.top = (coords['top']+0) +'px';
  }
  //alert("coords['top']: "+coords['top']);
  if(desc && desc != '') window.document.getElementById('vd_body').innerHTML = desc;
  else window.document.getElementById('vd_body').innerHTML = 'This video has no description.';
	div.style.visibility = 'visible';
}
// Determine position & size of element
function getCoords(element) {
    var left = element.offsetLeft;
    var top = element.offsetTop;
    var i=2;
    for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
      left += parent.offsetLeft;
      top += parent.offsetTop;
    }
    return {
    	left: left,
    	top: top,
    	width: element.offsetWidth,
    	height: element.offsetHeight
    };
}
function blink_unread_mail(black, stop) {
	//alert(black);
	clearInterval(blink_mail); 
	clearTimeout(blink_mail_t);
	if(stop == 1) {
		clearInterval(blink_mail); 
		clearTimeout(blink_mail_t);
		blink_mail = 0;
		blink_mail_t = 0;
	} else {
		if(black == 0) {
			window.document.getElementById('mail_info_blink').style.color = "#FF0000";
			window.document.getElementById('mail_info_blink').style.fontWeight = "bold";
		}
		else {
			window.document.getElementById('mail_info_blink').style.color = "#000000";
			window.document.getElementById('mail_info_blink').style.fontWeight = "normal";
		}
		clearInterval(blink_mail);
		clearTimeout(blink_mail_t); 
		if(black == 0) blink_mail_t = setTimeout("top.blink_unread_mail(1,0);", 500);
		else blink_mail_t = setTimeout("top.blink_unread_mail(0,0);", 500);
	}
	//alert("blink_mail: "+blink_mail+", blink_mail_t: "+blink_mail_t+", stop: "+stop);
}

function addCommentInProfile(encResId, comment, comm_type) {
 	xajax_addComment(encResId, comment, comm_type);
}

function showPhotoFromMain(encUid){
  var formItem = "thAction_"+encUid;
  //alert("formItem: "+formItem);
  var formToSubmit = window.document.forms["m_" + encUid];
  window.document.getElementById(formItem).value = '7';
  //alert("window.document.getElementById(formItem).value: "+window.document.getElementById(formItem).value);
  formToSubmit.submit();
  return false;
}
function showVideoFromMain(encUid){
  var formItem = "thAction_"+encUid;
  //alert("formItem: "+formItem);
  var formToSubmit = window.document.forms["m_" + encUid];
  window.document.getElementById(formItem).value = '8';
  formToSubmit.submit();
  return false;
}
function sendModelMail(enc_id) {
  mail = window.document.getElementById('text_mail').value;
  phone = window.document.getElementById('text_phone').value;
  name = window.document.getElementById('text_name').value;
  company = window.document.getElementById('text_company').value;
  subject = window.document.getElementById('text_subject').value;
  question = window.document.getElementById('text_question').value;
  
  window.document.getElementById('bt_send').value = "...";
  window.document.getElementById('bt_send').disabled == true;
  if (mail == '') alert("Enter your e-mail address!");
  else {
    if (subject == '') alert("Enter subject!");
    else {
      if (question == '') alert("Enter your question!");
      //$enc_id, $action = 0, $aFormValues
      else xajax_sendModelMail(enc_id, 1, mail, phone, name, company, subject, question);
    }
  }
}
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}