/*
 * jQuery Easing v1.1 - http://gsgd.co.uk/sandbox/jquery.easing.php
 *
 * Uses the built in easing capabilities added in jQuery 1.1
 * to offer multiple easing options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
jQuery.easing={easein:function(x,t,b,c,d){return c*(t/=d)*t+b},easeinout:function(x,t,b,c,d){if(t<d/2)return 2*c*t*t/(d*d)+b;var a=t-d/2;return-2*c*a*a/(d*d)+2*c*a/d+c/2+b},easeout:function(x,t,b,c,d){return-c*t*t/(d*d)+2*c*t/d+b},expoin:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(Math.exp(Math.log(c)/d*t))+b},expoout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b},expoinout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}if(t<d/2)return a*(Math.exp(Math.log(c/2)/(d/2)*t))+b;return a*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b},bouncein:function(x,t,b,c,d){return c-jQuery.easing['bounceout'](x,d-t,0,c,d)+b},bounceout:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},bounceinout:function(x,t,b,c,d){if(t<d/2)return jQuery.easing['bouncein'](x,t*2,0,c,d)*.5+b;return jQuery.easing['bounceout'](x,t*2-d,0,c,d)*.5+c*.5+b},elasin:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},elasout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},elasinout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},backin:function(x,t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},backout:function(x,t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},backinout:function(x,t,b,c,d){var s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},linear:function(x,t,b,c,d){return c*t/d+b}};

/**
 * LavaLamp - A menu plugin for jQuery with cool hover effects.
 * @requires jQuery v1.1.3.1 or above
 *
 * http://gmarwaha.com/blog/?p=7
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 0.2.0
 * Requires Jquery 1.2.1 from version 0.2.0 onwards. 
 * For jquery 1.1.x, use version 0.1.0 of lavalamp
 */
(function($){$.fn.lavaLamp=function(o){o=$.extend({fx:"linear",speed:500,click:function(){}},o||{});return this.each(function(){var b=$(this),noop=function(){},$back=$('<li class="back"><div class="left"></div></li>').appendTo(b),$li=$("li",this),curr=$("li.current",this)[0]||$($li[0]).addClass("current")[0];$li.not(".back").hover(function(){move(this)},noop);$(this).hover(noop,function(){move(curr)});$li.click(function(e){setCurr(this);return o.click.apply(this,[e,this])});setCurr(curr);function setCurr(a){$back.css({"left":a.offsetLeft+"px","width":a.offsetWidth+"px"});curr=a};function move(a){$back.each(function(){$(this).dequeue()}).animate({width:a.offsetWidth,left:a.offsetLeft},o.speed,o.fx)}})}})(jQuery);

/***
 * Apotex Canada jQuery functions
 */
$(function(){
	$('.apomenu').attr('class','lavamenu');
	$("#style1, #style2, #style3").lavaLamp({
		fx: "backout",
                speed: 700,
                click: function(event, menuItem) {
		return true;
                }
        });
});

$("#searchfor").focus(function(){
        if (($(this).val().toLowerCase() == "enter terms") || ($(this).val().toLowerCase() == "entrez le terme recherch\u00e9"))
	{ $(this).val(""); }
	$(".searchtext").attr('class', '.defaultsearchtext');
});

$(function(){
    	$(".showpdf").text("");
	$("a[@href$=pdf]").addClass("pdf");
});

function updateCookie(name, value)
{
   if (name != "" && value != "")
   {
      var NewDate = new Date();
      NewDate.setTime(NewDate.getTime()+(24*60*60*1000*31*5));
      document.cookie = name+"="+escape(value)+"; expires="+NewDate.toGMTString()+"; path=/";
   }
}

function Delete_Cookie( name, path, domain ) {

if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}



// Check For Valid License Number

