function site_url(path) {
	return SITE_URL + path;
}
function base_url(path) {
	return BASE_URL + path;
}
function theme_path (path) {
	return THEME_PATH + path;
}
//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;
};
/*
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;
 }
} 

var inputs;
//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).attr('src', imgFalse);
	} else {
		inputs[i].checked = 'checked';
		$('#checkImage'+i).attr('src', imgTrue);
	}
} 
function checkEnterAndSubmit(e, formId){ 
	var characterCode;
	if(e && e.which){ // (NN4)
		characterCode = e.which; 
	} else { // (IE)
		characterCode = e.keyCode; 
	}
	if(characterCode == 13){ 
		document.getElementById(formId).submit(); 
		return false;
	} else {
		return true;
	}
}




function updateClock ( )
{
  var currentTime = new Date ( );

  var currentYear = currentTime.getFullYear ( );
  var currentMonth = currentTime.getMonth ( ) + 1
  var currentDay = currentTime.getDate ( );
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Pad the minutes and seconds with leading zeros, if required
  currentMonth = ( currentMonth < 10 ? "0" : "" ) + currentMonth;
  currentDay = ( currentDay < 10 ? "0" : "" ) + currentDay;
  currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;

  // Update the time display
  document.getElementById("digital_clock").firstChild.nodeValue = currentTimeString;
}


function removeLoginBoxContent() {
	$('#myPassword').show();
	$('#myPassword_clear').hide();

	$('#myUsername').focus(function(){
		if(this.value=='Username') {
			this.value='';
			$('#myPassword').attr('value', '');
			$('#myPassword_clear').attr('value', '');
		}
	});
	$('#myPassword').focus(function(){
		if(this.value=='Password') {
			this.value='';
			$('#myUsername').attr('value', '');
			$('#myPassword_clear').attr('value', '');
		}
	});

	$('#myPassword_clear').focus(function() {
	    $('#myPassword_clear').hide();
	    $('#myPassword').show();
	    $('#myPassword').focus();
	});
	$('#myPassword').blur(function() {
	    if($('#myPassword').val() == '') {
	        $('#myPassword_clear').show();
	        $('#myPassword').hide();
	    }
	});


}
/*
	HEADER
*/

function logUserIn(username, password, redirect) {

        if(username == '' || password == '' || username == 'Username' || password == 'Password') {
                $('#login_message').empty();
		$('#login_message').append('Veuillez remplir les champs');
		$('#login_error_area').fadeIn();
                return;
        }

        $('#login_message').empty();
	$('#login_message').append("Vérification...");
	$('#login_error_area').fadeIn();

        var url="http://www.poker770.com/dev_new/index.php/auth/ajax_login/";
	$.ajax({
		type: "POST",
		url: url,
		data: "username=" + username + "&password=" + password,
		complete: function(text) {
			var login_data = jQuery.parseJSON(text.responseText);
			if(login_data['result'] == true) {
				$('#login_message').empty();
				$('#login_message').append(login_data['message']);
				$('#login_message').css('color', "#FFFFFF");
				try {
					pageTracker._trackPageview("/fr/loginok");
				} catch(err) {}
				if(redirect == 'reload')
					window.location.reload();
				else
					window.location.href = redirect;
                                return true;
                       	} else {
                        	try {
                                pageTracker._trackPageview("/fr/loginnok");
                                } catch(err) {}
                                $('#login_message').empty();
				$('#login_message').append(login_data['message']);
                                return false;
			}
		}
	});
}


/* HEADER */

	$("#lang_open").click(function(event) {
		event.preventDefault();
		$("#p770_language_tabs_expand").show();
	});

/* 
	FOOTER -----------------------------------
*/

$('footer_logo_click_and_buy').onclick = function() {
        window.open('http://clickandbuy.com/UK/en/help/surfer.html');
        return false;
}
$('footer_logo_money_bookers').onclick = function() {
        window.open('http://www.moneybookers.com/app/?l=EN');
        return false;
}
$('footer_logo_neteller').onclick = function() {
        window.open('https://www.neteller.com/home/index.jsf');
        return false;
}
$('footer_logo_click_2_pay').onclick = function() {
        window.open('https://click2pay.wirecard.com/click2pay/user_registration.c2p?locale=en');
        return false;
}
$('footer_logo_u_kash').onclick = function() {
        window.open('http://www.ukash.com/');
        return false;
}
$('footer_logo_paysafe').onclick = function() {
        window.open('http://www.paysafecard.com');
        return false;
}
$('footer_logo_adictel').onclick = function() {
        window.open('http://www.adictel.com/corporate/fr/');
        return false;
}
$('footer_logo_fairplayers').onclick = function() {
        window.open('http://www.fairplayers.com/');
        return false;
}
$('footer_logo_itechlabs').onclick = function() {
        window.open('http://www.casino770.com/casino770_RNG_certificate.pdf?PHPSESSID=655d3d73657ab955c7b46cbf64c34997');
        return false;
}
$('footer_logo_rss').onclick = function() {
        window.open('http://www.casino770.com/wiki/feed.php');
        return false;
}

function addFavouriteFooter() {
		var title = 'Poker770';
		var href = 'http://poker770.com';
		if (window.sidebar) {
				window.sidebar.addPanel(title, href, '');
		} else if (window.external) {
				window.external.AddFavorite(href, title);
		} else if (window.opera) {
				var e = document.createElement('a');;
				e.setAttribute('href', href);
				e.setAttribute('title', title);
				e.setAttribute('rel', 'sidebar');
				e.click();
		} else {
				alert("");
		}
}$(document).ready(function() {
	setInterval('updateClock()', 1000);

	/* clock */
    var flashvars = {};
    var params = {};
    var attributes = {};
    params.wmode = "transparent";
    swfobject.embedSWF('770_icon_analogclock.swf', "analog_clock", "17", "17", "9.0.0", false, flashvars, params, attributes);

	
	$('a[rel=external]').click(function(e){
		if(this.href != '' && this.href != '#'){
			window.open(this.href);
			return false;
		}
    });

	removeLoginBoxContent();

	
});
