﻿/**************************************************************************************************
************************************** BaUAE SCRIPTS *******************************************/

//Load TopMenu with relevant Picture
function loadMenus()
{
    AdjustColumnsHeight();  
    resizeWin(false);

    var strReturn = "";
    var strHref = window.location.href;
    var frameMenu = window.document.getElementById('TopFrame');

    if ( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase() ;
        strReturn = strQueryString;
        frameMenu.src = "/UserControls/FlashMenu/PagesContent/index.aspx" + strReturn ; 
        return false;
    }
    else
    {
        frameMenu.src = "/UserControls/FlashMenu/PagesContent/index.aspx";
    }    
}

/******************************************************************************************************************/

function hideIframe()
	{
	var frameMenu = window.document.getElementById('TopFrame');
	frameMenu .style.display="none";
	}
	
function ShowIframe()
	{
	var frameMenu = window.document.getElementById('TopFrame');
	frameMenu .style.display="block";
	}
	
/*******************************************************************************************************************/


//Handle on resize events
window.onresize= resizeWin;
function resizeWin( isHiddenActivated )
{
    windowWidth= GetWidth();
    //windowHeight = GetHeight();
    var frameMenu = window.document.getElementById('TopFrame');
    var containerCol = window.document.getElementById('containerCol');
    var headerTop = window.document.getElementById('headerTop');
     var footer = window.document.getElementById('footerCol');

    if (windowWidth < 997)
    {

    	showLayer("leftCol", false);
    	showLayer("rightCol", false);
    	
    	footer .style.margin= "0 auto"
    	headerTop.style.margin = "0 auto";
    	headerTop.style.padding = "0 10px";
    	frameMenu.style.width = "782px";
    	frameMenu.style.margin = "0 0 0 3px";
    	containerCol.style.padding = "0 10px";
    	isHiddenActivated=true;
    }
    else
    {
        showLayer("leftCol", true);
    	showLayer("rightCol", true);
    	footer .style.margin= "0 auto";
    	
    	footer.style.width = "789px";
    	headerTop.style.margin = "0 auto";
    	frameMenu.style.width = "100%";
    	frameMenu.style.margin = "0";
    	if(isHiddenActivated)
    	   	containerCol.style.padding = "0 118px 0 117px";
    }
}

function AdjustColumnsHeight()
{   
    // get a reference to the 4 DIVS that make up the columns
    
    var centerCol = window.document.getElementById('centerCol');
    var leftCol = window.document.getElementById('leftCol');
    var rightCol = window.document.getElementById('rightCol');
    var centerRightCol = window.document.getElementById('centerColRightMenu');
    //var containerCol= window.document.getElementById('containerCol');

    
    // calculate the max height
    //var hcontainerCol = containerCol.offsetHeight;
    var hCenterCol = centerCol.offsetHeight;
    var hLeftCol = leftCol.offsetHeight;
    var hRightCol = rightCol.offsetHeight;                        
    var hCenterRightCol = centerRightCol.offsetHeight;
    
    //get the max height of the 4 cols
    var maxHeight = Math.max(hCenterCol, Math.max(Math.max(hLeftCol, hRightCol)));
    // set the height of all 4 DIVS to the max height            
    centerCol.style.height = maxHeight + 'px';
    leftCol.style.height = maxHeight + 'px';
    rightCol.style.height = maxHeight + 'px'; 
    centerRightCol.style.height = maxHeight+ 'px';
    //containerCol.style.height = maxHeight+ 'px';

    // Show the footer
    window.document.getElementById('footerCol').style.visibility = 'inherit';       
}
        

/**************************************************************************************************
************************************** GENERAL SCRIPTS *******************************************/
//Show Hide layer (status -> false ==> Hide Layer)
function showLayer(layerID, status)
{
    var layer = window.document.getElementById(layerID);    
    layer.style.display = (status ? '' : 'none');
}

