function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function validEmail(s){
	var i = 1;
	var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@")){ i++ }
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
		else i += 2;
	while ((i < sLength) && (s.charAt(i) != ".")){ i++ }
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else { return true; }
}

function validateNewsletterForm(form){
   if( validEmail(form.email.value) ) { return true; }
   else {
   	   alert('Please enter a valid email address');
	   form.email.focus();
	   return false;
   }
}

function playvideo(videoid) {
	window.open('/videos/video_popup.cfm?id='+videoid,'video','width=520, height=400');
}

function forumTermsOfUse() {
	window.open('/forums/guidelines_popup.cfm','terms','width=600, height=600, scrollbars=1, resizable=1');	
}

// share page functions

function showShareDialog(title, image) {
	var dialog = Ext.get('shareDialog');
	if( dialog) { dialog.show(); }
	else {
		Ext.Ajax.request({
			url: '/includes/sharepage.cfm',
			params: { title: title, image: image },
			success: function(response, options) { 
					var content = response.responseText;
					Ext.get('inner_sidebar').insertHtml('afterEnd',content);	
				},
			failure: function(){
				alert('Error connecting to server');
			},
			scope: this
		});	
	}	
}

function closeShareDialog() {
	var sentdlg = Ext.get('shareDialog-sent');	
	sentdlg.update('');
	sentdlg.dom.style.display = 'none';
	Ext.get('shareDialog').hide();
}

function validateShareDialog(form) {
	if( form.firstname.value.length == 0 ) {
		alert('Please enter your first name');
		form.firstname.focus();
		return false;
	}
	if( form.lastname.value.length == 0 ) {
		alert('Please enter your last name');
		form.lastname.focus();
		return false;
	}
	if( !validEmail(form.fromemail.value) ) {
		alert('Please enter a valid email address for yourself');
		form.fromemail.focus();
		return false;
	}
	if( !validEmail(form.toemail.value) ) {
		alert('Please enter a valid email address for your friend');
		form.toemail.focus();
		return false;
	}
	return true;
}

function submitShareDialog() {
	var form = Ext.get('shareform').dom;
	var ccme = form.ccMe.checked ? 1 : 0;
	
	Ext.Ajax.request({
		url: '/components/public.cfc',
		params: { method: 'sharePage', firstname: form.firstname.value, lastname: form.lastname.value,
				  fromemail: form.fromemail.value, toemail: form.toemail.value, message: form.message.value,
				  ccme: ccme, title: form.title.value },
		success: function(response, options) {
				var str = '<h3>email sent!</h3><p>Your email has been sent to:<br><strong>'+options.toemail+'</strong>.</p>'
				var sentdlg = Ext.get('shareDialog-sent');
				sentdlg.update(str);
				sentdlg.show();
				window.scrollTo(0,0);
			},
		failure: function(){
			alert('Error connecting to server');
		},
		toemail: form.toemail.value,
		scope: this
	});
}

//--------------- store functions ------------------------------------------------------------


function notifyme(sku) {
  var winName = "notify";
  var theURL = "/store/site/notify_when_available.cfm?sku="+sku;
  var features = "resizable=yes,width=500,height=250";
  window.open(theURL,winName,features);
}

function secureShopping() {
  var winName = "secureShopping";
  var theURL = "/customercare/secureshopping_popup.cfm";
  var features = "resizable=no,width=500,height=300";
  window.open(theURL,winName,features);
}

function shippingInformation() {
  var winName = "shippingInformation";
  var theURL = "/customercare/shipping_popup.cfm";
  var features = "resizable=no,width=600,height=700,scrollbars=yes";
  window.open(theURL,winName,features);
}

function returnPolicy() {
  var winName = "returnPolicy";
  var theURL = "/customercare/returns_popup.cfm";
  var features = "resizable=no,width=600,height=400";
  window.open(theURL,winName,features);
}

function taxPolicy() {
  var winName = "taxPolicy";
  var theURL = "/customercare/taxes_popup.cfm";
  var features = "resizable=no,width=600,height=400";
  window.open(theURL,winName,features);
}

function shipOutsideUS() {
  location = '/customercare/ship_international.cfm'
}

// this function is used for displaying online store items
function show(itemno) {
  location = "/store/site/product.cfm?sku="+itemno+"&killnav=1";
}

// load a department in the new online store
function showdept(deptCode) {
  location = "/store/site/department.cfm?dc="+deptCode+"&killnav=1";
}

// this function is used for displaying online store categories
function showcat(catno) {
  location = "/store/site/department.cfm?oidx="+catno+"&killnav=1";
}

// use this function to link to the store in a particular category!
function lookup(cat, cat2) {
  location = "/store/site/department.cfm?oidx="+cat2+"&killnav=1";
}


//--------------------------------------------------------------------------------------------

function enlargeImage() {
	var src = this.src.replace('view=thumb','view=large');
	popImage(src);
}

// opens a window and sizes to the size of the image contained

function popImage(imageURL,imageTitle){
	
// Set the horizontal and vertical position for the popup
var PositionX = 100;
var PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
var defaultWidth  = 500;
var defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = false;

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,resizable,width=250,height=100,left='+PositionX+',top='+PositionY;
	
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(250,100);');
writeln('width=250-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
