var curLoc;

// GLOBAL JAVASCRIPT FILE FOR VERLO MATTRESS FACTORY STORES

// BROWSER DETECTION //
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 
 
   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isFirefox    = (ua.indexOf('firefox/') != -1);   
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   if ( (this.isWin) && (this.isNS7x) ) {
  	  NetscapeVer = navigator.userAgent; 
	  NSVersion = NetscapeVer.substring(82,85);
   	  this.isNS7even = (NSVersion == 7.0);
   }
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();


function _validate(form) 
{
	if(form.zip.value.length != 5) 
	{
		alert("Please enter a valid, five-digit zip code, like '53711'.");
		form.zip.focus();
		return false;
	}
	form.submit();
	return true;
}
function _cleartxt()
{
	document.getElementById().value = '';
}

// IMAGE SWAPPING AND PRELOADING
function init(location) {
	MM_preloadImages(
		'/images/nav_ourproducts_on.gif',
		'/images/nav_learningcenter_on.gif',
		'/images/nav_customerservice_on.gif',
		'/images/nav_ourcompany_on.gif',
		'/images/nav_line01.gif',
		'/images/nav_line02.gif',
		'/images/nav_line03.gif'
	);
	if (location == 'home') {
		MM_preloadImages(
			'/images/home_craftsman_on.gif',
			'/images/home_findverlo_on.gif',
			'/images/home_rcolmod3_on.gif'						
		);
	}
	if (location == 'products') {
		MM_preloadImages(
			'/images/leftmod_findverlo_on.gif',
			'/images/leftmod_craftsman_on.gif',
			'/images/leftmod_valuecollect_on.gif',
			'/images/printthispage_on.gif',
			'/images/emailthispage_on.gif',
			'/images/rightmod_wishlist_on.gif'
		);
	}
	if (location == 'global') {
		MM_preloadImages(
			'/images/leftmod_findverlo_on.gif',
			'/images/leftmod_craftsman_on.gif',
			'/images/leftmod_valuecollect_on.gif',
			'/images/printthispage_on.gif',
			'/images/emailthispage_on.gif',
			'/images/util_setasmystore_on.gif',
			'/images/util_maptostore_on.gif',
			'/images/util_returntodetails_on.gif'
		);
	}
	if (location == 'vc') {
		MM_preloadImages(
			'/images/vc/tryagain_on.gif',
			'/images/vc/valuecollection_on.gif',
			'/images/vc/mailinglist_on.gif',
			'/images/vc/viewdetails_on.gif',
			'/images/vc/viewdetails_lg_on.gif'
		);
	}	
}


function imgRoll (OorF,imName) {
	if (OorF == 'on') {
		document.images[imName].src = '/images/' + imName + '_on.gif';
	}
	else {
		document.images[imName].src = '/images/' + imName + '_off.gif';
	}			
}

function vcimgRoll (OorF,imName, wchNum) {
	if (OorF == 'on') {
		if (imName == 'viewdetails' || imName == 'viewdetails_lg') {
			document.images[imName+wchNum].src = '/images/vc/' + imName + '_on.gif';
		}
		else {
			document.images[imName].src = '/images/vc/' + imName + '_on.gif';
		}
	}
	else {
		if (imName == 'viewdetails' || imName == 'viewdetails_lg') {
			document.images[imName+wchNum].src = '/images/vc/' + imName + '_off.gif';
		}
		else {
			document.images[imName].src = '/images/vc/' + imName + '_off.gif';
		}
	}
}

function navRoll (OorF,imName, lineNum1, lineNum2) {
	if (OorF == 'on') {
		document.images[imName].src = '/images/' + imName + '_on.gif';
		if (lineNum1 !== '') {
			document.images[lineNum1].src = '/images/nav_linecover.gif';
		}
		if (lineNum2 !== '') {
			document.images[lineNum2].src = '/images/nav_linecover.gif';
		}
	}
	else {
		document.images[imName].src = '/images/' + imName + '_off.gif';
		if (lineNum1 !== '') {
			document.images[lineNum1].src = '/images/nav_' + lineNum1 + '.gif';
		}
		if (lineNum2 !== '') {
			document.images[lineNum2].src = '/images/nav_' + lineNum2 + '.gif';
		}
	}			
}

