﻿/**
 	* File: $Id$
 	*
 	* Javascript functions
 	*
 	* @copyright (C) 2007 Sdružení CLWEB
 	* @link http://www.clnet.cz
 	*
 	* @author CLWEB
	*/


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
/*
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
*/
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


function checkData(toCheck){
	switch(toCheck){
		case "orderForm":
		 Vars = new Array("paymentmethod","transportmethod");
		 Errors = new Array("Způsob platby", "Způsob dopravy");
		 Inputs = new Array();
		break;

		case "eshopusersForm":
		 Vars = new Array("unick","upass","upass2","uname","umail","utelefon;umobil","user_adress1");
		 Errors = new Array("Uživatelské jméno", "Heslo","Ověření hesla","Jméno a příjmení","e-mail","Telefon nebo mobil","Adresa");
		 Inputs = new Array();
		break;
	}

	message = "Následující položky musí být vyplněny:\n\n";
	for(i=0;i<Vars.length;i++){

		if( Vars[i].indexOf(";") == -1 ){
			if(document.getElementById(Vars[i])){
				if(document.getElementById(Vars[i]).disabled!=true){
					if(document.getElementById(Vars[i]).value=="" || document.getElementById(Vars[i]).value=="0"){
						message += Errors[i]+"\n";
					}
				}
			}
		} else {
			VarsTmp = Vars[i].split(";");
			addError = true;
			for(a=0;a<VarsTmp.length;a++){
				if(document.getElementById(VarsTmp[a])){
					if(document.getElementById(VarsTmp[a]).disabled!=true){
						if(document.getElementById(VarsTmp[a]).value!="" && document.getElementById(VarsTmp[a]).value!="0"){
							addError = false;
						}
					}
				}
			}

			if(addError){
				message += Errors[i]+"\n";
			}
		}
	}

	if(message!="Následující položky musí být vyplněny:\n\n"){
		alert(message);
		return false;
	} else {
		return true;
	}
}


function checkForm(form_id){

	check = checkData(form_id);

	if(check==true){
		return true;
	} else {
		return false;
	}
}


function disableTransportMethod(trans_id){
	transIdSelect = document.getElementById('transportmethod');
	if (trans_id == 1){ //Na prodejne
		transIdSelect.disabled=true;
	} else {
		transIdSelect.disabled=false;
	}
}


	/**
	* Rozbali / zabali polozky menu ( submenu je v tagu mpolozka{id}, obrazek imgpolozka{id}
	* @subpackage zpravy, class skupinyMenu
	**/
	function rozbalZabal(idP) {

		if(document.getElementById('mpolozka'+idP)!=undefined){
			blok = document.getElementById('mpolozka'+idP);
			imag = document.getElementById('imgpolozka'+idP);
			liTag = document.getElementById('bp'+idP);

			if(imag.className != "sub rozbalene"){
				imag.src = '/css/images/minus.gif';
			} else {
				imag.src = '/css/images/plus.gif';
			}

			if(blok.className!='sub rozbalene'){
				imag.className = 'sub rozbalene';
				blok.className = 'sub rozbalene';
				liTag.className = 'sub rozbalene';
			} else {
				imag.className = 'sub skryte';
				blok.className= 'sub skryte';
				liTag.className = 'sub skryte';
			}
		}

	} // rozbalZabal()


function getPage(from){
	document.forms["searchForm"]["FROM"].value=from;
	document.forms["searchForm"].submit();
}

function galleryAddDesc(id,fullpath,title){
	desc = document.getElementById("addDesc");
	descArea = document.getElementById("descArea");
	imgfullpath = document.getElementById("fullPath");
	imgid = document.getElementById("imgId");

	imgid.value = id;
	descArea.value = title;
	imgfullpath.value = fullpath;

	vND = document.getElementById('addDesc');

	if((xMousePosMax-300)<xMousePos){
		xpos = (xMousePos-250);
	} else {
		xpos = xMousePos;
	}

	vND.style.left = xpos+'px';
	vND.style.top = yMousePos+'px';

	/*Effect.toggle('addDesc','appear');*/
	desc.style.display="block";
}

function showDetails(element){
	hiddenBlock = element.parentNode;

	divs = hiddenBlock.getElementsByTagName("div");
	for(i=0;i<divs.length;i++){
		if(divs[i].className == "blockHidden"){
			if(divs[i].style.display == "none" || divs[i].style.display == ""){
				divs[i].style.display = "block";
			} else {
				divs[i].style.display = "none";
			}
		}
	}

}

function jsvoid(){
	
}

