function selectFeedMotive(motive) {
	var sendButton = document.getElementById('cmdInsertFeedback');
	
	switch(motive.value>>0) {
		case 1:
			sendButton.value = sendMail;
			break;
		case 2:
			sendButton.value = "Inserisci feedback";
			break;
		case 3:
			sendButton.value = "Inserisci feedback";
			break;
	}
	
	return false;
}
function checkRegNews(frm, privacy) {
	if(!validateEmail(frm.newsMail.value)) {
		alert(regNewsInsertValidMail);
		frm.newsMail.focus();
		return false;
	}
	if(frm.newsName.value == "") {
		alert(regNewsInsertValidName);
		frm.newsName.focus();
		return false;
	}
	
	if(privacy && !frm.newsPrivacy.checked) {
		alert(regNewsCheckPrivacy);
		frm.newsPrivacy.focus();
		return false;
	}
	
	
	return true;
}

function validateEmail(strValue) {	
	var objRegExp  = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return objRegExp.test(strValue);
}


function MM_verifyDate(str) {
	//var str = data;
	
	var format=0;
	var month=0;
	var day=0;
	var year=0;
	var err=false;
	if(str.length!=10)
		err=true;

	if(str.length==10)
		{
		// dd/mm/yyyy format
		if(str.charAt(2) == "/" && str.charAt(5) == "/" && str.length == 10)
				{
				format=1;
				// Check that day is a number.
				for (var i = 0; i < 2; i++) 
					{ var ch = str.substring(i, i + 1); if(ch < "0" || "9" < ch) err=true; }
				// Check that month is a number.
				for (var i = 3; i < 5; i++) 
					{ var ch = str.substring(i, i + 1); if(ch < "0" || "9" < ch) err=true; }
				// Check that year is a number.
				for (var i = 6; i < 10; i++) 
					{ var ch = str.substring(i, i + 1); if(ch < "0" || "9" < ch) err=true; }
				// Set variables
				if(err==
						false){day=eval(str.substring(0,2));month=eval(str.substring(3,5));  year=eval(str.substring(6,str.length)); }
				}


		// Incorrect format.
		if(format !=1)
				var err=true;
		}

		// Check that month is between 1 &12.
		if(month<=0 || month>=13)
		  err=true;

		// Check that day is right depending on month.
		if( month==2 && ((year/4)==parseInt(year/4)) )
		  { if(day<=0 || day>29) err=true; }
		if( month==2 && ((year/4)!=parseInt(year/4)) )
		  { if(day<=0 || day>28) err=true; }
		if( month==4 || month==6 || month==9 || month==11 )
		  { if(day<=0 || day>30) err=true; }
		if( month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12 )
		  { if(day<=0 || day>31) err=true; }


		// If anything appears incorrect, display error message.
		if(err==true)
		  {
		//  alert("Inserire la data nel formato gg/mm/aaaa");
			
		  return false;
		  }

		// If all is OK, return true.
		return true;

	}



