var selectedProduct = 0;
var selectedDesign = 0;
var selectedImage;
var auxSelectedProduct = 0;
var auxSelectedDesign = 0;
var styleChoosed = false;
var recentDeleted = false;
var mainTypeSel = "lnkmt0";
var inIndex;
var infoToggled = 0;

function SwapOn(imgId){
    if (document.images) {
        document.images['img'+imgId].src = RollimageOn[imgId].src;
    }
    return true;
}

function SwapOff(imgId){
    if (document.images) {
        document.images['img'+imgId].src = RollimageOff[imgId].src;
    }
    return true;
}
var rowcount = 1;
function addShirtRow(){
    rowcount++;
    table = document.getElementById('prodVariations');
        tbody = document.createElement("TBODY");
        tbody.id = "tbody" + rowcount;
        tbody.name = "tbody" + rowcount;
            tr = document.createElement("TR")
            tr.id = "var" + rowcount;
            tr.name = "var" + rowcount;
                /** Colors **/
                tdColorLabel = document.createElement("TD");
                tdColorLabel.id = "tdColorLabel" + rowcount;
                    txtpimId = document.createElement("input");
                    txtpimId.id = "pimId" + rowcount;
                    txtpimId.name = "pimId[]";
                    txtpimId.value = 'N';
                    txtpimId.type = "hidden";
                    lblColorLabel = document.createElement("label");
                    lblColorLabel.innerHTML = "Color:";
                    lblColorLabel.className = "fieldLabel";
                tdColorLabel.appendChild(txtpimId);
                tdColorLabel.appendChild(lblColorLabel);
                tdColorSelect = document.createElement("TD");
                tdColorSelect.id = "tdColorSelect" + rowcount;
                    selColorSelect = document.createElement("select");
                    selColorSelect.id = "selColor" + rowcount;
                    selColorSelect.name = "selColors[]";
                    selColor1 = document.getElementById('selColor1');
                    for (var i=0; i<selColor1.options.length; i++) {
                        var elm = selColor1.options[i];
                        selColorSelect.options[i] = new Option(elm.innerHTML);
                        selColorSelect.options[i].value = elm.value;
                    }
                    lnkAddColor = document.createElement("A");
                    lnkAddColor.href = "javascript:void(0);"
                    lnkAddColor.id = "lnkAddColor" + rowcount;
                    lnkAddColor.innerHTML = " Add color";
                    lnkAddColor.title = rowcount;
                    lnkAddColor.onclick = function() {
                        resultControl = "selColor" + this.title;
                        opener = this.id;
                        openPalette();
                    };
                tdColorSelect.appendChild(selColorSelect);
                tdColorSelect.appendChild(lnkAddColor);
                tdOnHandLabel = document.createElement("TD");
                tdOnHandLabel.id = "tdOnHandLabel";
                tdOnHandText = document.createElement("td");
                tdOnHandText.id='tdOnHandText' + rowcount;
                    lnkSize = document.createElement("A");
                    lnkSize.id = "lnkShowSizes" + rowcount;
                    lnkSize.name = "lnkShowSizes[]";
                    lnkSize.href = 'javascript:void(0);';
                    lnkSize.innerHTML = "Available sizes";
                    lnkSize.title = rowcount;
                    lnkSize.onclick = function() {
                        openerSize = this.id;
                        resultControlSize = "txtSizes" + this.title;
                        openSizeBox();
                    }
                    txtOnHand = document.createElement("input");
                    txtOnHand.id = "txtSizes" + rowcount;
                    txtOnHand.name = "txtSizes[]";
                    txtOnHand.type = "hidden";
                tdOnHandText.appendChild(lnkSize);
                tdOnHandText.appendChild(txtOnHand);
                tdImageLabel = document.createElement("TD");
                tdImageLabel.id = "tdImageLabel" + rowcount;
                tdImageLabel.className = 'fieldLabel';
                    lblImageLabel = document.createElement("label");
                    lblImageLabel.id = 'lblImageLabel' + rowcount;
                    lblImageLabel.innerHTML = "Image:";
                tdImageLabel.appendChild(lblImageLabel);
                tdImageFile = document.createElement("TD");
                tdImageFile.id = "tdImageFile" + rowcount;
                    filImageFile = document.createElement("input");
                    filImageFile.type = "file";
                    filImageFile.name = "txtImage[]";
                    filImageFile.id = "txtImage" + rowcount;
                tdImageFile.appendChild(filImageFile);
                tdMore = document.createElement("TD");
                tdMore.id = "tdMore" + rowcount;
                tdMore.innerHTML = "[+]";
                tdMore.onclick = function() {
                    addShirtRow();
                }
                tdRemove = document.createElement("TD");
                tdRemove.id = "tdRemove" + rowcount;
                tdRemove.innerHTML = "[-]";
                tdRemove.title = rowcount;
                tdRemove.onclick = function() {
                    this.parentNode.parentNode.parentNode.removeChild(document.getElementById("tbody"+this.title));
                }
                /***********/
                tr.appendChild(tdColorLabel);
                tr.appendChild(tdColorSelect);
                tr.appendChild(tdOnHandText);
                tr.appendChild(tdImageLabel);
                tr.appendChild(tdImageFile);
                tr.appendChild(tdMore);
                tr.appendChild(tdRemove);
            tbody.appendChild(tr);
        table.appendChild(tbody);
}
function refreshAllColors()
{
    selColors = document.getElementsByTagName("select");
    for (i in selColors) {
        if (selColors[i].className == "selColors") {
            var opts = selColors[i].options;
        }
    }
}
/**Expand and contract Brand or Category **/
function expContTree(title, label)
{
    var nodes = document.getElementById("subcategory"+title);
    if (document.getElementById(label).innerHTML == "[+]") {
        document.getElementById(label).innerHTML = "[-]";
        $("#subcategory"+title).show("slow");
    } else {
        document.getElementById(label).innerHTML = "[+]";
        $("#subcategory"+title).hide("slow");
    }
}
/**
* CONTRACT ALL SUBCATEGORIES
*/
function contractAllSubcategories()
{
    $(".subCat").hide(0);
}
/*
* OPEN A T-SHIRT IMAGE BASED ON THIS COLOR
*/
function openShirt(imageId)
{
    $("#t_shirt_image").animate({
        opacity:0
    }, 300);
    $("#imgDesign").animate({
       opacity:0
    },300);
    $.post("load_tshirt.php",{
           imageId: imageId,
           action: "loadShirt"
           }, function(html) {
               setTimeout("changeImage('" + html + "')",350);
               $("#t_shirt_image").animate({
                   opacity:1
               }, 900);
           });
           selectedImage = imageId;
}
function openShirt2(imageId)
{
    $("#t_shirt_image").animate({
        opacity:0
    }, 300);
    $("#imgDesign").animate({
       opacity:0
    },300);
    $.post("load_tshirt.php",{
           imageId: imageId,
           action: "loadShirt"
           }, function(html) {
               setTimeout("changeImage2('" + html + "')",350);
               $("#t_shirt_image").animate({
                   opacity:1
               }, 900);
           });
           selectedImage = imageId;
}
function openShirtDescPrice(imageId) {
    $("#divAppDescription").animate({
        opacity:0
    }, 300);
    $.post("load_tshirt.php",{
           imageId: imageId,
           designId: selectedDesign,
           action: "loadShirtDescPre"
           }, function(xml) {
               $("#divAppDescription").animate({
                   opacity:1
               }, 300, changeDescPress(xml));
           });
}
function changeDescPress(xml){
    data = xml.firstChild;
    price = data.childNodes[1].firstChild.data.replace(/[*]/gi, "<");
    price = price.replace(/[-]/gi, ">");
    price = price.replace(/[#]/gi, "&");
    var sizeInfo = $(xml).find("product").find("sizeInfo").text() + "<br clear='all'><a href='javascript:void(0);' onclick=\"hideSizingInfo()\">Close</a>";
    try {
        $("#sInfo").attr("innerHTML", data.firstChild.firstChild.data);
        $("#sInfo2").attr("innerHTML", sizeInfo);
    } catch(e)
    {

    }
    if(price.lastIndexOf("$")<0) {
        $("#divPrice").attr("innerHTML","$" + price);
    } else {
    	$("#divPrice").attr("innerHTML",price);
    }
}
function changeImage(html)
{
    $("#t_shirt_image").attr("innerHTML", html);
    $("#imgDesign").show(0);
    $("#imgDesign").animate({
        opacity:1
    },900);
}
function changeImage2(html)
{
    $("#t_shirt_image").attr("innerHTML", html);
    /*$("#imgDesign").show(0);
    $("#imgDesign").animate({
        opacity:1
    },900);*/
}
function chooseStyle(productId)
{
	selectedProduct = productId;
    document.getElementById('imgDesign').style.top = eval(getElementPosition("t_shirt_image").top + 75) + "px";
    document.getElementById('imgDesign').style.left = eval(getElementPosition("t_shirt_image").left + 95) + "px";
    $.post("load_tshirt.php",{
           productId: productId,
           action: "loadStyle"
           }, function(xml) {
               var data = xml.firstChild;
               $("#divColors").slideDown("fast", refreshColors(xml));
               openShirt(data.firstChild.attributes[0].value);
               openShirtDescPrice(productId);
           });
           styleChoosed = true;
}
function chooseStyleLettering(productId)
{
	selectedProduct = productId;
    document.getElementById('imgDesign').style.top = eval(getElementPosition("t_shirt_image").top + 75) + "px";
    document.getElementById('imgDesign').style.left = eval(getElementPosition("t_shirt_image").left + 95) + "px";
    $.post("load_tshirt.php",{
           productId: productId,
           action: "loadStyle"
           }, function(xml) {
               var data = xml.firstChild;
               $("#divColors").slideDown("fast", refreshColors2(xml));
               openShirt2(data.firstChild.attributes[0].value);
               openShirtDescPrice(productId);
           });
           styleChoosed = true;
}
function chooseStyleAcc(productId)
{
    document.getElementById('imgDesign').style.top = eval(getElementPosition("t_shirt_image").top + 75) + "px";
    document.getElementById('imgDesign').style.left = eval(getElementPosition("t_shirt_image").left + 95) + "px";
    $.post("load_tshirt.php",{
           productId: productId,
           action: "loadStyle"
           }, function(xml) {
               var data = xml.firstChild;
               $("#divSizes").slideDown("fast");
               changeBigDesign(productId);
               loadSizes(productId);
           });
           styleChoosed = true;
}
function refreshColors(xml) {
    var colors = xml.firstChild;
    lblSpace = document.createElement("label");
    lblSpace.innerHTML = "<br/>";
    document.getElementById('divColors').innerHTML = "";
    for(i=0; i<colors.childNodes.length; i++) {
        lnkColor = document.createElement("A");
        lnkColor.id = colors.childNodes[i].attributes[0].value;
        lnkColor.href = "javascript:void(0);";
        lnkColor.style.textDecoration = 'none';
        $('#divColorName').attr('innerHTML', "");
        lnkColor.innerHTML = "&nbsp;<span style='width:25px; background-color:#" + colors.childNodes[i].childNodes[0].childNodes[0].data + ";border: thin solid #cccccc;' onmouseOver= \"$('#divColorName').attr('innerHTML', '<strong>Color:</strong>" + colors.childNodes[i].childNodes[0].attributes[0].value +"')\">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;";
        lnkColor.onclick = function() {
            openShirt(this.id);
            $("#divSizes").slideUp("normal", loadSizes(this.id));
            $("#divAddToCart").slideUp("normal");
            //$("#divAddToCart").attr("innerHTML", "Make a choise");
            $("#divAddToCart").attr("innerHTML", "");
            //$("#divAddToCart").slideDown("slow");
        }
        document.getElementById('divColors').appendChild(lnkColor);
            //if (((i+1)%3)==0) {
            //    document.getElementById('divColors').appendChild(lblSpace);
            //}
        $("#divColors").slideUp("normal");
    }
}

function refreshColors2(xml) {
    var colors = xml.firstChild;
    lblSpace = document.createElement("label");
    lblSpace.innerHTML = "<br/>";
    document.getElementById('divColors').innerHTML = "";
    for(i=0; i<colors.childNodes.length; i++) {
        lnkColor = document.createElement("A");
        lnkColor.id = colors.childNodes[i].attributes[0].value;
        lnkColor.href = "javascript:void(0);";
        lnkColor.style.textDecoration = 'none';
        $('#divColorName').attr('innerHTML', "");
        lnkColor.innerHTML = "&nbsp;<span style='width:25px; background-color:#" + colors.childNodes[i].childNodes[0].childNodes[0].data + ";border: thin solid #cccccc;' onmouseOver= \"$('#divColorName').attr('innerHTML', '<strong>Color:</strong>" + colors.childNodes[i].childNodes[0].attributes[0].value +"')\">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;";
        lnkColor.onclick = function() {
            openShirt2(this.id);
            $("#divSizes").slideUp("normal", loadSizes(this.id));
            $("#divAddToCart").slideUp("normal");
            //$("#divAddToCart").attr("innerHTML", "Make a choise");
            $("#divAddToCart").attr("innerHTML", "");
            //$("#divAddToCart").slideDown("slow");
        }
        document.getElementById('divColors').appendChild(lnkColor);
            //if (((i+1)%3)==0) {
            //    document.getElementById('divColors').appendChild(lblSpace);
            //}
        $("#divColors").slideUp("normal");
    }
}

function getElementPosition(elemID)
{
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
    typeof document.body.leftMargin != "undefined") {
    offsetLeft += document.body.leftMargin;
    offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}
function loadSizes(productImageId) {
    $.post("load_tshirt.php",{
           productImageId: productImageId,
           action: "loadSize"
           }, function(xml) {
               refreshSizes(xml);
           });
}
function refreshSizes(xml)
{
    var sizes = xml.firstChild;
    var ulSizes = document.createElement("ul");
    ulSizes.id = "ulSizes";
    ulSizes.className='lavaLampNoImage';
    document.getElementById('divSizes').innerHTML = "";
    for(i=0; i<sizes.childNodes.length; i++) {
        radSize = document.createElement("input");
        radSize.id = "radSize" + sizes.childNodes[i].childNodes[0].childNodes[0].data;
        radSize.name = "radSize";
        radSize.className = "radSize";
        radSize.value = sizes.childNodes[i].childNodes[0].childNodes[0].data;
        radSize.title = sizes.childNodes[i].childNodes[0].childNodes[0].data;
        radSize.onclick = function() {
        	$(".radSize").attr("checked", false);
            $("#divAddToCart").slideUp("normal");
            selectedProduct = this.title;
            $("#stepsInstructions").slideUp("fast");
            this.checked=true;
            verifyCart();
        }
        radSize.style.display='none';
        radSize.type = "radio";
        lblSize = document.createElement("label");
        lblSize.id = "lblSize" + sizes.childNodes[i].childNodes[0].childNodes[0].data;
        lblSize.innerHTML = sizes.childNodes[i].childNodes[1].childNodes[0].data;
        lblSize.title = sizes.childNodes[i].childNodes[0].childNodes[0].data;
        liSizes = document.createElement("li");
        liSizes.id = "liSize" + sizes.childNodes[i].childNodes[0].childNodes[0].data;
        liSizes.title = sizes.childNodes[i].childNodes[0].childNodes[0].data;
        liSizes.onclick = function() {
        	$(".radSize").attr("checked", false);
            $("#divAddToCart").slideUp("normal");
            selectedProduct = this.title;
            $("#radSize" + this.title).attr("checked",true);
            $("#stepsInstructions").slideUp("fast");
            verifyCart();
        }
        liSizes.appendChild(radSize);
        liSizes.appendChild(lblSize);
        ulSizes.appendChild(liSizes);
    }
    ulSizes.style.width = eval(i * 60) + "px";
    $("#divSizes").slideDown("fast");
    document.getElementById('divSizes').appendChild(ulSizes);
    $("#liSize" + sizes.childNodes[0].childNodes[0].childNodes[0].data).click();
    $("#ulSizes").lavaLamp({
          fx: "backout",
          speed: 200,
          click: function(event, menuItem) {
              return false;
          }
	});
}
function addToCart()
{
	var error = false;
	if(document.getElementById('txtQuantity').value <=0) {
		error = true;
	}
	if (document.getElementById('txtQuantity').value.length>0) {
		for(i=0; i<document.getElementById('txtQuantity').value.length; i++) {
			digit = document.getElementById('txtQuantity').value.substr(i,1);
			if (digit <=0 || digit >9) {
				error = true;
			}
		}
	} else {
		error = true;
	}
	if (!error) {
    $("#divAddToCart").slideUp("normal");
    if(document.getElementById('txtQuantity').value){
    $.post("add_to_cart.php", {
        action: "add",
        designId: selectedDesign,
        productSizeId: selectedProduct,
        quantity: document.getElementById('txtQuantity').value
    }, function(html) {
           $.post("add_to_cart.php", {
               action: "refresh"
               },function(xml) {
                   refreshCartBox(xml);
           });
           verifyCart();
       }
    );
    }
	} else {
		alert("Invalid quantity");
	}
}
function refreshCart()
{

}
function change_quantity(id){
	document.getElementById(id).className = "caja_habilitada";
	document.getElementById(id).readOnly = false;
	document.getElementById(id).focus();
}

function refreshEdit(txtId,quantity){
   $("#divAddToCart").slideUp("fast");
    $.post("add_to_cart.php", {
        action: "edit",
        productSizeId: selectedProduct,
        designId: selectedDesign,
		txtId: txtId,
		quantity: quantity
    }, function(html) {
        $.post("add_to_cart.php", {
               action: "refresh"
               },function(xml) {
                   refreshCartBox(xml);
           }
       );
    }
    )

}
function editOrder(productSizeId, designId, quantity) {
	if(designId>0) {
	    qVal = $("#txtQ"+productSizeId + designId).val();
	} else {
		qVal = $("#txtQ"+productSizeId + "0").val();
	}
	error = "";
	if(qVal.length <=0) {
		error = "Please type a quantity";
	}
	if(qVal <=0) {
		error = "Quantity must be more than 0";
	}
	for (i=0; i<qVal.length; i++) {
		if (qVal.substr(i,1) >=0 && qVal.substr(i,1) <=9) {
		} else {
			error = "Quantity contains invalid characters";
		}
	}
	if(error=="") {
	    $.post("add_to_cart.php", {
            action: "edit",
            productSizeId: productSizeId,
            designId: designId,
		    quantity: quantity
        }, function() {
        	if(designId==0) {
        		designId="0";
        	}
    	    $("#lblQ" + productSizeId + designId).attr('innerHTML', $('#txtQ'+ productSizeId + designId).attr('value'));
    	    $('#qEnabled'+ productSizeId + designId).hide(0);
    	    $('#qDisabled'+ productSizeId + designId).slideDown("fast");
    	    $("#txtSubtotal").attr("value", $("#txtSubtotal").val().substr(1) - $("#lblT" + productSizeId + designId).attr("innerHTML"));
    	    $("#lblT"+ productSizeId + designId).attr("innerHTML", ($("#lblP" + productSizeId + designId).attr("innerHTML") * quantity).toFixed(2));
    	    $("#txtSubtotal").attr("value", "$" + (parseFloat($("#txtSubtotal").val()) + parseFloat($("#lblT" + productSizeId + designId).attr("innerHTML"))).toFixed(2));
    	    if(parseFloat($("#txtSubtotal").val().substr(1)) > 50) {
    	    	$("#txtShipping").val("$0");
    	    } else {
    	    	$("#txtShipping").val("$4.99");
    	    }
    	    //var calculations = parseFloat($("#txtSubtotal").val().substr(1)) +
    	    //parseFloat(parseFloat($("#txtShipping").val().substr(1))).toFixed(2) -
    	    //$("#txtDiscount").val().substr(1);
    	    $("#lblTotal").val((parseFloat($("#txtSubtotal").val().substr(1)) + parseFloat(parseFloat($("#txtShipping").val().substr(1)))).toFixed(2) - $("#txtDiscount").val().substr(1));
    	    $("#lblTotal").val("$"+parseFloat($("#lblTotal").val()));
    	    //$("#lblTotal").val("$"+calculations);
        });
	}else {
		alert(error);
	}
}
function editOrderAdmin(productSizeId, designId, quantity, detailId) {
	if(designId>0) {
	    qVal = $("#txtQ"+productSizeId + designId).val();
	} else {
		qVal = $("#txtQ"+productSizeId).val();
	}
	error = "";
	if(qVal.length <=0) {
		error = "Please type a quantity";
	}
	if(qVal <=0) {
		error = "Quantity must be more than 0";
	}
	for (i=0; i<qVal.length; i++) {
		if (qVal.substr(i,1) >=0 && qVal.substr(i,1) <=9) {
		} else {
			error = "Quantity contains invalid characters";
		}
	}
	if(error=="") {
	    $.post("do_order.php", {
            action: "editQty",
            detailId: detailId,
		    quantity: quantity
        }, function() {
        	if(designId==0) {
        		designId="";
        	}
    	    $("#lblQ" + productSizeId + designId).attr('innerHTML', $('#txtQ'+ productSizeId + designId).attr('value'));
    	    $('#qEnabled'+ productSizeId + designId).hide(0);
    	    $('#qDisabled'+ productSizeId + designId).slideDown("fast");
    	    $("#txtSubtotal").attr("value", $("#txtSubtotal").val().substr(1) - $("#lblT" + productSizeId + designId).attr("innerHTML"));
    	    $("#lblT"+ productSizeId + designId).attr("innerHTML", ($("#lblP" + productSizeId + designId).attr("innerHTML") * quantity).toFixed(2));
    	    $("#txtSubtotal").attr("value", "$" + (parseFloat($("#txtSubtotal").val()) + parseFloat($("#lblT" + productSizeId + designId).attr("innerHTML"))).toFixed(2));
    	    if(parseFloat($("#txtSubtotal").val().substr(1)) > 50) {
    	    	$("#txtShipping").val("$0");
    	    } else {
    	    	$("#txtShipping").val("$4.99");
    	    }
    	    total = (parseFloat($("#txtSubtotal").val().substr(1)) + parseFloat($("#txtShipping").val().substr(1)));
    	    total = total - $("#txtDiscount").val().substr(1);
    	    $("#lblTotal").attr("value", "$" + total.toFixed(2));
        });
	}else {
		alert(error);
	}
}
function refreshCartBox(xml)
{
    if(navigator.appName!="Microsoft Internet Explorer") {
        tbodyItems = document.getElementById('tbodyItems');
    }
    while (tbodyItems.childNodes.length >= 1 )
    {
        tbodyItems.removeChild(tbodyItems.firstChild );
    }
    var dataCar = xml.firstChild;
	if(dataCar.childNodes.length>0){
	    for(i=0; i<dataCar.childNodes.length; i++) {
	        trItem = document.createElement("TR");
	            tdDelete = document.createElement("TD");
	            if (dataCar.childNodes[i].childNodes[6].childNodes[0].data != " ") {
	               tdDelete.innerHTML = "<img src='images/icon_delete.gif' onclick='recentDeleted = true; auxSelectedProduct = " + selectedProduct + "; auxSelectedDesign = selectedDesign; selectedProduct=" + dataCar.childNodes[i].childNodes[0].childNodes[0].data + "; selectedDesign=" + dataCar.childNodes[i].childNodes[6].childNodes[0].data + "; removeFromCart();' alt='Remove' />";
	            } else {
	            	tdDelete.innerHTML = "<img src='images/icon_delete.gif' onclick='recentDeleted = true; auxSelectedProduct = " + selectedProduct + "; auxSelectedDesign = selectedDesign; selectedProduct=" + dataCar.childNodes[i].childNodes[0].childNodes[0].data + "; selectedDesign=0; removeFromCart();' alt='Remove' />";
	            }
	            tdEdit = document.createElement("TD");
				tdEdit.innerHTML = "<img src='images/icon_edit.gif' style='cursor:pointer;' onclick='change_quantity(\""+i+"\")' alt='Edit' />";

				tdDesign = document.createElement("TD");
				if(dataCar.childNodes[i].childNodes[8].childNodes[0].data != " ") {
	                tdDesign.innerHTML = "<img src='includes/phpt/phpThumb.php?src=../../images/designs/" + dataCar.childNodes[i].childNodes[8].childNodes[0].data + "&w=30&bg=" + dataCar.childNodes[i].childNodes[11].childNodes[0].data + "'>";
	                tdDesign.innerHTML += "&nbsp;&nbsp;<img src=includes/phpt/phpThumb.php?src=../../images/products/" + dataCar.childNodes[i].childNodes[2].childNodes[0].data + "&w=30>";
				} else {
					tdDesign.innerHTML += "&nbsp;&nbsp;<img src=includes/phpt/phpThumb.php?src=../../images/accesories/" + dataCar.childNodes[i].childNodes[2].childNodes[0].data + "&w=30>";
				}
	            tdColor = document.createElement("TD");
	            tdColor.innerHTML = "&nbsp;&nbsp;";
	            tdColor.style.backgroundColor = "#" + dataCar.childNodes[i].childNodes[4].childNodes[0].data;
	            tdColor.bgcolor = "#" + dataCar.childNodes[i].childNodes[4].childNodes[0].data;

	            tdSize = document.createElement("TD");
	            tdSize.innerHTML = dataCar.childNodes[i].childNodes[5].childNodes[0].data;

	            tdQuantity = document.createElement("TD");
	            	var txtQuantity = document.createElement("input");
		            txtQuantity.setAttribute("type","text");
		            txtQuantity.id = i;
		            txtQuantity.readOnly = true;
		            txtQuantity.className = "caja_formulario";
		            txtQuantity.name = "quantity"+ i;
		            txtQuantity.onblur = function () {
		            	 					selectedProduct = dataCar.childNodes[this.id].childNodes[0].childNodes[0].data ;
		            	 					selectedDesign = dataCar.childNodes[this.id].childNodes[6].childNodes[0].data;
		            						refreshEdit(this.id,this.value);
	    								   };
	            	txtQuantity.value = dataCar.childNodes[i].childNodes[9].childNodes[0].data;
		        tdQuantity.appendChild(txtQuantity);
		        //tdQuantity.innerHTML = dataCar.childNodes[i].childNodes[9].childNodes[0].data;
	        trItem.appendChild(tdDelete);
		    trItem.appendChild(tdEdit);
			trItem.appendChild(tdDesign);
	        trItem.appendChild(tdColor);
	        trItem.appendChild(tdSize);
	        trItem.appendChild(tdQuantity);
	        tbodyItems.appendChild(trItem);
	    }
	    document.getElementById('btnCheckout').style.display='';
	    document.getElementById('trTitles').style.display='';
	}
	else{
		trItem = document.createElement("TR");
		tdNoItems = document.createElement("TD");
        tdNoItems.innerHTML = "No items in cart";
        document.getElementById('btnCheckout').style.display='none';
        document.getElementById('trTitles').style.display='none';
        trItem.appendChild(tdNoItems);
	    tbodyItems.appendChild(trItem);
	}
    if(document.getElementById('itemsInCart')) {
        if (dataCar.attributes[0].value > 0) {
            document.getElementById("itemsInCart").innerHTML = dataCar.attributes[0].value + " items in cart";
        } else {
            document.getElementById("itemsInCart").innerHTML = "No items in cart";
        }
    }
}

function verifyCart()
{
    if (recentDeleted == true) {
        selectedProduct = auxSelectedProduct;
        recentDeleted = false;
    }
    if(selectedProduct > 0) {
        $.post("add_to_cart.php", {
            action: "verify",
            productSizeId: selectedProduct,
            designId: selectedDesign
            }, function(html) {
                $("#divAddToCart").attr("innerHTML", html);
                $("#divAddToCart").slideDown("fast");
                auxSelectedProduct = 0;
                recentDeleted = false;
            }
        )
    } else {
        $("#divAddToCart").slideDown("fast");
    }
}
function removeFromCart()
{
    $("#divAddToCart").slideUp("fast");
    $.post("add_to_cart.php", {
        action: "remove",
        productSizeId: selectedProduct,
        designId: selectedDesign
    }, function(html) {
        verifyCart();
        $.post("add_to_cart.php", {
               action: "refresh"
               },function(xml) {
               	   selectedDesign = auxSelectedDesign;
                   refreshCartBox(xml);
           });
    }
    )
}
function removeFromOrder(productSizeId, designId) {
	if(confirm("Click OK to remove item from your cart\nClick Cancel to keep it")) {
		$("#trItems" + productSizeId + designId).animate({
            opacity:0
        },300);
		setTimeout("$('#trItems" + productSizeId + designId +"').css('display', 'none')", 400);
		$.post("add_to_cart.php", {
        action: "remove",
        productSizeId: productSizeId,
        designId: designId
        }, function(ret) {
        	if(ret=='cart empty'){
        	    location.href='index.php'
        	}
            $("#txtSubtotal").attr("value", "$" + (parseFloat($("#txtSubtotal").val().substr(1)) - parseFloat($("#lblT" + productSizeId + designId).attr("innerHTML"))).toFixed(2));
        	if(parseFloat($("#txtSubtotal").val().substr(1)) > 50) {
    	    	$("#txtShipping").val("$0");
    	    } else {
    	    	$("#txtShipping").val("$4.99");
    	    }
        	$("#lblTotal").attr("value","$" + (parseFloat($("#txtSubtotal").val().substr(1)) + parseFloat($("#txtShipping").val().substr(1)) - $("#txtDiscount").val().substr(1)).toFixed(2));
        });
	}
}
/***************************************** Rotate images ************************************************************/
        var fadeimages=new Array();
        var fadebgcolor="transparent"
        var gradientStyle;

        ////NO need to edit beyond here/////////////

        var fadearray=new Array() //array to cache fadeshow instances
        var fadeclear=new Array() //array to cache corresponding clearinterval pointers

        var dom=(document.getElementById) //modern dom browsers
        var iebrowser=document.all

        function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder, withgradient){
        this.pausecheck=pause
        this.mouseovercheck=0
        this.delay=delay
        this.degree=10 //initial opacity degree (10%)
        this.curimageindex=0
        this.nextimageindex=1
        fadearray[fadearray.length]=this
        this.slideshowid=fadearray.length-1
        this.canvasbase="canvas"+this.slideshowid
        this.curcanvas=this.canvasbase+"_0"
        if (withgradient==true) {
            gradientStyle=' class="div_fade_gradient"';
        }else {
            gradientStyle=' class="div_fade_normal"';
        }
        //if (typeof displayorder!="undefined")
        //    theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
            this.theimages=theimages
            this.imageborder=parseInt(borderwidth)
            this.postimages=new Array() //preload images
            for (p=0;p<theimages.length;p++){
                this.postimages[p]=new Image()
                this.postimages[p].src=theimages[p][0]
            }

            var fadewidth=fadewidth+this.imageborder*2
            var fadeheight=fadeheight+this.imageborder*2

            if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
                document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;-khtml-opacity:10;"'+ gradientStyle + '></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;background-color:'+fadebgcolor+'"></div></div>')
            else
                document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
            if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
                this.startit()
            else{
                this.curimageindex++
                setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
            }
        }

        function fadepic(obj){
            if (obj.degree<100){
                obj.degree+=10
                if (obj.tempobj.filters&&obj.tempobj.filters[0]){
                    if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
                        obj.tempobj.filters[0].opacity=obj.degree
                    else //else if IE5.5-
                        obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
                }
                else if (obj.tempobj.style.MozOpacity)
                    obj.tempobj.style.MozOpacity=obj.degree/101
                else if (obj.tempobj.style.KhtmlOpacity)
                    obj.tempobj.style.KhtmlOpacity=obj.degree/100
            }
            else{
                clearInterval(fadeclear[obj.slideshowid])
                obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
                obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
                obj.populateslide(obj.tempobj, obj.nextimageindex)
                obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
                setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
            }
        }

        fadeshow.prototype.populateslide=function(picobj, picindex){
        var slideHTML=""
        if (this.theimages[picindex]) {
            if (this.theimages[picindex][1]!="") //if associated link exists for image
                slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
                slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
                if (this.theimages[picindex][1]!="") //if associated link exists for image
                    slideHTML+='</a>'
                picobj.innerHTML=slideHTML
            }
        }


        fadeshow.prototype.rotateimage=function(){
            if (this.pausecheck==1) //if pause onMouseover enabled, cache object
                var cacheobj=this
            if (this.mouseovercheck==1)
                setTimeout(function(){cacheobj.rotateimage()}, 100)
            else if (iebrowser&&dom||dom){
                this.resetit()
            var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
            crossobj.style.zIndex++
            fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
            this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
            }
            else{
                var ns4imgobj=document.images['defaultslide'+this.slideshowid]
                ns4imgobj.src=this.postimages[this.curimageindex].src
            }
            this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
        }

        fadeshow.prototype.resetit=function(){
            this.degree=10
            var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
            if (crossobj.filters&&crossobj.filters[0]){
                if (typeof crossobj.filters[0].opacity=="number") //if IE6+
                    crossobj.filters(0).opacity=this.degree
                else //else if IE5.5-
                    crossobj.style.filter="alpha(opacity="+this.degree+")"
            }
            else if (crossobj.style.MozOpacity)
                crossobj.style.MozOpacity=this.degree/101
            else if (crossobj.style.KhtmlOpacity)
                crossobj.style.KhtmlOpacity=obj.degree/100
        }


        fadeshow.prototype.startit=function(){
            var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
            this.populateslide(crossobj, this.curimageindex)
            if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
                var cacheobj=this
                var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
                crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
                crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
            }
            this.rotateimage()
        }
