var img_path="/KamiSever/img";
var search_start  = '';
var search_module = '<form action="!go" method="POST"><input type="hidden" name="ln" value="Pages-SearchAction.dpsp"><input type="text" name="contains" value="" size="30" maxlength="" style="border-right:#455C7C 1px solid; border-top:#455C7C 1px solid;	border-left:#455C7C 1px solid;	border-bottom:#455C7C 1px solid;">'+
'&nbsp;<input type="image" name="search" src="/KamiSever/img/mm_search.gif" width="16" height="15" border="0" align="middle"></form>';
if (document.images) {
  mm_contacts   = new Image(99, 15);  mm_contacts.src    = img_path+'/mm_contacts.gif';  
  mm_contacts_s  = new Image(99, 15);  mm_contacts_s.src  = img_path+'/mm_contacts_s.gif';
  
  mm_about   = new Image(99, 15);  mm_about.src    = img_path+'/mm_about.gif';  
  mm_about_s  = new Image(99, 15);  mm_about_s.src  = img_path+'/mm_about_s.gif';
  
  mm_home   = new Image(39, 15);  mm_home.src    = img_path+'/mm_home.gif';  
  mm_home_s  = new Image(39, 15);  mm_home_s.src  = img_path+'/mm_home_s.gif';
  
  mm_news   = new Image(99, 15);  mm_news.src    = img_path+'/mm_news.gif';  
  mm_news_s  = new Image(99, 15);  mm_news_s.src  = img_path+'/mm_news_s.gif';
  
  mm_products   = new Image(100, 15);  mm_products.src    = img_path+'/mm_products.gif';  
  mm_products_s  = new Image(100, 15);  mm_products_s.src  = img_path+'/mm_products_s.gif';
  
  mm_bproducts   = new Image(100, 15);  mm_bproducts.src    = img_path+'/mm_bproducts.gif';  
  mm_bproducts_s  = new Image(100, 15);  mm_bproducts_s.src  = img_path+'/mm_bproducts_s.gif';
  
  mm_services   = new Image(100, 15);  mm_services.src    = img_path+'/mm_services.gif';  
  mm_services_s  = new Image(100, 15);  mm_services_s.src  = img_path+'/mm_services_s.gif';
  
  mm_bservices   = new Image(100, 15);  mm_bservices.src    = img_path+'/mm_bservices.gif';  
  mm_bservices_s  = new Image(100, 15);  mm_bservices_s.src  = img_path+'/mm_bservices_s.gif';

  mm_about_system   = new Image(100, 15);  mm_about_system.src    = img_path+'/mm_about_system.gif';  
  mm_about_system_s  = new Image(100, 15);  mm_about_system_s.src  = img_path+'/mm_about_system_s.gif';
  
  mm_babout_system   = new Image(100, 15);  mm_babout_system.src    = img_path+'/mm_babout_system.gif';  
  mm_babout_system_s  = new Image(100, 15);  mm_babout_system_s.src  = img_path+'/mm_babout_system_s.gif';
  
  mm_to_subscr   = new Image(100, 15);  mm_to_subscr.src    = img_path+'/mm_to_subscr.gif';  
  mm_to_subscr_s  = new Image(100, 15);  mm_to_subscr_s.src  = img_path+'/mm_to_subscr_s.gif';
  
  mm_bto_subscr   = new Image(100, 15);  mm_bto_subscr.src    = img_path+'/mm_bto_subscr.gif';  
  mm_bto_subscr_s  = new Image(100, 15);  mm_bto_subscr_s.src  = img_path+'/mm_bto_subscr_s.gif';
  
  smenu_partners   = new Image(122, 20);  smenu_partners.src    = img_path+'/smenu_partners.gif';  
  smenu_partners_s  = new Image(122, 20);  smenu_partners_s.src  = img_path+'/smenu_partners_s.gif';

  mm_phone    = new Image(39, 15);  mm_phone.src    = img_path+'/mm_phone.gif';  
  mm_phone_s  = new Image(39, 15);  mm_phone_s.src  = img_path+'/mm_phone_s.gif';

  mm_bphone   = new Image(39, 15);  mm_bphone.src    = img_path+'/mm_bphone.gif';  
  mm_bphone_s = new Image(39, 15);  mm_bphone_s.src  = img_path+'/mm_bphone_s.gif';

  mm_baddition   = new Image(100, 15);  mm_baddition.src    = img_path+'/mm_baddition.gif';  
  mm_baddition_s = new Image(100, 15);  mm_baddition_s.src  = img_path+'/mm_baddition_s.gif';


}

