function newWindow(obj, wWidth, wHeight)
{
	if(obj == null)
		return false;

	var name = "obrazek" + Math.ceil( Math.random() * 3000 );
	var width = (wWidth == null) ? 500 : parseInt(wWidth);
	var height = (wHeight == null) ? 400 : parseInt(wHeight);
	var loc = null;
	
	if(obj.tagName == "A" & obj.getAttribute("href") != null)
	{
		loc = obj.getAttribute("href");
	}
	
	if(loc != null)
	{
		wnd = window.open(loc , name, 'toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=yes,status=no,width='+width+',height='+height);
		wnd.focus();
		return false;
	}
	else
	{
		return true;
	}
}

var wndMargin = 0;
var screenW, screenH;

screenW = window.screen.availWidth;
screenH = window.screen.availHeight;

function closeWindow()
{
	if(window.opener != null)
	{
		window.opener.focus();
	}
		
	this.window.close();
}

function resizeWindow(w, h)
{
	var wndW, wndH = 0;
	var posX, posY = 0;
	w += wndMargin;
	h += wndMargin;
	
	if(w >= screenW)
		wndW = screenW;
	else
		wndW = w;
	if(h >= screenH)
		wndH = screenH;
	else
		wndH = h;

	posX = Math.ceil((screenW / 2) - (wndW / 2));
	posY = Math.ceil((screenH / 2) - (wndH / 2));
	if(posX < 0)
		posX = 0;
	if(posY < 0)
		posY = 0;
	
	window.resizeTo(wndW, wndH);
	window.moveTo(posX, posY);
}

function display(id, doDisplay)
{
	var layer = document.getElementById(id);
	
	if(layer == null)
		return;

	if(doDisplay == null)
	{
		layer.style.display = (layer.style.display == 'none') ? 'block' : 'none';
	}
	else
		layer.style.display = (doDisplay == true) ? 'block' : 'none';
		
	return false;
}

function clearInput(input, defaultValue)
{
	if(input.value == defaultValue)
	{
		input.value = '';
	}
	return false;
}

function iframeAdmin(url, activeObj)
{
	if(document.getElementById(activeObj) == null)
	{
		return false;
	}
	
	document.getElementById(activeObj).src = url;
	
	document.getElementById(activeObj).width = '800';
	document.getElementById(activeObj).height = '650';
	
	display(activeObj, true);
	display('editer_' + activeObj, false);
	display('close_' + activeObj, true);
	
	return false;
}

function showArea(obj, show)
{
	if(show == true)
	{
	    document.getElementById(obj).className = "admin_box";
	}
	else
	{
	    document.getElementById(obj).className = "";
	}
	
	return false;
}

function setActiveFlap(activeObj, inactiveObjsS, activeFlap, inactiveFlapsS, classActive, classInactive) {
    if (document.getElementById(activeObj) == null) {
        return false;
    }

    if (classActive == null) {
        classActive = "active";
    }

    if (classInactive == null) {
        classInactive = "";
    }

    // oznaceni aktivni zalozky
    if (document.getElementById(activeFlap) != null) {
        document.getElementById(activeFlap).className = classActive;
    }

    // oznaceni ostatnich zalozek jako neaktivnich
    var inactiveFlaps = inactiveFlapsS.split(";");
    for (var i = 0; i < inactiveFlaps.length; i++) {
        if (document.getElementById(inactiveFlaps[i]) != null) {
            document.getElementById(inactiveFlaps[i]).className = classInactive;
        }
    }

    // zobrazeni aktivniho objektu
    display(activeObj, true);

    // skryti neaktivnich objektu
    var inactiveObjs = inactiveObjsS.split(";");
    for (var i = 0; i < inactiveObjs.length; i++) {
        if (document.getElementById(inactiveObjs[i]) != null) {
            display(inactiveObjs[i], false);
        }
    }

    return false;
}

