function select_jump (targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function menu_show()
{
  for (i=0; i<200; i=i+1)
  {
    	  
    if (getCookie('menu'+i))
      document.getElementById('menu'+i).style.display='block';
  }
}

function who_are_you() {
	
	
	var message = '<div id="who_are_you" style="display:none; position:absolute; z-index:2; height:161px; width:235px; background:url(\'http://www.aurore.ru/images/main/who_are_you.png\'); left:-300px; top:100px; color:red;"><div style="font-size:14px; margin:65px 6px 0 0; text-align:center;">Вы менеджер турагентства?</div><div style="font-size:22px; margin:2px 6px 0 0; text-align:center;">Тогда Вам сюда!</div></div>';
	var time = 0;
	
	if (!getCookie('who_are_you')) {
	
		$("#links").append(message);
		
		var timer = window.setInterval(function() {
	
				if (time == 1) { 
					$("#who_are_you").fadeIn();
				}
				else if(time == 15) {
					$("#who_are_you").fadeOut();
					window.clearInterval(timer);
					
					var now = new Date();
    				fixDate(now);
					now.setTime(now.getTime() + 6 * 24 * 60 * 60 * 1000);
    				setCookie('who_are_you', '1', now);
					
				}
				time++;			
			}, 500);
	}
}

function people_count()
{
  selected_item = document.getElementById('count').selectedIndex;
  n = document.getElementById('count').options[selected_item].value;

  for (i=1; i<=9; i=i+1)
  {
    if(i<=n)
      document.getElementById('people'+i).style.display='block';
    else
      document.getElementById('people'+i).style.display='none';
  }
}


function menu(n){
  if (document.getElementById('menu'+n).style.display=='none')
  {
    document.getElementById('menu'+n).style.display='block';
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('menu'+n, "set", now);
    document.getElementById('div'+n).style.backgroundImage='url(images/main/menu_up.gif)';
  }
  else
  {
    document.getElementById('menu'+n).style.display='none';
    deleteCookie('menu'+n);
    document.getElementById('div'+n).style.backgroundImage='url(images/main/menu_down.gif)';
  }
}

function menu_over(n){
  document.getElementById('div'+n).style.backgroundColor='#deeff7';
}

function menu_out(n){
  document.getElementById('div'+n).style.backgroundColor='#f8fdff';
}

function windows_open(url, winname)
{
  windop = window.open(url, winname, "height=120, width=300");
}

function windows_close() 
{
  windop.close();
}

function win_open(url, winname, width, height)
{
  popup = window.open(url, winname, "width="+width+", height="+height+", toolbar=0, location=0, directories=0, menubar=0, scrollbars=0, status=0");
  popup.focus();
}
function win_close() {
  popup.close();
}

function print_it() { 
  window.print(); 
  return false;
}

function show_open(element) {
  $(element).parent().next().toggle();
  return false;
}

function show_cities(country_id) {
  $('#a_tours > div:visible').hide();
  $('#a_cities > div:visible').hide();
  $('#a_cities'+country_id).toggle();
  $('.a_tc'+country_id).toggle();
   return false;
}

function show_tours(country_id) {
  $('#a_tours > div:visible').hide();
  $('#a_tours'+country_id).toggle();
  return false;
}

function counter (name) {
  if (name == 'Google') {
    document.write('<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-7009227-3"); pageTracker._trackPageview(); } catch(err) {}</script>');
  }
}

function parse_url (str, component) {
    // Parse a URL and return its components  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/parse_url
    // +      original by: Steven Levithan (http://blog.stevenlevithan.com)
    // + reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: blog post at http://blog.stevenlevithan.com/archives/parseuri
    // %          note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: Does not replace invaild characters with '_' as in PHP, nor does it return false with
    // %          note: a seriously malformed URL.
    // %          note: Besides function name, is the same as parseUri besides the commented out portion
    // %          note: and the additional section following, as well as our allowing an extra slash after
    // %          note: the scheme/protocol (to allow file:/// as in PHP)
    // *     example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
    // *     returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
    var  o   = {
        strictMode: false,
        key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
        q:   {
            name:   "queryKey",
            parser: /(?:^|&)([^&=]*)=?([^&]*)/g
        },
        parser: {
            strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-protocol to catch file:/// (should restrict this)
        }
    };
    
    var m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    uri = {},
    i   = 14;
    while (i--) {uri[o.key[i]] = m[i] || "";}
    // Uncomment the following to use the original more detailed (non-PHP) script
    /*
        uri[o.q.name] = {};
        uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
        });
        return uri;
    */
 
    switch (component) {
        case 'PHP_URL_SCHEME':
            return uri.protocol;
        case 'PHP_URL_HOST':
            return uri.host;
        case 'PHP_URL_PORT':
            return uri.port;
        case 'PHP_URL_USER':
            return uri.user;
        case 'PHP_URL_PASS':
            return uri.password;
        case 'PHP_URL_PATH':
            return uri.path;
        case 'PHP_URL_QUERY':
            return uri.query;
        case 'PHP_URL_FRAGMENT':
            return uri.anchor;
        default:
            var retArr = {};
            if (uri.protocol !== '') {retArr.scheme=uri.protocol;}
            if (uri.host !== '') {retArr.host=uri.host;}
            if (uri.port !== '') {retArr.port=uri.port;}
            if (uri.user !== '') {retArr.user=uri.user;}
            if (uri.password !== '') {retArr.pass=uri.password;}
            if (uri.path !== '') {retArr.path=uri.path;}
            if (uri.query !== '') {retArr.query=uri.query;}
            if (uri.anchor !== '') {retArr.fragment=uri.anchor;}
            return retArr;
    }
}

function substr_count( haystack, needle, offset, length ) {
	var pos = 0, cnt = 0;

	if(isNaN(offset)) offset = 0;
	if(isNaN(length)) length = 0;
	offset--;

	while( (offset = haystack.indexOf(needle, offset+1)) != -1 ){
		if(length > 0 && (offset+needle.length) > length){
			return false;
		} else{
			cnt++;
		}
	}
	return cnt;
}

function add_favorite(a) { 
	title=document.title; 
	url=document.location; 
	try { 
		// Internet Explorer 
		window.external.AddFavorite('http://www.avrora-intour.ru/#favorite', 'Туроператор Аврора Интур (Москва, Сочи, Санкт-Петербург)'); 
	} 
	catch (e) { 
		try { 
			// Mozilla 
			window.sidebar.addPanel('Туроператор Аврора Интур (Москва, Сочи, Санкт-Петербург)', 'http://www.avrora-intour.ru/#favorite', ""); 
		} 
		catch (e) { 
			// Opera 
			if (typeof(opera)=="object") { 
				a.rel="sidebar"; 
				a.title='Туроператор Аврора Интур (Москва, Сочи, Санкт-Петербург)'; 
				a.url='http://www.avrora-intour.ru/#favorite'; 
				return true; 
			} 
			else { 
				// Unknown 
				alert('Нажмите Ctrl-D чтобы добавить страницу в закладки'); 
			} 
		} 
	} 
	return false; 
}