function di(id, name) {
  if (document.images) {
    document.images[id].src = eval(name+".src");
  }
  return false;
}

//----- open_help -----

function help_open(wnd,url)
{
  var child_wnd;
 
  try
  {
    child_wnd = wnd.open(url,'help',
                         'top=0,left=0,height=400,width=500,status=no,toolbar=no,menubar=no,location=no,'+
                         'resizable=yes,scrollbars=yes');
    child_wnd.focus();
  }
  catch (e) {}
}


function open_help(wnd,help_id,user_guid)
{
  var child_wnd;
 
  try
  {
    child_wnd = wnd.open('!go?id_='+help_id+'&guid='+user_guid,'help',
                         'top=0,left=0,height=400,width=500,status=no,toolbar=no,menubar=no,location=no,'+
                         'resizable=yes,scrollbars=yes');
    child_wnd.focus();
  }
  catch (e) {}
}

//----- open_in_new_window -----
function open_in_new_window(wnd,w_url)
{
  var child_wnd;
  var rnd_val = Math.floor(Math.random()*1000);
 
  try
  {
    child_wnd = wnd.open(w_url,'newwin'+rnd_val,
                         'top=0,left=0,height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=yes,'+
                         'resizable=yes,scrollbars=yes');
    child_wnd.focus();
  }
  catch (e) {}
}

//----- ltrim -----
function ltrim( str )
{
  var ret = str;
  while (ret.substr(0,1) == ' ') ret = ret.substr(1,ret.length-1);
  return ret;
}

//----- get_init_cap -----
function get_init_cap( str )
{
  var ret = ltrim( str );

  ret = (ret.substr(0,1)).toUpperCase() + (ret.substr(1,ret.length-1)).toLowerCase();

  return ret;
}


function di(id, name, stat) {
  if (document.images) {
    document.images[id].src = eval(name+".src");
    if (stat != null)
      window.status = stat;
    else
      window.status = window.defaultStatus;
    return true;
  }
  return false;
}


// ----- image links -----

// **************************************************************
// *  for select from dictionary (unit 8860) (Alexi - version)  *
// **************************************************************
function get_value_from_dictionary(user_guid, input_id, title, table_name, id_field, name_field, prefix_field, show_prefix)
{
  var child_wnd;
  var rnd_val = Math.floor(Math.random()*1000);

  var inpt = document.all(input_id);
  if(inpt.options(inpt.selectedIndex).value != 'OTHERS')
  {
    inpt.setAttribute('old_selected_index', inpt.selectedIndex);
    return;
  }
  inpt.selectedIndex = inpt.getAttribute('old_selected_index');
  
  try
  {
    child_wnd = window.open('!go?id_=8860&guid='+user_guid+'&title='+title+'&table_name='+table_name+'&id_field='+id_field+
                            '&name_field='+name_field+'&prefix_field='+prefix_field+'&show_prefix='+show_prefix+'&input_id='+input_id
                            ,'newwin'+rnd_val,'top=20,left=20,height=555,width=400,status=no,toolbar=no,'+
                            'menubar=no,location=no,resizable=yes,scrollbars=no');
    child_wnd.focus();
  }
  catch (e) {}
}

function set_value_from_dictionary(input_id, id_value, name_value)
{
  var i;
  var inpt = document.all(input_id);

  for(i = 0; i < inpt.options.length; i++)
  {
    if(inpt.options(i).value == id_value)
    {
      inpt.selectedIndex = i;
      return;
    }
  } 

  var new_op = document.createElement("OPTION");
  inpt.options.add(new_op);
  inpt.options(inpt.options.length - 1).value = inpt.options(inpt.options.length - 2).value;
  inpt.options(inpt.options.length - 1).innerText = inpt.options(inpt.options.length - 2).innerText;
  inpt.options(inpt.options.length - 2).value = id_value;
  inpt.options(inpt.options.length - 2).innerText = name_value;
  inpt.selectedIndex = inpt.length - 2;
  inpt.setAttribute('old_selected_index', inpt.selectedIndex)
}

