var url = document.location.href;

// Switches the language of the page by changing the URL
function switchLanguage() {
	
	var str = document.location.href;

	if(str.indexOf("/en/") >= 0){
		url = url.replace("/en/", "/fr/");
		document.location = url;
	}
	
	else if(str.indexOf("lang=en") >= 0){
		url = url.replace("lang=en", "lang=fr");
		document.location = url;
	}
	
	else if(str.indexOf("/fr/") >= 0){
		url = url.replace("/fr/", "/en/");
		document.location = url;
	}
	
	else if(str.indexOf("lang=fr") >= 0){
		url = url.replace("lang=fr", "lang=en");
		document.location = url;
	}
	
}

// Used for entering and leaving search textbox so the user doesn't have to clear the 'Search' text
function Search_Enter(searchTextbox) {

	if ( searchTextbox.value.toLowerCase() == 'recherche' || searchTextbox.value.toLowerCase() == 'search' )
		searchTextbox.value = '';

}

function Search_Leave(searchTextbox) {

	var url = document.location.href;

	if( url.indexOf("/en/") >= 0 && searchTextbox.value.trim() == '' )
		searchTextbox.value = 'Search';
	
	if( url.indexOf("/fr/") >= 0 && searchTextbox.value.trim() == '' )
		searchTextbox.value = 'Recherche';
	

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  var selURL = selObj.options[selObj.selectedIndex].value;
  
  if (selURL == '')
  {
	// nothing need to do
  }
  
  else if (selURL.indexOf('~') == 0)
  {
  	window.open(selURL.substr(1, selURL.length), "_blank");
  }
  
  else
  {
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  }
  
  if (restore) selObj.selectedIndex=0;
  
}

function checkPageSecurity() {

    var currentUrl = document.location.href;
    var secured = currentUrl.indexOf("https://") == 0;
    
    if (typeof(_page_need_secure_) != 'undefined' && _page_need_secure_) {

        if (!secured)
            document.location.href = "https://" + currentUrl.substr(7);

    } 
    
    else {

        if (secured)
            document.location.href = "http://" + currentUrl.substr(8);

    }
    
}

// check security before any other scripts
var oldonload = window.onload;

if (typeof window.onload != 'function') {
    //window.onload = checkPageSecurity;
} 

else {

	window.onload = function() {
		//checkPageSecurity();
		//oldonload();
	};
	
}
