function webExtra(strUrl, strName, strFeatures) {
    var win = window.open(strUrl, strName, strFeatures);
    win.focus();
}

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;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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 changeImage(objname,imagename)
{
	var obj = document.getElementById(objname);
	if (obj != undefined)
		obj.src = imagename;
}

function infoPop(dest, width, height, scroll, resize) {
    theHeight = height;
    theWidth = width;
    theVerticalOffset = 0;
    theWindow = window.open(dest, 'it', 'width=' + theWidth + ',height=' + theHeight + ',scrollbars=' + scroll + ',resizable=' + resize + ',status=no');
    theWindow.moveTo(screen.width/2-(theWidth/2),screen.height/2-(theHeight/2)-theVerticalOffset);
}

	timeout =0;
	function Start(URL, WIDTH, HEIGHT) {
	windowprops = "left=50,top=50,width=" + (WIDTH+50) + ",height=" + (HEIGHT+50);
	text = "<html><head><title>Preview</title></head><body bgcolor='black'";
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + URL + "'>";
	if (timeout != 0) text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	text += "</center></body></html>";
	o4bpopup = window.open("", "preview", windowprops);
	o4bpopup.document.open();
	o4bpopup.document.write(text);
	o4bpopup.document.close();
}

	timeout =0;
	function Start1(URL, WIDTH, HEIGHT) {
	windowprops = "left=50,top=50,width=" + (WIDTH+50) + ",height=" + (HEIGHT+50);
	text = "<html><head><title>Preview</title></head><body bgcolor='white'";
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + URL + "'>";
	if (timeout != 0) text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	text += "</center></body></html>";
	o4bpopup = window.open("", "preview", windowprops);
	o4bpopup.document.open();
	o4bpopup.document.write(text);
	o4bpopup.document.close();
}

	timeout =0;
	function Start2(URL, NAME, WIDTH, HEIGHT) {
	windowprops = "left=50,top=50,location=no,directories=no,width=" + (WIDTH+50) + ",height=" + (HEIGHT+50);
	text = "<html><head><title>" + NAME + "</title></head><body bgcolor='white'";
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + URL + "'>";
	if (timeout != 0) text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	text += "</center></body></html>";
	o4bpopup = window.open("", NAME, windowprops);
	o4bpopup.document.open();
	o4bpopup.document.write(text);
	o4bpopup.document.close();
}
	timeout =0;
	function Start3(URL, NAME, WIDTH, HEIGHT) {
	windowprops = "left=50,top=50,location=no,directories=no,scrollbars=yes,width=" + (WIDTH+50) + ",height=" + (HEIGHT+50);
	text = "<html><head><title>" + NAME + "</title></head><body bgcolor='black'";
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + URL + "'>";
	if (timeout != 0) text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	text += "</center></body></html>";
	o4bpopup = window.open("", NAME, windowprops);
	o4bpopup.document.open();
	o4bpopup.document.write(text);
	o4bpopup.document.close();
}

function dupeBilling() {

	if (document.Form1.chkSameAsBilling.checked) {
	
		document.Form1.ddlShipCountry.value = document.Form1.ddlBillCountry.value;
		setAddressView("Ship");
		document.Form1.txtShipFirstName.value = document.Form1.txtBillFirstName.value;
		document.Form1.txtShipLastName.value = document.Form1.txtBillLastName.value;
		document.Form1.txtShipCompany.value = document.Form1.txtBillCompany.value;
		document.Form1.txtShipAddress1.value = document.Form1.txtBillAddress1.value;
		document.Form1.txtShipAddress2.value = document.Form1.txtBillAddress2.value;
		document.Form1.txtShipCity.value = document.Form1.txtBillCity.value;
		document.Form1.txtShipZip.value = document.Form1.txtBillZip.value;
		document.Form1.txtShipPhone.value = document.Form1.txtBillPhone.value;
		document.Form1.ddlShipState.selectedIndex = document.Form1.ddlBillState.selectedIndex;
	} else {
		document.Form1.ddlShipCountry.selectedIndex = 0
		setAddressView("Ship");
		document.Form1.txtShipFirstName.value = ""
		document.Form1.txtShipLastName.value = ""
		document.Form1.txtShipCompany.value = ""
		document.Form1.txtShipAddress1.value = ""
		document.Form1.txtShipAddress2.value = ""
		document.Form1.txtShipCity.value = ""
		document.Form1.txtShipZip.value = ""
		document.Form1.txtShipPhone.value = ""
		document.Form1.ddlShipState.selectedIndex = 0
	}
}

