//=======================================================================
//Copyright (C) 2001 Dubidot GmbH
//All rights reserved.
//
//THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//KIND , EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTIBILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//
//Date: 1998, 1999, 2000, 2001, 2002, 2003
//Author: ChS, MH, CT
//=======================================================================

// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)  && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);

var mac = ((navigator.appVersion.lastIndexOf("Mac") != -1 ));
var win = ((navigator.appVersion.lastIndexOf("Windows")!=-1));
var ie = ((navigator.appName == "Microsoft Internet Explorer"));
var ns = ((navigator.appName == "Netscape"));
var winME =(navigator.appVersion.lastIndexOf("Windows ME")!=-1);
var win2K =(navigator.appVersion.lastIndexOf("Windows NT 5")!=-1);
var winNT =(navigator.appVersion.lastIndexOf("Windows NT")!=-1);
var win98 =(navigator.appVersion.lastIndexOf("Windows 98")!=-1);
var win95 =(navigator.appVersion.lastIndexOf("Windows 95")!=-1);
var ns3 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 ));
var ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 ));
var ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5 ));
var ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 6 ));
var ie3 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 3 ));
var ie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
var ie5 = ((navigator.appVersion.lastIndexOf("MSIE 5")!=-1));
var ie6 = ((navigator.appVersion.lastIndexOf("MSIE 6")!=-1));
var ie7 = ((navigator.appVersion.lastIndexOf("MSIE 7")!=-1));
                
var is_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos !=-1) {                 
   is_konq  = true;
   is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
   is_major = parseInt(is_minor);
}                                 

var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml  = (is_safari || is_konq);

// END BROWSER CHECK CODE





self.name='MediaSuite';

window.setInterval('hidestatus()',200);
function hidestatus(){
	window.status='Media Suite';
}
	
if (is_ie5up)
{ 
/*do nothing*/ 
}
else if (is_nav6up || is_khtml)
{
/*do nothing*/ 
	if (is_khtml)is_nav6up=true;
}
else
{ 
	//alert(agt);
	//window.location.href ="_Browser.asp"; 
}

function GetElement(id)
{
	if (is_ie5up)
	{ 
		return document.all(id); 
	}
	else if (is_nav6up)
	{
		return document.getElementById(id);
	}
}


// ###############################################################
//


function SubmitForm(FormName)
{
	var keyPressed;
	
	if (is_ie5up)
	{
	   keyPressed = window.event.keyCode;
	   if (keyPressed == 13)
		{
			document.forms[FormName].submit();	
		}
	}	
}


// ###############################################################
//
//
function ResultToggle(TargetID)
	{ 
		var ButtonExp = GetElement(TargetID + '_Expandable');
		var ButtonColl= GetElement(TargetID);

		if (ButtonExp.style.display == "none")
			{  		
			ButtonExp.style.display = "";
			ButtonColl.style.display = "none";
			}	 
		else 
			{  	
			ButtonExp.style.display = "none";  	
			ButtonColl.style.display = "";
			}
		//
		if (is_nav6up) { 
			document.getElementById('Status').style.display = "none";	
		}
		else if (is_ie5up) {
			document.all('Status').style.display = "none";	
		}	
		
	}  
// ###############################################################
//
//
function ShowStatusText(strText)
{ 
	try
	{
		window.setInterval('HideStatusText()',5000);
		var objLayer;
		var objStatusText;
		if (is_nav6up) { 
			objLayer = document.getElementById('Status');
			//objStatusText = document.getElementById('StatusText');
		}
		else if (is_ie5up) {
			objLayer = document.all('Status');
			//objStatusText = document.all('StatusText');
		}
	
		if (objLayer)
			{
			if (objLayer.style.display == "none")
			    {  		
				objLayer.style.display = "";
				objLayer.style.top = document.body.scrollTop;
				objLayer.style.left = document.body.scrollLeft;
				objLayer.innerHTML = strText;
				}	 
			else 
				{  	
				objLayer.style.display = "none";  	
				}
				
			}
		}catch(e){ e = null;}
}  
// ###############################################################
//
//
function HideStatusText()
	{ 
		try{
			var objLayer;
		
			if (is_nav6up) { 
				objLayer = document.getElementById('Status');
			}
			else if (is_ie5up) {
				objLayer = document.all('Status');
			}
 			if (objLayer)
 			{	objLayer.style.display = "none";  	
 			}
 		}catch(e){ e = null;}
	}  
