function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
      appSource = sender.getHost().Source;
    }
    
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
      return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

    errMsg += "Code: "+ iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {           
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " +  args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}



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,
  					galleryCounts: false
  				});
  			}
  		}
  	};
  	
  });
  
  } catch(err) {
  
}


try {
  $(document).ready(function(){
    $("#productBox").ndRotator();
    $("#presentBox").ndRotator({slideShowTime:4000});
    
    $("#sendArticle").ndFormValidator();
    
    
    $("table.PrichuteMainTbl2 table").find("tr:first").addClass("tblHead");
    $(".PrichuteMainTbl2 table tr:even").addClass("tableLineColor");
    
	  
    //$("table").find('tbody td:nth-col(2)').addClass("colored");
    
  });
} 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


//*********************************** Klik na produkt do eshopu ***************************************


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://shop.nutrend.cz/cz/produkt/"+url+"/";


}





//*********************************** GALLERY ***************************************

function ClickEvent(e)
{
	var obj;
	var i=0;
	var title = "Nutrend gallery";
	
	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');
}

function FitWindowToImage(image)
{
    if (image)
    {
        try
        {
            window.resizeTo(image.width + 200, image.height + 10);
        }
        catch(ex)
        {}
    }
}

function OverServis ()
{
   if (document.design.Element0.value == "")
   {
      document.design.Element0.focus();
      alert ("Nezadal(a) jste Vaše jméno");
      return false;
   }
   if (document.design.Element1.value == "")
   {
      document.design.Element1.focus();
      alert ("Nezadal(a) jste Vaše přijmení");
      return false;
   }
   if (document.design.Element2.value == "")
   {
      document.design.Element2.focus();
      alert ("Nezadal(a) jste název ulice");
      return false;
   }
   if (document.design.Element3.value == "")
   {
      document.design.Element3.focus();
      alert ("Nezadal(a) jste město");
      return false;
   }
   if (document.design.Element4.value == "")
   {
      document.design.Element4.focus();
      alert ("Nezadal(a) jste PSČ");
      return false;
   }
  if (document.design.Element5.value == "")
   {
      document.design.Element5.focus();
      alert ("Nezadal(a) jste stát");
      return false;
   }
 
   if (document.design.Element6.value == "")
   {
      document.design.Element6.focus();
      alert ("Nezadal(a) jste telefon");
      return false;
   }
   inpCell=document.design.Element6.value;
   tel=/^[0-9]{9,12}$/
   if (!tel.test(inpCell))
   {
      document.design.Element6.focus();
      alert ("Chybný formát telefonního čísla");
      return false;
   }

   
   if (document.design.Element8.value == "")
   {
      document.design.Element8.focus();
      alert ("Nezadal(a) jste Váš e-mail");
      return false;
   }
   inpMail=document.design.Element8.value;
   mail=/^.+@.+\..{2,3}$/;
   if (!mail.test(inpMail))
   {
      document.design.Element8.focus();
      alert ("Chybný formát e-mailu");
      return false;
   }


}


function GetCustomMenuPosition(pos)
{
    pos.x=-6;
    pos.y=2;
}



var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

var someMenuEntered = 0;
var mainMenuVisible = 0;
var regionMenuVisible = 0;
var reglocMenuVisible = 0;
var currentVisibleLocMenu = 0;
var currentScript = 'none';

function getObj(id) {
  if (isDOM) return document.getElementById(id);
  if (isIE4) return document.all[id];
  if (isNS4) return document.layers[id];
}

function setTopOffset() {
  if (navigator.appName.indexOf('Microsoft') < 0) {
    getObj('body_table').style.top='-2px';
    getObj('bottom_line').style.top='-2px';
  }
}

function selectTopItem(obj) {
  getObj(obj).style.color='black';
  getObj(obj).style.background='#ffd469';
}

function selectMenuItem(obj) {
  getObj(obj).style.color='black';
  getObj(obj).style.background='#ffd469';
}

function deselectTopItem(obj) {
  getObj(obj).style.color='white';
  getObj(obj).style.background='black';
}

function deselectMenuItem(obj) {
  getObj(obj).style.color='black';
  getObj(obj).style.background='#c4daf7';
}

function setCurrentScript(sname) {
  currentScript = sname;
}

function checkDropMenu(id) {
  if (id == 1) someMenuEntered = 1;
  if (id == 0) {
    if (someMenuEntered == 1) {
      hideMainMenu();
      hideRegionMenu();
      hideRegLocMenu();
      hideCurrentLocMenu();
      someMenuEntered = 0;
    }
  }
}

