/* window.onload=menu; */
function menu(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('region'+i)) {document.getElementById('region'+i).style.display='none';document.getElementById('reg'+i).className='region';}
	}
	if (d) {d.style.display='block';d.previousSibling.className='region selected';} else {document.getElementById('region1').style.display='block';document.getElementById('region1').previousSibling.className='region selected';}
}

function scrollToCountry(regionId,countryId,countryPos) {
	var countryHeight = document.getElementById(countryId).clientHeight;
	var regionHeight = document.getElementById(regionId).clientHeight;
	/* var scrollPos = (countryHeight/2) * countryPos ; */
	var scrollPos = countryPos * 26;
	document.getElementById(regionId).scrollTop = scrollPos;

}

function openPeriods(block,img) {
	var el = document.getElementById(block);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		img.src='/i/bg/plus.gif';
	}
	else {
		el.style.display = 'block';
		img.src='/i/bg/minus.gif';
	}
}

function SignIn() {
	document.getElementById('sign_in').style.display='block';
}

function SignInOff() {
	document.getElementById('sign_in').style.display='none';
}


function sendBugIn() {
	var sendbug=document.getElementById('sendbug');
	/* sendbug.style.top = (screen.height-600)/2 + 'px';
	sendbug.style.left = (screen.width-400)/2 + 'px'; */
	if (sendbug.style.display!='block')
	{
		sendbug.style.display='block';
		/* $('sendbug').makeDraggable({'handle':$('sendbug')}); */
		this.scrollTo(0,0);
		/* this.scrollTo(0, 200).chain(function(){
			    this.scrollTo(200, 0);
		}); */
	}
	
}

function sendBugOff() {
	document.getElementById('sendbug').style.display='none';
}

function ajaxsubmit(uri, place) {
	var getstr = "?";
	var obj = (_('#'+place+' select'));
	alert(obj);
	/* getstr += obj.name + "=" + obj.options[obj.selectedIndex].value + "&"; alert(uri+getstr); */
	/* for (var i=0; i<obj.length); i++) {
		alert('112');
		/* getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&"; 
	} */
	/* alert(_('#'+place+' select').name); */
	ajaxRequest('findcoin?country=1', getstr, place);
	 
	document.getElementById(place).innerHTML='<img src="/i/bg/ajax.gif" class="ai" />';
}
function ajaxRequest(url, parameters, place) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/xml');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
	http_request.onreadystatechange = showAjaxResponse;
	/* alert(parameters); */
	http_request.open('GET', url + parameters, true);
	http_request.send(null);
}
function showAjaxResponse(where) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseText;
			/* alert(xmldoc); */
			document.getElementById('ajaxHereBaby').innerHTML = xmldoc;	
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function zoom (path, w, h, scroll)
{ 
//path='/i/'+path;
scrollbars = 0;
screenW = screen.width;
screenH = screen.height;
leftPos = (screenW - w)/2;
topPos = (screenH - h)/2;
if (w > 770 || h > 650) scrollbars = 1;
var params = "width=" + (w > 770 ? 770 : w) + ", height=" + (h > 650 ? 650 : h) + ", top="+topPos+", left="+leftPos+",menubar=no,location=no,resizable=no,scrollbars="+scroll+",statusbar=no,toolbar=no";
win=open(path, "New", params);
win.focus();
}

