function noErrorMessages () { return true; }
//window.onerror = noErrorMessages;

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_opera  = agt.indexOf("opera") > -1 ;
var is_safari = agt.indexOf("safari") > -1 ;

var isIE = ((document.all)? true  : false );
var isNS6 = ((document.getElementById && !document.all)? true: false );
var ie55up = (document.all && document.getElementById)?(true):(false);


if (!document.getElementById){
	document.getElementById = function (id){
							if (document.all){
								return document.all[id];
							}
						}
}

function $(id){return document.getElementById(id)}

function addFlashInside (containerId, url,id,w,h,bgcolor, wmode){
	str = '<embed swLiveConnect="true" quality=best type="application/x-shockwave-flash" menu=false  ' +
		' name="' + id + '" id="' + id + '" ' +
		' src="' + url + '" ' +
		' wmode="'+ wmode +'" ' +
		' bgcolor="' + bgcolor + '" ' +
		' width=' + w + ' height=' + h +
		' swLiveConnect=true ' +
		' allowScriptAccess="sameDomain" ' +
		' type="application/x-shockwave-flash" ' +
		' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ></embed>';
		//alert (containerId + ":" + $(containerId) + str);
	setHtml(containerId,str,false,false);

}

function addFlash(url,id,w,h,bgcolor, wmode){

	str = '<embed swLiveConnect="true" quality=best type="application/x-shockwave-flash" menu=false  ' +
		' name="' + id + '" id="' + id + '" ' +
		' src="' + url + '" ' +
		' wmode="'+ wmode +'" ' +
		' bgcolor="' + bgcolor + '" ' +
		' width=' + w + ' height=' + h +
		' swLiveConnect=true ' +
		' allowScriptAccess="sameDomain" ' +
		' type="application/x-shockwave-flash" ' +
		' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ></embed>';

	document.write (str);
}

var clickedSearch = false;
function catchSearch (evt){
	e = (isIE)? (window.event):(evt);

	if(e.keyCode==13){

		clickedSearch = true;
		if (document.forms[0]){document.forms[0].onsubmit = function(){return false};}
		result = validateSearch(false);
		/*
		if (e.cancelBubble) e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		if (e.returnValue) e.returnValue = false;
		if (e.cancel) e.cancel = false;
		*/
		return false;
	}
}

function validateSearch(){
	if ($('q')){
		if ($('q').value.length>1 ){
			top.location.href = '/search.aspx?q='+escape($('q').value);
			return true;
		}else{
			alert ("Search term must be at least 2 characters ");
			setFocus('q');
			return false;
		}
	}
}

function setFocus(id){
	if (id=="")return;
	var o = $(id);
	if (o)o.focus();
}

function setValue(id,val){
	if (id=="")return;
	var o = $(id);
	if (o)o.value = val;
}

function setHtml(id,html,toAppend,hideIfEmpty){
	if (id=="")return;
	var o = $(id);
	if (o){
		html = html.replace(/\\r\\n/gi,"");
		o.innerHTML = (toAppend)?(o.innerHTML+html):(html);
		if (hideIfEmpty && html=="") o.className = "off";
	}
}

function setClass(id,val){
	if (id=="")return;
	var o = $(id);
	if (o)o.className = val;
}
function replaceClass(id,str1,str2){
	if (id=="")return;
	var o = $(id);
	if (o){
		o.className = (o.className!="")?(o.className.replace (str1,str2)):(str2);
	}
}

function getParentId(id){
	var str = "";

	if (id=="")return;

	var o = $(id);
	if (o)o=o.parentElement;

	if (o)str=o.id;

	return str;
}

function getSelValue(id){
	var retVal = "";
	if (id=="")return;
	var o = $(id);
	if (o)retVal = o.value;
	return retVal;
}

function getIndex(id){
	var index = 0;
	if (id=="")return;
	var o = $(id);
	if (o)index=o.selectedIndex ;
	return index;
}

function selectIndex(id, index){
	if (id=="")return;
	var o = $(id);
	if (o)o.selectedIndex = index;
}
function selectValue(id, val){
	if (id=="")return;
	var o = $(id);
	if (o){

		for (i=0;i<o.length; i++){
			if (o[i].value.toLowerCase()==val.toLowerCase() || val==-1){
				o[i].selected = true;
				if (val!=-1)break;
			}
		}
	}
}

var lastPrefix = "";
var lastId = 0;
function showItem(prefix,id, dontClose){
	if (lastId>=0 || (dontClose && lastId==id )){
		replaceClass(lastPrefix+lastId,"block","off");
		replaceClass("nav"+lastId,"sel","reg")
	}

	if (lastId!=id || (dontClose && lastId==id) ){
		lastPrefix = prefix;
		lastId = id;
		replaceClass(lastPrefix+lastId,"off","block");
		replaceClass("nav"+lastId,"reg","sel")
	}else{
		lastId = 0;
		lastPrefix = "";
	}

}

