/* Shorcut jQuery pour no conflict avec Prototype.js */
var $j = jQuery.noConflict();



/* Cookies */
function set_cookie(name, value, nDays, path, domain, secure) {
	var cookie_string = name + "=" + escape(value);

	if (nDays) {
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    	cookie_string += "; expires=" + expire.toGMTString();
	}

	cookie_string += (path)   ? "; path=" + escape(path) : "";
    cookie_string += (domain) ? "; domain=" + escape(domain) : "";
	cookie_string += (secure) ? "; secure" : "";

	document.cookie = cookie_string;
}

function get_cookie(cookie_name) {
	var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

	if (results)
		return unescape(results[2]);
	else
		return null;
}

function delete_cookie(cookie_name) {
	var cookie_date = new Date ();
	cookie_date.setTime(cookie_date.getTime() - 1);
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


function printThisPage() {
	window.print();
}

/**
 * Set max-height universel
 */
function setMaxHeight(jElement, height) {
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		// setExpression ne semble pas marcher avec les popups
		jElement.css("height", height);
	} else {
		jElement.css("max-height", height);
	}
}



/**
 * Functions pour le rollover des images
 */
var Rollover = {
    restorationHolder : new Array(),

    /**
     * onmouseout
     *
     * Plusieurs swap peut arriver en meme temps, on les restore tous
     */
    restore: function() {
		$j.each(Rollover.restorationHolder, function(index, item){
			var jElement = $j("#"+item);
			var imageSrc = jElement.data("normal");
			jElement.attr("src", imageSrc);
		});

		Rollover.restorationHolder = new Array();
    },


    /**
     * onmouseover
     *
     * imageSrc est optionnel, si elle n'est pas inclus, on fais un rollover
     * avec l'image qui a le meme nom avec "-over" de append.
     */
    swap: function(elemId, imageSrc) {
    	var jElement = $j("#"+elemId);
    	var currentImg = jElement.attr("src");

    	jElement.data("normal", currentImg);
    	jElement.attr("src", imageSrc);

    	Rollover.restorationHolder.push(elemId);
    }
}


/**
 * Background change on rollover
 *
 *  Change the background image of another element on rollover 
 *  ** Note: This is an image slider - therefore all states of 
 *           the rollover must be within the same image!       
 */
function changeBackground(elementID,imgPos) {
	var imgHome = document.getElementById(elementID);
	imgHome.style.left = imgPos + "px";
}


/**
 * Changer le cursor
 */
var Cursor = {
	toDefault: function() {
		document.body.style.cursor = 'default';
	},

	toWait: function() {
		document.body.style.cursor = 'wait';
	}

}


function changeFontSize(size) {
	$j(".font-size").removeClass("font-size-selected");

	if (size == 'small') {
		set_cookie("fontSize", size);
		jQuery("body").css("font-size", "11px");
		$j("#fontSizeSmall").addClass("font-size-selected");
	}
	if (size == 'normal') {
		delete_cookie("fontSize");
		jQuery("body").css("font-size", "12px");
		$j("#fontSizeNormal").addClass("font-size-selected");
	}
	if (size == 'large') {
		set_cookie("fontSize", size);
		jQuery("body").css("font-size", "13px");
		$j("#fontSizeLarge").addClass("font-size-selected");

	}
}




function createOverlayBackground(elementId, options) {
	var jElement;

	// Test si ca existe, si non, on le cree
	jElement = $j("#" + elementId);
	if (jElement.size() == 0) {
		// ligne du body
		$j("body").prepend("<div id=\"" + elementId + "\" style=\"display: none\"></div>");

		jElement = $j("#" + elementId);
		if (jQuery.browser.msie && jQuery.browser.version < 7) {
			jElement.css("position", "absolute");
			jElement.css("left", "0");
			jElement.css("top", "0");
			jElement.css("height", document.body.offsetHeight);
		} else {
			jElement.css("position", "fixed");
			jElement.css("left", "0");
			jElement.css("top", "0");
			jElement.css("height", "100%");
		}
		jElement.css("background", "#000");
		jElement.css("opacity", "0.5");
		jElement.css("width", "100%");
		jElement.css("z-index", 99);
	}
}


/**
 * Si le id n'existe pas deja, la function cree lui-meme un wrapper autour.
 *
 * options:
 *   onclose : (hide|remove|disabled) or javascriptString; default is hide
 *   body : string
 *   className : string (Style class name)
 */
