var myVerticalSlide, catVerticalSlide
window.addEvent('domready', function() {   
	new SmoothScroll({duration:2000,fps:20, offset:{'x':-10000,'y':0}});
	
   	
	
	if ($chk($('emailsignup'))) {   
		var defeval = "Type Your Email Address"
		$('emailsignup').set("value", defeval)  ;
		$('emailsignup').addEvent("focus", function(){
			if ($('emailsignup').get("value") == defeval)  $('emailsignup').set("value", "") 
		})
		$('emailsignup').addEvent("blur", function(){
			if ($('emailsignup').get("value") == "")  $('emailsignup').set("value", defeval) 
		})
	}  
	
	
	if ($chk($('alert_me_email'))) {   
		var defeval = "Type in Your Email Address Here"
		$('alert_me_email').set("value", defeval)  ;
		$('alert_me_email').addEvent("focus", function(){
			if ($('alert_me_email').get("value") == defeval)  $('alert_me_email').set("value", "") 
		})
		$('alert_me_email').addEvent("blur", function(){
			if ($('alert_me_email').get("value") == "")  $('alert_me_email').set("value", defeval) 
		})
	}
	
	
	// init events for addGroup
	if ($('deal_date')) myCal = new Calendar({ deal_date: 'l, F d, Y' }, { classes: ['dashboard'], direction: 1 });   
   
	Element.implement({
			//implement show
			fancyShow: function() {
				this.fade('in');
			},
			//implement hide
			fancyHide: function() {
				this.fade('out');
	 		}  
		})
  
	
  	if ($('login_form_block'))  initLoginForm($('login_form_block'))
  	if ($('ifr')) $('ifr').src="" ;   
	 
	
	if ($('search_cats')){
	 	$('search_cats').isopen = 0 ;
		$('search_cats').setStyles({"opacity":"0"})
		$('search_cats').setStyles({"display":"block"})  
		// href="javascript:void(0)" onclick="toggle_search_cats()"
	   


	}
	
	
	if ($('search_names')){
	 	$('search_names').isopen = 0 ;
		$('search_names').setStyles({"opacity":"0"})
		$('search_names').setStyles({"display":"block"})  
		// href="javascript:void(0)" onclick="toggle_search_cats()"
	  	
	  
		
	}    
	
   
	
	
	
	
	$$(".explanation").each(function(item){
	   	 $(item).setStyle("opacity", 0);
			$(item).setStyle("display", "block"); 
	}) 
	
	
	$$(".picklist").each(function(item){
	   	 $(item).setStyle("opacity", 0);
			$(item).setStyle("display", "block"); 
	})            
	
	
   	if ($('addEmailOverlay')){
     // explanation("addEmailOverlay"); 
	}    
 
 
   
	if ($chk($('overlaybg'))) {   
	
	$("overlaybg").setStyle("opacity", 0);
	$("overlaybg").setStyle("display", "block");
	   
}
		
		 
	if ($('email_form_container')) {
		$('email_form_container').setStyles({"visibility":"visible"})
			myVerticalSlide = new Fx.Slide('email_form_container',{ 	
				duration: 1000,
				transition: Fx.Transitions.Pow.easeOut
				});

			myVerticalSlide.hide()
		   $('email_form_container').setStyles({"display":"block"})

			myVerticalSlide.addEvent('complete', function() {
		 //    	alert($('email_form_container').get("classname"));
			});
	} 
	
	//tooltips
	
	//when the dom is ready

		//store titles and text
/*
		$$('a.tipz').each(function(element,index) {   
			var content = element.get('title').split('::');
			element.store('tip:title', content[0]);
			element.store('tip:text', content[1]);
		});

		//create the tooltips
		var tipz = new Tips('.tipz',{
			className: 'tipz',
			fixed: true,  
			offsets: {'x':30, 'y':-100},
			hideDelay: 50,
			showDelay: 50
		});  
		

		tipz.addEvents({
			'show': function(tip) {   
				 tip.fade('in');
			},
			'hide': function(tip) {
			  tip.fade('out');
			}
		});
		
*/
		  
/* */

});   
        
             