function setPOText()
{
	if (document.Form1.radPurchaseOrder.checked)
	{
		document.Form1.disabled = false;
	}
	else
	{
		document.Form1.disabled = true;
	}
	
}

function verifyContinue()
{
	var errorMsg = "";

	// Validate address information
	
	// Billing
	var billfirstName = document.Form1.txtBillFirstName.value;
	if (billfirstName.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing first name is required.</li>";
	}
	
	var billLastName = document.Form1.txtBillLastName.value;
	if (billLastName.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing last name is required.</li>";
	}
	
	var billAddress1 = document.Form1.txtBillAddress1.value;
	if (billAddress1.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing address line 1 is required.</li>";
	}
	
	var billCity = document.Form1.txtBillCity.value;
	if (billCity.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing city is required.</li>";
	}
				
	var billState = document.Form1.ddlBillState;
	if (billState.selectedIndex == 0)
	{
		errorMsg = errorMsg + "<li>Billing state is required.</li>";
	}
	
	var billZip = document.Form1.txtBillZip.value;
	if (billZip.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing ZIP is required.</li>";
	}
	
	var billPhone = document.Form1.txtBillPhone.value;
	if (billPhone.length == 0)
	{
		errorMsg = errorMsg + "<li>Billing phone is required.</li>";
	}
	
	// Shipping
	var shipFirstName = document.Form1.txtShipFirstName.value;
	if (shipFirstName.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping first name is required.</li>";
	}
	
	var shipLastName = document.Form1.txtShipLastName.value;
	if (shipLastName.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping last name is required.</li>";
	}
	
	var shipAddress1 = document.Form1.txtShipAddress1.value;
	if (shipAddress1.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping address line 1 is required.</li>";
	}
	
	var shipCity = document.Form1.txtShipCity.value;
	if (shipCity.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping city is required.</li>";
	}
				
	var shipState = document.Form1.ddlShipState;
	if (shipState.selectedIndex == 0)
	{
		errorMsg = errorMsg + "<li>Shipping state is required.</li>";
	}
	
	var shipZip = document.Form1.txtShipZip.value;
	if (shipZip.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping ZIP is required.</li>";
	}
	
	var shipPhone = document.Form1.txtShipPhone.value;
	if (shipPhone.length == 0)
	{
		errorMsg = errorMsg + "<li>Shipping phone is required.</li>";
	}
	
	if (errorMsg.length > 0)
	{
		errorMsg = "Oops!  There was a problem with your entry:<ul>" + errorMsg + "</ul>";
		document.getElementById("lblFeedbackContinue").innerHTML = errorMsg;
		return 0;
	}
	else
	{
		__doPostBack("btnCheckOut", "");
		return 1;
	}	
}

function verifyNewAccount()
{
	var errorMsg = "";

	// Validate address information
	
	// Billing
	var firstName = document.Form1.txtNewCustomerFirstName.value;
	if (firstName.length == 0)
	{
		errorMsg = errorMsg + "<li>First name is required.</li>";
	}
	
	var lastName = document.Form1.txtNewCustomerLastName.value;
	if (lastName.length == 0)
	{
		errorMsg = errorMsg + "<li>Last name is required.</li>";
	}
	
	var email = document.Form1.txtNewCustomerEmail.value;
	if (email.length == 0)
	{
		errorMsg = errorMsg + "<li>An e-mail address is required.</li>";
	}
	
	var password = document.Form1.txtNewCustomerPassword.value;
	if (password.length == 0)
	{
		errorMsg = errorMsg + "<li>A password is required.</li>";
	}
		
	var passwordConfirm = document.Form1.txtNewCustomerPasswordConfirm.value;
	if (passwordConfirm.length == 0)
	{
		errorMsg = errorMsg + "<li>A confirmation password is required.</li>";
	}
	
	
	if (passwordConfirm != password)
	{
		errorMsg = errorMsg + "<li>Your passwords didn't match.</li>";
	}
	
	if (errorMsg.length > 0)
	{
		errorMsg = "Oops!  There was a problem with your entry:<ul>" + errorMsg + "</ul>";
		document.getElementById("lblFeedbackNewCustomer").innerHTML = errorMsg;
		return 0;
	}
	else
	{
		__doPostBack("btnNewCustomerCheck", "");
		return 1;
	}	
}