function openPop(pg,pgType) {
	if (pgType == 'learningcenterpop') {
		wt = 501;
		ht = 275;
		if (browser.isSafari) {
			wt = 511;
		}
	} else if (pgType == 'ornbedspop') {
		wt = 527;
		ht = 510;
		if (browser.isSafari) {
			wt = 537;
		}
	} else if (pgType == 'CVV2Help') {
		wt = 550;
		ht = 510;
		if (browser.isSafari) {
			wt = 537;
		}
	} else if (pgType == 'futonframespop') {
		wt = 527;
		ht = 500;
		if (browser.isSafari) {
			wt = 537;
		}
	}else if (pgType == 'adpop') {
		wt = 724;
		ht = 688;
		if (browser.isSafari) {
			wt = 724;
		}
	}else if (pgType == 'adpop2') {
		wt = 346;
		ht = 652;
		if (browser.isSafari) {
			wt = 346;
		}
	}
	var str="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width="+wt+",height="+ht+",left=0,top=0";
	pop=window.open(pg,"Verlo",str);
	pop.focus();
}

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 printPage() { 
	if ( ((browser.isMac) && (browser.isIE5x)) || (browser.isOpera) ) {
		alert('To Print This Page Press: Apple-P, or click the print icon in your browsers toolbar');
	}
	else {
		window.print();
	}
}

function noSpam(user,domain) {
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
}
	

/*****************************************************
* ypSlideOutMenu
* 3/04/2001
* --youngpup--
*****************************************************/
ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 300
ypSlideOutMenu.hideDelay = 200
ypSlideOutMenu.minCPUResolution = 10
// constructor
function ypSlideOutMenu(id, dir, left, top, width, height) {
	this.ie = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0
	if (this.ie || this.ns4 || this.dom) {
		this.id = id
		this.dir = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType = dir == "right" || dir == "down" ? "-" : "+"
		this.dim = this.orientation == "h" ? width : height
		this.hideTimer = false
		this.aniTimer = false
		this.open = false
		this.over = false
		this.startTime = 0
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")
		ypSlideOutMenu.Registry[id] = this
		var d = document
		var strCSS = '<style type="text/css">';
		strCSS += '#' + this.id + 'Container { visibility:hidden; '
		strCSS += 'left:' + left + 'px; '
		strCSS += 'top:' + top + 'px; '
		strCSS += 'overflow:hidden; z-index:10; }'
		strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
		strCSS += 'width:' + width + 'px; '
		strCSS += 'height:' + height + 'px; '
		strCSS += '}'
		strCSS += '</style>'
		d.write(strCSS)
		this.load()
	}
}
ypSlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp
	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container = obj1
		this.menu = obj2
		this.style = this.ns4 ? this.menu : this.menu.style
		this.homePos = eval("0" + this.dirType + this.dim)
		this.outPos = 0
		this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 
		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")
		//set initial state
		this.endSlide()
	}
}
ypSlideOutMenu.showMenu = function(id) {
	// EDITED TO HIDE MENUS FOR OPERA //
	if (!browser.isOpera) {
		var reg = ypSlideOutMenu.Registry
		var obj = ypSlideOutMenu.Registry[id]
		if (obj.container) {
			obj.over = true
			for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)
			if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
			if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
		}
	}
}
ypSlideOutMenu.hideMenu = function(id) {
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
}
ypSlideOutMenu.hideAll = function() {
	var reg = ypSlideOutMenu.Registry
	for (menu in reg) {
		ypSlideOutMenu.hide(menu);
		if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
	}
}
ypSlideOutMenu.hide = function(id) {
	var obj = ypSlideOutMenu.Registry[id]
	obj.over = false
	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	obj.hideTimer = 0
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
}
ypSlideOutMenu.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime() 
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}
ypSlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-") d = -d
		else if (this.open && this.dirType == "+") d = -d
		else if (!this.open && this.dirType == "-") d = -this.dim + d
		else d = this.dim + d
		this.moveTo(d)
	}
}
ypSlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}
ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }




// DROP DOWN POSITIONING
var myMenu1 = new ypSlideOutMenu("menu1", "down", 0, 152, 210, 190)
var myMenu2 = new ypSlideOutMenu("menu2", "down", 0, 152, 210, 142)
var myMenu3 = new ypSlideOutMenu("menu3", "down", 0, 152, 210, 160)
var myMenu4 = new ypSlideOutMenu("menu4", "down", 0, 152, 210, 158)

