// naseptavac
function autoComplete()
{
  new Ajax.Autocompleter('full_str', 'autocomplete-full_str', '/naseptavac.php', 
  {
    paramName: 'value'
  });

}

// ostatni funkce pro praci s objednavkou, obrazem, popupem atd.
function InfoWindow(strAddress) {showModalDialog(strAddress,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=450pt;dialogHeight=320pt");}

function validPsc(f) {
	if (!/^\d*$/.test(f.value)) {
		f.value = f.value.replace(/[^\d]/g,"");
	}
}

function validateEmail(email){
	if(window.RegExp){
		re = new RegExp("^[^@]+@[^.]+\..+$");
		if(!re.test(email)){
			alert("Formát emailové adresy není správný. Opravte políčko 'E-mail.' Např: pavel@novak.cz.");
			return false;
		}
	}
	return true;
}


function kontrola(){
	f=document.formregistrace.email.value;
    if((document.formregistrace.jmeno.value == "" || document.formregistrace.prijmeni.value == "")& document.formregistrace.nazev_firmy.value == ""){alert("Vyplňte název firmy nebo jméno a příjmení.");return false}
    if(document.formregistrace.ulice.value == ""){alert("Vyplňte ulici.");return false}
    if(document.formregistrace.mesto.value == ""){alert("Vyplňte město.");return false}
    if(document.formregistrace.psc.value == ""){alert("Vyplňte PSČ.");return false}
    if(document.formregistrace.ZD.checked == true) {
	    if(document.formregistrace.ZD_jmeno.value == ""){alert("Vyplňte jméno adresy doručení.");return false}
	    if(document.formregistrace.ZD_ulice.value == ""){alert("Vyplňte ulici adresy doručení.");return false}
	    if(document.formregistrace.ZD_mesto.value == ""){alert("Vyplňte město adresy doručení.");return false}
	    if(document.formregistrace.ZD_psc.value == ""){alert("Vyplňte PSČ adresy doručení.");return false}
    }
    if(document.formregistrace.telefon.value == ""){alert("Vyplňte telefon.");return false}
	if(validateEmail(f)==false){return false;}
  return true;
}


function kontrola_user(){
    if(document.formregistrace.firma.value == ""){alert("Vyplňte uživatelské jméno.");return false}
    if(document.formregistrace.heslo.value == ""){alert("Vyplňte heslo.");return false}
  return true;
}

function kontrola_reklamace(){
    if(document.formreklam.jmeno.value == ""){alert("Vyplňte Vaše jméno.");return false}
    if(document.formreklam.cislo_dokladu.value == ""){alert("Vyplňte číslo dokladu.");return false}
    if(document.formreklam.email.value == ""){alert("Vyplňte emailovou adresu.");return false}
    if(document.formreklam.popis.value == ""){alert("Vyplňte popis závady / Žádosti.");return false}
  return true;
}


function regishowexte(xhd)
{

	if (document.getElementById(xhd).style.display=='none')
		document.getElementById(xhd).style.display='';
	else
		document.getElementById(xhd).style.display='none';
}


function doklad(location,w,h,jmeno)
  {
   var p;
   p="copyhistory,width=720,height="+h+",left=0,top=0,scrollbars=yes"
   msg=open(location, jmeno, p);
  }
  
 function vypln_hledat_produkt(){
 if (document.hledat_produkt.full_str.value==''){document.hledat_produkt.full_str.value='Zadejte název zboží';}
 }
 
 
function picture(location,w,h,jmeno)
  {
   var p;
   p="copyhistory,width="+w+",height="+h+",left=0,top=0"
   msg=open(location, jmeno, p);
  }
  
function showtext(location,w,h,jmeno)
  {
   var p;
   p="copyhistory,scrollbars,resizeable,width="+w+",height="+h+",left=0,top=0"
   msg=open(location, jmeno, p);
  }

function shopinfomenu(x){
  if (x == 1){
    document.getElementById('shopinfomenu').style.display='';
  }else{
    document.getElementById('shopinfomenu').style.display='none';
  }
}
function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

// show-hide-scrolling
var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}


// operace s cookies resp sessions
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}