var cshow = false;
function showcities(val){
	
   if (cshow || val=="hide")  {
	$('picklist').fancyHide()
	cshow = false   
	$('overlaybg').setStyle("display","none")
	
	
	} else {
	 	$('picklist').fancyShow()
		cshow = true    
		var el    = $('doc')  
		var ss = el.getSize();    
	$('overlaybg').setStyle("display","block")
		$('overlaybg').setStyle("height", ss.y)
		$('overlaybg').setStyle("width", "100%")
	   // $('overlaybg').fancyShow()
		
		$('overlaybg').addEvent("click", function(){
			showcities("hide")
		})
	}
}  
     

function notifyleavingsite(str, bus) {
	alert("This online deal is offered by our sister site, '"+str+"'. We're taking you there now. You can purchase this deal there and use it online at the "+bus+" website from anywhere in the world! ") ;
}

 
function toggle_search(what, orientation){   
	var item, arrow, oitem 
	closeAllOverlays()
	
	if (what=='names'){
   		// var h = $('search_name').getSize(); 
		arrow =  $('searcharrowo2')
        item = $('search_names')
        oitem = $('search_cats')
		var p = $('bus_name_select_box').getPosition();   
		var s = $('bus_name_select_box').getSize();   
		//var pd = $('sidebar_r').getPosition();   
		var sc = $('search_names').getSize();  
		arrow.setStyles({
	   	 "margin-top": 78
		});
		
	 } else if (what == 'cats') {
        item = $('search_cats');
        oitem = $('search_names')
		arrow =  $('searcharrowo1')
		var p = $('bus_cat_select_box').getPosition();   
		var ps = $('bus_cat_select_box').getSize();   
		var s = $('bus_cat_select_box').getSize();   
        arrow.setStyles({
	   	 "margin-top": 58
		});
	  
	}     
	
	
   item.setStyles({
			"margin-top": 0,
			"width": 840
		});
	
	if (orientation=="l") {
		item.setStyles({
	   	 "margin-left": (s.x +10)
		});
		
		arrow.setStyles({
	   	 	"background-image": "url(/system/assets/img/barrow_search_l.png)",
			"margin-left" : -27
		}); 
		
	} else {

		item.setStyles({
	   	 "margin-left": (p.x - parseInt(item.getStyle('width')) - 80)
		}); 
	}
	
	
	    if (!item.isopen) {   
			item.fade("in") ;
			item.isopen = 1   
		}
	 	
	if (item.isopen == 1) {
		$('doc').addEvent("mousedown", closeAllOverlays)
	}      else {
		 $('doc').removeEvent("mousedown", closeAllOverlays);
	}
	//catVerticalSlide.toggle() 
}
      



  
function closeAllOverlays(){
    if ($('search_names').isopen) { 
		$('search_names').fade("out") ;  
		$('search_names').isopen = 0 
	}
    if ($('search_cats').isopen) { 
		$('search_cats').fade("out") ;  
		$('search_cats').isopen = 0 
	}                                 
	$('doc').removeEvent("mousedown", closeAllOverlays); 
	$('doc').removeEvent("mousedown", closeAllOverlays); 
}





function numbersOnly(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode                  
         if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
            return false;

         return true;
      }


function setReminder(id, loggedIn){ 
	if (!loggedIn) {alert("You must be logged in to set reminders."); return;}
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/setReminder/'+id,  
	            data: {  },  
	            onComplete: function(response) {
		 		   if (!response) alert('Didnt work');
					else {
				   	var div = new Element('div', {   
						 'id': 'rem_'+id,
					     'class': 'reminded',
						 'html' : "Reminder Set"
					    }); 
					if ($('rem_'+id)) div.replaces($('rem_'+id))
					} 
			    }        
	 }).send();
}               

