// ve funkci createCookie je natvrdo napsana cesta, az se to bude davat jinam, tak zmenit!!!!

/* 
  ------------------------------------------------
  PVII Equal CSS Columns scripts -Version 2
  Copyright (c) 2005 Project Seven Development
  www.projectseven.com
  Version: 2.1.0
  ------------------------------------------------
*/
function P7_colH2(){ //v2.1.0 by PVII-www.projectseven.com
 var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){P7_eqA2(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa=1;
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
}
function P7_eqT2(){ //v2.1.0 by PVII-www.projectseven.com
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){P7_colH2();}
}
function P7_equalCols2(){ //v2.1.0 by PVII-www.projectseven.com
 var c,e,el;if(document.getElementById){document.p7eqc=new Array();
 document.p7eqc[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc[document.p7eqc.length]=c;document.p7eqc[document.p7eqc.length]=el}}
 setInterval("P7_eqT2()",10);}
}
function P7_eqA2(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
}


/**
 * Popup okno
 *
 */
function popup (url, width, height)
{
   var windowParams = ('fullscreen=yes,width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
   var okno = open(url, 'newWindow', windowParams);
   okno.focus(); 
}

function editContent(id)
{
   popup(id, 700, 600);
}

/**
 * Odstranuje netisknutelne znaky z konce a zacatku stringu
 *
 * @param string string k osetreni
 * @return string upraveny text
 */
function trim (string)
{
 return string.replace( /^\s*|\s*$/g, '');
}

/**
 * odkaz na otevirani odkazu do novych oken
 * k odkazu se prida atribut rel="external"
 */
function externalLinks() 
{
   if (!document.getElementsByTagName) {
      return;
   }
   var anchors = document.getElementsByTagName("a");
   for (var i = 0; i < anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") &&
          anchor.getAttribute("rel") == "external") {
         anchor.target = "_blank";
      }
   }
}

/**
 * Vytvori COOKIE
 */
function createCookie(name,value,days) 
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  
  document.cookie = name+"="+value+expires+"; host=extranet.miton.cz; path=/miton/dalen4/current/www";
}

/**
 * Precte COOKIE
 */
function readCookie(name) 
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
  return null;
}

/**
 * Vymaze COOKIE
 */
function eraseCookie(name) 
{
  createCookie(name,"",-1);
}

// Schovani sidebaru 
function hideColumn() {
  var column = document.getElementById('column');
  var columnCollapsed = document.getElementById('column-collapsed');
  var container = document.getElementById('container');
  var content = document.getElementById('content');

  column.style.display = 'none';
  columnCollapsed.style.display = 'block';
  content.style.marginLeft = '13px';
  container.style.backgroundPosition = '-191px 0';
  createCookie('columnCollapse','1',180);
}

function showColumn() {
  var column = document.getElementById('column');
  var columnCollapsed = document.getElementById('column-collapsed');
  var container = document.getElementById('container');
  var content = document.getElementById('content');

  column.style.display = 'block';
  columnCollapsed.style.display = 'none';
  content.style.marginLeft = '205px';
  container.style.backgroundPosition = '0 0';
  createCookie('columnCollapse','0',180);
  
}

function switchColumn() { // pro fluidni design
  var column = document.getElementById('column'); 
  var columnCollapse = readCookie('columnCollapse');
  //alert(columnCollapse);
    
  if(columnCollapse == '') {columnCollapse = '0';} 
   
  if(columnCollapse == '0') {
    hideColumn();    
  } else {
    showColumn();
  }
  
  //var columnCollapse = readCookie('columnCollapse');
  //alert(columnCollapse);

}

/* Nepoužito, pouzivam kontrolu cookies v PHP a pak tam includnu podle toho konkretni css :)
function checkColumnState() {
  var columnCollapse = readCookie('columnCollapse');
  
  //alert(document.cookie);
  
  if (columnCollapse == '') {columnCollapse = 0;}
  
  if (columnCollapse == 1) {
    hideColumn();
  } else {
  
  }
  
  //alert(columnCollapse);
} 

*/  

//Nastaveni barvicek, ktere se budou menit
var color1 = '#000';
var color2 = '#fff';
var gbb1BgPos1 = 'top left';
var gbb1BgPos2 = 'top right';