function openWindowInfo(title,id_banner)
{
if(title=='customer'){
	$('div#divFooter').load('customer_service.php');
	$("div#divFooter").show("slow");

}
if(title=='add_banners'){
  $("div#divAdmBanner").show("normal");
  $("div#divUpBanner").hide("normal");
}

if(title=='edit_banners'){
    $.get("edit_website.php", { idImage:id_banner }, function(html){
        $('div#divUpBanner').load('edit_website.php?idImage='+id_banner);
        $("div#divUpBanner").show("slow");
        $("div#divAdmBanner").hide("normal");
       });
    }
}

//banners administracion
function confirm_entry(idDelete)
{
    input_box=confirm("Click OK or Cancel to Continue");
    if (input_box==true) {
        // Output when OK is clicked
        window.location.href='website.php?idDelete='+idDelete;
    }
}
//banners administracion
function changeMainDesign(id)
{
	if(selectedDesign != id) {
	    if (styleChoosed == false) {
	        changeBigDesign(id);
	    }
	    $.post("load_tshirt.php", {
            action: "change_design",
            id: id
        }, function(html) {
            $("#imgDesign").attr("src", html);
            loadDesignDesc(id);
        });
        selectedDesign = id;
        $('#divOrigDes').slideDown('normal');
	}
}
function loadDesignDesc(id)
{
	$.post("load_tshirt.php", {
        action: "load_design_desc",
        id: id
    }, function(json) {
    	var jsonObj = eval("(" + json + ")");
        $("#divDesignDescription").attr("innerHTML", jsonObj.description);
        $(".titles").attr("innerHTML", jsonObj.name);
        //openShirtDescPrice(selectedImage);
    });
}
function changeBigDesign(id)
{
	$("#imgDesign").animate({
       opacity:0
    },300);
	$.post("load_tshirt.php",{
           imageId: id,
           action: "loadBigDesign"
           }, function(html) {
           	   $("#t_shirt_image").animate({
           	   	    opacity:0
           	   }, 300);
           	   $("#t_shirt_image").css("height", "400");
           	   $("#t_shirt_image").attr("innerHTML", html);
               $("#t_shirt_image").animate({
               	opacity:1
               }, 300);
           });
}
function sendCard() {
	$("#divResults").attr("innerHTML", "Checking card please wait...<img src='/images/loading.gif' width='40px' height='40px' border='0' alt='Loading...' />")
	$("#CardInfo").hide(0);
	$("#divResults").show("slow");
	$.post("check_card.php",{
           cardNumber: document.getElementById('cardNumber').value,
           cardName: document.getElementById('cardName').value,
           cardExpiration: document.getElementById('cardExpiration').value,
           cvv: document.getElementById('cvv').value,
           ownerName: document.getElementById('ownerName').value,
           ownerStreet: document.getElementById('ownerStreet').value,
           ownerCity: document.getElementById('ownerCity').value,
           ownerState: document.getElementById('ownerState').value,
           ownerZip: document.getElementById('ownerZip').value,
           ownerCountry: document.getElementById('ownerCountry').value,
           total: document.getElementById('lblTotal').value.substr(1),
           action: "verify"
           }, function(xml) {
           	respMessage = "";
           	errorMsg = "";
           	orderId = "";
           	clientId = "";
           	status = "";
           	refNumber="";
           	try {
               fields = xml.getElementsByTagName("FIELD");
               for (i=0; i<fields.length; i++) {
               	   if(fields[i].attributes) {
                       if(fields[i].attributes[0].value=="auth_response") {
                           respMessage = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="status") {
                           status = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="order_id") {
                           orderId = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="reference_number") {
                           refNumber = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="error") {
                           errorMsg = fields[i].childNodes[0].data;
                       }
               	   }
               }
               if(respMessage == "0") {
                   respMessage = errorMsg;
               }
               orderIdGateway = orderId;
               $.post("check_card.php", {
                   action: "save_response",
                   order_id: 0,
                   referenceNumber: refNumber,
                   orderIdGateway: orderIdGateway,
                   status: status,
                   auth_response: respMessage
               });
               for (i=0; i<fields.length-1; i++) {
               	   if(fields[i].attributes) {
                       if(fields[i].attributes[0].value=="status") {
                           if(fields[i].childNodes[0].data == 0 || fields[i].childNodes[0].data == 2) {
                               $("#divResults").attr("innerHTML", respMessage + "<br/><input type='button' name='btnRetry' id='btnRetry' value='Retry' onclick=\" $('#divResults').hide(0); $('#CardInfo').show('normal'); $('#btnSubmit').slideDown('fast');  \" />");
                           } else {
                               saveOrder(respMessage, refNumber, orderIdGateway);
                           }
                       }
               	   }
               }
           }
           catch(e) {
               	$("#divResults").attr("innerHTML","Connection error, please  review all information and retry<br/><input type='button' name='btnRetry' id='btnRetry' value='Ok' class='btBkgndL' onclick=\" $('#divResults').hide(0); $('#CardInfo').show('normal'); $('#btnSubmit').slideDown('fast');  \" />");
           }
          }
           );
}
function showSizingInfo(){
    if(jQuery.browser.msie){
        $("div#divInfo").css("top", "30%");
        $("div#divInfo").css("left", "30%");
        $("div#divInfo").hide("slow");
    	$("div#divInfo").show("normal");
    }else{
    	$("div#divInfo").css("top", getElementPosition("linkSizeChart").top +60  + "px");
    	//$("div#divInfo").css("top", "30%");
    	$("div#divInfo").css("left", getElementPosition("linkSizeChart").right +68 + "px");
    	//$("div#divInfo").css("left", "30%");
    	$("div#divInfo").hide("slow");
    	$("div#divInfo").show("normal");
    }
}
function hideSizingInfo(){
	$("div#divInfo").hide("normal");
}
function showFaqInfo(){
	$("div#divInfo").hide("slow");
	$("div#divSizeFaq").show("normal");
}
function hideFaqInfo(){
	$("div#divSizeFaq").hide("slow");
}
function zoomIn(id)
{
	$("#" + id).animate({
        width:550,
        height:550
    }, 300);
    $("#" + id).css("position", "absolute");
}
function zoomOut(id, zoomValue)
{
    $("#" + id).animate({
        width:zoomValue,
        height: zoomValue
    }, 300);
    $("#" + id).css("position", "relative");
}
function saveNewShipping()
{
	$.post("do_client.php", {
		action: "newShip",
		txtSNAddress: $("#txtSNAddressA").val(),
		txtSNAddressB: $("#txtSNAddressB").val(),
		txtSNFirstName: $("#txtSNFirstName").val(),
		txtSNLastName: $("#txtSNLastName").val(),
		txtSNCity: $("#txtSNCity").val(),
		txtSNState: $("#txtSNState").val(),
		txtSNZip: $("#txtSNZip").val(),
		idClient: idClient
	}, function(html) {
		refreshSelect(html);
	});
}
function refreshSelect(selected)
{
	$.post("do_client.php", {
		idClient: idClient,
		selected: selected,
		action: "refShipList"
	}, function(xml) {
		var obj = document.getElementById('selSAddress');
		while (document.getElementById('selSAddress').options.length > 0) {
			obj.removeChild(obj.firstChild);
		}
		var data = xml.firstChild;
		var selected = data.attributes[0].value;
		for (i=0; i < data.childNodes.length; i++) {
		    text = data.childNodes[i].childNodes[0].data;
			value = data.childNodes[i].attributes[0].value;
			obj.options[i] = new Option(text, value);
			if (selected == value) {
				obj.options[i].selected = true;
			}
	    }
	    refreshAllShipFields(obj.value);
		$('#addShippingInfo').hide(0);
		$('#shippingInfo').slideDown('fast');
	});
}
function refreshAllShipFields(id)
{
	$.post("do_client.php", {
		action: "refShipData",
		shipId: id
	}, function(xml) {
		var data = xml.firstChild;
		$("#txtSAddress").attr("value", data.childNodes[0].childNodes[0].data);
		$("#txtSFirstName").attr("value", data.childNodes[1].childNodes[0].data);
		$("#txtSLastName").attr("value", data.childNodes[2].childNodes[0].data);
		$("#txtSCity").attr("value", data.childNodes[3].childNodes[0].data);
		$("#txtSState").attr("value", data.childNodes[4].childNodes[0].data);
		$("#txtSZip").attr("value", data.childNodes[5].childNodes[0].data);
		$("#lblSVAddressA").attr("innerHTML", data.childNodes[0].childNodes[0].data);
		$("#lblSVFirstName").attr("innerHTML", data.childNodes[1].childNodes[0].data);
		$("#lblSVLastName").attr("innerHTML", data.childNodes[2].childNodes[0].data);
		$("#lblSVCity").attr("innerHTML", data.childNodes[3].childNodes[0].data);
		$("#lblSVState").attr("innerHTML", data.childNodes[4].childNodes[0].data);
		$("#lblSVZip").attr("innerHTML", data.childNodes[5].childNodes[0].data);
		$("#lblSFirstName").attr("innerHTML", data.childNodes[1].childNodes[0].data);
		$("#lblSLastName").attr("innerHTML", data.childNodes[2].childNodes[0].data);
		$("#lblSCity").attr("innerHTML", data.childNodes[3].childNodes[0].data);
		$("#lblSState").attr("innerHTML", data.childNodes[4].childNodes[0].data);
		$("#lblSZip").attr("innerHTML", data.childNodes[5].childNodes[0].data);
	});
}
function openNewShip()
{
	$("#btnSaveShip").css("display", "");
	$("#btnCancelAddShip").css("display", "");
	$("#txtSNAddress").attr("value", "");
	$("#txtSNAddressB").attr("value", "");
	$("#txtSNFirstName").attr("value", "");
	$("#txtSNLastName").attr("value", "");
	$("#txtSNCity").attr("value", "");
	$("#txtSNState").attr("value", "");
	$("#txtSNZip").attr("value", "");
	$('#shippingInfo').hide(0);
	$('#addShippingInfo').slideDown('fast');
}
function openEditShip()
{
	$('#shippingInfo').hide(0);
	$('#shippingInfoEd').slideDown('fast');
}
function deleteShipInfo(id)
{
	if(document.getElementById('selSAddress').options.length > 0) {
	    $.post("do_client.php", {
		    action: "deleteShip",
		    shipId: id
	    }, function(html) {
		    alert(html);
		    refreshSelect(0);
	    });
	} else {
		alert("Must be at least 1 selected item");
	}
}
function saveOrder(respMessage, refNumber, orderIdGateway)
{
	var gift;
	if($("#chkGift").attr("checked")) {
		gift = '1';
	} else {
		gift='0';
	}
	$.post("do_order.php", {
		action: "finish_transaction",
		txtShipping: $("#txtShipping").val(),
		txtDiscount: $("#txtDiscount").val(),
		shippingType: $("#selShipp").val(),
		txtSubtotal: $("#txtSubtotal").val(),
		txtCouponName: $("#txtCouponName").val(),
		txtShippingInfoId: $("#selSAddress").val(),
		referenceNumber: refNumber,
		orderIdGateway: orderIdGateway,
		chkGift: gift,
		txtGiftMessage: $("#txtGiftMessage").val()
	}, function(html) {
		 //$("#divResults").removeClass("divResults");
         //$("#divResults").attr("innerHTML",html);
         complete_order();
	});
}
function showFPass()
{
	document.getElementById('forgotPass').style.top = eval(getElementPosition('aFPass').top-100) + "px";
	document.getElementById('forgotPass').style.left = eval(getElementPosition('aFPass').left - 40) + "px";
	$("#forgotPass").slideDown("fast");
}
function requestPass(email)
{
	if($('#txtFEmail').val().length>0)
	{
	    $('#divForm').hide(0);
	    $('#divResults').slideDown("fast");
	    $.post("send_pass.php", {
	    	email: email
	    }, function(html) {
		    $('#divResults').attr("innerHTML", html);
		    setTimeout("$('#divResults').hide(0); $('#divForm').slideDown('fast'); $('#forgotPass').slideUp('normal')", 3000);
	    });
	} else {
		alert("Please type an email address");
	}
}
function prepareToSearch()
{
	searchtxt=$('#txtSearch').val();
	if(inIndex=='YES') {
	    loadPage()
	    return false;
	} else {
		window.location.href="index.php?srctxt=" + $('#txtSearch').val();
		return false;
	}
}
function selectMainType(linkId,mainTypeId)
{
	document.getElementById(mainTypeSel).className='lnkTypes';
	mainTypeSel = "lnkmt" + linkId;
	document.getElementById("lnkmt" + linkId).className='lnkTypesActive';
	$.post("load_tshirt.php", {
	    action: "loadByType",
	    mainTypeId: mainTypeId
	}, function(html) {
		$("#shirts").attr("innerHTML", "");
		$("#shirts").attr("innerHTML", html);
		$("#shirts").jCarouselLite({
             btnNext: ".next",
             btnPrev: ".prev",
             circular: false
         });
         $("#shirtImages").lavaLamp({
                fx: "backout",
                speed: 200,
                click: function(event, menuItem) {
                    return false;
                }
		});
	});
}
function toggleInfo(divId)
{
	if(infoToggled<=0) {
		$('#'+divId).slideDown('fast');
		infoToggled=1;
	} else {
		$('#'+divId).slideUp('normal');
		infoToggled=0;
	}
}
function saveShip()
{
	$.post("do_client.php", {
	id: $('#selSAddress').attr('value'),
	txtSAddress: $('#txtSAddress').val(),
	txtSAddressB: $('#txtSAddressB').val(),
	txtSFirstName: $('#txtSFirstName').val(),
	txtSLastName: $('#txtSLastName').val(),
	txtSCity: $('#txtSCity').val(),
	txtSState: $('#txtSState').val(),
	txtSZip: $('#txtSZip').val(),
	action: 'updateShipping'
	}, function(html) {
		refreshShFields()
	});
}
function refreshShFields()
{
	document.getElementById('selSAddress').options[document.getElementById('selSAddress').selectedIndex].text = $('#txtSAddress').val();
	$('#lblSAddress').attr("innerHTML",$('#txtSAddress').val());
	$('#lblSFirstName').attr("innerHTML",$('#txtSFirstName').val());
	$('#lblSLastName').attr("innerHTML",$('#txtSLastName').val());
	$('#lblSCity').attr("innerHTML",$('#txtSCity').val());
	$('#lblSState').attr("innerHTML", $('#txtSState').val());
	$('#lblSZip').attr("innerHTML",$('#txtSZip').val());
	$('#shippingInfoEd').hide(0);
	$('#shippingInfo').slideDown('fast');
}
function refreshProfileShipFields(id)
{
	$.post("do_client.php", {
		action: "refShipData",
		shipId: id
	}, function(xml) {
		var data = xml.firstChild;
		$("#lblSFirstName").attr("innerHTML", data.childNodes[1].childNodes[0].data);
		$("#lblSLastName").attr("innerHTML", data.childNodes[2].childNodes[0].data);
		$("#lblSCity").attr("innerHTML", data.childNodes[3].childNodes[0].data);
		$("#lblSState").attr("innerHTML", data.childNodes[4].childNodes[0].data);
		$("#lblSZip").attr("innerHTML", data.childNodes[5].childNodes[0].data);
		$("#txtSAddress").val(data.childNodes[0].childNodes[0].data)
		$("#txtSFirstName").val(data.childNodes[1].childNodes[0].data);
		$("#txtSLastName").val(data.childNodes[2].childNodes[0].data);
		$("#txtSCity").val(data.childNodes[3].childNodes[0].data);
		$("#txtSState").val(data.childNodes[4].childNodes[0].data);
		$("#txtSZip").val(data.childNodes[5].childNodes[0].data);
		$("#lblSVAddressA").attr("innerHTML", data.childNodes[0].childNodes[0].data);
		$("#lblSVFirstName").attr("innerHTML", data.childNodes[1].childNodes[0].data);
		$("#lblSVLastName").attr("innerHTML", data.childNodes[2].childNodes[0].data);
		$("#lblSVCity").attr("innerHTML", data.childNodes[3].childNodes[0].data);
		$("#lblSVState").attr("innerHTML", data.childNodes[4].childNodes[0].data);
		$("#lblSVZip").attr("innerHTML", data.childNodes[5].childNodes[0].data);
	});
}
function saveClientInOrder()
{
	if($("#claction").val() == "saveClient") {
	var error="";
             if(document.getElementById("txtFirstName").value == "") {
                 error += "- First name \n";
             }
             if(document.getElementById("txtLastName").value == "") {
                 error += "- Last name \n";
             }
             if(document.getElementById("txtEmail").value == "") {
                 error += "- Email Address \n";
             }
             if(document.getElementById('txtEmail').value!=''){
                 error += checkEmail(document.getElementById('txtEmail').value);
             }
             if(document.getElementById('txtConfirmEmail')) {
                 if (document.getElementById('txtConfirmEmail').value!="" && document.getElementById('txtConfirmEmail').value != document.getElementById('txtEmail').value) {
             	     error += "- Email and confirmation must have the same values \n";
                 }
             }
             if(document.getElementById('pwdConfirm')) {
                 if (document.getElementById('pwdPassword').value!="" && document.getElementById('pwdConfirm').value != document.getElementById('pwdPassword').value) {
             	     error += "- Password and confirmation must have the same values \n";
                 }
             }
             if(document.getElementById("txtAddressA").value == "") {
                 error += "- Address \n";
             }
             if(document.getElementById("txtSNFirstName").value == "") {
                 error += "- Shipping First Name \n";
             }
             if(document.getElementById("txtSNLastName").value == "") {
                 error += "- Shipping Last Name \n";
             }
             if(document.getElementById("txtSNAddressA")) {
                 if(document.getElementById("txtSNAddressA").value == "") {
                     error += "- Shipping Address \n";
                 }
             } else if(document.getElementById("txtSNAddress")) {
                 if(document.getElementById("txtSNAddress").value=="") {
                     error += "- Shipping Address \n";
                 }
             }
             if(error=="") {
             	     $.post("do_client.php", {
		             action: $("#claction").val(),
		             txtFirstName: $('#txtFirstName').val(),
		             txtLastName: $('#txtLastName').val(),
     		         txtAddressA: $('#txtAddressA').val(),
		             txtAddressB: $('#txtAddressB').val(),
		             txtEmail: $('#txtEmail').val(),
		             txtCity: $('#txtCity').val(),
		             txtState: $('#txtState').val(),
		             txtZip: $('#txtZip').val(),
		             pwdPassword: $('#pwdPassword').val(),
		             txtPhone1: $('#txtPhone1').val()
	                     }, function(html) {
	                     	 idClient=html;
		                     refreshClientFieldsInOrder();
		                     $('#action').val("updateClient");
                             saveNewShipping();
	                     });
	                 } else {
	                 	alert("Please review: \n\n" + error);
                        return false;
	                 }
	} else {
		var error="";
             if(document.getElementById("txtFirstName").value == "") {
                 error += "- First name \n";
             }
             if(document.getElementById("txtLastName").value == "") {
                 error += "- Last name \n";
             }
             if(document.getElementById("txtEmail").value == "") {
                 error += "- Email Address \n";
             }
             if(document.getElementById('txtConfirmEmail')) {
                 if (document.getElementById('txtConfirmEmail').value!="" && document.getElementById('txtConfirmEmail').value != document.getElementById('txtEmail').value) {
             	     error += "- Email and confirmation must have the same values";
                 }
             }
             if(document.getElementById("txtAddressA").value == "") {
                 error += "- Address \n";
             }
             if(document.getElementById("txtSFirstName").value == "") {
                 error += "- Shipping First Name \n";
             }
             if(document.getElementById("txtSLastName").value == "") {
                 error += "- Shipping Last Name \n";
             }
             if(document.getElementById("txtSAddressA")) {
                 if(document.getElementById("txtSAddressA").value == "") {
                     error += "- Shipping Address \n";
                 }
             } else if(document.getElementById("txtSAddress")) {
                 if(document.getElementById("txtSAddress").value=="") {
                     error += "- Shipping Address \n";
                 }
             }
             if(error=="") {
	                 	$.post("do_client.php", {
		                action: $("#claction").val(),
		                idClient: idClient,
		                txtFirstName: $('#txtFirstName').val(),
		                txtLastName: $('#txtLastName').val(),
		                txtAddressA: $('#txtAddressA').val(),
		                txtAddressB: $('#txtAddressB').val(),
		                txtEmail: $('#txtEmail').val(),
		                txtCity: $('#txtCity').val(),
		                txtState: $('#txtState').val(),
		                txtZip: $('#txtZip').val(),
		                txtPhone1: $('#txtPhone1').val()
	               }, function() {
		                refreshClientFieldsInOrder();
	               });
	           } else {
                     alert("Please review: \n\n" + error);
                     return false;
               }
	           return true;
            }
}
function refreshClientFieldsInOrder()
{
	$("#ownerName").val($("#txtFirstName").val() + " " + $("#txtLastName").val());
	$("#ownerStreet").val($("#txtAddressA").val());
	$("#ownerCity").val($("#txtCity").val());
	$("#ownerState").val($("#txtState").val());
	$("#ownerZip").val($("#txtZip").val());
    $("#lblFirstName").attr("innerHTML",$("#txtFirstName").val());
    $("#lblLastName").attr("innerHTML",$("#txtLastName").val());
    $("#lblAddressA").attr("innerHTML",$("#txtAddressA").val());
    $("#lblAddressB").attr("innerHTML",$("#txtAddressB").val());
    $("#lblEmail").attr("innerHTML",$("#txtEmail").val());
    $("#lblCity").attr("innerHTML",$("#txtCity").val());
    $("#lblState").attr("innerHTML",$("#txtState").val());
    $("#lblZip").attr("innerHTML",$("#txtZip").val());
    $("#lblPhone1").attr("innerHTML",$("#txtPhone1").val());
    $("#ClInfo").slideUp("normal");
    $("#CardInfo").slideDown("fast");
}
function saveClient()
{
	$.post("do_client.php", {
		action: "saveClient",
		idClient: idClient,
		txtFirstName: $('#txtFirstName').val(),
		txtLastName: $('#txtLastName').val(),
		txtEmail: $('#txtEmail').val(),
		txtAddress: $('#txtAddress').val(),
		txtAddress2: $('#txtAddress2').val(),
		txtCity: $('#txtCity').val(),
		txtState: $('#txtState').val(),
		txtZip: $('#txtZip').val(),
		txtPhone1: $('#txtPhone1').val()
	}, function() {
		refreshClientFields();
	});
}
function refreshClientFields()
{
	$('#lblFirstName').attr('innerHTML', $('#txtFirstName').val());
	$('#lblLastName').attr('innerHTML', $('#txtLastName').val());
	$('#lblAddressA').attr('innerHTML', $('#txtAddress').val());
	$('#lblAddressB').attr('innerHTML', $('#txtAddress2').val());
	$('#lblCity').attr('innerHTML', $('#txtCity').val());
	$('#lblState').attr('innerHTML', $('#txtState').val());
	$('#lblZip').attr('innerHTML', $('#txtZip').val());
	$('#lblPhone1').attr('innerHTML', $('#txtPhone1').val());
	$('#clientInfoEd').hide(0);
	$('#clientInfo').slideDown('fast');
}
function sameInfo()
{
     if(document.getElementById("chkSame").checked == true) {
         document.getElementById("txtSNFirstName").value = document.getElementById("txtFirstName").value;
         document.getElementById("txtSNLastName").value = document.getElementById("txtLastName").value;
         document.getElementById("txtSNAddressA").value = document.getElementById("txtAddressA").value;
         document.getElementById("txtSNAddressB").value = document.getElementById("txtAddressB").value;
         document.getElementById("txtSNCity").value = document.getElementById("txtCity").value;
         document.getElementById("txtSNState").value = document.getElementById("txtState").value;
         document.getElementById("txtSNZip").value = document.getElementById("txtZip").value;
    } else {
         document.getElementById("txtSNFirstName").value = "";
         document.getElementById("txtSNLastName").value = "";
         document.getElementById("txtSNAddressA").value = "";
         document.getElementById("txtSNAddressB").value = "";
         document.getElementById("txtSNCity").value = "";
         document.getElementById("txtSNState").value = "";
         document.getElementById("txtSNZip").value = "";
    }
}
function showSpecialBox()
{
	if(document.getElementById("chkSpecial").checked) {
		$("#divSpecialWeekly").slideDown("fast");
	} else {
		$("#divSpecialWeekly").slideUp("normal");
	}
}
function showConfirm(object, div)
{
	if (object.checked) {
		$("#" + div).slideDown("fast");
	} else {
		$("#" + div).slideUp("normal");
	}
}
function goToCard()
{
	$.post("do_client.php", {
		action: "updateClient",
		idClient: idClient,
		txtFirstName: $('#txtFirstName').val(),
		txtLastName: $('#txtLastName').val(),
		txtAddress: $('#txtAddress').val(),
		txtAddress2: $('#txtAddress2').val(),
		txtCity: $('#txtCity').val(),
		txtState: $('#txtState').val(),
		txtZip: $('#txtZip').val(),
		txtPhone1: $('#txtPhone1').val(),
		txtSAddres: $('#txtSAddres').val(),
		txtSFirstName: $('#txtFirsName').val(),
		txtSLastName: $('#txtSLastName').val(),
		txtSCity: $('#txtCity').val(),
		txtSState: $('#txtSState').val(),
		txtSZip: $('#txtSZip').val()
	}, function() {
		refreshClientFields();
	});
}
function processCancelOrder(orderId, action)
{
	$("#divResults").attr("innerHTML", "Sending operation. Please wait...<img src='../images/loading.gif' width='40px' height='40px' border='0' alt='Loading...' />")
	$("#divForm").hide(0);
	$("#divResults").show("slow");
	$.post("card_transactions.php",{
           orderId: orderId,
           action: action
           }, function(xml) {
           	respMessage = "";
           	errorMsg="";
           	orderId = "";
           	status = "";
           	refNumber="";
           	try {
               fields = xml.getElementsByTagName("FIELD");
               for (i=0; i<fields.length; i++) {
               	   if(fields[i].attributes) {
                       if(fields[i].attributes[0].value=="response1") {
                           respMessage = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="status1") {
                           status = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="reference_number1") {
                           refNumber = fields[i].childNodes[0].data;
                       }
                       if(fields[i].attributes[0].value=="error1") {
                           errorMsg = fields[i].childNodes[0].data;
                       }
                       //alert(fields[i].attributes[0].value + "=" + fields[i].childNodes[0].data);
               	   }
               }
               if(respMessage=="" || respMessage==0) {
                   respMessage = errorMsg;
               }
               $.post("card_transactions.php", {
                   action: "save_response",
                   referenceNumber: refNumber,
                   status: status,
                   auth_response: respMessage
               });
               for (i=0; i<fields.length-1; i++) {
               	   if(fields[i].attributes) {
                       if(fields[i].attributes[0].value=="status1") {
                           if(fields[i].childNodes[0].data == 2) {
                               $("#divResults").attr("innerHTML", respMessage + "<br/><input type='button' name='btnRetry' id='btnRetry' value='Retry' onclick=\" $('#divResults').hide(0); $('#divForm').show('normal');  \" />");
                           }else if(fields[i].childNodes[0].data == 1) {
                               doOrder(orderId, respMessage, refNumber, action);
                           }  else {
                           	   $("#divResults").attr("innerHTML", errorMsg + "<br/><input type='button' name='btnRetry' id='btnRetry' value='Retry' onclick=\" $('#divResults').hide(0); $('#divForm').show('normal');  \" />");
                           }
                       }
               	   }
               }
           }
           catch(e) {
               	$("#divResults").attr("innerHTML","Connection error, please  review all information and retry<br/><input type='button' name='btnRetry' id='btnRetry' value='Ok' class='btBkgndL' onclick=\" $('#divResults').hide(0); $('#divForm').show('normal');  \" />");
           }
       }
   );
}
function doOrder(orderId, respMessage, refNumber, action) {
	$.post("do_order.php", {
	    action: action,
	    orderId: orderId,
	    respMessage: respMessage,
	    refNumber: refNumber
	}, function(html) {
	           $("#divResults").attr("innerHTML",html);
	});
}

