// JavaScript Document
<!--
function stoperror(){
return true;
}

window.onerror=stoperror;

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);


if (typeof Node != 'undefined') {
	Node.prototype.removeNode = function() { this.parentNode.removeChild(this) };
}


function DL_GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }

      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}

function DL_GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nTopPos = eElement.offsetTop;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }

      nTopPos += eParElement.offsetTop;    // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                          // return the number calculated
}

function insertRelatedItems() {//used for performance issue - loads related products thumbnail
	numberOfProducts=(arrayLength-3)/numberOfAttributes;
	for (var i = 0; i < numberOfProducts; i++) {
		relatedProducts=results[productCounter+11];
			newProduct.getElementsByTagName('div')[4].innerHTML=relatedProducts;
	}
	Behaviour.apply();//image preview behavior on related review thumbnails 
	imagePreview();
	//JSRC();
}

function insertProductTable() {
//testString="`Crayons.jpg`Hot Baby`800`Baby Kenzie! The Optic Signature Baby Bag by Coach has been one hot seller since initially introduced in Fall 2005. These popular diaper bags sold out so fast they were going on Ebay for over $600 this winter.`1234`productType`style`for`color`Crayons.jpg`AHot Baby`400`ABaby Kenzie! The Optic Signature Baby Bag by Coach has been one hot seller since initially introduced in Fall 2005. These popular diaper bags sold out so fast they were going on Ebay for over $600 this winter.`1235`productType`style`for`color";
	results = testString.split("`");
	numberOfAttributes=12;
	arrayLength=results.length;  
	numberOfProducts=(arrayLength-3)/numberOfAttributes;
	productCounter=1;
	insertBeforeMarker = document.getElementById('bottomMarker');
	for (var i = 0; i < numberOfProducts; i++) {
		imageFile=results[productCounter];
		productTitle=results[productCounter+1];
		productTitleURL = "/" + productTitle.replace(/ /g, "-") + ".html";
		productPrice=results[productCounter+2];
		productDescription=results[productCounter+3];
		productId=results[productCounter+4];
		productType=results[productCounter+5];
		productStyle=results[productCounter+6];
		forPerson=results[productCounter+7];
		productColor=results[productCounter+8];
		productURL=results[productCounter+9];
		productURLOrig=results[productCounter+9];
		ratingHTML=results[productCounter+10];
		relatedProducts=results[productCounter+11];
		productURL = productURL.replace("&", "~");
		if (checkId(productId)) {
			newProduct = templateTable.cloneNode(true);
			newProduct.getElementsByTagName('img')[0].src="images/productPics/"+imageFile;
			newProduct.getElementsByTagName('img')[0].alt=productTitle;
			
			//newProduct.getElementsByTagName('a')[1].href="http://classymommy.com/redirector.php?urlLocation="+productURL;
			newProduct.getElementsByTagName('h3')[0].getElementsByTagName('a')[0].innerHTML=productTitle + ": $" + productPrice;
			//newProduct.getElementsByTagName('span')[0].innerHTML="$"+productPrice;
			newProduct.getElementsByTagName('p')[0].getElementsByTagName('a')[0].innerHTML=productDescription;
			newProduct.id=productId;
			newProduct.getElementsByTagName('input')[0].value=productType;
			newProduct.getElementsByTagName('input')[1].value=productStyle;
			newProduct.getElementsByTagName('input')[2].value=forPerson;
			newProduct.getElementsByTagName('input')[3].value=productColor;
			newProduct.getElementsByTagName('div')[1].innerHTML=ratingHTML;
			links_in_desc_div = newProduct.getElementsByTagName('div')[0].getElementsByTagName('a').length //when stars are voted, the number of hrefs changes
			//newProduct.getElementsByTagName('div')[2].path=productTitle;
			newProduct.getElementsByTagName('a')[0].href=productTitleURL;
			newProduct.getElementsByTagName('a')[1].href=productTitleURL;
			newProduct.getElementsByTagName('a')[links_in_desc_div-1].href=productTitleURL;
			newProduct.getElementsByTagName('a')[links_in_desc_div-2].href=productTitleURL;
			//newProduct.getElementsByTagName('a')[4].innerHTML=productType;
			//newProduct.getElementsByTagName('a')[4].href="index.php?productType=" + productType;
			newProduct.getElementsByTagName('div')[4].innerHTML=relatedProducts;
			//
			/*newProduct.getElementsByTagName('a')[5].innerHTML = "For: " + forPerson;
			newProduct.getElementsByTagName('a')[5].href="index.php?for=" + forPerson;
			if (productColor!="") {
				newProduct.getElementsByTagName('a')[6].innerHTML = productColor + " Color";
				newProduct.getElementsByTagName('a')[6].href="index.php?color=" + productColor;
			} else {
				newProduct.getElementsByTagName('a')[6].innerHTML = "Color N/A";
			}
			newProduct.getElementsByTagName('a')[7].innerHTML=productStyle;
			newProduct.getElementsByTagName('a')[7].href="index.php?style=" + productStyle; */
			document.getElementById('productContainer').insertBefore(newProduct,insertBeforeMarker);
		}
		productCounter+=numberOfAttributes;
	}
	totalPages=results[arrayLength-2];
 	currentPage=results[arrayLength-1];
	pagingText="Pages: <br />";
	for (var k = 1; k <= totalPages; k++) {
		if (k==currentPage) {
			pagingText=pagingText + " " + "<div class='page_on'>" + k + "</div>";
		} else {
			if (browseOrSearch=="browse") {
				pagingText=pagingText + " " + "<div class='page_off' onClick='window.scrollTo(0,0); document.getElementById(\"pageNumber\").value=" + k + ";removeAllProducts();getProducts();'>" + k + "</div>";
			} else {
				pagingText=pagingText + " " + "<div class='page_off' onClick='window.scrollTo(0,0); document.getElementById(\"pageNumber\").value=" + k + ";removeAllProducts();findProducts();'>" + k + "</div>";
			}
		}
	}
	document.getElementById('paging').innerHTML=pagingText;
	Behaviour.apply();//image preview behavior on related review thumbnails 
	imagePreview();
	//JSRC();
	
}

