/**
  * Základní JavaScriptové funkce
  *
  * @author Kateřina Bambušková <katerina.bambuskova@seznam.cz>
  * @copyright Copyright 2007, VIAKIS.NET
  * @version 29.7.2007
  */

var Br = new BrCheck()

/**
  * Funkce pro otestování prohlížeče
  *
  * @return prohlížeč
  */
function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent.replace(/[\/]/g,' ');
	this.DOM	= document.getElementById ? true:false;

	this.OP5	= this.AGENT.indexOf("Opera 5")>-1							?true:false;
	this.OP6	= this.AGENT.indexOf("Opera 6")>-1							?true:false;
	this.OP7	= this.AGENT.indexOf("Opera 7")>-1							?true:false;
	this.OP8	= this.AGENT.indexOf("Opera 8")>-1							?true:false;
	this.OP		= (this.OP5 || this.OP6 || this.OP7 || this.OP8);

	this.IE4	= (document.all && !this.DOM && !this.OP)					        ?true:false;
	this.IE5	= (this.VER.indexOf("MSIE 5")>-1 && this.DOM && !this.OP)	?true:false; 
	this.IE6	= (this.VER.indexOf("MSIE 6")>-1 && this.DOM && !this.OP)	?true:false;
  this.IE7  = (this.VER.indexOf("MSIE 7")>-1 && this.DOM && !this.OP) ?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6 || this.IE7);

	this.NS4	= (document.layers && !this.DOM)							?true:false;
	this.NS7	= (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape')<this.AGENT.lastIndexOf('7'))?true:false;
	this.NS6	= (this.DOM && parseInt(this.VER) >= 5 && !this.NS7)		?true:false;
	this.NS		= (this.NS4 || this.NS6 || this.NS7);

	return this;
}

/**
  * Funkce varacející objekt podle ID
  *
  * @return objekt podle ID
  */
function getE(objectID){
  return document.getElementById(objectID); 
}

/**
  * Funkce zobrazení nebo ukrytí elementu
  *
  * @param element
  */
function ShowHide(element) {
	var e = getE( element );
	if (e.style.display=="none") {
		e.style.display = "" 
  }
	else {
		e.style.display = "none" 
  };
}

/**
  * Funkce pro přidání stránky do záložek
  *
  * @param String url
  * @param String title  
  */
function Bookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all){
		window.external.AddFavorite(url, title);
	}
	else{
		return true;
	}
}

