//  
   
// Turn on live watch feature, which will auto-refresh the CSS whenever saving the LESS code)  
//less.env = "development";  
//less.watch();  
 
//-------------------------------------------  
   
  var siteTag = 'ddfi'; 
  var siteLinkRoot = 'http://www.duracelldirect.fi/'; 
  var siteSecRoot = 'https://www.duracelldirect.fi/'; 
  var siteRoot = 'http://www.duracelldirect.fi/'; 
  var siteServRoot = 'http://www.duracelldirect.fi/'; 
  var siteDomain='duracelldirect.fi'; 
  var siteUriPrefix=''; 
    
  function order(locator,qty)     
  {   
	if(!qty) 
		qty=1; 
    if(typeof(locator) == "undefined")     
		this.location=siteServRoot+'e/Shopping.Cart';    
	else   
		this.location=siteServRoot+'e/Shopping.Cart?_action=add&p_surrogate='+locator+'&qty='+qty; 		   
  }     
  //-------------------------------------------   
   
  function orderVpn(vpn, vpn2, qty)    
  {    
	if(!qty)   
		qty=1;   
	if(typeof(vpn) == "undefined")    
		this.location=siteServRoot+'e/Shopping.Cart';    
	else if(typeof(vpn2) == "undefined" || vpn2=='-')    
		this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn+'&qty='+qty;	    
    else    
		this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn+'&qty='+qty+'&vpn2='+vpn2+'&qty2='+qty;    
  } 
  //-------------------------------------------    
  
  function orderTip(tipVpn)   
  {   
	  if(!confirm('WARNING: This power tip can only be used with the 2-Power branded, multi-tip devices shown on this page. Do you wish to continue ordering this power tip?'))  
		  return;  
		orderVpn(tipVpn,'-');  
  }	   
    
//-------------------------------------------    
// check the email address is reasonable:   
function checkEmail(email) {  
	if(!isValidEmail(email)) {  
	  alert('The email address is invalid.\n It should be similar to:\n\n yourname@yourcompany.com\n\nWith no spaces. Please enter it again.');   
	  return false;   
	}  
	return true;   
}  
//-------------------------------------------    
// check the email address is reasonable:   
function isValidEmail(email) {  
	if(isblank(email))   
		return false;   
	email = email.toLowerCase();   
	//  check for one '@':   
	var sections = email.split('@');   
	if(sections.length != 2)   
	return false;   
  
	// now split into sections on '.':   
	var username = sections[0].split('.');   
	var domain = sections[1].split('.');   
	if(domain.length < 2)   
	return false;   
  
	// check the username:   
	for(var i = 0; i < username.length; i++) {  
		if(!isValidEmailSection(username[i]))   
		return false;   
	}  
	// check the domain:   
	for(i = 0; i < domain.length; i++) {  
		if(!isValidEmailSection(domain[i]))   
		return false;   
	}  
	return true;   
}  
//-------------------------------------------    
// check there is a value:   
function isblank(str) {   
	for(var i = 0; i < str.length; i++) {   
		var ch = str.charAt(i);   
		if((ch != ' ') && (ch != '\n') && (ch != '\t'))   
		return false;   
	}   
	return true;   
}   
//-------------------------------------------    
// check this section of an email address is valid   
// a-z 0-9 - . _   
function isValidEmailSection(sec) {   
	if(sec.length < 1)   
	  return false;   
	for(var i = 0; i < sec.length; i++) {   
		var cc = sec.charCodeAt(i);   
		if( ((cc < 97) || (cc > 122)) &&   
			((cc < 48) || (cc > 57)) &&   
			((cc < 45) || (cc > 46)) &&   
			(cc != 95) )   
			return false;   
	}   
	return true;   
}  
  
//-------------------------------------------    
  
function showHelp(helpTopic)   
{   
var win = window.open(siteServRoot+'e/jsp/help/HelpWrapper.jsp?_page='+helpTopic,'_help','status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes, width=650, height=400');   
win.focus();   
}   
  
//-------------------------------------------    
// check there is a value:   
  
function validCardNo(val, min, max)   
{   
var count = 0;   
for(var i = 0; i < val.length; i++)   
{   
  var ch = val.charAt(i);   
  if((ch == '0') || (ch == '1')|| (ch == '2') || (ch == '3') || (ch == '4') ||    
	 (ch == '5') || (ch == '6') || (ch == '7') || (ch == '8') || (ch == '9'))   
	count++;   
  else if(ch != ' ')   
	return false;   
}   
  
if((count.valueOf() < min) || ((count.valueOf() > max) && (max > -1)))   
  return false;   
  
return true;   
}   
 
