// Suckerfish dropdown support
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
// end Suckerfish script

//-- USER AGENT OBJECT

var oUa, popup, iHome = 0, iAux = 0, bInit = 0, bNoInit = 0;

function clsUa(){
	this.ua=navigator.userAgent.toLowerCase();
	this.mac=(this.ua.indexOf("mac")!=-1);
	this.ns4=(document.layers);
	this.ns6=(this.ua.indexOf('netscape6/6.0')!=-1);
	this.w3c=(document.getElementById)?1:0;
	this.ieX=(document.all)?1:0;
	this.ie5=(this.ieX && this.w3c)?1:0;
	this.ieMac=(this.ieX && this.mac)?1:0;
	this.oContent = document.getElementById('content');
	this.oNavB = document.getElementById('navB');
	this.oNavC = document.getElementById('navC');
	this.oNavD = document.getElementById('navD');
	this.oNavDC = document.getElementById('navDC');
	this.oNavZ = document.getElementById('navZ');
	this.oOn = 0;
	}

//-- GLOBAL FORM METHODS

function clearField(x){
	x.value = '';
	}

function doTextAreaKeyup(x,y){
	var sVal = x.value;
	if (sVal.length > y) x.value = sVal.substring(0,y);
	}
    
function setCheckedBoolean(checkBox, field) {
    var hiddenField = document.getElementById(field);
    
    if(checkBox.checked) {
        hiddenField.value = true;
    } else {
        hiddenField.value = false;
    }
}

//-- GLOBAL POP-UP WINDOW METHODS

function openWindow(sUrl,iW,iH,bScr,bTbr,bRsz,sWin) {
	var iAW = screen.availWidth, iAH = screen.availHeight,
		sArg = 'toolbar=' + bTbr + ',location=0,directories=0,status=0,scrollbars=' + bScr + ',resizable=' + bRsz + ',width=' + iW + ',height=' + iH + ',left=' + (iAW-iW)/2 + ',top=' + (iAH-iH)/2;
	if (sWin) {
		sWin = window.open(sUrl,sWin,sArg);
		sWin.focus();
	} else {
		oWin = window.open(sUrl,'newWin',sArg);
		oWin.focus();
		}
	}

function closeRedirect(x){
	opener.location.href = x;
	opener.focus();
	window.close();
	}

//-- WISHLIST METHODS

var fRaw = 0, fFmt = 0;

