function doClick(e) {	
	 var key;
         if(window.event)
              key = window.event.keyCode;    
         else
              key = e.which;       
        if (key == 13)
        {
		document.location.href='http://search.bettersex.com/index?D='+document.getElementById('free_text2').value+'&Ntt='+document.getElementById('free_text2').value+'&Dk=0&N=0&Nty=1';		
		   if(window.event) {
		  event.keyCode = 0;
		  } else {
		 e.preventDefault();
		  }
        }
}

function doClick2(e) {	
	 var key;
         if(window.event)
              key = window.event.keyCode;    
         else
              key = e.which;       
        if (key == 13)
        {
		document.location.href='http://www.bettersex.com/createemailprofile.aspx?email='+document.getElementById('emailtop').value;		
		   if(window.event) {
		  event.keyCode = 0;
		  } else {
		 e.preventDefault();
		  }
        }
}

function doClick3(e) {	
	 var key;
         if(window.event)
              key = window.event.keyCode;    
         else
              key = e.which;       
        if (key == 13)
        {
		document.location.href='http://search.bettersex.com/index?D='+document.getElementById('search2_text').value+'&Ntt='+document.getElementById('seacrh2_text').value+'&Dk=0&N=0&Nty=1';		
		   if(window.event) {
		  event.keyCode = 0;
		  } else {
		 e.preventDefault();
		  }
        }
}


function golink(url) {
	document.location.href=url;
}

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
			if (ft[0] == ji) {
			return ft[1];
			}
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  var c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    var c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


$(document).ready(function(){

var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if(sPage=="shoppingcart.aspx") {

var fgift=getCookie('fgift');

if (fgift!=null && fgift!="") {

$('#_ctl0_ContentPlaceHolder1_pnlCartWithItems').prepend('<div style="padding:15px 0 15px 20px"><h2 style="color:#D51E00;">Be sure to check the bottom of the page to claim any FREE gifts you qualify for!</h2></div>');
}

}


$("a#single_image").fancybox();

$("a#inline").fancybox({
		'hideOnContentClick': true,
		'autoDimensions':false,
		'width':400
	});




if (querySt("sSC")=="8PB226") {
$('#_ctl0_ContentPlaceHolder1_pnlStage1').prepend('<div style="padding:15px 0 15px 20px"><a href="/sex-toys/sex-in-the-shower-c-270.aspx"><h2 style="text-decoration:underline;color:#3399ff;>>Click here to see all sex in the shower</h2></a></div>');

}
//alert("debug");
if (querySt("cc")=="EM022111") {
//alert("cc identified!");
setCookie('fgift','yes');
}

//space ad zoom
function checkImage(url)
{
var img = new Image;
img.onerror = img_onError;
img.src = url;
img.onload = do_something(url);
}

function img_onError()
{
//alert(this.src);
//console.log("no image");
//do nothing
}
function do_something(mysrc) {

var a = $('<a/>').attr('id', 'space_ad_img', 'href', mysrc, 'src', mysrc);
$("#_ctl0_ContentPlaceHolder1_pnlStage1 img:first").wrap(a);
$("#_ctl0_ContentPlaceHolder1_pnlStage1").prepend('<h2 align=center style="color:red">Click on the ad to zoom</h2>');
$("a#space_ad_img").fancybox({
		'hideOnContentClick': false,
		'autoDimensions':false,
'width':950,
'autoScale':false,
'href':mysrc,
'titleShow': false
	});
$("a#space_ad_img").hover(function() {
$(this).css('cursor','pointer');
}, function() {
$(this).css('cursor','auto');
});
}

//check for space ad page
if(sPage=="space_ad.aspx") {
var src = $("#_ctl0_ContentPlaceHolder1_pnlStage1 img:first").attr('src').replace('.jpg','-L.jpg');
checkImage(src);
}
//end space ad zoom

});




