/*---------------------------------------------------------*/
/*
	CMSystem.js
	For public rendering
*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*
	Function for posting in CM System
	Posting based on events
	strCommand:				The event that should be trigged
	strCommandArguments:	Arguments for the event
*/
/*---------------------------------------------------------*/
function CMS_Post(strCommand,strCommandArguments){
	var oCmsCommand	= getElm('SystemCommand');
	var oCmsCommandArguments = getElm('SystemCommandArguments');
	
	if(oCmsCommand && oCmsCommandArguments){	
		oCmsCommand.value = (typeof(strCommand) != "undefined") ? strCommand : "";
		oCmsCommandArguments.value = (typeof(strCommandArguments) != "undefined") ? strCommandArguments : "";
//		document.forms[0].target ="top";
		document.forms[0].submit();
	}
}
/*---------------------------------------------------------*/
/*CMS Post wrapper for posting in secure mode*/
/*---------------------------------------------------------*/
function CMS_PostSecure(strCommand,strCommandArguments){
	var oForm = document.forms[0];
	var sLocation = document.location.href;
	
	if(oForm){
		if(sLocation.indexOf("http://") == 0){
			oForm.action = sLocation.replace("http://","https://");
			oForm.target = "_top"; //post in the top (hole page)
		}
	}
	CMS_Post(strCommand,strCommandArguments);
}
/*---------------------------------------------------------*/
/*CMS Reload the window in secure mode with the current url for the rendered object*/
/*---------------------------------------------------------*/
function CMS_ReloadWindowWithSSL(sUrl){
	var sUrl = document.location.href;
	sUrl = sUrl.replace("http://","https://");
	window.top.document.location.href = sUrl;
}
/*---------------------------------------------------------*/
/*CMS Reload the window with given id*/
/*---------------------------------------------------------*/
function CMS_ReloadTop(bIsSecure,url){
	window.top.document.location.href = url;
}
function CMS_ReloadTopUrl(sUrl){
	window.top.document.location.href = sUrl;
}
/*---------------------------------------------------------*/
/*Reload a specific page*/
/*---------------------------------------------------------*/
function CMS_ReloadPage(){
	document.location.href = document.location.href;
}
/*---------------------------------------------------------*/
/*Reload a specific frame*/
/*---------------------------------------------------------*/
function CMS_ReloadFrame(sFrameName){
	//check if the frame exists
	if(typeof(window.top.frames[sFrameName]) != "undefined"){
		window.top.frames[sFrameName].document.location.href = window.top.frames[sFrameName].document.location.href;
	}
}
/*---------------------------------------------------------*/
/*Reload a specific page*/
/*---------------------------------------------------------*/
function CMS_LoadPage(objectId){
	document.location.href = "main.aspx?id=" + objectId;
}
/*---------------------------------------------------------*/
/*Open window function*/
/*---------------------------------------------------------*/
function CMS_OpenWindow(sUrl,sWindowName,iWidth,iHeight,sFeatures){
    sFeatures = (typeof (sFeatures) != "undefined") ? "," + sFeatures : "";
	var m = window.open(sUrl,sWindowName,"width="+ iWidth +",height="+ iHeight+""+sFeatures);
	m.focus();
}
/*---------------------------------------------------------*/
/*Open window function*/
/*---------------------------------------------------------*/
function CMS_OpenWindowLivescore(sUrl) {
    CMS_OpenWindow(sUrl, 'Livescore', 1024, 768, 'resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes')
}
/*---------------------------------------------------------*/
/*Get element by id wrapper function*/
/*---------------------------------------------------------*/
function getElm(sElementId){
	var elm = document.getElementById(sElementId);
	return elm;
}
/*---------------------------------------------------------*/
/*Wrapper function for show/hide element by using the display block:none*/
/*---------------------------------------------------------*/
function showHideElm(oElm){
	if(oElm){
		oElm.style.display = (oElm.style.display == "block" || oElm.style.display == "") ? "none" : "block"; 
	}
}

/*---------------------------------------------------------*/
/*Wrapper function for show element by using the display block:none*/
/*---------------------------------------------------------*/
function showElm(oElm){
	if(oElm){		
		oElm.style.display = "block";
	}
}

/*---------------------------------------------------------*/
/*Wrapper function for hide element by using the display block:none*/
/*---------------------------------------------------------*/
function hideElm(oElm){
	if(oElm){
		oElm.style.display = "none";
	}
}

/*---------------------------------------------------------*/
/*Function for selectin active menuItem
/*---------------------------------------------------------*/
var topSelectedId;
var levelSelectedId;
function setActiveMenuItem(objectId,parentObjectId){
	var oElm = null;
	var oElmLi = null;
	var sOrgCss = "";
	var oRef = window.top.frames['frmTop'];
	if(oRef != null){
		if(typeof(oRef.getElm) != "undefined"){
			if(topSelectedId){														
				oElm = oRef.getElm("nav_1_"+topSelectedId);
				oElmLi = oRef.getElm("li_1_"+topSelectedId);
				if(oElm && oElmLi){
					var sClass = "";
					if(oElm.className.indexOf('lastItem') > -1){
						sClass += "lastItem ";
					}
					if(oElm.className.indexOf('firstItem') > -1){
						sClass += "firstItem";
					}
					//ORG: oElm.className= (oElm.className.indexOf('lastItem') > -1) ? "lastItem" : "";
					//ORG: oElmLi.className= (oElmLi.className.indexOf('lastItem') > -1) ? "lastItem" : "";
					oElm.className = sClass;
					oElmLi.className = sClass;
					oElm.blur();
				}
			}
			if(levelSelectedId){
				oElm = oRef.getElm("nav_2_"+levelSelectedId);
				oElmLi = oRef.getElm("li_2_"+levelSelectedId);
				if(oElm && oElmLi){
					var sClass = "";
					if(oElm.className.indexOf('lastItem') > -1){
						sClass += "lastItem ";
					}
					if(oElm.className.indexOf('firstItem') > -1){
						sClass += "firstItem";
					}
					//ORG: oElm.className= (oElm.className.indexOf('lastItem') > -1) ? "lastItem" : "";	
					//ORG: oElmLi.className= (oElmLi.className.indexOf('lastItem') > -1) ? "lastItem" : "";
					oElm.className = sClass;
					oElmLi.className = sClass;
					oElm.blur();
				}
			}
			
			levelSelectedId = objectId;
			oElm = oRef.getElm("nav_2_"+levelSelectedId);
			oElmLi = oRef.getElm("li_2_"+levelSelectedId);
			
			if(!oElm && !oElmLi){
				levelSelectedId = parentObjectId;
				oElm = oRef.getElm("nav_2_"+levelSelectedId);
				oElmLi = oRef.getElm("li_2_"+levelSelectedId);
			}
			if(oElm && oElmLi){
				var sClass = "";
				if(oElm.className.indexOf('lastItem') > -1){
					sClass += "lastItem ";
				}
				if(oElm.className.indexOf('firstItem') > -1){
					sClass += "firstItem ";
				}
				sClass += "selected";
				//ORG: oElm.className = (oElm.className.indexOf('lastItem') > -1) ? "selected lastItem" : "selected";
				//ORG: oElmLi.className = (oElmLi.className.indexOf('lastItem') > -1) ? "selected lastItem" : "selected";
				oElm.className = sClass;
				oElmLi.className = sClass;
				oElm.blur();
			}
		}
	}
}