// ###############################################################
//
//
function ShowStatusTextConfirmation(strStatusText, strConfirmationText)
{ 
	var objLayer;

	if (is_nav6up) { 
		objLayer = document.getElementById('Status');
	}
	else if (is_ie5up) {
		objLayer = document.all('Status');
	}

	if (confirm(strConfirmationText))
	{
		ShowStatusText(strStatusText);
		return true;
	} else {
		return false;
	}
}  
// ###############################################################
//
//
function VerifyPasswordChange()
	{
	var User_NewPassword;
	var User_OldPassword;
	
	if (is_nav6up) { 
			User_NewPassword = document.getElementById('User_NewPassword');
			User_OldPassword = document.getElementById('User_OldPassword');
		}
		else if (is_ie5up) {
			User_NewPassword = document.all.User_NewPassword;
			User_OldPassword = document.all.User_OldPassword;
		}
	
	if (User_NewPassword.value == User_OldPassword.value ) 
		{
		User_Password.value = User_NewPassword.value 
		return true;
		}
	else
		{
		User_Password.value = ""
		User_NewPassword.value = ""
		alert ("Die Eingaben stimmen nicht ?berein !")
		return false;
		}
	}
// ###############################################################
//
function toggle( targetId )
	{ 
		var target;
			
		if (is_nav6up) { 
			target = document.getElementById( targetId );
		}
		else if (is_ie5up) {
			target = document.all( targetId );
		}
		
		//alert('b4 style:  ' +target.style.display)
		
		if (target.style.display == "none")
			{  		
			target.style.display = "";
			}	 
		else 
			{  	
			target.style.display = "none";  	
			}
		//alert('aftr style:  ' +target.style.display)
		
	}  

function treeToggle( targetId )
	{ 
		var target;
			
		if (is_nav6up) { 
			target = document.getElementById( targetId );
		}
		else if (is_ie5up) {
			target = document.all( targetId );
		}
		
		//alert('b4 style:  ' +target.style.display)
		
		if (target.style.display == "none" || target.style.display == "")
			{  		
			target.style.display = "block";
			}	 
		else if (target.style.display == "block")
			{  	
			target.style.display = "none";  	
			}
		//alert('after style:  ' +target.style.display)
		
	}  