function toggleMainMenu() {
  if (mainMenuVisible == 0) {
    hideRegionMenu();
    hideRegLocMenu();
    hideCurrentLocMenu();
    showMainMenu();
  } else {
    hideMainMenu();
  };
}

function showMainMenu() {
  mainMenuVisible = 1;
  getObj('main_menu').style.display='block';
}

function hideMainMenu() {
  mainMenuVisible = 0;
  getObj('main_menu').style.display='none';
}

function toggleRegionMenu() {
  if (regionMenuVisible == 0) {
    hideMainMenu();
    hideRegLocMenu();
    hideCurrentLocMenu();
    showRegionMenu();
  } else {
    hideRegionMenu();
  };
}

function showRegionMenu() {
  regionMenuVisible = 1;
  var l = getObj('mtop1').clientWidth + 15;
  getObj('region_menu').style.left = l + 'px';
  getObj('region_menu').style.display='block';
}

function hideRegionMenu() {
  regionMenuVisible = 0;
  getObj('region_menu').style.display='none';
}

function toggleRegLocMenu() {
  if (reglocMenuVisible == 0) {
    hideMainMenu();
    hideRegionMenu();
    hideCurrentLocMenu();
    showRegLocMenu();
  } else {
    hideCurrentLocMenu();
    hideRegLocMenu();
  }
}

function showRegLocMenu() {
  reglocMenuVisible = 1;
  var lof = getObj('mtop1').clientWidth + getObj('mtop2').clientWidth + 17;
  getObj('regloc_menu').style.left = lof + 'px';
  getObj('regloc_menu').style.display='block';
}

function hideRegLocMenu() {
  reglocMenuVisible = 0;
  getObj('regloc_menu').style.display='none';
}

function callScript(sname) {
  var url = sname + '?lang=1&rg=4&loc=3&prg=0';
  location.href = url;
}

function callScriptCamera(sname, cpart, camid) {
  var url = sname + '?lang=1&rg=4&loc=3&cpart=' + cpart + '&cam=' + camid;
  location.href = url;
}

function callScriptRegionData(sname,id) {
  var url = sname + '?lang=1&rg=' + id;
  location.href = url;
}

function callScriptAllData(sname) {
  var url = sname + '?lang=1';
  location.href = url;
}

function callURL(url) {
  location.href = url;
}

function callCurrentScript(id) {
  var url = currentScript + '?lang=1&rg=' + id + '&loc=3';
  location.href = url;
}

function callCurrentScriptAllData() {
  var url = currentScript + '?lang=1';
  location.href = url;
}

function callLocation(rg,loc) {
  var url = 'stredisko.php?lang=1&rg=' + rg +'&loc=' + loc;
  location.href = url;
}

function showLocMenu(id,por) {
  var tof = (getObj('regloc' + id).clientHeight * por) + por + 15;
  var lof = getObj('mtop1').clientWidth + getObj('mtop2').clientWidth + getObj('regloc_menu').clientWidth + 17;
  hideCurrentLocMenu();
  getObj('loc_menu' + id).style.left = lof + 'px';
  getObj('loc_menu' + id).style.top = tof + 'px';
  getObj('loc_menu' + id).style.display = 'block';
  currentVisibleLocMenu = id;
}

function hideCurrentLocMenu() {
  if (currentVisibleLocMenu != 0) {
    getObj('loc_menu' + currentVisibleLocMenu).style.display='none';
    currentVisibleLocMenu = 0;
  }
}

function WebLauncher(adr) {
  var url = "http://" + adr;
  if (adr.indexOf("http") == 0) url = adr;
  window.open(url,"","toolbar=no,scrollbars=yes,location=no,status=no,left=10,top=50,width=800,height=500,resizable=1");
}

function ImageLauncher(id,rg,loc) {
  var akce = "wimg.php?id=" + id + "&kat=20&rg=" + rg + "&loc=" + loc;
  window.open(akce,"","toolbar=no,scrollbars=yes,location=no,status=no,left=10,top=10,width=460,height=330,resizable=1");
}

function ImageLauncherLet(id,rg,loc) {
  var akce = "wimg4.php?id=" + id + "&kat=3&rg=" + rg + "&loc=" + loc;
  window.open(akce,"","toolbar=no,scrollbars=yes,location=no,status=no,left=10,top=10,width=460,height=330,resizable=1");
}

function showCamera(listObj) {
  var id_cam=listObj.options[listObj.selectedIndex].value;
  var akce = "kamera.php?lang=1&id_cam=" + id_cam;
  location.replace(akce);
}

function showVideo(rg,loc,cid) {
  var akce = "http://www.holidayinfo.cz/video.php?lang=1&rg=" + rg + "&loc=" + loc + "&cid=" + cid;
  window.open(akce,"","toolbar=no,scrollbars=no,location=no,status=no,left=40,top=20,width=350,height=400,resizable=1");
}