/*---------------------------------------------------------*/
/*Function for show/hide tabs content*/
/*---------------------------------------------------------*/
			
function changeTabShowDiv(showDiv,arrTabs){
	
	//Off		
	for(var i=0;i<arrTabs.length;i++){
					
		oTabElm = getElm(arrTabs[i]);		
		oTabElm.style.display = "none";
		
		oTabElm = getElm("li_" + arrTabs[i]);
		oTabElm.className = "";	
		
		oTabElm = getElm("a_" + arrTabs[i]);
		oTabElm.className = "";			
										
	}
	
	oTabElm = getElm(showDiv);
	oTabElm.style.display = "block";	
		
	oTabElm = getElm("li_" + showDiv);
	oTabElm.className = "selected";
	
	oTabElm = getElm("a_" + showDiv);
	oTabElm.className = "selected";
}

/*---------------------------------------------------------*/
//
//	Function to use for fix the security issue when use response.redirect in internet explorer
//	this appears in WinXp Sp2.
//	Reloads the specified frame with specific id (rendered id suggested)
//
/*---------------------------------------------------------*/
function checkRedirectXpSp2Issue(sFrameName,gObjectUrl){
	var bReturn = false;
	if( typeof(document.location) == "unknown") {
		bReturn = true;
		var oFrame = window.top.getElm(sFrameName);//'frmContent'
		if(oFrame != null){
			oFrame.src = gObjectUrl;
		}
	}
	return bReturn;
}

/*---------------------------------------------------------*/
/* Function to use in the layouts that are required to opens in a frame*/
/*---------------------------------------------------------*/
function checkFramesetRequiredLayout(sObjectUrl,sContentId){
	var bIsXpSp2RedirectIssue = checkRedirectXpSp2Issue('frmContent',sObjectUrl);
	if(!bIsXpSp2RedirectIssue){
		if(window.top.document){
			if(window.top.document.location.href == document.location.href){
				var params = "";
				var sTopLocation = window.top.document.location.search;
				if(sTopLocation.indexOf('?') >= 0){
					params = "?" + sTopLocation.substring(sTopLocation.indexOf('?')+1);
				}
				//remove all ?id= and &id= if exists in string
				if(params.search(/\?id=/gi) > -1 || params.search(/\&id=/gi) > -1){
					params = params.replace(/\&id=/gi,'DeleteMe=');
					params = params.replace(/\?id=/gi,'DeleteMe=');
					var i = params.indexOf("DeleteMe=");
					//delete all "lobjectid" from parameters
					while (params.indexOf("DeleteMe=") > -1){
						i = params.indexOf("DeleteMe=");
						params = params.replace(params.substr(i,45),""); //DeleteMe + 36 length guid
					}
				}
				if(params.length > 0){
					//replace ? with & if the string starts with that otherwise we add the "&" before the params
					params = ( params.indexOf('?') == 0) ? params.replace('?','&') : "&" + params;
				}
				window.top.document.location.href = sObjectUrl +"?ContentId="+sContentId + params;
			}
		}
	}
}
/*---------------------------------------------------------*/
/* Change the language id in the top url*/
/*---------------------------------------------------------*/
function CMS_ChangeLanguage(sLanguageId){
	var sTopUrl = top.location.href;
	if(sTopUrl.indexOf('LanguageId=')>-1){
		var iPos = sTopUrl.indexOf('LanguageId=');
		var tmp = sTopUrl.substr(iPos,13);
		sTopUrl = sTopUrl.replace(tmp,'LanguageId='+sLanguageId);
	}else{
		if(sTopUrl.indexOf('?') < 0){
			sTopUrl += "?";
		}else{
			sTopUrl += "&";
		}
		
		sTopUrl += "LanguageId="+sLanguageId;
	}
	top.location.href = sTopUrl;
}

function CMS_MarkError(sControlName, sErrorName, sMessage, sSetFocus) {
    var oInputElm = getElm(sControlName);
    var oErrorElm = getElm("error_" + sErrorName);
    if (!oInputElm) {
        oInputElm = document.forms[0][sControlName];
    }
    if (oInputElm) {
        //Cant focus hidden elements
        if (oInputElm.type.toUpperCase() != "HIDDEN") {
            //oInputElm.className = "fieldError";
            oInputElm.className = oInputElm.className + " fieldError";
            if (sSetFocus)
                oInputElm.focus();
        }
    }
    if (oErrorElm) {
        oErrorElm.innerHTML = sMessage;
        oErrorElm.style.display = "block";
    }
}

/*---------------------------------------------------------*/
/*Mark up an error from the command, set focus on field by defualt*/
/*---------------------------------------------------------*/
function CMS_MarkError(sInputName, sMessage) {
    CMS_MarkError(sInputName, sMessage, true);
}

/*---------------------------------------------------------*/
/*Mark up an error from the command, set focus on field if sSetFocus is true*/
/*---------------------------------------------------------*/
function CMS_MarkError(sInputName, sMessage, sSetFocus) {
    var oInputElm = getElm(sInputName);
    var oErrorElm = getElm("error_" + sInputName);
    if (!oInputElm) {
        oInputElm = document.forms[0][sInputName];
    }
    if (oInputElm) {
        //Cant focus hidden elements
        if (oInputElm.type.toUpperCase() != "HIDDEN") {
            //oInputElm.className = "fieldError";
            oInputElm.className = oInputElm.className + " fieldError";
            if (sSetFocus)
                oInputElm.focus();
        }
    }
    if (oErrorElm) {
        oErrorElm.innerHTML = sMessage;
        oErrorElm.style.display = "block";
    }
}

