<!-- hide script from old browsers

var type = "IE";	//Variable used to hold the browser name
var agt=navigator.userAgent.toLowerCase();
BrowserSniffer();

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else if (agt.indexOf("safari") != -1) type="SF";							            //Safari
	else type = "IE";		//I assume it will not get here
}

function ShowLayer(id, action){
	if (type=="IE") eval("document.all." + id + ".style.display='" + action + "'");
	if (type=="NN") eval("document." + id + ".display='" + action + "'");
	if (type=="MO" || type=="OP" || type=="SF") eval("document.getElementById('" + id + "').style.display='" + action + "'");

}

function visiLayer(id, action){
	if (type=="IE") eval("document.all." + id + ".style.visibility='" + action + "'");
	if (type=="NN") eval("document." + id + ".visibility='" + action + "'");
	if (type=="MO" || type=="OP" || type=="SF") eval("document.getElementById('" + id + "').style.visibility='" + action + "'");

}

var cur_lyr;
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// end hiding script from old browsers -->

var newWindow;

function subWindow() {
    if (arguments.length < 1) {
        alert("function subWindow called with " + arguments.length +
              " arguments, but it expects at least 1 arguments.");
        return null;
    }
    var heightval = arguments[1] != null ? arguments[1] : 480;
    var widthval = arguments[2] != null ? arguments[2] : 640;
    var filename = arguments[3] != null ? arguments[3] : "";
	var scrollbars = arguments[4] != null ? arguments[4] : 1;
	var LeftPosition = (screen.width) ? (screen.width-widthval)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height-heightval)/2 : 0;
	
    var dimensions = "directory=0,height="+heightval+",width="+widthval+
                     ",left="+LeftPosition+",top="+TopPosition+",resizable=1,statusbar=0,hotkeys=0,menubar=0,scrollbars="+scrollbars+",status=0,toolbar=0";

    var newWindow = window.open(filename,arguments[0],dimensions);
	{newWindow.focus()}

    if (!filename) {
        newWindow.document.write("<title>B&H Photo-Video Pro Audio, The world's largest dealer of imaging equipment at discount prices</title>")
        newWindow.document.write("<center><font size=4 color='red'>Loading, please wait...</font></center>")
    }
    return;
}




function subWindowNoScrollBars() {
    if (arguments.length < 1) {
        alert("function subWindowNoScrollbars called with " + arguments.length +
              " arguments, but it expects at least 1 arguments.");
        return null;
    }
    var heightval = arguments[1] != null ? arguments[1] : 480;
    var widthval = arguments[2] != null ? arguments[2] : 640;
    var filename = arguments[3] != null ? arguments[3] : "";
    return subWindow(arguments[0],heightval,widthval,filename,0);
}
function openchatpopup () {

	subWindow('livechat', 350, 650, '/find/liveChat.jsp', 0);

 }
// Resize Reload -->
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->

//Self Close Window
var closeTime = 0;
function closeWindow(closeTime){
setTimeout("self.close()",closeTime);
}




var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();


function ToggleItem(id, name) {
	objs = document.getElementsByName(name);
	
	for(var i=0; i < objs.length; i++){
		var obj = objs[i].parentNode;

		visible = (obj.style.display != 'none');
	
		if (visible)
		{
			obj.style.display = 'none';
		}
		
		document.getElementById(id).style.display = 'block';
	}
}

/* Start Header-Footer stuff*/	
function getCookie(c_name)
	{
		if (document.cookie.length>0)
		{
			c_start = document.cookie.indexOf(c_name + "=");
			if( c_start != -1 )
			{ 
				c_start = c_start + c_name.length + 1; 
				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 "";
	}
	var cartCookie = getCookie('TopBarCart');
	var hasCartCookie = cartCookie != "null" && cartCookie != "";
	var cookieData = hasCartCookie ? cartCookie.split("|") : null;


// Form Validation //
searched = false;
function validateForm(form, searchField)
{

	var searchString = searchField.value;

	searchString = searchString.replace(/^\s+/, "").replace(/\s+$/, "");
	
		if(!searched || searchString == '' ){
    		alert("Please enter keyword(s) or item number and try again");
        	return false;
        }
        
	searchField.value = searchString == null ? "" : searchString;
    if( searchField.value.length < 2 || searchField.value.search(/[^\*].*[^\*]/)==-1)
	{
        alert("- Please enter keyword 2 letters or more");
        return false;
    }
}

function clearDefaultSearch(el) {
	searched = true;
  	if (el.defaultValue==el.value) el.value = "";
}

function ForceNumericInput(This, e, AllowDot, AllowMinus)
{
	//this happens only wants the element has been updated and it forces only two numbers after decimal
	if((This.value.indexOf(".") != -1) && !e)
	{    		
		if(This.value.substr(This.value.indexOf(".") , This.value.length).length > 2)
		{
			This.value = This.value.substr(0 , (This.value.indexOf(".") + 3));
			return
		}
	}
	var ev = (window.event)? window.event: e;	
	if(ev)
	{
		var code = (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which);
    
		switch(code)
		{
			case 8:     // backspace
			case 9:     // tab
			case 37:    // left arrow
			case 39:    // right arrow
			case 46:    // delete
			case 13:    // enter
            	return;
		}
		if(AllowDot && (code == 190 || code == 110))
		{	
			// don't allow more than one dot
			if(This.value.indexOf(".") >= 0)
			{
				//check if firefox
				(window.event) ? (ev.returnValue=false) : (ev.preventDefault());
				return;
			}
			return;
		}
		// allow character of between 0 and 9
		if((code >= 48 && code <= 57) || (code >= 96 && code <= 105))
		{
			// wait until the element has been updated to make force only two numbers after decimal, the element has to have an id
			if(This.value.indexOf(".") != -1)
			{    		
				if(This.value.substr(This.value.indexOf(".") , This.value.length).length > 2)
				{
					var s = "ForceNumericInput(document.getElementById('"+This.id+"'))";
					setTimeout(s, 250);
					return;
				}
			}
			return;
		}
		//check if firefox
		(window.event) ? (ev.returnValue=false) : (ev.preventDefault());
	}
}
