function addBookmark(url, title)
{
 if (!url) url = location.href;
 if (!title) title = document.title;
 
 //Gecko
 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
 //IE4+
 else if (typeof window.external == "object") window.external.AddFavorite(url, title);
 //Opera7+
 else if (window.opera && document.createElement)
 {
   var a = document.createElement('A');
   if (!a) return false; //IF Opera 6
   a.setAttribute('rel','sidebar');
   a.setAttribute('href',url);
   a.setAttribute('title',title);
   a.click();
 }
 else return false;
 
 return true;
}


function ShowBlock(id, ids){
    for(i=0;i<ids.length;i++)  {
        document.getElementById(ids[i]).style.display = 'none';
        document.getElementById(ids[i]+'-li').setAttribute("class", "");
    }
    document.getElementById(id).style.display = 'block';
        document.getElementById(id+'-li').setAttribute("class", "selected");
}       

function ShowHide(id){
   if ( document.getElementById(id).style.display == 'block')
    document.getElementById(id).style.display = 'none';
   else
    document.getElementById(id).style.display = 'block';
}

function getMapObjectType(categoryId){
  if ( categoryId != '')
    $("#mapObjectTypeContainer")[0].innerHTML = $.ajax({
      url: rootPath+"mapobject/subcategorylist/"+categoryId,
      async: false
    }).responseText;
  else
    $("#mapObjectTypeContainer")[0].innerHTML = '';
}
function getSubCategory(categoryId){
  if ( categoryId != '')
    $("#companyTypeId")[0].innerHTML = $.ajax({
      url: rootPath+"companies/subcategorylist/"+categoryId,
      async: false
    }).responseText;
  else
    $("#companyTypeId")[0].innerHTML = '';
}
function getInsertionSubCategory(categoryId){
  if ( categoryId != '')
    $("#insertionCategory")[0].innerHTML = $.ajax({
      url: rootPath+"insertions/subcategorylist/"+categoryId,
      async: false
    }).responseText;
  else
    $("#insertionCategory")[0].innerHTML = '';
}
function getQuestionSubCategory(categoryId){
  if ( categoryId != '')
    $("#questionCategory")[0].innerHTML = $.ajax({
      url: rootPath+"questions/subcategorylist/"+categoryId,
      async: false
    }).responseText;
  else
    $("#questionCategory")[0].innerHTML = '';
}
function getSubCategoryForNew(categoryId){
  if ( categoryId != '')
    $("#companyTypeId")[0].innerHTML = $.ajax({
      url: rootPath+"companies/subcategorylistnew/"+categoryId,
      async: false
    }).responseText;
  else
    $("#companyTypeId")[0].innerHTML = '';
}
function getCategoryReferenceList(categoryId){
  if ( $("#companyReferenceIdList")[0] != null ) {
	  if ( categoryId != '')
		$("#companyReferenceIdList")[0].innerHTML = $.ajax({
		  url: rootPath+"companies/companyreferencelist/"+categoryId,
		  async: false
		}).responseText;
	  else
		$("#companyReferenceIdList")[0].innerHTML = '';
	}
}

function showClass(showClass, hideClass){
  $("li."+hideClass).removeClass("visible");
  $("li."+showClass).addClass("visible");
}

function checkAll(chkbxClass){
  $("."+chkbxClass).attr('checked', true);
}
function unCheckAll(chkbxClass){
  $("."+chkbxClass).attr('checked', false);
}


$(document).ready(function() {
        jQuery(window).bind("beforeunload",
            function(){
                if ( openNewWindow != null && openNewWindow==1) {
                    window.open(rootPath+'news/main','mainNews', '');
                }
            });
	if ( $('#rightBanners')[0] != null ) {
		$('#rightBanners')[0].innerHTML = $.ajax({
			url: rootPath+'index/rightbanners' + ($('#homePage')[0]!=null?'/homepage/1':''),
			async: false
			}).responseText; 
		if ( $('#befeaterBanner')[0] != null ) {
		var ITCGRef = 'none';if (document.referrer) ITCGRef = escape(document.referrer);
		var ITCGuTail = '?randad' + Math.round((Math.random()*10000000)) + '&' + ITCGRef;
		var ITCGSc = '<'+'script language="JavaScript" type="text/javascript" ';
		ITCGSc += 'src="http://www.itcgin.net/show/24132433/show.js'+ITCGuTail;
		ITCGSc += '"><'+'/script'+'>';
		
		$('#befeaterBanner')[0].innerHTML = ITCGSc; 
	}
	}

        $("input#searchKey").keypress(function (e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                location.href=rootPath+'search?searchKey='+$('#searchKey')[0].value;
                return false;
            } else {
                return true;
            }
        });

        $("input#userSearch").keypress(function (e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                location.href=rootPath+'user/index/usersearchkey/'+$('#userSearch')[0].value +'/withavatar/'+($('#withAvatar')[0].checked?1:0);
                return false;
            } else {
                return true;
            }
        });
        
        /*
	if ( $('#informers')[0] != null ) {
		$('#informers')[0].innerHTML = $.ajax({
			url: rootPath+'index/informers',
			async: false
			}).responseText; 
	}*/
	
	
        if ( showToolTip==1)
            setNewsToolTip();
	
});



function setNewsToolTip(){
    $("a.news-info").tooltip({
        bodyHandler: function() {
            var str = rootPath + $(this).attr("name");
            return $.ajax({
		      url: str,
                      delay: 0,
		      async: false
		    }).responseText;
        },
      delay: 2000,
      track:true,
        showURL: false
    });
}