// ###############################################################
//
//
function SaveForm()
	{
	if (confirm('?nderungen speichern!'))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
// ###############################################################
//
//
function OpenTracking(TrackingNumber)
{
	var upswindow = window.open("http://wwwapps.ups.com/tracking/tracking.cgi?tracknum="+TrackingNumber,"UPS","width=650,height=400,location=0,menubar=0,toolbar=0,titlebar=0,status=0,resizable=1,scrollbars=1");
}
// ###############################################################
// Funktionen f?r die Tools-Seite
//
//
function MS() 
{
	open("http://www.microsoft.com/ie/download/","MS","innerwidth=700,innerheight=500,width=700,height=500,directories,location,menubar,toolbar,titlebar,status");
}
//***********************************************************************
function StIt() 
{
	open("http://www.aladdinsys.com/expander/index.html","Stuffit","innerwidth=700,innerheight=500,width=700,height=500,directories,location,menubar,toolbar,titlebar,status");
}
//***********************************************************************
function WZ() 
{
	open("http://www.winzip.com/download.cgi?home","winzip","innerwidth=700,innerheight=500,width=700,height=500,directories,location,menubar,toolbar,titlebar,status");
}
//***********************************************************************
function AR() 
{
	open("http://www.adobe.com/prodindex/acrobat/readstep.html","adobe","innerwidth=700,innerheight=500,width=700,height=500,directories,location,menubar,toolbar,titlebar,status");
}
//***********************************************************************
function QTM() 
{
	open("http://www.apple.com/quicktime/download/index.html","quicktime","innerwidth=700,innerheight=500,width=700,height=500,directories,location,menubar,toolbar,titlebar,status");
}
//***********************************************************************
//***********************************************************************
function openPDF(mSource) 
{
	open(mSource,"PDF","innerwidth=700,innerheight=500,width=700,height=500,directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status,resizable=1");
}
function openWHIP(mSource) 
{
	open(mSource,"WHIP","innerwidth=700,innerheight=500,width=700,height=500,directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status,resizable=1");
}
// ###############################################################
//
//
function OpenWindow(mSource)
{
	openXtern(mSource,160,70);
}
// ###############################################################
//
//
function openXtern(mSource,iWidth,iHeight)
{
	open(mSource,"MediaSuiteX","innerwidth="+iWidth+",innerheight="+iHeight+",width="+iWidth+",height="+iHeight+",directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status=0,resizable=1,dependent=1,scrollbars=1");
}

function OpenOrderStep01Window(URL)
{
	open(URL,"DateWindow","width=390,height=170,location=no,menubar=no,toolbar=no,titlebar=no,status=no,resizable=no,scrollbars=no");
}
function openHelp(mSource)
{
	open(mSource,"MediaSuiteHelp","width=370,height=560,directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status=0,resizable=0,dependent=1,scrollbars=1");
}
// ###############################################################
//
function  positionVisual(posY,posX)
{
	if (!mac)
	{ 
	var visleft;
	var vistop;
		visleft = posY;	//document.body.offsetWidth - 315;
		vistop = posX;	//document.body.offsetHeight - 360;
		if (visleft < 280){	visleft = 280; }
		if (vistop < 50){	vistop = 50;}
		//if (vistop<95) {vistop= 95};
		visual.style.left = visleft ;
		visual.style.top = vistop ; 
		visual.style.visibility='visible';
		//alert ('visual.style.left = '+ visual.style.left +"\n"+'visual.style.top= '+ visual.style.top );
	}
}


// ###############################################################
function ShowCalender(target,language,day,month,year)
{ 

	  //alert("X_target:" + target );	
	  //alert("X_language:" + language );
	var xLink ;
	 xLink = "Calendar.asp?";
	 xLink = xLink + "language=" + language ;
	 xLink = xLink + "&TargetField=" + target ;

	 xLink = xLink + "&day=" + day ;
	 xLink = xLink + "&month=" + month ;
	 xLink = xLink + "&year=" + year ;

	var DMSCalendar = open(xLink,"DMSCalendar","innerwidth=180,innerheight=100,width=180,height=100,directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status=0,resizable=0,dependent=1,scrollbars=0");
	DMSCalendar.moveTo( window.screenLeft + event.clientX,window.screenTop  + event.clientY);

}
// ###############################################################
// functions related to the new navigation...

function browseCategoryMedia(cid)
{
	var url = 'ResultOverviewAdvanced.asp?sLevel=NEW&sMode=5&sType=5&sQuery=' + cid;
	
	if (parent != self) {
		// loaded in frames 
		if (is_nav6up) 
			top.frames[1].document.location.href =  url;
		else
			parent.frames.MediaSuite.document.location =  url;
	}
	else 
	{
			self.document.location = url;
	}
	
}

function encodeQuery(text) {
    text= text.replace(/%/g,"%25");
    return text;
}

function openDMSLink(URL)
{
	if (parent != self) {
	  	// loaded in frames
		if (is_nav6up) 
			top.frames[1].document.location.href =  encodeQuery(URL);
		else
			parent.frames.MediaSuite.document.location =  encodeQuery(URL);
	}
	else {
	  	self.location.location = encodeQuery(URL);
	}
}

//
function ShowGlobalMessage(strText)
	{ 
		var objLayer;
		var objLayerText;
		
		if (is_nav6up) 
		{ 
			objLayer = document.getElementById('GlobalMessage');
			//objLayerText = objLayer.innerText;
		}
		else if (is_ie5up) 
		{
			objLayer = document.all('GlobalMessage');
			//objLayerText = document.all.GlobalMessageText;
		}
		
		if (objLayer)
		{
			if (objLayer.style.display == "none")
			{  		
				objLayer.style.display = "";
				objLayer.style.top = document.body.scrollTop;
				objLayer.style.left = document.body.scrollLeft;
				if (strText != '')
						objLayer.innerHTML = strText;	
			}	 
			else 
			{  	
				objLayer.style.display = "none";  	
			}
		}
	}  
// ###############################################################
// ###############################################################
//
//
function RepositionLayers()
{
	var objLayer;
		
	if (is_nav6up) 
	{ 
		objLayer = document.getElementById('GlobalMessage');
	}
	else if (is_ie5up) 
	{
		objLayer = document.all('GlobalMessage');
	}
	
	if (objLayer)
	{
		if (objLayer.style.display != "none")
		{  			
			objLayer.style.top = document.body.scrollTop;
			objLayer.style.left = document.body.scrollLeft;
		}
					
		if (is_nav6up) 
		{ 
			objLayer = document.getElementById('Status');
		}
		else if (is_ie5up) 
		{
			objLayer = document.all('Status');
		}
				
		if (objLayer.style.display != "none")
		{  		
			objLayer.style.top = document.body.scrollTop;
			objLayer.style.left = document.body.scrollLeft;
		}
	}
}

function jsrsDebugInfo(){
  // use for debugging by attaching to f1 (works with IE)
  // with onHelp = "return jsrsDebugInfo();" in the body tag
  var doc = window.open().document;
  doc.open;
  doc.write( 'Pool Size: ' + jsrsContextPoolSize + '<br><font face="arial" size="2"><b>' );
  for( var i in jsrsContextPool ){
    var contextObj = jsrsContextPool[i];
    doc.write( '<hr>' + contextObj.id + ' : ' + (contextObj.busy ? 'busy' : 'available') + '<br>');
    doc.write( contextObj.container.document.location.pathname + '<br>');
    doc.write( contextObj.container.document.location.search + '<br>');
    doc.write( '<table border="1"><tr><td>' + contextObj.container.document.body.innerHTML + '</td></tr></table>' );
  }
  doc.write('</table>');
  doc.close();
  return false;
}


function downloadIframe(url)
{
var downloaddata1 = createDownloadContainer('downloaddata');
downloaddata.location = url;
}

function createDownloadContainer( containerName ){
 
  var container;
  switch( jsrsBrowser ) {
 
    case 'IE':
	  if (typeof(window.frames[containerName]) == 'undefined')
	  {
      document.body.insertAdjacentHTML( "afterBegin", '<span id="SPAN' + containerName + '"></span>' );
      var span = document.all( "SPAN" + containerName );
      var html = '<iframe name="' + containerName + '" id="' + containerName + '" src=""></iframe>';
      span.innerHTML = html;
      span.style.display = 'none';
      container = window.frames[ containerName ];
      }
      else
      {
      container = window.frames[ containerName ];
      }
      break;
      
    case 'MOZ':
		
	  if (document.getElementById(containerName) == null)
	  {
      var span = document.createElement('SPAN');
      span.id = "SPAN" + containerName;
      span.style.display = 'none';
      document.body.appendChild( span );
      var iframe = document.createElement('IFRAME');
      iframe.name = containerName;
      span.appendChild( iframe );
      container = iframe;
       }
      else
      {
      container = document.getElementById(containerName);
      }
      break;
  }
  return container;
  
}




















// ###############################################################
// ###############################################################
// FUNCTIONS FOR THE MEDIUM INFO FLYOUTS ETC...
//

var gEvt, gMid, gTitle;
var gX, gY;

// functions to get page coordinates of mouse event
function getMouseX(evt) {
	return (evt.pageX)? evt.pageX: evt.clientX + getScrollX();
}

function getMouseY(evt) {
	return (evt.pageY)? evt.pageY: evt.clientY + getScrollY();
}
// returns amount of vertical scroll
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}
// returns amount of horizontal scroll
function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}

