/************** HTML FUNCTIONS  ***************/

/************** ATTENTION ***************/
//PLEASE PUT NO DATA IN .JS FILES.  ALL DATA MUST BE PASSED INTO FUNCTIONS.
/************** /ATTENTION ***************/
	
	function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getCookieVal (offset) 
	{
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	
	function GetCookie (name) 
	{
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
		return null;
	}
	
	function SetCookie (name, value) 
	{
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}
	
	function ExpireCookie(cookie) 
	{
		var today = new Date();
		var the_date = new Date();
		the_date.setTime(today.getTime() - 1000);
		var the_cookie_date = the_date.toGMTString();
		var the_cookie = cookie +"=";
		var the_cookie = the_cookie + ";expires=" + the_cookie_date;
		document.cookie = the_cookie;
		//location.reload(true);
	}

	function scrollingDetector()
	{
		var bPageScrolls = false;
		
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			if(document.body.scrollTop <= 0)
				bPageScrolls = true;
		}		
		else
		{
			if(window.pageYOffset <= 0)
				bPageScrolls = true;
		}
			
		return 	bPageScrolls;
	}

	function setCssScrolling()
	{
		if(!scrollingDetector())
			document.styleSheets[1].cssRules['CBIMakeElementScrollable'].style.overflow = "hidden";			
	}
	
	function FormatPrinter()
	{
		var spanArray =document.getElementsByTagName("DIV");
		var imgArray =document.getElementsByTagName("IMG");
		
		for(var i=0;i<spanArray.length;i++)
		{	
			if(spanArray[i].className = "CBIMakeElementScrollable")
			{
				
				spanArray[i].className = "CBIMakeElementNotScrollable"; 
				
			}		
		}	
		
		for(var i=0;i<imgArray.length;i++)
		{	
			if(imgArray[i].className = "CBIImageBorder")
			{
				if(imgArray[i].id != "CyberbahnLogo")	
					imgArray[i].className = "invisible"; 
				
			}
			if(imgArray[i].className = "CBIImageNoBorder")
			{
				if(imgArray[i].id != "Symbol" && imgArray[i].id != "check")	
					imgArray[i].className = "invisible"; 
			}		
		}	
	}
	
	window.onload = function RemoveTopHeaderNavigation()
	{
		if(window.top != self)
		{ 
			if(document.getElementById('HeaderTable') != null)
			{
				document.getElementById('HeaderTable').className = "invisible";
			}	
			if(document.getElementById('TopNavigationTable') != null)	
			{
				document.getElementById('TopNavigationTable').className = "invisible";
			}	
		}
	}
	
	function ReFrameToTop()
	{
		if(window.top!= self ) 
		{ 
			var URL = window.location.href
			window.top.location.href = URL
		}
	}	
	

function isNetscape() {
	var isDom=typeof document.getElementById=="function";
	var netscape=(isDom&&navigator.appName=="Netscape"); 
	return netscape;
}

function setFixedHeight(name, height) {
	if (isNetscape()) {
		var div = document.getElementById(name);
		if (div != null)
			div.style.height = height;
	}
}
	
var MessageWindow='Description';
var msgWindow=null;
function windowOpener(mylink) 
{
	thisWindow = self;
	msgWindow=window.open (mylink,'MessageWindow','toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,width=550,height=425,resizeable=no');
	if(msgWindow!=null)
	{
		msgWindow.opener = thisWindow;
		msgWindow.focus();
	} 
}	

//function which handle all pop up windows 
function windowOpenerEx(URL,width,height,left,top) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left ="+left+",top ="+top+"');");
}

function windowOpenerExScroll(URL,width,height,left,top) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left ="+left+",top ="+top+"');");
}

function windowOpenerEx_tb_sc(URL,width,height,left,top,toolbar,scroll) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar="+toolbar+",scrollbars="+scroll+",location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left ="+left+",top ="+top+"');");
}
	 
function windowOpenerExScrollResize(URL,width,height,left,top) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height+",left ="+left+",top ="+top+"');");
}
/************** End  ***************/

//function to read  javascript cookie by its name
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
/************** End  ***************/
function OnCopyToClipboard(elementContent)
{
	if (elementContent != null)
	{
		if (window.clipboardData && clipboardData.setData)
		{
			clipboardData.setData("Text", elementContent);
		}
		else
		{
			alert("Internet Explorer required");
		}
	}
}

function OnCopyPlainTextToClipboard(elementContent)
{
	if (elementContent != null)
	{
		OnCopyToClipboard(elementContent);
	}
	else
		alert("The text passed was null.  Nothing was copied to the clipboard.");
}
			
function OnCopyHTMLElementToClipboard(elementID)
{
	//debugger;
	
	var element = document.getElementById(elementID);
	
	if (element != null)
		OnCopyToClipboard(element.innerText);
	else
		alert("Could not find the HTML element called '" + elementID + "' that contains the exception details and therefore, nothing was copied to the clipboard.");
}

function noenter() {
  return !(window.event && window.event.keyCode == 13); 
}

function getAgreementNoticeCookieName()
{
	return "subagr_note";
}

function getAgreementNoticeCookie()
{
	return GetCookie(getAgreementNoticeCookieName());
}

function setAgreementNoticeCookie()
{
	var expDays = 365; // number of days the cookie should last
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	SetCookie(getAgreementNoticeCookieName(), "true", exp, "/");
}
var watermark = null;

function createDemoWatermark(title, ignoreParent) {
	if (ignoreParent != true) {
		if ((parent != null && parent != window) || opener != null)
			return;
	}

	if (watermark == null && document.getElementById("watermark") == null)
	{

		watermark = document.createElement('div');
		watermark.innerHTML = title;
		var agentName = "";
		try{agentName=navigator.userAgent.toLowerCase();}catch(e){agentName="";}
		if (agentName.indexOf("firefox") >= 0) {
			watermark.id = "watermarkFF";
			watermark.className = "watermarkFF";
		}
		else {
			watermark.id = "watermarkIE";
			watermark.className = "watermarkIE";
			watermark.onclick = function () {this.className="invisible"}
			//watermark.onmouseout = function () {this.className="visible"}
		}

		var do_onload = null;
		if (window.onload != null)
			do_onload = window.onload;

		window.onload = function(e) {
			document.body.appendChild(watermark);
			if (do_onload != null) {
				do_onload(e);
			}
		}
	}

}