//Invio Password
function sendPWD(){
	var str = prompt(promptSendPwd,"");
	if(str) window.location.replace('default.asp?cmd=sendPwd&cmdString='+escape(str));
}
function checkConfirmPoints(frm) {
	if(frm.txtUserAddress.value == "") {
		alert(pointsAlert3);
		frm.txtUserAddress.focus();
		return false;
	}
	showWaitMessage();
	return true;
}
function checkPanelPuntiForm(frm) {
	var chk = frm.chkPremio;
	var retVal = false;	
	if(chk.length) {
		for(var i = 0; i < chk.length; i++) {
			if(chk[i].checked) {
				retVal = true;
				break;
			}
		}
	}
	else {
		retVal = chk.checked;
	}
	if(!retVal)
		alert(pointsAlert2);
	
	if(retVal)
		showWaitMessage();
	
	return retVal;
}
function checkOrderForm(frm){		
	if(frm.isGuestUser.value == 1) {
		if(!checkFRM(frm))
			return false;
	}		
	var courierIds = document.getElementsByName("courierID");
	var courierId = null;
	for(var i = 0; i < courierIds.length; i++) {
		if(courierIds[i].checked) {
			courierId = courierIds[i];
			break;
		}
	}
	if(!courierId) {
		courierId = courierIds[0].value>>0;
	}	
	if(!courierId) {	
		alert(window.courier);
		courierIds[0].focus();
		return false;
	}
	
	var paymentIds = document.getElementsByName("paymentID");
	var paymentId = null;
	for(var i = 0; i < paymentIds.length; i++) {
		if(paymentIds[i].checked) {
			paymentId = paymentIds[i];
			break;
		}
	}
	if(!paymentId) {	
		alert(window.payment);
		paymentIds[0].focus();
		return false;
	}
	
	if(frm.dataRitiro != null) {
		var dataRitiro = frm.dataRitiro.value;
		var year = dataRitiro.substr(6, 4);
		var day = dataRitiro.substr(0, 2);
		var month = dataRitiro.substr(3, 2)>>0;
		var dRitiro = new Date(year, month - 1, day);
		var today = new Date();
		
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
		if(!((dRitiro - today) >= 86400000 && (dRitiro - today) <= (86400000 * 5))) {
			alert(collectionDateInvalid);
			frm.dataRitiro.focus();
			return false;
		}		
	}
	
	if(frm.showDestBoxYes && frm.showDestBoxYes.checked && frm.selectDest && frm.selectDest.checked) {
		if(frm.destinationID.value == 0) {
			alert("SELEZIONARE UNA DESTINAZIONE ####");
			frm.destinationID.focus();
			return false;
		}
	}
	if(frm.showDestBoxYes && frm.showDestBoxYes.checked && frm.newDest && frm.newDest.checked) {
		if(frm.destCountry && frm.destCountry.value == "") {
			alert(destAltCountry);
			frm.destCountry.focus();
			return false;
		}
		if(frm.destName && frm.destName.value == "") {
			alert(destAltName);
			frm.destName.focus();
			return false;
		}
		if(frm.destAddress && frm.destAddress.value == "") {
			alert(destAltAddress);
			frm.destAddress.focus();
			return false;
		}
		if(frm.destCap && frm.destCap.value == "") {
			alert(destAltCAP);
			frm.destCap.focus();
			return false;
		}
		if(frm.destCity && frm.destCity.value == "") {
			alert(destAltCity);
			frm.destCity.focus();
			return false;
		}
		if(frm.destProv && frm.destProv.value == "") {
			alert(destAltProvince);
			frm.destProv.focus();
			return false;
		}
		if(frm.destPhone && frm.destPhone.value == "") {
			alert(destAltPhone);
			frm.destPhone.focus();
			return false;
		}
		else {
			var numPhone = frm.destPhone.value>>0;
			if(!numPhone) {
				alert(destAltPhoneInvalid);
				frm.destPhone.focus();
				return false;
			}
		}
	}
	frm.cmdSendOrderOk.disabled=true;
	showWaitMessage();
	frm.action = "default.asp?cmd=sendOrder";
	
	return true;
}
var popuptimeout = 0;
function showPopupMessage(timeout) {
	var popupMessage = document.getElementById('popupMessage');
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsoctop = document.all? iebody.scrollTop : pageYOffset

	if (document.all||document.getElementById) {	
		popupMessage.style.top = dsoctop + 250 + "px"
	}
	
	popupMessage.style.display='';
	popuptimeout = setTimeout(hidePopUpBanner, timeout * 1000);
}
function hidePopUpBanner() {
	var popupMessage = document.getElementById('popupMessage');
	if(popupMessage != null) {
		popupMessage.style.display = "none";
		document.cookie='hidepopup=1';
		if(popuptimeout != 0)
			clearTimeout(popuptimeout);
	}
}
function showWaitMessage() {
	var waitForSending = document.getElementById('waitSendingOrder');
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsoctop = document.all? iebody.scrollTop : pageYOffset

	if (document.all||document.getElementById) {	
		waitForSending.style.top = dsoctop + 75 + "px"
	}
	
	waitForSending.style.display='';
}
function openPopUp(strURL,w,h,t,l,refName,e){
	
	e=e||event;
	var obj = document.getElementById?document.getElementById(refName):document.layers?document.layers[refName]:document.all?document.all[refName]:null;
	if(t==null||l==null){
		if(e){
			//var l=e.clientX-150;
			//var t=e.clientY-34;
			l=e.screenX+20;
			t=e.screenY-222;
		}else if(obj){
			obj.css=document.layers?obj:obj.style;
			t=obj.css.top||obj.css.pixelTop||obj.offsetTop||100;
			l=obj.css.left||obj.css.pixelLeft||obj.offsetLeft||100;
		}else{t=100,l=100;}
	} else if(t>>0!=t&&l>>0!=l){
		l=l=="cs"?screen.width/2-w/2:100;
		t=t=="cs"?screen.height/2-h/2:100;
	}
	if(oPopUp&&!oPopUp.closed) oPopUp.close();
		//oPopUp.location.replace(strURL);
		//oPopUp.resizeTo(w,h);

	oPopUp = window.open(strURL,"PopUp","width="+w+",height="+h+",top="+t+",left="+l+",scrollbars=1,resizable=1");
	oPopUp.focus();
}

