
	function setCookie(name, value, expires) {
		var today = new Date(); 
   	today.setTime( today.getTime() ); 
		if ( expires ) 
  		{ expires = expires * 1000 * 60 * 60 * 24; } 
 			 var expires_date = new Date( today.getTime() + (expires) ); 
 			 var curCookie = name + "=" + escape(value) +	";expires=" + expires_date + "; path=/";
  			document.cookie = curCookie;
		}

function setCookieBetter(name, value, expires) {
	expire = new Date((new Date()).getTime() + expires * 3600000);
	var curCookie = name + "=" + escape(value) +	"; expires=" + expire.toGMTString() + "; path=/";
	document.cookie = curCookie;
}

  function getCookie(name) { // use: getCookie("name");
  			bikky = document.cookie;
  		  var index = bikky.indexOf(name + "=");
  		  if (index == -1) return null;
  		  index = bikky.indexOf("=", index) + 1;
  		  var endstr = bikky.indexOf(";", index);
  		  if (endstr == -1) endstr = bikky.length;
  		  return unescape(bikky.substring(index, endstr));
  		}
  
  function hideNewsPromo(){
				document.getElementById('newsletter_promobox').style.visibility='hidden';
				setCookie('newspromoclose', '123', 7);
			}
			
	function checkIfNewsSigned(){
		var news_signed = 0;
		news_signed = getCookie('news_signed');
		if (news_signed > 0 || getCookie('newspromoclose') == 123) {
			document.getElementById('newsletter_promobox').style.visibility='hidden';
		}
	}

function bookmark(anchor){
	if(window.external){	
		window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
		return false;
	}
	return true;
}
	
function open_popup(uri, wdth, hght, lft, tp, nme)	{
	newwindow=window.open(uri,nme,'height='+hght+',width='+wdth+',left='+lft+',top='+tp+'');
	if (window.focus) {newwindow.focus()}
	return false;
}
						
pic1= new Image(134,190); 
pic1.src="http://www.fortheloveofbeads.com/images/promopic.jpg"; 

pic2= new Image(445,17); 
pic2.src="http://www.fortheloveofbeads.com/images/closebar.gif"; 

pic3= new Image(175,22); 
pic3.src="http://www.fortheloveofbeads.com/images/subscribenow.gif"; 

function display_c(start){
window.start = parseFloat(start);
var end = 0 // change this to stop the counter at a higher value
var refresh=1000; // Refresh rate in milli seconds
if(window.start >= end ){
mytime=setTimeout('display_ct()',refresh)
}
else {alert("Egg Hunt is Over!");}
}

function display_ct() {
// Calculate the number of days left
var days=Math.floor(window.start / 86400); 
// After deducting the days calculate the number of hours left
var hours = Math.floor((window.start - (days * 86400 ))/3600)
// After days and hours , how many minutes are left 
var minutes = Math.floor((window.start - (days * 86400 ) - (hours *3600 ))/60)
// Finally how many seconds left after removing days, hours and minutes. 
var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600 ) - (minutes*60)))

var x = "(" + days + " Days " + hours + " Hours "  + minutes + " Minutes and "  + secs + " Seconds " + ")";



document.getElementById('ct').innerHTML = x;
 window.start= window.start- 1;

tt=display_c(window.start);
 }
 
 
function cartPage() {
	location.href = 'http://www.fortheloveofbeads.com/newcartdisplay.php';
}

function noItemsInCart() {
	alert ('Please add at least 1 product to your Shopping Cart.');
}

function popitup(URL)	{
	newwindow=window.open(url,'popup_name','height=568,width=623');
	if (window.focus) {newwindow.focus()}
	return false;
}	

style_swatch = 'width: 500px; margin: 0px;padding: 0px;background: #928ab1;background-color: #928ab1;border: 0px;color: #fff;background-image: url(/images/omo_bg3.gif);background-repeat: no-repeat;';	 

	
function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 
if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 
}
}	

function readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
  	if(document.cookie.length > 0) { 
   		offset = document.cookie.indexOf(search);
	   	if (offset != -1)  { 
   			offset += search.length;
    		end = document.cookie.indexOf(";", offset);
	     	if (end == -1) end = document.cookie.length;
    			cookieValue = unescape(document.cookie.substring(offset, end))
	    }
	}
	return cookieValue;
}