function set_old_selected_index(input_id)
{
  if(document.all(input_id).options(document.all(input_id).selectedIndex).value != 'OTHERS')
    document.all(input_id).setAttribute('old_selected_index', document.all(input_id).selectedIndex);
}



// ***************************************************
// *  for select from user dictionary (AT - version) *
// ***************************************************
var oSelect;
var gDay;
var gMonth;
var gYear;
var gFdate;
var gForm;


function CheckDParam(popupUrl,sFdate,sForm)
{
  gFdate    =  sFdate;
  gForm     =  sForm;

  if ( 1 == 1)
  {
    width = 200;
    height = 250;
    url = popupUrl;

    if (url == "") return;


    if (width == 0 && height == 0)
    {
      location.href = url;
      return;
    }

    r = Math.random();
    remote = window.open(url, "ChangeDate","height="+height+",width="+width+",location=no,"+
      "scrollbars=no,menubar=no,toolbar=no,resizable=yes,status=no");
    remote.focus();
  }
}

function ChangeDate(pid,sDay,sMonth,sYear)
{

  var Select  = gDay;
  var oOption = document.createElement("OPTION");
  oOption.text = sDay;
  oOption.value = sDay;
  oOption.selected = true;
  Select.add(oOption);


  var Select  = gMonth;
  var oOption = document.createElement("OPTION");
  oOption.text = sMonth;
  oOption.value = sMonth;
  oOption.selected = true;
  Select.add(oOption);

  var Select  = gYear;
  var oOption = document.createElement("OPTION");
  oOption.text = sYear;
  oOption.value = sYear;
  oOption.selected = true;
  Select.add(oOption);

}


function CheckDate(Select,sDay,sMonth,sYear)
{
  oSelect =  Select;
  gDay    =  sDay;
  gMonth  =  sMonth;
  gYear   =  sYear;  

  if ( Select.value == "OTHERS")
  {
    width = Select.options[Select.selectedIndex].popupWidth;
    height = Select.options[Select.selectedIndex].popupHeigth;
    url = Select.options[Select.selectedIndex].popupUrl;

    if (url == "") return;

    Select.selectedIndex = Select.getAttribute('old_selected_index');

    //Select.selectedIndex = 0;
    if (width == 0 && height == 0)
    {
      location.href = url;
      return;
    }

    r = Math.random();
    url += "&s_ref$="+Select.name;
    remote = window.open(url, "ChangePage","height="+height+",width="+width+",location=no,"+
      "scrollbars=no,menubar=no,toolbar=no,resizable=yes,status=no");
    remote.focus();
  }
}


function CheckDateLink(popupUrl,sDay,sMonth,sYear)
{
  gDay    =  sDay;
  gMonth  =  sMonth;
  gYear   =  sYear;  
  

  if ( 1 == 1)
  {
    width = 200;
    height = 250;
    url = popupUrl;

    if (url == "") return;


    if (width == 0 && height == 0)
    {
      location.href = url;
      return;
    }

    r = Math.random();
    remote = window.open(url, "ChangeDate","height="+height+",width="+width+",location=no,"+
      "scrollbars=no,menubar=no,toolbar=no,resizable=yes,status=no");
    remote.focus();
  }
}




function ChangeOwner(pid, pvalue)
{
  var Select  = oSelect;
  var oOption = document.createElement("OPTION");
  oOption.text = pvalue;
  oOption.value = pid;
  oOption.selected = true;
  Select.add(oOption);
}

function CheckOwner(Select)
{
  oSelect =  Select;
  if ( Select.value == "OTHERS")
  {
    width = Select.options[Select.selectedIndex].popupWidth;
    height = Select.options[Select.selectedIndex].popupHeigth;
    url = Select.options[Select.selectedIndex].popupUrl;

    if (url == "") return;

    Select.selectedIndex = Select.getAttribute('old_selected_index');

    //Select.selectedIndex = 0;
    if (width == 0 && height == 0)
    {
      location.href = url;
      return;
    }

    r = Math.random();
    url += "&s_ref$="+Select.name;
    remote = window.open(url, "ChangePage","height="+height+",width="+width+",location=no,"+
      "scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=no");
    remote.focus();
  }
}

function SetOldSelectedIndex(Select)
{
  if(Select.selectedIndex != Select.lenght - 1)
    Select.setAttribute('old_selected_index', Select.selectedIndex);
}

