// Global Varriables
var pop_win_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=yes,scrollbars=yes,statusbars=yes,status=no,titlebar=yes,toolbar=no,fullscreen=no';
var pop_win_calendar_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=no,scrollbars=no,statusbars=yes,status=no,titlebar=yes,toolbar=no,fullscreen=no';
var pop_win_time_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=no,scrollbars=no,statusbars=no,status=no,titlebar=yes,toolbar=no,fullscreen=no';
var pop_win_dialogin_picture_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=no,scrollbars=no,statusbars=no,status=no,titlebar=yes,toolbar=no,fullscreen=no';
var active_color_row = '#000084';


// pagecode - name of the created window
var pagecode = "new window";
var str_div_invisible = "none";
var str_div_visible   = "inline";


// open a note window
function ShowNote(URL)
{
  if(URL!=null)
  {
    ShowTable(URL,500,300);
  }
}


// get contact persons of the given company
function ShowCodeContacts(URL)
{
  if(URL!=null)
  {
    ShowTable(URL,400,300);
  }
}


/* get date selection table

   URL = page to open by window.open including 'field_id' param wich will hold the date value
   E.g. URL=calendar.htm?field_id=date
*/
function ShowCodeDate(URL)
{
  if(URL!=null)
  {
    ShowTable(URL,350,196,pop_win_calendar_params);
  }
}


// get time selection window
function ShowCodeTime(URL)
{
  if(URL!=null)
  {
    okno=popWin(URL,200,100,'pagecode','pagecode_window',pop_win_time_params);
    okno.focus();
  }
}


// open contact detail window
function ShowContactsDetail(URL)
{
  if(URL!=null)
  {
    okno=popWin(URL,400,300,'detail','contact_detail',pop_win_params);
    okno.focus();
  }
}


// open contact history window
function ShowHistoryContactsDetail(URL,i_move_x,i_move_y)
{
  if(URL!=null)
  {
    okno=popWin(URL,640,440,'detail','contact_history_detail',pop_win_params,i_move_x,i_move_y);
    okno.focus();
  }
}


// show popup menu
function ShowTable(URL,i_width,i_height,s_params,i_move_x,i_move_y)
{
  if(i_height==null)
  {
    i_height=200;
  }
  if(i_width==null)
  {
    i_width=300;
  }
  if(s_params==null)
  {
    s_params='';
  }
  if((i_move_x==null))
  {
    i_move_x=0;
  }
  if((i_move_y==null))
  {
    i_move_y = 0;
  }
  if(URL!=null)
  {
    okno=popWin(URL,i_width,i_height,'pagecode','pagecode_window',s_params,i_move_x,i_move_y);
  }
}



// create popup window named "page" + s_title
function popWin(URL,i_width,i_height,s_title,s_name,s_params,i_move_x,i_move_y,i_add_height)
{
  if(i_add_height==null)
  {
    i_add_height=16;
  }
  i_height+=i_add_height;
  var s_win_params='';
  if(parseInt(navigator.appVersion)>=4)
  {
    winl=100,
    wint=100;
  }
  var winl=(screen.width-i_width)/2;
  var wint=(screen.height-i_height)/2;
  if((i_move_x!=null)&&(typeof(i_move_x)=="number"))
  {
    winl=winl+i_move_x;
  }
  if((i_move_y!=null)&&(typeof(i_move_y)=="number"))
  {
    wint=wint+i_move_y;
  }
  day=new Date();
  if((s_params!=null)&&(s_params.length>0))
    s_win_params=s_params;
  else
    s_win_params=pop_win_params;
  eval(s_title+"=window.open('" + URL + "','" + s_name + "','" + s_win_params + ",width="+i_width+",height="+i_height+",left="+winl+",top="+wint+"');");
  eval(s_title+".focus();");
  return eval(s_title);
}



/* emphesize active table row

   Params:
   xpointer - pointer to itself (this)
   xstate   - true=active, false=inactive
   xcolor   - active color
   xbackcolor - inactive color
   without_change_cursor - no cursor change */

