//disable enter button
function disableEnter(e) {
	var pK = document.all? window.event.keyCode:e.which;
	return pK != 13;
}   
function captureEnter(e,frm) {		
	document.onkeypress = disableEnter; //disable enter for all browsers
	if (NS4) document.captureEvents(Event.KEYPRESS); //disable enter for NS4
	
	//netscape   
	if(NS6 || NS4) {    
		fireSearch(e.which,frm);
		
		
	} else {
		fireSearch(event.keyCode,frm);
	}
}
// fire when keycode == 13 ('enter' button)
function fireSearch(key,frm) {
	if(key==13) frm.hlinkSearch.click();		
}	
function googleSearch() {
//alert('hi1');
var searchTxt = document.getElementById('txtsearch1').value;
var searchType = "bet";
searchTxt=escape(searchTxt); 	
window.location.href = "http://www.bet.com/WebApplications/BetSearch/Search.aspx?searchQuery="+searchTxt+"&searchType="+searchType+"&c=all";
}

function isValidEmail(email) {

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	return reg.test(email);
	
}

function wordWrap(){
/******
* wordWrap to firefox for big words
* Creative Commons license * Version: 1.0 - 26/04/2006
* Autor: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
* Uso: call the function on onload of body element.
* put the class "word-wrap" on elements to wordwrap
*******/
    /*var larg_total,larg_carac,quant_quebra,pos_quebra;
    var elementos,quem, caracs, texto, display_orig;
    //alert('entered');
    elementos = document.getElementsByTagName("*")
    
    for(var i=0; i<elementos.length;i++){
        if(elementos[i].className=="word-wrap"){
            quem = elementos[i];
            
            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
            texto = String(quem.innerHTML)
            
            quem.innerHTML = " "
            
            display_orig = quem.style.display;
            quem.style.display="block";
            larg_oficial = quem.offsetWidth;
            //alert("oficial: " + larg_oficial)
            //alert("display " + quem.style.display)
            if(!document.all) quem.style.display="table";
            //alert("display " + quem.style.display)
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;
            //alert("total: " + larg_total)
            
            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g," ")
            larg_carac = larg_total / caracs
            if(larg_total>larg_oficial){
                quant_quebra = parseInt(larg_oficial/larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while(pos_quebra<=caracs){
                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
                    pos_quebra = pos_quebra + quant_quebra;
                }
            }else{
                quem.innerHTML = texto;
            }//end if do larg_total>larg_oficial
            quem.style.display = display_orig;
        }//end if do word wrap
    }//end for loop dos elementos*/
}

// This object implements a simple dropdown menu
MenuControl = function(containerID){
	// private init stuff here
	
	var baseID = 'subMenu';
	var currentID = 0;				

	return {
		
		getNextID : function() {
		
			++currentID;
			return '_i' + currentID;
			
		},
		
		//initializes the menu by traversing the markup for known IDs and structure and registers
		//all necessary events
		initializeMenu : function() {					
			
			var menuPos = jQuery('.utilityNavigation').position();
			var menuHeight = jQuery('.utilityNavigation').height();
			var self = this;
			
			//for each menu that has children
			jQuery('.utilityNavigation > dd > ul > li.hasChildren').each( function(index, item){
			
				//get the submenu
				var subMenu = jQuery(item).find('dl').get();
				
				if(subMenu != null) {
				
					var subMenuPos = jQuery(item).position();
					var subMenuHeight = jQuery(item).height();
					
					//var left = subMenuPos.left - menuPos.left;
					//var top = subMenuPos.top + subMenuHeight - menuPos.top;
					var left = subMenuPos.left;
					var top = menuHeight;
					
					var newID = self.getNextID();
					var html = "<div id=\"" + newID + "\" class=\"utilDropMenu\" style=\"left:" + left + "px;top:" + top + "px;\">" + item.innerHTML + "</div>";
					
					//inject the submenu markup into the navigation's parent
					jQuery('#' + containerID).append(html);
					
					var newSubMenu = jQuery('#' + newID);
					
					//create the parent child relationship between the submenus
					item._subMenu = newSubMenu;
					newSubMenu._parent = item;
					
					//allows an item to access the control it was created by
					item._menuControl = this;
					
					//register for over events
					jQuery(item).hover( function(){ self.showSubMenu(item); }, function(){ self.hideSubMenu(item); } );
					jQuery(newSubMenu).hover( function(){ self.showSubMenu(item); }, function(){ self.hideSubMenu(item); } );
				
				}
			
			});
		
		},
		
		hideSubMenu : function(item) {
		
			if(item._subMenu == null){ return; }

			if(this._menuExpanded != item){ return; }

			item._isCollapsing = true;

			if(this._hideSubMenuTimeout != null){

						//clearTimeout(this._hideSubMenuTimeout);

						//this._hideSubMenuTimeout = null;

			}

			//this._hideSubMenuTimeout = setTimeout("menu.hideSubMenuNow();", 50);
			
			this.hideSubMenuNow();
		
		},
		
		hideSubMenuNow : function() {
			
			if(this._menuExpanded != null && this._menuExpanded._isCollapsing){

				$(this._menuExpanded).removeClass("expanded");
				$(this._menuExpanded._subMenu).removeClass("expanded");
				this._menuExpanded._isCollapsing = false;
				this._menuExpanded = null;
			
			}
		
		},
		
		showSubMenu : function(item) {					
			
			if(item._subMenu == null){ return; }

			if(this._menuExpanded != null && this._menuExpanded != item){
						this.hideSubMenuNow();
			}

			this._menuExpanded = item;

			item._isCollapsing = false;

			$(item).addClass("expanded");

			$(item._subMenu).addClass("expanded");
					
		}
		
	};
	
};