//----------------------------------------------------------------------------------------------------------------------------------------|
//                                                     www.twmc.de                                                                        |
//----------------------------------------------------------------------------------------------------------------------------------------|
//                                                     ©Copyrights                                                                        |
//                                           twmc - TW. MARKETING CONSULTING                                                              |
//                                               IT Beratung Robert Bφhme                                                                 |
//----------------------------------------------------------------------------------------------------------------------------------------|
// Name :             init.js                                                                                                             |
// Erstellungsdatum : 04.12.2006                                                                                                          |
// Δnderungsdatum :   04.12.2006                                                                                                          |
//----------------------------------------------------------------------------------------------------------------------------------------|
// Kategorie :                                                                                                                            |
// Beschreibung :                                                                                                                         |
//----------------------------------------------------------------------------------------------------------------------------------------|

//browser detection
var isNav=false;
var isIE=false;
var coll;
var style;
var objnewwindow;
var isnewwindow = false;

var websitename="twmc - TW. MARKETING CONSULTING";

var arrDivName;
var deltaBlend = 1;
var loadingOpacity = 60;

function replaceString(string,suchen,ersetzen) {
ausgabe = "" + string;
while (ausgabe.indexOf(suchen)>-1) {
pos= ausgabe.indexOf(suchen);
ausgabe = "" + (ausgabe.substring(0, pos) + ersetzen + 
ausgabe.substring((pos + suchen.length), ausgabe.length));
}
return ausgabe;
}

function goToTopURL(url) { 
  top.window.location.href = url;
}

function goToMainFrameURL(url) { 
  MainFrame.location.href = url;
}

function goToURL(url,rootURL) 
{ 

  if(!rootURL)
  {
  	rootURL = '';
  }
  else
  {
  	rootURL = rootURL + '/';
  }
  window.location.href = rootURL + url;
}

function opennewWindow(url)
{
	if (isnewwindow && !objnewwindow.closed)
	{
		objnewwindow.close();
	}

	objnewwindow = window.open(url,"url","toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes");	
	objnewwindow.focus();
	isnewwindow = true;
	return objnewwindow;
}

if( parseInt(navigator.appVersion) >= 4){
	if(navigator.appName == "Netscape" || navigator.appName == "Opera"){
		isNav = true;
		coll = "document";
		style = "";
	} else {
		isIE = true;
		coll="document.all";
		style = ".style";
	}
}

function setStatusBar(msgStr) { self.status = msgStr; } 

function setStatusBarOrg() 
{
	self.status = websitename; 
	//setLoginFocus();
} 

function init() {
		if (isNav) {document.captureEvents(Event.MOUSEUP);} 
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function showMain(screentype) {

	setStatusBar(websitename);
  
	CenterDiv("Main",0,screentype);
	CenterDiv("LoadMain",58,screentype);
	CenterDiv("LoadingMsg",58,screentype);
 
}

function CenterDiv(divName,opacityValue,screentype) {

  //Resolution normal
	if (screentype >= 1280)
	{
    	window.document.getElementById (divName).style.left = (top.screen.availWidth/2)-(1244/2)-9;
	}
	else //Resolution small
	{
		if (screentype >= 1024)
		{
	    	window.document.getElementById (divName).style.left = (top.screen.availWidth/2)-(1024/2);
		}
	}
	
	window.document.getElementById (divName).style.visibility = "visible";
	
	if (opacityValue != "")
	{
		  //Visibility / Transparency
		  switch (navigator.appName)
		  {
		    case "Microsoft Internet Explorer":
		      window.document.getElementById(divName).style.filter= "alpha(opacity=" + opacityValue + ")";
		      break;
		    case "Netscape":
		      window.document.getElementById(divName).style.opacity = "." + opacityValue;
		      break;
		  }
  	}
}

function BlendOutDiv()
{
	var vfaktor = 4;
	var i;
	
	if (loadingOpacity > 20)
	{
		vfaktor = 25;
	}
	if (loadingOpacity > 35)
	{
		vfaktor = 38;
	}
	if (loadingOpacity > 50)
	{
		vfaktor = 55;
	}
	
	loadingOpacity = loadingOpacity - deltaBlend;
	
	if (loadingOpacity > 10)
	{
		window.setTimeout("BlendOutDiv()", vfaktor);
	}
	else
	{
		for (i = 0; i < arrDivName.length; i++)
		{
			window.document.getElementById(arrDivName[i]).style.visibility = "hidden";
		}
		BlendOutDivEnd();
	}
	
	for (i = 0; i < arrDivName.length; i++)
	{
		  switch (navigator.appName)
		  {
		    case "Microsoft Internet Explorer":
		      window.document.getElementById(arrDivName[i]).style.filter= "alpha(opacity=" + String(loadingOpacity) + ")";
		      break;
		    case "Netscape":
		      window.document.getElementById(arrDivName[i]).style.opacity = "." + String(loadingOpacity);
		      break;
		  }
	}
}

function hideLoading() {

	if (window.document.getElementById ("LoadBack"))
	{
		window.document.getElementById ("LoadBack").style.visibility = "hidden";
	}
	window.document.getElementById ("LoadText").style.visibility = "hidden";
	window.document.getElementById ("SiteMain").style.visibility = "visible";

}

function init_Page()
{
	top.window.moveTo(0,0); 
	if (document.all) 
   	{ top.window.resizeTo(screen.availWidth,screen.availHeight); } 
	else if 
   	(document.layers || document.getElementById) 
   	{ 
   	if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth)
     	{ top.window.outerHeight = top.screen.availHeight; 
       	top.window.outerWidth = top.screen.availWidth; } 
   	} 
}

function handleKeyDown (evt) {
  var keyCode = document.all ? event.keyCode :
                evt.which ? evt.which :
                evt.keyCode ? evt.keyCode :
                evt.charCode;
                
  var is_admin = top.window.document.URL.match(/(\/Sites\/Admin\/)/);

  if (keyCode == 13) {
    directLogin();
    return false;
  }
	if(!is_admin)
	{
	  if (keyCode == 17) {
	    alert('The [CTRL]-KEY is locked on this website.');
	    return false;
	  }
	}
  return true;
}

function setLoginFocus()
{
		if (window.document.getElementById("txtLoginUser"))
		{
			//window.document.getElementById("txtLoginUser").focus();
		}
		else if (parent.window.document.getElementById("txtLoginUser"))
		{
			//parent.window.document.getElementById("txtLoginUser").focus();
		}
}

function msgDlg(statusmsg)
{
	if (statusmsg != '')
	{
		alert(statusmsg);
	}
}



		
if (document.layers)
  document.captureEvents(Event.KEYDOWN);
  document.onkeydown = handleKeyDown;


MM_reloadPage(true);
