host = 'http://'+location.host;
path = host+'/data/img/'; 
legal_characters = '!#$%&()"*+,-./]:[;?_=|0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
thumb_path = 'http://img.youtube.com/vi/';

//---------------------------------------------------------------------------------------// 

function display_menu(id){ 
  if(document.getElementById && document.getElementById(id)){
    obj = document.getElementById(id);
    obj.style.display = (obj.style.display == 'none' ) ? 'block' : 'none';
  }
}

//---------------------------------------------------------------------------------------// 

function display_cat_menu(id){ 
  mid = 'menu'+id
  hid = 'head'+id
  
  if(document.getElementById && document.getElementById(mid)){
    obj1 = document.getElementById(mid);
    obj1.style.display = (obj1.style.display == 'none' ) ? 'block' : 'none';
  } 
  
  if(document.getElementById(hid)){
    obj2 = document.getElementById(hid);
    
    if(obj1.style.display == 'none'){
      obj2.className =  'bg_noneheader';
      obj2.innerHTML= obj2.innerHTML.replace('-','+');
    }
    else{
      obj2.className = 'bg_header';     
      obj2.innerHTML= obj2.innerHTML.replace('+','-');
    }
  }
  
  return false;
}

//---------------------------------------------------------------------------------------// 

function clear_bg(){
  obj = document.getElementById('menu');
  obj.className = 'bg5';
}

//---------------------------------------------------------------------------------------// 

function display_panel(){
  if(document.getElementById && document.getElementById('search_panel')){
    obj = document.getElementById('search_panel');
    obj.style.display = (obj.style.display == 'none' ) ? 'block' : 'none';
  }
}

//---------------------------------------------------------------------------------------// 

function select_all(form)
{
   sample_check = document.getElementById('checklist').checked;
   
   for (i = 0; i < form.elements.length; i++){
     if (form.elements[i].name=='items[]') form.elements[i].checked = sample_check;
   }
}


//---------------------------------------------------------------------------------------// 

function select_all_zones(myForm, name){
  var selection = true;

  for (i = 0; i < myForm.elements.length; i++){
     if (myForm.elements[i].name==name){
       if(myForm.elements[i].checked == false)
         selection = myForm.elements[i].checked;
    }
  }

  for (i = 0; i < myForm.elements.length; i++){
    if (myForm.elements[i].name==name) myForm.elements[i].checked = !selection;
  }
  return false;
}

//---------------------------------------------------------------------------------------//

function display_ext_zones(){                       
  if(document.getElementById && document.getElementById('addzone')){
    obj = document.getElementById('addzone');

    if(obj.style.display == 'none') obj.style.display = 'block'; 
    else obj.style.display = 'none';
  }
}

//---------------------------------------------------------------------------------------//

function show_tree(type) {
  var winWidth = 700;
  var winHeight = 530;
  var w = (screen.width - winWidth)/2;
  var h = (screen.height - winHeight)/2 - 60;
  var url = 'index.php?m=tree&type=' + type;
  var name = 'tree';
  var features = 'scrollbars=no,width='+winWidth+',height='+winHeight+',top='+h+',left='+w;
  window.open(url,name,features);
}

//---------------------------------------------------------------------------------------//  

function new_dir(type) {
  var folder_name = window.prompt('Folder name', 'New folder');
  
  if (folder_name == '' || folder_name == null)
    alert('Enter folder name!');
  else
    parent.frames['tree_view'].location.href='index.php?m=tree&type='+type+'&dir=' + parent.document.tree.current_path.value + '&action=list&newdir=' + folder_name;
} 
    
//---------------------------------------------------------------------------------------//   

function up_dir(type) {                            
  parent.frames['tree_view'].location.href='index.php?m=tree&type='+type+'&dir=' + parent.document.tree.current_path.value + '/..&action=list';
}
    
//---------------------------------------------------------------------------------------//       

function delfile(type, src) {
  parent.frames['tree_view'].location.href='index.php?m=tree&type='+type+'&dir=' + parent.document.tree.current_path.value + '&action=list&delfile=' + src;      
}

//---------------------------------------------------------------------------------------//       

function showfile(type, src) {
  if(parent.document.tree.use_preview.checked)
    parent.frames['show_view'].location.href='index.php?m=tree&type='+type+'&dir=' + parent.document.tree.current_path.value + '&action=show&file=' + src;      
  else
  parent.frames['show_view'].location.href='index.php?m=tree&action=show';      
   
   
  parent.document.tree.selected_file.value = parent.document.tree.current_path.value+'/'+src;
}         

//---------------------------------------------------------------------------------------//

function insertfile() {
  if (parent.document.tree.selected_file.value == '') {
    alert('Please, choose file!');
  }
  else {
    window.opener.document.mform['insertfile'].value = parent.document.tree.selected_file.value;
    setTimeout("self.close();", 50);    
  }
}
   
//---------------------------------------------------------------------------------------//
   