function fixPNG(element)
{
  //Если браузер IE версии 5.5-6
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG') //Если текущий элемент  картинка (тэг IMG)
    	{ 
		
		if (/\.png$/.test(element.src)) //Если файл картинки имеет расширение PNG
    	  {
        src = element.src;
        element.src = "/KamiSever/e.gif"; //заменяем изображение прозрачным gif-ом
      	}

		}
	else{
	  //если у элемента задана фоновая картинка, то присваеваем значение свойства background-шmage переменной src
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1]; //берем из значения свойства background-шmage только адрес картинки
        element.runtimeStyle.backgroundImage="none"; //убираем фоновое изображение
      }
    }
    //если, src не пуст, то нужно загрузить изображение с помощью фильтра AlphaImageLoader
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

function boldTd(id) {
  document.all[id].style.color = '#EBF1FC'; 
  document.all[id].style.background = '#ccccff'; 
}
function unboldTd(id) {
  document.all[id].style.color = '#0C2347';  
  document.all[id].style.background = '#EBF1FC'; 
}
function hMenu (id,tid) {document.all[id].style.visibility = 'hidden';unboldTd(tid);}
function h2Menu (id,tid) {document.all[id].style.visibility = 'hidden';}
function sMenu (id,tid) {document.all[id].style.visibility = 'visible';boldTd(tid);}
function hide (id) {document.getElementById(id).style.visibility = 'hidden';}
function display_inline (id) {document.getElementById(id).style.display = 'inline';}
function display_none (id) {document.getElementById(id).style.display = 'none';}

function show_hide (id) {
var elem = document.getElementById(id);
if(elem.style.visibility == 'visible')
 {
	elem.style.visibility = 'hidden';
 }else
 {
	elem.style.visibility = 'visible';
 }
}

function inline_none (id) {
var elem = document.getElementById(id);
if(elem.style.display == 'inline')
 {
	elem.style.display = 'none';
 }else
 {
	elem.style.display = 'inline';
 }
}
/*BEGIN Ajax call support*/
var request = null;
var isLoading = false;
    var READY_STATE_UNINITIALIZED = 0;
    var READY_STATE_LOADING = 1;
    var READY_STATE_LOADED = 2;
    var READY_STATE_INTERACTIVE = 3;
    var READY_STATE_COMPLETE = 4;
    var completeHandler = null;
    var errorHandler = null;


var onReadyState = function() {
        var ready = request.readyState;
        if (ready == READY_STATE_COMPLETE) {
            var httpStatus = request.status;
            if (httpStatus == 200 || httpStatus == 0) {
               if(isLoading) {
                    
					completeHandler();
                    isLoading = false;
					
                   }
            }
            else {
                errorHandler.call(request);
               isLoading = false;
            }
        }
    }
    var defaultError = function() {
        alert("Error!!!\n\nReadyState:" + this.readyState
            + "\nStatus: " + this.status
            + "\nHeaders: " + this.getAllResponseHeaders()
            + "\nResponse: " + this.responseText);
    }

    var loadXMLDoc = function(url, method, content, contentType, contentLength, headers, async) {
        if (!method) {
            method = "GET";
        }
        if (!contentType && method == "POST") {
            contentType = 'text/xml; charset=utf-8';
        }
        if (window.XMLHttpRequest) {
            request = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (error) {
                request = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        if (request) {
            try {
                request.open(method, url, async);
                if (contentType) {
                    request.setRequestHeader('Content-Type', contentType);
                }
                if (contentLength) {
                    request.setRequestHeader('Content-Length', contentLength);
                }
                if (headers) {
                    for (var h in headers) {
                        request.setRequestHeader(h, headers[h]);
                    }
                }
                request.onreadystatechange = onReadyState;
                                                               isLoading = true;
                request.send(content);
                                                               if(!async)
                                                                              isLoading = false;
            }
            catch (error) {
                errorHandler.call(request);
                                                               isLoading = false;
            }
        }
    }
/* END Ajax call support*/	

/* BEGIN Ajax calls*/
	function refr_captcha()
	{
		
		loadXMLDoc('!go?ln=Captcha.dpsp','GET', null,'text/html; charset=windows-1251',0,null,true);
		
	}
	completeHandler = function write_captcha()
	{
		var elem = document.getElementById('captcha_div');
		elem.innerHTML=request.responseText;
	}