/*---------------------------------------------------------*/
/*Mark up an error from the command*/
/*---------------------------------------------------------*/
function CMS_UnMarkError(sInputName){
	var oInputElm = getElm(sInputName);
	var oErrorElm = getElm("error_" + sInputName);
	if(!oInputElm){
		oInputElm = document.forms[0][sInputName];
	}
	if(oInputElm){
		//Cant focus hidden elements
		if(oInputElm.type.toUpperCase() != "HIDDEN"){
			//oInputElm.className = "fieldError";
			oInputElm.className = "normal";
		}
	}
	if(oErrorElm){
		oErrorElm.innerHTML = "";
		oErrorElm.style.display = "none";
	}
}

/*loop the input and check for the first fielderror class at input elements in the markup*/
function CMS_FocusFirstError(){
	var arrInput = document.getElementsByTagName('input');
	for(var i=0;i<arrInput.length;i++){
		var oInputElm = arrInput[i];
		if(oInputElm){
			//Cant focus hidden elements
			if(oInputElm.type.toUpperCase() != "HIDDEN"){
				if(oInputElm.className.indexOf("fieldError") > -1){
					oInputElm.focus();
					i = arrInput.length;//break the loop
				}
			}
		}
	}
}

/************************************************
 * Casino functions
 ***********************************************/
/*---------------------------------------------------------*/
/* Casino set reload timeout  */
/*---------------------------------------------------------*/
function __doReload()
{
	setTimeout('__doCasinoReload()', (300 * 1000));
}

/*---------------------------------------------------------*/
/* Casino reload isAlive page */
/*---------------------------------------------------------*/
function __doCasinoReload() {
	var url = document.URL;
	if(url.lastIndexOf('?') > -1)
	{
		url = url.substring(0, url.lastIndexOf('?'));
	}
	document.location = url + "?Reload=true";
}

function __doLogout()
{
	top.location = "main.aspx"
}
/*---------------------------------------------------------*/
/* Setfocus on the text field*/
/*---------------------------------------------------------*/

// Sets focus on the control with id = id
function CMS_SetFocus(id)
{
    var elem = document.getElementById(id);
	if(elem != null)
		elem.focus();
}
/*---------------------------------------------------------*/
/* This is a go back fucktion goes back in history*/
/*---------------------------------------------------------*/
function CMS_GoBackStage(StageCounter){
	var oStageCounter = StageCounter.value;
	//Save the value in hidden field
	if(oStageCounter == null)
		history.go(-1);
	if(oStageCounter > 0){
		history.go(-(++oStageCounter));
	}
	else
		history.go(-1);
} 
/*---------------------------------------------------------*/
/* This is a force 'save as' dialog function*/
/*---------------------------------------------------------*/
 function downloadme( fileName ){
	alert( fileName );
    myTempWindow = window.open(fileName);
    myTempWindow.document.execCommand("SaveAs",null,"SaveAsName.xml");
    myTempWindow.close();
}
/*---------------------------------------------------------*/
/* These fuctions set the colors over a tr in a table onMouseOver, onMouseOut,Onclicked.*/
/*---------------------------------------------------------*/

var lastClicked = null;		// Last table row that was clicked
// Sets bgcolor on tablerow (usage: on onmouseover="trOnMouseOver(this, 'myOverColor')")	
function CMS_TrOnMouseOver(elem, cssClass)
{
	if(elem != null)
	{
		if(lastClicked != null)
		{
			if(elem != lastClicked)
				elem.className =	cssClass;
		}
		else
			elem.className = cssClass;
	}
}
// Removes bgcolor on tablerow (usage: on onmouseout="trOnMouseOut(this, 'myOutColor')")
//<![CDATA[
function CMS_TrOnMouseOut(elem, cssClass)
{
	if(elem != null && elem != lastClicked)
		elem.className = cssClass;
}//]]>

// Sets bgcolor on clicked tablerow (usage: on onmousedown="trClicked(this, 'myNoClickedColor', 'myClickedColor')")
function CMS_TrClicked(elem, cssClass1, cssClass2)
{
	if(elem != null)
	{
		if(lastClicked != null)
			lastClicked.className = cssClass1;
		elem.className =  cssClass2;
		lastClicked		= elem;
	}
}

function CMS_OpenWebClient(agentName) 
{
	if(agentName == null){
		return;
	}else{
		var winObj=window.open('http://download.b2bpoker.com/client/'+agentName+'/web/'+agentName+'_popup.html','PokerClient', 'location=no,status=no,resizable=no,scrollbars=no,toolbar=no,width=790,height=533');
		
	}
}
/*Open funmoney web client, the url to the funmoney web client object .ie main.aspx?id=guid*/
function CMS_OpenFunmoneyWebClientWindow(sUrl){
	var winObj=window.open(sUrl,'PokerClient', 'location=no,status=no,resizable=no,scrollbars=no,toolbar=no,width=790,height=533');
}
		