function runScript(source, target, url, parameter)
{
	if(document.getElementById(target) == null || document.getElementById(source) == null)
	{
		return false;
	}
	
	var sourceContent;
	sourceContent = document.getElementById(source).innerHTML;
	
	var parameterValue;
	var urlParameter;
	
	if(parameter != null)
	{
		if(document.getElementById(parameter) != null)
		{
			parameterValue = document.getElementById(parameter).options[document.getElementById(parameter).selectedIndex].value;
			urlParameter = '&' + parameter + '=' + parameterValue;
		}
	}
	
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	{ xmlhttp = new XMLHttpRequest(); } 
	else
	if (window.ActiveXObject)
	{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	xmlhttp.open('GET', url + urlParameter, true);
	
	document.getElementById(target).innerHTML = '<div style="text-align: center;"><img src="http://www.allinfo.cz/frontend/images/loader.gif" alt="loading..." /></div>';
	document.getElementById(source).innerHTML = '<div style="text-align: center;"><img src="http://www.allinfo.cz/frontend/images/loader.gif" alt="loading..." /></div>';
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			var response = xmlhttp.responseText;
			document.getElementById(target).innerHTML = response;
		}
	}
	xmlhttp.send(null);
	
	document.getElementById(source).innerHTML = sourceContent;
	
	return false;
}

function changeContentObject(target, url)
{
	if(document.getElementById(target) == null)
	{
		return false;
	}
	
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	{ xmlhttp = new XMLHttpRequest(); } 
	else
	if (window.ActiveXObject)
	{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	xmlhttp.open('GET', url, true);
	
	document.getElementById(target).innerHTML = '<div style="text-align: center;"><img src="http://www.allinfo.cz/frontend/images/loader.gif" alt="loading..." /></div>';
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			var response = xmlhttp.responseText;
			document.getElementById(target).innerHTML = response;
		}
	}
	xmlhttp.send(null);
	
	return false;
}

function findEmail(url, activeObj, email)
{
	if(document.getElementById(activeObj) == null)
	{
		return false;
	}
		
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	{ xmlhttp = new XMLHttpRequest(); } 
	else
	if (window.ActiveXObject)
	{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	xmlhttp.open('GET', url + '?ajax_content=true&email=' + email, true);
	
	document.getElementById(activeObj).innerHTML = '<img src="http://www.allinfo.cz/frontend/images/loader.gif" alt="loading..." />';
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			var response = xmlhttp.responseText;
			document.getElementById(activeObj).innerHTML = response;
		}
	}
	xmlhttp.send(null);
			
	return false;
}

function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }

	 return true;					
}

function checkForm(email, classError)
{
	var emailID = document.getElementById(email);
	
	if ((emailID.value==null)||(emailID.value==""))
	{
		emailID.className = classError;
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.className = classError;
		emailID.focus();
		return false;
	}
	return true;
}

function selectCheckBox(activeObj, formObj)
{
	if(document.getElementById(activeObj) == null)
	{
		return false;
	}
	
	if(document.getElementById(activeObj).checked == false)
	{
		document.getElementById(activeObj).checked = true;
	}
	else
	{
		document.getElementById(activeObj).checked = false;
	}
	
	document.getElementById(formObj).submit();
			
	return false;
}

function findReg(url, activeObj, email, template)
{
	if(document.getElementById(activeObj) == null)
	{
		return false;
	}
		
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	{ xmlhttp = new XMLHttpRequest(); } 
	else
	if (window.ActiveXObject)
	{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	xmlhttp.open('GET', url + '?ajax_content=true&email=' + email + ((template != null) ? '&template=' + template : ''), true);
	
	document.getElementById(activeObj).innerHTML = '<div class="dataField"><h2>Ověřuji emailovou adresu</h2><div style="text-align: center;"><img src="http://www.allinfo.cz/frontend/images/loader.gif" alt="loading..." /></div></div>';
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			var response = xmlhttp.responseText;
			document.getElementById(activeObj).innerHTML = response;
		}
	}
	xmlhttp.send(null);
			
	return false;
}
