function voidfn(val)
{	var i = val;
}

// Basic utils
function uh_get_object(obj_id)
{	var obj_var = null;

	if( document.all )
		obj_var = document.all(obj_id);
    else if (document.getElementById)
		obj_var = document.getElementById(obj_id);
	else if(document.layers)
		obj_var = document.layers[obj_id];

    if( obj_var )
    	return obj_var;

    alert('Error retrieve object handle by id: ' + obj_id);}

function showHtml(obj_id)
{
	var obj = uh_get_object(obj_id);
	alert( obj.innerHTML );
}

////////////////////////////////////////////////////////////////////////////////
// Encoding Utils
function escapeEx(str)
{
    var ret = '';

	var i = 0;
    for (var i=0; i<str.length; i++)
    {
        var n = str.charCodeAt(i);
        if (n >= 0x410 && n <= 0x44F)
            n -= 0x350;
        else if (n == 0x451)
            n = 0xB8;
        else if (n == 0x401)
            n = 0xA8;
        if ((n < 65 || n > 90) && (n < 97 || n > 122) && n < 256)
        {
            if (n < 16)
                ret += '%0'+n.toString(16);
            else
                ret += '%'+n.toString(16);
        }
        else
            ret += String.fromCharCode(n);
    }

    return ret;
}


////////////////////////////////////////////////////////////////////////////////
// Windowing utils
// Show popup window
function mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}

function OpenWin(url)
{
	var newwindow = window.open(url, "DetailsWindow", "toolbar=no,status=yes,resizable=no,scrollbars=yes,location=no,menubar=no,width=400,height=500");
	newwindow.focus();
}

function OpenInfoWin(url)
{
	var newwindow = window.open(url, "InfoWindow", "toolbar=no,status=yes,resizable=no,scrollbars=yes,location=no,menubar=no,width=530,height=400");
	newwindow.focus();
	return newwindow;
}

function ReturnFormData(val1, target, val2, target1)
{
	target.value=val1;
	target1.value=val2;
	self.opener.focus();
	window.close();
}

function GetQueryStringParams(wnd)
{
	var query_string = wnd.location.search.substring(1);

	var params = query_string.split('&');

	var json_struct_str = " { params : {";
	for(i=0; i<params.length; i++)
	{		var item_arr = params[i].split('=');

		json_struct_str += (i != 0 ? "," : "") + " " + item_arr[0] + ": \"" + item_arr[1] + "\" ";	}
	json_struct_str += "} }; ";

	//alert( json_struct_str );

	eval('var ret_params = ' + json_struct_str);

	return ret_params;}

function generateSessionID()
{
	charStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";	var sessionId = "";
	for(i=0; i<12; i++)
	{
		sessionId += charStr.charAt( Math.floor(Math.random()*charStr.length) );
	}

	return sessionId;}

function hideItem(itid)
{
	var obj_it = uh_get_object(itid);
	obj_it.style.visibility = "hidden";
	obj_it.style.display = "none";}

function showItem(itid)
{
	var obj_it = uh_get_object(itid);
	obj_it.style.visibility = "visible";
	obj_it.style.display = "block";}

function showItemEx(itid, mode)
{
	var obj_it = uh_get_object(itid);
	obj_it.style.visibility = "visible";
	obj_it.style.display = mode;
}

function showProgress()
{
	var splash = uh_get_object('uh_progress');
	splash.style.visibility = 'visible';
	splash.style.display = 'block';
}

function hideProgress()
{
	var splash = uh_get_object('uh_progress');
	splash.style.visibility = 'hidden';
	splash.style.display = 'none';
}

function showTooltipProgress()
{
	var splash = uh_get_object('popuptooltip_progress');
	var dataobj = uh_get_object('popuptooltip_body');
	var imgobj = uh_get_object('popupprogress_gif');
	dataobj.style.visibility = 'hidden';
	dataobj.style.display = 'none';
	splash.style.visibility = 'visible';
	splash.style.display = 'block';
}

function hideTooltipProgress()
{
	var splash = uh_get_object('popuptooltip_progress');
	var dataobj = uh_get_object('popuptooltip_body');
	var imgobj = uh_get_object('popupprogress_gif');
	splash.style.visibility = 'hidden';
	splash.style.display = 'none';
	dataobj.style.visibility = 'visible';
	dataobj.style.display = 'block';
}

function showTooltip(obj_id, x, y)
{
	var obj = uh_get_object(obj_id);
	var obj_body = uh_get_object(obj_id + "_body");

	obj.style.visibility = "visible";
	obj.style.display = "block";
	obj.style.left = x + "px";
	obj.style.top = y + "px";

	obj_body.innerHTML = "Подождите пока загрузиться информация о гостинице с сервера...<br /><br /><a href=\"javascript:hideTooltip('" + obj_id + "')\" class=\"actlink\">закрыть</a>";
}

function hideTooltip(obj_id)
{
	var obj = uh_get_object(obj_id);
	var obj_body = uh_get_object(obj_id + "_body");

	obj_body.innerHTML = "empty";
	obj.style.visibility = "hidden";
	obj.style.display = "none";
}