function complete_order (){
    location.href = "complete_order.php";
}

function generateCupon()
{
	$.post("do_cupon.php", {
		action: "generate"
	}, function(html) {
		$("#txtCode").val(html);
	});
}
function changeShipValue(option)
{
	var shipvalue = 0;
	if(option == 1) {
		shipvalue = '4.99';
	}
	if(option == 2) {
		shipvalue = '9.99';
		if($("#txtCouponName").val() == "free shipping"){
            $("#txtDiscount").val("$0");
            $("#txtCouponName").val("");
            $("#chkCupon").click();
        }
        $("#txtDiscount").highlightFade('red');
	}
	if(option == 3) {
		shipvalue='14.99';
		if($("#txtCouponName").val() == "free shipping"){
            $("#txtDiscount").val("$0");
            $("#txtCouponName").val("");
            $("#chkCupon").click();
        }
        $("#txtDiscount").highlightFade('red');
	}

	if(option == 4) {
		shipvalue='14.99';
		if($("#txtCouponName").val() == "free shipping"){
            $("#txtDiscount").val("$0");
            $("#txtCouponName").val("");
            $("#chkCupon").click();
        }
        $("#txtDiscount").highlightFade('red');
	}

	if(option == 5) {
		shipvalue='19.99';
		if($("#txtCouponName").val() == "free shipping"){
            $("#txtDiscount").val("$0");
            $("#txtCouponName").val("");
            $("#chkCupon").click();
        }
        $("#txtDiscount").highlightFade('red');
	}

	$("#txtShipping").val("$" + shipvalue);
	if(parseFloat($("#txtSubtotal").val().substr(1)) > 50 && option == 1) {
        $("#txtShipping").val("$0");
    }
	$("#txtShipping").highlightFade('red');
    total = (parseFloat($("#txtSubtotal").val().substr(1)) + parseFloat($("#txtShipping").val().substr(1)));
    total = total - $("#txtDiscount").val().substr(1);
    $("#lblTotal").attr("value", "$" + total.toFixed(2));
}
function showCupon(object)
{
	if(object.checked) {
		$('#divCupon').slideDown('fast');
	} else {
		$('#divCupon').slideUp('normal');;
	}
}
function applyCupon(number)
{
	$.post("check_card.php",
	{
	    action: "check_cupon",
	    code: number
	}, function(xml) {
		var discValue = parseFloat(xml.firstChild.childNodes[0].childNodes[0].data);
		if(discValue >0) {
				$("#txtDiscount").highlightFade('red');
		}
		var value1 = xml.firstChild.attributes[0].value;
		$("#txtCouponName").val(value1);
		if(value1 != "free shipping"){
		    var discValue = (parseFloat($("#txtSubtotal").val().substr(1)) * discValue)/100;
		}
		if(parseFloat($("#txtShipping").val().substr(1)) > 9){
		    var discValue = 0;
            $("#txtCouponName").val("");
            $("#chkCupon").click();
		}
		$("#txtDiscount").val("$" + discValue.toFixed(2));
	    total = eval(parseFloat($("#txtSubtotal").val().substr(1)) + parseFloat($("#txtShipping").val().substr(1)));
	    total = eval(total - $("#txtDiscount").val().substr(1));
        $("#lblTotal").attr("value", "$" + total.toFixed(2));
	});
}
function verifyRegEmail(email)
{
	$.post("do_register.php",
	{
		action: "verifyIfExists",
		txtEmail: email
	}, function(html) {
		if(html == "1") {
			$("#divRegLogin").slideDown("normal");
			$("#btnSubmit").slideUp("normal");
		} else if(html == "2") {
			$("#divRegActivate").slideDown("normal");
			$("#btnSubmit").slideUp("normal");
		}
	});
}
function activateAccount(email)
{
	$.post("do_register.php", {
	    action: "activateAccount",
	    txtEmail: email
	}, function(html) {
		$("#divRegActivate").attr("innerHTML", "Your account has been activated.<br /><br /> Please review your email and then. <br> <input type='button' value='Login' class='btBkgndR' onclick=\"window.location.href='register_login.php';\"");
	});
}
function checkEmail (strng, fieldname) {
	if (fieldname==undefined) {
		fieldname = "Email";
	}
	var error="";
    	var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) {
	       error = "- " + fieldname + " is not a valid email address.\n";
    	}
	else {
	//test email for illegal characters
       		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
         	if (strng.match(illegalChars)) {
			error = "- " + fieldname + " contains illegal characters.\n";
		}
    	}
	return error;
}
function reorder(id)
{
	$(".orderText").each(function() {
		if(($(this).val()== $("#"+id).val()) && ($(this).attr("id") != id)) {
			$(this).val("");
		}
	});
	orderValue = $("#" + id).val();
	$.post("do_design.php", {
		id:id,
		showOrder: orderValue,
		action: "reorder"
	}, function(xml) {

	});
}
function setDefaultCat(id)
{
	$.post("do_categories.php" , {
	    action: "set_as_defaul",
	    id: id
	}, function() {

	});
}