var activeColor='#0098da';

function loginResponse(response,url){
	if( response >0){
		document.location=url;	
	}else{
		ShowModalBox('/connection.php?ttype=normal&url='+url,'Connection'	);
	}
}

function checkProtected(url){
	var dest = '/confirmModal.php';
	var myAjax = new Ajax.Request(
		dest,
		{
		method: 'get',
		parameters: {todo: 'isLoged'},
		onComplete:function(t){loginResponse(t.responseText,url);}
		});	
}
function ShowModalWithLink(url,msg,theAnchor){
	removeVisitedColor();
	var strClose='&times;';
	Modalbox.show(url,{ closeString:'Fermer la fenêtre',closeValue: strClose, title: msg, afterHide:function(){var t=document.getElementById(theAnchor);t.style.color=activeColor;}})
}
function ShowModalBox(url,msg){
	var strClose='&times;';
	Modalbox.show(url,{ closeString:'Fermer la fenêtre',closeValue: strClose, title: msg});
}
function ShowModalThumbnails(url,recetteNo,picId){
	var strClose='&times;';
	var msg='Confirmation';
	Modalbox.show(url,{ closeString:'Fermer la fenêtre',closeValue: strClose, title: msg,beforeLoad:function(){removeImage(picId);}, afterHide:function(){getThumnails(recetteNo)}});
}
function ShowModalThumbnailsNewRecette(url,user_id,picId){
	var strClose='&times;';
	var msg='Confirmation';
	Modalbox.show(url,{ closeString:'Fermer la fenêtre',closeValue: strClose, title: msg,beforeLoad:function(){removeImage(picId);}, afterHide:function(){getThumnailsNewRecette(user_id)}});
}
function ShowModalBoxDisableSelect(url,msg){
	var strClose='&times;';
	Modalbox.show(url,{ closeString:'Fermer la fenêtre',closeValue: strClose, title: msg,onShow:function(){document.onmousedown=reEnable;},afterHide:function(){document.onmousedown=disableselect;}});
}
function ShowModalVoir(url,msg,frm){
	var strClose='&times;';
	Modalbox.show(url,{closeString:'Fermer la fenêtre',closeValue: strClose, title: msg,method: 'post' , params: Form.serialize(frm), afterHide:function(){document.location='goToRecette.php?no='+frm.no.value}}); 
}
function removeBadChard(str){
	str=str.replace(/œ/g,'oe');
	str=str.replace	(/’/g,'\'');
	return str;
}
function removeVisitedColor(){
	for (i=0; i<document.links.length; i++) {
		if (document.links[i].style.color==activeColor ||document.links[i].style.color=='rgb(0, 152, 218)' ){
			document.links[i].style.color='';
		}
	}
}
function getThumnails(recetteNo){
		var url='confirm.php';	
 		var myAjax = new Ajax.Request(
		  url,
		  {
			method: 'get',
			parameters: {todo: 'getThubnails',no:recetteNo},
			onSuccess:function(xtr){
				$('thumbnails').innerHTML=xtr.responseText;
				if($('thumbnails').innerHTML =='')$('thumbnails').setStyle({display:'none'})
			}
		  });		
}
function getThumnailsNewRecette(id){
		var url='confirm.php';	
 		var myAjax = new Ajax.Request(
		  url,
		  {
			method: 'get',
			parameters: {todo: 'getThubnailsNewRecette',user_id:id},
			onSuccess:function(xtr){
				$('thumbnails').innerHTML=xtr.responseText;
				if($('thumbnails').innerHTML =='')$('thumbnails').setStyle({display:'none'})
			}
		  });		
}
function removeImage(picId){
	var obj=$('comments');
	var str='[fullalbumimg]'+picId+'[/fullalbumimg]';
	obj.value=obj.value.replace(str,'');
}