function verifyProcess()
{
	
	var orderTotal;
	var afterGC = document.getElementById("lblOrderTotalAfterGCs").innerHTML.replace(/^\s*|\s*$/g,"");
		
	if (afterGC.length == 0)
		orderTotal = parseFloat(document.getElementById("lblTotal").innerHTML.replace("$", ""));
	else
		orderTotal = parseFloat(afterGC.replace("$", ""));
	
	if (orderTotal > 0.009)
	{
		// Validate the credit card information
		var cardType = document.Form1.ddlCardType;
		var errorMsg = "";
		if (cardType.selectedIndex == 0)
		{
			errorMsg = errorMsg + "<li>Card type not specified</li>";
		}
		
		var cardNumber = document.Form1.txtCardNumber.value;
		if (cardNumber.length == 0)
		{
			errorMsg = errorMsg + "<li>Invalid card number</li>";
		}
		
		var expireMonth = document.Form1.ddlExpireMonth;
		if (expireMonth.selectedIndex == 0)
		{
			errorMsg = errorMsg + "<li>Expire month not set</li>";
		}
		
		var expireYear = document.Form1.ddlExpireYear;
		if (expireYear.selectedIndex == 0)
		{
			errorMsg = errorMsg + "<li>Expire year not set</li>";
		}
		
		var cvc = document.Form1.txtCardVerificationCode.value;
		if (cvc.length == 0)
		{
			errorMsg = errorMsg + "<li>Credit Card verification required</li>";
		}
		
		if (errorMsg.length > 0)
		{
			errorMsg = "Oops!  There was a problem with your entry:<ul>" + errorMsg + "</ul>";
			document.getElementById("lblFeedbackProcess").innerHTML = errorMsg;
			return 0;
		}
		else
		{
			__doPostBack("btnProcess", "");
			return 1;
		}
	}
	else
	{
		__doPostBack("btnProcess", "");
		return 1;
	}	
}

function setAddressView(billOrState)
{
	
	var txtBillFirstName = document.getElementById("txt" + billOrState + "FirstName");
	
	if (txtBillFirstName != null)
	{
		var ddlCountry = document.getElementById("ddl" + billOrState + "Country");
		var index = ddlCountry.selectedIndex;
		var countryCode = ddlCountry.options[index].value;
		var arrStateValue;
		var arrStateText;
		var stateInstruction;
		var cityLabel;
		var stateLabel;
		var zipLabel;
		var stateDropDownView;
		var stateValueView;
		
		if (countryCode == "US")
		{
			
			// USA
			arrStateValue = new Array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","GU","HI","ID","IL","IN","IA",
				"KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR",
				"PA","PR","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AA","AE","AP");
			arrStateText = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut",
				"Delaware","District of Columbia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa",
				"Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana",
				"Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon",
				"Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington",
				"West Virginia","Wisconsin","Wyoming","Armed Forces Americas","Armed Forces Europe","Armed Forces Pacific");
			
			stateInstruction = "-- Choose a state --";
			cityLabel = "City";
			stateLabel = "State";
			zipLabel = "ZIP Code";
			stateDropDownView = "visible";
			stateValueView = "hidden";
			
		}
		else if (countryCode == "CA")
		{
			// Canada
			arrStateValue = new Array("AB","BC","MB","NB","NL","NT","NS","NU","ON","PE","QC","SK","YT");
			arrStateText = new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland and Labrador","Northwest Territories",
				"Nova Scotcha","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon");
			stateInstruction = "-- Choose a province --";
			cityLabel = "City";
			stateLabel = "Province";
			zipLabel = "Postal Code";
			stateDropDownView = "visible";
			stateValueView = "hidden";
			
		}
		else if (countryCode == "GB")
		{
			// UK
			cityLabel = "Post Town";
			stateLabel = "";
			zipLabel = "Postal Code";
			stateDropDownView = "hidden";
			stateValueView = "hidden";
		}
		else if (countryCode == "AU")
		{
			// Australia
			arrStateValue = new Array("ACT","NSW","NT","QLD","SA","TAS","VC","WA");
			arrStateText = new Array("Australian Capital Territory","New South Wales","Northern Territory","Queensland","South Australia",
				"Tasmania","Victoria", "Western Australia");
				cityLabel = "City";
			stateInstruction = "-- Choose a State --";
			stateLabel = "State";
			zipLabel = "Postal Code";
			stateDropDownView = "visible";
			stateValueView = "hidden";
		}
		else if (countryCode == "FR")
		{
			// France
			cityLabel = "City";
			stateLabel = "";
			zipLabel = "Postal Code";
			stateDropDownView = "hidden";
			stateValueView = "hidden";
		}
		else if (countryCode == "DE")
		{
			// Germany
			cityLabel = "City";
			stateLabel = "";
			zipLabel = "Postal Code";
			stateDropDownView = "hidden";
			stateValueView = "hidden";
		}
		else if (countryCode == "IE")
		{
			// UK
			cityLabel = "Post Town";
			stateLabel = "";
			zipLabel = "Postal Code";
			stateDropDownView = "hidden";
			stateValueView = "hidden";
		}
		else
		{
			// All others
			cityLabel = "City";
			stateLabel = "Province";
			zipLabel = "Postal Code";
			stateDropDownView = "hidden";
			stateValueView = "visible";			
		}

		var ddlState = document.getElementById("ddl" + billOrState + "State");

		var txtStateValue = document.getElementById("txt" + billOrState + "StateValue");	
		
		if (stateValueView == "visible")
		{
			ddlState.style.display = "none";
			txtStateValue.style.display = "inline";
		}
		else
		{
			ddlState.style.display = "inline";
			txtStateValue.style.display = "none";
		}
		
		txtStateValue.style.visibility = stateValueView;
		
		var stateValue = txtStateValue.value;

		ddlState.style.visibility=stateDropDownView;

		if (stateDropDownView == "visible")
		{
			txtStateValue.style.display = "none";
			ddlState.length = 0;
			ddlState.options[0] = new Option(stateInstruction, "");
							
			for (var j =0; j<arrStateValue.length; j++)
			{
				ddlState.options[j+1] = new Option(arrStateText[j],arrStateValue[j]);
				if (arrStateValue[j] == stateValue)
					ddlState.options[j+1].selected = true;
			}
		}
		
		var lblCity = document.getElementById("lbl" + billOrState + "City");
		lblCity.innerHTML = cityLabel;
		
		var lblState = document.getElementById("lbl" + billOrState + "State");
		lblState.innerHTML = stateLabel;
		
		var lblZip = document.getElementById("lbl" + billOrState + "Zip");
		lblZip.innerHTML = zipLabel;
	}
}

