jQuery.noConflict();
var allowCom = false;
jQuery(document).ready( function() {
	if (window.opener) {
                try {
                        var lead_id_div = window.opener.document.getElementById("lead_id_div");
                } catch(e) {
                        var lead_id_div = false;
                }
		if(lead_id_div) {
			jQuery('.header_menu, #cart, #home_bottom_four').hide();
			allowCom = true;
		}
	}
});

function TSSAddToCart( order_product_id ) {
	if(window.opener) {
                try {
                        var lead_id_div = window.opener.document.getElementById("lead_id_div");
                } catch(e) {
                        var lead_id_div = false;
                }
		if(lead_id_div) {
			window.opener.addToQuote( order_product_id );
			self.close();
			return;
		}
	}
	window.location.href = "/cart/add/product/" + order_product_id;
}

function TSSAfterEdit( order_product_id ) {
        if(window.opener) {
                try {
                        var lead_id_div = window.opener.document.getElementById("lead_id_div");
                } catch(e) {
                        var lead_id_div = false;
                }
                if(lead_id_div) {
                        window.opener.postEdit( order_product_id );
                        self.close();
                        return;
                }
        }
	window.location.href = "/cart/?edited_opid=" + order_product_id;
}

function popupSaveEmail(){
	var email = $('email').value;
	if($('email').value != '' && $('email').value != 'enter e-mail address'){ 
		if(isValidEmailAddress(email) && email ) {
			var popup = window.open('','popup','menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width=400,height=435');
			$('email_signup').submit();
			_gaq.push(['_trackEvent', 'Conversion', 'Confirmation', 'Email Sign-Up']);
			return true;
		} else {
			jQuery.prompt("We're sorry, the address you entered <span style='text-transform:uppercase;color:red;'>"+ $('email').value +"</span> is invalid.  Please edit and then resubmit.<br><br>Or please contact customer service and we'll be happy to help.<br /><br />800.754.1455<br /><a href='mailto:design@theshadestore.com' class='bottom_row_link text_links'>design@theshadestore.com</a>", {opacity: 0.4});
			return false;
		}
	} else {
		jQuery.prompt("Please enter a valid e-mail address.", {opacity: 0.4});
		return false;
	}
};
	 
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

<!--
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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=700,left = 420,top = 250');");
}

function ajaxNavigate(url, update_div_id, containing_div_id, selection, set_id, unset_style, set_style) {

    new Ajax.Request(url, {
            method: "get",
            onSuccess: function(transport){
                var container = $(containing_div_id);
                var unset_items = container.select(selection);

                unset_items.each(function(item) {
                        item.removeClassName(set_style);
                        item.addClassName(unset_style);
                    });

                if (set_id != '') {
                    var set_item = $(set_id);
                    set_item.removeClassName(unset_style);
                    set_item.addClassName(set_style);
                }

                $(update_div_id).innerHTML = transport.responseText;
            },
            onFailure: function(transport) {
                alert("Unable to access the server. Please contact customer support.");
            }
    });

}

function ajaxPost(form_id, url, update_div_id) {
    new Ajax.Request(url, {
            method: "post",
            parameters: $(form_id).serialize(),
            onSuccess: function(transport){
                $(update_div_id).innerHTML = transport.responseText;
            },
            onFailure: function(transport) {
                alert("Unable to access the server. Please contact customer support.");
            }
            
            


		

    });
    
    if(window.parent.loadLeadTable){window.parent.loadLeadTable();}
    
}

$ = jQuery;
/*Updates the shopping cart text at the top of the screen*/
function updateProductCheckoutText() {
    $.ajax({
        url: '/cart/get-summary',
        type: 'GET',
        dataType: "json",
        success: update_cart_summary
    });
}

/*Decides what text to display in the cart*/
function update_cart_summary(blah, foo, r) {
    try {
		var d = $.parseJSON(r.responseText);
		var product_string = "";
		var swatch_string = "";

		if (parseInt(d.product_count) <= 1) {
		    product_string = "PRODUCT";
		} else if (parseInt(d.product_count) > 1) {
		    product_string = "PRODUCTS";
		}

		if (parseInt(d.swatch_count) <= 1) {
		    swatch_string = "SAMPLE";
		    swatch_string2 = "";
		} else if (parseInt(d.swatch_count) > 1) {
		    swatch_string = "SAMPLES";
		    swatch_string2 = "S";
		}

		c_summary = "(";
		if (d.product_count > 0) {
		    c_summary += d.product_count + " " + product_string;
		}

		if (d.product_count > 0 && d.swatch_count > 0) {
		    c_summary += ", ";
		}
		if (d.swatch_count > 0) {
		    c_summary += d.swatch_count + " " + swatch_string;
		    var sample_summary = swatch_string2 + " (" + d.swatch_count + ")";
		}
		c_summary += ")";
		if (d.product_count == 0 && d.swatch_count == 0) {
		    c_summary = 'SHOPPING CART';
		}
		$('#cart_summary, .cart_summary').html(c_summary);
		$('.cart_summary').css('width', 'auto');
		$('.cart_summary').css('width', $('.cart_summary').width()); 
    } catch(e) {
	//
	}
}
jQuery.noConflict();

