//***  CONFIGURATION *******//


searchCount = 3;
searchURL = 'http://links.boom.ge/search.php';

allURL    = Array(
        'http://www.boom.ge/search.php',
        'http://links.boom.ge/search.php',
        'http://news.boom.ge/geo/'
      );

boomColors = Array('#D10303','#00940A','#3A679E','#FF7E00','#FE5B00','#757575',"#E71085","#6892F3","#FAC361","#124B91","#6CA409","#000000");

//**************************//

ListVisible = false;



if(readCookie('color') in boomColors)
    ChangeColors(readCookie('color'));


function writeCookie(cookieName, cookieContent, cookieExpireTime){
  var cookiePath = '/';
  if(cookieExpireTime>0){
    var expDate=new Date()
    expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60)
    var expires=expDate.toGMTString()
    document.cookie=cookieName+"="+escape(cookieContent)+";path="+escape(cookiePath)+";expires="+expires+";domain=boom.ge";
  }
    else
    document.cookie=cookieName+"="+escape(cookieContent)+";path="+escape(cookiePath)+";domain='boom.ge'";
  
}

//alert(readCookie('color'));

function readCookie(cookieName){
  var ourCookie=document.cookie;
  if(!ourCookie || ourCookie=="")return ""
  ourCookie=ourCookie.split(";")
  var i=0;
  var Cookie;
  while(i<ourCookie.length){
    Cookie=ourCookie[i].split("=")[0];
    if(Cookie.charAt(0)==" ")
    Cookie=Cookie.substring(1);
    if(Cookie==cookieName){
      return unescape(ourCookie[i].split("=")[1])
    }
    i++;
  }
  return "";
}

function deleteCookie(cookieName){
  var cookiePath = '/';
  document.cookie=cookieName+"="+readCookie(cookieName)+";path="+escape(cookiePath)+";expires=Thu, 01-Jan-1970 00:00:01 GMT;";
}

function DrawService(id, key, position){
 key = menuSet[id-1]; 
 if(document.cookie)
   document.write('<span id="servItem'+ position + '" class="dark_gray">' + getMenuImage(id-1,key) + '</span>');
 else
  BuildButtonNonEdit(id);
 }

function ShowList(position){
 var MenuId = 'srv'+position;
 if(document.getElementById(MenuId).style.display=="none")
    { 
    ListVisible = true;
    changeHTML(MenuId,Buildsrv(position));
    for(i=1;i<=servCount;i++)
     SetVisibility('srv'+i,'none');
    SetVisibility(MenuId,'block');
    }
 else
   {
   SetVisibility(MenuId,'none');
   
   }
}



function BuildButtonNonEdit(id,key,position){
  document.write('<span id="servItem'+ position + '" class="dark_gray">' + getMenuImage(id,key) + '</span>');
}

function changeHTML(elementId,code){
  var element=document.getElementById(elementId);
  element.innerHTML = code;
}

function getMenuImage(id, key){
  if(key){
    for(i=0;i<=MenuAllData.length;i++){
      if(MenuAllData[i]){
        if(key == MenuAllData[i][6]){
          id = i;
        }
      }
    }
  }
  return '<a class="serv_button" href="'+MenuAllData[id][0]+'"><img src="'+MenuAllData[id][1]+'" width="'+MenuAllData[id][2]+'" height="'+MenuAllData[id][3]+'" alt="'+MenuAllData[id][4]+'" title="'+MenuAllData[id][4]+'" align="center" border="0">&nbsp;'+MenuAllData[id][5]+'</a>';
} 

function SetVisibility(block,style){
  if(document.getElementById)
    document.getElementById(block).style.display = style;
}