function checkUbytovani(rg,loc) {
  if (getObj('ubyt_form').mail.value == '') {
    alert('Vyplňte Váą e-mail prosím!');
    return false;
  }

  return true;
}

var bannerLink = 'http://www.rwe.cz';
var bannerLinkArray = new Array;
bannerLinkArray[0]='http://www.rwe.cz';
bannerLinkArray[1]='http://www.rwe.cz';
bannerLinkArray[2]='http://www.rwe-transgas.cz';
bannerLinkArray[3]='http://www.rwe-transgas.cz';
bannerLinkArray[4]='http://www.rwe-transgas.cz';
bannerLinkArray[5]='http://www.rwe-jmp.cz';
bannerLinkArray[6]='http://www.rwe-scp.cz';
bannerLinkArray[7]='http://www.rwe-smp.cz';
bannerLinkArray[8]='http://www.rwe-stp.cz';
bannerLinkArray[9]='http://www.rwe-vcp.cz';
bannerLinkArray[10]='http://www.rwe-zcp.cz';

function setBannerLink(bid) {
  var btt = 2000;

  bannerLink = bannerLinkArray[bid];

  bid = bid + 1;
  if (bid == 11) bid = 0;

  if ((bid == 2) || (bid == 3) || (bid == 4)) btt = 1000;
  setTimeout("setBannerLink(" + bid + ")", btt);
}

function showBannerLink() {
  window.open(bannerLink,"","toolbar=no,scrollbars=yes,location=no,status=no,left=10,top=50,width=800,height=500,resizable=1");
}

function showTVTimes() {
  window.open("showtimes.php?rg=4&loc=3&lang=1","","toolbar=no,scrollbars=yes,location=no,status=no,left=10,top=50,width=200,height=80,resizable=1");
}


var myTWin = window.myTWin; 

function OpenMyWin(link,winName) 
{ 
  var retValue=true; 
  if (myTWin!=null && !myTWin.closed) 
  { 
    myTWin.focus(); 
    myTWin.location.href=link.href;
window.open(url, null, "top=" + top + ",left=" + left + ",height=" + h + ",width=" + w + ",status=yes,toolbar=no,menubar=no,location=yes,resizable=yes,scrollbars=yes");    

  } 
  else 
  { 
    myTWin=window.open(link.href,winName); 
    if (myTWin==null || typeof(myTWin)=="undefined") 
      retValue=false; 
    else 
    { 
      link.target=winName; 
      myTWin.focus(); 
    } 
  } 
  return retValue; 
} 


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 ValidateSendMail()
{
if(!IsNoEmpty(GetElement('Name'),true,3,'Vyplňte prosím políčko Jméno','Pole Jméno musí obsahovat nejméně 3 znaky'))return false;	
if(!IsEmail(GetElement('SenderEmail'),true,'Vložte prosím platnou e-mailovou adresu.',false))return false;	
if(!IsEmail(GetElement('RecipientEmail'),true,'Vložte prosím platnou e-mailovou adresu.',false))return false;	
if(!IsNoEmpty(GetElement('Remark'),true,3,'Vyplňte prosím políčko Titulek.','Pole Titulek  musí obsahovat nejméně 3 znaky'))return false;	
return true;
}


function searchtxb_lenght() {
  
  if (document.getElementById("txtExpresion").value != "hledání...") {
  
    if (document.getElementById("txtExpresion").value.length<=3) {
      alert("Zadejte prosím minimálně 4 znaky");
      return false;
    }
    
  return true;
  }
  alert("Zadejte prosím hledaný výraz");
  return false;
}

function OverFAQ ()
{
   if (document.design.inpOsobnostiName.value == "")
   {
    document.design.inpOsobnostiName.focus();
    alert ("Nezadal(a) jste jméno a příjmení");
    return false;
   }
   if (document.design.inpOsobnostiEmail.value == "")
   {
    document.design.inpOsobnostiEmail.focus();
    alert ("Nezadal(a) jste Váš e-mail");
    return false;
   }
   inpMail=document.design.inpOsobnostiEmail.value;
   mail=/^.+@.+\..{2,3}$/;
   if (!mail.test(inpMail))
   {
    document.design.inpOsobnostiEmail.focus();
    alert ("Chybný formát e-mailu");
    return false;
   }
   if (document.design.inpOsobnostiQuestion.value == "")
   {
    document.design.inpOsobnostiQuestion.focus();
    alert ("Nezadal(a) jste dotaz");
    return false;
   }
 }