/*
	Function to handle DHTML page swap
	Containers named like: paging1,paging2,paging3...
	PagerLinks named like: lnkPaging1,lnkPaging2,lnkPaging3...
	Holder for current value named: txtCurrentPage (hidden textbox)
*/
function CMS_PagingSwap(iPage,iTotalPages){
	var oCurrentPage = getElm('txtCurrentPage');
	if(oCurrentPage != null){
		var oHidden = getElm('paging'+ oCurrentPage.value);
		var oLnkPagingNotActive = getElm('lnkPaging'+ oCurrentPage.value);
	}
	if(iPage < 1){
		iPage = 1;
	}
	else if(iPage > iTotalPages){
		iPage = iTotalPages;
	}
	//Correct styles on prev/next buttons
	var oLnkPrev = getElm('lnkPagingPrev');
	if(oLnkPrev!= null){
		oLnkPrev.className = (iPage == 1) ? "disabled" : "";
	}
	var oLnkNext = getElm('lnkPagingNext');
	if(oLnkNext!= null){
		oLnkNext.className = (iPage == iTotalPages) ? "disabled" : "";
	}
	
	var oVisible = getElm('paging'+ iPage)
	var oLnkPagingActive = getElm('lnkPaging'+ iPage);
		
	if(oHidden){
		oHidden.style.display = "none";
	}
	if(oLnkPagingNotActive){
		oLnkPagingNotActive.className = "";
	}
	
	if(oVisible){
		oVisible.style.display = "block";
	}
	if(oLnkPagingActive){
		oLnkPagingActive.className = "selected";
	}
	if(oCurrentPage){
		oCurrentPage.value = iPage;
	}
	
}
/*
	Function to handle keypresses
	Keycode listener that can be used on textboxes to check if enter is pressed to execute a command.
	Used with i.e. onkeydown attribute
	Command to execute = string
	Command argument for the command = string
	Event
	Should the command be executed in secure mode = bool
	Example:
	CMS_InputTextSubmitChecker('MyCommand','MyCommmandArguments',event,false);
*/
function CMS_InputTextSubmitChecker(strCmd,strCmdArguments,evt,bIsSecure){
	//Enter has keycode 13
	if(evt.keyCode == 13){
		if(!bIsSecure){
			CMS_Post(strCmd,strCmdArguments);
		}
		else{
			CMS_PostSecure(strCmd,strCmdArguments);
		}
	}
}
/*Flash activation script for Internet Explorer*/
/*
onload = function getFlashObjectsIE(){
	alert("test");
	var uAgent = navigator.userAgent.toLowerCase();
	//Only IE windows
	if(uAgent.indexOf('msie') > 0  && uAgent.indexOf('windows') > 0){
		var arrObjects = document.getElementsByTagName('object');
		for(var i=0;i<arrObjects.length;i++){
			var flashWrapper = arrObjects[i].parentNode;
			var flashBodyCasinoGamePlay = getElm('CasinoGamePlayFlash'); //no activation on Casino Flash games
			var flashBodyCasinoGamePlay2 = getElm('CasinoGamePlay'); //no activation on Casino Flash games
			var doFlashActivation = true;
			//No activation if wrapper is around flash object with the classname "flashObjectNoActivate" 
			if(flashWrapper != null){
				if(flashWrapper.className == "flashObjectNoActivate"){
					doFlashActivation = false;
				}
			}
			// No activation on the casino game play page
			if(flashBodyCasinoGamePlay != null || flashBodyCasinoGamePlay2 != null){
				doFlashActivation = false;
			}
			if(doFlashActivation == true){
				//activate object
				arrObjects[i].outerHTML = arrObjects[i].outerHTML;
			}
		}
	}
}
*/
/*adds an onload event to rendering*/
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
		func();
		}
	}
}
/*add an onrezise event to rendering*/
function addResizeEvent(func){
	var oldonresize = window.onresize;
	if (typeof window.onresize != 'function') {
		window.onresize = func;
	}else {
		window.onresize = function() {
		if (oldonresize) {
			oldonresize();
		}
		func();
		}
	}
}
/* 
	Sets alternating rows on a table.
	tableId: the table to process
	startIndex: the row to start at ( can be used to skip headerrows )
	skipEndRowsCount: how many rows at the end of the table to skip

*/
function SetAlternatingRows( tableId, startIndex, skipEndRowsCount )
{
	var tableObj = document.getElementById( tableId );
	
	if( tableObj != null )
	{
		var endIndex = tableObj.rows.length - skipEndRowsCount;
		
		if( tableObj.rows.length-1 < endIndex )
			endIndex = tableObj.rows.length;
										
		for( i = startIndex; i < endIndex; i++ )
		{
			if( (i % 2) == 0 )
				tableObj.rows[i].className = 'listItemRowAlternating';
			else
				tableObj.rows[i].className = 'listItemRow';
		}
	}
}
/*cookies*/
/*set a cookie*/
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + escape(path) : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
/*get a cookie*/
function getCookie(name) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);

		if (begin == -1) {
			begin = dc.indexOf(prefix);

			if (begin != 0)
				return null;
		} else
			begin += 2;

		var end = document.cookie.indexOf(";", begin);

		if (end == -1)
			end = dc.length;

		return unescape(dc.substring(begin + prefix.length, end));
}

function SortDropDownList( idStr )
{
	var listBox = getElm( idStr );
	if( listBox == null )
	{
		return false;
	}
	else
	{
		var countryId = listBox.options[listBox.selectedIndex].value;
	}
	
	var ListArray = new Array( listBox.options.length );
	
	for( i = 1; i < listBox.options.length; i++ )
	{
		ListArray[i-1] = listBox.options[i].text +"#_-_#"+listBox.options[i].value;
	}
	
	ListArray.sort( sortIgnoreCaseAscending );		
	
	for( i = 1; i < listBox.options.length; i++ )
	{
		nameAndValue = ListArray[i-1].split( "#_-_#" );
		listBox.options[i].text = nameAndValue[0];
		listBox.options[i].value = nameAndValue[1];
		if(countryId == listBox.options[i].value){
			listBox.options[i].selected = true;
		}
	}
	
}
function sortIgnoreCaseAscending(a, b)
{
	var valA = a.toLowerCase();
	var valB = b.toLowerCase();
	if (valA>valB) return 1;
	if (valA <valB) return -1;
	return 0;
}

function sortIgnoreCaseDescending(a, b)
{
	var valA = a.toLowerCase().valueOf();
	var valB = b.toLowerCase().valueOf();
	if (valA<valB) return 1;
	if (valA >valB) return -1;
	return 0; 
}

function StopPaste( e )
{		
	if(	window.event )
	{
		var pressedKey = String.fromCharCode(e.keyCode).toLowerCase();
		if (e.ctrlKey && (pressedKey == "c" || pressedKey == "v"))
		{
			//Slovenians/Hungerians/Polish keyboard layouts
			if(e.altKey && pressedKey == "v"){
				return true;}
			else{
				return false;}
		}
	}
	else
	{
		var pressedKey = String.fromCharCode(e.which).toLowerCase();
		
		if (e.ctrlKey && (pressedKey == "c" || pressedKey == "x" || pressedKey == "v"))
		{
			//Slovenians/Hungerians/Polish keyboard layouts
			if(e.altKey && pressedKey == "v"){
				return true;}
			else{
				return false;}
		}
	}
	return true;
}