var myOffset1 = -460;
var myOffset2 = -355;
var myOffset3 = -232;
var myOffset4 = -99;

var smallWinOffset1 = 29;
var smallWinOffset2 = 134;
var smallWinOffset3 = 257;
var smallWinOffset4 = 390;

myMenu1.onactivate = repositionMenu1
myMenu2.onactivate = repositionMenu2
myMenu3.onactivate = repositionMenu3
myMenu4.onactivate = repositionMenu4


function repositionMenu1() {
	if (getWindowWidth() < 800) {
		var newLeft = smallWinOffset1;
	}
	else {
		var newLeft = getWindowWidth() / 2 + myOffset1;
		if (browser.isFirefox) { newLeft = newLeft - 8; }
		else if ( (curLoc !=  'home') && (browser.isNS7x) ) { newLeft = newLeft - 8; }
	}
	myMenu1.container.style ? myMenu1.container.style.left = newLeft + "px" : myMenu1.container.left = newLeft;
}


function repositionMenu2() {
	if (getWindowWidth() < 800) {
		var newLeft = smallWinOffset2;
	}
	else {
		var newLeft = getWindowWidth() / 2 + myOffset2;
		if (browser.isFirefox) { newLeft = newLeft - 8; }
		else if ( (curLoc !=  'home') && (browser.isNS7x) ) { newLeft = newLeft - 8; }
	}
	myMenu2.container.style ? myMenu2.container.style.left = newLeft + "px" : myMenu2.container.left = newLeft;
}

function repositionMenu3() {
	if (getWindowWidth() < 800) {
		var newLeft = smallWinOffset3;
	}
	else {
		var newLeft = getWindowWidth() / 2 + myOffset3;
		if (browser.isFirefox) { newLeft = newLeft - 8; }
		else if ( (curLoc !=  'home') && (browser.isNS7x) ) { newLeft = newLeft - 8; }
	}
	myMenu3.container.style ? myMenu3.container.style.left = newLeft + "px" : myMenu3.container.left = newLeft;
}

function repositionMenu4() {
	if (getWindowWidth() < 800) {
		var newLeft = smallWinOffset4;
	}
	else {
		var newLeft = getWindowWidth() / 2 + myOffset4;
		if (browser.isFirefox) { newLeft = newLeft - 8; }
		else if ( (curLoc !=  'home') && (browser.isNS7x) ) { newLeft = newLeft - 8; }
	}
	myMenu4.container.style ? myMenu4.container.style.left = newLeft + "px" : myMenu4.container.left = newLeft;
}



function getWindowWidth() {
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}

function mailThisPage() {

	mail_str  = "mailto:?subject="+escape(document.title)+"&body="+escape("I thought you might be interested in this: ")+escape(location.href);
	location.href = mail_str;
}

function clearZip(element)
{
	if(element.value=='zip code')
	{
		element.value = '';
	}
}

