/**
  * Základní JavaScriptové funkce
  *
  * @author Kateřina Bambušková <katerina.bambuskova@seznam.cz>
  * @copyright Copyright 2008, VIAKIS.NET
  * @version 18.2.2008
  */

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" 
  };
}


/**
  * @param element
  */
function AddSizeOld() {
  var count = parseInt(document.CommodityForm.sizeCount.value) + 1;
	document.CommodityForm.sizeCount.value = count;
	document.getElementById("size").innerHTML = document.getElementById("size").innerHTML + "<tr><td>Rozměr:</td><td><input id=\"sSize\" class=\"input_text input_date\" type=\"text\" name=\"sSize" + count + "\" value=\"\" /></td><td>Cena:</td><td><input class=\"input_text input_date\" type=\"text\" name=\"nPrice" + count + "\" value=\"\" /> Kč</td></tr>";
}

function AddSize() {
  var count = parseInt(document.CommodityForm.sizeCount.value) + 1;
	document.CommodityForm.sizeCount.value = count;
	
  var x = document.getElementById('size'); 
  var input = document.createElement('input');
  input.setAttribute('class', 'input_text input_date' );  
  input.setAttribute('name', 'sSize'+count );  
  input.setAttribute('value', '' ); 
  var input2 = document.createElement('input');
  input2.setAttribute('class', 'input_text input_date' );  
  input2.setAttribute('name', 'nPrice'+count );  
  input2.setAttribute('value', '' ); 
  var input3 = document.createElement('input');
  input3.setAttribute('class', 'input_text input_date' );  
  input3.setAttribute('name', 'nWeight'+count );  
  input3.setAttribute('value', '' ); 
  var tr = document.createElement('tr');
  var td1 = document.createElement('td');
  var td2 = document.createElement('td');
  var td3 = document.createElement('td');
  var td4 = document.createElement('td');
  var td5 = document.createElement('td');
  var td6 = document.createElement('td');
  var text1 = document.createTextNode('Rozměr:');
  var text2 = document.createTextNode('Cena:');
  var text3 = document.createTextNode(' Kč');
  var text4 = document.createTextNode('Hmotnost:');
  var text5 = document.createTextNode(' kg');
  td1.appendChild(text1);
  td2.appendChild(input);
  td3.appendChild(text2);
  td4.appendChild(input2);
  td4.appendChild(text3);
  td5.appendChild(text4);
  td6.appendChild(input3);
  td6.appendChild(text5);
  tr.appendChild(td1);
  tr.appendChild(td2);
  tr.appendChild(td3);
  tr.appendChild(td4);
  tr.appendChild(td5);
  tr.appendChild(td6);
  x.appendChild(tr);
}


function AddParameter() {
  var count = parseInt(document.CommodityForm.parameterCount.value) + 1;
	document.CommodityForm.parameterCount.value = count;
	
  var x = document.getElementById('parameter'); 
  var input = document.createElement('input');
  input.setAttribute('class', 'input_text input_date' );  
  input.setAttribute('name', 'sParameter'+count );  
  input.setAttribute('value', '' ); 
  var input2 = document.createElement('input');
  input2.setAttribute('class', 'input_text input_date' );  
  input2.setAttribute('name', 'nExtra'+count );  
  input2.setAttribute('value', '' ); 
  var tr = document.createElement('tr');
  var td1 = document.createElement('td');
  var td2 = document.createElement('td');
  var td3 = document.createElement('td');
  var td4 = document.createElement('td');
  var text1 = document.createTextNode('Parametr:');
  var text2 = document.createTextNode('Příplatek:');
  var text3 = document.createTextNode(' Kč');
  td1.appendChild(text1);
  td2.appendChild(input);
  td3.appendChild(text2);
  td4.appendChild(input2);
  td4.appendChild(text3);
  tr.appendChild(td1);
  tr.appendChild(td2);
  tr.appendChild(td3);
  tr.appendChild(td4);
  x.appendChild(tr);
}


function AddExtension() {
  var count = parseInt(document.CommodityForm.extensionCount.value) + 1;
	document.CommodityForm.extensionCount.value = count;
	
  var x = document.getElementById('extension'); 
  var input = document.createElement('input');
  input.setAttribute('class', 'input_text input_date' );  
  input.setAttribute('name', 'sExtension'+count );  
  input.setAttribute('value', '' ); 
  var input2 = document.createElement('input');
  input2.setAttribute('class', 'input_text input_date' );  
  input2.setAttribute('name', 'nPercent'+count );  
  input2.setAttribute('value', '' ); 
  var tr = document.createElement('tr');
  var td1 = document.createElement('td');
  var td2 = document.createElement('td');
  var td3 = document.createElement('td');
  var td4 = document.createElement('td');
  var text1 = document.createTextNode('Prodloužení:');
  var text2 = document.createTextNode('Navýšení:');
  var text3 = document.createTextNode(' %');
  td1.appendChild(text1);
  td2.appendChild(input);
  td3.appendChild(text2);
  td4.appendChild(input2);
  td4.appendChild(text3);
  tr.appendChild(td1);
  tr.appendChild(td2);
  tr.appendChild(td3);
  tr.appendChild(td4);
  x.appendChild(tr);
}

/**
  * 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 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í logovacího formuláře
  *
  * @return boolean true - OK, false - chyba
  */
