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_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7")!=-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 getFlashStr (url,id,w,h,bgcolor,wmode,flashVars){
	if (isIE){
		bgcolor=bgcolor ? '<param name="bgColor" value="'+bgcolor+'" />' : "";
		wmode=wmode ? '<param name="wmode" value="'+wmode+'" />' : "";
		flashVars=flashVars? '<param name="FlashVars" value="'+flashVars+'">':'';
		str = '<object type="application/x-shockwave-flash" \
			classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" \
			codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" \
			name="' + id + '" id="' + id + '" \
			style="width:'+w+'px;height:'+h+'px;">\
			<param name="movie" value="'+url+'" />\
			'+flashVars+'\
			'+bgcolor+'\
			'+wmode+'\
			</object>';
	}else{
		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" ' +
			' FlashVars="' + flashVars + '" ' +
			' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ></embed>';
	}
	//alert (str);
	return str;
}
function addFlashInside (containerId, url,id,w,h,bgcolor,wmode,flashVars){
	var str = getFlashStr(url,id,w,h,bgcolor,wmode,flashVars);
	setHtml(containerId,str,false,false);

}


function addFlash(url,id,w,h,bgcolor, wmode,flashVars){
	var str = getFlashStr(url,id,w,h,bgcolor, wmode,flashVars);
	document.write (str);
	window[id] = $(id);
	if(id=='oStory') setTimeout(function(){if($('oStory').rollOutAll)$('mainFlash').onmouseout=function(){$('oStory').rollOutAll();}},5000);
}

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 (document.getElementById('q')){
		if (document.getElementById('q').value.length>1 ){
			top.location.href = 'search.aspx?q='+encodeURI(document.getElementById('q').value);
			return true;
		}else{
			alert ("Search term must be at least 2 characters ");
			document.getElementById('q').focus();
			return false;
		}
	}
}

function setValue(id,val){
	if (id=="")return;
	var o = document.getElementById(id);
	if (o)o.value = val;
}

function setHtml(id,html,toAppend,hideIfEmpty){
	if (id=="")return;
	var o = document.getElementById(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 = document.getElementById(id);
	if (o)o.className = val;
}
function replaceClass(id,str1,str2){
	if (id=="")return;
	var o = document.getElementById(id);
	if (o)o.className = o.className.replace (str1,str2);

}

function getParentId(id){
	var str = "";

	if (id=="")return;

	var o = document.getElementById(id);
	if (o)o=o.parentElement;

	if (o)str=o.id;

	return str;
}

function getSelValue(id){
	var retVal = "";
	if (id=="")return;
	var o = document.getElementById(id);
	if (o)retVal = o.value;
	return retVal;
}

function getIndex(id){
	var index = 0;
	if (id=="")return;
	var o = document.getElementById(id);
	if (o)index=o.selectedIndex ;
	return index;
}

function selectIndex(id, index){
	if (id=="")return;
	var o = document.getElementById(id);
	if (o)o.selectedIndex = index;
}
function selectValue(id, val){
	if (id=="")return;
	var o = document.getElementById(id);
	if (o){

		for (i=0;i<o.length; i++){
			if (val==-1 || o[i].value.toLowerCase()==val.toString().toLowerCase()){
				o[i].selected = true;
				if (val!=-1)break;
			}

		}
	}
}

var lastPrefix = "";
var lastId = 0;
function showItem(prefix,id){

	if (lastId>0){
		replaceClass(lastPrefix+lastId,"block","off");
		replaceClass("nav"+lastId,"sel","reg")
	}

	if (lastId!=id || prefix=="center" ){
		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 = 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"));
	}
}

function addVideo(containerId , fileName,w,h){
	if (fileName=="")return;
	var str = '<object classid=CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95 ' +
			'  width='+w+' height='+h+' type=application/x-oleobject > ' +
			' <param name="AudioStream" VALUE="1"> ' +
			' <param name="AutoSize" VALUE="0"> ' +
			' <param name="AutoStart" VALUE="True"> ' +
			' <param name="AnimationAtStart" VALUE="-1"> ' +
			' <param name="AllowScan" VALUE="-1"> ' +
			' <param name="AllowChangeDisplaySize" VALUE="1"> ' +
			' <param name="BufferingTime" VALUE="5"> ' +
			' <param name="ClickToPlay" VALUE="-1"> ' +
			' <param name="CursorType" VALUE="0"> ' +
			' <param name="CurrentPosition" VALUE="-1"> ' +
			' <param name="DisplayBackColor" VALUE="0"> ' +
			' <param name="DisplayForeColor" VALUE="16777215"> ' +
			' <param name="DisplayMode" VALUE="0"> ' +
			' <param name="DisplaySize" VALUE="0"> ' +
			' <param name="Enabled" VALUE="1"> ' +
			' <param name="EnableFullScreenControls" VALUE="0"> ' +
			' <param name="EnableTracker" VALUE="-1"> ' +
			' <param name="Filename" VALUE="/'+fileName+'"> ' +
			' <param name="PlayCount" VALUE="11"> ' +
			' <param name="SendErrorEvents" VALUE="True"> ' +
			' <param name="SendKeyboardEvents" VALUE="0"> ' +
			' <param name="ShowCaptioning" VALUE="0"> ' +
			' <param name="ShowControls" VALUE="-1"> ' +
			' <param name="ShowAudioControls" VALUE="-1"> ' +
			' <param name="ShowDisplay" VALUE="0"> ' +
			' <param name="ShowGotoBar" VALUE="0"> ' +
			' <param name="ShowPositionControls" VALUE="-1"> ' +
			' <param name="ShowStatusBar" VALUE="0"> ' +
			' <param name="ShowTracker" VALUE="-1">       ' +
			' <param name="WindowlessVideo" VALUE="-1">    ' +
			'</object>';

			setHtml(containerId,str,false,false);





		}


function getFlash(movieName)
{
  if (window.document[movieName]) return window.document[movieName];
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; 
  }
  else return document.getElementById(movieName);
}

