var shotStr = ""; 
var resUrl = ""; 
var updatingNow = 0; //needed to do not show wait cursor during updating lists

function createVideoThumbVod(id, resUrl, flashVars, sizeW, sizeH) {
  var swf = new flash ();
  swf.setSWF (resUrl + '/thPlayer_vod.swf', sizeW, sizeH, 8); 
  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) {
  if (window.document.getElementById('isDetails') === null) {
    window.location = "/selectedVideo/"+id;
  } else {
    xajax_play(resId, 1); 
  }
}
function backLoginForm() {
  if (null === window.document.getElementById('isLoginForm')) {
    xajax_backLoginForm(); 
  } else { 
    setTimeout("backLoginForm();", 2000); 
  }
}
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 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 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 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); 
}

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 {
    // alert("Paymethod: " + paymethod);
    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 ss_fullView(id, w, h) {
  window.open(resUrl+"/"+id, 'Screenshot', 'width='+w+',height='+h+',resizable=0,left=300,top=250'); 
  //window.open(resUrl+"/"+id, '', ''); 
}

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();
}
var ppmInterval = 0; 
function checkPPM_VOD(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); 
}
var overRate = 0; 
var lines = 0; 
var items = 0; 
function rateOnMove(enc, line, num) {
  ///alert(lines+"_"+items); 
  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";  
    }  
  }
}
function thisMovie(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
var jsReady = true; 
var ssIds=new Array();
function isReady() {
  return jsReady;
}
function giveIds() {
  return ssIds;
}
function insertScreenShots(resUrl, h, w) {
  var swf = new flash ();
  swf.setSWF (resUrl + '/screenShots.swf', w, h, 8, "ssMovie"); 
  swf.setParam ('bgcolor', '#000000');
  swf.setParam ('quality', 'high');
  swf.setParam ('allowScriptAccess', 'always'); 
  swf.setParam ('flashvars', 'resRoot='+resUrl);
  var out = swf.display ();
  var container = window.document.getElementById("SSContainer");
  if (null !== container) container.innerHTML = out; 
  jsReady = true;
  //thisMovie("ssMovie").sendToActionScript("abc");
}
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);
}
var commentInt; 

//********************
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 overLine(id) {
  window.document.getElementById('line_'+id).style.background = "#777777"; 
  window.document.getElementById('line_'+id).style.color = "#FFFFFF"; 
  window.document.getElementById('controls_'+id).style.display = ""; 
}
function outLine(id) {
  window.document.getElementById('line_'+id).style.background = ""; 
  window.document.getElementById('line_'+id).style.color = "#CCCCCC"; 
  window.document.getElementById('controls_'+id).style.display = "none"; 
}
function moveUp(id, price, currency, sId) {
  var ok=0; 
  if (price != 0) {
    if (confirm('Moving up the movie will cost you '+currency+price+', please, confirm.')) {
      ok = 1; 
    }
  } else ok = 1; 
  if (ok == 1) xajax_videoTv_moveItemUp(id);//window.location = '/videoTvPlaylist.php?moveUp='+id+'&sId='+sId;
}
function checkMethod(frmId) {
  if (null !== window.document.getElementById('payment_method')) {
    window.document.getElementById('formName_' + frmId).value = window.document.getElementById('payment_method').value; 
  }
}


function tv_refreshChannels() {
  var form = document.forms['filters_form'];
  if (null !== form) {
    var values = {};
    values.category = form.category_select.value;
    values.payFilter = 0;
    if (form.check_free.checked) values.payFilter += 1;
    if (form.check_allowed.checked) values.payFilter += 2;
    if (form.check_other.checked) values.payFilter += 4;
    if (form.check_live.checked) values.payFilter += 8;
    if (form.check_all.checked) {
      values.payFilter = 15;
    }
    xajax_tv_refresh_channels(values); 
  }
}
function tv_clearAllFilters() {
  var form = document.forms['filters_form'];
  if (null !== form) {
    form.check_other.checked = false; form.check_free.checked = false; form.check_allowed.checked = false;
  }
}
function tv_clearAllFilter() {
  var form = document.forms['filters_form'];
  if (null !== form) {
    form.check_all.checked = false;
  }
}