function getScrollHeight(){
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function getPageSize(){	
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}		
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight*3;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function fadeout_gallery_div(){
	setTimeout("fadout_gallery_div_help()", 4000);	
}
function fadout_gallery_div_help(){
	opacity('gallery', 100, 0, 500);
}	

function hideDHTML(id)	{
	document.getElementById(id).style.visibility = 'hidden';		
	document.getElementById('overlay_' + id).style.width = 0 +"px";
	document.getElementById('overlay_' + id).style.height = 0 +"px";	
	document.getElementById('overlay_' + id).style.visibility='hidden';	
}

function hideDHTML_wishsuccess()	{
	document.getElementById('wishlist_form_success').style.visibility = 'hidden';		
	document.getElementById('overlay_wishlist_form_success').style.width = 0 +"px";
	document.getElementById('overlay_wishlist_form_success').style.height = 0 +"px";	
	document.getElementById('overlay_wishlist_form_success').style.visibility='hidden';	
	show_leftnav_cart();
}

function reportError(request){}


function check_radio(radioactive, radionotactive){
	document.getElementById(radionotactive).checked = false;
	document.getElementById(radioactive).checked = true;	
	if (radioactive == 'returncustomer')
	{
		document.getElementById('return_pass').style.display = 'block';
		document.getElementById('retcust').value = 'yes';
	}
	else {
			document.getElementById('return_pass').style.display = 'none';
			document.getElementById('retcust').value = 'no';
		}		
}

function wish_add(theelid, option1, option2, thepage) {
		
		var pid = parseFloat($F('pid_' + theelid));
		var qty = $F('qty_' + theelid);
		var qtyleft = $F('qtyleft_' + theelid);
		var page = '';
		if(thepage == 1){
			page = 'cart-added.html?src=discount';
		}
		if(thepage == 2){
			page = 'cart-added.html?src=product';
		}
		if(thepage == 3){
			page = 'cart-added.html?src=justarrived';
		}
		if(thepage == 4){
			page = 'cart-added.html?src=bbc';
		}
		if(thepage == 6){
			page = 'cart-added.html?src=related';
		}
		
		
		if (isNaN(qty) || qty.indexOf(".") > 0){
			alert("Please enter digits only.");
			return;
		}
		if (qty == ""){
			alert("Please enter a valid number of sets.");
			return;
		}
		
		qty = parseFloat(qty);
		qtyleft = parseFloat(qtyleft);
		if (qtyleft < qty){
			alert("We are sorry, we only have "+qtyleft+" sets left. Please pick a smaller number of sets.");
			return;
		}else if (qty < 0 || qty == 0){
			alert("Please enter a valid number of sets.");
			return;
		}
		
    var url = 'ajax_cart_update.php';
    var pars = 'pid=' + pid + '&qty=' + qty;
    var myAjax = new Ajax.Updater({success: 'wishdisplay'},url,
      {
        method:'post',
        parameters: pars,
		onSuccess: pageTracker._trackPageview(page),
        onFailure: reportError
      });
    document.getElementById('infobox2').style.display = 'block';  
    document.getElementById('qty_' + theelid).value = 'done';
    document.getElementById('qty_' + theelid).disabled = 'true';
}

function show_leftnav_cart(){
	var url = 'ajax_cart_leftnav_show.php';
  var pars = '';
  var myAjax = new Ajax.Updater({success: 'wishdisplay'},url,
     {
       method:'post',
       parameters: pars, 	  
       onFailure: reportError
     });	
  document.getElementById('infobox2').style.display = 'block';       
}

function wish_add_sg_firsttime(theelid, newemail, newscheckbox, thePage) {
		var pid = parseFloat($F('pid_' + theelid));
		var qty = $F('qty_' + theelid);
		var qtyleft = $F('qtyleft_' + theelid);
		var retcustwrite = 'no';
		var sccountry = $F('sccountry');
		var pass = $F('password');
		var retcusttrue = $F('retcust');
		if (retcusttrue == 'yes'){
			retcustwrite = 'yes';
		}
		if (isNaN(qty) || qty.indexOf(".") > 0){
			alert("Please enter digits only.");
			return;
		}
		if (qty == ""){
			alert("Please enter a valid number of sets.");
			return;
		}
		
		if (sccountry == "--"){
			alert("Please select your country.");
			return;
		}
		
		qty = parseFloat(qty);
		qtyleft = parseFloat(qtyleft);
		if (qtyleft < qty){
			alert("We are sorry, we only have "+qtyleft+" sets left. Please pick a smaller number of sets.");
			return;
		}else if (qty < 0 || qty == 0){
			alert("Please enter a valid number of sets.");
			return;
		}
		var newemailwrite = '';
	  var newscheckboxwrite = 'no';
	  if (newemail == 'yes'){
	  	newemailwrite = document.getElementById('newemail').value;	
	  		//email
				if(!check_email(newemailwrite)){
					alert("Your email address is invalid. Please enter again.");
					return;
				}
	  }
	  if (document.getElementById('wishnewscheckbox').checked == true){
	  	newscheckboxwrite = 'yes';
	  }
    var url = 'ajax_cart_update_firsttime.php';
    var pars = 'pid=' + pid + '&qty=' + qty + '&newemail=' + newemailwrite + '&newscheckbox=' + newscheckboxwrite + '&retcustwrite=' + retcustwrite + '&pass=' + pass + '&sccountry=' + sccountry;
    var myAjax = new Ajax.Updater({success: 'wishlist_form_success'},url,
      {
        method:'post',
        parameters: pars,
		onSuccess: pageTracker._trackPageview(thePage),
        onFailure: reportError
      });      
      
    hideDHTML('wishlist_form');  
    arrayPageSize = getPageSize();
		marginThisLeft2 = (arrayPageSize[0] - 554) / 2;
		document.getElementById('wishlist_form_success').style.marginLeft = marginThisLeft2;
		document.getElementById('wishlist_form_success').style.marginTop = 100 + document.body.scrollTop;
		document.getElementById('wishlist_form_success').style.visibility='visible';
		document.getElementById('overlay_wishlist_form_success').style.visibility='visible';
		document.getElementById('overlay_wishlist_form_success').style.width = arrayPageSize[0] +"px";
		document.getElementById('overlay_wishlist_form_success').style.height = arrayPageSize[1] +"px";
		opacity('overlay_wishlist_form_success', 0, 70, 1000);
		document.getElementById('qty_' + theelid).value = 'done';
		document.getElementById('qty_' + theelid).disabled = 'true';
}

function show_slick_wishlist_sg(theelid, thePage){
	
	if (readCookie('wishloggedin')){
	
			wish_add(theelid, '', '', thePage);
		
		return;
	}
		var qty = $F('qty_' + theelid);
		var qtyleft = $F('qtyleft_' + theelid);		
		
		if (isNaN(qty) || qty.indexOf(".") > 0){
			alert("Please enter digits only.");
			return;
		}
		
		if (qty == ""){
			alert("Please enter a valid number of sets.");
			return;
		}
		
		qty = parseFloat(qty);
		qtyleft = parseFloat(qtyleft);
		if (qtyleft < qty){
			alert("We are sorry, we only have "+qtyleft+" sets left. Please pick a smaller number of sets.");
			return;
		}else if (qty < 0 || qty == 0){
			alert("Please enter a valid number of sets.");
			return;
		}
	
	scrolled = getScrollHeight();	
	arrayPageSize = getPageSize();
	marginThisLeft2 = (arrayPageSize[0] - 554) / 2;
	document.getElementById('wishlist_form').style.marginLeft = marginThisLeft2;
	document.getElementById('wishlist_form').style.marginTop = 100 + scrolled;
	document.getElementById('wishlist_form').style.visibility='visible';
	document.getElementById('overlay_wishlist_form').style.visibility='visible';
	document.getElementById('overlay_wishlist_form').style.width = arrayPageSize[0] +"px";
	document.getElementById('overlay_wishlist_form').style.height = arrayPageSize[1] +"px";
	opacity('overlay_wishlist_form', 0, 70, 1000);
	if(thePage == 1){
		document.getElementById("wishlist_form_url").href= "javascript: wish_add_sg_firsttime("+ theelid +", 'yes', '','cart-added.html?src=discount')";
	}
	else if(thePage == 2){
		document.getElementById("wishlist_form_url").href= "javascript: wish_add_sg_firsttime("+ theelid +", 'yes', '','cart-added.html?src=product')";
	}
	else if(thePage == 3){
		document.getElementById("wishlist_form_url").href= "javascript: wish_add_sg_firsttime("+ theelid +", 'yes', '','cart-added.html?src=justarrived')";
	}
	else if(thePage == 4){
		document.getElementById("wishlist_form_url").href= "javascript: wish_add_sg_firsttime("+ theelid +", 'yes', '','cart-added.html?src=bbc')";
	}
	else if(thePage == 6){
		document.getElementById("wishlist_form_url").href= "javascript: wish_add_sg_firsttime("+ theelid +", 'yes', '','cart-added.html?src=related')";
	}
}

function showCheckoutOptions(){
	scrolled = getScrollHeight();	
	arrayPageSize = getPageSize();
	marginThisLeft2 = (arrayPageSize[0] - 554) / 2;
	document.getElementById('checkout_choices').style.marginLeft = marginThisLeft2;
	document.getElementById('checkout_choices').style.marginTop = 100 + scrolled;
	document.getElementById('checkout_choices').style.visibility='visible';
	document.getElementById('overlay_checkout_choices').style.visibility='visible';
	document.getElementById('overlay_checkout_choices').style.width = arrayPageSize[0] +"px";
	document.getElementById('overlay_checkout_choices').style.height = arrayPageSize[1] +"px";
	opacity('overlay_checkout_choices', 0, 20, 1000);
}