var passwordField = $('<input type="password" name="ac_password" class="styledInput" value="" id="signinPassword" onblur="passwordBlur($(this));" />');
var passwordFieldReplacment = $('<input type="text" name="ac_password" class="styledInput" value="your password" id="signinPassword" onfocus="passwordFocus($(this));" />');

function formFieldFocus(idx, f_name) {
	field = fields_ids[idx];
	txt   = fields_txt[idx];
	obj   = eval("document.getElementById(\"" + f_name + "\")." + field);
	if(obj.value == txt) {
		obj.value = "";
	}
	return true;
}

function formFieldBlur(idx, f_name) {
	field = fields_ids[idx];
	txt   = fields_txt[idx];
	obj   = eval("document.getElementById(\"" + f_name + "\")." + field);
	if(obj.value == "") {
		obj.value = txt;
	}
	return true;
}

function submitForm(f_name) {
	for(i = 0; i < fields_ids.length; ++i) {
		obj = eval("document.getElementById(\"" + fields_ids[i] + "\")");
		if(obj.value == fields_txt[i]) {
			obj.value = "";
		}
	}
	eval("document.getElementById(\"" + f_name + "\").submit();");
	return false;
}

function setContextForForm(field_name, field_value) {
	eval("document.getElementById(\"" + field_name + "\").value = '" + field_value + "';");
	return false;
}

function detailedFields(field_id) {
	obj = eval("document.getElementById(\"" + field_id + "\")");
	if(!obj.style.display || obj.style.display == "none") {
		obj.style.display = "block";
	} else if(obj.style.display == "block") {
		obj.style.display = "none";
		obj.value = "Please specify";
	}
}

function openPopup(popupLocation, popupName, popupWidth, popupHeight) {
	var screenWidth = 760;
	var screenHeight = 420;
	if (self.screen.width) {
		screenWidth = self.screen.width;
		screenHeight = self.screen.height;
	}
	var popupTop = (screenHeight-popupHeight)/2;
	var popupLeft = (screenWidth-popupWidth)/2;
	newPopupName=window.open(popupLocation, 'newname', 'height=' + popupHeight + ', width=' + popupWidth + ', left=' + popupLeft + ', top=' + popupTop + ', resizable=0');
	if (newPopupName.focus) {
		newPopupName.focus();
	}
	return false;
}

function openInNewWindow() {
	var newWindow = window.open(this.getAttribute('href'), '_blank');
	if(newWindow) {
		newWindow.focus();
	}
	return false;
}

function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.appendChild) {
		var objWarningText;
		var strWarningText;
		var link;
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (link.getAttribute && link.getAttribute) {
				if (link.getAttribute("href") && link.getAttribute("rel") == "external") {
					link.onclick = openInNewWindow;
				}
			}
		}
		objWarningText = null;
	}
	if ($('input[type=password]')) {
		var myInput = $('input[type=password]');
		var myTabIndex = myInput.attr('tabIndex');
		myInput.replaceWith(passwordFieldReplacment);
		passwordFieldReplacment.attr('tabIndex', myTabIndex);
	}
}

function sfHover() {
	if (document.getElementById) {
		var sfEls = document.getElementById("globalNav").getElementsByTagName("LI");
		if (sfEls) {
			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"), "");
				}
			}
		}
	}
}

function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);
        if(switch_id.className == 'hide') {
           switch_id.className = 'styledTable';
        }else{
           switch_id.className = 'hide';
        }
	}
}

function showHideBlock(theid, desiredClass){
	if (document.getElementById) {
		var switch_id = document.getElementById(theid);
		if (switch_id.className != desiredClass) {
			if (switch_id.className == 'hide') {
				switch_id.className = 'dontHide';
			} else {
				switch_id.className = 'hide';
			}
		}
	}
}
function focusMe(me) {
	me.focus();
}

function passwordFocus(me) {
	var myTabIndex = me.attr('tabIndex');
	me.replaceWith(passwordField);
	passwordField.attr('tabIndex', myTabIndex);
	setTimeout(focusMe, 10, passwordField);
}

function passwordBlur(me) {
	if (me.val() == '') {
		var myTabIndex = me.attr('tabIndex');
		me.replaceWith(passwordFieldReplacment);
		passwordFieldReplacment.attr('tabIndex', myTabIndex);
	}
}


// Make product panels in product listing equal heights //

$(document).ready(function() {
	$(".productListing .nonMicroformatWrapper .fn").equalHeights().css('overflow','hidden');
	$(".productListing .nonMicroformatWrapper .priceWrapper").equalHeights().css('overflow','hidden');
	$(".productListing .photo").equalHeights().css('overflow','hidden');
	$(".productListing .description").equalHeights().css('overflow','hidden');	
});

// Hide @font-face until rendered //
WebFontConfig = {
custom: { families: ['TitilliumText22LBold', 'TitilliumText22LRegular'],
urls: [ 'css/font-face.css' ] }
};
  
(function() {
	document.getElementsByTagName("html")[0].className += " wf-loading";
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
	'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
})();