var winW = 0; var winH = 0; var bottomH = 0; var containerH = 0;
function tv_setSizes() {
  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
    }
  }
  containerH = winH - 200;
  window.document.getElementById('controls').style.height = containerH;
  window.document.getElementById('player').style.height = containerH;
  tv_resizeChannels();
}
function tv_resizeChannels() {
  if (null !== window.document.getElementById('channels')) {
    window.document.getElementById('channels').height = winH - 300;
  } else {
    setTimeout('tv_resizeChannels();', 500);
  }
}

var flex_container_id = "";
var vPlayer_flex_id = 'vPlayer_flex';
function changeFullWindowSize(w, h, flex_container_id) {
  
  var all_content = document.getElementById('all_content');
  var only_video_player = document.getElementById('only_video_player');
  var flex_container = document.getElementById('videoViewContainer');
  if(flex_container_id != "") {
    flex_container_id = flex_container_id;
  } else {
    flex_container_id = 'videoViewContainer';
  }
  //alert("video_id: "+video_id);
  //alert("flex_container_id: "+flex_container_id);
  var flex_container = document.getElementById(flex_container_id);
    
  if(!document.getElementById(vPlayer_flex_id)) {
    vPlayer_flex_id = 'player';
  }
  var vPlayer_flex = document.getElementById(vPlayer_flex_id);
  var video_content = "";
  var mode = "";
  
  if(vPlayer_flex.style.width == "100%") mode = 'n';
  else mode = 'f';
    
  w = (w != undefined)?w:730;
  h = (h != undefined)?h:400;
  //alert("mode: "+mode);
  if(mode == "f")  {    
    
    //alert("flex_container.innerHTML: "+flex_container.innerHTML);
    video_content = flex_container.innerHTML;
    //alert("video_content: "+video_content);
    flex_container.innerHTML = "";
    all_content.style.display = "none";
    only_video_player.innerHTML = video_content;
    only_video_player.style.display = "block";
    
    setTimeout(''
      +'document.getElementById("'+vPlayer_flex_id+'").width = "100%";'
      +'document.getElementById("'+vPlayer_flex_id+'").style.width = "100%";'
      +'document.getElementById("'+vPlayer_flex_id+'").height = "100%";'
      +'document.getElementById("'+vPlayer_flex_id+'").style.height = "100%";'
      +'document.getElementById("'+flex_container+'").width = "100%";'
      +'document.getElementById("'+flex_container+'").style.width = "100%";'
      +'document.getElementById("'+flex_container+'").height = "100%";'
      +'document.getElementById("'+flex_container+'").style.height = "100%";'
      +'', 1);
    
    only_video_player.style.zIndex = "1000";
    
  } else {
    video_content = only_video_player.innerHTML;
    only_video_player.innerHTML = "";
    
    setTimeout(''
      +'document.getElementById("'+flex_container+'").width = "'+w+'px";'
      +'document.getElementById("'+flex_container+'").style.width = "'+w+'px";'
      +'document.getElementById("'+flex_container+'").height = "'+h+'px";'
      +'document.getElementById("'+flex_container+'").style.height = "'+h+'px";'
      +'document.getElementById("'+vPlayer_flex_id+'").width = "'+w+'px";'
      +'document.getElementById("'+vPlayer_flex_id+'").style.width = "'+w+'px";'
      +'document.getElementById("'+vPlayer_flex_id+'").height = "'+h+'px";'
      +'document.getElementById("'+vPlayer_flex_id+'").style.height = "'+h+'px";'
      +'', 1);
      
    all_content.style.display = "block";
    flex_container.innerHTML = video_content;
    
    
    only_video_player.style.display = "none";
  }
}