function ssoIps() {
	return ssoJumpFormAction('IPS');
}
function ssoJump() {
	var selectedValue= document.ssoJumpForm.ssoJumpList[document.ssoJumpForm.ssoJumpList.selectedIndex].value;
	if (typeof selectedValue != 'undefined' && selectedValue != '') {
		var selectedValueArray = selectedValue.split('#');
		var acctType= selectedValueArray[0];
		var acctIndex= parseInt(selectedValueArray[1], 10);
		if (isNaN(acctIndex)) {
			acctIndex= "";
		}
		ssoJumpFormAction(acctType, acctIndex);
	}
	return false;
}
function ssoUpdateFormAction(acctType, acctIndex) {
	// open within the same target window by default
	document.ssoJumpForm.target= "";
	document.ssoJumpForm.ssoJumpAccount.value= acctIndex;
	document.ssoJumpForm.ssoJumpType.value= acctType;
	set(document.ssoJumpForm, '/OLB/fin/sum/null/ssoAm?mode=form3');
	document.ssoJumpForm.submit();
	return false;
}
function ssoJumpFormAction(acctType, acctIndex) {
	// rename the window to make sure that CFM always opens as a popup
	window.name="main";
	// open within the same target window by default
	document.ssoJumpForm.target= "";
	document.ssoJumpForm.ssoJumpAccount.value= acctIndex;
	document.ssoJumpForm.ssoJumpType.value= acctType;
	if (acctType == il || acctType == nb || acctType == mc) {
		var popupText = "VEUILLEZ NOTER:";
		popupText+= "\n\nNous vous transférons automatiquement au site ";
		if (acctType == il) {
			popupText+= "BMO Ligne D'Action";
		} else if (acctType == nb) {
			popupText+= "BMO Nesbitt Burns";
		} else if (acctType == mc) {
			popupText+= "MasterCard";
		}
		popupText+= ". Vous n'aurez pas besoin d'entrer votre nom d'utilisateur et votre mot de passe.";
		popupText+= "\n\nVous pouvez retourner aux services bancaires en ligne en tout temps en choisissant « Services bancaires en ligne » dans le menu déroulant qui apparaît dans le coin supérieur droit de chaque page.";
		popupText+= "\n\nPour votre protection, la session des Services bancaires en ligne sera maintenant interrompue. Lorsque vous accéderez de nouveau aux Services bancaires en ligne, la date et l’heure de la \"dernière session\" auront été mises à jour.";
		popupText+= "\n\nPar mesure de sécurité, votre session bancaire en ligne sera interrompue. Une nouvelle session commencera lorsque vous retournerez à la page des services bancaires en ligne.";
		popupText+= "\n\nCe transfert peut prendre quelques instants. Ne cliquez pas sur le bouton « Précédent » de votre navigateur avant d'avoir utilisé l'autre site pour empêcher la fermeture de toutes vos applications (cette caractéristique vise à assurer votre sécurité).";
		// ask user to confirm and if the answer is "OK" - submit
		if (confirm(popupText)) {
			if (acctType == mc) {
				set(document.ssoJumpForm, '/OLBmain/ssoMc');
			} else {
				set(document.ssoJumpForm, '/OLBmain/ssoAm');
			}
			document.ssoJumpForm.submit();
		}
	} else if (acctType == 'CFM' || acctType == 'IPS' || acctType == 'IL' || 
				acctType == 'NB' || acctType == 'MMC' || acctType == 'OMC') {
		// default forward (new window)
		defaultWindowHandler = window.open('',"window_" + acctType,'width=640,height=480,top=50,left=150,toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no');
		document.ssoJumpForm.target= "window_" + acctType;
		set(document.ssoJumpForm, '/OLBmain/ssoDefault');
		document.ssoJumpForm.submit();
	} else {
		// CFM will popup in a new window
		keep = null;
		document.ssoJumpForm.target= "cfmWindow";
		set(document.ssoJumpForm, '/OLBmain/ssoCfm');
		top.cfmWindowHandler = window.open('','cfmWindow','width=640,height=480,top=50,left=150,toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no');
		document.ssoJumpForm.submit();
		top.cfmWindowHandler.focus();
	}
	return false;
}
function closePopups() {
	if (top.cfmWindowHandler) {
		top.cfmWindowHandler.close();
	}
	if (top.cfmWindow) {
		top.cfmWindow.close();
	}
	return true;
}
/* Pop up window for all external links */
function confirmation(url){
	Popup(url,11);
	//window.showModalDialog(url,"","dialogWidth:480px;dialogHeight:200px");
}
function Popup(myUrl,popType) {
	var winName='olb_popup';
	var winTop=50;
	var winLeft=150;
	var d = new Date();
	var winTime = d.getUTCHours()+'_'+d.getUTCMinutes()+'_'+d.getUTCSeconds();
	switch (popType) {
		case 1:   // tools & info/help section - max size pop up, full too bar, resizable, scrollbars
		  	popup = window.open(myUrl,winName+winTime,'width=640,height=480,top=' + winTop + ',left=' + winLeft + ',toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no');
		break
		case 2:  // olb tool/message  - max pop up size, no tool bar, not resizable, scrolling if necessary
		  popup = window.open(myUrl,winName+winTime,'width=640,height=480,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
		case 3:  // olb tool/message  - smaller pop up size, no tool bar, not resizable, scrolling if necessary
		  popup = window.open(myUrl,winName+winTime,'width=480,height=360,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
		case 4:  // calendars  - smallest pop up size, no tool bar, not resizable, scrolling if necessary
		  popup = window.open(myUrl,winName+winTime,'width=360,height=360,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
		case 5:  // popups within popups  - smallest pop up size, no tool bar, not resizable, scrolling if necessary
			winTop=100;
			winLeft=200;
	  	popup = window.open(myUrl,winName+winTime,'width=640,height=480,top=' + winTop + ',left=' + winLeft + ',toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=no,copyhistory=no');
		break
		case 6:  // printer friendly pages
		  popup = window.open(myUrl,winName+winTime,'width=600,height=480,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
// these are NOT in the style guide
//		case 7:  // olb tool/message  - max pop up size, no tool bar, not resizable, scrolling if necessary
//		  popup = window.open(myUrl,winName+winTime,'width=800,height=450,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
//		break
//		case 8:  // Sign In pages's forgotton password.
//		  popup = window.open(myUrl,winName+winTime,'width=480,height=360,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
//		break
		case 9:  // EMT Tour Only (Not Part of Style Guide)
		  popup = window.open(myUrl,winName+winTime,'width=800,height=600,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
		case 10:  // Contact Us / Locate Us Popup (Not Part of Style Guide)
		  popup = window.open(myUrl,winName+winTime,'width=775,height=550,top=-25,left=125,toolbar=no,scrollbars=0,resizable=0,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		break
		// For recettes
		case 11:  // olb tool/message  - smaller pop up size, no tool bar, not resizable, scrolling if necessary
		  popup = window.open(myUrl,'confirmation','width=480,height=200,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		  break;
	  case 12:  // calander  - smaller pop up size, no tool bar, not resizable, scrolling if necessary
	 		bl=new bw_check();if(bl.ns6){
				popup = window.open(myUrl,'Menu','width=255,height=210,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
			}else{
			  popup = window.open(myUrl,'Menu','width=220,height=203,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
			 }
		  break;
		// addItems
	 case 14:  // addItems  - smaller pop up size, no tool bar, not resizable, scrolling if necessary
	 	//	alert(bw_check());
		  popup = window.open(myUrl,'Menu','width=500,height=235,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,copyhistory=no');
		  break;
	}
	popup.focus();
}
function selectAll(formname,checkType) {
	var idx, theCheckbox;
	idx = 0;
	theCheckbox = eval("document." + formname + "." + checkType + idx);
	while (typeof(theCheckbox) == "object")
	{
		theCheckbox.checked = true
		idx++;
		theCheckbox = eval("document." + formname + "." + checkType + idx);
	}
}
function selectAll_1(formname,checkType) {
	var idx, theCheckbox;
	idx = 0;
	theCheckbox = eval("document." + formname + "." + checkType);
	while (typeof(theCheckbox) == "object")
	{
		try {
			theCheckbox[idx].checked = true;
		
			idx++;
			theCheckbox = eval("document." + formname + "." + checkType);
		} catch (ex){
			//one element only
			theCheckbox.checked = true;
			return;
		}
	}
}
function openB2CWindow(URL) {
	window.open(URL,"B2C_PARENT","width=640,height=480,top=50,left=150,toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no");
}
function clearAll(formname,checkType) {
	var idx, theCheckbox;
	idx = 0;
	theCheckbox = eval("document." + formname + "." + checkType + idx);
	while (typeof(theCheckbox) == "object")
	{
		theCheckbox.checked = false
		idx++;
		theCheckbox = eval("document." + formname + "." + checkType + idx);
	}
}
function clearAll_1(formname,checkType) {
	var idx, theCheckbox;
	idx = 0;
	theCheckbox = eval("document." + formname + "." + checkType);
	while (typeof(theCheckbox) == "object")
	{
		try {
			theCheckbox[idx].checked = false;
			idx++;
			theCheckbox = eval("document." + formname + "." + checkType);
		} catch (ex){
			//one element only
			theCheckbox.checked = false;
			return;
		}
	}
}
function changeAll(formname,checkType,ifChecked) {
	var idx, theCheckbox;
	if (eval(ifChecked)) {
		idx = 0;
		theCheckbox = eval("document." + formname + "." + checkType + idx);
		while (typeof(theCheckbox) == "object")
		{
			theCheckbox.checked = true
			idx++;
			theCheckbox = eval("document." + formname + "." + checkType + idx);
		}		
	} else {
		idx = 0;
		theCheckbox = eval("document." + formname + "." + checkType + idx);
		while (typeof(theCheckbox) == "object")
		{
			theCheckbox.checked = false
			idx++;
			theCheckbox = eval("document." + formname + "." + checkType + idx);
		}
	}
}
//sets the number of 'checked' checkboxes in the 'counter' field of 'formname'
function processCheckboxes(formname,checkType,counter) {
		
	var idx = 0;
	var count = 0;
	var theCheckbox = eval("document." + formname + "." + checkType);
	var counter = eval("document." + formname + "." + counter);
	
	while (typeof(theCheckbox) == "object")	{
		try {			
			if (theCheckbox[idx].checked == true) {
				counter.value = ++count; 
			}
		} catch (ex) {
			//there is only one checkbox on the form
			if (theCheckbox.checked == true) {
				counter.value = ++count; 
			}
				
			return;
		}
		idx++;
		theCheckbox = eval("document." + formname + "." + checkType);
	}
   	return ;	
}
function resetMe() {
	document.form1.reset();
}
function goHere(loc) {
	this.location.href=loc;
}
function filter (imagename, objectsrc) {
	if (document.images) {
	document.images[imagename].src=eval(objectsrc+".src")
	}
}
/* main tab rolloves */
/*
if (document.images) {
	chinese = new Image;
	chinese_on = new Image;
	finsum = new Image;
	finsum_on = new Image;
	billpay = new Image;
	billpay_on = new Image;
	transfers = new Image;
	transfers_on = new Image;
	messcent = new Image;
	messcent_on = new Image;
	persinfo = new Image;
	persinfo_on = new Image;
	accnts = new Image;
	accnts_on = new Image;
	invest = new Image;
	invest_on = new Image;
	mortlons = new Image;
	mortlons_on = new Image;
	chinese.src = "/images/chinese.gif";
	chinese_on.src = "/images/chinese_on.gif";
	finsum.src = "/images/fr/finsum.gif";
	finsum_on.src = "/images/fr/finsum_on.gif";
	
	billpay.src = "/images/fr/billpay.gif";
	billpay_on.src = "/images/fr/billpay_on.gif";
	
	transfers.src = "/images/fr/transfers.gif";
	transfers_on.src = "/images/fr/transfers_on.gif";
	
	messcent.src = "/images/fr/messcent.gif";
	messcent_on.src = "/images/fr/messcent_on.gif";
	
	persinfo.src = "/images/fr/persinfo.gif";
	persinfo_on.src = "/images/fr/persinfo_on.gif";
	accnts.src = "/images/fr/accnts.gif";
	accnts_on.src = "/images/fr/accnts_on.gif";
	invest.src = "/images/fr/invest.gif";
	invest_on.src = "/images/fr/invest_on.gif";
	mortlons.src = "/images/fr/mortlons.gif";
	mortlons_on.src = "/images/fr/mortlons_on.gif";
}
*/				
function isPresent(the_value,list)
{
	    var token_array = list.split('&');
        var i;
        if(document.EmtSendForm.list)
        {
        	if(document.EmtSendForm.list.value=="###")
        	{
                for(i=0;i<token_array.length;i++)
                {
       					if(token_array[i].toUpperCase() == the_value.toUpperCase())
                        {
                                return true;
                        }
                }
                return false;
                }
        	else
        	{
        		return false;
        	}
        }
        else
        {
                return false;
        }
}
//*******************************************************************************
// * Function Name: openStaticPopUp
// * 
// * Parameters:
// *   URL		URL to display in the popup
// *   windowName	windowName as per the javascript window.open definition
// *			(the window name can be anything for the purposes of this
// *			 function)
// *
// * Description:
// *   Opens a pop up browser window with the URL that is passed in. This function
// *   is sensitive to the size of the screen and resizes and repositions the 
// *   popup accordingly
// ******************************************************************************/
function openStaticPopUp(URL,windowName)
{
// If the screen resolution in 800x600 then 
	if(screen.availWidth==800)
	{
		top.viewWin = window.open(URL, windowName, "width=680,height=490,top=20,left=60,scrollbars=1,toolbar=0,resizable=1,menubar=0,location=0,status=0,fullscreen=0,directories=0,channelmode=0");
	}
	else
	{
		top.viewWin = window.open(URL, windowName, "width=680,height=490,top=70,left=200,scrollbars=1,toolbar=0,resizable=1,menubar=0,location=0,status=0,fullscreen=0,directories=0,channelmode=0");
	}
}
function bw_check()
{
    var is_major = parseInt( navigator.appVersion );
    this.nver = is_major;
    this.ver = navigator.appVersion;
    this.agent = navigator.userAgent;
    this.dom = document.getElementById ? 1 : 0;
    this.opera = window.opera ? 1 : 0;
    this.ie5 = ( this.ver.indexOf( "MSIE 5" ) > -1 && this.dom && !this.opera ) ? 1 : 0;
    this.ie6 = ( this.ver.indexOf( "MSIE 6" ) > -1 && this.dom && !this.opera ) ? 1 : 0;
    this.ie4 = ( document.all && !this.dom && !this.opera ) ? 1 : 0;
    this.ie = this.ie4 || this.ie5 || this.ie6;
    this.mac = this.agent.indexOf( "Mac" ) > -1;
    this.ns6 = ( this.dom && parseInt( this.ver ) >= 5 ) ? 1 : 0;
    this.ie3 = ( this.ver.indexOf( "MSIE" ) && ( is_major < 4 ) );
    this.hotjava = ( this.agent.toLowerCase().indexOf( 'hotjava' ) != -1 ) ? 1 : 0;
    this.ns4 = ( document.layers && !this.dom && !this.hotjava ) ? 1 : 0;
    this.bw = ( this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera );
    this.ver3 = ( this.hotjava || this.ie3 );
    this.opera7 = ( ( this.agent.toLowerCase().indexOf( 'opera 7' ) > -1 ) || ( this.agent.toLowerCase().indexOf( 'opera/7' ) > -1 ) );
    this.operaOld = this.opera && !this.opera7;
    return this;
};
function sendRecherche(){
		// pour la page de voirRecettes
		var strSearch="";
		var valeur="Ingrédient "
		var url="recherche.php?displayType=recherche&todo=search&SearchType=0&search_word=";
		for(i=1;i<5;i++){
			var name="ingredient"+i;
			var e= document.getElementById(name);
			var val=e.value
			if(e.value.indexOf(valeur+i)<0){
				strSearch += e.value+"+"		   
			}
			
		}
		strSearch=strSearch.substr(0,strSearch.length-1);
		document.location=url+strSearch;
	}