function changeInputType(oldObject, oType) {
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;
	if(oldObject.tabIndex) newObject.tabIndex = oldObject.tabIndex;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return newObject;
}

function changeInputError(oldObject) {
	var newObject = document.createElement('div');
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.tabIndex) newObject.tabIndex = oldObject.tabIndex;
	newObject.innerHTML = oldObject.innerHTML;
	newObject.className = "header_input_error ie6";
	newObject.onclick = oldObject.onclick;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return newObject;
}

function changeRulesNumber(oldObject) {
	var newObject = document.createElement('img');
	if(oldObject.width) newObject.width = oldObject.width;
	if(oldObject.height) newObject.height = oldObject.height;
	if(oldObject.src) newObject.src = oldObject.src;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return newObject;
}

function langSelOnOff() {
	if ($('language_selector_box').style.display == 'none') {
		//$('language_selector_box').appear({duration: 0.01});
		$('language_selector_box').show();
	} else {
		//$('language_selector_box').fade({duration: 0.01});
		$('language_selector_box').hide();
	}
}

//this function runs when the page is loaded, switch the checkbox with an image
//image is at header.php
function replaceChecks() {
	
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			//create a new image
			var img = document.createElement('img');
			//img.className = inputs[i].className;

			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			if(typeof inputs[i].onclick == 'function') {

			} else {
				img.onclick = new Function('checkChange('+i+')');
			}
			//place image in front of the checkbox
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			
			//hide the checkbox
			inputs[i].style.display='none';
			img.style.cursor = 'pointer';
			//img.style.border = '1px solid #c5c5c5';
			img.style.border = '0';
			if(typeof inputs[i].onclick == 'function') {
				img.onclick = function(){
					img_id = img.id.split("checkImage")[1];
					checkChange(img_id);
				};
				Event.observe(img, "click", $(img.id).next('input').onclick);
			} else {
				img.onclick = new Function('checkChange('+i+')');
			}

		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {
	if(inputs[i].checked) {
		inputs[i].checked = '';
		$('checkImage'+i).src = imgFalse;
	} else {
		inputs[i].checked = 'checked';
		$('checkImage'+i).src = imgTrue;
	}
}

/*
Script for adding bookmark fixed by Andrei
*/
function CreateBookmarkLink(title, url, obj) {
	//Firefox Bookmark
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
		return false;
	}
	// IE Favorite
	if(window.external) {
		window.external.AddFavorite( url, title);
		return false;
	}
	// Opera 7+ Browser
	if(window.opera && window.print) {
		obj.setAttribute('href',url);
		obj.setAttribute('title',title);
		obj.setAttribute('rel','sidebar');
		obj.click();
		return false;
	}
	//any other browser
	if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){//chrome doesn't allow any JS to trigger anything in browser, but we know CTRL+D works
		alert('Please press Ctrl + D to add Casino770 to your favourites');
		return false;
	}
	alert('Your browser doesn\'t support automatic bookmarking. Please add Casino770 to your favorites manually.'+"\n"+' Thank you.');//don't know which browser he has, and we don't know key combination to trigger favs
	return false;
}

/*
This function handles the dropdown
dropdown span: id_elem
dropdown input hidden: id_elem + '_input'
*/
function setDropDown(id_elem, label, value) {
	$(id_elem).update(label);
	$(id_elem + '_input').value= value;
	return false;
}

//Sidebar Button function
function launch_sidebarbtn(btn_number) {
	alert(btn_number);
}