function PasswordStrengthMeter( txtPwd )
{
	var strLength	= txtPwd.value.length;
	var startDown	= 'a'.charCodeAt(0);
	var endDown		= 'z'.charCodeAt(0);
	var startUp		= 'A'.charCodeAt(0);
	var endUp		= 'Z'.charCodeAt(0);
	var startNum	= '0'.charCodeAt(0);
	var endNum		= '9'.charCodeAt(0);
	
	var lengthPoint = 0;
	var hasNum		= 0;
	var hasDown		= 0;
	var hasUp		= 0;
	var hasMisc		= 0;
	var hasInvalidChar = 0;
			
	if( strLength < 8 )
		lengthPoint = 0;
	if( strLength >= 8 && strLength < 15 )
		lengthPoint = 1;
	if( strLength >= 15 )
		lengthPoint = 2;
		
	for( i = 0; i < strLength; i++ )
	{
		var ch = txtPwd.value.charAt( i );
		var charInt = txtPwd.value.charCodeAt( i );
		if( charInt >= startNum && charInt <= endNum )
		{
			hasNum = 1;
		}
		else if( charInt >= startDown  && charInt <= endDown )
		{
			hasDown = 1;
		}
		else if( charInt >= startUp  && charInt <= endUp )
		{
			hasUp = 1;
		}
		else if( '!.-'.indexOf( ch ) != -1 )
		{
			hasMisc = 1;
		}
		else
		{
			//invalid character
			hasInvalidChar = true;
		}
	}
	
	var isValid = false;
	
	if( lengthPoint >= 1 && hasNum == 1 && hasDown == 1 && !hasInvalidChar )
		isValid = true;

	var passwordStrength = 0;				
	if( isValid )
		passwordStrength = lengthPoint + hasNum + hasDown + hasUp + hasMisc - 2;//if it is valid passwordStrength is 3

	if( isValid )
	{
		getElm( 'strength-0' ).className = 'display-none-pass';
		getElm( 'strength-1' ).className = 'display-none-pass';
		getElm( 'strength-2' ).className = 'display-none-pass';
		getElm( 'strength-3' ).className = 'display-none-pass';
		getElm( 'strength-4' ).className = 'display-none-pass';

		getElm( 'strength-'+passwordStrength ).className = 'display-block-pass';
	}
	else
	{
		getElm( 'strength-0' ).className = 'display-block-pass';
		getElm( 'strength-1' ).className = 'display-none-pass';
		getElm( 'strength-2' ).className = 'display-none-pass';
		getElm( 'strength-3' ).className = 'display-none-pass';
		getElm( 'strength-4' ).className = 'display-none-pass';
	}
}

function ValidateConfirmPassword( pId1, pId2 )
{
	var msg = getElm( 'msgConfirmPassword' ).value;
	
	var pwd = getElm( pId1 );
	var cnfPwd = getElm( pId2 );
					
	if( pwd.value != '' && cnfPwd.value != '' &&  pwd.value != cnfPwd.value )
	{
		CMS_MarkError( cnfPwd.name, msg, false );
	}
	else
	{
		CMS_UnMarkError( cnfPwd.name );
	}	
}

var originalEmailClassName = "";
function ValidateConfirmEmail( eId1, eId2 )
{
	var email = getElm( eId1 );
	var cnfEmail = getElm( eId2 );
	
	var msg = getElm( 'msgEmailNotTheSame' ).value;
	
	if( originalEmailClassName == "" ) 
		originalEmailClassName = 'wide';//cnfEmail.className;
					
	if( email.value != '' && cnfEmail.value != '' &&  email.value != cnfEmail.value )
	{//not empty and not the same email
		CMS_MarkError( cnfEmail.name, msg, false );	
	}
	else if(  email.value != '' && cnfEmail.value != '' )
	{//not empty and the same email
		CMS_UnMarkError( cnfEmail.name );
		cnfEmail.className = originalEmailClassName;
		ValidateEmailAddress( cnfEmail );
	}	
	else if(  email.value != '' && cnfEmail.value == '' )
	{//only the first email is filled in			
		ValidateEmailAddress( email );
	}
}

function ValidateEmailAddress( emailField )
{
	if( originalEmailClassName == "" ) 
		originalEmailClassName = emailField.className;

	var emailRegEx = getElm( 'reEmailRegex' ).value;
	var msg = getElm( 'msgEmailAddressNotCorrect' ).value;
	
	if( emailField.value != "" && emailField.value.match( emailRegEx ) == null )
	{
		CMS_MarkError( emailField.name, msg, false );
	}
	else
	{
		CMS_UnMarkError( emailField.name );
	
		if( originalEmailClassName != "" )
			//emailField.className = originalEmailClassName;
			emailField.className = 'wide';
			
	}
}

function PlayBingoGame(gameid) {
    new Ajax.Request(wroot + 'customers/WebForms/Integration/Wallet/Bingo/getbingourl.aspx?cmd=gameurl&gameid=' + gameid, { method: 'get', onSuccess: function(transport) { startBingo(transport) } })
}

function PlayBingo() {
    new Ajax.Request(wroot + 'customers/WebForms/Integration/Wallet/Bingo/getbingourl.aspxcmd=gameurl', { method: 'get', onSuccess: function(transport) { startBingo(transport) } });
}

function PlayLiveCasino(game) {
    new Ajax.Request(wroot + 'customers/WebForms/Integration/Wallet/LiveCasino/getlivecasinourl.aspx?&game=' + game, { method: 'get', onSuccess: function(transport) { startLiveCasino(transport) } });
}

function GetStartTime(gameid, libkey, control)
{
    new Ajax.Request(wroot + 'customers/WebForms/Integration/Wallet/Bingo/getbingourl.aspx?cmd=starttime&gameid=' + gameid + '&libkey=' + libkey + '&control=' + control, { method: 'get', onSuccess: function(transport) { returnStartTime(transport) } });
}

startLiveCasino = function(transport) {
    var response = transport.responseJSON;
    if (response.success == "1") {
        var winh = 640;
        var winw = 776;
        var winl = (screen.width - winw) / 2;
        var wint = (screen.height - winh) / 2;
        var gameWindow = window.open(response.url, 'link', "width=" + winw + ",height=" + winh + ",top=" + wint + ",left=" + winl + ",resizable=yes");
        if (parseInt(navigator.appVersion) >= 4) {
            gameWindow.window.focus();
        }
    }
    else {
        if (response.url != undefined) {
            if (confirm(response.message)) {
                window.location = response.url;
            }
        } else {
            alert(response.message);
        }
    }
}

var systemTime = new Date();
var clockDiff = new Date();

returnStartTime = function( transport) {
	var rObj = transport.responseJSON;
	if (rObj.StartTime!='')	{
		var time = rObj.servertime.split(',');
		systemTime.setFullYear(time[0],time[1]-1,time[2]);
		systemTime.setHours(time[3],time[4],time[5],time[6]);
		var tLocalDate = new Date();			
		clockDiff.setTime(tLocalDate.getTime() - systemTime.getTime());
	
		CMS_TimeCountdown(rObj.gameid, rObj.libkey, rObj.control, rObj.year, rObj.month, rObj.day, rObj.hour, rObj.minute, rObj.second, '1');
	}
	else {
		setTimeout('GetStartTime(\''+rObj.gameid+'\', \''+rObj.libkey+'\',\''+rObj.control+'\');', 10000);
	}
}


