//if (window.captureEvents){
//window.captureEvents(Event.KEYPRESS);
//window.onkeypress = function (e) { if(e.which == 13) { return false; } } 
//} 

var menu = new menu();
menu.build();

 


//REMOVES IE BLINKING ON BACKGROUNDS
var nav = window.navigator.userAgent.toString().toLowerCase();
var isMSIE = nav.indexOf("msie") > -1 && nav.indexOf("opera") == -1;
if (isMSIE){
document.execCommand("BackgroundImageCache",false,true);
}

var split_domain = document.domain.split(".");
var cookie_domain = split_domain[0]+"."+split_domain[1]+"."+split_domain[2];

function setCookie(c_name,value,expiredays){
  var exdate=new Date()
  exdate.setDate(exdate.getDate()+expiredays)
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/; domain="+cookie_domain;
}  
function deleteCookie (c_name) {
  if (getCookie(c_name)) {
     document.cookie=c_name+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain="+cookie_domain;
  }
}
function getCookie(c_name){
  if (document.cookie.length>0)  {
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)    { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end))
      } 
    }
  return ""
}

function add_js_file(f) { 
  return '/'+document.getElementById("cache_date").value+f;
}
	
/*
	Fade out an element.
*/
function fade_out( elem, callback  ) {

	if ( typeof( elem ) != "object" ) elem = document.getElementById( elem );
	elem.style.display = "block";

	// create the animation
	var aniObj = new YAHOO.util.Anim(
		elem,
		{ opacity: {from: 1, to: 0 } },
		0.4,
		YAHOO.util.Easing.easeBoth
	)

	if ( typeof( callback ) != "undefined" ) aniObj.onComplete.subscribe( callback );
	aniObj.animate(); // execute the animation
}

function getTime() {
	var now = new Date();
	return now.getTime();
}

function getURLVar(urlVarName) {
  var urlHalves = String(document.location).split('?');
  var urlVarValue = '';
  if(urlHalves[1]){
  var urlVars = urlHalves[1].split('&');
    for(i=0; i<=(urlVars.length); i++){
      if(urlVars[i]){
      var urlVarPair = urlVars[i].split('=');
        if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
        	if ( urlVarPair[1] ) urlVarValue = urlVarPair[1];
			else urlVarValue = true;
        }
      }
    }
  }
  return urlVarValue;   
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

		
function urldecode( str ) {
    var histogram = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"] = '%27'; histogram['('] = '%28'; histogram[')'] = '%29'; histogram['*'] = '%2A'; histogram['~'] = '%7E'; histogram['!'] = '%21';histogram['%20'] = '+'; histogram['\u00DC'] = '%DC'; histogram['\u00FC'] = '%FC'; histogram['\u00C4'] = '%D4'; histogram['\u00E4'] = '%E4'; histogram['\u00D6'] = '%D6'; histogram['\u00F6'] = '%F6'; histogram['\u00DF'] = '%DF'; histogram['\u20AC'] = '%80'; histogram['\u0081'] = '%81'; histogram['\u201A'] = '%82'; histogram['\u0192'] = '%83'; histogram['\u201E'] = '%84'; histogram['\u2026'] = '%85'; histogram['\u2020'] = '%86'; histogram['\u2021'] = '%87'; histogram['\u02C6'] = '%88'; histogram['\u2030'] = '%89'; histogram['\u0160'] = '%8A'; histogram['\u2039'] = '%8B'; histogram['\u0152'] = '%8C'; histogram['\u008D'] = '%8D'; histogram['\u017D'] = '%8E'; histogram['\u008F'] = '%8F'; histogram['\u0090'] = '%90'; histogram['\u2018'] = '%91'; histogram['\u2019'] = '%92'; histogram['\u201C'] = '%93'; histogram['\u201D'] = '%94'; histogram['\u2022'] = '%95'; histogram['\u2013'] = '%96'; histogram['\u2014'] = '%97'; histogram['\u02DC'] = '%98'; histogram['\u2122'] = '%99'; histogram['\u0161'] = '%9A'; histogram['\u203A'] = '%9B'; histogram['\u0153'] = '%9C'; histogram['\u009D'] = '%9D'; histogram['\u017E'] = '%9E'; histogram['\u0178'] = '%9F';

    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    

    ret = decodeURIComponent(ret);

    return ret;
}


function strpos (haystack, needle, offset) {
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
}

function in_array( js_array, string ) {
	for ( i in js_array ) {
		if ( js_array[i] == string ) return true;
	}
	return false;
}


function disableEnterKey(evt)
{
	var evt = (evt) ? evt : ((event) ? event : null); 
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
	if ((evt.keyCode == 13) && (node.type=="text")) {
		if (evt.preventDefault) evt.preventDefault();
		if (evt.stopPropagation) evt.stopPropagation();
		return false;
	} else {
	return true;
	}
}

 
 
/*** Temporary text filler function. Remove when deploying template. Good for testing ***/
var gibberish=["This is just some filler text", "Welcome to Bragadoo.com", "Demo content nothing to read here"]
function filltext(words){
for (var i=0; i<words; i++)
document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
