// Misc Functions
// RD2011, Burchia Rolf


// Shortcut ID
function $(id) { 
    return document.getElementById(id); 
} 
function $$(id) { 
    return document.getElementsByName(id); 
} 
// Dummy-Function
function bu_f_dummyfunction()
{
}
// Externer Link
function bu_f_externallink(Adresse) {
  bu_NewBrowserWindow = window.open(Adresse, "_blank");
  bu_NewBrowserWindow.focus();
}
// Interner Link
function bu_f_link(Adresse) {
  
    window.location = Adresse;
}
// Bitmap Over
function bu_f_bitmap_over(id)
{
	bu_g_overout_file = id.src;	
    if(bu_g_overout_file.search(bu_g_currentMenuSelectionString)==-1) id.src = id.src.substr(0,id.src.length-4)+"_over.png";
}
// Bitmap Out
function bu_f_bitmap_out(id)
{
	if(bu_g_overout_file.search(bu_g_currentMenuSelectionString)==-1) id.src = bu_g_overout_file;
}
// Link Over
function bu_f_link_over(id)
{
	bu_g_overout_color = id.style.color;
	id.style.color = "RGB(204,51,0)";
}
// Link Out
function bu_f_link_out(id)
{
	id.style.color = bu_g_overout_color;
}
// Link Over Blue
function bu_f_link_over_blue(id)
{
	bu_g_overout_color = id.style.color;
	id.style.color = "RGB(46,92,184)";
}
// Link Out Blue
function bu_f_link_out_blue(id)
{
	id.style.color = bu_g_overout_color;
}


// Button Over
function bu_f_button_over(id)
{
	bu_g_overout_color = id.style.color;
	id.style.color = "RGB(204,0,0)";
}
// Link Out
function bu_f_button_out(id)
{
	id.style.color = bu_g_overout_color;
}
// Widget on/off
function bu_f_widget_onoff(id)
{
	if($(id).style.display!="none")
    {
    		$(id).style.display = "none";
    }
    else
    {
    		$(id).style.display = "block";
    }	
}

// Language Setting
function bu_f_lang_get()
{
	if(document.cookie)
	{
		bu_g_lang = document.cookie.substring(5, document.cookie.length);
	}
};
function bu_f_lang_set(langcode)
{
	bu_g_lang = langcode;
	var cookiedatum = new Date();
    cookiedatum.setFullYear(cookiedatum.getFullYear()+1);
    document.cookie = "lang="+bu_g_lang+"; expires="+cookiedatum.toGMTString();
    location.reload();
};




// Get Scrollpos
function bu_f_pageYOffset()
{
if(!window.pageYOffset)
    {
 		 var ypos=document.documentElement.scrollTop;
    }
    else
    {
    	 var ypos = window.pageYOffset;
    }    
return(ypos);
}

// Get Scrollpos
function bu_f_pageXwidth()
{
if(!window.innerWidth)
    {
 		var xpos=document.documentElement.clientWidth;
    }
    else
    {
    	var xpos = window.innerWidth;
    }    
return(xpos);
}

// Get Scrollpos
function bu_f_pageYheight()
{
if(!window.innerHeight)
    {
 		var xpos=document.documentElement.clientHeight;
    }
    else
    {
    	var xpos = window.innerHeight;
    }    
return(xpos);
}

// Check if the footer should be shut off/on
function bu_f_checkwindowfooter() {
	if(bu_f_pageYheight()<650) {
		$("w_footer").style.display = "none";
		$("w_overlay").style.top = "5px";
	} else
	{
		$("w_footer").style.display = "block";
		$("w_overlay").style.top = "225px";
	}
}


// Cursor Position and Mouse Events


// Load dynamic content
function bu_f_getContent(sel)
{
	var myAjax = new Ajax();
  	myAjax.url="main.php";
    myAjax.data="select="+sel;
    myAjax.onSuccess=bu_f_getContent_successHandler;
    myAjax.doRequest();
}
function bu_f_getContent_successHandler(txt,xml)
{
	var txtpart = txt.split("BU_DL0");
    if(txtpart!="")
    {
    var codestring = txtpart[1].replace("/\n/","");
    eval(codestring);
    }
}

// Check for changed hash anchor 
function bu_f_checkAnchor(){   
    if(bu_g_currentAnchor != window.location.hash) {  
        bu_g_currentAnchor = window.location.hash;  
        if(bu_g_currentAnchor!="#inside")
        {      
        	if(!bu_g_currentAnchor) 
        	{ 
            	window.location.hash = "#news";
       	}
        	else  
        	{    
        		var splits = bu_g_currentAnchor.substring(1).split('&');   
    			var selector = splits[0];
            	var section = splits[0]+".php"; 
            	delete splits[0];  
            	var params = splits.join('&');
            	var query = section + params;
                  if(bu_g_menustrings.search(bu_g_currentMenuSelectionString)!=-1) $("w_nav_bitmap_"+bu_g_currentMenuSelectionString).src = "img/mila_menubutton_"+bu_g_currentMenuSelectionString+".png";
	              bu_g_currentMenuSelectionString = selector;
                  if($("w_nav_bitmap_"+selector))
            	{             
            		$("w_nav_bitmap_"+bu_g_currentMenuSelectionString).src = "img/mila_menubutton_"+bu_g_currentMenuSelectionString+"_selected.png";
            	}           
        	}
        	bu_f_getContent(query);
        }
        else
        {
        	if($("w_nav_bitmap_"+bu_g_currentMenuSelectionString))
            {
            $("w_nav_bitmap_"+bu_g_currentMenuSelectionString).src = "img/mila_menubutton_"+bu_g_currentMenuSelectionString+".png";
        	};
            bu_g_currentMenuSelectionString = "inside";
            $("w_list").style.display = "none";
        }
    }  
}  

// Switch for Printer Mode
function bu_f_printer_on() {
	var adresse = window.location;
	var search = window.location.search;
	//if(search=="") { adresse = "http://test.rheintalduathlon.ch/index.php?select=news_aktuell.php&menuselect=1"; };
	if(search=="") { adresse = "http://www.rheintalduathlon.ch/index.php?select=news_aktuell.php&menuselect=1"; };
	bu_NewBrowserWindow = window.open(adresse+"&print=1", "_blank");
    bu_NewBrowserWindow.focus();
}