startBingo = function(transport) {
    var rObj = transport.responseJSON;
    if (rObj.success == "1") {
        window.open(wroot + 'customers/WebForms/Integration/Wallet/Bingo/PlayBingo.aspx', 'Bingo', "width=1024,height=800,resizable=yes");
    }
    else {
        if (confirm(rObj.url)) {
            window.location = wroot + "cashier/signup.aspx";
        }
    }
}

	/* ObjectSwap - Bypasses the new ActiveX Activation requirement in Internet Explorer by swapping existing ActiveX objects on the page with the same objects. Can also be used for Flash version detection by adding the param:
	<param name="flashVersion" value="8" /> to the object tag.

	Author: Karina Steffens, www.neo-archaic.net
	Created: April 2006
	Changes and bug fixes: May 2006
	Bug fixes: June 2006
	Changes: October 2006 (Included Opera9 and excluded IE5.5)
	*/

	//Check if the browser is InternetExplorer, and if it supports the getElementById DOM method
	var ie = (document.defaultCharset && document.getElementById && !window.home);
	var opera9 = false;
	if (ie) {
	    //Check for ie 5.5 and exclude it from the script
	    var ver = navigator.appVersion.split("MSIE")
	    ver = parseFloat(ver[1])
	    ie = (ver >= 6)
	} else if (navigator.userAgent.indexOf("Opera") != -1) {
	    //Check for Opera9 and include it in the ObjectSwap
	    var versionindex = navigator.userAgent.indexOf("Opera") + 6
	    if (parseInt(navigator.userAgent.charAt(versionindex)) >= 9)
	        opera9 = true;
	}
	//Perform ObjectSwap if the browser is IE or Opera (if not just check flashVersion)
	var oswap = (ie || opera9)

	//Hide the object to prevent it from loading twice
	if (oswap) {
	    document.write("<style id='hideObject'> object{display:none;} </style>");
	}

	/*Replace all flash objects on the page with the same flash object, 
	by rewriting the outerHTML values
	This bypasses the new IE ActiveX object activation issue*/
	objectSwap = function() {
	    if (!document.getElementsByTagName) {
	        return;
	    }
	    //An array of ids for flash detection
	    var stripQueue = [];
	    //Get a list of all ActiveX objects
	    var objects = document.getElementsByTagName('object');
	    for (var i = 0; i < objects.length; i++) {
	        var o = objects[i];
	        var h = o.outerHTML;
	        //The outer html omits the param tags, so we must retrieve and insert these separately
	        var params = "";
	        var hasFlash = true;
	        for (var j = 0; j < o.childNodes.length; j++) {
	            var p = o.childNodes[j];
	            if (p.tagName == "PARAM") {
	                //Check for version first - applies to all browsers
	                //For this to work, a new param needs to be included in the object with the name "flashVersion" eg:
	                //<param name="flashVersion" value="7" />
	                if (p.name == "flashVersion") {
	                    hasFlash = detectFlash(p.value);
	                    if (!hasFlash) {
	                        //Add the objects id to the list (create a new id if there's isn't one already)
	                        o.id = (o.id == "") ? ("stripFlash" + i) : o.id;
	                        stripQueue.push(o.id);
	                        break;
	                    }
	                }
	                params += p.outerHTML;
	            }
	        }
	        if (!hasFlash) {
	            continue;
	        }
	        //Only target internet explorer
	        if (!oswap) {
	            continue;
	        }
	        //Avoid specified objects, marked with a "noswap" classname
	        if (o.className.toLowerCase().indexOf("noswap") != -1) {
	            continue;
	        }
	        //Get the tag and attributes part of the outer html of the object
	        var tag = h.split(">")[0] + ">";
	        //Add up the various bits that comprise the object:
	        //The tag with the attributes, the params and it's inner html
	        var newObject = tag + params + o.innerHTML + " </OBJECT>";
	        //And rewrite the outer html of the tag 
	        o.outerHTML = newObject;
	    }
	    //Strip flash objects
	    if (stripQueue.length) {
	        stripFlash(stripQueue)
	    }
	    //Make the objects visible again
	    if (oswap) {
	        document.getElementById("hideObject").disabled = true;
	    }
	}

	detectFlash = function(version) {
	    if (navigator.plugins && navigator.plugins.length) {
	        //Non-IE flash detection.
	        var plugin = navigator.plugins["Shockwave Flash"];
	        if (plugin == undefined) {
	            return false;
	        }
	        var ver = navigator.plugins["Shockwave Flash"].description.split(" ")[2];
	        return (Number(ver) >= Number(version))
	    } else if (ie && typeof (ActiveXObject) == "function") {
	        //IE flash detection.
	        try {
	            var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);
	            return true;
	        }
	        catch (e) {
	            return false;
	        }
	    }
	    //Catchall - skip detection
	    return true;
	}

	//Loop through an array of ids to strip
	//Replace the object by a div tag containing the same innerHTML.
	//To display an alternative image, message for the user or a link to the flash installation page, place it inside the object tag.  
	//For the usual object/embed pairs it needs to be enclosed in comments to hide from gecko based browsers.
	stripFlash = function(stripQueue) {
	    if (!document.createElement) {
	        return;
	    }
	    for (var i = 0; i < stripQueue.length; i++) {
	        var o = document.getElementById(stripQueue[i]);
	        var newHTML = o.innerHTML;
	        //Strip the comments
	        newHTML = newHTML.replace(/<!--\s/g, "");
	        newHTML = newHTML.replace(/\s-->/g, "");
	        //Neutralise the embed tag
	        newHTML = newHTML.replace(/<embed/gi, "<span");
	        //Create a new div element with properties from the object
	        var d = document.createElement("div");
	        d.innerHTML = newHTML;
	        d.className = o.className;
	        d.id = o.id;
	        //And swap the object with the new div
	        o.parentNode.replaceChild(d, o);
	    }
	}

	//Initiate the function without conflicting with the window.onload event of any preceding scripts
	var tempFunc = window.onload;
	window.onload = function() {
	    if (typeof (tempFunc) == "function") {
	        try {
	            tempFunc();
	        } catch (e) { }
	    }
	    objectSwap();
	}
	
/*---------------------------------------------------------*/
/*This function is counting down the time to a exact time.*/
/*---------------------------------------------------------*/