var oPopUp;
onunload = function(){if(oPopUp&&!oPopUp.closed) oPopUp.close();}

function checkCorrectPoints() {
	
	var userPoints = document.getElementById("hUserPoints").value>>0;
	
	var chkPremio = document.getElementsByName("chkPremio");
	var totalSelPoints  = 0;
	if(chkPremio.length) {
		for(var i = 0; i < chkPremio.length; i++) {
			if(chkPremio[i].checked)
				totalSelPoints += chkPremio[i].value.split("|")[1]>>0;
		}
	}
	else {
		if(chkPremio.checked)
			totalSelPoints += chkPremio.value.split("|")[1]>>0;
	}
	if(totalSelPoints > userPoints) {
		alert(pointsAlert1);
		return false;		
	}
	else 
		return true;
}

function printVersionWnd(mainurl, id) {
	var oPopUp = window.open(mainurl + "/showPrintVersion.asp?id=" + id,"printVersion","width=700,height=900,scrollbars=1,resizable=1");
	oPopUp.focus();	
	return false
}
function checkCameretteOptions(frm) {
	var chkOptions = frm.artAccessori;
	var oneChecked = false;
	try {
		for(var i = 0; i < chkOptions.length; i++) {
			if(chkOptions[i].checked) {
				oneChecked = true;
				break;
			}
		}
	}
	catch(err) {
		if(chkOptions.checked) {
			oneChecked = true;
		}
	}
	if(!oneChecked) {
		alert(checkOneOption);
	}
	
	return oneChecked;
}
function checkTrioOptions(frm) {
	var chkOptions = frm.artAccessori;
	var oneChecked = false;
	try {
		for(var i = 0; i < chkOptions.length; i++) {
			if(chkOptions[i].checked) {
				oneChecked = true;
				break;
			}
		}
	}
	catch(err) {
		if(chkOptions.checked) {
			oneChecked = true;
		}
	}
	if(!oneChecked) {
		alert(checkOneOption);
	}
	
	return oneChecked;
}
function checkBestPrice(frm) {
	if(frm.txtProductName.value == "") {
		alert(bestPriceProductName);
		frm.txtProductName.focus();
		return false;
	}
	if(frm.txtUrl.value == "") {
		alert(bestPriceAddress);
		frm.txtUrl.focus();
		return false;
	}
	if(frm.txtName.value == "") {
		alert(bestPriceName);
		frm.txtName.focus();
		return false;
	}
	if(!validateEmail(frm.txtMail.value)) {
		alert(bestPriceName);
		frm.txtMail.focus();
		return false;
	}
	if(frm.txtConfirmMail.value != frm.txtMail.value) {
		alert(bestPriceConfirmMail);
		frm.txtConfirmMail.focus();		
		return false;
	}
	return true;
}
function delCartBuono(id) {
	if(confirm(deleteBuono)) {
		window.location.href="default.asp?cmd=showCart&delBuonoId=" + id;
	}
}
function delCartGift(id, title) {
	if(confirm(deleteGift + title + "?")) {
		window.location.href="default.asp?cmd=showCart&delGiftId=" + id;
	}
}
function delCartProduct(id, title, linePresent) {
	if(linePresent) {
		if(confirm(deleteScontItemAlso1 + title + deleteScontItemAlso2)) {
			window.location.href="default.asp?cmd=showCart&delId=" + id + "&lp=1";
		}
	}
	else {
		if(confirm(deleteItem + title + "?")) {
			window.location.href="default.asp?cmd=showCart&delId=" + id;
		}
	}
}
function delCartSubProduct(id, parentId, title) {
	if(confirm(deleteItem + title + "?")) {
		window.location.href="default.asp?cmd=showCart&delSubId=" + id + "&parentId=" + parentId;
	}
}
function delCartParentProduct(id, title) {
	if(confirm(deleteItem + title + deleteAllAccessories + "?")) {
		window.location.href="default.asp?cmd=showCart&delParentId=" + id;
	}
}
function checkInsertFeedback(frm) {
	var action = frm.action;
	var retValue = true;
	var selGiudizio = false;
	var selGiudizioIx = 0;
	
	for(var i = 0; i < frm.optGiudizio.length; i++) {
		if(frm.optGiudizio[i].checked) {
			selGiudizio = true;
			selGiudizioIx = i;
			break;
		}
	}	
	if(!selGiudizio) {
		alert(feedbackJudge);
		return false;
	}
	
	var selMotive = false;
	for(var i = 0; i < frm.motive.length; i++) {
		if(frm.motive[i].checked) {
			selMotive = true;
			break;
		}
	}	
	if(!selMotive && (selGiudizioIx == 1)) {
		alert("Selezionare una motivazione.");
		return false;
	}
	
	//sendButton.form.method = "GET";
	//sendButton.form.action = "mailto:assistenza@newbabyland.com?body=asdasdsa";// + feedbackSubjectMail + orderId;
	
	var orderId = frm.orderId.value;
	//frm.method = "POST";
	frm.action = "";
	if(frm.motive[0].checked) {
		//frm.method = "GET";
		window.location.href = "mailto:assistenza@newbabyland.com?subject=" + escape(feedbackSubjectMail) + orderId;		
		retValue = false;
	}
	else if(frm.motive[1].checked) {
		//alert(escape(feedbackMessageInfo2));
		alert(feedbackMessageInfo2);
		return false;
	}

	if(frm.txtFeedback.value == "") {
		alert(feedbackInsertText);
		frm.txtFeedback.focus();
		return false;
	}
	
	return retValue;	
}
function alertChoiceVariants(frm) {
	alert(choiceVariantProduct);
	document.getElementById("cboVariants").focus();
	return false;
}
function checkInsertGift(frm) {	
	if(frm.fromName.value == "") {
		alert(giftSenderName);
		frm.fromName.focus();
		return false;
	}
	if(!validateEmail(frm.giftMail.value)) {
		alert(giftMail);
		frm.giftMail.focus();
		return false;
	}
	if(frm.giftMail.value != frm.giftMailConfirm.value) {
		alert(giftConfirmMail);
		frm.giftMailConfirm.focus();
		return false;
	}
	if(frm.giftName.value == "") {
		alert(giftName);
		frm.giftName.focus();
		return false;
	}
	return true;
}
function checkCreateListaNascita(frm) {
	if(frm.txtListaDescription.value == "") {
		alert(insertDescriptionForList);
		frm.txtListaDescription.focus();
		return false;
	}
	if(frm.txtListaScadenza.value == "" || !MM_verifyDate(frm.txtListaScadenza.value)) {		
		alert(invalidDateForList);
		frm.txtListaScadenza.focus();
		return false;		
	}
	else {
		var strDate = frm.txtListaScadenza.value;
		var insertDay = strDate.substr(0, 2)>>0;
		var insertMonth = (strDate.substr(3, 2)>>0) - 1;
		var insertYear = strDate.substr(6, 4)>>0;
		
		
		var checkInsertDate = false;
		var currentDate = new Date();
		
		if(insertYear > currentDate.getFullYear())
			checkInsertDate = true;
		else if(insertYear == currentDate.getFullYear())
			if(insertMonth > currentDate.getMonth())
				checkInsertDate = true;
			else if(insertMonth == currentDate.getMonth())
				if(insertDay > currentDate.getDate())
					checkInsertDate = true;
		
		if(!checkInsertDate) {
			alert(dateListMustBeMajor);
			frm.txtListaScadenza.focus();
			return false;
		}
	}
	showWaitMessage();
	return true;
}
function checkInsertListaCode(frm) {
	if(frm.txtListaNascitaCode.value == "") {
		alert(insertListaCode);
		frm.txtListaNascitaCode.focus();
		return false;
	}
	
	return true;
}