// Search popup
function hideSearchPopup(obj_id)
{
	var obj = uh_get_object(obj_id);
	var obj_body = uh_get_object(obj_id + "_body");

	obj_body.innerHTML = "empty";
	obj.style.visibility = "hidden";
	obj.style.display = "none";
}

function showTooltipTextShort(obj_id, x, y, txt)
{
	var obj = uh_get_object(obj_id);
	var obj_body = uh_get_object(obj_id + "_body");

	obj.style.visibility = "visible";
	obj.style.display = "block";
	obj.style.left = x + "px";
	obj.style.top = y + "px";

	obj_body.innerHTML = txt + "<br />";

	//alert( "obj: " + obj_id + "; " + txt );
}

function selWordFromLink(itid, val1, target_id, droptip_id)
{
	//alert( val1 );

	var target = uh_get_object( target_id );
	//var valnameobj = uh_get_object( val1 );

	//target.value=val1.value;
	target.value=val1;
	target.focus();
	hideTooltip(droptip_id);
}

function addslashes (str) {
    //return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

function fillSearchList(str_val, obj_id, inp_id)
{
	var ctrl_droplist = uh_get_object( obj_id );
	var ctrl_text = uh_get_object( inp_id );

	if( search_is_running )
		return;

	search_is_running = true;

	if( str_val.length > 1 )
	{
	  	if( AJAX != null )
		{
			//alert( 'Ajax OK' );
			var process_fn = function(res)
			{
				//alert( "Respoce: " + res );

				eval( 'var responce_data = ' + res );

				var div_inner_html = "";
				var tmpstr = "";

				try
				{
					var show_debug = false;
					// Fill list of cities
					for(i=0; i<responce_data.words.length; i++)
					{
						//if( i>0 )
						//	div_inner_html += '<br />';

						tmpstr = responce_data.words[i].word;
						tmpstr = tmpstr.replace("<b>", "");
						tmpstr = tmpstr.replace("</b>", "");
						tmpstr = tmpstr.replace("\"", "&quot;");

						if( i == 6 )
						{
							//var show_debug = true;
							//alert( responce_data.words[i].word + ' : ' + tmpstr );
						}

						var csitem = responce_data.words[i];

						div_inner_html += '<tr><td style="width: 110px; text-align: center;">'+(csitem.p != '' ? '<img src="http://www.smt.ua/'+csitem.p+'" width="'+csitem.pw+'" height="'+csitem.ph+'" alt="" />' : '')+'</td>'+
							'<td><input type="hidden" name="alldropvals[]" id="seldropitname'+(i+1)+'" value="'+tmpstr+'" />' +
							//'<a href="javascript:selWordFromLink(\''+csitem.itid+'\', \'seldropitname'+(i+1)+'\', \'' + inp_id + '\', \'' + obj_id + '\');" class="searchitem">' + responce_data.words[i].word + '</a></td></tr>';
							'<a href="javascript:selWordFromLink(\''+csitem.itid+'\', \''+tmpstr+'\', \'' + inp_id + '\', \'' + obj_id + '\');" class="searchitem">' + responce_data.words[i].word + '</a></td></tr>';
					}

					if( div_inner_html == "" )
						hideSearchPopup(obj_id);
					else
					{
						//alert(div_inner_html);
						div_inner_html = "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">" + div_inner_html + "</table>";
						showTooltipTextShort(obj_id, ctrl_text.offsetLeft, ctrl_text.offsetTop + 20, div_inner_html);
					}
				}
				catch(e1)
				{
					// Some errors occure while retieving city list so do nothing
					hideSearchPopup(obj_id);
				}

				search_is_running = false;
			};

			var post_req_str = "rcom=uh_com_srchlist&swstart=" + unescape(escapeEx(str_val));
			//var post_req_str = "rcom=uh_com_city_start&citystart=" + str_val;
			AJAX.SendRequest('POST', '', process_fn, encode64(post_req_str));
		}
	}
	else
	{
		hideSearchPopup(obj_id);
		search_is_running = false;
	}
}


///////////////////////////////////////////////////////////////////////////////
// Base 64 utils

// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   var line_len = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >>> 2;
      if( !isNaN(chr2) )
      	enc2 = ((chr1 & 3) << 4) | (chr2 >>> 4);
      else
      	enc2 = ((chr1 & 3) << 4);

      if( !isNaN(chr3) )
      	enc3 = ((chr2 & 15) << 2) | (chr3 >>> 6);
      else
      	enc3 = ((chr2 & 15) << 2);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1);
      output = output + keyStr.charAt(enc2);
      output = output + keyStr.charAt(enc3);
      output = output + keyStr.charAt(enc4);

	/*
      line_len += 4;
      if(line_len >= 72)
      {
      	line_len = 0;
      	output = output + '\r\n';
      }
 	*/

   } while (i < input.length);

   //alert("len: " + output.length + "; " + output);

   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}


// Global vars
var search_is_running = false;
