host = 'http://'+location.host;
path = host+'/data/img/'; 
imglist = new Array;
var old_image;

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

function display_menu(id){ 

  //alert(id);
  
  for(i=0; i<=30; i=i+1){
    lt = 'menu'+i;
    //alert(lt);
    if(id == i) continue;  
    
    if(document.getElementById && document.getElementById(lt)){
     itema = document.getElementById(lt);
     itema.style.display = 'none';
     itema.style.backgroundColor = '#f0f0f1'; 
    }
  }
    
  child = document.getElementById('menu'+id);
  main = document.getElementById('head'+id);
  main.style.backgroundColor = '#f0f0f1';
  content = main.innerHTML;
      
  if(child.style.display == 'none'){
    child.style.display = 'block';
    content = content.replace('+', '-');
  }
  else{
    child.style.display = 'none';
    content = content.replace('-', '+');
  }
  
  main.innerHTML = content;   
  return false;
}


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

function preload_images() {
  if (document.images) {

    for(i=1; i<=7; i++){ 
      imglist[i] = new Image(); 
      imglist[i].src = host + "/data/img/menu/"+i+"_on.jpg"; 
    }
  } 
}

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

function change_menu(id, type){

  if(type){
    old_image = document.images['menu'+id].src;
    document.images['menu'+id].src = imglist[id].src; 
  }
  else
    document.images['menu'+id].src = old_image;  
}

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

function change_bg(type, id, ison){

  obj = document.getElementById(type+id);
  
  if(ison){
    if(type == 'head') obj.style.backgroundColor = '#f8f8f8';
    else obj.style.backgroundColor = '#cee3f7';
  }
  else{
    if(type == 'head') obj.style.backgroundColor = '#f0f0f1';
    else obj.style.backgroundColor = '#ffffff';
  }
}

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

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 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 update_selects(cat_active, subcat_active) {
  var first_select = document.getElementById("country_id");
  var second_select = document.getElementById("city_id");
  
  if(!first_select.options.length){
    first_select.options[0] = new Option('All', 0); 
    
    for (var i=0; i<countries.length; i++){
      subs = countries[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 = cities[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+1] = new Option(subs[1], subs[0]);

      if(subs[0] == subcat_active)
        second_select.options[i+1].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 action_form(myForm, action){  
  myForm.act.value = action;
  myForm.submit(); 
  return false;
}


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

function auto_iframe(frameId){ 
  try{ 
    frame = document.getElementById(frameId); 
    innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document; 
    objToResize = (frame.style) ? frame.style : frame; 
    
    new_size = innerDoc.body.scrollHeight + 10;
    objToResize.height = (new_size>1000) ? new_size : 1000; 
  } 
  catch(err){ 
    window.status = err.message; 
  } 
}
//---------------------------------------------------------------------------------------//

function jumpMenu(myForm, selObj) {
  myForm.act.value = 'change';
  myForm.id.value = selObj.options[selObj.selectedIndex].value;
  myForm.submit(); 
  return false;
}

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

function readFull(num) {
  var shortText = document.getElementById("annotation_short_"+num);
  var fullText = document.getElementById("annotation_full_"+num);
  var isIE; 
  if(window.ActiveXObject) isIE=1;
  if (isIE) fullText.style.display = "block";
  else fullText.style.display = "table-cell";
  shortText.style.display = "none";
}

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

function readShort(num) {
  var shortText = document.getElementById("annotation_short_"+num);
  var fullText = document.getElementById("annotation_full_"+num);
  var isIE; 
  if(window.ActiveXObject) isIE=1;
  if (isIE) shortText.style.display = "block";
  else shortText.style.display = "table-cell";
  fullText.style.display = "none";
}

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

function refreshOrder () {
  var cost = $('cost').innerHTML;
  var quantity = $('quantity').value;
  var total_cost = cost*quantity;
  
  $('total_cost').innerHTML = total_cost;
}

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

function setProperties () {
  document.getElementById('properties_block').style.display = "block";
  document.getElementById('set_properties').style.display = "none";
}

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

function hideProperties () {
  document.getElementById('properties_block').style.display = "none"
  document.getElementById('set_properties').style.display = "block";
}

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

function forgot_password () {
  var forgot = document.createElement("input");
  forgot.type = 'hidden';
  forgot.name = 'forgot';
  forgot.value = true;
  document.forms.auth.appendChild(forgot); 
  document.forms.auth.submit();

}

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

function payback_navi (step) {
  var step_input = document.createElement("input");
  step_input.type = 'hidden';
  step_input.name = 'step_'+step;
  step_input.value = true;
  document.forms.apply_payback.appendChild(step_input); 
  document.forms.apply_payback.submit();

}
//---------------------------------------------------------------------------------------//

function set_url(type) {
  if(type==1) select_box = document.pform.pageurl;
  else select_box = document.pform.modurl;
  
  url = select_box.options[select_box.selectedIndex].value;
  
  if(url) {
    document.pform.document_url.value = url;
    document.pform.document_url.readOnly = 1;
  }
  else
   document.pform.document_url.readOnly = 0;
   
  return false;
  
}

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

function display_childmenu(id){
  if(document.getElementById && document.getElementById('childmenu'+id)){
    obj = document.getElementById('childmenu'+id);
    obj1 = document.getElementById('tdchild'+id); 
     
    obj.style.display = (obj.style.display == 'none' ) ? 'block' : 'none';
    obj1.style.display = (obj1.style.display == 'none' ) ? 'block' : 'none';  
  }
}

function showImage(id) {
  window.open('/gallery/' + id + '.html?image', '_blank',
    'height=694,left=20,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top=40,width=860');
}

function showSwf(url) {
  window.open(url, '_blank',
    'height=500,left=20,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top=40,width=700');
}

function initMenu(){
    jQuery('#top_nav li').hover(
    function(){
        jQuery(this).css('background', '#fcedfb');
        jQuery(this).find('a').css('color', '#000');
        jQuery(this).find('ul li a').css('color', '#FFF');
        jQuery(this).find('ul').css('z-index', '200');
        jQuery(this).find('ul').show(); 
    },
    function(){
        jQuery(this).css('background', 'none');
        jQuery(this).find('a').css('color', '#FFF');
        jQuery(this).find('ul').hide(); 
    })
    
    jQuery('#top_nav li ul li').hover(
    function(){
        jQuery(this).css('background', '#d9d9d9');
        jQuery(this).css('color', '#76006c');
        jQuery(this).find('a').css('color', '#76006c');
    },
    function(){
        jQuery(this).css('background', 'url(/data/img/topnavbg.png) repeat');
        jQuery(this).css('color', '#FFF');
        jQuery(this).find('a').css('color', '#FFF');
    })
}