function colorIt( xpointer,xstate,xcolor,xbackcolor,without_change_cursor)
{
  var default_color=active_color_row;
  var deactivate_color="transparent";
  var change_cursor=true;
  if((xcolor!=null)&&(typeof(xcolor)=="string"))
  {
    default_color=xcolor;
  }
  if((xbackcolor!=null)&&(typeof(xbackcolor)=="string"))
  {
    deactivate_color=xbackcolor;
  }
  if((without_change_cursor!=null)&&(typeof(without_change_cursor)=="boolean")&&(without_change_cursor==true))
  {
    change_cursor=false;
  }
  if(xstate)
  {
    xpointer.style.background=default_color;
    if(change_cursor){
      xpointer.style.cursor='hand';
    }
  }
  else
  {
    xpointer.style.background=deactivate_color;
    xpointer.style.cursor='default';
  }
}


/* fill values in parent window

   Params:
   id - name of the item for 2-nd value
   value - stored to form's id element
   desc - description
   fill_title - if 'A' fils title of a textbox */

function Fill(id,value,desc,fill_title)
{
  if(window.opener && window.opener.open && !window.opener.closed && window.opener.document.getElementById(id))
  {
    window.opener.document.getElementById(id).value=value;
    if((desc!=null)&&(desc.length>0))
    {
      if((fill_title!=null)&&(fill_title=='A'||fill_title=='1'))
      {
        window.opener.document.getElementById(id).title='"' + desc + '"';
      }
      if(window.opener.document.getElementById(id+'_display'))
      {
        window.opener.document.getElementById(id+'_display').value=desc;
      }
    }
  }
  self.close();
}


// hide a layer
function HideLayer(layer_name)
{
  _layer=document.getElementById(layer_name);
  if(_layer)
  {
    _layer.style.display=str_div_invisible;
  }
}


// show a layer
function ShowLayer(layer_name)
{
  _layer=document.getElementById(layer_name);
  if(_layer)
  {
    _layer.style.display=str_div_visible;
  }
}


// hide div
function Hide_Back_Button(layer_name)
{
  if((layer_name!=null)&&(window.history.length==0))
  {
    HideLayer(layer_name);
  }
}


// select a project
function Active_New_Project(URL)
{
  if(URL!=null)
  {
    window.location.href=URL;
  }
}


// check comunication form validity
function Communication_Valid(form)
{
  if((typeof(form)=='object'))
  {
    if((typeof(form.subject)=='object')&&(form.subject.value==""))
    {
      form.subject.focus();
      window.alert("Předmět zprávy musíte vyplnit!");
      return false;
    }
    else if((typeof(form.message)=='object')&&(form.message.value==""))
    {
      form.message.focus();
      window.alert("Text zprávy musíte vyplnit!");
      return false;
    }
    else
      return true;
  }
  return false;
}


// check password change form validity
function ChangePassword_Valid(form)
{
  if((typeof(form)=='object'))
  {
    if((typeof(form.dialogin_oldpwd)=='object')&&(form.dialogin_oldpwd.value==""))
    {
      form.dialogin_oldpwd.focus();
      window.alert("Původní heslo musíte vyplnit!");
      return false;
    }
    else if((typeof(form.dialogin_newpwd)=='object')&&(form.dialogin_newpwd.value==""))
    {
      form.dialogin_newpwd.focus();
      window.alert("Nové heslo musíte vyplnit!");
      return false;
    }
    else if((typeof(form.dialogin_newpwdverif)=='object')&&(form.dialogin_newpwdverif.value==""))
    {
      form.dialogin_newpwdverif.focus();
      window.alert("Potvrzení nového hesla musíte vyplnit!");
      return false;
    }
    else if((typeof(form.dialogin_newpwdverif)=='object')&&(form.dialogin_newpwdverif.value!=form.dialogin_newpwd.value))
    {
      form.dialogin_newpwdverif.focus();
      form.dialogin_newpwdverif.value="";
      window.alert("Položky 'nové heslo' a 'potvrzení nového hesla' nejsou stejné!");
      return false;
    }
    else
    {
      var _oldpwd=eval("form."+"dialogin_oldpwd"+".value");
      var _newpwd=eval("form."+"dialogin_newpwd"+".value");
      var _newpwdverif=eval("form."+"dialogin_newpwdverif"+".value");
      var _oldpwd_hash=hex_md5(_oldpwd);
      var _newpwd_hash=hex_md5(_newpwd);
      form.oldpwd.value=_oldpwd_hash;
      form.newpwd.value=_newpwd_hash;
      form.newpwdverif.value=_newpwd_hash;
      eval("form."+"dialogin_oldpwd"+".value=''");
      eval("form."+"dialogin_newpwd"+".value=''");
      eval("form."+"dialogin_newpwdverif"+".value=''");
      return true;
    }
  }
  return false;
}