function createOverlay(elementId, options) {
	this.jElement = null;

	var str = "";
	var testExistId = false;

	options           = options           || {};
	options.onclose   = options.onclose   || "hide";
	options.disableCloseButton = options.disableCloseButton   || "false";
	options.className = options.className || "rp-darkblue";
	options.body      = options.body      || " ";
	options.title     = options.title     || " ";
	options.center    = Boolean(options.center)  || null;
	options.visible   = Boolean(options.visible) || null;
	options.width     = options.width     || null;
	options.height    = options.height    || null;
	

	// Strings
	var overlayCloseBtn  = overlayCloseBtn   || "Close";

	
	// Test si ca existe
	this.jElement = $j("#" + elementId);
	if (this.jElement.size() > 0) {
		testExistId = true;
		options.body = this.jElement.html();
	}

	// ligne du body
	if (testExistId != true) {
		$j("body").prepend("<div id=\"" + elementId + "\" class=\"" + options.className + "\" style=\"display: none\"></div>");
	}

	this.jElement = $j("#" + elementId);


	// Si c'est deja initialized on ne la recree pas.
	init = jElement.data("initialized");
	if (init == true) {
		return; // On a deja cree le overlay
	} else {
		jElement.data("initialized", true);
	}


    // Gestion du Close
	var closeAction = null;
	if (options.onclose != "disabled") {
		if (options.onclose == "remove")      { closeAction = "$j('#" + elementId + "').remove()"; }
		else if (options.onclose == "hide")   { closeAction = "$j('#" + elementId + "').hide()"; }
		else                                  { closeAction = options.onclose; }
	}

	str +=  "<table class=\"rp\">" +
			"<tr>" +
			"	<td class=\"rp-tl\"></td>" +
			"	<td class=\"rp-top\">";

			if (closeAction) {
				str += "<div class=\"rp-close\" onclick=\"" + closeAction + "\" />";
			}

	str +=  "<h1>" + options.title + "</h1>" +
			"</td>" +
			"	<td class=\"rp-tr\"></td>" +
			"</tr><tr>" +
			"	<td class=\"rp-left\"></td>" +
			"	<td class=\"rp-middle\"><div id=\"" + elementId + "-body\" class=\"rp-body\">" + options.body + "</div>";

			if (closeAction && !options.disableCloseButton) {
				str += "<div style=\"text-align:right; padding: 5px;\">";
				str += "<a href=\"javascript:void(0)\" onclick=\"" + closeAction + "\" class=\"rbtn rbtn-blue\"><span>"+ overlayCloseBtn +"</span></a>";
				str += "</div>";
			}

	str +=  "   </td>" +
			"	<td class=\"rp-right\"></td>" +
			"</tr><tr>" +
			"	<td class=\"rp-bl\"></td>" +
			"	<td class=\"rp-bottom\"></td>" +
			"	<td class=\"rp-br\"></td>" +
			"</tr></table>";


	this.jElement.html(str);

	$j(".rp-body").css('position', 'relative');

	// Width
	if (options.width != null) {
		this.jElement.width(options.width);
	}

	// Height
	if (options.height != null) {
		$j("#" + elementId + "-body").css('height', options.height);
		$j("#" + elementId + "-body").css('overflow', 'auto');
	}

	// Keep inside viewport
	keepElementInViewport(elementId);
	
	
	// Centering
	if (options.center == true) {
		centerElement(elementId);
	}

	// Visible
	if (options.visible == true) {
		this.jElement.show();
	} else {
		this.jElement.hide();
	}
	
	
	jElement.css("z-index", 100);

	this.jElement.draggable({handle: $j("#" + elementId + " .rp-top")});

	return this;
}


function showPopupItem(mainContainerId, itemId) {
	var popupElement = $j("#"+ mainContainerId);
	
	if (popupElement.data("lastOpen") != null){
		$j("#" + popupElement.data("lastOpen")).hide();
	} 
	
	$j('#' + itemId).show();
	popupElement.data("lastOpen", itemId);
	popupElement.show();
}






function applyStyles() {
	// Pour IE6 seulement
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		// Transparent PNG
		$j(document).pngFix();
    	// Fix les div qui sont vide
		$j('.clear:empty').css("font-size", '0px');
	}
}


function beforeAjaxRequest() {}

function afterAjaxRequest() {
	applyStyles();
}

/*function initAjax4JSF() {
	try {
		A4J.AJAX.onError = function(req,status,message) {
			alert("Ajax error!! = req=" + req + ", status=" + status + ", message=" + message);
		};
	}
	catch(error) {}
}
*/