var obj;
function clearText(control)
 {
    obj = control;
    control.value = "";
 } 
 
 function checkEnter(e){ 
  if(e && e.which){ 
    e = e;
    characterCode = e.which;
  } else {
    e = event;
    characterCode = e.keyCode;
  }
 
  if(characterCode == 13){ 
    getURLParam();
    return false;
  } else {
    return true;
  }
}


//Set Background Image to "Cell" as imageName = Full Path and name of Backround Image
function turn_OnOff(cell, imgName) {    
    if (document.images != null) {
        cell.style.backgroundImage = "url('" + imgName + "')";
    }    
}

function changePage(theform, pageLocation )
{
     pageName = theform;
     site = pageLocation + "#" + pageName;                    
     document.location = site;
}

function linkToAnchor(anchorName) {
  self.location.hash = anchorName;
}

function PrintIFrame(frameName)
{
	try{
	    parent[frameName].focus();
	    parent[frameName].print();
	}
	catch(e){}
}

//navigate to drop down list value
function goThere(){
var theTarget = "_blank";
if(!document.getElementById("ddpSiteSelector").selectedIndex==""){
window.open(document.getElementById("ddpSiteSelector").options[document.getElementById("ddpSiteSelector").selectedIndex].value,theTarget,"");}}

//Preload Images
function MM_preloadImages()
{ 
    //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/************************************* Start Modal Popup Starter ********************************************************/
function Start(URL, NAME, WIDTH, HEIGHT) {
    timeout = 60; 
    windowprops = "left=50,top=10,width=" + WIDTH + ",height=" + HEIGHT;

    text = "<html><head><title></title></head><body topmargin='0' leftmargin='0' bgcolor='white'";

    if (timeout != 0)
        text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";

    text += "><center><img src='" + URL + "'>";
    text += "</center></body></html>";

    preview = window.open("", NAME, windowprops);
    preview.document.open();
    preview.document.write(text);
    preview.document.close();
}
/************************************* End** Modal Popup Starter ********************************************************/

/************************************* Start Toggler ********************************************************************/
function addEvent( obj, type, fn ) {
		if (obj.addEventListener) {
			obj.addEventListener( type, fn, false );
			EventCache.add(obj, type, fn);
		}
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
			obj.attachEvent( "on"+type, obj[type+fn] );
			EventCache.add(obj, type, fn);
		}
		else {
			obj["on"+type] = obj["e"+type+fn];
		}
	}
		
	var EventCache = function(){
		var listEvents = [];
		return {
			listEvents : listEvents,
			add : function(node, sEventName, fHandler){
				listEvents.push(arguments);
			},
			flush : function(){
				var i, item;
				for(i = listEvents.length - 1; i >= 0; i = i - 1){
					item = listEvents[i];
					if(item[0].removeEventListener){
						item[0].removeEventListener(item[1], item[2], item[3]);
					};
					if(item[1].substring(0, 2) != "on"){
						item[1] = "on" + item[1];
					};
					if(item[0].detachEvent){
						item[0].detachEvent(item[1], item[2]);
					};
					item[0][item[1]] = null;
				};
			}
		};
	}();
	
	function $() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}
		return elements;
	}
	
	function toggle() {
		for ( var i=0; i < arguments.length; i++ ) {
			$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : '' );
		}
	}
/************************************* End Toggler **********************************************************************/

/************************************* Start GetQueryString **********************************************************************/
function getQueryString(queryPrefix)
{
    var referrer = document.location.toString();			
			
	if (!referrer) {
        return false;
  }
  
  //var queryPrefix = "region=";
  var startPos = referrer.toLowerCase().indexOf(queryPrefix);
  if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
    return false;
  }
  
  var endPos = referrer.indexOf("&", startPos);
  if (endPos < 0) {
    endPos = referrer.length;
  }
  
  var queryString = referrer.substring(startPos + queryPrefix.length, endPos);
  // fix the space characters
  queryString = queryString.replace(/%20/gi, " ");
  queryString = queryString.replace(/\+/gi, " ");
  
  return queryString;

}

/************************************* End GetQueryString **********************************************************************/

