/* Окно операторов on-line */
function showOnlinePopup(url, evt) {
	onlineWindow.setCoord(evt.clientX, evt.clientY).open(['left', 'bottom']);
}
/* Конец: окно операторов */


function change_value(elem,oper) {
	var element = document.forms[form_name].elements[elem];
	if (oper == 'inc') {
		element.value++;			
	} 
	else  {
		if (element.value > 0) element.value--;
		if (element.value == 0) element.value="";			
	}
} 

function room_children() {														
			
	var ch1 = document.getElementById('sel_ch1');
	var ch2 = document.getElementById('sel_ch2');
	var chall = document.getElementById('ch_block');
									
	switch (rs[document.forms[form_name].rs.value]) {
		case 2: 
			ch1.disabled=false; 
			ch2.disabled=false; 
			chall.style.display = 'block';
		break;
		case 1: 
			ch1.disabled=false; 
			ch2.disabled=true; 
			ch2.selectedIndex = 0;
			chall.style.display = 'block';
		break;    
		default:
			ch1.disabled=true; 
			ch2.disabled=true; 
			ch1.selectedIndex = 0;
			ch2.selectedIndex = 0;
			chall.style.display = 'none';
		break;        
	}
}
		

function ShowWin(url,x,y,name,isscrollbars) {
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
    
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}


