/*	-------------------------------------------------------------
	function addEvent(obj, type, fn)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Adds an event listener
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function addEvent( obj, type, fn ){ 
	   if (obj.addEventListener){ 
	      obj.addEventListener( type, fn, false );
	   }
	   else if (obj.attachEvent){ 
	      obj["e"+type+fn] = fn; 
	      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
	      obj.attachEvent( "on"+type, obj[type+fn] ); 
	   } 
	} 
/*	-------------------------------------------------------------
	function clearField(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Clears value of form object
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function clearField(obj,value) {
	if(obj.value==value)
		obj.value = '';
	}
	function resetField(obj,value) {
		if(obj.value=='')
			obj.value = value;
	}
/*	-------------------------------------------------------------
	function controlCoupon(obj,maxTotal,target)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Updates total cost when using coupon
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	var couponTotal = 0;
	function controlCoupon(obj,maxV,target) {
		var v = parseFloat(obj.value);
		var newV = 0.00;
		if (!isNaN(v)) {
		  if(v<maxV&&v>-1)
		  	newV = v;
		  else
		  	newV = maxV;	
		}
		/* set coupon value */
		obj.value = newV.toFixed(2);
		/* update total */		
		var target = document.getElementById(target);
		var total = target.innerHTML;
		
		/* added as was trying to do calculation on non number */
		var temp = new Array();
		temp = total.split('$');
		
		/* remember orignal total */
		if(couponTotal==0)
			couponTotal = temp[1];
		target.innerHTML = "CDN $" + (couponTotal-newV).toFixed(2);
	}
	
/*	-------------------------------------------------------------
	function toggle(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Toggle object between hidden and not hidden
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function toggle(obj) {
		toggleClass(obj,'hidden')
	}
	
/*	-------------------------------------------------------------
	function toggleMultiple(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Shows an object and hides an object
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function toggleMultiple(objShow,objHide) {
		showObject(objShow);
		hideObject(objHide);
	}
/*	-------------------------------------------------------------
	function toggleTabs(activeTab,noOfTabs,tabPrefix)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Sets tab to visible and hides others
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/	
	function toggleTabs(activeTab,noOfTabs,tabPrefix) {
		for (i=1;i<=noOfTabs;i++) {
			if(i==activeTab) {
				removeClass(''+ tabPrefix +'-tab-'+i+'-plinth','hidden');
				addClass(''+ tabPrefix +'-tab-'+i+'-link','active');
			}
			else
			{
				addClass(''+ tabPrefix +'-tab-'+i+'-plinth','hidden');
				removeClass(''+ tabPrefix +'-tab-'+i+'-link','active');
			}
		}
	}
/*	-------------------------------------------------------------
	function toggleTab(activeTab,noOfTabs)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Sets tab to visible and hides others
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/	
	function toggleTab(activeTab,noOfTabs) {
		for (i=1;i<=noOfTabs;i++) {
			if(i==activeTab) {
				removeClass("tab-"+i+"-plinth","hidden");
				addClass('tab-'+i+'-link','active');
			}
			else
			{
				addClass('tab-'+i+'-plinth','hidden');
				removeClass('tab-'+i+'-link','active');
			}
		}
	}
/*	-------------------------------------------------------------
	function addClass(obj,cssClass)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Adds class to object keeping current classes
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function addClass(obj,cssClass) {
		var object = document.getElementById(obj);
		var str = object.className;
		if(str.indexOf(cssClass)<0)
			str = str + " " + cssClass;
		object.className = str;
	}
/*	-------------------------------------------------------------
	function removeClass(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Removes class from object if exists
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function removeClass(obj,cssClass) {
		var object = document.getElementById(obj);
		var str = object.className;
		if(str.indexOf(cssClass)>-1)
			str = str.replace(cssClass,'');	
		object.className = str;
	}
/*	-------------------------------------------------------------
	function toggleClass(obj,cssClass)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Toggle class of object
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function toggleClass(obj,cssClass) {
		var object = document.getElementById(obj);
		var str = object.className;
		if(str.indexOf(cssClass)>-1)
			str = str.replace(cssClass,'');
		else
			str = str + " " + cssClass;
		object.className = str;
	}

/*	-------------------------------------------------------------
	function hideObject(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Sets objects class to hidden
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function hideObject(obj) {
		addClass(obj,'hidden')
	}

/*	-------------------------------------------------------------
	function showObject(obj)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Removes class hidden from object
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function showObject(obj) {
		removeClass(obj,'hidden')
		if(obj == 'sendtofriend'){
		getPosition(obj);
		}
	}
/*	-------------------------------------------------------------
	function toggleImage
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Change image src
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	function toggleImage(obj,src) {
  	object = document.getElementById(obj);
		object.src = src; }
/* ---------------------------------------------------------------
	function possition floating div
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- -
	Description: position send to a friend floating div
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
	function getPosition(div){
	var thediv = document.getElementById(div);
	
	var scrollY;
      
      if (document.all)
      {     
         if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
         else
            scrollY = document.documentElement.scrollTop;
      }   
      else
      {
         scrollY = window.pageYOffset;
      }

		thediv.style.top = (scrollY+140)+"px";
		thediv.style.left = (document.body.offsetWidth/2.25)+"px";

}

function getWindowWidth() {
	// Default to screen dimensions.
	var winW = window.screen.width;
	// Attempt to retrieve browser window dimensions.
	if (window.innerWidth) {
		winW = window.innerWidth;
	} else {
		if (document.documentElement.offsetWidth) { winW = document.documentElement.offsetWidth; } else if (document.body.offsetWidth) { winW = document.body.offsetWidth; }
	}
	return winW;
}

function bodyClass() {
	var bodyLayout = $("body").attr("class");
	var broswerWidth = getWindowWidth();
	if (broswerWidth < 810) {
		if (bodyLayout.indexOf('two-col')>-1) { $("body").addClass("lowres-two-col"); }
		if (bodyLayout.indexOf('one-col')>-1) { $("body").addClass("lowres-one-col"); }
		$("body").removeClass("hires").addClass("lowres");
	}
	if (broswerWidth > 1080) {
		if ((bodyLayout.indexOf('two-col')>-1) || (bodyLayout.indexOf('one-col')>-1)) { $("body").removeClass("lowres-two-col").removeClass("lowres-two-col"); }
		$("body").removeClass("lowres").addClass("hires");
	}
	if ((broswerWidth > 810) && (broswerWidth < 1080) ) { $("body").removeClass("lowres").removeClass("lowres-one-col").removeClass("lowres-two-col").removeClass("hires"); }
}