/**********************************************************************************************************************/

//Get the window width and height in JavaScript using a cross-browser function that works with all versions of Internet Explorer and Firefox.
function GetWidth()
{
    var x = 0;
    if (self.innerHeight)
    {
        x = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        x = document.documentElement.clientWidth;
    }
    else if (document.body)
    {
        x = document.body.clientWidth;
    }
    return x;
}
 
function GetHeight()
{
    var y = 0;
    if (self.innerHeight)
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        y = document.body.clientHeight;
    }
    return y;
}

function turn_OnOff(cell, imgName){    
    if (document.images != null) {
        cell.style.backgroundImage = "url('/Style Library/_Images/" + imgName + "')";
    }    
}
function searchOnKeyEnter()
 {
      var key_enter= 13; // 13 = Enter
      if (key_enter==event.keyCode)
      {  
	  event.cancelBubble = true;
	  event.returnValue = false;      
          event.keyCode=0; 

          getURLParam();
      }
 }

function getURLParam(){
    if(obj != null){
        strReturn = "?k=" + obj.value;//strQueryString;

        document.getElementById('centerCol').innerHTML = "<img alt='' src='/SiteCollectionImages/subpageheader.jpg'/><br/><div class='title' style='padding-left:20px'>AUDI Research</div><div><iframe style='margin-left:4px'width='580' height='280' scrolling='auto' id='showresult' frameborder='0'></iframe></div>";
        document.getElementById('showresult').src = "http://research.banqueaudi.com/Pages/BasalResults.aspx" + strReturn; 
        changeTopMenuPict("ResearchCenter");
        return false;
    }
    else
        alert("Please enter a keyword");
}

function getExtendedDatabase(){
    document.getElementById('centerCol').innerHTML = "<img alt='' src='/SiteCollectionImages/subpageheader.jpg'/><br/><div class='title' style='padding-left:20px'>AUDI Research</div><div><iframe style='margin-left: 4px'width='580' height='400' scrolling='auto' id='showresult' frameborder='0'></iframe></div>";
    document.getElementById('showresult').src = "http://research.banqueaudi.com/Pages/BasalResults.aspx";
    changeTopMenuPict("ResearchCenter"); 
}

function changeTopMenuPict(pictName)
{
    var frameMenu = window.document.getElementById('TopFrame');
    frameMenu.src = "/Usercontrols/FlashMenu/PagesContent/index.aspx?pic_url=" + pictName ; 
}

function showLayer(layerID, status)
{
    var layer = window.document.getElementById(layerID);
    if(layer != null)    
    	layer.style.display = (status ? '' : 'none');
}

 var obj;
 function clearText(control)
 {
    obj = control;
	if(control.value=="Keyword")
	   control.value = "";
 } 
 /***************************************** *************************************************/
 function printThisPage()
{
var Content = "<head><link rel=stylesheet type=text/css href='/Style Library/Default.css'></head>";
//var contentText = document.getElementById('content').innerHTML;
//var Content = paul + "<br/><br>" + Content;
Content += document.getElementById('centerMainColContent').innerHTML;
var contentPrint = window.open('','Content');
contentPrint.document.open();
contentPrint.document.write(Content);
contentPrint.document.close();
contentPrint.print();
}

/********************************* preload images ******************************/


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/********************************* send to friend ******************************/
    function sendit2(){ 
        var thispage=location.href; 
        var pagename=prompt("What e-mail address do you want to send the page to?",""); 
        window.open("mailto:"+pagename+"?Subject=Check out this neat page&body="+thispage,"_self");} 
     function Sendit(){ 
	 if (navigator.appName == 'Firefox'){sendit2()} else
 if (navigator.appName == 'Netscape') {sendit2()} else{ 
   if (navigator.appName == 'Microsoft Internet Explorer') {sendit2()} 
            else {alert("Unfortunately your browser, "+navigator.appName+ ", does not support this feature. Please use the \n File » Send » Link by Email...\n menu option to send the page");}} }//--> 