function resendGiftEmail(id, type) {
	  
	var req = new Request({  
	            method: 'post',  
	            url: '/directories/resendGiftEmail',  
	            data: { id:id, type:type },  
	            onComplete: function(response) { 
		 		   if (!response || response != 'ok') alert('Didnt work');
					else {
				   	alert("The email was resent")
					} 
			    }        
	 }).send();
}
            
function checkEmailForAccount(email, responsediv, site_id) {    
	var response = null;
	var req = new Request({  
	            method: 'post',  
	            url: '/account/checkEmailForAccount',  
	            data: { email:email, site_id:site_id },  
	            onComplete: function(response) {  
	 //  alert(response)  ;
		 		   if (!response) alert('Didnt work');
					else {
				     	if (response=="ok"){ 
							 var cc = responsediv+"_c" ;
								    $(cc).setStyle("display", "none");   
					   // 	   		$(cc).className=''
  						//	$(responsediv).className='bigok'
					   	 	oktogo = true; 
					  //  $(responsediv).set("html", "<br />This email address is good to go (not being used by another account)");
						} else {
//					      $(responsediv).set("html", "This email address is currently used by another account. Is it yours? If so, please log in first. You will see the login box on this page. We can't process this order using the email address <strong>'"+email+"'</strong> until we know it's your account. <h2><a href='javascript:;' onclick='explanation(\"loginOverlay\")'>Log In</a></h2>" );
						 	oktogo = false;  
						var cc = responsediv+"_c" ;
						    $(cc).setStyle("display", "block");   
					   		$(cc).className='bigalert'  
							if ($chk($('uu'))) $('uu').set("value", email)
							if(typeof onCheckEmailForAccountComplete == 'function') { 
							onCheckEmailForAccountComplete(); 
							}
						}
					} 
			    }        
	 }).send();
}     



function checkEmailExists(email, responsediv, site_id) {
	
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/checkEmailForAccount',  
	            data: { email:email, site_id:site_id },  
	            onComplete: function(response) { 
		 		   if (!response) alert('Didnt work');
					else {
				     	if (response=="ok"){  
							 var cc = responsediv+"_c" ;
								    $(cc).setStyle("display", "none");   
							   		$(cc).className=''
  							$(responsediv).className='bigok'
					   	 	oktogo = true; 
					    $(responsediv).set("html", "<br />This email address is good to go (not being used by another account)");
						} else {
					      $(responsediv).set("html", "This email address is currently used by another account. Is it yours? If so, please log in first. You will see the login box on this page. We can't process this order using the email address <strong>'"+email+"'</strong> until we know it's your account. " );
						 	oktogo = false;  
						var cc = responsediv+"_c" ;
						    $(cc).setStyle("display", "block");   
					   		$(cc).className='bigalert'  
							if ($chk($('uu'))) $('uu').set("value", email)
							if(typeof onCheckEmailForAccountComplete == 'function') { 
							onCheckEmailForAccountComplete(); 
							}
						}
					} 
			    }        
	 }).send();
}

 

function showEmailFormCheckout(responsediv) {
$(responsediv).set("html", "Please log in to your account to keep your vouchers all together. " );
 	oktogo = false;  
var cc = responsediv+"_c" ;
    $(cc).setStyle("display", "block");   
	$(cc).className='bigalert'  
	}                
	
	

					function setSpecialDealsReminder(id, loggedIn){ 
						if (!loggedIn) {alert("You must be logged in to set reminders."); return;}
						var req = new Request({  
						            method: 'post',  
						            url: '/specialDeals/setReminder/'+id,  
						            data: {  },  
						            onComplete: function(response) {
							 		   if (!response) alert('Didnt work');
										else {
									   	var div = new Element('div', {   
											 'id': 'rem_'+id,
										     'class': 'reminded',
											 'html' : "Reminder Set"
										    }); 
										if ($('rem_'+id)) div.replaces($('rem_'+id))
										} 
								    }        
						 }).send();
					}
					