//Opens New window in full width and height
function openWindowFull(page_url,window_name) {
	var WindowFull = window.open(page_url,window_name,"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-20));
	WindowFull.focus();
}

//Opens New window in full width and height
function openGameWindow(game, login_info) {
	console.log();
}

//Opens GameWindow (specific game)
function gameWindow(page_url) {
	var WindowFull = window.open(page_url,'game_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

//Opens HitechWindow
function hitechWindow(page_url) {
	var WindowFull = window.open(page_url,'hitech_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

//Opens CashierWindow
function cashierWindow(page_url) {
	var WindowFull = window.open(page_url,'cashier_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,scrolling=yes,scrollbars=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

//Opens New window in almost half width and height
function openWindowHalf(page_url,window_name) {
	var WindowHalf = window.open(page_url,window_name,"left=" + (screen.width - screen.width*0.60 - 50) + ",screenX=" + (screen.width - screen.width*0.6 -50) + ",top=60,screenY=60,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width*0.6 + ",height=" + (screen.height-50)*0.7);
	WindowHalf.focus();
}

//Gets absolute position of an element.
function getAbsolutePosition(element) {
	var r = {
		x: element.offsetLeft,
		y: element.offsetTop
	};
	if (element.offsetParent) {
		var tmp = getAbsolutePosition(element.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

//Php equivalent ucWords
function ucwords( str ) {
	// Uppercase the first character of every word in a string 
	//
	// version: 812.316
	// discuss at: http://phpjs.org/functions/ucwords
	// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// +   improved by: Waldo Malqui Silva
	// +   bugfixed by: Onno Marsman
	// *     example 1: ucwords('kevin van zonneveld');
	// *     returns 1: 'Kevin Van Zonneveld'
	// *     example 2: ucwords('HELLO WORLD');
	// *     returns 2: 'HELLO WORLD'
	str = (str+'').toLowerCase();
	return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) {
		return $1.toUpperCase ( );
	} );
}


function explode(separator, text) {
	var r = text.split(separator);

	var ending = r.slice().join(separator);
	//r.length = count;
	//r[count-1] = ending;

	return r;
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

//checks for enter key and submits the form
function checkEnterAndSubmit(e, formId){ //e is event object passed from function invocation
	var characterCode;// literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.getElementById(formId).submit(); //submit the form
		return false;
	}
	else{
		return true;
	}
}

/*
	Opens new Hitech, this function is used in flash banners
	This function use the global var hitechLobbyUrl, defined in each page on header section
*/
function openHitech() {
	var WindowFull = window.open(hitechLobbyUrl,'hitech_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

function openNewHitech() {
	var WindowFull = window.open(newHitechLobbyUrl,'hitech_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

function openOldHitech() {
	var WindowFull = window.open(oldHitechLobbyUrl,'hitech_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
	WindowFull.focus();
}

function downloadCasino() {
	pageTracker._trackPageview('/download-casino');
	document.location="http://www.casino770.com/down770/770_french/html/downactive.php?idaffiliation=" + idaffiliation;
}
function downloadCasino_lang(lang) {
	pageTracker._trackPageview('/download-casino');
	if(lang == 'fr')
		document.location="http://www.casino770.be/down770/770_french/downactive.php?idaffiliation=" + idaffiliation;
	else if(lang == 'en' || lang == 'pt')
		document.location="http://www.casino770.be/down770/770_english/downactive.php?idaffiliation=" + idaffiliation;
	else if(lang == 'de')
		document.location="http://www.casino770.be/down770/770_german/downactive.php?idaffiliation=" + idaffiliation;
	else if(lang == 'nl')
		document.location="http://www.casino770.be/down770/770_english/downactive.php?idaffiliation=" + idaffiliation;
}
function openOldHitech() {
	var WindowFull = window.open(oldHitechLobbyUrl,'hitech_window',"left=0,screenX=0,top=0,screenY=0,titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,width=" + screen.width + ",height=" + (screen.height-50));
//WindowFull.focus();
}

function openFullscreen(link) {
	var WindowFull = window.open(link.href,'hitech_window',"fullscreen=yes, titlebar=no,toolbar=no,directory=no,resizable=1,scrolling=yes,scrollbar=yes,scroll=yes,top=0,left=0,width="+screen.width+",height="+screen.height);
	WindowFull.focus();
}

Event.observe(window, 'load', function() {
	$$('a[rel="external"]').each(function(link){
		link.observe('click', function(e) {
			var el = e.element();
			window.open(el.readAttribute('e_href'));
			return false;
		});
	});
});

var Cookie = {
	data: {},
	options: {
		expires: 1,
		domain: "",
		path: "",
		secure: false
	},

	init: function(options, data) {
		Cookie.options = Object.extend(Cookie.options, options || {});

		var payload = Cookie.retrieve();
		if(payload) {
			Cookie.data = payload.evalJSON();
		}
		else {
			Cookie.data = data || {};
		}
		Cookie.store();
	},
	getData: function(key) {
		return Cookie.data[key];
	},
	setData: function(key, value) {
		Cookie.data[key] = value;
		Cookie.store();
	},
	removeData: function(key) {
		delete Cookie.data[key];
		Cookie.store();
	},
	retrieve: function() {
		var start = document.cookie.indexOf(Cookie.options.name + "=");

		if(start == -1) {
			return null;
		}
		if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
			return null;
		}

		var len = start + Cookie.options.name.length + 1;
		var end = document.cookie.indexOf(';', len);

		if(end == -1) {
			end = document.cookie.length;
		}
		return unescape(document.cookie.substring(len, end));
	},
	store: function() {
		var expires = '';

		if (Cookie.options.expires) {
			var today = new Date();
			expires = Cookie.options.expires * 86400000;
			expires = ';expires=' + new Date(today.getTime() + expires);
		}

		document.cookie = Cookie.options.name + '=' + escape(Object.toJSON(Cookie.data)) + Cookie.getOptions() + expires;
	},
	erase: function() {
		document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	},
	getOptions: function() {
		return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');
	}
};

function showHideSubmenu(id,flag){
	if(document.getElementById('submenu_'+id)){
		document.getElementById('submenu_'+id).style.display = flag ? 'block' : 'none';
	}
}