//Menic barvy pozadi u velkeho obrazku 
function switchBigPicImgBg() {
  var bigPicImg = document.getElementById('bigpic-img');
  var gbb1 = document.getElementById('gbb1');
  var bigPicImgBg = readCookie('bigPicImgBg');
  
  if (bigPicImg.style.backgroundColor == '') {bigPicImg.style.backgroundColor = color1;} 
    
  if (bigPicImgBg == '0' ) { 
      
      //alert(bigPicImg.style.backgroundColor);
      
      bigPicImg.style.backgroundColor = color2;
      gbb1.style.backgroundPosition = gbb1BgPos2;
      createCookie('bigPicImgBg','1',180);
      createCookie('gbb1BgPos','gbb1BgPos2',180);
        
  } else {
    bigPicImg.style.backgroundColor = color1;
    gbb1.style.backgroundPosition = gbb1BgPos1;
    createCookie('bigPicImgBg','0',180);
    createCookie('gbb1BgPos','gbb1BgPos1',180);
  }
  
  //alert(bigPicImg.style.backgroundColor);
  //var bigPicImgBg = readCookie('bigPicImgBg');
  //alert(bigPicImgBg);
} 

/* Na zaklade cookies zkontroluje jakou barvu uzivatel naposledy mel vybranou - nepouzito, ted pres PHP
function checkBigPicImgBg() {
  var bigPicImg = document.getElementById('bigpic-img');
  var bigPicImgBg = readCookie('bigPicImgBg');
  var gbb1 = document.getElementById('gbb1');
  var gbb1BgPos = readCookie('gbb1BgPos');
  
  //alert(bigPicImgBg);
  //alert(columnCollapse);
  
  if (bigPicImgBg == '') {bigPicImgBg = 'color1';}
  
  if (bigPicImgBg == 'color2') {
    bigPicImg.style.backgroundColor = color2;
    gbb1.style.backgroundPosition = gbb1BgPos2;
  } else {
  
  }
}
*/

//Omrdavka na window.onload :)
function regInitFcn (fcn)
{
  if (!window.addEventListener && !window.attachEvent) return false;
  if (window.addEventListener) window.addEventListener("load", fcn, false);
  else window.attachEvent("onload", fcn);
  return true;
}





//regInitFcn(initialize);


function onFlashUploadFinish() {
 //window.location="./"; 
}



function validOrder() {
    jQuery("#buyForm").validate({
        errorClass: "error",
        validClass: "valid",

        highlight: function(element, errorClass, validClass) {
            jQuery(element).addClass(errorClass).removeClass(validClass);
            jQuery(element.form).find("label[for=" + element.id + "]").addClass('highlight');
        },
        unhighlight: function(element, errorClass, validClass) {
            jQuery(element).removeClass(errorClass).addClass(validClass);
            jQuery(element.form).find("label[for=" + element.id + "]").removeClass('highlight');
        },
        rules: {
			jmeno: {required: true},
            prijmeni: {required: true},
            ulice: {required: true},
            mesto: {required: true},
            psc: {required: true},
            telefon: {required: true},
			email: {required: true, email: true}
		},
        messages: {
            jmeno: {required: ' '},
            prijmeni: {required: ' '},
            ulice: {required: ' '},
            mesto: {required: ' '},
            psc: {required: ' '},
            telefon: {required: ' '},
            email: {required: ' '}
		}
  });
}

function changeTechDotaz(el, isFocus) {
	if (el.value == 'Váš dotaz:') {
		el.value = '';
	}
	else if(el.value == '' && !isFocus) {
		el.value = 'Váš dotaz:';
	}

}




function showTable(city) {
   
  jQuery.ajax({
    type: "GET",
    url:"./",
    data:"city="+city+"&gettimetable=true",
    success: function(data) {
    $('timetable').innerHTML = data;
    location.hash = '#timetable';
      //alert('Load was performed. '+data);
    }
  });
  
  /*
  jQuery.ajax(
  {
  type: "GET", 
  url: './', 
  params,
  success: function(data) {
    //$('.result').html(data);
    alert('Load was performed. '+data);
    }
  }
  );
  */

}