function setWatch(id, loggedIn){ 
	if (!loggedIn) {alert("You must be logged in to watch auctions."); return;}
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/setWatch/'+id,  
	            data: {  },  
	            onComplete: function(response) {
		 		   if (!response) alert('Didnt work');
					else {
				   	var span = new Element('span', {   
						 'id': 'watch_'+id,  
						 'class' : 'watching',
						 'html' : "<div class='eye'></div>You are watching this auction"
					    });
					if ($('watch_'+id)) span.replaces($('watch_'+id))
					} 
			    }        
	 }).send();
} 


function removeReminder(id){ 
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/removeReminder/'+id,  
	            data: {  },  
	            onComplete: function(response) {
		 		   if (!response) alert('Didnt work');
					else {
				   	var li = "r_"+id; 
					var el = $(li) ;
					el.set("class","deleted");
					
					var li = "ra_"+id; 
					var el = $(li) ;
					el.destroy();
					} 
			    }        
	 }).send();
}



function removeWatch(id){ 
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/removeWatch/'+id,  
	            data: {  },  
	            onComplete: function(response) {
		 		   if (!response) alert('Didnt work');
					else {
				   	var li = "w_"+id; 
					var el = $(li) ;
					el.set("class","deleted");
					
					var li = "wa_"+id; 
					var el = $(li) ;
					el.destroy();
					} 
			    }        
	 }).send();
}     

function processLoginForm(f){
  // if () 
}

function initLoginForm(f){  
	f.username.value="email address" ;
	f.password.value="password" ;
	f.username.onfocus = function(){
		if (f.username.value == "email address") f.username.value = "" ;
	}
	f.username.onblur = function(){
		if (f.username.value == "") f.username.value = "email address" ;
	}
	
	if (!document.all){
		// password - toggle between input types
		f.password.type = "text" ;
		f.password.onfocus = function(){ 
			f.password.type = "password" ;
			if (f.password.value == "password") f.password.value = "" 
		}
	
		f.password.onblur = function(){
			if (f.password.value == "") {
				f.password.type = "text" ;
				f.password.value = "password" ;
			}
		}
	} else {
		f.password.onfocus = function(){ 
			if (f.password.value == "password") f.password.value = "" 
		}
	
		f.password.onblur = function(){
			if (f.password.value == "") {
				f.password.value = "password" ;
			}
		}
	}
}    



// script by Josh Fraser (http://www.onlineaspect.com)

function calculate_time_zone() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	var i;
	// check just to avoid error messages 
	return (tz_convert(std_time_offset)) ;
	if (document.getElementById('timezone')) {
		for (i = 0; i < document.getElementById('timezone').options.length; i++) {
			if (document.getElementById('timezone').options[i].value == convert(std_time_offset)+","+dst) {
				document.getElementById('timezone').selectedIndex = i;
				break;
			}
		}
	}
}

function tz_convert(value) {
	var hours = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var mins = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var secs = parseInt(value);
	var display_hours = hours;
	// handle GMT case (00:00)
	if (hours == 0) {
		display_hours = "00";
	} else if (hours > 0) {
		// add a plus sign and perhaps an extra 0
		//display_hours = (hours < 10) ? "+0"+hours : "+"+hours;
		display_hours = hours;
	} else {
		// add an extra 0 if needed 
		display_hours = (hours > -10) ? "-"+Math.abs(hours) : hours;
	}
	
	mins = (mins < 10) ? "0"+mins : mins;
	return display_hours // +":"+mins;
}

//onload = calculate_time_zone;


function expandSELECT(sel) {
//  $(sel).set("className","selectWide");
}


function contractSELECT(sel) {
 // $(sel).set("className","selectNarrow");
}
      