function goToCash(frm) {

	if(frm.optSendToMe && frm.optSendToMe[0].checked && frm.onlyList.value>>0 == 0) {
		//controlla nel carrello se ci sono articoli in lista
		alert(cashSendInfo);
		
		return false;
	}
	frm.action="default.asp?cmd=makeOrder";
	frm.submit();
	return true;
}
function checkAvailQta(frm, maxvalue) {
	var qta = frm.nx.value>>0;
	qta = (qta > maxvalue ? maxvalue : qta);
	frm.nx.value = qta;
}
function checkInfoRequest(frm) {
	
	if(frm.sendername.value == "") {
		alert(requestNameMsg);
		frm.sendername.focus();
		return false;
	}
	if(!validateEmail(frm.email.value)) {
		alert(requestEmailMsg);
		frm.email.focus();
		return false;
	}
	if(frm.info.value == "") {
		alert(requestInfoMsg);
		frm.info.focus();
		return false;
	}
	
	return true;
}

//var currentRelImage = null;
//var currentRelInfoBox = null;
//var currentInitValue = 0;
function choiceRelVariants(cbo, classId) {
	
	$("." + classId).hide();
	$("#relImage_" + cbo.value).show();
	$("#relInfoBox_" + cbo.value).show();
	
	/*if(currentInitValue != initValue) {
		currentRelImage = null;
		currentRelInfoBox = null;
		currentInitValue = initValue;
	}
	if(currentRelImage == null) currentRelImage = document.getElementById("relImage_" + initValue);
	if(currentRelInfoBox == null) currentRelInfoBox = document.getElementById("relInfoBox_" + initValue);
	
	var divImage = document.getElementById("relImage_" + cbo.value);
	var divRelInfoBox = document.getElementById("relInfoBox_" + cbo.value);
	
	if(currentRelImage != null) currentRelImage.style.display = 'none'; // $("#" + currentRelImage.id).fadeOut("slow");
	if(divImage != null) divImage.style.display = ''; // $("#" + divImage.id).fadeIn("slow");
	currentRelImage = divImage;
	
	if(currentRelInfoBox != null) currentRelInfoBox.style.display = 'none'; // $("#" + currentRelInfoBox.id).fadeOut("slow");
	if(divRelInfoBox != null) divRelInfoBox.style.display = ''; // $("#" + divRelInfoBox.id).fadeIn("slow");
	currentRelInfoBox = divRelInfoBox;
	*/
}