var count  = 0;
function CMS_TimeCountdown(gameId,librarykey,ObjectcountdownItem,year, month, day, hour, minute, second ,format)
{
			var countdownItem	=	document.getElementById(ObjectcountdownItem); 
			
			var tLocalDate = new Date();
			//Diff the 
	        systemTime.setTime(tLocalDate.getTime() - clockDiff.getTime()); 
			//Convert both today's date and the target date into miliseconds.                           
			
			Todays_Date = (new Date(systemTime.getFullYear(),systemTime.getMonth(), systemTime.getDate(), 
									systemTime.getHours(), systemTime.getMinutes(), systemTime.getSeconds())).getTime();                                 
			
			Target_Date = (new Date(year, month - 1, day, hour, minute, second)).getTime();                  
	        var flag = false;
			//Find their difference, and convert that into seconds.                  
			Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	    
			if(Time_Left < 0)
				Time_Left = 0;
				
	        		
			switch(format)
				{
				case 0:
						//The simplest way to display the time left.
						//countdownItem.innerHTML = Time_Left + ' seconds';
						countdownItem.innerHTML = countdownItem.innerHTML;
						break;
		case 1:
		    //More datailed.
		    days = Math.floor(Time_Left / (60 * 60 * 24));
		    Time_Left %= (60 * 60 * 24);
		    hours = Math.floor(Time_Left / (60 * 60));
		    Time_Left %= (60 * 60);
		    minutes = Math.floor(Time_Left / 60);
		    Time_Left %= 60;
		    seconds = Time_Left;

		    dps = 's'; hps = 's'; mps = 's'; sps = 's';
		    //ps is short for plural suffix.
		    if (days == 1) dps = '';
		    if (hours == 1) hps = '';
		    if (minutes == 1) mps = '';
		    if (seconds == 1) sps = '';
		    //The last 30 seconds we swift the class of the div to highlight it//minutes == 0 && seconds < 30)
		    if (hours == 0 && minutes == 0 && seconds < 30) {
		        //Set 0 two the interface variables when they are lower then 10.
		        if (hours < 10) { hours = '0' + hours; }
		        if (minutes < 10) { minutes = '0' + minutes; }
		        if (seconds < 10) { seconds = '0' + seconds; }
		        var text = librarykey + ' ';
		        text += hours + ':';
		        text += minutes + ':';
		        text += seconds;
		        if (countdownItem.className != null && countdownItem.className != '') {
		            if ('bingoNextGameHighlight' != countdownItem.className) {
		                countdownItem.className = 'bingoNextGameHighlight'; //Set new class the last 20 seconds
		            }
		        }
		        else { countdownItem.style.fontWeight = 'bold'; }
		        
		        countdownItem.innerHTML = text;
		        //When it says 0 hours, minutes and seconds we make a recursive call to the ajax function.
		        if (hours == 0 && minutes == 0 && seconds == 0) {
		            //Recursive call to the ajax function to start the count down again
		            GetStartTime(gameId, librarykey, ObjectcountdownItem);

		            flag = true;
		        }
		        if (flag) { return; }
		    }
		    else {
		        //Set 0 two the interface variables when they are lower then 10.
		        if (hours < 10) { hours = '0' + hours; }
		        if (minutes < 10) { minutes = '0' + minutes; }
		        if (seconds < 10) { seconds = '0' + seconds; }

		        var text = librarykey + ' ';
		        text += hours + ':';
		        text += minutes + ':';
		        text += seconds;

		        if (countdownItem.className != null && countdownItem.className != '') {
		            if ('bingoNextGame' != countdownItem.className) {
		                countdownItem.className = 'bingoNextGame'; //Set default class
		            }
		        }
		        else { countdownItem.style.fontWeight = 'normal'; }
		        countdownItem.innerHTML = text;
		    }
		    break;
				default: 
						countdownItem.innerHTML = countdownItem.innerHTML;
				}
	        if(flag){return;}      
			//Recursive call, keeps the clock ticking.
			setTimeout('CMS_TimeCountdown(\''+gameId+'\', \''+librarykey+'\',\''+ObjectcountdownItem+'\',' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + format + ');', 1000);
}
/*---------------------------------------------------------*/
/*This function is checking if the website is with frames or not.*/
/*---------------------------------------------------------*/
function IsFrameSet(){
	if(parent.frmContent)
	{	return true;	}
	else{	return false;	}
}
/*---------------------------------------------------------*/
/*This function is using the browsers print function and   */
/*depending if the website is with frames or without frames*/
/*---------------------------------------------------------*/
function printing()
{
	if(IsFrameSet()){
		parent.frmContent.print();
	}else{
		window.print();
	}
}
/*---------------------------------------------------------*/
/*This function is using for open a casino game in          */
/*fullscreen                                                */
/*---------------------------------------------------------*/