if (!document.getElementsByClassName) document.getElementsByClassName = function(className, parentElement) {
  if (typeof parentElement == 'string'){
    parentElement = document.getElementById(parentElement);
  } else if (typeof parentElement != 'object' ||
             typeof parentElement.tagName != 'string'){
    parentElement = document.body;
  }
  var children = parentElement.getElementsByTagName('*');
  var re = new RegExp('\\b' + className + '\\b');
  var el, elements = [];
  var i = 0;
  while ( (el = children[i++]) ){
    if ( el.className && re.test(el.className)){
      elements.push(el);
    }
  }
  return elements;
} 

function changeContent(story)
{
	story = story.replace("/","");
	var div = $("hpStory");
	var divStory = $(story);
	if(div && divStory)
	{
		var subObjStories = document.getElementsByClassName("item",div);
		if(subObjStories && subObjStories.length > 0) for(var c=0; c< subObjStories.length; c++) subObjStories[c].style.display="none";
		setOpacity(div,0);
		divStory.style.display="block";
		transContent(0,10,1);
	}
}

function transContent(currentVal, endVal, increment ) {
	var subObj = $("hpStory");
	if (subObj){
		// If equal, we are done. No change.
		if (currentVal == endVal) return;
		// If less, that means we are fading in.
		if (currentVal < endVal){
			if(currentVal + increment >= endVal)
				setOpacity(subObj, endVal);
			else
			{
				currentVal = currentVal + increment;
				setOpacity(subObj, currentVal);
				setTimeout ("transContent("+currentVal+","+endVal+","+increment+")" , 50);
			}
		// This means it is greater than endVal, so we are fading out.
		}else{
			if(currentVal - increment <= endVal)
			{
				currentVal = endVal;
				setOpacity(subObj, currentVal);
				subObjStories = document.getElementsByClassName("item",subObj);
				if(subObjStories && subObjStories.length > 0) for(var c=0; c< subObjStories.length; c++) subObjStories[c].style.display="none";
			}else{
				currentVal = currentVal - increment;
				setOpacity(subObj, currentVal);
				setTimeout ("transContent("+currentVal+","+endVal+","+increment+")" , 20);
			}
		}
	}
}

function setOpacity(element, value) {
	element.style.opacity = value /10;
	element.style.filter = 'alpha(opacity='+value*10+')';
}

function closeContent()
{
	var div = $("hpStory");
	//if(div)	transContent(10, 0, 1);
	if(div) setOpacity(div, 0);
}