var currentDivImage = null;
var currentInfoBox = null;
var currentViewCart = null;
var currentPointsBox = null;
var currentZoomBox = null;
var currentOtherImages = null;

function choiceVariants(value) {
	if(currentDivImage == null) currentDivImage = document.getElementById("variant_0");
	if(currentInfoBox == null) currentInfoBox = document.getElementById("infoBox_0");
	if(currentPointsBox == null) currentPointsBox = document.getElementById("pointsBox_0");
	if(currentViewCart == null) currentViewCart = document.getElementById("viewCart_0");
	if(currentZoomBox == null) currentZoomBox = document.getElementById("zoomImage_0");
	if(currentOtherImages == null) currentOtherImages = document.getElementById("otherImages_0");
	
	var divImage = document.getElementById("variant_" + value);
	var divInfoBox = document.getElementById("infoBox_" + value);
	var divViewCart = document.getElementById("viewCart_" + value);
	var divPointsBox = document.getElementById("pointsBox_" + value);
	var divZoomBox = document.getElementById("zoomImage_" + value);
	var divOtherImages = document.getElementById("otherImages_" + value);
		
	if(currentDivImage != null) $("#" + currentDivImage.id).fadeOut("slow");//.style.display = "none";	
	if(divImage != null) $("#" + divImage.id).fadeIn("slow"); //.style.display = "";
	currentDivImage = divImage;
	
	if(currentInfoBox != null) currentInfoBox.style.display = "none";
	if(divInfoBox != null) divInfoBox.style.display = "";
	currentInfoBox = divInfoBox;
	
	if(currentViewCart != null) currentViewCart.style.display = "none";
	if(divViewCart != null) divViewCart.style.display = "";
	currentViewCart = divViewCart;
	
	if(currentPointsBox != null) currentPointsBox.style.display = "none";
	if(divPointsBox != null) divPointsBox.style.display = "";
	currentPointsBox = divPointsBox;
	
	if(currentZoomBox != null) currentZoomBox.style.display = "none";
	if(divZoomBox != null) divZoomBox.style.display = "";
	currentZoomBox = divZoomBox;
	
	if(currentOtherImages != null) currentOtherImages.style.display = "none";
	if(divOtherImages != null) divOtherImages.style.display = "";
	currentOtherImages = divOtherImages;
	if(value != 0)
		$("#colorname").text($("#imgcolor_" + value).attr('alt'));
	else
		$("#colorname").text("Seleziona un colore##");
	$("#cboVariants").val(value);
	$("li.selected").removeClass("selected");
	$("#licolor_" + value).addClass("selected");
	
}