function update_selects(cat_active, subcat_active) {
  var first_select = document.getElementById("cats");
  var second_select = document.getElementById("subcats");
  
  if(!first_select.options.length){
    first_select.options[0] = new Option('', 0); 
    
    for (var i=0; i<cats.length; i++){
      subs = cats[i].split(':');
      first_select.options[i+1] = new Option(subs[1], subs[0]);
      
      if(subs[0] == cat_active)
        first_select.options[i+1].selected = true;
    }
  }
  
  var choice = first_select.options[first_select.selectedIndex].value;
  var db = subcats[choice];
  
  second_select.options.length = 0;
  
  if (choice != ""){
    //second_select.options[0] = new Option('All', 0); 
    for (var i=0; i<db.length; i++) {
      subs = db[i].split(':');
      second_select.options[i] = new Option(subs[1], subs[0]);
      
      if(subs[0] == subcat_active)
        second_select.options[i].selected = true;
    }
  }
}    

//---------------------------------------------------------------------------------------//    
	
function im(path, title){
  host = 'http://'+location.hostname+'/';
  window.open(host+'catalog/image.html?path='+path+'&title='+title,'','width=100, height=100, scrollbars=no');		
}	

//---------------------------------------------------------------------------------------//

function goto_pr() {
  select_box = document.pform.prlist;
  eval("parent.location='"+select_box.options[select_box.selectedIndex].value+"'");
  return false;
  
}

//---------------------------------------------------------------------------------------//
	
function sethome(o,siteurl,sitename) {
	var name = navigator.appName;
	var useragent = navigator.userAgent;
	var version = parseInt(navigator.appVersion);
	var needtoknow = 1;
	
	if ( useragent.indexOf("MSIE") != -1) {
			var index = navigator.userAgent.indexOf("MSIE ");
			if ( index != -1 ) {
				version = parseInt(navigator.userAgent.substring(index+5,index+6));
			}
			if ( version > 4) {
				o.style.behavior='url(#default#homepage)'; o.setHomePage(siteurl);
				needtoknow = 0;
			}
	}
	if (needtoknow != 0) {
		alert('Ваш браузер не поддерживает автоматической установки стартовой страницы')
		//openBrWindow('/help/makehomepage.html','winMakeHomepage','location=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=450');
	}
}
   
//---------------------------------------------------------------------------------------//
   
var old_image;

function on_image(id){
  if(document.images){
    old_image = document.images['img_main'].src;
    document.images['img_main'].src = image_array[id].src; 
  }
}

//---------------------------------------------------------------------------------------//

function out_image(id){
  if(document.images){
    document.images['img_main'].src = old_image; 
  }
}

//---------------------------------------------------------------------------------------// 
var timeout_id;
var times = 0;

function show_block(){
  if(document.getElementById && document.getElementById('addinfo')){
    obj = document.getElementById('addinfo');
    display = (obj.style.display == 'none' ) ? 'block' : 'none';
    
    ctop = screen.height/2 - 100 + document.documentElement.scrollTop;
    cleft = document.body.clientWidth/2 - 100 + document.documentElement.scrollLeft;
    
    obj.style.cssText = 'position:absolute; display:'+display+'; left:'+cleft+'px; top:'+ctop+'px; width:200px; height: 60px;';
  } 
  
  timeout_id = setInterval("hide_block()", 1000);
}

//---------------------------------------------------------------------------------------// 

function hide_block(){
  
  times++;

  if(times == 1){
    if(document.getElementById && document.getElementById('textinfo')){
      obj = document.getElementById('textinfo');
      obj.innerHTML = 'Товар добавлен!';
    }
  }
  else {
   if(document.getElementById && document.getElementById('addinfo')){
     obj = document.getElementById('addinfo');
     obj.style.display = (obj.style.display == 'none' ) ? 'block' : 'none';
   }
   clearInterval(timeout_id);
  }
}

//---------------------------------------------------------------------------------------//

function encrypt(text, key){
  var character
  var character_location
  var encrypted_location
  var encrypted_character
 
  var encrypted_string = ""
 
  for(i=0;i<text.length; i++){
    character = text.substring(i,i+1);  
    character_location = legal_characters.indexOf(character);
    encrypted_location = (character_location ^ key);
    encrypted_character = legal_characters.substring(encrypted_location, encrypted_location + 1);
    encrypted_string += encrypted_character
  }
 return encrypted_string;
}

//---------------------------------------------------------------------------------------//

function decrypt(text, key){
  var character
  var character_location
  var encrypted_location
  var encrypted_character
 
  var decrypted_string = ""
 
  for(i=0;i<text.length; i++){
    character = text.substring(i,i+1);  
    encrypted_location = legal_characters.indexOf(character);
    character_location = (encrypted_location ^ key);
    character = legal_characters.substring(character_location, character_location + 1);
    decrypted_string += character
  }
 return decrypted_string;
}

//---------------------------------------------------------------------------------------//

function thumb(code){
  return thumb_path+code+'/0.jpg';
}
