// ### DETECTION BROWSER ###

// Retourne strBrowser=NN si Netscape Navigator ou strBrowser=IE si MSIE
var strBrowser = "IE";
if (navigator.appName.substring(0,8) == "Netscape") strBrowser = "NN";
if (navigator.appName.substring(0,9) == "Microsoft" && navigator.appVersion.indexOf("Win") > 0 ) strBrowser = "IE";

// Detection browser
var browser;
var isIE4 = (document.all) ? true:false; 
if (isIE4) { 
	if (navigator.userAgent.indexOf('MSIE 6') > 0) { 
		browser = 'IE6';
	} else if (navigator.userAgent.indexOf('MSIE 5') > 0) { 
		browser = 'IE5';
	} else {
		browser = 'IE4';
	} 
} else {
	if (navigator.userAgent.indexOf('Netscape/7') > 0) { 
		browser = 'NN7';
	} else if (navigator.userAgent.indexOf('Netscape/6') > 0) { 
		browser = 'NN6';
	} else {
		browser = 'NN4';
	} 
} 

// Détection Mac
var OS;
if (navigator.appVersion.indexOf("Mac") != -1) {
	OS = 'mac'; 
} else {
	OS = 'win'; 
}

// ########## ROLLOVERS ##########

function switchToOn(imgName, sourceName) {
	if (sourceName == null) {
		imgOn = eval(imgName + "ON.src");
	} else {
		imgOn = eval(sourceName + "ON.src");
	}
	document[imgName].src = imgOn;
}

function switchToOff(imgName, sourceName) {
	if (sourceName == null) {
		imgOff = eval(imgName + "OFF.src");
	} else {
		imgOff = eval(sourceName + "OFF.src");
	}
	document[imgName].src = imgOff;
}

// ######## COMPTEUR TEXTE #######

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

// ######## VALIDATION NUM #######

function isNumeric(strString) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	for (i = 0; i<strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

// ######## VALIDATION @@@ #######

function checkEmail(strInput) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(strInput);
}

// ######## FORMULAIRES ########

// Vérifie les renseignements pour l'abonnement aux bulletins
function checkAbonnementBulletins(strPrenom, strNom, strCourriel, strCourrielConfirme) {
	
	var strMessage = 'Erreur(s) :\n';
	
	if (strPrenom == '') {
		strMessage += 'Veuillez entrer votre prénom.\n';
	}
	
	if (strNom == '') {
		strMessage += 'Veuillez entrer votre nom.\n';
	}
	
	if (strCourriel == '') {
		strMessage += 'Veuillez entrer votre adresse de courriel.\n';
	} else if (!checkEmail(strCourriel)) {
		strMessage += 'Votre adresse de courriel ne semble pas valide.\n';
	} else {
		if (strCourrielConfirme == '') {
			strMessage += 'Veuillez confirmer votre adresse de courriel.\n';
		} else if (strCourriel != strCourrielConfirme) {
			strMessage += 'Votre adresse de courriel ne correspond pas à votre confirmation.\n';
		}
	}
	
	if (strMessage != 'Erreur(s) :\n') {
		alert(strMessage);
		return false;  
	} else {
		return true;
	}
	
}


// Vérifie l'entrée lors de l'upload d'une photo
function checkPhoto(strPhoto, strReturnURL) {
	if (strPhoto == '') {
		var isConfirmed = confirm ('Attention!\nSi vous laissez ce champ vide et qu\'une photo fait actuellement\npartie de votre profil celle-ci sera effacée.\nVoulez-vous continuer?');
		if (isConfirmed) {
			return true;
		} else {
			self.location.href = strReturnURL;
			return false;
		}
	} else {
		return true;
	}
}


// Vérifie les entrées lors d'une ouverture de session
function checkOuvrirSession(strCourriel, strPassword) {

	var strMessageErreur = 'Erreur(s) :\n';
	
	if (strCourriel == '') {
		strMessageErreur += 'Veuillez entrer votre adresse de courriel.\n';
	} else if (!checkEmail(strCourriel)) {
		strMessageErreur += 'Votre adresse de courriel ne semble pas valide.\n';
	}
	
	if (strPassword == '') {
		strMessageErreur += 'Veuillez entrer votre mot de passe.\n';
	}
	
	if (strMessageErreur != 'Erreur(s) :\n') {
		alert(strMessageErreur);
		return false;  
	} else {
		return true;
	}

}