function popupFullScreenCasinoGameLoad(url, sCasinoRedirectLoadPageUrl, sisAuthenticatedUser, libFullscreenMessage) {

    params = 'top=0, left=0';
    params += ', fullscreen=yes';
    params += ', scrollbars=no';
    params += ', toolbar=no';
    params += ', menubar=no';
    params += ', location=no';
    params += ', directories=no';
    params += ', status=no';
    params += ', resizable=yes';
    var uAgent = navigator.userAgent.toLowerCase();
    var setCasinoGame = document.getElementById('casinoGame');
    var sethideflash = document.getElementById('hideflash');
    var gameTable = document.getElementById('gameTable');
    if (sethideflash != null) {
        sethideflash.style.display = "none";
    }
    if (gameTable != null) {
        gameTable.style.display = "none";
    }
    if (setCasinoGame != null) {
        setCasinoGame.className = "undisplayFlash";
        setCasinoGame.innerHTML = libFullscreenMessage;
    }

    //Check browser version if it's IE or soemthing else
    if (uAgent.indexOf('msie') > 0 && uAgent.indexOf('windows') > 0) {
        //If IE open this, the redirect does not work the same in IE as the rest of the browser. Only if the user is logged in we make a redirect.
        if (sisAuthenticatedUser == 'true') {
            document.location.href = sCasinoRedirectLoadPageUrl;
        }
        params += ', width=' + screen.width;
        params += ', height=' + screen.height;
        CMS_OpenWindow(url, 'Fullscreen_casino', screen.width, screen.height, params)
    }
    else {
        //This is for all the other browsers
        document.location.href = sCasinoRedirectLoadPageUrl;
        CMS_OpenWindow(url, 'Fullscreen casino', screen.width, screen.height, params)
    }
}
/*************************************************************************************************************************/
/* This is a tooltip it will be displayed from mouse position. toolTipTargetElm, is the where the tooltip should execute */
/* have to be an element id. toolTipMessageElm, is where the content for the tooltip is placed, has to have an element id.*/
/* The tooltip can be between 150-280 pixels wide,toolTipWidth                                                            */
/*************************************************************************************************************************/
function preloadTooltip(toolTipTargetElm, toolTipMessageElm, toolTipVirtualElm, toolTipWidth) {
    //Set default width of the tooltip; 
    var elmToolTipWidth = 150;
    if (toolTipWidth == null || toolTipWidth == "") {
        elmToolTipWidth;
    } else { elmToolTipWidth = toolTipWidth; }
    if ($(toolTipTargetElm) != null && $(toolTipMessageElm) != null) {
        var elmVirDestination = document.createElement("div");
        elmVirDestination.id = toolTipVirtualElm;
        //Set the virtual Destination divs styles
        elmVirDestination.style.display = 'none';
        elmVirDestination.className = 'toolTip';
        elmVirDestination.style.position = 'absolute';
        var divTopRight = document.createElement("div");
        divTopRight.className = 'toolTipCornerTopRight';
        var divTopLeft = document.createElement("div");
        divTopLeft.className = 'toolTipCornerTopLeft';
        divTopRight.appendChild(divTopLeft);
        var divTopMiddle = document.createElement("div");
        divTopMiddle.className = 'toolTipTopMiddle';
        divTopLeft.appendChild(divTopMiddle);
        elmVirDestination.appendChild(divTopRight);
        var textElm = document.createElement("p");
        textElm.innerHTML = $(toolTipMessageElm).innerHTML;
        elmVirDestination.appendChild(textElm);
        var divBottomRight = document.createElement("div");
        divBottomRight.className = 'toolTipCornerBottomRight';
        var divBottomLeft = document.createElement("div");
        divBottomLeft.className = 'toolTipCornerBottomLeft';
        divBottomRight.appendChild(divBottomLeft);
        var divBottomMiddle = document.createElement("div");
        divBottomMiddle.className = 'toolTipBottomMiddle';
        divBottomLeft.appendChild(divBottomMiddle);
        elmVirDestination.appendChild(divBottomRight);
        var body = document.getElementsByTagName('body')[0].appendChild(elmVirDestination);
    }
    else {return false;}
    Event.observe($(toolTipTargetElm), 'mouseover', function(e) {//focus, mouseover
    var ev = e ? e : event;
        //Fix style defect in IE browsers get background image from body background
        var elmBodyStyleBGImage = document.body.style.backgroundImage;
        $(elmVirDestination).style.width = elmToolTipWidth + 'px';
        $(elmVirDestination).style.left = (Event.pointerX(ev) + 20) + 'px';
        $(elmVirDestination).style.top = (Event.pointerY(ev) + 0) + 'px';
        $(elmVirDestination).show();
        //Fix style defect in IE browsers set background image from the saved value
        document.body.style.backgroundImage = elmBodyStyleBGImage;
    });
    Event.observe($(toolTipTargetElm), 'mouseout', function() {
        //Fix style defect in IE browsers get background image from body background
        var elmBodyStyleBGImage = document.body.style.backgroundImage;
        $(elmVirDestination).hide();
        //Fix style defect in IE browsers set background image from the saved value
        document.body.style.backgroundImage = elmBodyStyleBGImage;
    });
}
function preloadOnfocus(onFocusTargetElm, onFocusMessageElm) {
    if ($(onFocusTargetElm) && $(onFocusMessageElm)) {
        Event.observe($(onFocusTargetElm), 'focus', function(e) {//focus, mouseover
            $(onFocusMessageElm).className = 'divOnFocusMessage';
            new Effect.Appear(onFocusMessageElm, { duration: 0.3 });
            $(onFocusMessageElm).display = 'inline';
        });
        Event.observe($(onFocusTargetElm), 'blur', function() {
            //Fix style defect in IE browsers get background image from body background
            new Effect.Fade(onFocusMessageElm, { duration: 0.3 });
            //Fix style defect in IE browsers set background image from the saved value
        });
    }
}
function preloadOnChange(onFocusTargetElm, onFocusMessageElm) {
    if ($(onFocusTargetElm) && $(onFocusMessageElm)) {
        Event.observe($(onFocusTargetElm), 'change', function(e) {//focus, mouseover
            $(onFocusMessageElm).className = 'divOnFocusMessage';
            new Effect.Appear(onFocusMessageElm, { duration: 0.3 });
            $(onFocusMessageElm).display = 'inline';
        });
        Event.observe($(onFocusTargetElm), 'blur', function() {
            //Fix style defect in IE browsers get background image from body background
            new Effect.Fade(onFocusMessageElm, { duration: 0.3 });
            //$(onFocusMessageElm).display = 'none';
            //Fix style defect in IE browsers set background image from the saved value
        });
    }
}

/*************************************************************************************************************************/
/* This is a script for setting hints to input fields, setts a new class or style to the field css                       */
/*************************************************************************************************************************/
function prepareFieldsForHints() {
    var input, textarea;
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; (input = inputs[i]); i++) {
        if (inputs[i].getAttribute('type') == 'text' || inputs[i].getAttribute('type') == 'password') {
            Event.observe(input, 'focus', oninputfocus);
            Event.observe(input, 'blur', oninputblur);
        }
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i = 0; (textarea = textareas[i]); i++) {
        Event.observe(input, 'focus', oninputfocus);
        Event.observe(input, 'blur', oninputblur);
    }
};
function oninputfocus(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.className = 'txtFieldSystemAuthOnfocus';
    //source.style.background = '#ffffcc';
    //source.style.background = '#bd9dc9';
}
function oninputblur(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.className = 'txtFieldSystemAuth';
    //source.style.background = '#FFF';
}

/*************************************************************************************************************************/
/* This is a script for setting hints to input fields, the span with a hint has to have the id hint_XXX, else you will   */
/* remove .asp validation spans, this script is for input and select                                                     */
/*************************************************************************************************************************/
function prepareInputsForHints() {
    var inputs = document.getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
            // the span exists!  on focus, show the hint
            inputs[i].onfocus = function() {
                //this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                var node = this.parentNode.getElementsByTagName("span")[0];
                if (node.id.indexOf("hint_") > -1) {
                    node.style.display = "inline";
                }
            }
            // when the cursor moves away from the field, hide the hint
            inputs[i].onblur = function() {
                //this.parentNode.getElementsByTagName("span")[0].style.display = "none";
                var node = this.parentNode.getElementsByTagName("span")[0];
                if (node.id.indexOf("hint_") > -1) {
                    node.style.display = "none";
                }
            }
        }
    }
    // repeat the same tests as above for selects
    var selects = document.getElementsByTagName("select");
    for (var k = 0; k < selects.length; k++) {
        if (selects[k].parentNode.getElementsByTagName("span")[0]) {
            selects[k].onfocus = function() {
                //this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                var node = this.parentNode.getElementsByTagName("span")[0];
                if (node.id.indexOf("hint_") > -1) {
                    node.style.display = "inline";
                }
            }
            selects[k].onblur = function() {
                //   this.parentNode.getElementsByTagName("span")[0].style.display = "none";
                var node = this.parentNode.getElementsByTagName("span")[0];
                if (node.id.indexOf("hint_") > -1) {
                    node.style.display = "none";
                }
            }
        }
    }
}