function $(e)
{
	return document.getElementById(e);
}

function WeatherChange(city)
{
	var data = weather_data[city];
	$('weather-today-tmp').innerHTML='<span class="temp-low">'+data['day1']['low']+'&deg;C</span>/<span class="temp-hi">'+data['day1']['hi']+'&deg;C</span>';
	$('weather-today-icon').src='/img/weather/32x32/'+data['day1']['icon']+'.gif';
	
	$('weather-tomorow-tmp').innerHTML='<span class="temp-low">'+data['day2']['low']+'&deg;C</span>/<span class="temp-hi">'+data['day2']['hi']+'&deg;C</span>';
	$('weather-tomorow-icon').src='/img/weather/32x32/'+data['day2']['icon']+'.gif';
}


function evalScrips(response)
{
	var re = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)','img');
	var match;
	while (match = re.exec(response))
	{
		console.log('match : '+match[1]);
		eval(match[1]);
	}
}

function Collection(div_id, images)
{
    this.block_id        = div_id.split('-')[0];
    this.block_div_id    = div_id;
    this.el_image        = document.getElementById('image-collection-' + this.block_div_id);
    this.el_description  = document.getElementById('description-' + this.block_div_id);
    this.el_counter      = document.getElementById('collection-counter-' + this.block_div_id);
    this.images          = images;
    this.current_index   =  0;

    this.getNextImage = function()
    {
        var temp = new Image();
        var img = new Image();

        if(arguments.length)
        {
            switch (arguments[0])
            {
                case 'forward':
                    temp = this.images[this.current_index + 1] || this.images[0];
                    break;

                case 'back':
                    temp = this.images[this.current_index - 1] || this.images[this.images.length - 1];
                    break;
            }
        }
        else
        {
            temp = this.images[current_index + 1] || this.images[current_index];
        }

        img.src = temp.src;
        img.width = temp.width;
        img.height = temp.height;
        img.description = temp.description;
        img.key_index = temp.key_index;

        return img;
    };

    this.next_image      = this.getNextImage('forward');
    this.previous_image  = this.getNextImage('back');

    this.show = function(direction)
    {
        switch(direction)
        {
            case 'next':
                this.el_image.src             = this.next_image.src;
                this.el_image.width           = this.next_image.width;
                this.el_image.height          = this.next_image.height;
                this.current_index            = this.next_image.key_index;
                this.el_description.innerHTML = this.next_image.description;
                this.el_counter.innerHTML = this.current_index + 1 + '/' + this.images.length;
                break;

            case 'previous':
                this.el_image.src             = this.previous_image.src;
                this.el_image.width           = this.previous_image.width;
                this.el_image.height          = this.previous_image.height;
                this.current_index            = this.previous_image.key_index;
                this.el_description.innerHTML = this.previous_image.description;
                this.el_counter.innerHTML = this.current_index + 1 + '/' + this.images.length;
                break;
        }

        this.next_image     = this.getNextImage('forward');
        this.previous_image = this.getNextImage('back');

        return false;
    };

    this.onclick = function()
    {
		var w = 500;
		var h = 500;
		var topPos = (screen.height - h) / 2;
		var leftPos = (screen.width - w) / 2;

		newwindow=window.open(this.images[this.current_index].href,'name','left=' + leftPos + ',top=' + topPos + ',height=' + h + ',width=' + w + ',scrollbars=yes,resizable=yes');
		if (window.focus) {newwindow.focus()}
    	return false;
    }

}


function toggle(element)
{
	if (element.style.display == 'block')
	{
		element.style.display = 'none';
	}
	else{
		element.style.display = 'block';
	}
}

function change_image_src(image_id,src, hash, title)
{
	$(image_id).src=src;
	$(image_id).title=title;
	if ($('JS_image_text'))
	{
	 $('JS_image_text').innerHTML=title;
	}
	window.location.hash = hash;
}

//Tabs
var panes = new Array();

function setupPanes(containerId, defaultTabId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible
  
    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;    
}

//End tabs


