var RND=parseInt(Math.random()*100000);

function show_win(width,height,s_url){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	var win=window.open(s_url,"imgswin","resizable=yes,scrollbars=yes,toolbar=no,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height+",top="+p_top+",left="+p_left);
	win.focus();
}

function show_print(width,height,s_url,idg){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	var win_name="win_"+idg;
	var win_print=window.open(s_url,win_name,"resizable=yes,scrollbars=yes,toolbar=yes,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height+",top="+p_top+",left="+p_left);
	win_print.focus();
}

function active_win(surl){
	window.opener.document.location=surl;
}

function add_bask_img(idcat,idgoods){
	document.write("<a href='javascript:show_win(500,200,\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\")'><img src='/i/basket.gif' width=19 height=16 hspace=4 border=0 alt='в корзину' align=absmiddle></a>");
}

function add_bask_text(idcat,idgoods){
	document.write("<a href='javascript:show_win(500,200,\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\")'>Добавить в корзину</a>");
}

function set_selected(p,v){
	for (i=0; i < p.options.length; i++) {
		if (p.options[i].value==v) { p.options[i].selected=true; break; }
	}
}

function set_radio(p,v){
	for (i=0; i < p.length; i++) {
		if (p[i].value==v) { p[i].checked=true; break; }
	}
}

function set_checked(p,v){
	if (p.value==v) p.checked=true; 
}

function show_parent_div(div_par){
    var IDParentElement="", NextParentElement="";
		var obj=null; 
		var obj1=null;
    if (document.getElementById(div_par)!=null)
    {
			obj1=document.getElementById(div_par);
			for(var i=0; i<10; i++) {
				obj=obj1;
				if (obj!=null) {
					if (obj.id!="" && obj.style.display!="block") {
						obj.style.display="block";
					}
				}
				else break;
				obj1=eval("obj.parentElement");
			}
		}
}

function show_div(id_cur){
	var div_set=null;
	div_set=document.getElementById(id_cur);
	if (div_set!=null) {
		if (div_set.style.display=="block") div_set.style.display="none";
		else div_set.style.display="block";
	}
}

CurCurse='1.0';
CurValuteFlag='0'; // 0 - не установлен, 1-доллары, 2-рубли.

function normalize(price)
{	var pr, str;
	pr=parseInt(Math.round(price*100));
	str = new String(pr);
	pr="";
	if (str.length>2)
		pr += str.substring(0, str.length-2);
	else
		pr += "0";
	pr += ".";
	if (str.length>2)
		pr += str.substring(str.length-2, str.length);
	else
	{	if (str.length==1)
			pr += "0";
		pr += str;
	}
	return pr;
}

function price_alt(in_price,in_usd,in_rur){
	if (in_price=='' || (in_usd=='' && in_rur=='')) return;
	var normal_price=parseFloat("0"+in_price);
	if (in_usd!='') { document.write( normalize(normal_price*CurCurse)+" руб." ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
	if (in_rur!='') { document.write( normalize(normal_price/CurCurse)+" $" ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
}

function price_alt2(in_price){
	var normal_price=parseFloat("0"+in_price);
	if (CurValuteFlag=='1') { document.write( normalize(normal_price*CurCurse)+" руб." ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
	if (CurValuteFlag=='2') { document.write( normalize(normal_price/CurCurse)+" $" ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
}

function ico_img(graph)
{
	if (graph == '/i/null.gif') document.write('<img src="/i/ico_noimg.gif" width=30 height=30 border=0 alt="Изображение отсутствует">');
	else if (graph == '/i/noimage.gif') document.write('<img src="/i/ico_noimg.gif" width=30 height=30 border=0 alt="Изображение отсутствует">');
	else document.write('<img src="/i/ico_img.gif" width=30 height=30 border=0 alt="Описание с изображением">')
}

function CreateCookie(name,value,ex_date){
	var today=new Date();
	today.setDate(today.getDate()+ex_date);
	document.cookie=name+"="+value+"; expires="+today.toGMTString()+"; path=/;";
}

function CreateTmpCookie(name,value){
	document.cookie=name+"="+value+"; path=/;";
}

function RemoveCookie(name){
	CreateCookie(name,"",-1);
}

function SetCompare(obj,id_goods){
	if (!obj.checked) RemoveCookie("idg"+id_goods); else CreateTmpCookie("idg"+id_goods,id_goods);
}

function SpellCompare(obj){
	var str="";
	var start_IDG=0;
	var end_IDG=-1;
	var break_point=0;
	var flag;
	while (start_IDG!=-1){
		start_IDG=document.cookie.indexOf("idg",start_IDG);
		end_IDG=document.cookie.indexOf("=",start_IDG);
		if (start_IDG==-1 || end_IDG==-1) break;
		idg=unescape(document.cookie.substring(start_IDG+3,end_IDG));
		start_IDG=end_IDG;
		flag=false;
		//alert("idg="+idg+" , obj.idg.length="+obj.idg.length);
		if (isNaN(obj.idg.length)) { 
			if (obj.idg.value==idg) { obj.idg.checked=true; flag=true; }
		}
		else {
			for (i=0;i<obj.idg.length;i++) {
				if (obj.idg[i].value==idg) { obj.idg[i].checked=true; flag=true; break; }
			}
		}
		//alert("flag="+flag);
		if (!flag) { 
			//alert("!!! idg="+idg);
			str+="<input type=hidden name=idg value="+idg+">"
		}
		break_point++; if (break_point>10) break;
	}
	return str;
}

function SearchScroll(FileAction,pgsize,numpage,stype,str_url){
	var s1=new RegExp("pgsize=.&|pgsize=..&|pgsize=...&", "gi");
	var s2=new RegExp("page=.&|page=..&|page=...&", "gi");
	var s3=new RegExp("stype=.&|stype=..&|stype=...&", "gi");
	str_url=str_url.replace(s1,''); str_url=str_url.replace(s2,''); str_url=str_url.replace(s3,'');
	document.location = FileAction + '?c=search&pgsize='+pgsize + '&page='+numpage +'&stype='+stype + '&'+str_url;
}

function logoff(file_templ,idc,stype,page,idr,idt,idn){
	RemoveCookie("login");
	RemoveCookie("pass");
	RemoveCookie("userid");
	document.location='/'+ file_templ +'?idc='+idc +'&stype='+stype +'&page='+page +'&idr='+idr +'&idt='+idt +'&idn='+idn +'&r='+RND;
	//location.reload();
}

var MainID;
var ParentID;
var RubricID;
var Add_Under_Cur_Country='<table border=0 cellpadding=0 cellspacing=0 style="margin:1 5 0 5;"><tr valign=top><td colspan=3 height=20 class=td_grey_top><b>Курорты / Города</b></td></tr><tr><td><img src="/i/td_grey_bot_left.gif" width=6 height=6 alt=""></td><td bgcolor=#A2B5BC width=100%></td><td><img src="/i/td_grey_bot_right.gif" width=6 height=6 alt=""></td></tr></table>';
var Add_Under_Cur_Resort='<img src="/i/0.gif" class=hr_gray4><br><table cellpadding=0 cellspacing=0 style="margin:0 5 0 5;"><tr valign=top><td colspan=3 class=td_top></td></tr><tr valign=top><td class=td_left></td><td width=100% class=td_hotel><b>Отели</b></td><td class=td_right></td></tr><tr><td><img src="/i/td_bot_left.gif" width=6 height=6></td><td class=td_bot></td><td><img src="/i/td_bot_right.gif" width=6 height=6></td></tr></table>';
var Add_After_Cur_Resort='<img src="/i/0.gif" class=hr_gray4>';

function cat_01(val){if (MainID==val) document.write(Add_Under_Cur_Country);}
function cat_02(val){if (MainID==val) document.write('<img src="/i/0.gif" class=hr_gray2>');}
function cat_11(val){if (ParentID==val || RubricID==val) document.write(Add_Under_Cur_Resort);}
function cat_12(val){if (ParentID==val || RubricID==val) document.write(Add_After_Cur_Resort);}

function path(val_level,val_idc,val_name){
	if (val_level==0) { str_a="Страна"; str_title="Информация о стране "+val_name; }
	else if (val_level==1) { str_a="Курорт / Город"; str_title="Информация о городе / курорте "+val_name; }
	else if (val_level==2) { str_a="Тип отеля"; str_title="Информация об отелях "+val_name; }
	else { str_a="Описание отеля"; str_title="Информация об отеле "+val_name; }
	document.write('<a href="/vcd-'+val_idc+'/catalog_info.html" title="'+str_title+'">'+str_a+'</a>');
	//if (val_url!='') document.write('<a href="'+val_url+'">'+str_a+'</a>');
	//else document.write(str_a);
}

function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01
 newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
 newWindow.document.open();
 newWindow.document.write('<html><title>'+alt+'</title><BODY onload="qwer=1;return true;"  bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">'); 
  if (imageType == "swf"){
   newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
   newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
   newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
   newWindow.document.write('</embed></object>');  }else{
   newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">');    }
 newWindow.document.write('</body></html>');
 newWindow.document.close();
 newWindow.focus();
}