function fetchMediumDetails()
{
	jsrsExecute('MediumDetailsFlyout.asp', setMediumInfoDA, 'getMediumDetailsFromID' , gMid);
}

function getMediumInfo(evt, mid, title)
{
        if (evt) {
		gX = getMouseX(evt);
		gY = getMouseY(evt);
	}
	
	gMid = mid;
	gTitle = title;
	
	window.setTimeout("fetchMediumDetails()", 100);
	
}

function showSaveFavorite(mSource)
{
	var iWidth = 450;
	var iHeight = 250;
	var fwin;
 	fwin = window.open(mSource,"FavWin","innerwidth="+iWidth+",innerheight="+iHeight+",width="+iWidth+",height="+iHeight+",directories=0,location=0,menubar=0,toolbar=0,titlebar=0,status=0,resizable=1,dependent=1,scrollbars=1");
	if(!fwin.opener) {fwin.opener = window;}

}

function checkForChanges()
{


}


function openHelpKrones(folder)
{
	var url = "/custom/help/"+folder+"/index.html"
	window.open(url,'_blank','width=820, height=600, top=120, left=300, toolbar=no, menubar=no, location=no, scrollbars=no')
}

/**
 * checks weather enter was pressed
 */
function CheckEnter(evt) {
    //alert(evt);
    var keyCode = document.layers ? evt.which : evt.keyCode;
     // alert(keyCode);
     if (keyCode == 13) {
        return true; 
    }
    return false;
}