function Buildsrv(position){
  var CurrentMenuKey = menuSet[position-1]; 
  if(document.getElementById){
    slideHTML = '<div style=" position:absolute; z-index:900'+position+';" class="serv_list"><table cellpadding="0" cellspacing="0" border="0" width="120">';
    for(i=0;i<=MenuAllData.length;i++){
      if(MenuAllData[i]){
        elementClass = 'active';
        var inJsMenu = false;
        var menuInOutClass = 'jsmenuOut';
        for(c=0;c<=menuSet.length;c++){
          if(menuSet[c] == MenuAllData[i][6]){
            inJsMenu = true;
          }
        }
        if(CurrentMenuKey == MenuAllData[i][6]){elementClass = 'current'}
        if(inJsMenu){ menuInOutClass = 'jsmenuIn';}
        slideHTML += '<tr class="' + elementClass + '"><td class="out" onmouseover="this.className=\'over\'" onmouseout="this.className=\'out\'"  onclick="return changeService('+position+',\''+MenuAllData[i][6]+'\');return false"><span class="'+menuInOutClass+'">';
        slideHTML += MenuAllData[i][5];
        slideHTML += '</span></td></tr>';
      }
    }
    slideHTML += '</table></div>'; 
    return slideHTML; 
  }
}


function changeService(pos,key)
   {
    ListVisible = false;
    deleteCookie('js_menu');
    CValue = "";
    for(i=0;i<servCount;i++){ 
       if(i!=pos-1)
          CValue  = CValue  + ' ' + menuSet[i];
       else  
          CValue  = CValue  + ' ' + key; 
      } 
    CValue = CValue.substring(1);  
    writeCookie('js_menu',CValue, 77777); 
    menuSet[pos-1]=key; 
    changeHTML('servItem'+pos,getMenuImage('',key)); 
    SetVisibility('srv'+pos,'none');
 }

function HideLayers(){
  if(ListVisible)
     {
      for(i=1;i<=servCount;i++)
        SetVisibility('srv'+i,'none');
    }
  ListVisible = false;
  HideColors();
}

function HideColors(){
  document.getElementById('colors').innerHTML = "";
}

function SetHome(obj){
 obj.style.behavior='url(#default#homepage)'; 
 obj.setHomePage('http://www.boom.ge'); 
 return false;
}


//*****   SEARCH   *****///

function SetSearch(obj){
 for(i=1; i<=searchCount ; i++)
    document.getElementById('search'+i).className =(obj==i)?'searchActive':'searchInactive'; 
 searchURL = allURL[obj-1];   
 if(document.forms['search'].query.value!="")
   {
      SendRequest();
      document.forms['search'].submit();
 
   }
 return false;
}

function SendRequest(){
  document.forms['search'].action = searchURL;
  /*if (document.getElementById('search2').href+'search.php' == searchURL){
	document.forms['search'].query.name = 'keyword';
  }*/

}

//*********************//
function SaveGeo(){
 deleteCookie("geo");
 if(document.getElementById('geo').checked)
   writeCookie('geo',"1", 77777);
 else
   writeCookie('geo',"0", 77777);
 elm = document.all('query');
 rng = elm.createTextRange();
 rng.collapse(false);
 rng.select();
 elm.click();
 elm.focus();
}

//*********************//

function selectMenuItem(objSelect,param)
{
  var sURL = objSelect.options[objSelect.selectedIndex].value;
  window.location.href = "?" + param + "="+sURL;
  return false;
}

//*********************
function ShowColors(){
  var colors ="";
   for(i=0;i<boomColors.length;i++)
     {
       colors += "<div style='width:16px;height:16px;margin:2px;background:"+boomColors[i]+"'>";
       colors += "<img src='images/dot.gif' style=\"width:12px;height:12px;border:2px solid #ccc;cursor:hand;\" onclick=\"ChangeColors('"+i+"');\"></div>";
     }
   document.getElementById('colors').innerHTML = colors; 
}

function ChangeColors(colorId){

  document.styleSheets[0].rules[0].style.borderColor = boomColors[colorId];
  document.styleSheets[0].rules[1].style.background  = boomColors[colorId];
  document.styleSheets[0].rules[2].style.color       = boomColors[colorId];
  writeCookie('color',colorId, 77777);
  
}