function storeInfoToggle()
{
	var el = document.getElementById('storeinfo');
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
function toggleAddress()
{
		if(document.getElementById("sameaddress").checked)
		{
			document.getElementById("bfname").value = document.getElementById("sfname").value;
			document.getElementById("blname").value = document.getElementById("slname").value;
			document.getElementById("bcompany").value = document.getElementById("scompany").value;
			document.getElementById("badd1").value = document.getElementById("sadd1").value;
			document.getElementById("badd2").value = document.getElementById("sadd2").value;
			document.getElementById("bcity").value = document.getElementById("scity").value;
			document.getElementById("bzip").value = document.getElementById("szip").value;
			document.getElementById("bphone").value = document.getElementById("sphone").value;
		}
		else
		{
			document.getElementById("bfname").value="";
			document.getElementById("blname").value="";
			document.getElementById("bcompany").value="";
			document.getElementById("badd1").value="";
			document.getElementById("badd2").value="";
			document.getElementById("bcity").value="";
			document.getElementById("bzip").value="";
			document.getElementById("bphone").value ="";
		}
		
	}
	
    function updatePrice(element, c_id, l_id, q_id, franId)
    {
		
		var dropdownIndex = document.getElementById('sizeSel').selectedIndex;
		var sizeValue = document.getElementById('sizeSel')[dropdownIndex].value;
		var dropdownIndex = document.getElementById('typeSel').selectedIndex;
		var typeValue = document.getElementById('typeSel')[dropdownIndex].value;
		if(sizeValue !="")
		{
			document.getElementById('typeSel').removeAttribute('disabled');
		}
		if(typeValue !="")
		{
			document.getElementById('submit').removeAttribute('disabled');
		}
		
		poststring="c_id="+c_id+"&l_id="+l_id+"&q_id="+q_id+"&s_id="+sizeValue+"&t_id="+typeValue+"&franId="+franId;
		getPriceresponse(poststring);
  	}
    function getPriceresponse(poststring)
    {
    	var url = "/ajax/generateprice.jsp";
        poststring += '&rand=' + Math.floor(Math.random() * 999);
        var myAjax = new Ajax.Request(url,
        {
	        method: 'post',
            parameters: poststring,
            onComplete: refreshPage,
          	onFailure: function() { alert("There was trouble getting your information from the server."); }
        }
       	);
    }
    function refreshPage(response)
    {
    	$('priceAmount').update(response.responseText);
	}

	
	function getStoreInfo()
	{
		if(document.getElementById('zipbtn').value.length == 5)
		{
			$('zip').hide();
		}
	}

	function showZip()
	{
		$('zipdiv').show();
		$('storename').hide();
		$('priceAmount').hide();
		$('storechange').hide();
		document.getElementById('sizeSel').setAttribute('disabled', 'disabled');
		document.getElementById('typeSel').setAttribute('disabled', 'disabled');
		document.getElementById('submit').setAttribute('disabled', 'disabled');

	}
	
	function iszipFilled()
	{
		if(document.getElementById('zip').value.length == 5)
		{
				$('zipdiv').hide();
		}
	}
	function toggletab(element)
    {
          var ul = element.parentNode.parentNode;
          var childlisoful = ul.getElementsByTagName('li');
          for (var i=0; i < childlisoful.length; i++)
          {
                  childlisoful[i].className = '';
          }
          var li = element.parentNode;
          var childlis = li.getElementsByTagName('li');

          if (li.className == '')
          {
                  li.className = 'focused';
          }
          else
          {
                  li.className = '';
                  for (var i=0; i < childlis.length; i++)
                  {
                          childlis[i].className = '';
                  }

          }
    }
    function tab1()
    { 
		$('features').show();
    	$('warranty').hide();
    	$('reviewlogin').hide();
    	$('reviews').hide();
    	$('storeinfo').hide();
		$('reviewcomplete').hide();
    }

    function tab2()
    { 
   		$('features').hide();
    	$('warranty').show();
    	$('reviews').hide();
    	$('reviewlogin').hide();
    	$('storeinfo').hide();
		$('reviewcomplete').hide();
    }

    function tab3()
    { 
    	$('features').hide();
    	$('warranty').hide();
    	$('reviewlogin').hide();
    	$('reviews').show();
    	$('storeinfo').hide();
		$('reviewcomplete').hide();
    }

    function tab4()
    { 
		$('features').hide();
    	$('warranty').hide();
    	$('reviewlogin').hide();
    	$('reviews').hide();
    	$('storeinfo').show();
		$('reviewcomplete').hide();
    }
  
	function validateZipFrm()
	{
		if(document.getElementById('zip').value==null || document.getElementById('zip').value=="" || document.getElementById('zip').value.length !=5)
		{
			alert("Please enter a valid zip code.");
		}
		else
		{
			return true;
		}
		return false;
	}
	function disableAddCart()
	{
			document.getElementById('submit').setAttribute('disabled', 'disabled');
	}
	function enableAddCart()
	{
			document.getElementById('submit').removeAttribute('disabled');
	}
	function replaceMissingImages(element)
	{
	  	element.src = '/images/vproducts/photo_not_available.jpg';
		if(element.id == 'productdisplay')
		{
			$('largerPic').hide();
			element.style.marginBottom ="26px";
		}
	}
	function toggleNav(element, path)
	{
		var li = element.parentNode;
		var ul = document.getElementById('linelist');
	    var navlis = ul.getElementsByTagName('li')
		
	    for (var i=0; i < navlis.length; i++)
        {  
		 	navlis[i].className = '';

        }
	    
	
	    var childlis = li.getElementsByTagName('li');  
    	if (li.className == '')
        { 
            
            window.location="/products/"+path;
            //li.className = 'focused';
        }
        else
        {
        	li.className = '';
            for (var i=0; i < childlis.length; i++)
            {
            	childlis[i].className = '';
            }

        }

	}

	function validateCustomerInfo(source)
	{
	
		if((document.getElementById('semail').value.indexOf(".") < 2) || (document.getElementById('semail').value.indexOf("@") < 0))
		{
			alert("Please enter a valid email address.");
		    return false;	
		}
		if(document.getElementById('sfname').value =="")
		{
			alert("Please enter the your first name.");
			return false;
		}
		else if(document.getElementById('slname').value =="")
		{
			alert("Please enter your last name.");
			return false;
		}
		else if(document.getElementById('semail').value =="")
		{
			alert("Please enter your email.");
			return false;
		}
		else if(document.getElementById('sadd1').value =="")
		{
			alert("Please enter the shipping address.");
			return false;
		}
		else if(document.getElementById('scity').value =="")
		{
			alert("Please enter the shipping city.");
			return false;
		}
		else if(document.getElementById('szip').value =="")
		{
			alert("Please enter the shipping zip.");
			return false;
		}
		else if(document.getElementById('sphone').value =="")
		{
			alert("Please enter a home/mobile telephone number.");
			return false;
		}
		document.getElementById('cartfrm').submit();
		return true;
	
	}
	
	var ccErrors = new Array ()
	ccErrors [0] = "Unknown card type";
	ccErrors [1] = "No card number provided";
	ccErrors [2] = "Credit card number is in invalid format";
	ccErrors [3] = "Credit card number is invalid";
	ccErrors [4] = "Credit card number has an inappropriate number of digits";
	
	function validatePayment()
	{
	
		var radioObj = document.cartfrm.paymenttype;
	
		var paytype = "";
	
		if(!document.getElementById('oneaddress').checked)
		{

			
			if((document.getElementById('bemail').value.indexOf(".") < 2) || (document.getElementById('bemail').value.indexOf("@") < 0))
			{
				alert("Please enter a valid email address.");
			    return false;	
			}
			if(document.getElementById('bfname').value =="")
			{
				alert("Please enter the your first name.");
			    return false;
			}
			else if(document.getElementById('blname').value =="")
			{
				alert("Please enter your last name.");
				return false;
			}
			else if(document.getElementById('bemail').value =="")
			{
				alert("Please enter your billing email.");
				return false;
			}
			else if(document.getElementById('badd1').value =="")
			{
				alert("Please enter the billing address.");
				return false;
			}
			else if(document.getElementById('bcity').value =="")
			{
				alert("Please enter the billing city.");
				return false;
			}
			else if(document.getElementById('bzip').value =="")
			{
				alert("Please enter the billing zip.");
				return false;
			}
			else if(document.getElementById('bphone').value =="")
			{
				alert("Please enter a home/mobile telephone number.");
				return false;
			}
		}
		
		var radioLength = radioObj.length;
		if(radioLength == undefined)
		{
			if(radioObj.checked)
				paytype=radioObj.value;
		}
		for(var i = 0; i < radioLength; i++)
		{
		
			if(radioObj[i].checked)
			{
				paytype=radioObj[i].value;
			}
		}
		if(paytype =="")
		{
			alert("Please select a payment type.");
			return false;
		}
		if(document.getElementById('cardnum').value =="" )
		{
			alert("Please enter card number.");
		    return false;
		}
		/*if (!checkCreditCard(document.getElementById('cardnum').value, paytype)) 
		{
				alert(ccErrors[ccErrorNo]);
				return false;
		}*/
		if(document.getElementById('cvv').value =="")
		{
			alert("Please enter CVV2 Code.");
		    return false;
		}
		

	
		document.getElementById('cartfrm').submit();
		return true;
	}
	
	
	function checkCreditCard (cardnumber, cardname) {
    // Array to hold the permitted card characteristics

	  var cards = new Array();

	  // Define the cards we support. You may add addtional card types.

	  //  Name:      As in the selection box of the form - must be same as user's
	  //  Length:    List of possible valid lengths of the card number for the card
	  //  prefixes:  List of possible prefixes for the card
	  //  checkdigit Boolean to say whether there is a check digit

	  cards [0] = {name: "Visa", 
	               length: "13,16", 
	               prefixes: "4",
	               checkdigit: true};
	  cards [1] = {name: "Mastercard", 
	               length: "16", 
	               prefixes: "51,52,53,54,55",
	               checkdigit: true};
	  cards [2] = {name: "Amex", 
	               length: "15", 
	               prefixes: "34,37",
	               checkdigit: true};
	  cards [3] = {name: "Discover", 
	               length: "16", 
	               prefixes: "6011,622,64,65",
	               checkdigit: true};
	
	  
	  // Establish card type
	  var cardType = -1;
	  for (var i=0; i<cards.length; i++) {

	    // See if it is this card (ignoring the case of the string)

		if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
	      cardType = i;
  		  break;
	    }
	  }

	  // If card type not found, report an error

	if (cardType == -1) {
	    
		 ccErrorNo = 0;
	     return false; 
	  }

	  // Ensure that the user has provided a credit card number
	  if (cardnumber.length == 0)  {
	     ccErrorNo = 1;
	     return false; 
	  }

	  // Now remove any spaces from the credit card number
	  cardnumber = cardnumber.replace (/\s/g, "");

	  // Check that the number is numeric
	  var cardNo = cardnumber
	  var cardexp = /^[0-9]{13,19}$/;
	  if (!cardexp.exec(cardNo))  {
	     ccErrorNo = 2;
	     return false; 
	  }

	  // Now check the modulus 10 check digit - if required
	  if (cards[cardType].checkdigit) {
	    var checksum = 0;                                  // running checksum total
	    var mychar = "";                                   // next char to process
	    var j = 1;                                         // takes value of 1 or 2

	    // Process each digit one by one starting at the right
	    var calc;
	    for (i = cardNo.length - 1; i >= 0; i--) {

	      // Extract the next digit and multiply by 1 or 2 on alternative digits.
	      calc = Number(cardNo.charAt(i)) * j;

	      // If the result is in two digits add 1 to the checksum total
	      if (calc > 9) {
	        checksum = checksum + 1;
	        calc = calc - 10;
	      }

	      // Add the units element to the checksum total
	      checksum = checksum + calc;

	      // Switch the value of j
	      if (j ==1) {j = 2} else {j = 1};
	    } 

	    // All done - if checksum is divisible by 10, it is a valid modulus 10.
	    // If not, report an error.
	    if (checksum % 10 != 0)  {
	     ccErrorNo = 3;
	     return false; 
	    }
	  }  

	  // The following are the card-specific checks we undertake.
	  var LengthValid = false;
	  var PrefixValid = false; 
	  var undefined; 

	  // We use these for holding the valid lengths and prefixes of a card type
	  var prefix = new Array ();
	  var lengths = new Array ();

	  // Load an array with the valid prefixes for this card
	  prefix = cards[cardType].prefixes.split(",");

	  // Now see if any of them match what we have in the card number
	  for (i=0; i<prefix.length; i++) {
	    var exp = new RegExp ("^" + prefix[i]);
	    if (exp.test (cardNo)) PrefixValid = true;
	  }

	  // If it isn't a valid prefix there's no point at looking at the length
	  if (!PrefixValid) {
	     ccErrorNo = 3;
	     return false; 
	  }

	  // See if the length is valid for this card
	  lengths = cards[cardType].length.split(",");
	  for (j=0; j<lengths.length; j++) {
	    if (cardNo.length == lengths[j]) LengthValid = true;
	  }

	  // See if all is OK by seeing if the length was valid. We only check the 
	  // length if all else was hunky dory.
	  if (!LengthValid) {
	     ccErrorNo = 4;
	     return false; 
	  };   

	  // The credit card is in the required format.
	  return true;
	}
	function createReviewLogin()
	{
		document.getElementById('reviewlogin').style.display = 'block';
		document.getElementById('reviews').style.display = 'none';
	}
	
	function validateReviewUser()
	{
		poststring="invoiceid="+document.getElementById('invoicenum').value+"&lname="+document.getElementById('lastname').value+"&fgoodid="+document.getElementById('fgoodid').value;
		getReviewUserResponse(poststring, 'nolist');
  	}
	function validateReviewUserFromList(invoiceId, lastName, fgoodId)
	{
		document.getElementById('fgoodid').value = fgoodId;
		poststring="invoiceid="+invoiceId+"&lname="+lastName+"&fgoodid="+fgoodId;
		getReviewUserResponse(poststring, 'list');
  	}
    function getReviewUserResponse(poststring, type)
    {
    	var url = "/ajax/validateReviewUser.jsp";
        poststring += '&rand=' + Math.floor(Math.random() * 999);
        var myAjax = new Ajax.Request(url,
        {
	        method: 'post',
            parameters: poststring,
            onComplete: showReviewForm,
          	onFailure: function() { alert("There was trouble getting your information from the server."); }
        }
       	);
    }
    function showReviewForm(response)
    {
		var responseVal = response.responseText; 
		if(responseVal.match(/true/))
		{
			document.getElementById('reviewlogin').style.display = 'none';
			document.getElementById('reviews').style.display = 'none';
			document.getElementById('reviewform').style.display = 'block';
		}
		else{
			alert("The Invoice # or Last Name could not be found. Please try agian.")
		}
		
	}
	
	
	function getReviewInfo()
	{
		if(document.getElementById('rname').value == '')
		{
			alert("Please enter a review name.");
			return false;
		} 
		else if(document.getElementById('remail').value == '')
		{
			alert("Please enter a review email.");
			return false;
		}
		else if(document.getElementById('location').value == '')
		{
			alert("Please enter a review location.");
			return false;
		}
		else if(document.getElementById('rating').value == '')
		{
			alert("Please enter a review rating.");
			return false;
		}
		else if(document.getElementById('comment').value == '')
		{
			alert("Please enter a review comment.");
			return false;
		}
		poststring="fgoodid="+document.getElementById('fgoodid').value+"&name="+document.getElementById('rname').value+"&email="+document.getElementById('remail').value+"&location="+document.getElementById('location').value+"&rating="+document.getElementById('rating').value+"&comment="+document.getElementById('comment').value;
		insertReview(poststring);
  	}
    function insertReview(poststring)
    {
    	var url = "/ajax/insertNewReview.jsp";
        poststring += '&rand=' + Math.floor(Math.random() * 999);
        var myAjax = new Ajax.Request(url,
        {
	        method: 'post',
            parameters: poststring,
            onComplete: showReviewCompleteScreen,
          	onFailure: function() { alert("There was trouble getting your information from the server."); }
        }
       	);
    }
    function showReviewCompleteScreen(response)
    {
		document.getElementById('reviewlogin').style.display = 'none';
		document.getElementById('reviews').style.display = 'none';
		document.getElementById('reviewform').style.display = 'none';
		document.getElementById('reviewcomplete').style.display = 'block';
	}
	
	function activateReview(id, action)
	{
		poststring="id="+id+"&action="+action;
		updateReview(poststring);
	}
	
	function updateReview(poststring)
    {
    	var url = "/ajax/updateReview.jsp";
        poststring += '&rand=' + Math.floor(Math.random() * 999);
        var myAjax = new Ajax.Request(url,
        {
	        method: 'post',
            parameters: poststring,
            onComplete: showStatusScreen,
          	onFailure: function() { alert("There was trouble getting your information from the server."); }
        }
       	);
    }
	
	function showStatusScreen()
	{
		window.location = "/admin/activatereviews"
	}
	
	function toggleBilling()
	{
		if(document.getElementById('oneaddress').checked)
		{
			document.getElementById('customerinfo').style.display = "none";
		}
		else
		{
			document.getElementById('customerinfo').style.display = "";
		}
	}
	
	function validateReviewUserAndProducts()
	{
		poststring="invoiceid="+document.getElementById('invoicenum').value+"&lname="+document.getElementById('lastname').value;
		getReviewUserItemListResponse(poststring);
	}
	function getReviewUserItemListResponse(poststring)
	{
	   	var url = "/ajax/validateReviewUserItemList.jsp";
	    poststring += '&rand=' + Math.floor(Math.random() * 999);
	    var myAjax = new Ajax.Request(url,
	    {
	        method: 'post',
	        parameters: poststring,
	        onComplete: showProductReviewList,
	       	onFailure: function() { alert("There was trouble getting your information from the server."); }
	    }
	   	);
	}
	function showProductReviewList(response)
	{
		$('reviewlogin').hide();
		$('reviews').update(response.responseText);

	}
	function validateRegistrationUserAndProducts()
	{
		poststring="invoiceid="+document.getElementById('invoicenum').value+"&lname="+document.getElementById('lastname').value;
		getRegistrationUserItemListResponse(poststring);
	}
	function getRegistrationUserItemListResponse(poststring)
	{
	   	var url = "/ajax/validateRegistrationUserItemList.jsp";
	    poststring += '&rand=' + Math.floor(Math.random() * 999);
	    var myAjax = new Ajax.Request(url,
	    {
	        method: 'post',
	        parameters: poststring,
	        onComplete: showProductRegistrationList,
	       	onFailure: function() { alert("There was trouble getting your information from the server."); }
	    }
	   	);
	}
	function checkAllProducts()
	{
		var checkboxes = [];
		checkboxes = $$('input').each(function(e){ if(e.type == 'checkbox')  e.checked = 1 });
		
		return false;
	}
	function showProductRegistrationComplete(response)
	{
		alert("show/hide");
	}
	function showProductList()
	{
	
		$j('.userInfo').hide();
		$j('.prodreviewlist').show();
	}
	function registerProducts()
	{
		boxes = document.f1.Liked.length
		txt = ""
		for (i = 0; i < boxes; i++) {
			if (document.f1.Liked[i].checked) {
				txt = txt + document.registerform.lineItemId[i].value + ","
			}
		}
		alert(txt);

		
		poststring = "lineItemId="+txt;
		var url = "/ajax/insertNewRegistration.jsp";
	    poststring += '&rand=' + Math.floor(Math.random() * 999);
	    var myAjax = new Ajax.Request(url,
	    {
	        method: 'post',
	        parameters: poststring,
	        onComplete: showProductRegistrationComplete,
	       	onFailure: function() { alert("There was trouble getting your information from the server."); }
	    }
	   	);
	}
	function updateRegistrationEmail()
	{
		var url = "/ajax/updateContactInfo.jsp";
		poststring="phone="+document.getElementById('phone').value+"&zip="+document.getElementById('zip').value+"&state="+document.getElementById('state').value+"&city="+document.getElementById('city').value+"&address2="+document.getElementById('address2').value+"&first_name="+document.getElementById('first_name').value+"&last_name="+document.getElementById('last_name').value+"&address1="+document.getElementById('address1').value+"&email="+document.getElementById('email').value+"&customer_id="+document.getElementById('customer_id').value;
	
		 var myAjax = new Ajax.Request(url,
	    {
	        method: 'post',
	        parameters: poststring,
	        onComplete: showProductList,
	       	onFailure: function() { alert("There was trouble getting your information from the server."); }
	    }
	   	);
	}
	function showProductRegistrationList(response)
	{
		$('reviewlogin').hide();
		$('reviews').update(response.responseText);

	}
	function doValCus(source, keyCode){
		var keyField = source;
		n=source.name;
		p1=keyField;
		ValidatePhone(keyField, keyCode);
	}
	function ValidatePhone(element, keycode) {
	        if (keycode != 8) {
	                var phonestring = document.getElementById(element.id).value.replace(/\D*/g, "");
	               	document.getElementById(element.id).value = phonestring;
	                if (phonestring.length > 0) {

	                        if (phonestring.length <= 3) {
	                                element.value = "(" + phonestring.substring(0,3) + ((phonestring.length == 3) ? ")" : "");
	                                element.selectionStart = element.value.length;
	                        } else if (phonestring.length <= 6) {
	                                element.value = "(" + phonestring.substring(0,3) + ")" + phonestring.substring(3,6) + ((phonestring.length == 6) ? "-" : "");
	                                element.selectionStart = element.value.length;
	                        } else {
	                                element.value = "(" + phonestring.substring(0,3) + ")" + phonestring.substring(3,6) + "-" + phonestring.substring(6,10);
	                                element.selectionStart = element.value.length;
	                        }


	                }
	        }
	}
