function showFoilDropdown()
{
	$("#div_foil_1").slideToggle(100);
}

function onSelectChange(type, id) {
	var selected = $("#" + type + "_" + id);
	if ((selected.val() != "") && (selected.val() != null)) {  
		$("#div_" + type + "_" + (parseInt(id)+1)).show(100);
	}  else {
		$("#div_" + type + "_" + (parseInt(id)+1)).hide(100);
	}
}

function largeProductImage()
{
	$.blockUI({ 
       message: $('div#large'), 
       showOverlay: false,
       css: { 
         top:  ($(window).height() - 600) /2 + 'px', 
         left: ($(window).width() - 600) /2 + 'px',
		 width: '150px',
         border: 'none', 
         padding: '15px', 
         backgroundColor: '#000',
         '-webkit-border-radius': '10px', 
         '-moz-border-radius': '10px', 
         opacity: .80, 
         color: '#fff'
       } 
   });
}

function popular_itemLoadCallback(carousel, state)
{
    if (state != 'init')
        return;

    jQuery.get('index.php?popular=true', function(data) {
        product_itemAddCallback(carousel, carousel.first, carousel.last, data);
    });
};

function new_itemLoadCallback(carousel, state)
{
    if (state != 'init')
        return;

    jQuery.get('index.php?new=true', function(data) {
        product_itemAddCallback(carousel, carousel.first, carousel.last, data);
    });
};

function product_itemAddCallback(carousel, first, last, data)
{
    var items = data.split('|');

    for (i = 0; i < items.length; i++) {
		var split = items[i].split('%5E');
        carousel.add(i+1, product_getItemHTML(split[0], split[1], split[2]));
    }

    carousel.size(items.length);
};

function product_getItemHTML(ahref, alt, url)
{
    return '<a href="' + ahref + '" title="' + alt +'"><img src="' + url + '" title="' + alt + '" alt="' + alt + '" width="199px" height="134px"/></a><br /><strong>' + alt + '</strong>';
};

function updateStocks(product_id)
{
	$("#stocks").load("index.php?product_id=" + product_id + "&paper=true&stocks=" + $("input[name='stock_color']").fieldArray() + "&textures=" + $("input[name='stock_texture']").fieldArray() + "&prices=" + $("input[name='stock_price']").fieldArray()); 
}

function selectAllStockColors(product_id)
{
	$("input[name='stock_color']").each(function() {
		this.checked = "checked";
	});
	
	updateStocks(product_id);
}

function unselectAllStockColors(product_id)
{
	$("input[name='stock_color']").each(function() {
		this.checked = null;
	});
	
	updateStocks(product_id);
}

function selectAllStockTextures(product_id)
{
	$("input[name='stock_texture']").each(function() {
		this.checked = "checked";
	});
	
	updateStocks(product_id);
}

function unselectAllStockTextures(product_id)
{
	$("input[name='stock_texture']").each(function() {
		this.checked = null;
	});
	
	updateStocks(product_id);
}

function unselectAllStockPrices(product_id)
{
	$("input[name='stock_price']").each(function() {
		this.checked = null;
	});
	
	updateStocks(product_id);
}

