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.3});
	} else {
		$('language_selector_box').fade({duration: 0.3});
	}
}

//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
*/
function CreateBookmarkLink(title, url) {
	url = window.location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

/*
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-50));
	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 downloadCasino() {
	pageTracker._trackPageview('/download-casino');
	document.location="http://www.casino770.com/down770/770_french/html/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();
}