function GetElement(jmeno)
{
	return window.document.getElementById(jmeno);
}

function popUpWindow2(ID,URL,WIDTH,HEIGHT) {
    eval("page" + ID + " = window.open(URL, '" + ID + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + WIDTH + ",height=" + HEIGHT + ",left = 100,top = 30');");
}

/*function retDataFromPopUp(id, seq, nm) {
    window.opener.document.getElementById(id).value = nm;
    window.opener.document.getElementById("h_"+ id).value = seq;    
}
*/

function popUpWindow(URL,WIDTH,HEIGHT,PARAM) 
{
    day = new Date();
    id = day.getTime();
    if (PARAM=='') PARAM = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1';
    eval("page" + id + " = window.open(URL, '" + id + "', '"+PARAM+",width=" + WIDTH + ",height=" + HEIGHT + ",left = 100,top = 30');");
}

function popUpIdWindow(ID,URL,WIDTH,HEIGHT,PARAM) 
{
    var id = ID;
    if (PARAM=='') PARAM = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1';
    eval("page" + id + " = window.open(URL, '" + id + "', '"+PARAM+",width=" + WIDTH + ",height=" + HEIGHT + ",left = 100,top = 30');");
}

function popUpNewBrowserWindow(URL) 
{
    day = new Date();
    id = day.getTime();
    PARAM = 'fullscreen=1,toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width='+screen.width+',height='+screen.height+',left = 0,top = 0';
    eval("page" + id + " = window.open(URL, '" + id + "', '" + PARAM + "');");
}

//print page
function printPage(){
	window.print();
}

function DelRow(i,r)
{
	if(r.value=='D')
	{
		r.value='U';
		i.src='./images/wwfdel.gif';
		i.alt='smazat záznam';
	}
	else
	{
		r.value='D';
		i.src='./images/wdrop.gif';
		i.alt='obnovit záznam';
	}
}

function checkEmail(email)
{
	if (window.RegExp)
	{ 
		var re = new RegExp('^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$');
		
		if (!re.test(email))
			{
			window.alert("Emailová adresa nemá správný formát!");
			return false;
			}
	}
	return true;
}

function validateComment(form) {
	var nick =  form.nick.value;
	var email =  form.email.value;
	var titulek =  form.titulek.value;
	if (nick=="") {alert('Položka Nick je povinná!'); return false;}
  	if (titulek=="") {alert('Položka Nadpis příspěvku je povinná!'); return false;}
  	if (!checkEmail(email)) {return false;}
  return true;
}

function validateRozcestnik()
{
	if (GetElement('r_typ').value=='') {alert('Položka Typ odkazu je povinná!'); return false;}
  	if (GetElement('r_email').value=='') {alert('Položka Váš email je povinná!'); return false;}
  	if (GetElement('r_text').value=='') {alert('Položka Text odkazu je povinná!'); return false;}
  	if (GetElement('r_url').value=='') {alert('Položka Url odkazu je povinná!'); return false;}
  	if (!checkEmail(GetElement('r_email').value)) {return false;}
  return true;
}

function minFtxtLen(form) 
{
	var ftxt =  form.ftxt.value;
	
	if (ftxt.length>0 && ftxt.length<4) {alert('Položka hledaného textu musí mít minimálně čtyři znaky !'); return false;}
  
  return true;
}

function qSearchTarget(form, val) 
{
	if(val=='ARCHIV') form.action='archiv.php';
	else if(val=='GALLERY') form.action='photogallery.php';
	else if(val=='PHOTO') form.action='photos.php';
	else form.action='news.php';
}