function ContestCheck() {
  if (document.ContestForm.sAnswer[0].checked == false && document.ContestForm.sAnswer[1].checked == false && document.ContestForm.sAnswer[2].checked == false) {
      window.alert ("Zvolte některou odpověď!!!");
      return false;
  } else if (document.ContestForm.sEmail.value=="" || document.ContestForm.sEmail.value=="@") {
      window.alert ("Vyplňte Váš email!!!");
      document.ContestForm.sEmail.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 UserCheck() {
  if (document.UserForm.sFirstName.value=="") {
      window.alert ("Vyplňte jméno!!!");
      document.UserForm.sFirstName.focus();
      return false;
  } else if (document.UserForm.sLastName.value=="") {
      window.alert ("Vyplňte příjmení!!!");
      document.UserForm.sLastName.focus();
      return false;
  } else if (document.UserForm.sStreet.value=="") {
      window.alert ("Vyplňte ulici!!!");
      document.UserForm.sStreet.focus();
      return false;
  } else if (document.UserForm.sCity.value=="") {
      window.alert ("Vyplňte město!!!");
      document.UserForm.sCity.focus();
      return false;
  } else if (document.UserForm.sZipCode.value=="") {
      window.alert ("Vyplňte PSČ!!!");
      document.UserForm.sZipCode.focus();
      return false;
  } else if (document.UserForm.sEmail.value=="") {
      window.alert ("Vyplňte email!!!");
      document.UserForm.sEmail.focus();
      return false;
  } else if (document.UserForm.sMobile.value=="" && document.UserForm.sPhone.value=="") {
      window.alert ("Vyplňte vaše mobilní nebo telefonní číslo!!!");
      document.UserForm.sMobile.focus();
      return false;
  } else if (document.UserForm.sMobile.value=="+420") {
      window.alert ("Neplatné mobilní číslo!!!");
      document.UserForm.sMobile.focus();
      return false;
  } else if (document.UserForm.sPassword.value=="") {
      window.alert ("Vyplňte heslo!!!");
      document.UserForm.sPassword.focus();
      return false;
  } else if (document.UserForm.sConfirmPassword.value=="") {
      window.alert ("Vyplňte kontrolu hesla!!!");
      document.UserForm.sConfirmPassword.focus();
      return false;
  } else if (document.UserForm.sPassword.value!=document.UserForm.sConfirmPassword.value) {
      window.alert ("Heslo a kontrola hesla nejsou stejné!!!");
      document.UserForm.sPassword.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 UserCheckEdit() {
  if (document.UserForm.sFirstName.value=="") {
      window.alert ("Vyplňte jméno!!!");
      document.UserForm.sFirstName.focus();
      return false;
  } else if (document.UserForm.sLastName.value=="") {
      window.alert ("Vyplňte příjmení!!!");
      document.UserForm.sLastName.focus();
      return false;
  } else if (document.UserForm.sStreet.value=="") {
      window.alert ("Vyplňte ulici!!!");
      document.UserForm.sStreet.focus();
      return false;
  } else if (document.UserForm.sCity.value=="") {
      window.alert ("Vyplňte město!!!");
      document.UserForm.sCity.focus();
      return false;
  } else if (document.UserForm.sZipCode.value=="") {
      window.alert ("Vyplňte PSČ!!!");
      document.UserForm.sZipCode.focus();
      return false;
  } else if (document.UserForm.sEmail.value=="") {
      window.alert ("Vyplňte email!!!");
      document.UserForm.sEmail.focus();
      return false;
  } else if (document.UserForm.sPhone.value=="" && document.UserForm.sMobile.value=="") {
      window.alert ("Vyplňte telefon nebo mobil!!!");
      document.UserForm.sPhone.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 CategoryCheck() {
  if (document.CategoryForm.fkParent.value=="") {
      window.alert ("Vyplňte nadřazenou kategorii!!!");
      document.CategoryForm.fkParent.focus();
      return false;
  } else if (document.CategoryForm.sName.value=="") {
      window.alert ("Vyplňte jméno!!!");
      document.CategoryForm.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 CommodityCheck() {
  if (document.CommodityForm.sName.value=="") {
      window.alert ("Vyplňte jméno!!!");
      document.CommodityForm.sName.focus();
      return false;
  } else if (document.CommodityForm.fkCategory.value=="") {
      window.alert ("Vyberte kategorie!!!");
      document.CommodityForm.fkCategory.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
}

/**
  * 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 testování formuláře pro práci s odkazy
  *
  * @return boolean true - OK, false - chyba
  */
function LinksCheck() {
  if (document.linksForm.pkLink.value=="") {
      window.alert ("Vyplňte název!!!");
      document.linksForm.pkLink.focus();
      return false;
  } else if (document.linksForm.sURL.value=="") {
      window.alert ("Vyplňte URL!!!");
      document.linksForm.sURL.focus();
      return false;
  } else {
      //window.alert ("OK");
      return true;
  }
} 

function OrderCheck() {
  if (document.OrderForm.souhlas.checked) {
      //document.OrderForm.submit();
      return true;
  } else {
      window.alert ("Musíte souhlasit s obchodními podmínkami!!!");
      document.OrderForm.souhlas.focus();
      return false;
  }
} 



function SizeCheck() {
  if (document.ItemForm.rozměr.value=="") {
      window.alert ("Vyberte rozměr!!!");
      document.ItemForm.rozměr.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 položku: *"+name+"* smazat?")) location.href = record;
}

function OrderStorno() {
   if (confirm("Opravdu chcete objednavku zrušit?")) return true;
   else return false;
}