// Clean du champ recherche
var isCleaned = false;
function  cleanRecherche(oChampRecherche) {
	if (!isCleaned) {
		oChampRecherche.value = '';
		isCleaned = true;
	}
}

var isCleaned = false;
function cleanJoueur(oChampJoueur) {
    if (!isCleaned) {
        oChampJoueur.value = '';
        isCleaned = true;
    }
}

// ######## FORMULAIRES ########



// ######## POP-UPS ########

function popupMap(strPage, intWidth, intHeight, strOptions) {
	var intTop = (screen.height-intHeight)/2;
	var intLeft = (screen.width-intWidth)/2;
	window.open(strPage, "", "top=" + intTop + ",left=" + intLeft + ",width=" + intWidth + ",height=" + intHeight + "," + strOptions);
}

var oTrailerWindow = '';
function openTrailerWindow(strURLTrailer, strFilmTitle) {
	self.name = "MainWindow";
	strURL = '/cinema/trailers.aspx?URL=' + escape(strURLTrailer) + '&Film=' + escape(strFilmTitle);
	if (oTrailerWindow.location && !oTrailerWindow.closed) {
		oTrailerWindow.location.href = strURL;
	} else {
		intDimX = 550;
		intDimY = 510;
		if (strBrowser = "IE") intDimY = intDimY-0; //correction pour MSIE
		strFeatures = "top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + intDimX + ",height=" + intDimY;
		oTrailerWindow = window.open(strURL, 'Trailers', strFeatures);
		if (!oTrailerWindow.opener) oTrailerWindow.opener = self;
	}
	if (window.focus) oTrailerWindow.focus();
}

function popup(page, parametre)
{ 
window.open(page,'',parametre); 
} 

// ######## POP-UPS ########



// ######## PAGE PRÉCÉDENTE ########

function precedente()
{
	window.history.back();
}

// ######## PAGE PRÉCÉDENTE ########



// ######## FERMER LA FENETRE ########
function Fermer() 
{ 
opener=self; 
self.close(); 
}
// ######## FERMER LA FENETRE ########



// ######## TOOLTIPS ########

var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0

if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}

var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo

if(ie){
Ex = "event.x"
Ey = "event.y"

topColor = "#7D92A9"
subColor = "#A5B4C4"
}

if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere

topColor = "#7D92A9"
subColor = "#A5B4C4"
}

function MoveToolTip(layerName, FromTop, FromLeft, e){
if(ie){eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.body.scrollTop))}
if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop))}
eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
}

function ReplaceContent(layerName){

if(ie){document.all[layerName].innerHTML = ContentInfo}

if(ns){

with(document.layers[layerName].document) 
{ 
   open(); 
   write(ContentInfo); 
   close(); 
}

}

}

function Activate(){initialize=1}
function deActivate(){initialize=0}

function overhere(e){
if(initialize){

MoveToolTip("ToolTip", Ey, Ex, e)
eval(doc + "ToolTip" + sty + ".visibility = 'visible'")
}

else{
MoveToolTip("ToolTip", 0, 0)
eval(doc + "ToolTip" + sty + ".visibility = 'hidden'")
}

}

function EnterContent(layerName, TTitle, TContent){

ContentInfo = '<table border="0" width="220" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="97%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="95%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>';

ReplaceContent(layerName)

}

// ######## TOOLTIPS ########

function displaynone(document_name) {
    document.getElementById(document_name).style.display = 'none';
}

function changepic(img_name, img_src) {
    document[img_name].src = img_src;
}

function clearlabel(lbl_name, lbl_text) {
    document.getElementById(lbl_name).innerHTML = lbl_text;
}




// ########### FONCTION DE L'OBJET AJAXCONTROLTOOLKIT /USERCONTROLS/COMMON/ANIMATIONPOPUP.ASCX ###############
// Move an element directly on top of another element (and optionally  
// make it the same size).  
function CoverAnimationAjax(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}  