function showTvPrgDetail(d, img, nm, dt, tv, txt, cursorx, cursory)
{
	var x=new Array('tv_nm','tv_foto','tv_dt','tv_station','tv_text');
	
	var z=d.getElementById('detail');
	
	if(z.style.visibility=='hidden')
	{
		z.style.marginTop=(cursory-220)+'px';
		
		z.style.marginLeft=(cursorx-220)+'px';
		
		z.style.visibility='visible';
		
		z.style.zIndex="2";
	}
	
	for(var i=0;i<x.length;i++)
	{
		var n=d.getElementById(x[i]);
		switch(i)
		{
			case 0:			
				n.innerHTML=nm;
				break;
			case 1:			
				n.innerHTML='<img src="./'+img+'">';
				break;
			case 2:			
				n.innerHTML=dt;
				break;
			case 3:			
				n.innerHTML=tv;
				break;
			case 4:			
				n.innerHTML=txt;
				break;
			default:
				break;
		}
	}
}

function SetCookie(cookieName,cookieValue, nMin) {
 var today = new Date();
 var expire = new Date();
 
 if (nMin==null || nMin==0) nMin=30;
 expire.setTime(today.getTime() + nMin*60*1000);
 document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
}

function simpleMenuAJQuery(url, html){
	jQuery("div#"+html).load(url);
}
/*
function setMenuHidden(html){
	$("div#"+html).css("display","none");
}*/

function simpleAJQuery(url, html){
	jQuery(html).load(url);
}

function simpleToggle(html){
	 jQuery(html).slideToggle("fast");
}

/*skryje polozku*/
function hide_html(html){
	jQuery(html).hide("slow");
}

/*zobrazi polozku*/
function show_html(html){
	jQuery(html).show("slow");
}

/*vymaze hodntu combo boxu*/
function ResetCombo(FormName,ide,dis){
	document.forms[FormName].elements[ide].selectedIndex = null;
	document.getElementById(ide).disabled = dis;
}
/*smaze hodnotu z text. inputu*/
function ResetInput(ide){
	document.getElementById(ide).value = null;
}
/*nastavi checkbox na null*/
function ResetCheck(ide){
	document.getElementById(ide).checked = null;
}
/*nastavi polozku formulare na disabled*/
function disableForm(ide){
	document.getElementById(ide).disabled = true;
}
/*nastavi polozku formulare na enabled*/
function enableForm(ide){
	document.getElementById(ide).disabled = false;
}
/*pokud je nastavena hodnota comboboxu, vrati true, pokud je null vrati false*/
function getVarFromCombo(FormName,ide){
		if (document.forms[FormName].elements[ide].selectedIndex != '') return true;
		else return false;
}
/*pokud je checkbox zaskrtnuty, vrati true, jinak false*/
function getVarFromCheck(ide){
		if (document.getElementById(ide).checked != '') return true;
		else return false;
}
/*pokud text. input obsahuje nejakou hodnotu, vrati true, jinak false*/
function getVarFromText(ide){
		if (GetElement(ide).value != '') return true;
		else return false;
}

function confirm_delete(WARNING) {
		if (confirm(WARNING)) {return true;}
    	else {return false;}
}
function openWindow(url,widthX,heightY){
        if(widthX>heightY){
            leftX=(screen.width-widthX)/2; 
            topY=(screen.width-widthX)/2; }//lezici obdelnik
        else{
            leftX=(screen.width-widthX)/2; //stojici obdelnik
            topY=(screen.height-heightY)/2;
        }
				var okno = window.open(url,'RallyMania','width='+widthX+',height='+heightY+',left='+leftX+',top='+topY+',scrollbars=yes,location=no,resizable=yes,copyhistory=no,directories=no'); 
				okno.document.writeln("<html>");
        okno.document.writeln("<head>");
        okno.document.writeln("<title>Rally-Mania.cz</title>");
        okno.document.writeln("</head>");
        okno.document.writeln("<body bgcolor=\"black\" topmargin=\"0\" leftmargin=\"0\">");
        okno.document.writeln("<div align=\"center\"><font face=\"Verdana\" size=\"2\" color=\"white\"><< Kliknutím na obrázek zavřete okno >></font></div>");
        okno.document.writeln("<img src=\"" + url + "\" width=\"" + widthX + "\" height=\"" + heightY + "\" alt=\"Rally-Mania.cz\" title=\"Rally-Mania.cz\" onclick=\"window.close();\" />");
        okno.document.writeln("</body>");
        okno.document.writeln("</html>");
        okno.document.close();
				return false;
}	

