

try {
  $(function() {
  	$.fn.nyroModal.settings.processHandler = function(settings) {
  		var from = settings.from;
  		if (!settings.type && from && from.href) {
  			/*alert(
  				'type should be image: '+settings.type + '\n'
  				+ "need to determine if image manually");*/
  			var arr = from.href.split('?');
  			//if carrying extra stuff
  			if(arr.length>1){
  				var newArr=arr[0].split('.');
  				var newType=settings.type;
  				//alert('extension is: ' + newArr[newArr.length-1]);
  				switch(newArr[newArr.length-1].toUpperCase()){
  					case 'IMG':
  					case 'JPG':
  					case 'JPEG':
  					case 'PNG':
  					case 'GIF':
  					case 'ASPX':
  						newType='image';
  						break;
  					default:
  						newType=settings.type;
  				}
  				//alert("new type is " + newType);
  				$.nyroModalSettings({
  					type: newType
  				});
  			}
  		}
  	};
  	
  });
  
  $(document).ready(function(){       
    $(".allForms").ndFormValidator(); 
    $("a[rel^='lightbox']").nyroModal({galleryCounts: false});
    
    
  });
} catch(err) {

}


function createCookie() {
  var date = new Date(); 
	date.setTime(date.getTime()+(7*24*60*60*1000));
	var expires = date.toGMTString();
	document.cookie = "headBannBox2=true;EXPIRES="+expires+"; path=/";
}


// funkce pro vlozeni fotek z fotogalerie ke clanku START
function GenerateCustomFckGallery(files_array)
{
    var result="<br>";
		for (var a=0;a<files_array.length;a++)
			result+="<a href=\""+files_array[a].path+"\" rel=\"lightbox[roadtrip2]\"><img class=\"body-gallery\" alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
		return result;
}
// funkce pro vlozeni fotek z fotogalerie ke clanku END

//*********************************** Poradna pretvoreni nazvu kategorie do url ***************************************


function getDocname(url)
{
//window.alert('to je on');

var pos=url.indexOf("?");
	if (pos!=-1)
		url=url.substring(0,pos);
	url=url.substring(url.lastIndexOf("/")+1,url.length-5);
	//return url
//alert("http://shop.nutrend.cz/cz/produkt/"+url+"/");
window.location.href="http://www.svet-bydleni.cz/"+url+"/";
}



function ShowHideVlozit(){ 
//if (window.location.href = 'http://www.svet-bydleni.cz/bydleni/poradna/default.aspx');
//document.getElementById('ShowHideLink').style.display = 'none';
//return false;
}

function BodyGaleryView(src, title)
{
	if ((src==null)||(src==""))
		return false;

	var pwb='<html>\r\n'+
		'<head><title>Svet-bydleni.cz</title></head>\r\n'+
		'<scr'+'ipt type="text/javascript" src="/_JS/custom.js"></scr'+'ipt>\r\n'+
		'<body leftMargin=0 topMargin=0  style="cursor:pointer; font-family:Verdana; font-size:14px;font-weight:bold;">\r\n'+
		'<div style="display:none;width:100%;padding-top:25px;text-align:center;" id="errTxt">THE PICTURE IS NOT AVAILABLE.</div>\r\n'+
		'<img src="'+src+'" onClick="window.close();" alt="" id=foto onload="popupResizeWin()" onerror="popupNotLoaded()">\r\n'+
		
		'</body>\r\n'+
		'</html>\r\n';

	var _child=window.open("about:blank","","left=0,top=0,height=200,width=200,scrollbars=yes");
	_child.document.write(pwb);
}

function popupResizeWin()
{
	var foto=document.getElementById("foto");

	var iWidth=document.body.clientWidth;
	iWidth=foto.width-iWidth;
	window.resizeBy(iWidth,0); 
	
	var iHeight=document.body.clientHeight;
	iHeight=foto.height-iHeight;
	window.resizeBy(0,iHeight);
	
	window.moveTo(0,0);
}

function popupNotLoaded()
{
	document.getElementById("foto").style.display="none";
	document.getElementById("errTxt").style.display="block";
	window.resizeTo(350,40);
}

function newWin(url)
    {
		window.open(url, "newBox","width=600,height=400")
	}

// POZOR NA SPRAVNE KODOVANI SOUBORU!!! 

/* ------ DropDown Menu Position ------ */


function GetCustomMenuPositionRoot(pos)
{
pos.x=+6;
pos.y=+108;
}
function GetCustomMenuPositionChildren(pos)
{
pos.x=+6;
pos.y=+108;
}


//--- Svet bydleni - Validace poli ve fotogaleriich  --//