function addthisbusinessstuff(f){  
	return true;
	
}
function sendEmailToAFriend(f, loggedin){ 
	if (!loggedin) {
		alert("You need to be logged in to send email.");
		return false;
	}
   if (f.share_name.value != "" && f.share_email.value !="" && isValidEmail(f.share_email.value) ) {
	var req = new Request({  
	            method: 'post',  
	            url: '/auctions/sendToFriend/',  
	            data: {share_name: f.share_name.value,
		  				share_email: f.share_email.value,
						auction_id: f.auction_id.value},  
	            onComplete: function(response) {
		 		   
				   	var div = new Element('div', {   
						 'id': 'email_response',  
						 'class' : 'email_response',
						 'html' : "<div class='ok'></div>Thanks for sharing with "+f.share_name.value+"."
					    });
					if ($('email_response')) div.replaces($('email_response')) ;
					 togSlide()
					} 
			           
	 }).send();
	
}    else {
	  alert("Both the name and email need to be filled in");
} 
return false;
}       

var couponWin
function printCoupon(id) {
	couponWin = window.open('/directories/printCoupon/'+id, "Print-Coupon", "width=500,height=300,top=100,left=100,status=no,toolbars=no,location=no") ;
	if (couponWin) couponWin.focus();  
} 

var topen=0;
function togSlide(){
	topen = topen == 1 ? 0 : 1 ;
    if (open) $('hlink').setStyles({"background-color":"#ffffff"})  ;
    else $('hlink').setStyles({"background-color":"#f0f0f0"})  ;
     myVerticalSlide.toggle()
}

function googlize(str) {
	return str.replace(' ','+');
	return str;
}
function isValidEmail(str) {
   	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = str;
	   if(reg.test(address) == false) {
	      return false;
	   }
   
	return true;
}      
function getMap(address_data){
	var src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=";
	src += googlize(address_data[0]) + "," + googlize(address_data[2]) + "," + googlize(address_data[3]);
   src += "&amp;sll=32.012739,-80.843583&amp;sspn=0.048034,0.052357&amp;gl=us&amp;ie=UTF8&amp;z=14&amp;iwloc=addr&amp;ll=32.023359,-80.839376&amp;output=embed&amp;s=AARTsJqQTLc6GGFlLHhP9eWGOwapGoSy8Q" ;
  
 var html ='<iframe width="580" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=1200+market+street+san+francisco;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=1200+market+street+san+francisco&amp;sll=37.773508,-122.421188&amp;sspn=0.09376,0.126858&amp;ie=UTF8&amp;ll=37.787539,-122.412758&amp;spn=0.023741,0.036478&amp;z=14&amp;iwloc=addr" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
     
 



  	var i = new Element('div', {   
		 'id': 'mapit',  
		 'class' : 'map',
		 'html' : html
	    });
	i.replaces($('mapit')) 
}




Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
                               

function showevent(id) {       
	var nid = "desc"+id ;
	var shell = "eo_"+id ;
		if (!$chk(nid)) return;
		var showme = $(nid).getStyle("display") == "none";
		if (showme) {
			var link = "tog_"+id
			if ($chk($(link))) $(link).set("html", "Hide Details <img src='/system/assets/img/directories/arrow_up.png' border='0' align='absmiddle' />") ;
			$(nid).setStyle("display", "block") ; 
			$(shell).set("class","event_outer_alt" );
		}  else {
			var link = "tog_"+id
			$(shell).set("class","event_outer" );
			if ($chk($(link))) $(link).set("html", "Show Details <img src='/system/assets/img/directories/arrow_down.png' border='0' align='absmiddle' />") ;
			$(nid).setStyle("display", "none") ;
		}
}   

var viewtypes = ["calBody", "map_canvas"]  ;
function viewMode(type){  
	$(type).setStyle("display", "block")  
	$('sidebar_r').style.display = type=="calBody" ? "none" : "block" ;
	 for (var r =0 ; r<viewtypes.length; r++) {
		   var t = viewtypes[r] ;
			if (t!=type) $(t).setStyle("display", "none") ;

	}
}
    
