function getCookie(Name){
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

function setCookie(name, value){
	document.cookie = name+"="+value
}

// ================== 
// ! DATE FUNCTIONS   
// ================== 

function parseDate(str) {
    var date = str.split('/'); 
	return new Date(date[2], date[0] - 1, date[1]); 
}
function GetDaysBetweenDates(date1, date2) { 
    return(date2 - date1) / (1000 * 60 * 60 * 24);
}
currentTime = new Date();




function gotoLink(form)

{

var OptionIndex=form.currentLocale.selectedIndex;

parent.location = form.currentLocale.options[OptionIndex].value;

}
function encode_utf8( s ) {
		return encodeURIComponent( s );
	}

// Reset 'submit' so that the form can be submitted again.
function resetTimer() {
	window.clearTimeout(timeoutID);
	window.status = "Enter PIN";
	submit = false;
	document.login.pin.focus();
}

function checkLogin() {
	
	// This is to make sure that the form is submitted only once when
	// the user hits several times on the login button.
	if (submit) {
		alert("Your request is being processed.\nPlease do not hit reload or refresh.\nThis request may take up to a minute to process.");
		return false;
	}
	timeoutID = window.setTimeout("resetTimer()", timeout*1000);
	submit = true;
	
	return true;
}
		
function DoSearch() {
	var searchTerm = encode_utf8(document.getElementById("searchInput").value);
	var path = "/search/search_results.jhtml";
	path = path + "?N=0";
	path = path + "&Ntt=" + searchTerm;
	path = path + "&D=" + searchTerm;

	if (searchTerm.length != 0) {
		window.location = path;
		//alert(searchTerm.length);
	}
	return false;
}

sfHover = function() {     
	if (document.getElementById("nav") != null) {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");     
	for (var i=0; i<sfEls.length; i++) {         
		sfEls[i].onmouseover=function() {             
			this.className+=" sfhover";         
		}         
		sfEls[i].onmouseout=function() {             
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");         
		}     
	} 
}	
} 
sfStorehover = function() {
	if (document.getElementById("storeNav") != null) {
		var sfEls = document.getElementById("storeNav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfStorehover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfStorehover\\b"), "");
			}
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.attachEvent) window.attachEvent("onload", sfStorehover);


function getSearchType ( selectedtype )
{
  document.search.searchType.value = selectedtype ;
  document.search.submit() ;
}
function checkEnter(e)
{
  var characterCode;
  // FOR NETSCAPE
  if (e && e.which) { e = e; characterCode = e.which; }
  else { e = event; characterCode = e.keyCode; }
  // FOR IE
  if (characterCode == 13) { getSearchType('site'); return false; }
  else { return true; }
}
var submit = false;
var timeout = 300;  // 5 minutes.




/* jQuery Functions */
$("img[src$=.png]", ":not(#fdbk_tab)").pngFix();
$(document).ready(function(){

	
	var theDate=new Date();
	var justYear=theDate.getFullYear();				
	$("#footDate").html(justYear);
	
	
	
// =========================== 
// ! load media with inline popup   
// =========================== 

	function loadMod() {
		$("body").prepend("<div id='modBg'></div>");
		 

		$("#modBg").css({
			"display":"block",
			"width":document.documentElement.clientWidth,
			"height":document.documentElement.clientHeight
		});

		$("#modBg").fadeTo("fast", 0.7);
		$("#fdbk_tab").css("zIndex","100");
	}


	$('.itemPath').css("visibility","hidden");
	$(".loadTheMod").css("cursor","pointer");
	$(".loadTheMod").click(function(){
		theItem = $(this).attr('rel').replace(" ","%20");
		loadMod();
		var patt = /\.\w{3}$/g;
		theExt = theItem.match(patt);
		
		if(theExt == ".flv"){
			plrWidth = "534";
			plrHeight = "339";
		}else{ //theExt == ".swf"
			plrWidth = "800";
			plrHeight = "460";
		}		
		
		
		$(".k_float").css("zIndex","100");
		$("body").append("<div id=\"ilLoader\">&nbsp;</div>");
	
		var iLdrCss = {
	        'position' : 'absolute',
	        'width' : '100%',
	        'height' : '50px',
	        'top' : '200px',
	        'z-index' : '2010',
	        'text-align' : 'center',
	        'background' : 'url(\'/images/gui/spinner-loading.gif\') center no-repeat',
	        'overflow':'visible'
	      }

		$("#ilLoader").css(iLdrCss);
		
		$("#ilLoader").load("/common/inline-fla.jhtml?item="+theItem, function(){  //load item container
			$(this).css("backgroundImage","none");
			$("#itemCont").css({
				"width": plrWidth+"px",
				"height": plrHeight+"px",
				"background": "#FFFFFF"
				});
			//alert(plrWidth);
			plroffStW = $("#itemCont object").width();
			cntrWidth = $("#IlCenter").width();
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$("#IlCenter").prepend("<img src=\"/images/gui/closeButton.gif\" id=\"IlClsBut\" />");
			}else{
				$("#IlCenter").prepend("<img src=\"/images/gui/closeButton.png\" id=\"IlClsBut\" />");
			}
			clsButWid=$("#closeBut").width();
			clsButHgt=$("#closeBut").height();
			offsetClsButX = ((cntrWidth - plroffStW)/2)-(clsButWid/2);
			offsetClsButY = clsButHgt/2;
			var clsButCss = {
		        'position' : 'absolute',
		        'left' : (offsetClsButX)-15,
		        'top' : '-'+(offsetClsButY)-15,
		        'margin-bottom' : '-15px',
		        'cursor' : 'pointer',
		        'z-index' : '2013',
		        'display' : 'block'
			}

			$(this).find("#IlClsBut").css(clsButCss);
			$(this).find("#IlClsBut").click(function(){
				$("#modBg").fadeOut("fast");
				$("#ilLoader").remove();
				$("#modBg").remove();
				$(".k_float").css("zIndex","9999999");
				//showSelect();
			});
		});
		$("ilDlgCont").fadeTo("fast",1.0)
	});
	
	$("#lanSwch").hover(function(){
		//$(this).children().css("display", "inline");
		$("#otherLan").css("opacity",0);
		$("#otherLan").css("display","inline");
		$("#otherLan").animate({"top": "-28px", "opacity": 1}, "fast");
	},
	function (){
		$("#otherLan").animate({"top": "-=14px", "opacity": 0}, "normal", function(){
			$("#otherLan").css("top", "-14px");
			$("#otherLan").css("display","inline");
		});
	});
	
});

function activeTab(brandPath){
	
	if 			(brandPath == "/hanita") 		{ var setTab = "hanitaTab";
	} else if 	(brandPath == "/gtd") 			{ var setTab = "gtdTab";
	} else if 	(brandPath == "/manchester") 	{ var setTab = "manTab";
	} else if 	(brandPath == "/circle") 		{ var setTab = "circleTab";
	} else if 	(brandPath == "/clappdico") 	{ var setTab = "clappTab";
	} else if 	(brandPath == "/rubig") 		{ var setTab = "rubigTab";
	} else 										{ var setTab = "widiaTab";
	}
	
	return setTab;
}


// =================================== 
// ! ADD "NEW" STARBURST TO LISTED ITEMS
// USE - "newBurst($('.class'))"
// =================================== 
function newBurst(elem){
	$(elem).each(function(){
		if ($(this).attr('rel')) {
			dateDiff = GetDaysBetweenDates(parseDate($(this).attr("rel")),currentTime);
			if (dateDiff < 90){
				var curClass = $(this).attr("class");
				$(this).attr("class",curClass+" addBurst");
			}
		}
	});
}