function OverFoto ()
{
   if (document.design.FirstName.value == "")
   {
      document.design.FirstName.focus();
      alert ("Nezadal(a) jste Vaše jméno a Příjmení");
      return false;
   }
   if (document.design.Element1.value == "")
   {
      document.design.Element1.focus();
      alert ("Nezadal(a) jste Město");
      return false;
   }
   if (document.design.Email.value == "")
   {
      document.design.Email.focus();
      alert ("Nezadal(a) jste Váš e-mail");
      return false;
   }
   inpMail=document.design.Email.value;
   mail=/^.+@.+\..{2,3}$/;
   if (!mail.test(inpMail))
   {
      document.design.Email.focus();
      alert ("Chybný formát e-mailu");
      return false;
   }
   if (document.design.AuthorDescription.value == "")
   {
      document.design.AuthorDescription.focus();
      alert ("Nezadal(a) jste kontaktní adresu");
      return false;
   }
   

 }




//--- Svet bydleni - Validace poli ve fotogaleriich  --//

function OverFotoLight ()
{
   if (document.design.FirstName.value == "")
   {
      document.design.FirstName.focus();
      alert ("Nezadal(a) jste Vaše jméno a Příjmení");
      return false;
   }
   if (document.design.LastName.value == "")
   {
      document.design.LastName.focus();
      alert ("Nezadal(a) jste Město");
      return false;
   }
   if (document.design.Email.value == "")
   {
      document.design.Email.focus();
      alert ("Nezadal(a) jste Váš e-mail");
      return false;
   }
   inpMail=document.design.Email.value;
   mail=/^.+@.+\..{2,3}$/;
   if (!mail.test(inpMail))
   {
      document.design.Email.focus();
      alert ("Chybný formát e-mailu");
      return false;
   }
   if (document.design.AuthorDescription.value == "")
   {
      document.design.AuthorDescription.focus();
      alert ("Nezadal(a) jste kontaktní adresu");
      return false;
   }
   

 }




function ResizeWindowEditor()
{
    var container = document.getElementById("container");
    if (container)
    {
        window.resizeTo(container.offsetWidth + 30, container.offsetHeight + 1);
    }
}



function countit(pocet) 
{
  var str = document.forms["design"].Description;
 if(str.value.length>pocet)
  	str.value = document.forms["design"].text.value.substr(0,pocet);

  document.getElementById("charsWritten").innerHTML =  str.value.length;
  document.getElementById("charsLeft").innerHTML = pocet - str.value.length;
}



function ExternalGalery(url) {
var win = window.open(url,'','width=800,height=600,left=0,top=0,scrollbars=yes,location=no,resizable=yes');
if (win) return false;
else return true
}


function ResizeWindowForm()
{
    var container = document.getElementById("container");
    if (container)
    {
        window.resizeTo(container.offsetWidth + 30, container.offsetHeight + 82);
    }
}




//--- Svet bydleni - Zvetseni okna pri nahrani obrazku v prohlizeci --//

function FitWindowToImage(oimg)
{
 //elm = document.getElementById('Image');
 if (oimg)
 {
    //alert("width: " + elm.width + "; Image.height: " + elm.height);
    window.resizeTo(oimg.width + 71, oimg.height + 260)
  }
}



function FitWindowToImage2(oimg)
{
 //elm = document.getElementById('Image');
 if (oimg)
 {
    //alert("width: " + elm.width + "; Image.height: " + elm.height);
    window.resizeTo(oimg.width + 80, oimg.height + 245)
  }
}



//--- Svet bydleni - katalog firem obrazky START --//

function resImg(image)
{
/* alert('resize'+image.height); */
   
    if (image.height > 0)
    {
        if ((image.height / 60) > 1)
            image.style.width = Math.round(60 * (60 / image.height));
        else
            image.style.height = Math.round(60 * (image.height / 60 ));
    }
    if (image.height < 61) image.parentNode.style.height = 'auto';
}


function resImg200(oimg) {
	if (oimg.height > 180 || oimg.width > 180) {
		var dZoom = 180 / oimg.width;
		var oHeight =	oimg.height;
		var oWidth = oimg.width;
		if ((oimg.height * dZoom) > 180) {
			dZoom = 180 / oimg.height;
		}
		oimg.width = Math.round(oWidth * dZoom);
		oimg.height = Math.round(oHeight * dZoom);
	}
}




function resImg780(oimg) {
	if (oimg.height > 780 || oimg.width > 780) {
		var dZoom = 780 / oimg.width;
		var oHeight =	oimg.height;
		var oWidth = oimg.width;
		if ((oimg.height * dZoom) > 780) {
			dZoom = 780 / oimg.height;
		}
		oimg.width = Math.round(oWidth * dZoom);
		oimg.height = Math.round(oHeight * dZoom);
	}
}






//--- Svet bydleni - katalog firem obrazky END --//