function initTopnavSubmenuEvent() {
    // hide menu when user clicks anywhere but the dropdown
    $j(document).mouseup(function(event) {
        var fromDropdown = $j(event.target).parents(".topnav-submenu").length;
        // 0 means the event is not originated from the dropdown
        if (fromDropdown == 0) {
        	$j(".topnav-submenu").hide(200);
        }
    });

    // Les elements qui ont la class 'submenu-handler' sert a faire apparaitre les submenu
    $j(".topnav li").click( function(){
        if ($j(".topnav-submenu", this).css("display") != "block") {
        	$j(".topnav-submenu", this).show(150);
        }
    });
}




<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


//window.onload=montre;
function homemontre(srcTrigger, id) {
	$j(".province").hide();
	
	$j("#" + id).show();
	
	$j(srcTrigger).mouseout(function(){
		$j("#" + id).hide();
	});
}

//
/* if ((screen.width==800) && (screen.height==600))
{
   	window.location="accueil_lower.html";
}
*/

/**
 * Function to call when loading the page. Redirect to the right page when the cookie is there
 */
function loadEvents() {
 // Read the cookie and redirect to the right page
 var c = readCookie('UserNameCogeco');
    if (c == "")          return;
 else 
            document.forms["loginform"].user.value = c;

 var d = readCookie('PasswordCogeco');
    if (d == "")          return;
 else 
            document.forms["loginform"].pass.value = d;
            document.forms["loginform"].rempassword.checked = true;
}


/**
 * This function is called when the language and province are selected.
 * It sets the cookie accordingly
 * It also sets another cookie (see name in header) to say if we should keep the cookie
 */
function selectedEvent() {
 
 if (document.forms["loginform"].rempassword.checked) {
  setCookie('UserNameCogeco', document.forms["loginform"].user.value, 180);
  setCookie('PasswordCogeco', document.forms["loginform"].pass.value, 180);
 }
 else {
  setCookie('UserNameCogeco','',0);
  setCookie('PasswordCogeco','',0);
 }
 return true;
}

/**
 * This function save the url of the login form that was used to access webmail.
 * When a user logs out of webmail we redirect him to this url.
 */
function savePreferences() {
 setCookie('UrlLogoutWebmail', 'https://www.cogeco.ca/portal/fr/webmail_q.html', 1);
}



  function setFocus()
  {
     document.forms[0].elements("userID").focus();
  }





function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=550,height=500');
self.name = "mainWin"; }



  function doLostUserName(){
    document.forms(0).action = 'https://www.cogeco.ca/nwf/user/id/forgot_user_id_qualification.jsp;jsessionid=BAF91D6A6462E189E3AACF3431D038F4';
    document.forms(0).submit();
  }

  function doLostPassword(){
    document.forms(0).action = 'https://www.cogeco.ca/nwf/forgot/password/initiate.do;jsessionid=BAF91D6A6462E189E3AACF3431D038F4';
    document.forms(0).submit();
  }

  function doLogin(){
    document.forms(0).action = 'https://www.cogeco.ca/nwf/login/webuser/initiate.do;jsessionid=BAF91D6A6462E189E3AACF3431D038F4';
    document.forms(0).submit();
  }



function setFocus()
{
 document.forms[0].elements("userID").focus();
}



//window.onload=montre;
//function montre(id) {
//var d = document.getElementById(id);
//	for (var i = 1; i<=10; i++) {
///		if (document.getElementById('faqcontent'+i)) {document.getElementById('faqcontent'+i).style.display='none';}
//	}
//if (d) {d.style.display='block';}
//}




//shwhide
function showHide(shID) {
	if (document.getElementById(shID)) {
	
	 if (document.getElementById(shID+'-show').style.display != 'none')
 {

		 document.getElementById(shID+'-show').style.display = 'none';
		 document.getElementById(shID+'-hide').style.display = 'inline';
		 document.getElementById(shID).style.display = 'block';
 	}
	 else if (document.getElementById(shID+'-show').style.display != 'inline')
	 {

		 document.getElementById(shID+'-show').style.display = 'inline';
		 document.getElementById(shID+'-hide').style.display = 'none';
		 document.getElementById(shID).style.display = 'none';
	 }

 else {
	 document.getElementById(shID+'-show').style.display = 'inline';
	 document.getElementById(shID+'-hide').style.display = 'none';
	 document.getElementById(shID).style.display = 'none';
 }
 }
}

jQuery(document).ready(function(){
	applyStyles();
	initTopnavSubmenuEvent();
	
	$j("#homemenu1, #homemenu2, #homemenu3, #homemenu4").hover(
		function(){$j(this).show();},
		function(){$j(this).hide();}
	);
});