
//play the movie
function playMovie (file, large){
	if(large){
		var so = new SWFObject(BASE_URL + 'includes/player.swf','mpl',604, 329,'8');
		so.addVariable('width',604);
		so.addVariable('height',329);
	}else{
		var so = new SWFObject(BASE_URL + 'includes/player.swf','mpl',421, 259,'8');
		so.addVariable('width',421);
		so.addVariable('height',259);		
	}
	
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addVariable('file', BASE_URL + file);
	so.addVariable('image', BASE_URL + 'images/stillvideo.jpg');
	so.addVariable('linkfromdisplay','true');
	so.addVariable('searchbar','false');
	so.addVariable('autostart','true');
	so.addVariable('wmode', 'transparent');
	so.write('player');
}

function loadPhotoInfo(eventId, type, photoIndex){
	$("#photoInfo").load( BASE_URL + 'ajax/photoInfo.ajax.php', {'event' : eventId, 'type' : type, 'index' : photoIndex});
}

function coverCans(cans){
	for(var i = cans+1; i <= 5; i++){
		document.getElementById( "voteCans_" + i).src = "http://coorslight.solutionexl.com/images/cannette_off.png";
		 //.className = "dim";
	}
}
function resetCans(){
	for(var i = 1; i <=5; i++)
		document.getElementById( "voteCans_" + i).src = "http://coorslight.solutionexl.com/images/cannette_on.png";
	//	document.getElementById( "voteCans_" + i) //.className = "dimFalse";
}

function voteCans(id, cans){
	$("#cansHolder").load( BASE_URL + 'ajax/photoVote.ajax.php', {'voteId' : id, 'vote' : cans});
}
	
function shareFb(url, title){
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function loadPhotoMini(eventId, type, page){
	$("#photoMinis").load( BASE_URL + 'ajax/photoMini.ajax.php', {'event' : eventId, 'type' : type, 'page' : page});
}

function loadPhotoConnect(key, type){
		$("#photoConnect").load( BASE_URL + 'ajax/photoConnect.ajax.php', {'key' : key, 'type' : type});
}
function validatePC(key){
	var error = "";
	if (document.getElementById('email').value	==	"" || !isValidEmail(document.getElementById('email').value))	error +=	"Ton courriel est invalide\n";
	if (document.getElementById('first').value == "")		error += "Ton prenom est invalide\n";
	if (document.getElementById('last').value	==	"")		error	+= "Ton nom est invalide\n";
	if (document.getElementById('day').value == "" || document.getElementById('month').value == "" || document.getElementById('year').value == "" ) error += "Ta date de naissance est invalide\n";
	else if (fetchAge(document.getElementById('day').value, document.getElementById('month').value, document.getElementById('year').value) < 18)		error += "Tu n'as pas l'age requis\n";
	if (document.getElementById('newsletter').checked	==	false)		error	+= "Tu dois t'abonner a l'INSIDER\n";
	
	if (error != "")	alert("Corrige les champs suivants :\n\n" + error);
	else{
		var bday = document.getElementById('year').value + "-" + document.getElementById('month').value + "-" + document.getElementById('day').value ;
	
		$("#photoConnect").load( BASE_URL + 'ajax/photoConnect.ajax.php', {'type' : 'thanks', 'key' : key, 'first' : document.getElementById('first').value, 'last' : document.getElementById('last').value, 'email' : document.getElementById('email').value, 'bday' : bday});
	}
}

function isValidEmail(str) {
	//var str		=	document.getElementById('newsletter_email').value;
	var at		=	"@"
	var dot		=	"."
	var lat		=	str.indexOf(at)
	var lstr	=	str.length
	var ldot	=	str.indexOf(dot)
	var error = false;
	
	if (str == "" || str == null)		error = true;
	if (str.indexOf(at)==-1)	error = true;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)		error = true;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)		error = true;
	if (str.indexOf(at,(lat+1))!=-1)		error = true;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)		error = true;
	if (str.indexOf(dot,(lat+2))==-1)		error = true;
	if (str.indexOf(" ")!=-1)		error = true;

	if(error)	return false;
	else	return true;
}

function validateAge(){
	if (document.getElementById('day').value == "" || document.getElementById('month').value == "" || document.getElementById('year').value == "" 
					|| !isValidDate(document.getElementById('day').value,document.getElementById('month').value,document.getElementById('year').value)){
		alert("SVP fournir ta date de naissance");
		return false;
	}
}

function isValidDate(day, month, year){
	month = month - 1; //not sure why but it must be there!!!
	var myDate = new Date( year, month, day );

	return (	(myDate.getDate() == day) && (myDate.getMonth() ==month) && (myDate.getFullYear() == year) );
}


/* finalist ajax */

function loadFinalistLocation(id){
	$("#photoLocation").load( BASE_URL + 'ajax/finalistsLocation.ajax.php', {'id' : id});
}
function loadFinalistInfo(id){
	$("#photoInfo").load( BASE_URL + 'ajax/finalistInfo.ajax.php', {'id' : id});
}
function voteFinalist(id){
	$("#cansHolder").load( BASE_URL + 'ajax/finalistVote.ajax.php', {'id' : id});
}
function loadFinalistMini(type, page){
	$("#photoMinis").load( BASE_URL + 'ajax/finalistMini.ajax.php', {'type' : type, 'page' : page});
}

//get the age from the bd
function fetchAge(BirthDay, BirthMonth, BirthYear){
	// Find the differences
	var now = new Date();	
	YearDiff = now.getFullYear() - BirthYear;
	MonthDiff = now.getMonth() - BirthMonth;
	DayDiff = now.getDay() - BirthDay;
	// If the birthday has not occured this year
	if (DayDiff < 0 || MonthDiff < 0)
		YearDiff--;
		
	return YearDiff;
}




/* scool up jquery pretty */
function scroll(){

	
	$.scrollTo('#voteTop', {duration:800});
	
}

/* disbale right mosue clikc */
//Disable right mouse click Script

//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com
///////////////////////////////////

function clickIE4(){
if (event.button==2){
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

//-----END Disable right mouse click Script