// ------ overeni formulare  napiste nam---------------------- //

function OverNewsletter ()
{
    if (document.NewsRegistrForm.inpNewsMail.value == "")
    {
       document.NewsRegistrForm.inpNewsMail.focus();
       alert ("Nezadal(a) jste Váš e-mail");
       return false;
    }
    inpMail=document.NewsRegistrForm.inpNewsMail.value;
    mail=/^.+@.+\..{2,4}$/;
    if (!mail.test(inpMail))
    {
       document.NewsRegistrForm.inpNewsMail.focus();
       alert ("Chybný formát e-mailu");
       return false;
    }
 //    if (document.NewsRegistrForm.Element5.value == "")
//    {
//       document.NewsRegistrForm.Element5.focus();
//       alert ("Nezadal(a) jste Váš e-mail");
//       return false;
//    }
//    inpMail=document.NewsRegistrForm.Element5.value;
//    mail=/^.+@.+\..{2,3}$/;
//    if (!mail.test(inpMail))
//    {
//       document.NewsRegistrForm.Element5.focus();
//       alert ("Chybný formát e-mailu");
//       return false;
//    }

 }
 
 

 // ------------------- END --------------------- //



//--- Raiffeisen Styl - zobrazeni podminek souteze START --//


function podminky(url) {
var win = window.open(url, null,"width=800,height=800,left=40,top=10,scrollbars=yes,location=no,resizable=yes");
if (win) return false;
else return true
}

//--- Raiffeisen Styl - zobrazeni podminek souteze END --//



//--- Svet bydleni - galerie fotek by barry 01 --//


function fototest(url) {
var win = window.open(url, null,"width=800,height=600,left=40,top=10,scrollbars=yes,location=yes,resizable=yes");
if (win) return false;
else return true
}

//--- Svet bydleni - galerie fotek by barry 01 END --//


//--- Svet bydleni - galerie fotek by barry --//

function foto(url) {
var win = window.open(url, ifrejm,"width=800,height=600,left=40,top=10,scrollbars=yes,location=yes,resizable=yes");
if (win) return false;
else return true
}

//--- Svet bydleni - galerie fotek by barry END --//







//--- Raiffeisen Styl kontrola formulare START --//
    
function Check(f) 
{
  var strerr = "";
  
  if (f.Element0.value=="") strerr += "Jméno\n";
  if (f.Element1.value=="") strerr += "Příjmení\n";
  if (f.Element2.value=="") strerr += "Ulice\n";
  if (f.Element3.value=="") strerr += "Město\n";
  if (f.Element4.value=="") strerr += "PSČ\n";
  if (f.Element5.value=="") strerr += "Telefon  mobil\n";
  if (f.Element6.value=="") strerr += "Okres\n";
  if (f.Element7.value=="") strerr += "E-mail\n";
  if (f.Element8.value=="") strerr += "Současné řešení bytu domu určeného k rekonstrukci  nákupu\n";
  if (f.Element9.value=="") strerr += "Rozměr bytu či domu\n";
  if (f.Element10.value=="") strerr += "Typ bytu\n";
  if (f.Element11.value=="") strerr += "Rozsah rekostrukce\n";
  if (f.Element12.value=="") strerr += "Rozpočet\n";
  if (f.Element13.value=="") strerr += "Slogan\n";

  if (strerr != "") 
  {
    alert("Vyplňte všechna pole:\n\n" + strerr);
    return false;
  }
  if (!f.Element15.checked) 
  {
    alert("Účast v soutěži je třeba potvrdit souhlasem s podmínkami soutěže");
    return false;
  }
if (!f.Element16.checked) 
  {
    alert("Musíte potvrdit souhlas s použitím osobních údajů");
    return false;
  }
  return true;
}
//--- Raiffeisen Styl kontrola formulare END --//

//--- Svetbydleni CLOSE ---//
function CloseResults(idecko, obj){
el=document.getElementById(idecko).style; 
el.display=(el.display == 'block')?'block':'none';

}

//--- Svetbydleni CLOSE end ---//


//*********************************** GALLERY ***************************************

function ClickEvent(e)
{
	var obj;
	var i=0;
	var title = "Raiffeisen Styl";
	
	if (Br.IE)
		obj = window.event.srcElement;
	else
		obj = e.target;

	/*
	while(obj.parentNode.tagName!="TBODY" && obj.parentNode.tagName!="TABLE" && i<20)
	{
		obj = obj.parentNode;
		i++;
	}
	obj = obj.childNodes[0].childNodes[0];
	*/

	if (typeof(obj)=='object')
		if (obj.tagName=='IMG')
		{
			if (obj.alt!="") title=obj.alt;
			GaleryView(obj, title);
		}
} 