// reply to communication record
function FillCommunicationForm(form_name,subject,message,referer)
{
  var form_referer='0';
  if(form_name!=null)
  {
    form=document.getElementById(form_name);
    if(referer!=null)
    {
      form_referer=referer;
    }
    if(typeof(form)=='object')
    {
      if(typeof(form.subject)=='object')
      {
        form.subject.value='Re: '+subject;
      }
      if(typeof(form.referer)=='object')
      {
        form.referer.value=form_referer;
      }
      if(typeof(form.message)=='object')
      {
        form.message.value="\r\n\r\n>>"+message;
        window.scroll(0,10);
        form.message.focus();
      }
    }
  }
}


// display verification dialogue
function VerifyForm(AText)
{
  var result=window.confirm(AText);
  return result;
}


/* deactive account and redirect

   params:
   AText - window caption
   URL - redirect target    */

function DeactiveUser(AText, URL)
{
  var TopWin=window.top;
  if(VerifyForm(AText)&&(URL!=null))
  {
    TopWin.location.href=URL;
  }
}


// browse image in a window
function ShowWindowPicture(URL,i_width,i_height,i_move_x,i_move_y)
{
  if(URL!=null)
  {
    var s_param=pop_win_dialogin_picture_params;
    var i_px=60;
    if((i_width>(screen.width-i_px))||(i_height>(screen.height-i_px)))
    {
      s_param=pop_win_params;
      i_width=screen.width-i_px;
      i_height=screen.height-i_px;
    }
    okno=popWin(URL,i_width,i_height,'picture','picture_window',s_param,i_move_x,i_move_y,0);
    okno.focus();
  }
}


// show CATI report
function ShowCatiReport(URL,report_type)
{
  if(URL!=null)
  {
    if(report_type==null)
    {
      report_type='1';
    }
    window.location.href=URL+report_type;
  }
}


// show CAPI report
function ShowCapiReport(URL,report_type)
{
  if(URL!=null)
  {
    if(report_type==null)
    {
      report_type='1';
    }
    window.location.href=URL+report_type;
  }
}


// show CAWI report
function ShowCawiReport(URL,report_type)
{
  if(URL!=null)
  {
    if(report_type==null)
    {
      report_type='1';
    }
    window.location.href=URL+report_type;
  }
}


// show questionaire in a new window
function ShowQuestionaire(URL)
{
  if(URL!=null)
  {
    win = window.open(URL,"_blank");
    win.focus();
  }
}


/* shows or hides given <DIV> element */
function ShowHideOpenQ(AQName){
   QDiv = window.document.getElementById(AQName);
   if (QDiv) {
     if (QDiv.style.display=='inline') {
       QDiv.style.display='none';
     }
     else {
       QDiv.style.display='inline';
     }
   }
}


/* shows or hides given <DIV> element */
function ShowHideBlock(ABlockID,AMarkID){
   Block = window.document.getElementById(ABlockID);
   if (Block) {
     if (Block.style.display=='inline') {
    	 Block.style.display='none';
     }
     else {
    	 Block.style.display='inline';
     }
     Mark = window.document.getElementById(AMarkID);
     if (Mark) {
	     if (Mark.innerHTML == '[+]') {
	    	 Mark.innerHTML = '[-]';
	     }
	     else {
	    	 Mark.innerHTML = '[+]';
	     }
     }
     
   }
}