function submitEvent(id) {
	   
	    	  var etitle = $('addevent_name').get("value")
			 var etype_id = $('addevent_type').options[$('addevent_type').selectedIndex].value
			 var edate = $('event_date').get("value")
			 var eloc = $('addevent_location').get("value") ; 
			var edesc =  $('addevent_description').get("value") ;   

			var opts = {
				etitle:etitle,
				etype_id: etype_id,
				edate: edate,
				eloc: eloc,
				user_id: id }   
				
				for (var t in opts) {
					if (opts[t] == "") {
					   alert("All '*' fields must be filled out before submitting. \nPlease complete the form. ") 
						return false;
					}
				}       
				opts.edesc = edesc;
				
			
			var req = new Request({  
			            method: 'post',  
			            url: '/events/userSubmission',  
			            data: opts,  
			            onComplete: function(response) { 
				 		   if (!response) alert('Didnt work');
							else {
							$('addeventarea').set("html", "<h4>Thank you!</h4><p>Your event will be posted pending our review. Check back later!</p> ") ;
							} 
					    }        
			 }).send();
}       

function rfb(oid, sid){
	// record facebook
	 var req = new Request({  
	            method: 'post',  
	            url: '/specialDeals/recordFacebook',  
	            data: {site_id:sid, offer_id:oid},  
	            onComplete: function(response) { 
					//alert(response)
			    }        
	 }).send();
} 

function signupemail_specialDeals( fromOverlay , elem, eresp){
	 
	if (fromOverlay) var e = $('alert_me_email').get("value") ;
	else if (elem) var e =  $(elem).get("value")  
	else var e =  $('emailsignup').get("value")
	if (!e) {
		alert("Please type in an email address");
		return false; 
	}
		
	if (!isValidEmail(e)) {
		alert("The email address doesn't look right, please check it");
		return false
	}
	   
	var opts = {
		email:e
	}   
		var n=1;    
		var el = "alert_me_cat_"+n ;
		var item
		while ($chk($(el))) {
			if ($(el).get("checked") == true) opts["cat"+n] = 1 ;
			n++;
		   el = "alert_me_cat_"+n ;  
		}   
		
		if (!$chk($("alert_me_cat_1"))) {
			while (n<5) {
				opts["cat"+n] = 1 
				n++;
			}
		}
		
	var req = new Request({  
	            method: 'post',  
	            url: '/specialDeals/recordSDNotify',  
	            data: opts,  
	            onComplete: function(response) {
		  	   if (!response) alert('Didnt work');
					else { 
						if (response=="ok") {  
							Cookie.write('sd_notified', '1', {duration:30, path:"/"}) ;
						   
						
						 if ($chk($('alert_me_email'))) {
							$('alert_me_email').setStyle("display", "none")
						   // $('checks').setStyle("display", "none")
							$('bsignup').setStyle("display", "none")
							$('ebg').setStyle("display", "none")
							$('sub').setStyle("display", "none")
						}    
						 	if ($chk($('emailsignuptop'))) {    
								$('emailsignuptext').set("html", "<div class='etop_text'>Thank You! <span>You will be notified when the next deal begins</span></div>") ;
						   		var f = function(){ new Fx.Morph('emailsignuptop', {duration: 2000, transition: Fx.Transitions.Cubic.easeOut}).start({marginTop:"-80px"}) };
								f.delay(2000) 
							}
						   
						if ($chk($(eresp))) {
							$(eresp).set("html","<h3>Thank you! You will be notified of the next great deal when it begins.</h2> <h3>In the future you can edit your notification preferences on the 'My Favorites' page. (You will need to register to do it)</h3> ") ;
						}
						   // $('emailsignuptop').setStyle("display", "none")
					  
							if (fromOverlay) {
								$('email_capture_response').set("html", "<div style=''><h2 style='margin-top:30px;'><span>Thank You!</span>You will be notified of the next great deal when it begins.</h2> <h3>In the future you can edit your notification preferences on the 'My Favorites' page. (You will need to register to do it) <br /><br />This window will close momentarily....</h3></div>")  
								var r = function(){
									ohide("addEmailOverlay") 
								} 
								r.delay(3000)        
							}
						}
					   // if (fromOverlay) 
						if ($chk($('addEmail_response')))  $('addEmail_response').set("html", "<br /><h2><span>Thank you!</span>You will be notified the moment our next deal starts!</h2> ") ;
					} 
			    }        
	 }).send();
}   

  
function showhideelem(elem_id){       
	var val = $(elem_id).getStyle("display") == "block" ? "none" : "block" ;
	$(elem_id).setStyle("display", val)
}
var m_on = null ; 
function mapit(id) {  
    //alert(m_on+" - " + id)   
var vv = $('map_canvas').getStyle("display") == "block" ; 
if (!vv) {viewMode('map_canvas')}
	if (m_on == id) return;
	if (m_on && m_on!=id) { 
		if (this["infowindow"+m_on]) {
		var t = this["infowindow"+m_on]  
		t.close();    
		}
		m_on = null ;
	} 
	     
	
	if (!this["infowindow"+id]) {
		alert("no info window: "+id);
		return;}
		var t = this["infowindow"+id]
		var m = this["marker"+id]
	
	t.open(map,m);  
	m_on = id;
	
}           