function showDropDown(selectedDDL)
{

	var ddl = document.getElementById("ddlBrandsB");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsM");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsS");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsBC");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsT");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsRF");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsNVB");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsNVM");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsNVG");
	ddl.style.display = "none";
	ddl = document.getElementById("ddlBrandsNVL");
	ddl.style.display = "none";
	
	ddl = document.getElementById(selectedDDL);
	ddl.style.display = "block";
		
	/*	
	var ddlBrands = document.getElementById("ddlBrands"); 
	ddlBrands.options.length = 0;
	ddlBrands.options[ddlBrands.options.length] = new Option("Select a Brand...", "");

	for (j=0;j<ddl.options.length; j++)
	{
		ddlBrands.options[ddlBrands.options.length] = new Option(ddl.options[j].text,ddl.options[j].value);
	}

	if (ddlBrands.options.length > 0)
	{
		ddlBrands.focus();
	}
	
	ddlBrands.onchange = function() {
	doBrowse(this.value);
	}

*/
}

function initBrowser() 
{
	alert("dasfsdf");
	/*
	var aBinoculars = document.getElementById("aBinoculars");
	aBinoculars.setAttribute("href", categories.binoculars.href);
	
	alert(categories.binoculars.href);

	var aMonoculars = document.getElementById("aMonoculars");
	aMonoculars.setAttribute("href", categories.monoculars.href);

	var aScopes = document.getElementById("aScopes");
	aScopes.setAttribute("href", categories.scopes.href);

	var aTripods = document.getElementById("aTripods");
	aTripods.setAttribute("href", categories.tripods.href);

	var aRangeFinders = document.getElementById("aRangeFinders");
	aRangeFinders.setAttribute("href", categories.rangefinders.href);

	var aBinoCams = document.getElementById("aBinoCams");
	aBinoCams.setAttribute("href", categories.binocams.href);

	var aNightVision = document.getElementById("aNightVision");
	aNightVision.setAttribute("href", categories.nvbinoculars.href);

	*/
}

function doBrowse(href) {
	if (href != "")
	{
		document.location = href;
	}
}

function showHd(){
    if(document.getElementById("hpc").style.display == 'none')
    {
         document.getElementById("hpc").style.display = '';
    }
    else
    {
         document.getElementById("hpc").style.display = 'none';             
    }
}