function wlAddItem(x,y,z){

	var oQty = document.getElementById(y);


	if (x.tagName.toLowerCase() == 'input'){
		x.checked = (x.checked) ? false : true;
		return;
		}

	x = x.firstChild;
	x.checked = (x.checked) ? false : true;

	oQty.disabled = x.checked;


	z = z.substring(0, z.length - 2);

	if (isNaN(parseFloat(fRaw)) || isNaN(parseFloat(z))) return;

	z = parseInt(z) * parseInt(oQty.value);


	fRaw = (x.checked) ? eval(parseFloat(fRaw) + parseFloat(z)).toFixed(2) : eval(parseFloat(fRaw) - parseFloat(z)).toFixed(2);

	fFmt = fRaw;

	var intZ = parseInt(fFmt.length/3),
		arrPrc = new Array();

	if (fFmt.length > 6){
		for (var i = 0; i < intZ; i++){
			arrPrc[i] = fFmt.substring(fFmt.length - 3, fFmt.length);
			fFmt = fFmt.substring(0, fFmt.length - 3);
			}
		for (var i = arrPrc.length - 1; i > 0; i--) fFmt = fFmt + ',' + arrPrc[i];
		fFmt = fFmt + arrPrc[0];
		}

	document.getElementById('subtotal').innerHTML = fFmt;
	}
	
	function resetComments() {
		var form = document.forms["billing_shipping"];
		var comments = form.comments.value;
		
		if(comments.indexOf("**Please do not send credit card information**") != -1) {
			comments = "";
		}
		return true;
	}
	
    function trimString (str) {
        return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
    }

	function submitForm(name, action) {
		form = document.forms[name];
		
		// form validation
		if(name == 'billing_shipping') {
			if(form.billing_firstName.value.length == 0) {
				alert("Contact & Billing information requires a person's name");
				form.billing_firstName.focus();
				return false;
			} else if(form.billing_lastName.value.length == 0) {
				alert("Contact & Billing information requires a person's name");
				form.billing_lastName.focus();
				return false;
			} else if(trimString(form.billing_telephone1.value).length == 0) {
				alert("Contact & Billing information requires a contact telephone number");
				form.billing_telephone1.value = "";
				form.billing_telephone1.focus();
				return false;
			} else if(form.billing_timeFrames.options[form.billing_timeFrames.selectedIndex].value == "") {
				alert( "Please select the best time to reach you." );
				form.billing_timeFrames.focus();
				return false;
			}else if(form.billing_email.value.length == 0 || 
				form.billing_email.value.indexOf("@") == -1) {
				alert("Contact & Billing information requires a valid email address");
				form.billing_email.focus();
				return false;
			} else if(form.billing_street.value.length == 0) {
				alert("Contact & Billing information requires a street address");
				form.billing_street.focus();
				return false;
			} else if(form.billing_city.value.length == 0) {
				alert("Contact & Billing information requires a city");
				form.billing_city.focus();
				return false;
			} else if(form.billing_zip.value.length == 0) {
				alert("Contact & Billing information requires a zip code");
				form.billing_zip.focus();
				return false;
			}
			
			// shipping info
			if(form.shipping_name != null && form.shipping_name.value.length == 0) {
				alert("Shipping information requires a person's name");
				form.shipping_name.focus();
				return false;
			} else if(trimString(form.shipping_telephone1.value).length == 0) {
				if (form.sameAsBilling[1].checked) {
					alert("Shipping information requires a telephone number");
					form.shipping_telephone1.value = "";
					form.shipping_telephone1.focus();
					return false;
				}
			} else if(form.shipping_street != null && form.shipping_street.value.length == 0) {
				alert("Shipping information requires a street address");
				form.shipping_street.focus();
				return false;
			} else if(form.shipping_city != null && form.shipping_city.value.length == 0) {
				alert("Shipping information requires a city");
				form.shipping_city.focus();
				return false;
			} else if(form.shipping_zip != null && form.shipping_zip.value.length == 0) {
				alert("Shipping information requires a zip code");
				form.shipping_zip.focus();
				return false;
			}
			
		}

		var defaultComment = "**Please do not send credit card information**";
		var comment = form.comments.value;
		if(comment.indexOf(defaultComment) != -1 && comment.length == defaultComment.length) {
			form.comments.value = "";
		}

		form.method.value = action;
        	form.submit();
	}
	
//-- HOME PAGE PROMOTION METHODS

function promoMover(x){
	if (!bInit) return;
	x.style.background = '#D4E0ED';
	x.style.border = '1px solid #FFFFFF';
	x.style.color = '#7097BF';
	x.style.cursor = (oUa.ieX && !oUa.mac) ? 'hand' : 'pointer';
	}

function promoMout(x){
	x.style.background = '#83A6CA';
	x.style.color = '#FFFFFF';
	x.style.border = '1px solid #FFFFFF';
	}

function promoClick(x){
	if (x){
		window.location.href = '$velsitepath/dept.do?dept=YYZ4';
	} else {
		openWindow('$velsitepath/promo_200508.vm?x=0',637,511,0,0,0,'winPromo');
		}
	}

function beddingClick(){
	openWindow('$velsitepath/bedding/bedding_mix01.vm?x=0',624,600,0,0,0,'winPromo');
}

function findYourStyle(url){
	openWindow(url,637,540,0,0,0,'winFYS');
}

//-- RFX SWATCH VIEW

function openSwatchRFX(sUrl) {
	var iW = 650, iH = 510, iAW = screen.availWidth, iAH = screen.availHeight,
		sArg = 'toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,width=' + iW + ',height=' + iH + ',left=' + (iAW-iW)/2 + ',top=' + (iAH-iH)/2;
	winSwatch = window.open(sURL,'winSwatch',sArg);
	winSwatch.focus();
	}

function blurRedirect(x){
	opener.location.href = x;
	opener.focus();
	}

//-- SWATCH VIEW METHODS

function swapSwatch(x){
	document.getElementById('imgLabel').innerHTML = arrSwatch[x][0];
	document.bigImage.src = arrSwatch[x][1];
	sRepeatName = arrSwatch[x][0];
	sRepeatUrl = arrSwatch[x][1];
//	document.getElementById('matDetail').innerHTML = arrSwatch[x][2];
	}