function showAll(type){
	tagLi = document.getElementById('main').getElementsByTagName('li');
	for(i=0;i<tagLi.length;i++){
		if(type=="rozsirene"){
			if(tagLi[i].className == "rozsirene hide" || tagLi[i].className == "rozsirene show"){
				tagLi[i].className = "rozsirene show";
			} else if(tagLi[i].className == "uplne hide" || tagLi[i].className == "uplne show") {
				tagLi[i].className = "uplne hide";
			}
		} else {
			if(tagLi[i].className == "rozsirene hide" || tagLi[i].className == "rozsirene show"){
				tagLi[i].className = "rozsirene show";

			} else if(tagLi[i].className == "uplne hide" || tagLi[i].className == "uplne show") {
				tagLi[i].className = "uplne show";

			}
		}
	}	// for
}

function hideAll(){
	tagLi = document.getElementById('main').getElementsByTagName('li');
	for(i=0;i<tagLi.length;i++){
		if(tagLi[i].className == "rozsirene show" || tagLi[i].className == "rozsirene hide"){
			tagLi[i].className = "rozsirene hide";
		} else if(tagLi[i].className == "uplne show" || tagLi[i].className == "uplne hide"){
			tagLi[i].className = "uplne hide";
		}
	}
}

function copyAddr(){
	document.getElementById('user_adress2').value = document.getElementById('user_adress1').value;
}

function copyAddrNew(){
	document.getElementById('user_street2').value = document.getElementById('user_street1').value;
	document.getElementById('user_city2').value = document.getElementById('user_city1').value;
	document.getElementById('user_psc2').value = document.getElementById('user_psc1').value;
}

function zobrazSkryj(id){
	el=document.getElementById(id).style;
	el.display=(el.display == 'block')?'none':'block';

	elbut=document.getElementById('buttonky');
	elbut.className=(elbut.className == 'buttonrozbalit')?'buttonzabalit':'buttonrozbalit';
	elbut.title=(elbut.title == 'Rozbalit filtry')?'Zabalit filtry':'Rozbalit filtry';

	/*el.className=(el.className == 'displayblock')?'displaynone':'displayblock';*/
}


function expandDis(element){
	hiddenBlock = element.parentNode.parentNode;

	searchRel = hiddenBlock.id;

	divs = hiddenBlock.getElementsByTagName("div");

	for(i=0;i<divs.length;i++){
		if( divs[i].className == searchRel || divs[i].className == 'disAnswer '+searchRel || divs[i].className == 'disReply '+searchRel){

			if(divs[i].style.display == "none" || divs[i].style.display == ""){
				divs[i].style.display = "block";
			} else {
				divs[i].style.display = "none";
			}
		}
	}

}

function expandAllDis(element){
	hiddenBlock = element.parentNode.parentNode;

	divs = hiddenBlock.getElementsByTagName("div");

	for(i=0;i<divs.length;i++){
		
		if(divs[i].id.indexOf('dis') != -1){

			disBlock = divs[i];

			searchRel = disBlock.id;
			dvs = disBlock.getElementsByTagName("div");
			for(a=0;a<dvs.length;a++){
				if( dvs[a].className == searchRel || dvs[a].className == 'disAnswer '+searchRel || dvs[a].className == 'disReply '+searchRel){
					if(dvs[a].style.display == "none" || dvs[a].style.display == ""){
						dvs[a].style.display = "block";
					} else {
						dvs[a].style.display = "none";
					}
				}
			}



		}
	}
}

// pridani stranky do oblibenych
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;
}

// slouzi ke zkopirovani hodnot inputu z jednoho formu do druheho ktery se pak odesila. hledani a filtry
function copySearchData() {
	var searchForm;
	var filtrForm;

	 if (document.forms["filtr"]!=undefined) {
		searchForm = document.forms["search_form"];
		filtrForm = document.forms["filtr"];

		filtrForm["search"].value=searchForm["search"].value;
		/*if (searchForm["na-detske-hry"].checked){
			filtrForm["na-detske-hry"].value=searchForm["na-detske-hry"].value;
	 	} else {
			filtrForm["na-detske-hry"].value='';
		}*/		

		filtrForm.submit();
		return false;

	 } else {
		searchForm = document.forms["search_form"];
		searchForm.submit();
		return false;

	 }
}

function boxyLoad(uri,typ,boxyTitle, icon){

	if(boxyTitle == undefined){
		boxyTitle = 'Okno';
	}

	icon = '<div class="icon"><img src="/css/images/'+icon+'.png" width="32" height="32" border="0" /></div>';

	if(typ == undefined || typ == ''){
		Boxy.load(uri, {title:icon+boxyTitle, closeText:"X"});
	} else if(typ=="alert") {
		new Boxy(uri, {title:icon+boxyTitle, closeText:"X"}); 
	//	Boxy.alert(uri, function(){  }, {title:icon+boxyTitle, closeText:"X"});
	}
}