function AddFavorite(linkObj,addUrl,addTitle)
{
  if (document.all && !window.opera)
  {
    window.external.AddFavorite(addUrl,addTitle);
    return false;
  }
  else if (window.opera && window.print)
  {
    linkObj.title = addTitle;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
  {
    if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
    {
      window.sidebar.addPanel(addTitle,addUrl,'');
      return false;
    }
  }
  window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
  return false;
}


/**
  * Funkce pro přidávání Cookies
  *
  * @param String strName jméno
  * @param String strData hodnota
  */
function InsertCookies(strName,strData){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=\/;";
}


/**
  * Funkce pro testování formuláře pro změnu hesla
  *
  * @return boolean true - OK, false - chyba
  */
function ChangePasswordCheck() {
  if (document.ChangePasswordForm.oldPassword.value=="") {
      window.alert ("Vyplňte staré heslo!!!");
      document.ChangePasswordForm.oldPassword.focus();
      return false;
  } else if (document.ChangePasswordForm.newPassword.value=="") {
      window.alert ("Vyplňte nové heslo!!!");
      document.ChangePasswordForm.newPassword.focus();
      return false;
  } else if (document.ChangePasswordForm.checkPassword.value=="") {
      window.alert ("Vyplňte kontrolu hesla!!!");
      document.ChangePasswordForm.checkPassword.focus();
      return false;
  } else if (document.ChangePasswordForm.checkPassword.value!=document.ChangePasswordForm.newPassword.value) {
      window.alert ("Nové heslo a kontrola hesla nejsou stejné!!!");
      document.ChangePasswordForm.checkPassword.focus();
      return false;      
  } else {
      //window.alert ("OK");
      return true;
  }
}


/**
  * Funkce pro přidávání Cookies pro debug
  *
  * @param String strName jméno
  * @param String strData hodnota
  */
function InsertCookiesDebug(strName,strData){
	var vyprs=new Date();
	
	if (strData == "1") {
    strData = "0";
  } else {
    strData = "1"
  }
	
	vyprs.setDate(vyprs.getDate() + 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=\/;";
}

/**
  * Funkce pro testování logovacího formuláře
  *
  * @return boolean true - OK, false - chyba
  */
function LoginCheck() {
  if (document.loginForm.login.value=="") {
      window.alert ("Vyplňte Váš login!!!");
      document.loginForm.login.focus();
      return false;
  } else if (document.loginForm.password.value=="") {
      window.alert ("Vyplňte Vaše heslo!!!");
      document.loginForm.password.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}


/**
  * Funkce pro testování formuláře pro práci s pracovníky
  *
  * @return boolean true - OK, false - chyba
  */
function WorkerCheck() {
  if (document.WorkerForm.pkWorker.value=="") {
      window.alert ("Vyplňte login!!!");
      document.WorkerForm.pkWorker.focus();
      return false;
  } else if (document.WorkerForm.sName.value=="") {
      window.alert ("Vyplňte jméno!!!");
      document.WorkerForm.sName.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}

/**
  * Funkce pro testování formuláře pro práci s pracovníky
  *
  * @return boolean true - OK, false - chyba
  */
function TaskWorkersCheck() {
  if (document.TaskWorkersForm.fkTask.value=="") {
      window.alert ("Vyberte úlohu!!!");
      document.TaskWorkersForm.fkTask.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}

/**
  * Funkce pro testování formuláře pro práci s fazemi
  *
  * @return boolean true - OK, false - chyba
  */
function FazeCheck() {
  if(document.FazeForm.dEnd.value=="") {
      window.alert ("Vyplňte do!!!");
      document.FazeForm.dEnd.focus();
      return false;
  } else if(document.FazeForm.dStart.value=="") {
      window.alert ("Vyplňte od!!!");
      document.FazeForm.dStart.focus();
      return false;
  } else if (document.FazeForm.pkFaze.value=="") {
      window.alert ("Vyplňte ID!!!");
      document.FazeForm.pkFaze.focus();
      return false;
  } else if (document.FazeForm.sColor.value=="") {
      window.alert ("Vyplňte barvu!!!");
      document.FazeForm.sColor.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}


/**
  * Funkce pro testování formuláře pro práci s ceníky
  *
  * @return boolean true - OK, false - chyba
  */
function PriceListCheck() {
  if (document.PriceListForm.pkPriceList.value=="") {
      window.alert ("Vyplňte nazáv!!!");
      document.PriceListForm.pkPriceList.focus();
      return false;
  } else if (document.PriceListForm.nPrice.value=="") {
      window.alert ("Vyplňte cenu!!!");
      document.PriceListForm.nPrice.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}

/**
  * Funkce pro testování formuláře pro práci s úlohami
  *
  * @return boolean true - OK, false - chyba
  */
function TaskCheck() {
  if (document.TaskForm.pkTask.value=="") {
      window.alert ("Vyplňte ID!!!");
      document.TaskForm.pkTask.focus();
      return false;
  } else if (document.TaskForm.dDeadline.value=="") {
      window.alert ("Vyplňte termín!!!");
      document.TaskForm.dDeadline.focus();
      return false;
  } else if (document.TaskForm.nHH.value=="") {
      window.alert ("Vyplňte člověkohodiny!!!");
      document.TaskForm.nHH.focus();
      return false;
  } else if (document.TaskForm.fkPriceList.value=="") {
      window.alert ("Vyplňte typ práce!!!");
      document.TaskForm.fkPriceList.focus();
      return false;
  } else if (document.TaskForm.sState.value=="") {
      window.alert ("Vyplňte stav!!!");
      document.TaskForm.sState.focus();
      return false;
  } else if (document.TaskForm.nPriority.value=="") {
      window.alert ("Vyplňte prioritu!!!");
      document.TaskForm.nPriority.focus();
      return false;
  } else if (document.TaskForm.sDescription.value=="") {
      window.alert ("Vyplňte popis!!!");
      document.TaskForm.sDescription.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}

/**
  * Funkce pro potvrzení smazání záznamu
  *   
  * @param name ID
  * @param record záznam
  */
function ItemDeleteConfirm(name,record) {
   if (confirm("Opravdu chcete *"+name+"* položku smazat?")) location.href = record;
}
/**
  * Funkce pro potvrzení smazání pracovnika
  *
  * @param name ID
  * @param record pracovník  
  */
function WorkerDeleteConfirm(name,record) {
   if (confirm("Opravdu chcete *"+name+"* pracovníka smazat?")) location.href = record;
}

/**
  * Funkce pro potvrzení smazání ceny
  *
  * @param name ID  
  * @param record cena
  */
function PriceListDeleteConfirm(name,record) {
   if (confirm("Opravdu chcete *"+name+"* záznam smazat?")) location.href = record;
}