function sortIt(order) {
	document.getElementById('pageNumber').value=1;
	document.getElementById('sortBy').value=order;
	if (browseOrSearch=="browse") {
		setTimeout('getProducts()',120);
	} else {
		setTimeout('findProducts()',120);
	}
	removeAllProducts();	
}


function checkId(productId) {
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		if(productId==products[j].id) {
			return false;
		}
	}
	return true;
}
function checkPrice(priceRange) {
	removeAllProducts();
	document.getElementById('pageNumber').value=1;
	priceHighLow = priceRange.split("`");
	priceLow=priceHighLow[0]*1;
	priceHigh=priceHighLow[1]*1;
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		price=products[j].getElementsByTagName('tr')[0].getElementsByTagName('td')[2].innerHTML;
		price=price.substr(1,price.length)*1;
		if(price>=priceLow && price<=priceHigh && priceRange!="%") {
		} else {
			//fader = new Fadomatic(products[j], 10, 100);
			//fader.fadeOut();
			//delete fader; 
			products[j].removeNode(true);
			j--;
			numberOfProductsShown--;
		}
	}
}

function checkProductType(productTypeSelected) {
	removeAllProducts();
	document.getElementById('pageNumber').value=1;
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		productTypeCurrent=products[j].getElementsByTagName('input')[0].value;
		if(productTypeCurrent.indexOf(productTypeSelected)==-1 && productTypeSelected!="%") {
			products[j].removeNode(true);
			j--;
			numberOfProductsShown--;
		} 
	}
}
function checkStyle(styleSelected) {
	removeAllProducts();
	document.getElementById('pageNumber').value=1;
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		styleCurrent=products[j].getElementsByTagName('input')[1].value;
		if(styleCurrent.indexOf(styleSelected)==-1 && styleSelected!="%") {
			products[j].removeNode(true);
			j--;
			numberOfProductsShown--;
		} 
	}
}
function checkForPerson(personSelected) {
	removeAllProducts();
	document.getElementById('pageNumber').value=1;
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		forPersonCurrent=products[j].getElementsByTagName('input')[2].value;
		if(forPersonCurrent.indexOf(personSelected)==-1 && personSelected != "%") {
			products[j].removeNode(true);
			j--;
			numberOfProductsShown--;
		} 
	}
}
function checkColor(colorSelected) {
	removeAllProducts();
	document.getElementById('pageNumber').value=1;
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('table');
	numberOfProductsShown=products.length;
	for (var j = 0; j < numberOfProductsShown; j++) {
		colorCurrent=products[j].getElementsByTagName('input')[3].value;
		if(colorCurrent.indexOf(colorSelected)==-1 && colorSelected != "%") {
			products[j].removeNode(true);
			j--;
			numberOfProductsShown--;
		} 
	}
}
function removeAllProducts() {
	document.getElementById('paging').innerHTML="";
	productTable=document.getElementById('productContainer');
	products=productTable.getElementsByTagName('div');
	numberOfProductsShown=products.length;
	for (var g = numberOfProductsShown-2; g >= 0; g--) {
		products[g].removeNode(true);
		//numberOfProductsShown=numberOfProductsShown-1;
	}
}

