var W3CDOM = (document.createElement && document.getElementsByTagName);
var tempdir = '';




function showMap(){
    hideLists();
    new_window_link();
    if(document.getElementById('rightRail')){
    var xrightphoto = document.getElementById('rightRail');
    var obchodlinx = xrightphoto.getElementsByTagName('a');
	  for (var i = 0; i < obchodlinx.length; i++)
	  {    
	  if (obchodlinx[i].id) { 
	        obchodlinx[i].number = obchodlinx[i].id;
	        obchodlinx[i].onmouseover = highObchod;  
	        obchodlinx[i].onmouseout = darkObchod;
    }
	  }
    }
    if(document.getElementById('obchodypicMap')){
    var obchodypicMap = document.getElementById('obchodypicMap');
    var areas = obchodypicMap.getElementsByTagName('area');
 
	  for (var i = 0; i < areas.length; i++)
	  {  
	  if (areas[i].id) { 
          areas[i].number = areas[i].id.substring(2, 10) ;
	        areas[i].onmouseover = highObchod;  
	        areas[i].onmouseout = darkObchod;
    }
	  }    
    }
}

function highObchod(){
   if(document.getElementById('obchodypic')){
   var obchodypic = document.getElementById('obchodypic');
   url = tempdir + '/maps/' + this.number + '.gif';
   obchodypic.src = url;
   data = 'shopid='+this.number.substring(6,10);   ;
        url='/inside/ajx-obchod.php'; 
        if (window.ActiveXObject)
        {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
        httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("POST", url, true); 
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        httpRequest.send(data);
        httpRequest.onreadystatechange= function () {processRequestx(); } ;
        return false;
   }
}
function darkObchod(){
   if(document.getElementById('obchodypic')){
   var obchodypic = document.getElementById('obchodypic');
   obchodypic.src = tempdir + '/maps/none.gif';
   data = 'shopid=0';   ;
        url='/inside/ajx-obchod.php'; 
        if (window.ActiveXObject)
        {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
        httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("POST", url, true); 
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        httpRequest.send(data);
        httpRequest.onreadystatechange= function () {processRequestx(); } ;
        return false;
   }
}

function processRequestx()
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    { 
      var semka = document.getElementById("semka");
      semka.innerHTML = httpRequest.responseText;
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}



function hideLists(){
    if(document.getElementById('rightRail')){
    var xrightphoto = document.getElementById('rightRail');
    var obchodlinx = xrightphoto.getElementsByTagName('ul');
	  for (var i = 0; i < obchodlinx.length; i++)
	  {
    if(obchodlinx[i].id){
    obchodlinx[i].style.display = 'none'; 
    }
    } 
    var obchodh = xrightphoto.getElementsByTagName('h4');
	  for (var i = 0; i < obchodh.length; i++)
	  {
    if(obchodh[i].id){
    obchodh[i].number = obchodh[i].id;
    obchodh[i].onclick = toggleList;
    }
    }     
    } 
}
function toggleList(){
    if(document.getElementById('rightRail')){
    var xrightphoto = document.getElementById('rightRail');    
    var obchodlinx = xrightphoto.getElementsByTagName('ul');    
	  for (var i = 0; i < obchodlinx.length; i++)
	  {
    if(obchodlinx[i].id){
    if(obchodlinx[i].id.substring(2, 4) == this.number.substring(1, 4)){
    if(obchodlinx[i].style.display == 'none'){
    obchodlinx[i].style.display = 'block'; 
    document.getElementById(this.number).style.backgroundImage = 'url('+tempdir+'/images/minus.gif)';
    }
    else{
    obchodlinx[i].style.display = 'none';
    document.getElementById(this.number).style.backgroundImage = 'url('+tempdir+'/images/plus.gif)';         
    }
    }
    } 
    }
}
}
var path_to_icon 		= tempdir+'/images/icon.gif';
var link_alt_text 		= 'Otevřít odkaz v novém okně';
var link_title_text 	= 'Otevřít odkaz v novém okně';

function new_window_link() {
	if (!document.getElementById || !document.createTextNode || !document.domain || !document.getElementById('text')) return;
	var text = document.getElementById('text');
	var linx = text.getElementsByTagName('a');
	for (var i = 0; i < linx.length; i++)
	{
		// just for off-site links
		if (linx[i].href.length > 0)
		{
			if((linx[i].protocol == 'http:')||(linx[i].protocol == 'https:'))
			{

      	if ((linx[i].href.split('/')[2].replace(/www\./, '') != document.domain.replace(/www\./, '')||(linx[i].href.split('out.php')[1]))
				&& !linx[i].getAttribute('target')
				&& !linx[i].parentNode.id.match(/^copy/)
        && (linx[i].childNodes[0].tagName != 'IMG')
        )
				{
					// create new elements
					var nwl = document.createElement('a');
					var nwl_image = document.createElement('img');
					var space = document.createTextNode(' ');
					// setup image attributes
					nwl_image.setAttribute('src', path_to_icon);
					nwl_image.setAttribute('alt', link_alt_text);
					nwl_image.setAttribute('title', link_title_text);
					// set link attributes
					nwl.setAttribute('href', linx[i].getAttribute('href'));
					nwl.setAttribute('target', '_blank');
					nwl.setAttribute('title', link_title_text);
					nwl.className = 'new_window_link';
					// append new elements
					nwl.appendChild(nwl_image);
					linx[i].parentNode.insertBefore(space, linx[i].nextSibling);
					linx[i].parentNode.insertBefore(nwl, linx[i].nextSibling.nextSibling);
				}
			}
		}
	}
}
function formKontaktSend(formID){  
        var data = ''; 
        var form = document.getElementById(formID);
        var f_el = form.getElementsByTagName('input'); 
        var f_length = f_el.length; 
        
        for(i=0;i<f_length;i++){  
        if(f_el[i].type != 'checkbox'){
        data += f_el[i].name + '=' + f_el[i].value + '&'; 
        }
        else{
        if(f_el[i].checked == true){
        data += f_el[i].name + '=' + f_el[i].value + '&';
        }
        }  
        }
        var textareas = form.getElementsByTagName('textarea'); 
        for(i=0;i<textareas.length;i++){ 
        data += textareas[i].name + '=' + textareas[i].value + '&'; 
        } 
        var f_el = form.getElementsByTagName('select'); 
        var f_length = f_el.length; 
        for(i=0;i<f_length;i++){ 
        var options = f_el[i].getElementsByTagName('option'); 
        for(j=0;j<options.length;j++){ 
        if (options[j].selected == true || options[j].selected == 'true')
        data += f_el[i].name + '=' + options[j].value + '&';         
        }
        }             
        url='./pages/SendKontakt.php';           
        if (window.ActiveXObject)
        {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
        httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("POST", url, true); 
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        httpRequest.send(data);
        httpRequest.onreadystatechange= function () {processRequest(); } ;
        return false;
} 



function processRequest()
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    { 
      //buildGalery();
      var semka = document.getElementById("xcontactform");
      semka.innerHTML = httpRequest.responseText;
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}


function Validate(formID){
  var re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  var theForm = document.getElementById(formID);
  var theMessage = 'Vyplňte prosím povinná pole:<b><br/>';
  
  if((theForm.textik.value=='')||(theForm.email.value.search(re) != 0)){ 
       if(theForm.jmeno.value==''){ theMessage = theMessage +'Jméno <br/>'; }    
       if(theForm.textik.value==''){ theMessage = theMessage +' Zpráva <br/>'; }        
       if(theForm.email.value.search(re) != 0){ theMessage = theMessage +' E-mail [funkční adresa] '; }
        theMessage = theMessage +'</b>';
        document.getElementById('requiredtext').style.display= "block";
        document.getElementById('requiredtext').innerHTML= theMessage;        
       // setTimeout( "HideIt()",2500);
        return false;
        }
        else{
        formKontaktSend(formID);
        return false;
        }
}


function Validate2(formID){
  var re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  var theForm = document.getElementById(formID);
  var theMessage = 'Vyplňte prosím povinná pole:<b><br/>';
  
  if((theForm.fannickname.value=='')||(theForm.fanfanpass.value=='')){ 
       if(theForm.fannickname.value==''){ theMessage = theMessage +'Jméno <br/>'; }    
       if(theForm.fanfanpass.value==''){ theMessage = theMessage +' Heslo <br/>'; }        
        theMessage = theMessage +'</b>';
        document.getElementById('requiredtext').style.display= "block";
        document.getElementById('requiredtext').innerHTML= theMessage;        
       // setTimeout( "HideIt()",2500);
        return false;
        }
        else{
        return true;
        }
}
