// funkce pro vlozeni fotek z fotogalerie ke clanku START
function GenerateCustomFckGallery(files_array)
{
		var result="";
		for (var a=0;a<files_array.length;a++)
			result+="<a class=\"lightview\" href=\""+files_array[a].path+"\" rel=\"gallery[myset]\"><img class=\"body-gallery\" alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
		return result;
}
// funkce pro vlozeni fotek z fotogalerie ke clanku END

function SendFilterForm() {  
  var myForm = document.getElementById("filterForm");
  myForm.submit();  
}

// 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

//kontrola kontaktnich udaju START - czech
function validateForm() {
  var company = document.getElementById('Firm');
  var ico = document.getElementById('Ico');  
  var companyAgend = document.getElementById('Name');
  var ticketCount = document.getElementById('TicketCount');
  var email = document.getElementById('Email');
  var phone = document.getElementById('Phone');    
  
  var reg_email = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  var reg_phone = /^[ 0-9\.\+\/\-]{8,}$/;
  
  var alertString = new Array();  
  
  if (company.value == '') {
    alertString.push("<p style='padding:5px;color:#C23832'>Nevyplnili jste název firmy</p>");   
  }
  
  if (ico.value == '') {
    alertString.push("<p style='padding:5px;color:#C23832'>Nevyplnili jste IČO</p>");           
  }
  
  if(IsNumeric(ico.value) == false) {
    alertString.push("<p style='padding:5px;color:#C23832'>IČO musí být číselná hodnota</p>");
  }
  
  if (companyAgend.value == '') {
    alertString.push("<p style='padding:5px;color:#C23832'>Nevyplnili jste zastupce firmy</p>");    
  }
  
  if (ticketCount.value == '') {
    alertString.push("<p style='padding:5px;color:#C23832'>Nevyplnili jste počet účastníků</p>");    
  }
  
  if(IsNumeric(ticketCount.value) == false) {
    alertString.push("<p style='padding:5px;color:#C23832'>Počet účastníků musí být číselná hodnota</p>");
  }
  
  if (!reg_email.test(email.value)) {
    alertString.push("<p style='padding:5px;color:#C23832'>Email je zadán ve špatném formátu. Zadejte prosím platný e-mail</p>");
  }
  
  if (phone.value == '') {
    alertString.push("<p style='padding:5px;color:#C23832'>Nevyplnili jste Telefon</p>");
  }
  
  if (alertString.length > 0) {    
    var errorObject = document.createElement('div');
    errorObject.setAttribute("id", "mb_errorMsg");       
    var myValue = '';
    for(var i = 0;i < alertString.length;i++) {      
      myValue += alertString[i];
    }    
    document.getElementById('mb_errorMsg').innerHTML = myValue; 
    Mediabox.open('#mb_errorMsg', 'Chyba', '');
    return false;
  }
       
}

function IsNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {  
      IsNumber = false;
    }
  }
  return IsNumber; 
}

//kontrola kontaktnich udaju END - czech

function infoBox(message) {
  var viewMessage = "<p style='padding:5px;color:#C23832'>"+message+"</p>";
  document.getElementById('mb_infoMsg').innerHTML = viewMessage;
  Mediabox.open('#mb_infoMsg', 'Info', '');
}


function imgSelect(id) {
  for(var i = 1;i<4;i++) {
    if(i==id) {
      document.getElementById("img_"+id).style.display = "block";
    } else {
        document.getElementById("img_"+i).style.display = "none";
    }
  }
}

Date.format = 'dd.mm.yyyy';

$(function()
{
	$('.date-pick').datePicker(
    {
      clickInput:true,
      startDate:'01/01/1996',
      renderCallback:function($td, thisDate, month, year)
				{
					if (thisDate.getDay()==0) {						
						$td.addClass('disabled');
					}
				}
    });
});

$(document).ready(function(){       
  // Nastaveni Javascriptove validace prislusnym formularum dle ID
  $(".allForms").ndFormValidator();
});
  