/***********************************************
* Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var sto, sto1
function cdtime(container, targetdate, offsetSeconds){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()  
//alert(offsetSeconds)        
//this.currentTime.setTime(currentTime.getTime(  ) + offsetSeconds)
this.offsetSeconds=parseInt(offsetSeconds) ;
this.targetdate=new Date(targetdate)    
//alert(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
sto = setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate - this.currentTime)/1000 - this.offsetSeconds  //difference btw target date and current date, in seconds
//alert(timediff)
if (timediff<0){ //if time is up
//this.timesup=true
this.container.innerHTML="00:00:00"; 
//window.location.reload()
//clearTimeout(sto)
//clearTimeout(sto1)
return;
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
sto1 = setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

/////CUSTOM FORMAT OUTPUT FUNCTIONS BELOW//////////////////////////////

//Create your own custom format function to pass into cdtime.displaycountdown()
//Use arguments[0] to access "Days" left
//Use arguments[1] to access "Hours" left
//Use arguments[2] to access "Minutes" left
//Use arguments[3] to access "Seconds" left

//The values of these arguments may change depending on the "baseunit" parameter of cdtime.displaycountdown()
//For example, if "baseunit" is set to "hours", arguments[0] becomes meaningless and contains "n/a"
//For example, if "baseunit" is set to "minutes", arguments[0] and arguments[1] become meaningless etc


function formatresults(){    
	var dy = "", hr = "";
	
	if (this.timesup==false){//if target date/time not yet met  
		if (arguments[0] > 0)  dy = arguments[0]+ (arguments[0] == 1 ?  " day " : " days "); 
		if (arguments[1] > 0) hr = arguments[1]+ (arguments[1] == 1 ?  " hour " : " hours ")  
		var addon ="" ;
	if (dy == "") addon += arguments[2]+" min ";
	if (dy == "" && arguments[1] < 8) {
		hr = hr.replace("hour","hr")
		addon += arguments[3]+" sec"
	}
	var displaystring= dy + hr + addon ;    
	if (displaystring == "00:00:00") times_up(); 
	
	}
	else{ //else if target date/time met
	window.location.reload()
	}
	return displaystring 
}

function formatresults2(){
	var dy = "", hr = "";

	if (this.timesup==false){//if target date/time not yet met  
		if (arguments[0] > 0)  dy = arguments[0]+ (arguments[0] == 1 ?  " day " : " days "); 
		if (arguments[1] > 0) hr = arguments[1]+ (arguments[1] == 1 ?  " hour " : " hours ")  
		var addon ="" ;
	if (dy == "") addon += arguments[2]+" minutes ";
	if (dy == "" && arguments[1] < 8) {
		addon += arguments[3]+" seconds"
	}
	var displaystring= dy + hr + addon ;
	}
	else{ //else if target date/time met
	window.location.reload()
	}
	return displaystring
}

 function formatresults_hms(){
	var disp="", dy = "", days=false, hr = "";

	if (this.timesup==false){//if target date/time not yet met 
		hr =  arguments[1]
			show_ct = false 
	   	if (arguments[0] > 0) {
	   		dy = arguments[0];
			days = true 
		}
			if (arguments[1] > 0) hr = arguments[1] 
			var addon ="" ;
   			var  m ="";
			m = arguments[2];
			var s = arguments[3]
		
			if (days && dy<10) dy = "0" + dy;
			if (hr<10) hr = "0" + hr;
			if (hr==0) hr = "00" ;
			if (m<10) m = "0" + m;
			if (m==10) m = "00" ;
			if (s<10) s = "0" + s;
			if (s==0) s = "00" ;
            if (days) disp = dy + ":" ;
	 		disp +=  hr + ":" + m ;
			if (!days) disp += ":" + s ;    
	   
	
	var displaystring= disp
	if (displaystring == "00:00:00") times_up(); 
	}
	else{ //else if target date/time met
	window.location.reload()
	}
	return displaystring
}             

function buy_now(id, type, burl){  
    overlay("transition_o") 
	if (!burl) burl="";            
	$("ifr").set("src", burl + "/" + type + "/pay_now_pass_vars/" + id ) ;
}

function overlay(type, options) {
	explanation(type, options)
}      
function times_up(timediff,offsetSeconds, targdate, currentime){
	 var r = function() {
		window.location.reload()   
	}
	r.delay(1000);
		
	}




function ohide(id){
	$(id).fancyHide()
	$('overlaybg').fancyHide()  
	if (id=="addEmailOverlay") Cookie.write("sd_notified", "1", {duration:20, path:"/"})
}
     

function explanation(type, options){
	
		var scroll = window.getScroll();
  var id =type    
if (!$chk($(id))) return;
	$('overlaybg').addEvent("click", function(){
		ohide(id)
	})
	var centered = window.getSize().x/2 - $(id).getSize().x/2 
	var vcentered = window.getSize().y/2 - $(id).getSize().y/2 + scroll.y   
	if (type=="addEmailOverlay") {       
		var centered = window.getSize().x/2 - 641/2 
		var vcentered = window.getSize().y/2 - 519/2 + scroll.y - 60
	}
	
    $(id).setStyle("left", centered)
	$(id).setStyle("margin-top", vcentered)
	$(id).setStyle("display", "block")
	$(id).setStyle("opacity", "1")
                          
var el    = window; 
var ss = el.getSize();    
$('overlaybg').setStyle("height", ss.y + scroll.y + 200)
$('overlaybg').setStyle("width", "100%")
$('overlaybg').setStyle("opacity", "1")
//$('overlaybg').fancyShow()  
 
    
	
	
}


function stoggleItem(targ){ 
    var isoff = $(targ).getStyle("display") == "none" ; 
	if (isoff) $(targ).setStyle("display", "block")
	else $(targ).setStyle("display", "none")
  
}   

function ptoggleItem(targ1, targ2){ 
    var isoff = $(targ1).getStyle("display") == "none" ; 
	if (isoff) {
		$(targ1).setStyle("display", "block")
		$(targ2).setStyle("display", "none")
	} else {
	   $(targ2).setStyle("display", "block")
		$(targ1).setStyle("display", "none")
	}
  
}

function toggleItem(targ, oelem){ 
    var isoff = $(targ).getStyle("display") == "none" ; 
	$$('.sect').each(function(item){
		if (item == $(targ) ) {
			 item.setStyle("display", "block")
		} else item.setStyle("display", "none")
	})    
	
	$$('.busq a').each(function(item){
		if (item == $(oelem) || item == oelem) item.addClass("on")
		else item.removeClass('on') 
		
	})
	  
}  

function setWSize(body){       
	var w =  window.getSize();
	w = w.y ; 
  //  alert(w);
 	$$('.center_content').each(function(item){
		item.setStyle("height", w-100) ;
	})
}        




function emailCapture(action){
 //   $('addEmailOverlay').fancyShow(); 
//	if ($chk($('alert_me_email'))) $('alert_me_email').focus();
};