Number.prototype.format =			function(n){
										n = n||2;
										var factor = Math.pow(10,n);
										var x = Math.round(this * factor) / factor;
										return x.toFixed(n).replace(/(\d{1,3})(?=(?:\d{3})+\.)|\./g,function($1){return $1=="."?",":$1+"."});
									}

var curPaymentCost = 0;
var curTransportCost = 0;
var curTotalCost = 0;

function excludeCost(exclude) {
	var paymentCost = document.getElementById("paymentCost");
	var transportCost = document.getElementById("transportCost");
	var totalCost = document.getElementById("totalCost");
	
	if(curPaymentCost == 0) {
		curPaymentCost = new Number(paymentCost.value.replace(",", "."));
		curTransportCost = new Number(transportCost.value.replace(",", "."));
		curTotalCost = new Number(totalCost.value.replace(",", "."));
	}
	
	if(exclude) {
		paymentCost.value = (0).format();
		transportCost.value = (0).format();
		totalCost.value = (0).format();
	}
	else {
		paymentCost.value = curPaymentCost.format();
		transportCost.value = curTransportCost.format();
		totalCost.value = curTotalCost.format();
	}
	
}
function checkSearch(frm, defaultText) {
	var searchText = document.getElementById("cmdString").value||"";
	var cboCustomT9 = document.getElementById("cmdT9");
	
	
	if(defaultText.toLowerCase() == searchText.toLowerCase())
		searchText = "";
		
	//if(cboCustomT9) {
		if(/*cboCustomT9.value == 0 && */searchText.length < 3) {
			alert(invalidSearchMsg);
			return false;
		}
	//}
	return true;
	
}
function resetSearchText(defaultText) {
	var searchText = document.getElementById("cmdString");
	if(defaultText.toLowerCase() == searchText.value.toLowerCase())
		searchText.value = "";
}
function restoreSearchText(defaultText) {
	var searchText = document.getElementById("cmdString");
	if(searchText.value == "")
		searchText.value = defaultText;
}