/**hoverIntent*/  
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);  
  
$(function(){    
	/* sub navigation */   
	var config = {       
		 sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)       
		 interval: 100,  // number = milliseconds for onMouseOver polling interval       
		 over: doOpen,   // function = onMouseOver callback (REQUIRED)       
		 timeout: 50,   // number = milliseconds delay before onMouseOut       
		 out: doClose    // function = onMouseOut callback (REQUIRED)       
	};   
	function doOpen() {   
		$(this).addClass("show-panel"); 
		liRelativeTop = $(this).offset().top - $("div.grid-1").offset().top; 
		ctnAvailSpaceBottom = $("div.grid-1").height() - liRelativeTop; 
		var subPanel = $(this).find("ul"); 
		var subPanelHeight = subPanel.height(); 
		// Check the container available space at bottom, if not enough space, then display sub-panel upwards. 
		if (ctnAvailSpaceBottom < subPanelHeight) 
			subPanel.css("top", -subPanelHeight+$(this).height()+3); 
		// Otherwise it means the container has enough space to let the sub-panel display downward. 
		// Check the browser's bottom space, and display the sub-panel upwards when browser's bottom space is not enough, but has enough top space 
		else { 
			var windowAvailSpaceBottom = $(window).height() + $(window).scrollTop() - $(this).offset().top; 
			if (windowAvailSpaceBottom < subPanelHeight && liRelativeTop > subPanelHeight)  
				subPanel.css("top", -subPanelHeight+$(this).height()+3); 
		} 
	} 
	function doClose() {   
		$(this).removeClass("show-panel"); 
		$(this).find("ul").css("top",0); // reset top 
	}   
	$("li.has-panel").hoverIntent(config);   
	   
	$("ul.prod-thumbs li").hover(function() { 
		// If not the current displaying thumbnail   
		if (!$(this).hasClass("curr")) { 
			$(this).parent().find("li.curr").removeClass("curr"); // Remove effect class on current displaying thumbnail 
			$(this).parent().parent().find("img.prod-img-lg").attr("src",$(this).find("img").attr('src')); // Change the image source on the large image to be currect selected thumbnail's source 
			$(this).addClass("curr"); // Add effect class on currect selected thumbnail   
		}   
	}, function(){}); 
	$("ul.tabs li").click(function() {   
		if (!$(this).hasClass("active")) {   
			var tabCtn = $(this).parent();   
			tabCtn.find("li.active").removeClass("active");   
			$(this).addClass("active");   
			var tabContentCtn = tabCtn.next();   
			tabContentCtn.find(".active").removeClass("active");   
			tabContentCtn.children().eq(tabCtn.children().index(this)).addClass("active");   
		}   
	}); 
	$("li.blob").hover(function() {   
		$(this).addClass("hover");   
	}, function(){   
		$(this).removeClass("hover");   
	});   
	$("ul.listing-product img.prod-img").hover(function() {   
		$(this).addClass("hover");   
	}, function(){   
		$(this).removeClass("hover");   
	});   
	/* Image Roll Over */ 
	$("img.has-roll-over").hover(function() {   
		var offset = $(this).offset();   
		var html = '<img id="roll-over" src="'+$(this).attr("src").replace(/_stamp/g, '')+'"/>';   
		$("body").append(html);   
		$("img#roll-over").css('top',offset.top-100).css('left', offset.left+$(this).width());   
	}, function(){   
		$("img#roll-over").remove();   
	}); 
	/*Add to Cart Button*/ 
	$("input.add-to-cart").click(function(event) { 
		event.preventDefault(); 
		var form=$(this).parent(); 
		if ($(this).hasClass("order-vpn")) 
			orderVpn(form.find("input[name='vpn']").val(),'-',form.find("input[name='qty']").val()); 
		else 
			order(form.find("input[name='p_surrogate']").val(),form.find("input[name='qty']").val()); 
	}); 
        /*Search Box Default Text*/
        var searchBox = $("input#search-box-top");
        if ($.trim(searchBox.val())=='')
                searchBox.val(searchBox.attr('default_text'));
        searchBox.focusin(function() {
                if ($(this).val() == $(this).attr('default_text'))
                        $(this).val('');
        });  
        searchBox.focusout(function() {
                if ($.trim($(this).val()) == '')
                        $(this).val($(this).attr('default_text'));
        });
});  