function openWindowFotogalerie(url,widthX,heightY){
        if(widthX>heightY){
            leftX=(screen.width-widthX)/2; 
            topY=(screen.width-widthX)/2; 
            widthX+=30;
            heightY+=100;
            }//lezici obdelnik
        else{
            leftX=(screen.width-widthX)/2; //stojici obdelnik
            topY=(screen.height-heightY)/2;
            widthX+=30;
            heightY+=100;
        }
        
				var okno = window.open(url,'RallyMania','width='+widthX+',height='+heightY+',left='+leftX+',top='+topY+',scrollbars=yes,location=no,resizable=yes,copyhistory=no,directories=no'); 
				return false;
}

function slideSwitch(id,elm) {var active = jQuery('#'+id+' '+elm+'.active');if ( active.length == 0 ) active = jQuery('#'+id+' '+elm+':last');var next =  active.next().length ? active.next() : jQuery('#'+id+' '+elm+':first');active.addClass('last-active');next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 800, function() {active.removeClass('active last-active');});}

/*Fce ziska X souradnici kurzoru mysi uzivatele*/
function findXCoord(evt) {
	/*Ie browser*/
	if (evt.x) return evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	/*gecko*/
	if (evt.pageX) return evt.pageX; 
}
/*Fce ziska Y souradnici kurzoru mysi uzivatele*/
function findYCoord(evt) {
	/*Ie browser*/
	if (evt.y) return evt.clientY + document.documentElement.scrollTop + document.body.scrollTop
	/*gecko*/
	if (evt.pageY) return evt.pageY; 
}


//screen resolution
function screenResW()
{
	return screen.width
}

function screenResH()
{
	return screen.height;
}

function findPos(elm) 
{
	var obj = GetElement(elm);	
	
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	
		//return [curleft,curtop];
		return curleft+','+curtop;
	}
}

/*funkce testuje nastaveni css stylu daneho elementu a css vlastnosti*/
function getElementCssPropertyValue(html_element,css_element)
{
	var val = jQuery(html_element).css(css_element);
		
	return val;
}


/*funkce testuje, jestli je zadanny html element visible or not*/
function getElementCssProperty(html_element)
{
	var display = jQuery(html_element).css("display");
		
	if (display!='none') return true;
	else return false;
}


/*Nastavi CSS vlastnost xhtml elementu*/
function setCssPropertyToElement(html_element,arr_css_id,arr_css_val)
{
	/*alert(arr_css_id.length);*/
	for (i = 0; i < arr_css_id.length; i++){
		
		jQuery(html_element).css(arr_css_id[i],arr_css_val[i]);
		
	}
}
/*Rici nacteni Google Video search controlu*/
function LoadVideoSearchControl(search_string)
        {
            /*alert(search_string);*/

            var predefinedTags = [
   				{ query : "gronholm", label : "Marcus&nbsp;Grönholm"},
                       		{ query : "sebastien loeb", label : "Sébastien&nbsp;Loeb"},
                       		{ query : "hirvonen", label : "Mikko&nbsp;Hirvonen"},
                                ];
    
            //var predefinedTags = [search_string];
                                

	    var options = { twoRowMode : false, string_allDone : "Vyhledat nové video!", largeResultSet : true};

	    var videoSearch = new GSvideoSearchControl(
	                              document.getElementById("videoControl"),
	                              predefinedTags,
	                              null,
	                              saveTags,
	                              options
	                              );
        }



function loadTags() {
    var tagStrings = GSvideoSearchControl_JSON.stringify("videoControl");
    return tagStrings;
  }

function saveTags(tags) {
    alert(tags);
  }
/*
function setTags(tags) {
    this.tags = tags;
}

setTags.prototype.getTags = function() {
    return this.tags;
}
*/