var resultsFadeOut = null;
var startSearch = null;

function resultsMouseMove(element) {
	if(resultsFadeOut != null)
		clearTimeout(resultsFadeOut);
	
	resultsFadeOut = setTimeout("fadeOut('" + element.id + "')", 3000);
}
function fadeOut(id) {	
	$('#' + id).hide();
	$('#cboVariants').removeClass("visibilityHidden");
}
function searchList(event, searchId) {		
	var searchElement = document.getElementById(searchId);
	
	$('#cboVariants').addClass("visibilityHidden");
	
	if(resultsFadeOut != null)
			clearTimeout(resultsFadeOut);
			
	if(event.which == 27) {
		 fadeOut("results_" + searchId);		
		return;
	}
	if(event.which >= 37 && event.which <= 40)
		return;
		
	if(searchElement == null || searchElement.value == "") {		
		fadeOut("results_" + searchId)
		return;
	}
	if(startSearch != null)
		clearTimeout(startSearch);
	startSearch = setTimeout("inlineSearch('" + searchElement.value + "','" + searchId + "')", 300);
	
	
	//resultsFadeOut = setTimeout("fadeOut('results_" + searchId + "')", 3000);

}
function inlineSearch(searchValue, searchId) {
	
	$.get("inlineSearch.asp", {search: searchValue}, function(data) {		
		$("#results_" + searchId).html(data);
		$("#results_" + searchId).show();			
	
	});
}

$(document).ready(function(){
    
    $(".autoZoom").mouseover(function(event){
    	//alert($(this).parent().parent().attr("id"))
    	//$(this).parent().parent().toggleClass("flashingBorder").toggleClass("flashingBorder_hover");
    	//$(this).toggleClass("flashingBorder").toggleClass("flashingBorder_hover");
			$(this).stop(true);
			$(this).css({"z-index":"999"});
    	$(this).animate({"width": "200px","left": "-50%","top": "-50%"}, "slow");
    	$(this).attr({"src" : $(this).attr("bsrc")});
    	
    }).mouseout(function(event){
    	//$(this).toggleClass("flashingBorder").toggleClass("flashingBorder_hover");
			$(this).stop(true);
			
    	$(this).animate({"width": "100px","left": "0%","top": "0%"}, "slow", function(event) {$(this).css({"z-index":"1"});});
    	//$(this).parent().parent().toggleClass("flashingBorder").toggleClass("flashingBorder_hover");
    	$(this).attr({"src" : $(this).attr("ssrc")});
    });

  });
function changeOrder(order) {
	var newOrder = "priceA";
	var orderby = document.getElementById("orderBy");
	var curOrder = orderby.value;
	
	if(order == "price") {
		newOrder = "priceA";
		if(curOrder == "priceA")
			newOrder = "priceD";
		else if(curOrder == "priceD")
			newOrder = "priceA";
	}
	
	if(order == "desc") {
		newOrder = "descA";
		if(curOrder == "descA")
			newOrder = "descD";
		else if(curOrder == "descD")
			newOrder = "descA";
	}
	
	orderby.value = newOrder;
	orderby.form.submit();
}

var currentShow = "boxDescription";
function sheetShowBox(id) {
	$("#" + currentShow).hide();
	$("#" + id).fadeIn();
	$("#container_" + currentShow).removeClass("selected");
	$("#container_" + id).addClass("selected");
	currentShow = id;
	return false;
}

function showComparePopup(id) {
	var oPopUp = window.open("showCompare.asp?id=" + id,"Compare","width=650,height=500,scrollbars=1,resizable=1");
	oPopUp.focus();
}

function facebookShare() {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}