function ShowWin_ti_order(url,x,y,name,isscrollbars) {
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
    
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function ShowPropWin(url,prx,pry,name,isscrollbars) {
	var x,y;
	y=screen.availHeight
	if(!y) y=screen.height
	x=screen.availWidth
	if(!x) x=screen.width
	
	x = parseInt(prx*x/100);
	y = parseInt(pry*y/100);
	
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
	isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function rc(obj, color) {
	if (color==1) 
	  obj.style.backgroundColor="#FAFAFA";
	else
	  obj.style.backgroundColor="#fff";
}

function ti_op(obj) {
	ShowWin_ti_order(obj.href,450,400,"","yes"); 
	return false;
}

function ti_bp(obj) {
	ShowWin_ti_order(obj.href,1000,600,"","yes"); 
	return false;	
}

function ti_bk(obj) {
	ShowWin_ti_order(obj.href,1024,768,"","yes");
	return false;	
}

function ti_of(obj) {
	ShowWin_ti_order(obj.href,780,580,"","yes"); 
	return false;	
}

function ti_ms(obj) {
	ShowWin(obj.href,450,470,"","yes"); 
	return false;	
}

function ti_am(obj) {
	cx=screen.width / 2 - (450 / 2);
	cy=(screen.height/2-(470/2));
	window.open('about:blank','report','"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width=450,height=470,scrollbars=yes,top='+cy+',left='+cx+'"');
	//ShowWin(obj.action, 450, 470, "", "yes");
}

function make_bookmark() {				
  var form = document.forms[form_name];
  	
  var qs = '';
  
  prepare_submit(true);
  	  
  var inputs = form.getElementsByTagName('input');;
  
  for(var i = 0; i < inputs.length; i++){
    if (inputs[i].type=='hidden') {
		if(qs.length) qs += '&';
    	qs += inputs[i].name+'='+inputs[i].value;
	}
  }
	
  var names = new Array('df','dt','nf','nt','rs','ch1','ch2','ti','pf','pt','st','ld');
  
  for (key in names) {
  	var elem = form[names[key]];
	if (typeof(elem) != 'undefined' && elem != null) {
		if(qs.length) qs += '&';	 
  		qs += elem.name+'='+elem.value;
	}
  }
  
  
  ShowWin("/window/bookmark/?"+qs,300,200,"","yes"); 
}


function make_bookmark_new(filterSet) {					    
	ShowWin(filterSet.getDataQuery("/window/bookmark/?"),300,200,"","yes"); 
}


function ti_first_change_city(){
	var sel = document.getElementById('ct_sel');
	window.location = './?ct='+sel.value;
}

function Selecter(Form, EName, S) {
    var f=Form;
    for ( i=0; i<f.length; i++ ) {
        if (f.elements[i].name==EName) {
            f.elements[i].checked=(S==1)?true:false;
        }
   }        
}



function SelectDir(Form, EName) {
var f=Form;
var A=new Array(66,67,12,32,43,102,1,30,75,84,87,3);
Selecter(document.lForm,"countrys[]",0);
for (i=0; i<f.length; i++) {
if (f.elements[i].name==EName) {
for (j=0; j<A.length; j++) { 
if (f.elements[i].value==A[j]) { f.elements[i].checked=true; }
}
}
} 
}

function loginFocus() {
	log = document.getElementById('login');
	setTimeout("log.focus()", 200);//FF does not wish to understand normally method focus ()
}

// лого-банеры сетей отелей и операторов на главной

var curAlNw = 0;
var curOp = 0;

function loadBestPrices(op,descr) {
	$(".bfa_list_links a").removeClass("active");
	$(".bpExcHref a").attr({ "href":"javascript:void(0);", "target":"" });

	if (typeof(descr)!='undefined') {
		jQuery.get("/bp/op_descr?op=" + op, function(data) {
			$("#main_op_descr").html(data);
			$("#main_op_descr").show(1);
			jQuery.get("/bp/main?op=" + op + "&rnd=" + Math.random(), function(data) {
				$("#main_best_price").html(data);
				$("#main_best_price").show(500, function(){ 
					if ($("#bpCo").attr("value")) {
						$("#hrefBpCo" + $("#bpCo").attr("value")).addClass("active");
						$(".bpExcHref a").each(function(){
							if(typeof(this.attributes['firsthref']) !== 'undefined') {
								this.attributes['href'].value = this.attributes['firsthref'].value + $("#bpCo").attr("value");
								this.target = "_blank";
							}
						});
					}
				});
				$("div[name='mainStat']").each(function() { //статистика показа
					s(this.attributes["user"].value,{ op:this.attributes["op"].value,co:this.attributes["co"].value,ct:this.attributes["ct"].value });
				});
			});
		});
	} else {
		jQuery.get("/bp/main?op=" + op + "&rnd=" + Math.random(), function(data) {
			$("#main_best_price").html(data);
			$("#main_best_price").show(500, function(){ 
				if ($("#bpCo").attr("value")) {
					$("#hrefBpCo" + $("#bpCo").attr("value")).addClass("active");
					$(".bpExcHref a").each(function(){
						if(typeof(this.attributes['firsthref']) !== 'undefined') {
							this.attributes['href'].value = this.attributes['firsthref'].value + $("#bpCo").attr("value");
							this.target = "_blank";
						}
					});
				}
			});
		});
	}
}




function changeAl(al_nw) {
	$("#al_nw_"+curAlNw).attr('src', $("#al_nw_"+curAlNw).attr('src_gr'));
	$("#al_nw_"+al_nw).attr('src', $("#al_nw_"+al_nw).attr('src_act'));
	$("#info"+curAlNw).css('display','none');
	$("#info"+al_nw).css('display','');
	curAlNw = al_nw;
}

function loadAl(img) {
    $.getJSON('/getdata?f=al_nw_logo&al_nw=' + $(img).attr("ind"),
        function(data) {
       		$('#al_links').html('&nbsp;');
        	$.each(data, function(i, item) {
        		$('#al_links').append('<a href="' + item.url + '" target="_blank">' + item.name + '</a><img src="/i/arrow_down3.gif" alt="" width="5" height="3" hspace="3" class="vam">');
        	});
        	$(".hotels-line").css("background", $(img).attr("color_bg"));
			$(".hotels-line").css("border-top-color", $(img).attr("color_f"));
			$(".hotels-line a").css("color", $(img).attr("color_f"));
			$(".hotels-line a").css("border-bottom-color", $(img).attr("color_f"));
        	//$("#al_links").fadeIn("slow");
        }
    );
	$('#al_links').html('&nbsp;');
}


function changeOp(op) {
	$("#op_"+curOp).attr('src', $("#op_"+curOp).attr('src_gr'));
	$("#op_"+op).attr('src', $("#op_"+op).attr('src_act'));
	
	if (curOp!=op) {
		curOp = op;
		$("#main_op_descr").hide(1);
		$("#main_best_price").hide(500, function() {
			loadBestPrices(op,true);
		});
	} else {
		$("#main_best_price").hide(500, function() {
			loadBestPrices(op);
		});
	}
}


function loadOp(img) {
    $.getJSON('/getdata?f=op_logo&op=' + $(img).attr("ind") + '&ct=' + $(img).attr("ct"),
        function(data) {
       		$('#rs_links').html('&nbsp;');
        	$.each(data, function(i, item) {
        		$('#rs_links').append('<a href="' + item.url + '" target="_blank">' + item.name + '</a><img src="/i/arrow_down4.gif" alt="" width="5" height="3" hspace="3" class="vam">');
        	});
        	$(".oper-line").css("background", $(img).attr("color_bg"));
			$(".oper-line").css("border-top-color", $(img).attr("color_f"));
			$(".oper-line a").css("color", $(img).attr("color_f"));
			$(".oper-line a").css("border-bottom-color", $(img).attr("color_f"));
        	//$("#rs_links").fadeIn("slow");
        }
    );
	$('#rs_links').html('&nbsp;');
}

function randLogo(className) {
	count = $(className).length;
	if(!count) return 0;
	rnd = Math.floor(count * Math.random());
	if(rnd == count) rnd--;
	return $(className).eq(rnd).attr('ind');
}
// \лого-банеры сетей отелей и операторов на главной

// voiting

function loadVoiting(number) {
	url = '/window/voting_new/';
	if(number!=undefined && number)
		url = url + '?number=' + number; 
	//alert(url);
	$.get(url, function(data) {
		$('#voiting_form').html(data);
	});
	//$('#voiting_form').html('загрузка...');
}
/*
function insertIt() {
	var _y = document.getElementById('allspo_first_voting_body');
	var _x = window.frames[0].document.body.innerHTML;
	_y.innerHTML = _x

	if($('#voting').length)
		$('#div_plus #label').html('ответить');
	if($('#results').length)
		$('#div_plus #label').html('результаты');
} 

function set_checked(val){
	var frame = window.frames[0];
	frame.set_checked(val);
}

function prepare_vote(){
	var frame = window.frames[0];
	frame.A();
	return false;
}

function ti_first_voting_show(){
	$('#allspo_first_voting_body').toggle();        		
	$('#div_plus').toggle();        		
}
*/
// \voiting



function getElementPosition(elemPtr) {
    var posX = elemPtr.offsetLeft;
    var posY = elemPtr.offsetTop;

    while (elemPtr.offsetParent != null) {
        elemPtr = elemPtr.offsetParent;
        posX += elemPtr.offsetLeft;
        posY += elemPtr.offsetTop;
    }
    this.x = posX;
    this.y = posY;
    
    return this;
}

function chElVisBellow(elId, vis) {
    var calLeer = document.getElementById(elId);
    var calPosition = new getElementPosition(calLeer);
	
	MyVisibility = (vis == true) ? "visible" : "hidden";
    
    CalTop=calPosition.y;
    CalLeft=calPosition.x;
    CalBottom=CalTop+calLeer.clientHeight;
    CalRight=CalLeft+calLeer.clientWidth;
	
    // select
    for (var i=0; i<document.getElementsByTagName("select").length; i++) {
        Cu=document.getElementsByTagName("select")[i];
		
        // eii?aeiaou oaeia iauaeoa
        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;
		
        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {
			
            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }
	
    // iframe
    for (var i=0; i<document.getElementsByTagName("iframe").length; i++) {
        Cu=document.getElementsByTagName("iframe")[i];
		
        // eii?aeiaou oaeia iauaeoa
        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;

        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {
			
            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }

    return true;
}

function showHideBlock(elId) {			
	if ($("#" + elId).css("display") == "none") {
		$("#" + elId).css("display", "block");				
		if ($.browser.msie) { chElVisBellow(elId, false); }
	} else {
		$("#" + elId).css("display", "none");
		if ($.browser.msie) { chElVisBellow(elId, true); }
	}
}

// парсит в ассоциативный массив урл 
// get = parse_get(window.location.search);
// get['key'] или get.key - обращаемся :)
function parse_get(str, array){

    pos = str.indexOf('?');
    if(pos != -1)
        str = str.substr(pos + 1, str.length);

    var glue1 = '=';
    var glue2 = '&';
 
    var array2 = str.split(glue2);
    var array3 = [];
    for(var x=0; x<array2.length; x++){
        var tmp = array2[x].split(glue1);
        array3[unescape(tmp[0])] = unescape(tmp[1]).replace(/[+]/g, ' ');
    }
 
    if(array){
        array = array3;
    } else{
        return array3;
    }
}

function showCityDiv(div_id){
    if(window.ct == undefined){
    	jQuery('#ct_1').css({ 'display' : 'none' });
    } else {
    	jQuery('#ct_' + window.ct).css({ 'display' : 'none' });
    }
    jQuery('#ct_' + div_id).css({ 'display' : 'block' });
	window.ct = div_id;
	
	switch(div_id) {
		case 1:
			jQuery('#rus').removeClass('for_click').addClass("clicked");	
			jQuery('#ukr').removeClass('clicked').addClass("for_click");	
			jQuery('#co_select').val('0');	
			break;
		case 114:
			jQuery('#rus').removeClass('clicked').addClass("for_click");	
			jQuery('#ukr').removeClass('for_click').addClass("clicked");	
			jQuery('#co_select').val('0');		
			break;
		default:
			jQuery('#rus').removeClass('clicked').addClass("for_click");	
			jQuery('#ukr').removeClass('clicked').addClass("for_click")
			break;
	}
}