var lastFilter = "";
var lastFilterType = "";
var lastPrevSibling = "";
function showFilter(filterType,id){
	var oPrev;
	var o;
	if (lastFilter!=""){
		setClass(lastFilter,"");
		if (lastFilterType!="all"){
			setClass(eval(lastFilterType+"DDL"),"");
		}else{
			setClass("filterBox","");
		}
	}
	if (lastPrevSibling!="")setClass(lastPrevSibling,"");

	lastFilterType = filterType;
	lastFilter = id;
	o = $(id);
	if (o){
		oPrev = o.previousSibling;
		oPrev.className="side";
		lastPrevSibling=oPrev.id;
	}

	setClass(lastFilter,"sel");
	if (lastFilterType!="all"){
		setClass(eval(lastFilterType+"DDL"),"sel");
	}else{
		setClass("filterBox","closed");
	}
}

function callFilter(queryName){
	if (lastFilterType!=""){
		self.location = "/" + queryName+".aspx?" + lastFilterType + "="+ getSelValue(eval(lastFilterType+"DDL"));
	}
}

function filterFOI(setFilter){

    if (!$("chkIT") || !$("chkWA"))return;

    if (setFilter){
		setFilter = setFilter.toUpperCase();
		$("chkIT").checked = (setFilter.indexOf("IT")>-1);
		$("chkWA").checked = (setFilter.indexOf("WA")>-1);
	}


    var isIT = $("chkIT").checked;
    var isMA = $("chkWA").checked;

    if (!isIT && !isMA){
        mode = 1;
    }else if (isIT && !isMA){
        mode = 2;
    }else if (!isIT && isMA){
        mode = 3;
    }else if (isIT && isMA){
        mode = 4;
    }

    if (typeof(FOIarr)!="undefined"){
        var itemsCount = FOIarr.length;
        var isHandled = 0;
        for (var i=0; i<itemsCount-1;i++){
			isHandled = 0;
           if (mode==1){
				if (FOIarr[i][1]==1 || FOIarr[i][2]==1){
					replaceClass ("item"+FOIarr[i][0], "block","off");
					isHandled = 1;
				}
           }else if (mode==2){
				if (FOIarr[i][1]==0 && FOIarr[i][2]==1){
					replaceClass ("item"+FOIarr[i][0], "block","off");
					isHandled = 1;
				}
			}else if (mode==3){
				if (FOIarr[i][1]==1 && FOIarr[i][2]==0){
					replaceClass ("item"+FOIarr[i][0], "block","off");
					isHandled = 1;
				}
           }else if (mode==4){
				//isHandled = 1;
			}

            if (isHandled==0){
				replaceClass("item"+FOIarr[i][0], "off","block");
			}
        }
    }
}

var anchors=[];
var targets=[];
function fixAnchors() {
	var siteHost = location.host;
	var aTags=document.getElementsByTagName("a");
	for (var i=0;i<aTags.length; i++){
		a = aTags[i];
		if ( /#/.test(a.href)){
			if (a.href.toLowerCase().indexOf("http://"+siteHost)==0){
				anchors.push (a);
			}
		}
		if (a.name)targets[(isIE)?(a.name):(escape(a.name))] = a;
	}
	for (var i=0;i<anchors.length;i++){
		DOM.Event("click",function(e){scrollToAnchor(e)},anchors[i]);


	}
}


function scrollToAnchor(e){
	var o = (e.srcElement)?(e.srcElement):(e.target);

	if(!o)return;
	var href = o.href;
	var anchorName = href.substr(href.indexOf("#")+1);

	if (targets[anchorName]){
		aTop = getOffsetTop(targets[anchorName]);
		document.documentElement.scrollTop=aTop;
		targets[anchorName].focus();

		if (e.preventDefault) {
		  e.preventDefault();
		  e.stopPropagation();
		} else {
		  e.returnValue = false;
		  e.cancelBubble = true;
		}
	}
}

function credit(e){
	e.outerHTML='<a href="http://www.mantis.co.il/" target="_blank" class="' + e.className + '" >' + e.innerHTML + '</a>';
}

function makeLink(e,href){
	var txt = e.innerHTML;
	var cssClass = e.className;
	if (cssClass=="anchor")cssClass="";
	if (href != "" && txt != "")
	{
		link = '<a target="_blank" href="' + href + '" class="'+ cssClass +'" >' + txt + '</a>';
	}
	else if (href == "" && txt != "")
	{
		link = '<a class="'+ cssClass +'"  >' + txt + '</a>';
	}
	else if (href != "" && txt == "")
	{
		link = '<a target="_blank" href="' + href + '" class="'+ cssClass +'" >' + href + '</a>';
	}
	
	
	e.outerHTML = link;		
	
}

function setUserCountry(country){
    //alert(country);
    if($('country')){
        selectValue('country', country);
        //if country was not found set select to choose
        if($('country').value.toLowerCase() != country.toLowerCase() || country == "")
            selectIndex('country',0);
    }
}