(function(){
/*
* YASS 0.1.3 - The fastest CSS1 selectors JavaScript library
*
* Copyright (c) 2008 Nikolay Matsievsky aka sunnybear (webo.in, webo.name)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008-12-05 03:25:02 +3000 (Fri, 5 Dec 2008) $
* $Rev: 31 $
*/
var _ = function () {
    var selector = arguments[0];
/* return cache if exists */
    if (_.cache[selector] && !arguments[1]) {
        return _.cache[selector];
    } else {
	if (!selector) {
		return undefined;
	}
	var doc = document;
/* apply querySelector if exists */
        if (doc['querySelectorAll']) {
            _.sets = doc['querySelectorAll'](selector);
        } else {
            switch (selector) {
/* return some simple and fast cases */
                case 'a':
                    _.sets = doc.links ? doc.links : doc['getElementsByTagName']('a');
                    break;
                case 'body':
                    _.sets = doc.body;
                    break;
                case 'form':
                    _.sets = doc.forms ? doc.forms : doc['getElementsByTagName']('form');
                    break;
                case 'head':
                    _.sets = doc['getElementsByTagName']('head')[0];
                    break;
                case 'img':
                    _.sets = doc.images ? doc.images : doc['getElementsByTagName']('img');
                    break;
                case 'title':
                    _.sets = doc.title;
                    break;
/* generic case */
                default:
/* split selectors by comma -- to from initial groups of elements */
                    var groups = selector.split(/, */),
                        groups_length = groups.length - 1,
                        j = -1;
                    while (j++ < groups_length) {
/* split selectors by space -- to form groups tag-id-class */
                        var singles = groups[j].split(/ +/),
                            singles_length = singles.length - 1,
                            i = -1,
                            level = 0;
/* clean nodes with DOM root */
                        _.nodes = doc;
                        while (i++ < singles_length) {
/* inspired with John's Resig fast replace implementation,
more details:
http://ejohn.org/blog/search-and-dont-replace/
http://webo.in/articles/habrahabr/40-search-not-replace/
*/
                            singles[i].replace(/([^\.#]+)?(?:#([^\.#]+))?(?:\.([^\.#]+))?/, function(a, tag, id, klass) {
/* fast check for ID */
                                if (tag == '' && klass == '' && !level) {
                                    _.nodes = doc[/*@cc_on !@*/0 ? 'all' : 'getElementById'](id);
                                } else {
/* fast check for TAG */
                                    if (klass == '' && id == '' && !level) {
                                        _.nodes = doc['getElementsByTagName'](tag);
/* generic selector to get element by TAG, CLASS, ID */
                                    } else {
/* array to merge results */
                                        var newNodes = {},
/* length of root nodes */
                                            nodes_length = _.nodes.length,
                                            J = -1,
/* iterator of return array, equals to its length */
                                            idx = 0;
/* if root is single -- just make it as an array */
                                        if (!nodes_length) {
                                            _.nodes = [_.nodes[0]?_.nodes[0]:_.nodes];
                                            nodes_length = 1;
                                        }
                                        while (J++ < nodes_length) {
                                            var node = _.nodes[J];
                                            if (node) {
/* find all TAGs */
                                                var childs = node['getElementsByTagName'](tag ? tag : '*'),
                                                    childs_length = childs.length - 1,
                                                    h = -1;
                                                while (h++ < childs_length) {
                                                    var child = childs[h];
/* check them for ID or CLASS */
                                                    if ((!id || (id && child.id == id)) && (!klass || (klass && child.className.match(klass)))) {
/* add to result array */
                                                        newNodes[idx++] = child;
                                                    }
                                                }
                                            }
                                        }
/* put selected nodes in local nodes' set */
                                        _.nodes = newNodes;
					_.nodes.length = idx - 1;
                                    }
                                }
/* dirty iterator to prevent choosing document for deep elements */
                                level++;
                            });
/* remember selected nodes to global set to start new selection */
                            if (groups_length) {
                                var nodes_length = _.nodes.length - 1,
                                    K = -1,
                                    idx = _.sets ? _.sets.length : 0;
				_.sets = _.sets ? _.sets : {};
                                while (K++ < nodes_length) {
                                    _.sets[idx++] = _.nodes[K];
                                }
                                _.sets.length = idx;
/* or just copy nodes to this set */
                            }
                        }
                    }
		    _.sets = _.sets ? _.sets : _.nodes;
                    break;
            }
        }
/* save result in cache */
        _.cache[selector] = _.sets.length>1||_.sets.nodeName ? _.sets : _.sets[0];
/* clear all properties to prevent memory leaks */
	_.sets = _.nodes = null;
/* return saved result */
        return _.cache[selector];
    }
};
/* current set of nodes, to handle single selectors */
_.nodes = null;
/* current sets of nodes, to handle comma-separated selectors */
_.sets = null;
/* cache for selected nodes */
_.cache = {};
/* initialization as a global var */
window._ = _;
})();
