/**
 	* 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 "regForm":
		 Vars = new Array("unick","upass1","upass2","ufname","ulname","umail","utelefon","user_city1","user_street1","user_psc1");
		 Errors = new Array("Uživatelské jméno","Heslo","Kontrola hesla","Jméno","Příjmení", "E-mail","Telefon","Město","Ulice a čp.","Psč");
		 Inputs = new Array();
		break;
		

		case "orderForm":
		case "eshopusersForm":
		 Vars = new Array("ufname","ulname","umail","utelefon","user_city1","user_street1","user_psc1");
		 Errors = new Array("Jméno","Příjmení", "E-mail","Telefon","Město","Ulice a čp.","Psč");
		 Inputs = new Array();
		break;
	}

	message = "<center><b>Následující položky musí být vyplněny:</b><br />";
	showErrorMess = false;
	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 += "<br>"+Errors[i]+"\n";
						showErrorMess = true;	
					}
				}
			}
		} 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 += "<br>"+Errors[i]+"\n";
			}
		}
	}

	if(showErrorMess==true){
		//alert(message);
		boxyLoad(message+'</center>','alert','!!! Pozor !!!','icon');	
		//return false;
	} else {
		if(toCheck == 'orderForm') 
			document.orderForm.submit();
		else if (toCheck == 'regForm'){
			

			if(document.getElementById("upass1").value!=document.getElementById("upass2").value){
				message = '<b>Ověření heslá nesouhlasí, zadejte jej znovu!</b>';
				boxyLoad('<center>'+message+'</center>','alert','!!! Pozor !!!','icon');
				$("#upass2").val('');
				setTimeout('$("#upass1").val(\'\').focus()', 1700);

			} else {	
				document.regForm.submit();
			}
		}	
		//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_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 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="/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") {
		//uri = '<div id="fancybox-wrap" style="display: block; width: 481px; height: auto; top: 334px; left: 319px;"><div id="fancybox-outer"><div id="fancybox-title" class="fancybox-title-float" style="left: 125px; display: block;"><table cellspacing="0" cellpadding="0" id="fancybox-title-float-wrap"><tbody><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">ABUS FTS 88 přídavný okenní zámek bílý</td><td id="fancybox-title-float-right"></td></tr></tbody></table></div><div id="fancybox-bg-n" class="fancybox-bg"></div><div id="fancybox-bg-ne" class="fancybox-bg"></div><div id="fancybox-bg-e" class="fancybox-bg"></div><div id="fancybox-bg-se" class="fancybox-bg"></div><div id="fancybox-bg-s" class="fancybox-bg"></div><div id="fancybox-bg-sw" class="fancybox-bg"></div><div id="fancybox-bg-w" class="fancybox-bg"></div><div id="fancybox-bg-nw" class="fancybox-bg"></div><div id="fancybox-content" style="border-width: 10px; width: 461px; height: 330px;"><img id="fancybox-img" src="http://zm.clweb.cz/UserFiles/File/produkt/41/obrazky/_original/fts88_560x400.jpg" alt="ABUS FTS 88 přídavný okenní zámek bílý"></div><a id="fancybox-close" style="display: inline;"></a><a id="fancybox-left" href="javascript:;"><span id="fancybox-left-ico" class="fancy-ico"></span></a><a id="fancybox-right" href="javascript:;"><span id="fancybox-right-ico" class="fancy-ico"></span></a></div></div>';

		$.fancybox({'transitionIn'	:'fade',
			    'transitionOut'	:'fade',
			     'content': '<br />'+uri+'<br />',
			     'speedIn'	:600,'speedOut'	:200,'overlayShow':true,'centerOnScroll':true,'enableEscapeButton':true});
		$.fancybox.resize();
		
		//$.fancybox('transitionIn':'elastic',
		//'transitionOut'	:'elastic',
	//	'speedIn'	:600, 
	//	'speedOut'	:200, 
	//	'overlayShow'	:true,
	//	'type': 	'inline',
	//	'title': 	'!!! Pozor !!!',
	//	'content': 	'Testovaci'
	//	); 	

		
		//new Boxy(uri, {title:icon+boxyTitle, closeText:"X"}); 
		//Boxy.alert(uri, function(){  }, {title:icon+boxyTitle, closeText:"X"});
	}
	
}