function writeBreadcrumb() {
	document.getElementById('breadcrumbProductType').innerHTML=document.getElementById('productTypeSelector').options[document.getElementById('productTypeSelector').selectedIndex].text;
	styleZ=document.getElementById('styleSelector').options[document.getElementById('styleSelector').selectedIndex].text.replace("Style:", "");
	document.getElementById('breadcrumbStyle').innerHTML=styleZ;
	personZ=document.getElementById('forPersonSelector').options[document.getElementById('forPersonSelector').selectedIndex].text.replace("For:", "");
	document.getElementById('breadcrumbFor').innerHTML=personZ;
	priceZ=document.getElementById('priceRangeSelector').options[document.getElementById('priceRangeSelector').selectedIndex].text.replace("Price:", "");
	document.getElementById('breadcrumbPrice').innerHTML=priceZ;
	colorZ=document.getElementById('colorSelector').options[document.getElementById('colorSelector').selectedIndex].text.replace("Color:", "");
	document.getElementById('breadcrumbColor').innerHTML=colorZ;
}
function setFocus() {
	document.getElementById('focusGetter').focus();
}
// This technique is a combination of a technique I used for highlighting FAQ's using anchors 
// and the ever popular yellow-fade technique used by 37 Signals in Basecamp.

// Including this script in a page will automatically do two things when the page loads...
// 1. Highlight a target item from the URL (browser address bar) if one is present.
// 2. Setup all anchor tags with targets pointing to the current page to cause a fade on the target element when clicked.

// This is the amount of time (in milliseconds) that will lapse between each step in the fade
var FadeInterval = 200;

// This is where the fade will start, if you want it to be faster and start with a lighter color, make this number smaller
// It corresponds directly to the FadeSteps below
var StartFadeAt = 15;

// This is list of steps that will be used for the color to fade out
var FadeSteps = new Array();
	FadeSteps[1] = "DD";
	FadeSteps[2] = "DD";
	FadeSteps[3] = "DD";
	FadeSteps[4] = "CC";
	FadeSteps[5] = "BB";
	FadeSteps[6] = "AA";
	FadeSteps[7] = "99";
	FadeSteps[8] = "88";
	FadeSteps[9] = "77";
	FadeSteps[10] = "66";
	FadeSteps[11] = "55";
	FadeSteps[12] = "44";
	FadeSteps[13] = "33";
	FadeSteps[14] = "22";
	FadeSteps[15] = "11";

// This is the recursive function call that actually performs the fade
function DoFade() {
    if (colorId >= 1) {
		targetId.style.backgroundColor = "#ff" + FadeSteps[colorId] + "ff";
		
        // If it's the last color, set it to transparent
        if (colorId==1) {
            //targetId.style.backgroundColor = "transparent";
			//var colorId=7;
			window.clearTimeout(runnit);
		}
        colorId--;
		
        // Wait a little bit and fade another shade
        runnit = setTimeout("DoFade()", FadeInterval);
	}
}
//colorId=7;
//DoFade(colorId, targetId);
//-->
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("The email address you entered is not a valid email adress.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("The email address you entered is not a valid email adress.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("The email address you entered is not a valid email adress.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("The email address you entered is not a valid email adress.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("The email address you entered is not a valid email adress.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("The email address you entered is not a valid email adress.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("The email address you entered is not a valid email adress.")
		    return false
		 }

 		 return true					
	}

function ValidateForm(emailField){
	var emailID=emailField;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	 if (!confirm("By entering this contest, you are signing up for the Classy Mommy email newsletter. After receiving the first newsletter, you can always opt out. Would you like to continue?")){
		 return false;
	}
	return true
 }