$(document).ready(function(){
	$('form#hp').submit(function() {

		var LicenseCheckForm = document.forms["hp"];

if ((LicenseCheckForm.license.value == "") || (LicenseCheckForm.license.value == "Enter your license number or code") || (LicenseCheckForm.license.value == "entrez votre num\u00e9ro de licence ou de code") || (!document.forms["hp"].HCPCheck.checked))
{
   return false;
}

     if ((LicenseCheckForm.license.value == "Apotex") || (LicenseCheckForm.license.value == "apotex") || (LicenseCheckForm.license.value == "APOTEX")) {
			return true;
		}
		else {

			var response = "";
			for (i = 0, n = LicenseCheckForm.HCPType.length; i < n; i++) {
				if (LicenseCheckForm.HCPType[i].checked) {
					var profession = LicenseCheckForm.HCPType[i].value;
					break;
				}
			}
			
			response = CheckValidLicense(LicenseCheckForm.license.value, LicenseCheckForm.province.value, profession, LicenseCheckForm.HCPCheck.checked);
			
			if ((response == "") && (ProvinceChecked  == "ok") && (LicenseChecked == "ok") && (HCPCheckChecked == "ok")) {
				return true;
			}
			else {
				return false;
			}
			return;
		}
					
		function CheckValidLicense (license, province, profession) {

			// ZA01 = Pharmacist
			// ZA05 = Physician
			// ZA06 = Other Healthcare Professional

			var LicenseError = document.getElementById("errorlicense");
			var error = "";
			var licenseCode = document.getElementById("license");
			switch (province) {
				case "AB":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^[eEsScC0-9]{6}$|^\\d{5}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{4,5}$");
				    }
				    else if (profession == "ZA01")
				    {
				        ValidLicense = new RegExp("^\\d{4}$");
				    }
				    break;
				case "BC":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^\\d{5}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{5,6}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^0?\\d{4}$");
				    }
				    break;
				case "MB":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^\\d{2}\\-?\\d{3}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^1\\d{5}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^\\d{5}$");
				    }
				    break;
				case "NB":
				    if (profession == "ZA05") {
						var str = document.getElementById("license").value;
						var stripStr = str.replace("-", "");
						if ( stripStr.length >= 8 ) {
							LicenseError.className = "error_view";
							error = 1;
							return error;
						}
						else {
							ValidLicense = new RegExp("^\\d{4,5}|^\\d{2}\\-?\\d{5}$");
						}
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^0\\d{5}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^\\d{4}$");
				    }
				    break;
				case "NF":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^[a-zA-Z]\\d{5}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{4,5}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^\\d{2}\\-?\\d{3,4}$");
				    }
				    break;
				case "NT":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^\\d{4}\\-?\\d{4,5}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{1,4}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^\\d{4}\\-?\\d{4,5}$");
				    }
				    break;
				case "NS":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^[a-zA-Z]?\\d{6}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{4,5}$");
				    }
				    else if (profession == "ZA01") {
				        ValidLicense = new RegExp("^\\d{2,4}$");
				    }
				    break;
				case "NU":
				    if (profession == "ZA05") {
				        ValidLicense = new RegExp("^[mM][aAlL][pP](2008)?\\-\\d{3}$");
				    }
				    else if (profession == "ZA06") {
				        ValidLicense = new RegExp("^\\d{1,4}$");
				    }
				    else if (profession == "ZA01") {
						ValidLicense = new RegExp("^[pP][hH][aA][rR](2008)?\\-\\d{3}$");
					}
					break;
				case "ON":
					if (profession == "ZA05") {
						ValidLicense = new RegExp("^\\d{5,6}$");
					}
					else if (profession == "ZA06") {
						ValidLicense = new RegExp("^\\d{7}$|^[a-zA-Z]{2}\\d{5,6}$");
					}
					else if (profession == "ZA01") {
						ValidLicense = new RegExp("^\\d{3,6}$");
					}
					break;
				case "PE":
					if (profession == "ZA05") {
						ValidLicense = new RegExp("^\\d{3}$|^[a-zA-Z]?\\d{4}$");
					}
					else if (profession == "ZA06") {
						ValidLicense = new RegExp("^\\d{4}$");
					}
					else if (profession == "ZA01") {
						ValidLicense = new RegExp("^\\d{4,5}$");
					}
					break;
				case "QC":
					if (profession == "ZA05") {
						ValidLicense = new RegExp("^\\d{2}\\-?\\d{3,4}$");
					}
					else if (profession == "ZA06") {
						ValidLicense = new RegExp("^\\d{6,7}$");
					}
					else if (profession == "ZA01") {
						ValidLicense = "";
						error += validatePq(error);
					}
					break;
				case "SK":
					if (profession == "ZA05") {
						ValidLicense = new RegExp("^(\\d{2})?\\d{4}$");
					}
					else if (profession == "ZA06") {
						ValidLicense = new RegExp("^\\d{4,5}$|^\\d{7}(\\-\\d{3})?$");
					}
					else if (profession == "ZA01") {
						ValidLicense = new RegExp("^[a-zA-Z]\\d{4}$");
					}
					break;
				case "YT":
					if (profession == "ZA05") {
						ValidLicense = new RegExp("^\\d{4}\\-?\\d\\-?\\d{3}$");
					}
					else if (profession == "ZA06") {
						ValidLicense = new RegExp("^\\d{3,4}$");
					}
					else if (profession == "ZA01") {
						ValidLicense = new RegExp("^\\d{4}\\-?\\d\\-?\\d{3}$");
					}
					break;
				}
			try {
				if (license.match(ValidLicense) && error == "" ) {
					throw "valid";
				}
				else {
					throw "invalid";
				}
			}
			catch (isValid) {
				if ((license != "") && (isValid == "invalid")) {
					error = 1;
					LicenseError.className = "error_view";
				}
				else if (isValid == "valid") {
					error = "";
					LicenseError.className = "error_hide";
				}
				else {
					LicenseError.className = "error_hide";
				}
				return error;
			}
		}
		function validatePq (licensecode) {

			var LicenseError = document.getElementById("errorlicense");
			var qcNum = parseInt(document.getElementById("license").value);
			var error = "";
			if ( isNaN(qcNum) == true) {
				LicenseError.className = "error_view";
				error = 1;
			}
			else {
				if ((qcNum >= 1000 && qcNum <= 4999)
				|| (qcNum >= 81101 && qcNum <= 99327)
				|| (qcNum >= 200101 && qcNum <= 210999)) {
					LicenseError.className = "error_hide";
					error= "";
				}
				else {
					LicenseError.className = "error_view";
					error = 1;
				}
			}
		return error;
		}
		
	});
});


