var menu_id = "menu"; // Id of flash menu located in header.tpl


// Gets and returns page and query string from url
function GetPage()
{
	var fullURI = document.URL;
	var symbolIndex = fullURI.indexOf('#');
	var qMarkIndex = fullURI.indexOf(unescape('?'));
	
	var page;
	var queryString = '';
	if(symbolIndex > -1)
	{
		if(qMarkIndex > symbolIndex)
		{
			page = fullURI.substring(symbolIndex + 1, qMarkIndex - 1);
			queryString = fullURI.substring(qMarkIndex);
		}
		else
		{
			page = fullURI.substring(symbolIndex + 1);
		}
	}
	else
	{
		page = 'news'; // Default page
	}
	
	return [page, queryString];
}

// Navigates to specified page
function NavigateTo(page, newWindow)
{
	if(newWindow == 0 && page)
	{
		window.location = page+".php";
	}
	else if(newWindow == 1)
	{
		if(page == "lk")
		{
			window.open("http://www.latvijaskoncerti.lv");
		}
		else if(page == "tickets")
		{
			window.open("http://www.bilesuparadize.lv/organizers/68");
		}
	}
}

// Opens a page without refresh
function LoadContent(page, queryString, targetElemId)
{
	httpObject = getHTTPObject();
    if (httpObject != null)
	{
		var targetElem = document.getElementById(targetElemId);
		if(targetElem)
		{
        	httpObject.open("GET", page+".php"+queryString, false);
	        httpObject.send(null);
	        httpObject.onreadystatechange = fillHtml(targetElem);
		}
    }
}
function fillHtml(targetElem)
{
	if(httpObject.readyState == 4)
	{
		targetElem.innerHTML = httpObject.responseText;
	}
}
function getHTTPObject()
{
	if (window.ActiveXObject)
   	{	
   		return new ActiveXObject("Microsoft.XMLHTTP");
	}
   	else if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
   	else
	{
		alert("Your browser does not support AJAX.");
      	return null;
   	}
}

// Function removes all query string parameters, if any, and returns parsed URI
function RemoveQueryString()
{	
	var escapedURI = escape(document.URL);
	var newURI = document.URL;
	var qMark = escape('?');
	if(escapedURI.match(qMark))
	{				
		var qMarkIndex = escapedURI.indexOf(qMark);
		var uriLength = escapedURI.length;
		var strToRemove = escapedURI.substring(qMarkIndex, uriLength);
		newURI = unescape(escapedURI.replace(strToRemove, ''));
	}
	
	return newURI;
}

// Returns an array of specified class (optional params - tagName, container, exact_match)
function GetElementsByClassName(className, tagName, container, exact_match)
{
	if (container == null)
	{
		var allElements = document.getElementsByTagName(tagName);
	}
	else
	{
		var allElements = container.getElementsByTagName(tagName);
	}
	var reqElements = new Array();
	
	if (allElements != null)
	{
		if(allElements.length > 0)
		{
			var j = 0;
			for(var i = 0; i < allElements.length; i++)
			{
				if((exact_match && allElements[i].className == className) || 
				   (!exact_match && allElements[i].className.match(className)))
				{
					reqElements[j] = allElements[i];
					j++;
				}
			}
			
			if (reqElements != null)
			{
				if(reqElements.length > 0)
				{
					return reqElements;
				}
				else
				{
					return null;
				}
			}
		}
	}
	else
	{
		return null;
	}
}



function ShowProgramme(idToShow, idsToHide, classToHide)
{
	var elemToShow = document.getElementById(idToShow);
	var idsToHide = idsToHide.split('?');
	
	var elemsToHide = new Array();
	for(var i = 0; i < idsToHide.length; i++)
	{
		var elemToHide = document.getElementById(idsToHide[i]);
		if(elemToHide)
		{
			elemsToHide.push(elemToHide);
		}
	}
	
	var classElemsToHide = GetElementsByClassName('subcategory_img', 'img', null, true);	
	
	if(elemToShow)
	{
		elemToShow.style.display = "block";
	}	
	for(var i = 0; i < elemsToHide.length; i++)
	{
		elemsToHide[i].style.display = "none";
	}
	if(classElemsToHide != null)
	{
		for(var i = 0; i < classElemsToHide.length; i++)
		{
			classElemsToHide[i].style.display = "none";
		}
	}
}


function ReadMore(idToRemove, textIdToShow)
{
	var toRemove = document.getElementById(idToRemove);
	var textToShow = document.getElementById(textIdToShow);

	toRemove.parentNode.removeChild(toRemove);
	textToShow.style.display = 'block';
}