function GaleryView(obj, title)
{
	var ImgURL="";
	var nDot=0;
	var nWidth=10, nHeight=60;
	var _child;
	if (typeof(obj)!='object') return false;
	ImgURL = obj.src;
	if (ImgURL=="" && ImgURL=="undefined") return false;
	nDot = ImgURL.lastIndexOf(".");
	ImgURL = ImgURL.substr(0, nDot) + "big" + ImgURL.substr(nDot, ImgURL.length);

	if (Br.NS)
	{
		nWidth += 14;
		nHeight += 23;
	}

	_child=window.open("about:blank","","height=200,width=200");
	_child.document.write('<html>\n')
	_child.document.write(' <head><title>' + title + '</title></head>\n')
	_child.document.write(' <body leftMargin=0 topMargin=0  style="cursor:pointer; font-family:Verdana; font-size:14px;font-weight:bold;">\n')
	_child.document.write('<script language="javascript">\n');
	_child.document.write('function ResizeWin()');
	_child.document.write('	{window.resizeTo(document.getElementById("foto").width+' + nWidth + ',document.getElementById("foto").height+' + nHeight + ');}\n');
	_child.document.write('function notLoaded()');
	_child.document.write('	{document.getElementById("foto").style.display="none";\n');
	_child.document.write('	document.getElementById("errTxt").style.display="block";');
	_child.document.write('	window.resizeTo(350, 40)}');
	_child.document.write('</script>\n');
	_child.document.write('<div style="display:none;width:100%;padding-top:25px;text-align:center;" id="errTxt">THE PICTURE IS NOT AVAILABLE.</div>\n');
	_child.document.write('<img src="' + ImgURL + '" alt="" id=foto onload="ResizeWin()" onerror="notLoaded()">\n');
	_child.document.write(' </body>\n');
	_child.document.write('</html>\n');
}



//*************************MENU
function GetCustomMenuPositionRoot(pos)
{
	pos.x=-1;
	pos.y=124
}

function GetCustomMenuElementTagName(root)
{
	return "BODY";
}

function fnValidateForm( sElements, sLabelElements ) {
	var bReturn = true;
	var strAlert = "";
	var el = "";
	var arrEl = sElements.split("~");
	var arrLbl = sLabelElements.split("~");
	var x=0;
	for ( a = 0; a < arrEl.length; a++ ) {
		el = document.getElementById("Wizard_" + arrEl[a]);
		if ( !el ) {
			//strAlert += "\nNázev textového pole - " + arrEl[a] + " - neexistuje!\n\n"; bReturn = false;
		} else {
			  if ( el.value == "" ) 
        { 
          strAlert += "Není vyplněno pole: " + arrLbl[a] + "\n"; bReturn = false;
        }
		}
	}

	if ( !bReturn ) { alert(strAlert); }
	return bReturn;
}

//kontrola kontaktnich udaju START
function validateForm() {  
  var email = document.getElementById('writetousmail'); 
  var reg_email = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;  
  
  if (!reg_email.test(email.value)) {
    alert('Email je zadán ve špatném formátu. Zadejte prosím platný e-mail');
    return false;
  } 
}
//kontrola kontaktnich udaju END

function copyValue(srcEl,elId,con){ document.getElementById(elId).value=srcEl.value+";"+con; }

function kontrola(souhlas){
	var s = document.getElementById('souhlas');	
	if(s.checked == false){ alert('Pokud se chcete registrovat musíte souhlasit s registračními podmínkami!'); return false; }
}

function showLoginBox(){
	var gl = document.getElementById('galleryLogin');
	if(gl.style.display == "block"){ gl.style.display = "none"; }
	else{ gl.style.display = "block"; }
	
}

// kontrola registracniho formulare pro uzivatelskou fotogalerii

function kontrolaRegistrace(form){ 
	var s = document.getElementById('souhlas');	
	if(s.checked == false){ alert('Pokud se chcete registrovat musíte souhlasit s registračními podmínkami!'); return false; }

	if(form.userName.value == ""){
		alert("Zadejte prosím Vaše přihlašovací jméno!");
		form.userName.focus(); 
		return false;		  
	}
	

	else if(form.password.value == ""){
		alert("Zadejte prosím Vaše heslo!");
		form.password.focus(); 
		return false;		  
	}

	else if( (form.password2.value == "") || (form.password2.value != form.password.value) ){
		alert("Heslo pro ověření je prázdné nebo se neshoduje se zadaným heslem v políčku výše.");
		form.password2.focus(); 
		return false;		  
	}
	
	else if(form.mail.value == "" || form.mail.value.indexOf('@')==-1 || form.mail.value.indexOf('.')==-1){
		alert("Zadejte prosím Váš e-mail!");
		form.mail.focus();
		return false;
	}
		
}
