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(){
    // Nastaveni Javascriptove validace prislusnym formularum dle ID
    $(".allForms").ndFormValidator();
  	$("#topMenu").ndMenu({showActiveClass:"False"});
  });
  
} catch(err) {

}

// funkce pro zrušení defaultního textu input pole END

function KillDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == elementValue) {
    document.getElementById(elementId).value = "";
  }
}

// funkce pro zrušení defaultního textu input pole END

// funkce pro zpětné vložení def. textu START

function PasteDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == "") {
    document.getElementById(elementId).value = elementValue;
  }  
}

// funkce pro zpětné vložení def. textu END

function ukaz(){}

// vyhledavani ve slovniku
function SearchDict()
{
    var elm = document.getElementById("word");
    if (elm != null && elm.value != "hledej...")
    {
        var url = cutUrlParams(window.location.href, ["PageId","Letter","Text"]);
        url = setNiceUrlParameter(url, "text", escape(elm.value));
        window.location.href = url;
    }
}

// vyhledavani
function fnSearch() {}
function xxxx(){
   if (GetElement('EXPS').value.length<4 && GetElement('EXPS').value!='hadaj...')  {
      alert('Uvete aspo 4 znaky.');return false;
	}
	else
	{
      SetForm('/hladanie/default.aspx?catId=2516&txbSearch=' + GetElement('EXPS').value,true);
  }
}
			
function newWin(url)
{window.open(url, "newBox","width=600,height=400")}


function newbasketitem(id,name,amount,price)
{
	var item=Basket.New();
	item.Id=id;
	item.Name=name;
	item.Amount=amount;
	item.Price=price;
	Basket.Save(item);
}

function changePrice(qty_el,id)
{
	var item=Basket.Get(id);
	if (qty_el.value=='0') 
	{
		Basket.Delete(id);
	}
	else 
	{
	 	item.Amount=qty_el.value;
		Basket.Save(item);	
	}
	
}

function deleteCookie()
{
   Basket.Clear();
}

function OverForm ()
{
   if (document.order.firstname.value == "")
   {
      document.order.firstname.focus();
      alert ("Nezadal(a) jste křestní jméno");
      return false;
   }
   if (document.order.lastname.value == "")
   {
      document.order.lastname.focus();
      alert ("Nezadal(a) jste příjmení");
      return false;
   }
   if (document.order.street.value == "")
   {
      document.order.street.focus();
      alert ("Nezadal(a) jste ulici");
      return false;
   }
   if (document.order.city.value == "")
   {
      document.order.city.focus();
      alert ("Nezadal(a) jste město");
      return false;
   }
   if (document.order.zip.value == "")
   {
      document.order.zip.focus();
      alert ("Nezadal(a) jste PSČ");
      return false;
   }
  if (document.order.phone.value == "")
   {
      document.order.phone.focus();
      alert ("Nezadal(a) jste telefonní číslo");
      return false;
   }
   inpCell=document.order.phone.value;
   tel=/^[0-9]{9,12}$/
   if (!tel.test(inpCell))
   {
      document.order.phone.focus();
      alert ("Chybný formát telefonního čísla");
      return false;
   }
   if (document.order.mail.value == "")
   {
      document.order.mail.focus();
      alert ("Nezadal(a) jste Váš e-mail");
      return false;
   }
   inpMail=document.order.mail.value;
   mail=/^.+@.+\..{2,3}$/;
   if (!mail.test(inpMail))
   {
      document.order.mail.focus();
      alert ("Chybný formát e-mailu");
      return false;
   }
   alert("Vaše objednávka byla přijata. Děkujeme");
   return true;
 }
 
	function fnRedirect(idSel, idTxt)
	{
		var bReturn	= true;
		var objSel		= document.getElementById(idSel);
		var valOpt	  = objSel.options[objSel.selectedIndex].value;
		var valTxt		= document.getElementById(idTxt).value;

		if ( valOpt.indexOf(",") > -1 )
		{
			var arr = valOpt.split(",");
			valOpt = arr[0];
		}

		if (valOpt == 0 && valTxt != "") {
			bReturn = true;
		}else if (valOpt == 0){
			alert("Musíte vybrat kategorii nebo vložit hledaný výraz.");
			bReturn = false;
		}else{
			if (valTxt == "") { document.location.href="?CatID=" + valOpt; bReturn = false;}
		}
		return bReturn;
	}

function GenerateCustomFckGallery(files_array)
{
		var result="<br>";
		for (var a=0;a<files_array.length;a++)
			result+="<img class=\"body-gallery\" onclick=\"BodyGaleryView('"+files_array[a].path+"', 'Elmax.cz')\" alt=\"\" src=\""+files_array[a].thumb+"\" />";
		return result;
}
	function fnValidateForm ( sElements, sLabelElements ) {
		var bReturn = true;
		var strAlert = "";
		var el = "";
		var arrEl = sElements.split("~");
		var arrLbl = sLabelElements.split("~");
		for ( a = 0; a < arrEl.length; a++ ) {
			el = document.getElementById(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;
	}
	
	
	function BodyGaleryView(src, title)
{
	if ((src==null)||(src==""))
		return false;

	var pwb='<html>\r\n'+
		'<head><title>'+title+'</title></head>\r\n'+
		'<scr'+'ipt type="text/javascript" src="http://www.elmax.cz/_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 redirectParent(anchor)
{
	try
	{
		window.opener.location.href=anchor.href;
		this.close();
	}
	catch (ex)
	{
		return true;
	}

	return false;
}


//function ShowFlash() {
//  AddEventHandler(window,"load",function() {Mediabox.open('#mb_infoBox','','800 600')});
//}

