// boscovs.js
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	
	function openAboutCoupons()
	{
		window.open('AboutCoupons.bos','newwindow','menubar=no,width=400, height=600, resizable=yes,scrollbars=no');
	}
	
	function checkCountry()
    {
	   	var country = document.getElementById("country");
		delivery = (country.value == 'USA'); 
    	if(!delivery)	
    		alert("We currently do not ship to locations outside the continental United States, including Alaska and Hawaii.");
    } 
    
    function checkBillingState()
	{
    		var state   = document.getElementById('billingAddress.state');
   			delivery = !(state.value == 'AK' || state.value == 'HI');
    		if(delivery == false)
    		{
    			alert("We currently do not ship to locations outside the continental United States, including Alaska and Hawaii.");
     		}
	} 
    
  	function checkState()
	{
    		var state   = document.getElementById('state');
   			delivery = !(state.value == 'AK' || state.value == 'HI');
    		if(delivery == false)
    		{
    			alert("We currently do not ship to locations outside the continental United States, including Alaska and Hawaii.");
     		}
	} 
	
	function openRebate(rebateId)
	{
		window.open('Rebate.bos?rebateId='+rebateId,'newwindow','menubar=no,height=400,width=300,resizable=yes,scrollbars=no');
	}
	
	function openGiftWrap()
	{
		window.open('GiftWrapping.bos','newwindow','menubar=no,height=500,width=500,resizable=yes,scrollbars=yes');
	}
	
	function openSecurePaymentAuth()
	{
		window.open('SecurePaymentAuthorization.bos','pauth','menubar=no,height=400,width=390,resizable=no,scrollbars=no');
	}
	
	function openDelivery()
	{
		window.open('ShippingAssistant.bos','newwindow','menubar=no,height=500,width=500,resizable=yes,scrollbars=yes');
	}
	
	function openReturn()
	{
		window.open('ReturnPolicy.bos','newwindow','menubar=no,height=700,width=800,resizable=yes,scrollbars=yes');
	}
	
	function openPrivacyPolicy()
	{
		window.open('PrivacyPolicy.bos','newwindow','menubar=no,height=700,width=800,resizable=yes,scrollbars=yes');
	}
	
	function openBoscovsTerms()
	{
		window.open('BoscovsTermsAndConditions.bos','newwindow','menubar=no,height=700,width=800,resizable=yes,scrollbars=yes');
	}
	
	function openGuarantee()
	{
		window.open('Guarantee.bos','newwindow','menubar=no,height=500,width=500,resizable=yes,scrollbars=yes');
	}
	
	function openCustomerService()
	{
		javascript:window.open('FAQ.bos','newwindow','menubar=no,height=800,width=800,resizable=yes,scrollbars=yes');
	}
	
	function openShoppingAssistant(){
		window.open('ShoppingAssistant.bos','newwindow','menubar=no,height=500,width=500,resizable=yes,scrollbars=yes');
	}
	
	function openCVV2(){
		window.open('CVV2.bos','newwindow','menubar=no,width=350,height=390,resizable=yes,scrollbars=no');
	}
	
	function openWhatsAPin()
	{
		window.open('WhatsAPin.bos','newwindow','menubar=no,height=400,width=400,resizable=yes,scrollbars=no');
	}
		
	function openAlternate(imageName)
	{
		window.open('AltImage.bos?altImageName='+imageName,'newwindow','menubar=no,height=460,width=420,resizable=yes,scrollbars=no');
	}
	
	function changeProductButtonValue(bv)
	{
		document.addForm.productSubmitButton.value=bv;
		return true;
	}
	
	function changeButtonAndPostAddToCartForm(bv)
	{	
		changeProductButtonValue(bv);
		return postAddToCartForm();
	}
	
	function postAddToCartForm()
	{
		document.addForm.submit();
	}
	
	function popup(url, width, height) 
	{
		if (!width)
			var width = 500;
		if (!height)
			var height = 450;
		
    	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=' + width + ',height=' + height);
	    self.name = "mainWin";
    }
	
	   
    function popupCreditApplication(url) 
	{
    	creditWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=800,height=575');
	    self.name = "mainWin";
    }
	
    function applyHSBC()
	{
		document.Form1.submit();
	}
    
    function replyHSBC()
	{
		document.reply.submit();
	}
    
    function autoTab(input,len, e) 
	{
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) 
		{
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
		}
	
		function containsElement(arr, ele) 
		{
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			{
				found = true;
			}
			else
			{
				index++;
			}
			return found;
		}
		
		function getIndex(input) 
		{
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)
			{
				index = i;
			}
			else 
			{
				i++;
			}
			return index;
		}
		return true;
	}
	
	function handleCardTypeChange()
	{
		var sel = document.getElementById("creditCard.paymentPlanOption");
		
		if(sel.options[sel.selectedIndex].value.indexOf("Boscov") == 0)
		{
			document.getElementById("creditCard.verificationCode").disabled = true;
			document.getElementById("creditCard.month").disabled = true;
			document.getElementById("creditCard.year").disabled = true;
		}
		else
		{
			document.getElementById("creditCard.verificationCode").disabled = false;
			document.getElementById("creditCard.month").disabled = false;
			document.getElementById("creditCard.year").disabled = false;
		}		
	}
	
	function submitMarcoleRegistry()
	{
		document.forms['marcolenavform'].submit();
	}	
	
	function changeFormActionAndSubmit(formName, formAction)
	{
		var formObj = document.getElementById(formName);
		formObj.action = formAction;
		formObj.submit();
	}
	
	function popUp(url) 
	{
		popupWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,width=570,height=450');
		self.name = "mainWin"; 
	}
	
	function writeExternalLinkageForm(serverUrl,sessionid, styleid, regid)
	{
       gol = new GenericOnlineLinker();
       gol.setServerURL(serverUrl);
       gol.setNavKey( 'guest.registryDetail' );
       gol.setTransaction( 'RegistryDetail' );
       gol.setLastTransaction( 'InitializeRetailer' );
       gol.setViewId( 'jsp' );
       gol.setSessionId(sessionid);
       gol.setStyleId( styleid );
       gol.setRegistryId( regid );
       gol.setRetailerId( '0' );
       gol.setApplId( 'gol' );
       gol.setStoreId( '80001' );
	   
       gol.writeForm();
	}
	
	function backToRegistry()
	{
		document.navform.submit();
	}
	
	function showAdobe(imageFile)
	{
		window.open(imageFile, "_blank", "width=900,height=600,resizeable=yes,scrollbars=yes");
		return false;
	}
	
	function validateEmail(form_id, email) 
	{
		var options = { url : "/StoreFrontWeb/email-regex.js", async : false};
		var response = $.ajax(options);
		var data = jQuery.parseJSON(response.responseText);
        var reg = new RegExp(data.emailRegex);
		var input  =document.forms[form_id].elements[email];
		
		if(input != null)
		{
			var address = jQuery.trim(input.value);
			document.forms[form_id].elements[email].value = address;
		
			if(reg.test(address) == false) 
			{
				alert('Invalid Email Address');
				return false;
			}
		}
		return true;
	}
	
	function toggleContactUsFields()
	{
		
		var subject = document.getElementById("subject").value;
		
		document.getElementById("documentNumberRow").style.display = 'none';
		document.getElementById("storeLocationRow").style.display = 'none';
		document.getElementById("orderNumberRow").style.display = 'none';
		
		document.getElementById("storeLocation").disabled=true;
		document.getElementById("documentNumber").disabled=true;
		
		//ReportPostDeliveryIssue
		if(subject == "5")
		{
			document.getElementById("documentNumberRow").style.display = '';
			document.getElementById("orderNumber").value = '';
			document.getElementById("storeLocation").value = '';
			
			document.getElementById("storeLocation").disabled=true;
			document.getElementById("documentNumber").disabled=false;
		}
		//CommentsOnRecentStoreVisit
		else if (subject == "8")
		{
			document.getElementById("storeLocationRow").style.display = '';
			document.getElementById("documentNumber").value = '';
			document.getElementById("orderNumber").value = '';
			
			document.getElementById("storeLocation").disabled=false;
			document.getElementById("documentNumber").disabled=true;
		}
		//OnlineAndPhoneOrders
		else if(subject == "1")
		{
			document.getElementById("orderNumberRow").style.display = '';
			document.getElementById("documentNumber").value = '';
			document.getElementById("storeLocation").value = '';
			
			document.getElementById("storeLocation").disabled=true;
			document.getElementById("documentNumber").disabled=true;
		}
		else
		{
			document.getElementById("documentNumber").value = '';
			document.getElementById("orderNumber").value = '';
			document.getElementById("storeLocation").value = '';
			
			document.getElementById("storeLocation").disabled=true;
			document.getElementById("documentNumber").disabled=true;
		}
	}

	var searchJson;

	function popupEgiftCardPreview() 
	{
		var values = $(egiftCardFormDivId).serialize();
		var myWindow=window.open('','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=700,height=800');
		$.post(egiftCardPreviewUri,values ,function(data){ myWindow.document.write(data);	myWindow.focus();});
	}

	function verifySearchType()
	{
		var searchText = $('#searchText').val();
		var options = { url : "/StoreFrontWeb/search-type.js?searchText="+searchText, async : false};
		var response = $.ajax(options);
		var data = jQuery.parseJSON(response.responseText);
		if(data.isRedirect == "true")
		{
			var myWindow=window.open(data.url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=800,height=600');
			myWindow.focus();
			return false;
		}	
		return true;
	}