function updateAdvancedSearch()
{	
	var array = $("#advancedSearchForm").formHash();
	var options = "advanced_search=true";
	
	for (keyVar in array) {
		var options = options + "&" + keyVar + "=" + array[keyVar];
	}
	
	$("#advanced_search").load("index.php?" + options); 
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

$(document).ready(function()
{	
	$('.foldertable').tableHover({colClass: 'hover', cellClass: 'hovercell', ignoreCols: [1,2]}); 
					    
	$('.showhide').toggle(function(){
	  $(this).parent().next().show('fast').removeClass('hide').preventDefault;
	  $(this).html('Hide');	
	  },function(){
		$(this).parent().next().hide('fast').addClass('hide').preventDefault;
	    $(this).html('Show');
	})
	
	$('.hideshow').toggle(function(){
		$(this).parent().next().hide('fast').addClass('hide').preventDefault;
	    $(this).html('Show');
	  },function(){
		  $(this).parent().next().show('fast').removeClass('hide').preventDefault;
		  $(this).html('Hide');
	})
	
	$("input[name='stock_color']").each(function() {
		this.checked = "checked";
	});
	
	$('.product_search').defaultValue('Search Products...');
	
	$(".cat_ajax").change(function(){
		var id = $(this).attr('id').split('_');
		var maincatalog = $("#maincatalog_"+id[1]);
		var subcats = $("#subcat_"+id[1]);
		var prods = $("#product_"+id[1]);
		var is_sample = 0;
		if($("#sample_request").length) is_sample = 1;
		$.getJSON(
			"index.php",
			{ajax:'1', action:'request_maincat_change', cat:maincatalog.val(), is_sample:is_sample},
			function(data){
				if(data){				
					if(data['prods']){
						prods.removeAttr("disabled");				
						prods.find('option').remove();
						prods.append($('<option></option').val("").html("Select Product"));
						$.each(data['prods'], function(key, item){
							prods.append($('<option min="'+item['min_qty']+'"></option').val(item['id']).html(item['name']+' - '+item['rel']).attr('rel', item['rel']).attr('name', item['name']).addClass(item['img']));
						})		
						$("#showProducts_"+id[1]).removeClass("grayed");							
					} else {
						disableProd(prods)
						$("#showProducts_"+id[1]).addClass("grayed");	
					}
					if(data['subcats']){
						subcats.find('option').remove();
						subcats.append($('<option></option').val("").html("Select Subcategory"));
						$.each(data['subcats'], function(val, text){
							subcats.append($('<option></option').val(val).html(text));
						})	
						subcats.parent().parent().show();
					} else {
						disableSubcat(subcats)
					}				
				} else {
					disableProd(prods)
					$("#showProducts_"+id[1]).addClass("grayed");	
					disableSubcat(subcats)
				}
			}		
		)	
	});
	$(".ajax_subpcat").change(function(){
		var id = $(this).attr('id').split('_');		
		var subcats = $("#subcat_"+id[1]);
		var prods = $("#product_"+id[1]);
		var is_sample = 0;
		if($("#sample_request").length) is_sample = 1;
		$.getJSON(
			"index.php",
			{ajax:'1', action:'request_subcat_change', cat:subcats.val(), is_sample:is_sample},
			function(data){
				if(data){				
					prods.removeAttr("disabled");				
					prods.find('option').remove();
					prods.append($('<option></option').val("").html("Select Product"));
					$.each(data, function(key, item){
						prods.append($('<option min="'+item['min_qty']+'"></option').val(item['id']).html(item['name']+' - '+item['rel']).attr('rel', item['rel']).attr('name', item['name']).addClass(item['img']));
					})
					$("#showProducts_"+id[1]).removeClass("grayed");	
				} else {
					disableProd(prods);
					$("#showProducts_"+id[1]).addClass("grayed");	
				}
			}		
		)	
	});
	function disableProd(prods){
		prods.removeAttr("disabled");				
		prods.find('option').remove();
		prods.append($('<option></option').val("").html("Select Product"));				
		prods.attr("disabled", "disabled");	
		
	}
	function disableSubcat(subcats){
		subcats.parent().parent().hide();
		subcats.find('option').remove();
		subcats.append($('<option></option').val("").html("Select Subcategory"));	
	}


	
	$('.ajax_product').click(function(){
		var id = $(this).attr('id').split("_");
		if($(this).val()){
			$("#rowAddOtherProd_"+id[1]).show();
			
			if($("#quantity").length){
				var tmp = $(this).find("option:selected").attr('min')
				$("#quantity").rules("remove", "range");
				$("#quantity").rules("add", {range:[tmp, 10000000]});
				$("#jserror_quantity").html("Please enter a quantity. Start from "+tmp)
			}
			
		} else {
			$("#rowAddOtherProd_"+id[1]).hide();
			$("#div_product_" + (parseInt(id[1])+1)).hide(100);
		}
	});
	$(".addOtherProd").click(function(){
		$("#"+$(this).attr('rel')).show(100);
	})
	
	
	$('#stock_1').click(function(){
		onSelectChange("stock", 1);
	});
	$('#stock_2').click(function(){
		onSelectChange("stock", 2);
	});
	$('#stock_3').click(function(){
		onSelectChange("stock", 3);
	});
	$('#stock_4').click(function(){
		onSelectChange("stock", 4);
	});
	$('#stock_5').click(function(){
		onSelectChange("stock", 5);
	});
		
	$('.foil_s').click(function(){
		var id = $(this).attr('id').split("_");
		onSelectChange("foil", id[1]);
	})	
	
  	$("[id^='div_product_']").hide();
  	$("[id^='div_stock_']").hide();
	$("[id^='div_foil_']").hide();
  	
	if (show_sample_2 == 1) {
		$("#div_product_2").slideToggle(100);	
	}

	$('#showChart').click(function() { 
	        $.blockUI({ 
	            message: $('div#colorChart'), 
	            css: { 
	              top:  ($(window).height() - 906) /2 + 'px', 
	              left: ($(window).width() - 710) /2 + 'px', 
	              width: '710px'
	            } 
	        });
			$('.blockOverlay').attr('title','Click to close').click($.unblockUI); 
	 });

	$('#showLargeProduct').click(function() { 
	        $.blockUI({ 
	            message: $('div#largeProduct'), 
	            css: { 
	              top:  ($(window).height() - 600) /2 + 'px', 
	              left: ($(window).width() - 600) /2 + 'px', 
	              width: '710px'
	            } 
	        });
			$('.blockOverlay').attr('title','Click to close').click($.unblockUI); 
	 });

	$(".product_search").autocomplete("index.php", {
		width: 450,
		selectFirst: false,
		matchContains: false,
		max: 1500,
		extraParams: { type:"product_ac" }
	});

	$(".product_search").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
	});

	var showText='Show Answers';
	var hideText='Hide Answers';

	$('.faq_category').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');
	$('.faq_category').hide();

	$('a.toggleLink').click(function() {
		$(this).html ($(this).html()==hideText ? showText : hideText);
		$('.faq_category').hide();$('a.toggleLink').html(showText);
		$(this).parent().next('.faq_category').toggle();
		
		return false;
	});
	
	$("#phone").mask("999-999-9999");
	$(".focus").focus();
	
	$("#shipping_method").change(function(){
		if($(this).val()==0){
			$("#form_sample_custom_shipping").show()
		} else {
			$("#form_sample_custom_shipping").hide()
		}
	})
	
	$(".del_submit").click(function(){
		if(!confirm("Deleting. Are you sure?")) return false;
	})

	
	$(".sortable").each(function(){
		var id = $(this).attr('id').split('_')
		$(this).tablesorter({widthFixed: true, sortList: [[id[1],1]]});
	})

	var form_quote_sel_quantity_last = $(".form_quote_sel_quantity:checked");
	$(".form_quote_sel_quantity").click(function(){

		if(form_quote_sel_quantity_last && parseInt($(this).val()) != parseInt(form_quote_sel_quantity_last.val()) ){
			form_quote_sel_quantity_last.removeAttr('checked');
		} else {
			return false;
		}
		form_quote_sel_quantity_last = $(this);
	})

		
		
	var validator = $(".from_validate").validate({
		showErrors: function(errorMap, errorList) {
			var valids = this.validElements();
			var invalids = this.invalidElements();

			valids.each(function(){
				$("#jserror_"+$(this).attr('id')).hide();
			})
			
			if (invalids.length > 0) {
				$("#err_text").text("See below for problem with submission and try again.");
				$("#err_block").show();
				
				invalids.each(function(){
					if($(this).attr('id') == 'password2' || $(this).attr('id') == 'user_password2') {
						if(!$(this).val()){
							$("#jserror_"+$(this).attr('id')).text('Please confirm your password.');
						} else {
							$("#jserror_"+$(this).attr('id')).text('Passwords don\'t match, please retype password.');
						}
					}
					$("#jserror_"+$(this).attr('id')).show();
				})
			} else {
//				$("span.error").hide();
//				$("#err_block").hide();
			}
		}
	});	
	
	$("#b_add_addr").click(function(){
		$("#addr_edit").val("0");
		$("#f_addr_sel").submit();
	})
	$("#b_sel_addr").click(function(){
		$("#f_addr_sel").submit();
	})	
	
	$('.qoute_check').each(function(){
		if($(this).is(':checked')){
			$("#"+$(this).attr('id')+"_div").show();
		} else {
			$("#"+$(this).attr('id')+"_div").hide();
		}
		$(this).click(function(){	
			$("#"+$(this).attr('id')+"_div").toggle();
		})
	})
	
	$(".textpopup").each(function(){
		$(this).jqm({trigger: false, closeClass:'close_popup', overlay: 0});
		
		var tmp_obj = $(this);
		$('a[rel='+$(this).attr('id')+']').click(function(e){
			tmp_obj.jqmShow();
			tmp_obj.css("top", parseInt(e.clientY-100));
			tmp_obj.css("left", e.clientX);
			tmp_obj.css("width", "280px");
		})
	})
	
	
	var lastSelectFoil = null;
	$("#foil_popup").jqm({trigger: false, overlay: 0});
	$("a.showFoils").click(function(){
		var tmpClicked = $(this);
		if(!$("#foil_popup").html()){
			$.post(
				"index.php",
				{ajax:'1', action:'get-foil_popup'},
				function(data){
					if(data){
						$("#foil_popup").html(data);
						showFoilPopup(tmpClicked);
					}
				}
			)
		} else {
			showFoilPopup(tmpClicked);
		}
		return false;		
	})
	function showFoilPopup(tmpClicked){
		lastSelectFoil = $("#"+tmpClicked.attr('rel'));
		
		if(lastSelectFoil.val()){			
			var tmpObj = $('#afoil_'+lastSelectFoil.val())
			if(!tmpObj.attr("id")) return;
			$(".select_foil").removeClass('current');
			tmpObj.addClass('current');
		}		
		$('#foil_popup').jqmShow();
	}
	
	$(".select_foil").live('click', function(){
		var id = $(this).attr('id').split('_');
		if(lastSelectFoil){
			lastSelectFoil.val(id[1]);
			var subId = lastSelectFoil.attr('id').split("_");
			if(subId[1]) {
				onSelectChange("foil", subId[1]);
			}
			lastSelectFoil = null;
		}
		
		$("#foil_popup").jqmHide();
	})
	
	
	var lastSelectStock = null;
	$("#stock_popup").jqm({trigger: false, overlay: 0});
	$("a.showStock").click(function(){
		var tmpClicked = $(this);
		if(!$("#stock_popup").html()){
			$.post(
				"index.php",
				{ajax:'1', action:'get-stock_popup'},
				function(data){
					if(data){
						$("#stock_popup").html(data);
						showStockPopup(tmpClicked);
					}
				}
			)
		} else {
			showStockPopup(tmpClicked);
		}
		return false;
	})
	function showStockPopup(tmpClicked){
		lastSelectStock = $("#"+tmpClicked.attr('rel'));
		
		if(lastSelectStock.val()){			
			var tmpObj = $('#astock_'+lastSelectStock.val())
			if(!tmpObj.attr("id")) return;
			$(".select_stock").removeClass('current');
			tmpObj.addClass('current');
		}		
		$('#stock_popup').jqmShow();
	}
		
	$(".select_stock").live('click', function(){
		var id = $(this).attr('id').split('_');
		if(lastSelectStock){
			lastSelectStock.val(id[1]);
			var subId = lastSelectStock.attr('id').split("_");
			if(subId[1]) {
				onSelectChange("stock", subId[1]);
			}
			lastSelectStock = null;
		}
		
		$("#stock_popup").jqmHide();
	})
	
	var lastSelectProduct = null;
	$("#product_popup").jqm({trigger: false, overlay: 0});
	$("a.showProds").click(function(){
		lastSelectProduct = $("#"+$(this).attr('rel'));
		
		if(lastSelectProduct.attr("disabled")){	
			lastSelectProduct = null;
		} else {
			var prod_popup_place = $("#prod_popup_place")
			prod_popup_place.html('');
			var tmpHtml = '';
			var tmpIds = '';
			lastSelectProduct.find("option").each(function(){
				if($(this).val()){
					tmpIds += $(this).val()+"_";
					tmpHtml += '<div><a href="images/products/'+$(this).attr("class")+'" id="popupprod_'+$(this).val()+'" rel="'+$(this).attr("rel")+'" class="select_prod">'+$(this).attr("name")+'</a></div>';
				}
			})			
			prod_popup_place.html(tmpHtml);
			$("#prod_popup_imgtitle").html('');
			$("#prod_popup_img").html('');
			$("#prod_popup_select").removeAttr("rel");
			
			if(lastSelectProduct.val()){			
				populateProduct($('#popupprod_'+lastSelectProduct.val()))
			} else {
				populateProduct($('#prod_popup_place').find(".select_prod:first"))
			}
			
			$(".select_prod").click(function(){	
				populateProduct($(this))	
				return false;			
			})
			$('#product_popup').jqmShow();
		}
		return false;		
	})
	
	function populateProduct(obj){
		if(!obj.attr("id")) return;
		var tmpId = obj.attr("id").split('_');
		$("#prod_popup_imgtitle").html('<a href="javascript:;">'+obj.html()+'</a>');
		$("#prod_popup_imgtitle").find('a').click(selectProduct)
		
		$("#prod_popup_styletitle").html('Style: '+obj.attr('rel'));
			$("#prod_popup_img").html('<img width="300" src="'+obj.attr("href")+'">');
		
		$("#prod_popup_img").find("img").css("cursor", "pointer").click(selectProduct)
		$("#prod_popup_select").attr("rel", tmpId[1]);
		$(".select_prod").each(function(){
			$(this).parent().removeClass('current')
		});
		obj.parent().addClass('current');
	}
	
	$("#prod_popup_select").click(selectProduct)	
		
	function selectProduct(){
		if(lastSelectProduct && $("#prod_popup_select").attr('rel')){			
			lastSelectProduct.val($("#prod_popup_select").attr('rel'));
			var tmpId = lastSelectProduct.attr('id').split("_");
			if(tmpId[1]) {
				if(lastSelectProduct.val()){
					$("#rowAddOtherProd_"+tmpId[1]).show();
				} else {
					$("#rowAddOtherProd_"+tmpId[1]).hide();
					$("#div_product_" + (parseInt(tmpId[1])+1)).hide(100);
				}
			}
			
			lastSelectProduct = null;
		}
		
		$("#product_popup").jqmHide();		
	}
	
	

	

	$(".close_popup").live('click', function(){			
		var tmpId = $(this).attr('id').split('_');
		$("#"+tmpId[1]+"_popup").jqmHide();
		return false;
	})
	
	$(".ajax_product").each(function(){
		var tmpId = $(this).attr('id').split('_');
		if(tmpId[1]){
			if($(this).val()){
				onSelectChange("product", tmpId[1]);
			}
		}
	})
	
	$(".ajax_stock").each(function(){
		var tmpId = $(this).attr('id').split('_');
		if(tmpId[1]){
			if($(this).val()){
				onSelectChange("stock", tmpId[1]);
			}
		}
	})	

	$(".ajax_stock").each(function(){
		var tmpId = $(this).attr('id').split('_');
		if(tmpId[1]){
			if($(this).val()){
				onSelectChange("stock", tmpId[1]);
			}
		}
	})	
	
	$(".sample_select").each(function(){		
		var tmpId = $(this).attr('id').split('_');
		if(tmpId[1]){
			if($(this).val()){
				onSelectChange("foil", tmpId[1]);
			}
		}
	})	
	
	$(".ajdriven").change(function(){
		var tmp_cur = $(this);
		$.getJSON(
			"index.php",
			{ajax:'1', action:'update_pfpage_selects', 
				sizes:$("#select-sizes").val(), 
				pockets:$("#select-pockets").val(), 
				product_three_panel:$("#select-panels").val(),
				product_orientation:$("#select-orientations").val(),
				product_round_corners:$("#select-comer_types").val(),
				reinforce_edges:( $("#checkbox-reinforce_edges").is(':checked') && !$("#checkbox-reinforce_edges").is(':disabled')),
				capacity_folders:( $("#checkbox-capacity_folders").is(':checked') && !$("#checkbox-capacity_folders").is(':disabled')),
				windows:( $("#checkbox-windows").is(':checked') && !$("#checkbox-windows").is(':disabled'))
			},
			function(data){
				if(tmp_cur.attr('id') != "select-sizes" || tmp_cur.val() == -1)			
					updatePFPSelect("select-sizes", data['sizes']);
					
				if(tmp_cur.attr('id') != "select-pockets" || tmp_cur.val() == -1)
					updatePFPSelect("select-pockets", data['pockets']);
					
				if(tmp_cur.attr('id') != "select-panels" || tmp_cur.val() == -1)			
					updatePFPSelect("select-panels", data['product_three_panel']);
					
				if(tmp_cur.attr('id') != "select-orientations" || tmp_cur.val() == -1)		
					updatePFPSelect("select-orientations", data['product_orientation']);
					
				if(tmp_cur.attr('id') != "select-comer_types" || tmp_cur.val() == -1)		
					updatePFPSelect("select-comer_types", data['product_round_corners']);
					
				if(tmp_cur.attr('id') != "select-reinforce_edges")
					updatePFPCheckbox($("#checkbox-reinforce_edges"), data['reinforce_edges']);
					
				if(tmp_cur.attr('id') != "select-capacity_folders")
					updatePFPCheckbox($("#checkbox-capacity_folders"), data['capacity_folders']);
					
				if(tmp_cur.attr('id') != "select-windows")
					updatePFPCheckbox($("#checkbox-windows"), data['windows']);
			}
		)		
	})
	function updatePFPSelect(id, data){	
		var tmp_obj = $("#"+id);
		var tmp_val = tmp_obj.val();
		$("#"+id+" option:not(option:first)").each(function(){$(this).remove()});
		
		$.each(data, function(val, text) {
			tmp_obj.append('<option value="'+val+'">'+text+'</option');
		})
		tmp_obj.find('option[value='+tmp_val+']').attr('selected', 'selected');
	}
	function updatePFPCheckbox(obj, data){	
		if(data) {
			obj.removeAttr('disabled');			
			$("label[for="+obj.attr('id')+"]").css("color", "#333");
		} else {
			obj.attr('disabled', 'disabled');
			$("label[for="+obj.attr('id')+"]").css("color", "#aaa");
		}
	}
	
	
	$('.product-image-cell, .product-images-thumbnails').find('a').lightBox();
	
	$('.folder_design_box div a').lightBox();
	
	$('.tabs-list').find('li').click(function(){
		$('.tabs-list').find('li.active').removeClass('active');
		$(this).addClass('active');
		$('.prod-tabs').hide();
		$('#'+$(this).find('a').attr('rel')).show();
	})
	$('.see_all').click(function(){
		$("#li_"+$(this).attr('rel')).click();
	    return false;
	})
		
	$(".tabbed > a").click(function(){
		$('.tabs').hide();
		$("#"+$(this).attr('rel')).show();
		
		$(".tabbed > a").removeClass('cur');
		$(this).addClass('cur');
		
		return false;
	})
	
	
	$("#login_box_link").click(function(){
		$(this).parent().parent().toggleClass('arf1_collapsed');
		return false;
	})
		
	$("#login_form").validate({
		showErrors: function(errorMap, errorList) {
			var valids = this.validElements();
			var invalids = this.invalidElements();

			valids.each(function(){
				$("#jserror_"+$(this).attr('id')).hide();
			})
			
			if (invalids.length > 0) {
				$("#err_text").text("See below for problem with submission and try again.");
				$("#err_block").show();
				
				invalids.each(function(){
					if($(this).attr('id') == 'password2' || $(this).attr('id') == 'user_password2') {
						if(!$(this).val()){
							$("#jserror_"+$(this).attr('id')).text('Please confirm your password.');
						} else {
							$("#jserror_"+$(this).attr('id')).text('Passwords don\'t match, please retype password.');
						}
					}
					$("#jserror_"+$(this).attr('id')).show();
				})
			} else {
//				$("span.error").hide();
//				$("#err_block").hide();
			}
		}
	});	
	
	$("#folders_table tr").each(function(){
		var o1 = $(this).find('td:first').find('a.prod_img_box1')
		var o2 = $(this).find('td:last').find('a.prod_img_box1')
		if(o1.height() && o2.height()) {
			var h1 = parseInt(o1.height());
			var h2 = parseInt(o2.height());
			if(h1 > h2) o2.height(h1)
			else o1.height(h2)
		}
	})
	
	$('a.submit').click(function(){
		$(this).parents('form').submit();
	})
		
/*		
	$("#login_btn").click(function(){
		var err = false;
		var email_patt = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
		
		if(email_patt.test($("#login_email").val())){
			$("#login_email_err").hide()
		} else {
			$("#login_email_err").show()
			err = true;
		}
		
		if($("#login_pass").val().length){
			$("#login_pass_err").hide()
		} else {
			$("#login_pass_err").show()
			err = true;
		}
		
		if(!err){
			$.post(
				"index.php",
				{ajax:'1', action:'request_login', 
					username:$("#login_email").val(), 
					password:$("#login_pass").val()
				},
				function(data){
					if(data['error']){
						$("#login_error").text(data['error']).show();
					} else {
						$("#login_error").hide();
					}
					
					if(data['success']){
						$("#head_login h3").html(data['success']);
						$("#already_reg_box1").hide();
					}
				},
				"json"
			)
		}
		return false;
	})
*/
});

jQuery.validator.addMethod("zipPostalCode", function(value, element) {
	return this.optional(element) || /^[0-9a-zA-Z\ ]{5,7}$/i.test(value);
}, "Invalid ZIP/Postal Code"); 	


