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;
	}
}

/*
Elad Kaspin 9.12.07 - Replaced this function with the following one, for 2 reasons -
1. true || ... else - will neve happen.
2. Searches from a languaged site home page does not return the language's prefix.

function validateSearch(){

	if (document.getElementById('q')){
		if (true || document.getElementById('q').value.length>1 ){

			var sitePrefix = top.location.pathname.substring (0,top.location.pathname.indexOf("/"));

			top.location.href = sitePrefix + 'search.aspx?q='+escape(document.getElementById('q').value);
			return true;
		}else{
			alert ("Search term must be at least 2 characters ");
			document.getElementById('q').focus();
			return false;
		}
	}
}
*/
function validateSearch()
{
    var txtSearch = $("q");

	if (txtSearch)
	{
		var sitePrefix = document.getElementsByTagName("BASE")[0].href;
		top.location.href = sitePrefix + "search.aspx?q=" + encodeURIComponent(txtSearch.value);
		return true;
	}

	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(el,str1,str2){
	if (!el)return;

	if (el){

		var re = new RegExp(str1,"gi");
		if (typeof(el.className)!="undefined"){
			el.className = el.className.replace (re, str2);
		}else{
			el.className = str2;
		}
	}
}
function replaceClass2(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==val || val==-1){
				o[i].selected = true;
				if (val!=-1)break;
			}
		}
	}
}

function hover(el,isOver){
	if (!el)return;
	el.src = el.src.toLowerCase().replace(
		(isOver)?(".gif"):("_on.gif") ,
		(isOver)?("_on.gif"):(".gif")
		);
}


function hoverById(id,isOver){
	hover ($(id), isOver);
}



var lastPrefix = "";
var lastId = 0;
function showItem(prefix,id){

	if (lastId>0 && lastId!=id ){
		replaceClass($(lastPrefix+lastId),"block","off");
		replaceClass($("nav"+lastId),"sel","reg")
	}

	if (lastId!=id){
		lastPrefix = prefix;
		lastId = id;
		replaceClass($(lastPrefix+lastId),"off","block");
		replaceClass($("nav"+lastId),"reg","sel")
	}else{
		if (prefix!="photos"){
			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 = document.getElementById(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"));
	}
}



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 tellFriend(e){
	e.href = "mailto:?subject=Read this article from UltraShape.com: "  + "&body="+location.href;
}

function bookmark(){
	if (window.sidebar) {
		window.sidebar.addPanel("Ultrashape.com - " + document.title, location.href,"");
	} else if( window.external ) {
		external.AddFavorite(location.href, "Ultrashape.com - " + document.title );
	}
}



function onContent(f){//(C)webreflection.blogspot.com
var a=onContent,b=navigator.userAgent,d=document,w=window,c="onContent",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
a[c]=(function(o){return function(){a[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(a[c]);
if(d[e])d[e]("DOMContentLoaded",a[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))(function(){/loaded|complete/.test(d[r])?a[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};
/*ofir
onContent(function(){
	if (typeof(sitePathFromRoot)!="undefined"){
		var s = document.forms[0].action.replace(sitePathFromRoot,"/");

	    if ( typeof(document.forms[0].formId)=="undefined"){


	    document.forms[0].action = s.indexOf("http://")==-1  ? "/" + s : s ;
	    }
	}

});

*/

onContent(function()
{
	var action = document.forms[0].action;
	var httpPos = action.lastIndexOf("http:");

	if (httpPos>-1)
	{
		// fix prefix slash caused by forms
		document.forms[0].action = action.substring(httpPos);

	}

	// remove the lang psaudo folder
	if (typeof(sitePathFromRoot)!="undefined")
	{
		var s = document.forms[0].action.replace(sitePathFromRoot,"/");
		document.forms[0].action = s;
	}
});

function toggle(id, display)
{
    if (id && id != "")
    {
        var el = $(id);

        if (el &&
			el.style.display &&
			el.style.display != display)
        {
            el.style.display = display;
        }
    }
}

function show(id)
{
	toggle(id, "block");
}

function hide(id)
{
	toggle(id, "none");
}

var toggleTimeout;

function syncToggle(hiddenID, elementIDs)
{
	if (!elementIDs) return;
	var currElement;

	for (var i = 0; i < elementIDs.length; i++)
	{
		currElement = $(elementIDs[i]);

		DOM.Event("mouseover", function() {
			clearTimeout(toggleTimeout);
			show(hiddenID);
			}, currElement);

		DOM.Event("mouseout", function() {
			toggleTimeout = setTimeout(function() { hide(hiddenID); }, 200);
			}, currElement);
	}
}