function Ajax(method,onComplete)
{
	this.requestobj = null;
	this.queryStringSeparator = "?";
	this.argumentSeparator = "&";
	this.method = method;
	this.URLString = '';
	this.failed = false;
	
	if (window.XMLHttpRequest)
	{
          // If IE7, Mozilla, Safari, etc: Use native object
          this.requestobj = new XMLHttpRequest()
	}
	else
	{
		if (window.ActiveXObject)
		{
          // ...otherwise, use the ActiveX control for IE5.x and IE6
          this.requestobj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
        	this.failed = true;
        }
	
	}
	
	
	if (this.failed)
	{
		alert('Failed to create AJAX object');
	}
	
	this.request = function(url,params)
	{
		
		this.urlString= url + this.queryStringSeparator + params;
		if (this.method == "GET") {
			totalurlstring = url + this.queryStringSeparator + params;
			this.requestobj.open(this.method, totalurlstring, true);
			
		} else {
			this.requestobj.open(this.method, url, true);
			try {
				this.requestobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
			} catch (e) { }
			this.URLString=params;
		}
		this.requestobj.onreadystatechange = onComplete;
		
		this.requestobj.send(this.URLString);
	}
	
	
}

function get_districts(city_id,district,selectID,lang)
{
	var ajax = new Ajax('GET',onComplete=function()
		{
			switch(ajax.requestobj.readyState)
			{
				case 4:
					xml = ajax.requestobj.responseXML;
					xmlroot = ajax.requestobj.responseXML.documentElement;
					var district_count = xmlroot.getElementsByTagName('district').length-1;
					var select = document.getElementById(selectID);
					select.options.length=0;
					
					for (i=0;i<=district_count;i++)
					{
						var op_txt = xmlroot.getElementsByTagName('district')[i].firstChild.data;
						var op_val = xmlroot.getElementsByTagName('district')[i].getAttribute('value');
						var op = document.createElement('option');
						if (district == op_val)
						{
							op.setAttribute('selected',true);
						}
						//console.log(op_val+':'+xmlroot.getElementsByTagName('district')[i].firstChild.data);
						op.setAttribute('value',op_val);
						var txt = document.createTextNode(op_txt);
						op.appendChild(txt);
						select.appendChild(op);
						select.disabled=false;
					}
				break;
			}
		}
	);
	ajax.request('/ajax_server.php','action=get_districts&city_id='+city_id+'&district='+district+'&lang='+lang);
}

function hideNotStandardBanner(divHide, divShow)
{
	document.getElementById(divHide).style.display="none";
	document.getElementById(divShow).style.display="block";
}

function hideBanner()
{
  var banner = document.getElementById('code69');
  banner.innerHTML='\
  <div id="GF1"><embed src="http://images.ibox.bg/2008/10/14/201.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="728" height="90" name="z1" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>\
  ';
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	    return (isIE) ? window[movieName] : document[movieName];
  }

function collectVars(movie, title) {
   getFlashMovie("movie").sendVarsToFlash(movie, title);
   $('JS-title').innerHTML = title;
}

/*VW flash code begin*/

function PlayFlashMovie()
{
  document.getElementById("floating_part").Play();
}
function StopFlashMovie()
{
  document.getElementById("floating_part").Stop();
}
 
function magRemoveFlash(objectName) {
    var object = document.getElementById(objectName) || false;
    if(object) object.parentNode.removeChild(object);
}

function closeFlash(){
  document.getElementById("bigflash").style.display="none";
  StopFlashMovie();
}
function openFlash(){
  document.getElementById("bigflash").style.display="block";
  PlayFlashMovie();
}
	
/*End VW flash code*/

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
	return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
	if (document.embeds && document.embeds[movieName])
	  return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
	return document.getElementById(movieName);
  }
}
function swapBanner(movie){
	  var _elem = 'NiveaBanner';
		switch(movie)
		{
			case 1:
				var divHide = _elem + (movie + 1);
				var divShow = _elem + movie;
			break;
			case 2:
				var divHide = _elem + (movie -1) ;
				var divShow = _elem + movie;
			break;
		}

	  document.getElementById(divHide).style.display="none";
	  document.getElementById(divShow).style.display="block";

		var flashMovie=getFlashMovieObject("Movie"+movie);
		if (typeof(flashMovie) != 'function')
			flashMovie.Play();
	}