
function OpenCustomizationWindow(sourceHTML) {
    OpenBrowserWindow("CustomizationSamples", "height=500,width=500,toolbar=no,scrollbars=no,menubar=no", sourceHTML);
}

function OpenBrowserWindow(windowName, windowFeatures, sourceHTML) {

    OpenWindow = window.open("", windowName, windowFeatures);
    OpenWindow.document.write(sourceHTML)
    OpenWindow.document.close()
    self.name = "main"
}


var historyImage;

function OnLoadSetup()
{	
    historyImage = GetElementByServerControlId("ucProductClassSummaryImage_imgProduct").src;
    DisplayPanel('ucProductClassSummary_pnlDescription', 'TabTableImg1', 'images/PCTabTableDesc');
    ResizeTable();
}

function ResizeTable()
{
	if(document.getElementById("imgProductTbl").offsetHeight>250)
	{
        ChangeStyleById("imgProductTbl", "height", document.getElementById("imgProductTbl").offsetHeight);
    }
}


function ResizeDiv() {
    if (document.getElementById("pnlProductClassImage").offsetHeight > 250) {
        ChangeStyleById("pnlProductClassImage", "height", document.getElementById("pnlProductClassImage").offsetHeight);
    }
}

function DisplayPanelReview()
{
    DisplayPanel('ucProductClassReviewSummary_pnlReviews', 'TabTableImg2', 'images/PCTabTableReviews');
}

//Display alternate views of Description and Reviews panels
function DisplayPanel(panelname, TabTableImgIdInput, TabTableImgSrcInput)
{
    var showpanel = panelname;
    //get browser type
    var nav = window.navigator;
    var browserType = nav.appName.toUpperCase();
    var browserVersion = nav.appVersion;
    var curr_fld;

	if (browserType.substring(0,3)=="MIC") 			
	{       
        browserType = "Microsoft";
    }
	if(browserType=="Microsoft")
	{
        GetElementInMicrosoft('ucProductClassSummary_pnlDescription').style.display = 'none';
        GetElementInMicrosoft('ucProductClassReviewSummary_pnlReviews').style.display = 'none';
        GetElementInMicrosoft('ucProductClassSizing_pnlSizing').style.display = 'none';
        GetElementInMicrosoft(showpanel).style.display = 'inline';
    }
	else
	{
        var list = new Array("ucProductClassSummary_pnlDescription", "ucProductClassReviewSummary_pnlReviews", "ucProductClassSizing_pnlSizing");

        ChangeStylesByServerControlIds(list, "display", "none");

        ChangeStyleByServerControlId(panelname, "display", "inline");
    }

    //SetTabTableImgSrc
    var TabTableImgId = TabTableImgIdInput;
    var TabTableImgSrc = TabTableImgSrcInput;

	if(TabTableColSpan == 2)
	{
        ChangeStyleById("TabTableImg1", "source", "images/PCTabTableDescVer1_Solid.gif");
        ChangeStyleById("TabTableImg2", "source", "images/PCTabTableReviewsVer1_Solid.gif");
        ChangeStyleById(TabTableImgId, "source", TabTableImgSrc + "Ver1_White.gif");

        ChangeStyleById("TabTableImg3", "display", "none");

        ChangeStyleById("TabTableImg1", "width", "125");
        ChangeStyleById("TabTableImg2", "width", "125");
    }
	else if(TabTableColSpan == 3)
	{
        ChangeStyleById("TabTableImg1", "source", "images/PCTabTableDescVer2_Solid.gif");
        ChangeStyleById("TabTableImg2", "source", "images/PCTabTableReviewsVer2_Solid.gif");
        ChangeStyleById("TabTableImg3", "source", "images/PCTabTableSizingVer2_Solid.gif");
        ChangeStyleById(TabTableImgId, "source", TabTableImgSrc + "Ver2_White.gif");

        ChangeStyleById("TabTableImg1", "width", "83");
        ChangeStyleById("TabTableImg2", "width", "83");
        ChangeStyleById("TabTableImg3", "width", "84");
    }
}

function CodePop(QS) 
{	
    //display AlternateViews window in popup
    var theQS = "";
    theQS = QS;
    window.open("AlternateViews.aspx?prodClassId=" + QS, "AlternateViews", "width=400,height=400", "toolbar=no", "location=no", "directories=no", "status=no", "menubar=no", "scrollbars=no", "screenX=0", "screenY=0", "top=0", "left=0");
    return false;
}

function PopUpToSeeAllColors(QS)
{
    var theQS = "";
    theQS = QS;
    window.open("SeeAllColors.aspx?ProductClassId=" + QS, "SeeAllColors", "width=450,height=500", "toolbar=no", "location=no", "directories=no", "status=no", "menubar=no", "scrollbars=no", "screenX=0", "screenY=0", "top=0", "left=0");
    return false;
}

function MM_swapImgRestore() 
{	
    //v3.0
    //this function is executed on mouseout from OtherAttributesUserControl images
    //it restores the image corresponding to the product selected in the Ordering Control
    //it follows execution of MM_swapImage
    var i;
    var x;
    var a = document.MM_sr;

	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
	{
        x.src = x.oSrc;
    }

    ChangeStyleByServerControlId("ucProductClassSummaryImage_imgProduct", "source", historyImage);
}

function MM_preloadImages() 
{ 
    //v3.0
    var d = document;
	if(d.images)
	{ 
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
		{
			if (a[i].indexOf("#")!=0)
			{ 
                d.MM_p[j] = new Image; d.MM_p[j++].src = a[i];
            }
        }
    }
}

function MM_findObj(n, d)
{ 
    //v4.01
    var p, i, x;
    if (!d) d = document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() 
{ 
    //v3.0
    //changes the main image (imgProduct) depending on the Alternate View selected
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
	for(i=0;i<(a.length-2);i+=3)
	{
		if ((x=MM_findObj(a[i]))!=null)
		{
            document.MM_sr[j++] = x;
			if(!x.oSrc) 
			{
                x.oSrc = x.src;
            }
            var newsource = a[i + 2];
        }
    }
    newsource = newsource.replace("thumbnails/", "");
    newsource = newsource.replace("_alt", "");
    newsource = newsource.replace("thumb_", "");

    ChangeStyleByServerControlId("ucProductClassSummaryImage_imgProduct", "source", newsource);

    ResizeTable();
}

function ChangeBigImageSource(smallImage,imagesrc)
{
    var newSource = imagesrc;

    newSource = newSource.replace("thumbnails/", "");
    newSource = newSource.replace("_alt", "");
    newSource = newSource.replace("thumb_", "");

    ChangeStyleById("imgProduct", "source", newSource);
    ChangeStyleById("lblDescription", "innerHTML", smallImage.alt);

    ResizeTable();
}
function GetFileName(filepath) {

    var lastDelimiterindex = filepath.lastIndexOf('/');
    var filename = filepath.substring(lastDelimiterindex + 1);
    return filename;

}

function CheckForNoImage() {

    var imageName;
    var countRealImage = 0;
    for (var i = 0; i < attribArray.length; i++) {
        imageName = GetFileName(attribArray[i][3]);
        if (imageName.indexOf("noimage.jpg") == -1) {
            countRealImage++;
            
        }
        else {
            countRealImage--;
        }
        
    }
    return countRealImage;
}

function SynchronizeDisplayWithSelection(ddlAttribute1ID, ddlAttribute2ID, ddlAttribute3ID, swapImage) {
    
    clearLastZoom();
    $('#pnlImagesRegion a:first').attr("href", 'noimage');

    var ddlAttribute1 = document.getElementById(ddlAttribute1ID);
    var ddlAttribute2 = document.getElementById(ddlAttribute2ID);
    var ddlAttribute3 = document.getElementById(ddlAttribute3ID);
    var checkfornoimage = CheckForNoImage();
    var numberOfAttributes = GetNumberOfAttributes(ddlAttribute1, ddlAttribute2, ddlAttribute3);

    var attributeRow;

    switch (numberOfAttributes) {
        case 1:
            attributeRow = GetAttributeRowForOne(ddlAttribute1);
            break;
        case 2:
            attributeRow = GetAttributeRowForTwo(ddlAttribute1, ddlAttribute2);
            break;
        case 3:
            attributeRow = GetAttributeRowForThree(ddlAttribute1, ddlAttribute2, ddlAttribute3);
            break;
    }

    if (attributeRow != null) {
        var imgProductClassImage = document.getElementById(imgProductClassImageID);
        var lblPrice = document.getElementById(lblPriceID);

        if (lblPrice != null)
            lblPrice.innerHTML = attributeRow[4];
        
        var imagePath = imageServerUrl + attributeRow[3];
        imagePath = imagePath.replace(/images/i, "");
        
        if (swapImage && imgProductClassImage != null) {
            if (checkfornoimage >= 0) {
                imgProductClassImage.src = imagePath;
                setHighResolutionImage(imagePath);
            }
            else {
                imgProductClassImage.src = imgwebphoto;
                setHighResolutionImage(imgwebphoto);
            }
        
        }
        //        var lblBackOrder = document.getElementById(lblBackOrderID);        
        //        var lblDropShip = document.getElementById(lblDropShipID);
        //        var lblOnSale = document.getElementById(lblOnSaleID);
        //        
        //        if (lblBackOrder != null)
        //            lblBackOrder.innerHTML = attributeRow[7];     

        //        if (lblDropShip != null) {
        //            lblDropShip.innerHTML = attributeRow[6];
        //            if (attributeRow[5] == "True")
        //                lblDropShip.style.display = "inline";
        //            else
        //                lblDropShip.style.display = "none";
        //        }

        //        if (lblOnSale != null) {
        //            if (attributeRow[8] == "True")
        //                lblOnSale.style.display = "inline";
        //        }
        //        else
        //            lblOnSale.style.display = "none";


    }

    ResizeDiv();
}

function GetAttributeRowForOne(ddlAttribute1) {
    var option = ddlAttribute1.options[ddlAttribute1.selectedIndex];

    if (option != null && attribArray != null) {
        var attributeId = option.value;

        for (var i = 0; i < attribArray.length; i++) {
            var row = attribArray[i];
            var attribute1Column = row[0];
            if (attribute1Column == attributeId) {
                return row;
                break;
            }
        }
    }
}

function GetAttributeRowForTwo(ddlAttribute1, ddlAttribute2) {
    var option1 = ddlAttribute1.options[ddlAttribute1.selectedIndex];
    var option2 = ddlAttribute2.options[ddlAttribute2.selectedIndex];

    if (option1 != null && option2 != null && attribArray != null) {
        var attribute1Id = option1.value;
        var attribute2Id = option2.value;

        for (var i = 0; i < attribArray.length; i++) {
            var row = attribArray[i];
            var attribute1Column = row[0];
            var attribute2Column = row[1];
            
            if (attribute1Column == attribute1Id && attribute2Column == attribute2Id) {
                return row;
                break;
            }
        }
    }
}

function GetAttributeRowForThree(ddlAttribute1, ddlAttribute2, ddlAttribute3) {
    var option1 = ddlAttribute1.options[ddlAttribute1.selectedIndex];
    var option2 = ddlAttribute2.options[ddlAttribute2.selectedIndex];
    var option3 = ddlAttribute3.options[ddlAttribute3.selectedIndex];

    if (option1 != null && option2 != null && option3 != null && attribArray != null) {
        var attribute1Id = option1.value;
        var attribute2Id = option2.value;
        var attribute3Id = option3.value;

        for (var i = 0; i < attribArray.length; i++) {
            var row = attribArray[i];
            var attribute1Column = row[0];
            var attribute2Column = row[1];
            var attribute3Column = row[2];

            if (attribute1Column == attribute1Id && attribute2Column == attribute2Id && attribute3Column == attribute3Id) {
                return row;
                break;
            }
        }
    }
}

function GetNumberOfAttributes(ddlAttribute1, ddlAttribute2, ddlAttribute3) {

    var numberOfAttributes = 0;

    if (ddlAttribute1 != null && ddlAttribute2 != null && ddlAttribute3 != null) {
        numberOfAttributes = 3;
    } else if (ddlAttribute1 != null && ddlAttribute2 != null && ddlAttribute3 == null) {
        numberOfAttributes = 2;
    } else if (ddlAttribute1 != null && ddlAttribute2 == null && ddlAttribute3 == null) {
        numberOfAttributes = 1;
    }
    return numberOfAttributes;
}

function ShowImage()
{
    var ddlAttribute1;
    var ddlAttribute2;
    var ddlAttribute3;

    ddlAttribute1 = GetElementByServerControlId("ucOrderingControl_ddlAttribute1");
    ddlAttribute2 = GetElementByServerControlId("ucOrderingControl_ddlAttribute2");
    ddlAttribute3 = GetElementByServerControlId("ucOrderingControl_ddlAttribute3");

	if (!document.images)
			{
        return;
    }

    //get the image, and other settings
    var imgIndex1;
    var imgIndex2;
    var imgIndex3;
    var attribDesc = GetElementByServerControlId("ucProductClassSummaryImage_lblAttributeDesc");
    var itemNo = GetElementByServerControlId("ucProductClassSummaryImage_lblItemNo");
    var lblPrice;

    //display either productclass or specific product image  
    //  in upper left corner of page (ucProductClassSummaryImage)

	if( ddlAttribute2 == null && ddlAttribute3 == null )
	{	   
        //1 attribute
        imgIndex1 = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;

		for(var i = 0; i < attribArray.length; i++)
		{
			if(attribArray[i][0] == imgIndex1)
			{	
                ChangeProductInformation(i, 1);
                return;
            }
        }
    }
	else if( ddlAttribute2 != null && ddlAttribute3 == null )
	{			
        //2 attributes;
        imgIndex1 = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;
        imgIndex2 = ddlAttribute2.options[ddlAttribute2.selectedIndex].value;

		 for(var i = 0; i < attribArray.length; i++)
		{
			if(attribArray[i][0] == imgIndex1 && attribArray[i][1] == imgIndex2 )
			{
                ChangeProductInformation(i, 2);
                return;
            }
        }
    }
	else
	{	
        //3 attributes	
        imgIndex1 = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;
        imgIndex2 = ddlAttribute2.options[ddlAttribute2.selectedIndex].value;
        imgIndex3 = ddlAttribute3.options[ddlAttribute3.selectedIndex].value;
		 for(var i = 0; i < attribArray.length; i++)
		{
			if(attribArray[i][0] == imgIndex1 && attribArray[i][1]==imgIndex2 && attribArray[i][2] == imgIndex3)
			{
                ChangeProductInformation(i, 3);
                return;
            }
        }
    }
}

function UpdateDaysSupply(productid, daysSupply, txtBoxName)
{
    ChangeStyleById(txtBoxName, "innerHTML", daysSupply);
    ChangeProductMessage(productid);
}

function ChangeProductMessage(productid)
{
	if(typeof productArray != 'undefined')
	{
		for(var i = 0 ; i < productArray.length; i++)
		{

			if(productArray[i][0] == productid)
			{
				if( productArray[i][1]  == "True" )
				{
                    ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "display", "inline");
                    ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "innerHTML", productArray[i][2]);
                }
				else
				{
                    ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "display", "none");
                }

                ChangeStyleByServerControlId("ucOrderingControl_lblBackOrder", "innerHTML", productArray[i][3]);

				if(productArray[i][5]  == "True")
				{
                    ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "inline");
                }
				else
				{
                    ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "none");
                }
            }
        }
    }
}

function ChangeProductInformation( x, numattributes )
{
    var ddlAttribute2 = GetElementByServerControlId("ucOrderingControl_ddlAttribute2");
    var ddlAttribute3 = GetElementByServerControlId("ucOrderingControl_ddlAttribute3");

	for(var i = 0; i < attribArray.length; i++)
	{
		if( numattributes==1 || (numattributes==2 && attribArray[x][1]==ddlAttribute2.options[ddlAttribute2.selectedIndex].value) || (numattributes==3 && attribArray[x][1]==ddlAttribute2.options[ddlAttribute2.selectedIndex].value && attribArray[x][2]==ddlAttribute3.options[ddlAttribute3.selectedIndex].value) )
			{
            ChangeStyleByServerControlId("ucOrderingControl_lblBackOrder", "innerHTML", attribArray[x][7]);

            ChangeStyleByServerControlId("ucOrderingControl_ucProductPrice_lblPrice", "innerHTML", attribArray[x][4]);

			if( attribArray[x][5]  == "True" )
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "display", "inline");
                ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "innerHTML", attribArray[x][6]);
            }
			else
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblDropShipMsg", "display", "none");
            }

			if(attribArray[x][8]  == "True")
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "inline");
            }
			else
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "none");
            }

            return;
        }
    }
}

function ChangeProductImage() 
{
    var ddlControl = GetElementByServerControlId("ucOrderingControl_ddlAttribute1");
    var imgUrl;

	if (!document.images)
	{
        return
    }

    //get the image, and other setting
    var imgIndex = ddlControl.options[ddlControl.selectedIndex].value

	for(var i = 0; i < attribArray.length; i++)
	{
		if(attribArray[i][0] == imgIndex)
		{
            imgUrl = attribArray[i][3];
        }
    }

	if(imgUrl != "/product/")
	{
        ChangeStyleByServerControlId("ucProductClassSummaryImage_imgProduct", "source", imgUrl);

        historyImage = imgUrl;
    }
	alert(imgUrl);
	if( GetElementByServerControlId("lblProductName").innerHTML == "Gift Certificates" )
	{
        SelectGiftCertType();
    }

    ResizeTable();
}


function SelectShipWithItem()
{
    var orderName = null;

    //get the selected value from the drop-down list
    var ddlOrderName = GetElementByServerControlId("ucOrderingControl_ddlOrderName");

    orderName = ddlOrderName.options[ddlOrderName.selectedIndex].value;

    //get the order id of the first order with the selected order name
    //the order id will be used later to set the active option in the orders list
    var orderId = null;

	for(var i = 0; i < orders.length; i++)
	{
		if(orders[i][1] == orderName)
		{
            orderId = orders[i][0];
            break;
        }
    }

    //get the ship with control
    var ddlOrders = GetElementByServerControlId("ucOrderingControl_ddlShipWith");

    //make the earliest order in the list with the same horse name the active order
	for(var i = 0; i < ddlOrders.options.length; i++)
	{
		if(ddlOrders.options[i].value == orderId)
		{
            //select the item in the drop-down list
            ddlOrders.selectedIndex = i;

            //select the "ship with" radio button
            SelectShipWith();

            break;
        }
    }
}

function openPriceChart(strProdID)
{
    url = "PharmaPrice.aspx?productid=" + strProdID;

    window.open(url, "PharmaPrice", "width=700,height=350,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,screenX=0,screenY=0,top=0,left=0");
}

function SetCurrentProductData()
{
    var ddlAttribute1 = GetElementByServerControlId("ucOrderingControl_ddlAttribute1");

    var productID = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;

    var feedingAmount = ddlAttribute1.options[ddlAttribute1.selectedIndex].text;

    //set the cups per feeding and price
	for(i = 0; i < attribArray.length; i++)
	{
		if(attribArray[i][0] == productID)
		{
            ChangeStyleByServerControlId("ucOrderingControl_ucProductPrice_lblPrice", "innerHTML", attribArray[i][1]);
            ChangeStyleByServerControlId("ucOrderingControl_lblCupsPerFeeding", "innerHTML", attribArray[i][2]);

			if(attribArray[i][8]  == "True")
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "inline");
            }
			else
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "none");
            }

            break;
        }
    }

    //update the equivalancy
	for(i = 0; i < equivArray.length; i++)
	{
        var controlId = "ucOrderingControl_lblEquiv_" + equivArray[i][0];

        ChangeStyleByServerControlId(controlId, "innerHTML", "(" + equivArray[i][1] + " cups, " + Math.round(equivArray[i][1] / feedingAmount) + " days)");
    }
}

function SetCurrentProductDataPortionPak()
{
    var ddlAttribute1 = GetElementByServerControlId("ucOrderingControl_ddlAttribute1");

    var productID = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;

    var feedingAmount = ddlAttribute1.options[ddlAttribute1.selectedIndex].text;

    //set the cups per feeding and price
	for(i = 0; i < attribArray.length; i++)
	{
		if(attribArray[i][0] == productID)
		{
            ChangeStyleByServerControlId("ucOrderingControl_lblPrice", "innerHTML", attribArray[i][1]);
            ChangeStyleByServerControlId("ucOrderingControl_lblCupsPerFeeding", "innerHTML", attribArray[i][2]);

			if(attribArray[i][8]  == "True")
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "inline");
            }
			else
			{
                ChangeStyleByServerControlId("ucOrderingControl_lblProductOnSaleMessage", "display", "none");
            }

            break;
        }
    }

    //update the equivalancy
	for(i = 0; i < equivArray.length; i++)
	{
        var controlId = "ucOrderingControl_lblEquiv_" + equivArray[i][0];

        ChangeStyleByServerControlId(controlId, "innerHTML", "(" + equivArray[i][1] + " cups, " + Math.round(equivArray[i][1] / feedingAmount) + " days)");
    }
}

function SwitchToSmartPakSingle()
{	
    ChangeStyleByServerControlId("ucOrderingControl_rbSingle", "checked", true);
}

function SwitchToCustom()
{
    ChangeStyleByServerControlId("ucOrderingControl_rbCustom", "checked", true);
}

function SwitchToKnownDose()
{
    ChangeStyleByServerControlId("ucOrderingControl_rbKnownDosage", "checked", true);
}

function SelectNewOrder()
{
    ChangeStyleByServerControlId("ucOrderingControl_rbNewOrder", "checked", true);
}

function SelectExistingOrder()
{
    ChangeStyleByServerControlId("ucOrderingControl_rbExistingOrder", "checked", true);
}

function SelectShipWith()
{
    ChangeStyleByServerControlId("ucOrderingControl_rbShipLater", "checked", true);
}

function SelectGiftCertType()
{
    var ddlControl = GetElementByServerControlId("ucOrderingControl_ddlAttribute1");
    var Index = ddlControl.options[ddlControl.selectedIndex].value

    var uclist = new Array("ucOrderingControl_lblRecipEmail", "ucOrderingControl_txtRecipEmail", "ucOrderingControl_lblFromEmail", "ucOrderingControl_txtFromEmail", "ucOrderingControl_lblSubject", "ucOrderingControl_txtSubject");
    var uclist2 = new Array("ucOrderingControl_lblFromName", "ucOrderingControl_txtFromName", "ucOrderingControl_lblSpecialMessage", "ucOrderingControl_txtSpecialMessage");

	if(Index == '1997695888')
	{
        ChangeStylesByServerControlIds(uclist, "display", "inline");
        ChangeStylesByServerControlIds(uclist2, "display", "inline");

        ChangeStyleByServerControlId("ucOrderingControl_plQTY", "display", "none");

    }
	else if (Index == '1997695889')
	{
        ChangeStylesByServerControlIds(uclist, "display", "none");
        ChangeStylesByServerControlIds(uclist2, "display", "inline");

        ChangeStyleByServerControlId("ucOrderingControl_plQTY", "display", "inline");

    }
	else if(Index == '1997710568')
	{
        ChangeStylesByServerControlIds(uclist, "display", "none");
        ChangeStylesByServerControlIds(uclist2, "display", "none");

        ChangeStyleByServerControlId("ucOrderingControl_lblFromName", "display", "inline");
        ChangeStyleByServerControlId("ucOrderingControl_txtFromName", "display", "inline");
        GetElementByServerControlId("ucOrderingControl_txtFromName").value = "SmartPak";
        ChangeStyleByServerControlId("ucOrderingControl_plQTY", "display", "inline");

    }
}

function ChangeStyleByServerControlId(elementId, styleName, value)
{
    var element = GetElementByServerControlId(elementId);

    if(element != null)
    {
        switch(styleName)
        {
            case "display":
                element.style.display = value; break;
            case "width":
                element.style.width = value; break;
            case "height":
                element.style.height = value; break;
            case "checked":
                element.checked = value; break;
            case "innerHTML":
                element.innerHTML = value; break;
            case "source":
                element.src = value; break;
            default:
                break;
        }
    }
}

function ChangeStylesByServerControlIds(elementIds, styleName, value)
{
    for (var i = 0; i<elementIds.length;i++)
    {
        ChangeStyleByServerControlId(elementIds[i], styleName, value);
    }
}

function ChangeStyleById(elementId, styleName, value)
{
    var element = document.getElementById(elementId);

    if(element != null)
    {
        switch(styleName)
        {
            case "display":
                element.style.display = value; break;
            case "width":
                element.style.width = value; break;
            case "height":
                element.style.height = value; break;
            case "checked":
                element.checked = value; break;
            case "innerHTML":
                element.innerHTML = value; break;
            case "source":
                element.src = value; break;
            default:
                break;
        }
    }
}

function ChangeStylesByIds(elementIds, styleName, value)
{
    for (var i = 0; i<elementIds.length;i++)
    {
        ChangeStyleById(elementIds[i], styleName, value);
    }
}

function GetElementByServerControlId( controlId )
{
    return document.getElementById(prefixvar + controlId);
}

function GetElementInMicrosoft( controlId )
{
    return document.all[prefixvar + controlId];
}

function SelectAutoShip(controlId)
{
    SetCheckControl(controlId, true);
}

function SetCheckControl(controlId,isChecked)
{
	if (controlId != null)
	{
        var ctl = document.getElementById(controlId);
		if (ctl == null)
		{
            var re = /\$/g
            controlId = controlId.replace(re, "_");
            ctl = document.getElementById(controlId);
        }

		if (ctl != null)
		{
            ctl.checked = isChecked;
            ctl.click();
        }
    }
}

function SelectOrderToShipWith(lstAccount,controlId,shipWithButton)
{		

	if ((lstAccount != null) && (lstAccount.options.length > lstAccount.selectedIndex))
	{
        var option = lstAccount.options[lstAccount.selectedIndex];
		if (option != null)
		{
            var orderName = option.value;

            var shipWithCtl = document.getElementById(controlId);

			if (shipWithCtl != null)
			{
				for(var i = 0; i < shipWithCtl.options.length; i++)
				{	  			
					if(shipWithCtl.options[i].text.indexOf(orderName) != -1)
					{ 					
                        shipWithCtl.selectedIndex = i;
                        //SetCheckControl(shipWithButton,true);				
                        break;
                    }
                }
            }
        }
    }
}

//Two Image functions restore original Adobe functionality for Alternate Image Switching
function Alternate_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function swapAlternateImage() { //v3.0
    var i, j = 0, x, a = swapAlternateImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = Alternate_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }

}

 //Begin ProductClass Zoom
$(document).ready(function() {

    var img = $('#pnlImagesRegion img:first');
    var path = img.attr("src");

    setHighResolutionImage(path);
    var offset = img.offset();

    var options =
    {
        imageLeftOffset: offset.left,
        imageTopOffset: offset.top
    }

    $('.jqZoom').jqzoom(options);

});

function swapImages(imagePath) {

    clearLastZoom();

    var img = $('#pnlImagesRegion img:first');
    img.attr("src", imagePath);

    $('#pnlImagesRegion a:first').attr("href", 'noimage');
    setHighResolutionImage(imagePath);

}

function clearLastZoom() {

    $('.captionZoom').remove();
    $('.jqZoomPup').remove();
    $('.temp').remove();
    $('.jqZoomWindow').remove();

}

function setHighResolutionImage(imagePath) {

    var highResImagePath = getHighResolutionImagePath(imagePath);
    var highResImage = new Image();

    $(highResImage).load(function() {
        $('#pnlImagesRegion a:first').attr("href", highResImagePath);
        if ($('.captionZoom').length == 0) $('#pnlImagesRegion a:first').after('<br>');
    }).error(function() {
        $('#pnlImagesRegion a:first').attr("href", 'noimage');
        $('.captionZoom').remove();
    });

    highResImage.src = highResImagePath;

}

function getHighResolutionImagePath(imagePath) {
    return imagePath.replace(/product/i, "product/highres");
}

(function($) {
    $.fn.jqzoom = function(options) {
        var settings = {
            zoomType: 'standard', //standard/reverse/innerzoom
            zoomWidth: 400, 	//zoomed width default width
            zoomHeight: 300, 	//zoomed div default width
            xOffset: 10, 	//zoomed div default offset
            yOffset: 0,
            position: "right", //zoomed div default position,offset position is to the right of the image
            lens: true, //zooming lens over the image,by default is 1;
            lensReset: false,
            imageOpacity: 0.2,
            title: false,
            alwaysOn: false,
            showEffect: 'show',
            hideEffect: 'hide',
            fadeinSpeed: 'fast',
            fadeoutSpeed: 'slow',
            preloadImages: false,
            showPreload: false,
            preloadText: 'Loading zoom',
            preloadPosition: 'center',   //bycss
            highResImage: '',
            imageLeftOffset: 0,
            imageTopOffset: 0
        };

        //extending options
        options = options || {};
        $.extend(settings, options);

        return this.each(function() {

            var a = $(this);
            var img = $("img", this);

            if (a[0].href.indexOf('noimage') != -1) //no high res image
            {
                $('.captionZoom').remove();
                $(a).css('cursor:default');
                $(a).click(function() { return false; });
                return false;
            }

            $(a).css('outline-style', 'none');

            var smallimage = new Smallimage(img);
            var smallimagedata = {};
            var largeimage = null;
            var largeimageloaded = false;

            var btop = 0;
            var bleft = 0;
            var lens = new Lens();
            var lensdata = {};

            var scale = {};
            var stage = null;
            var running = false;
            var mousepos = {};
            var firstime = 0;
            var preloadshow = false;
            var isMouseDown = false;
            var dragstatus = false

            smallimage.loadimage();

            $(this).click(function() { return false; });

            $(this).hover(function(e) {
                mousepos.x = e.pageX;
                mousepos.y = e.pageY;
                activate();
            }, function() {
                deactivate();
            });

            function activate() {

                if (!running) {

                    //finding border
                    smallimage.findborder();

                    running = true;

                    largeimage = new Largeimage(a[0].href);

                    if (!largeimageloaded || $.browser.safari) {
                        largeimage.loadimage();
                    } else {
                        //after preload
                        if (settings.zoomType != 'innerzoom') {
                            stage = new Stage();
                            stage.activate();
                        }
                        lens = new Lens;
                        lens.activate();
                    }

                    a[0].blur();
                    return false;
                }
            }

            function deactivate() {

                largeimage = null;
                if (settings.zoomType == 'reverse') {
                    img.css({ 'opacity': 1 });
                }

                if (!settings.alwaysOn) {
                    //resetting parameters
                    running = false;
                    largeimageloaded = false;
                    $(lens.node).unbind('mousemove');
                    lens.remove();
                    if ($('div.jqZoomWindow').length > 0) {
                        stage.remove();
                    }
                    if ($('div.jqZoomTitle').length > 0) {
                        ZoomTitleObj.remove();
                    }

                    $().unbind();

                    a.unbind('mousemove');

                    firstime = 0;
                    //remove ieiframe
                    if (jQuery('.zoom_ieframe').length > 0) {
                        jQuery('.zoom_ieframe').remove();
                    }

                    $('.temp').remove();
                    $('.jqZoomWindow').remove();
                    $('.jqZoomPup').remove();
                    $('.preload').remove();

                } else {
                    if (settings.lensReset) {
                        switch (settings.zoomType) {
                            case 'innerzoom':
                                largeimage.setcenter();
                                break;
                            default:
                                lens.center();
                                break;
                        }
                    }
                }

            };

            function Smallimage(image) {
                this.node = image[0];

                this.loadimage = function() {
                    this.node.src = image[0].src;
                };
                this.findborder = function() {
                    var bordertop = '';
                    bordertop = $(img).css('border-top-width');
                    btop = '';
                    var borderleft = '';
                    borderleft = $(img).css('border-left-width');
                    bleft = '';

                    if (bordertop) {
                        for (i = 0; i < 3; i++) {
                            var x = [];
                            x = bordertop.substr(i, 1);

                            if (isNaN(x) == false) {
                                btop = btop + '' + bordertop.substr(i, 1);
                            } else {
                                break;
                            }
                        }
                    }

                    if (borderleft) {
                        for (i = 0; i < 3; i++) {
                            if (!isNaN(borderleft.substr(i, 1))) {
                                bleft = bleft + borderleft.substr(i, 1)
                            } else {
                                break;
                            }
                        }
                    }
                    btop = (btop.length > 0) ? eval(btop) : 0;
                    bleft = (bleft.length > 0) ? eval(bleft) : 0;

                }

                this.node.onload = function() {

                    a.css({ 'cursor': 'default', 'display': 'block' });

                    if (a.css('position') != 'absolute' && a.parent().css('position')) {
                        a.css({ 'cursor': 'default', 'position': 'relative', 'display': 'block' });
                    }
                    if (a.parent().css('position') != 'absolute') {
                        a.parent().css('position', 'relative');
                        //a.css('position','relative');
                    }
                    else {
                        //a.css('position','relative');
                    }
                    if ($.browser.safari || $.browser.opera) {
                        $(img).css({ position: 'absolute', top: '0px', left: '0px' });
                    }

                    smallimagedata.w = $(this).width();
                    smallimagedata.h = $(this).height();
                    smallimagedata.l = settings.imageLeftOffset;
                    smallimagedata.t = settings.imageTopOffset;
                    smallimagedata.r = smallimagedata.w + smallimagedata.l;
                    smallimagedata.b = smallimagedata.h + smallimagedata.t;

                    a.height(smallimagedata.h);
                    a.width(smallimagedata.w);

                };

                return this;
            };

            function Lens() {

                //creating element and adding class
                this.node = document.createElement("div");
                $(this.node).addClass('jqZoomPup');

                this.node.onerror = function() {
                    $(lens.node).remove();
                    lens = new Lens();
                    lens.activate();
                };

                this.loadlens = function() {

                    switch (settings.zoomType) {
                        case 'reverse':
                            this.image = new Image();
                            this.image.src = smallimage.node.src; // fires off async
                            this.node.appendChild(this.image);
                            $(this.node).css({ 'opacity': 1 });
                            break;
                        case 'innerzoom':

                            this.image = new Image();
                            this.image.src = largeimage.node.src; // fires off async
                            this.node.appendChild(this.image);
                            $(this.node).css({ 'opacity': 1 });
                            break
                        default:
                            break;
                    }

                    switch (settings.zoomType) {
                        case 'innerzoom':
                            lensdata.w = smallimagedata.w;
                            lensdata.h = smallimagedata.h;
                            break;
                        default:
                            lensdata.w = (settings.zoomWidth) / scale.x;
                            lensdata.h = (settings.zoomHeight) / scale.y;
                            break;
                    }

                    $(this.node).css({
                        width: lensdata.w + 'px',
                        height: lensdata.h + 'px',
                        position: 'absolute',
                        /*cursor: 'crosshair',*/
                        display: 'none',
                        //border: '1px solid blue'
                        borderWidth: 1 + 'px'
                    });
                    a.append(this.node);
                }
                return this;
            };

            Lens.prototype.activate = function() {

                this.loadlens();

                switch (settings.zoomType) {
                    case 'reverse':
                        img.css({ 'opacity': settings.imageOpacity });

                        (settings.alwaysOn) ? lens.center() : lens.setposition(null);
                        //lens.center();
                        a.bind('mousemove', function(e) {
                            mousepos.x = e.pageX;
                            mousepos.y = e.pageY;
                            lens.setposition(e);
                        });
                        break;
                    case 'innerzoom':

                        //	lens = new Lens();
                        //	lens.activate();

                        $(this.node).css({ top: 0, left: 0 });
                        if (settings.title) {
                            ZoomTitleObj.loadtitle();
                        }

                        largeimage.setcenter();

                        a.bind('mousemove', function(e) {
                            mousepos.x = e.pageX;
                            mousepos.y = e.pageY;
                            largeimage.setinner(e);
                        });
                        break;
                    default:

                        (settings.alwaysOn) ? lens.center() : lens.setposition(null);

                        $(a).bind('mousemove', function(e) {

                            mousepos.x = e.pageX;
                            mousepos.y = e.pageY;
                            lens.setposition(e);
                        });

                        break;
                }

                return this;
            };

            Lens.prototype.setposition = function(e) {


                if (e) {
                    mousepos.x = e.pageX;
                    mousepos.y = e.pageY;
                }

                if (firstime == 0) {
                    var lensleft = (smallimagedata.w) / 2 - (lensdata.w) / 2;
                    var lenstop = (smallimagedata.h) / 2 - (lensdata.h) / 2;

                    $('div.jqZoomPup').show()
                    if (settings.lens) {
                        this.node.style.visibility = 'visible';
                    }
                    else {
                        this.node.style.visibility = 'hidden';
                        $('div.jqZoomPup').hide();
                    }

                    firstime = 1;

                } else {
                    var lensleft = mousepos.x - smallimagedata.l - (lensdata.w) / 2;
                    var lenstop = mousepos.y - smallimagedata.t - (lensdata.h) / 2;
                }

                if (overleft()) {
                    lensleft = 0 + bleft;
                } else
                    if (overright()) {
                    if ($.browser.msie) {
                        lensleft = smallimagedata.w - lensdata.w + bleft + 1;
                    } else {
                        lensleft = smallimagedata.w - lensdata.w + bleft - 1;
                    }


                }

                if (overtop()) {
                    lenstop = 0 + btop;
                } else
                    if (overbottom()) {

                    if ($.browser.msie) {
                        lenstop = smallimagedata.h - lensdata.h + btop + 1;
                    } else {
                        lenstop = smallimagedata.h - lensdata.h - 1 + btop;
                    }

                }
                lensleft = parseInt(lensleft);
                lenstop = parseInt(lenstop);

                $('div.jqZoomPup', a).css({ top: lenstop, left: lensleft });

                if (settings.zoomType == 'reverse') {
                    $('div.jqZoomPup img', a).css({ 'position': 'absolute', 'top': -(lenstop - btop + 1), 'left': -(lensleft - bleft + 1) });
                }

                this.node.style.left = lensleft + 'px';
                this.node.style.top = lenstop + 'px';

                largeimage.setposition();

                function overleft() {
                    return mousepos.x - (lensdata.w + 2 * 1) / 2 - bleft < smallimagedata.l;
                }

                function overright() {

                    return mousepos.x + (lensdata.w + 2 * 1) / 2 > smallimagedata.r + bleft;
                }

                function overtop() {
                    return mousepos.y - (lensdata.h + 2 * 1) / 2 - btop < smallimagedata.t;
                }

                function overbottom() {
                    return mousepos.y + (lensdata.h + 2 * 1) / 2 > smallimagedata.b + btop;
                }

                return this;
            };

            Lens.prototype.center = function() {
                $('div.jqZoomPup', a).css('display', 'none');
                var lensleft = (smallimagedata.w) / 2 - (lensdata.w) / 2;
                var lenstop = (smallimagedata.h) / 2 - (lensdata.h) / 2;
                this.node.style.left = lensleft + 'px';
                this.node.style.top = lenstop + 'px';
                $('div.jqZoomPup', a).css({ top: lenstop, left: lensleft });

                if (settings.zoomType == 'reverse') {
                    $('div.jqZoomPup img', a).css({ 'position': 'absolute', 'top': -(lenstop - btop + 1), 'left': -(lensleft - bleft + 1) });
                }

                largeimage.setposition();
                if ($.browser.msie) {
                    $('div.jqZoomPup', a).show();
                } else {
                    setTimeout(function() { $('div.jqZoomPup').fadeIn('fast'); }, 10);
                }
            };

            Lens.prototype.getoffset = function() {
                var o = {};
                o.left = parseInt(this.node.style.left);
                o.top = parseInt(this.node.style.top);
                return o;
            };

            Lens.prototype.remove = function() {

                if (settings.zoomType == 'innerzoom') {
                    $('div.jqZoomPup', a).fadeOut('fast', function() { $(this).remove(); });
                } else {
                    $('div.jqZoomPup', a).remove();
                }
            };

            Lens.prototype.findborder = function() {
                var bordertop = '';
                bordertop = $('div.jqZoomPup').css('borderTop');
                //alert(bordertop);
                lensbtop = '';
                var borderleft = '';
                borderleft = $('div.jqZoomPup').css('borderLeft');
                lensbleft = '';
                if ($.browser.msie) {
                    var temp = bordertop.split(' ');

                    bordertop = temp[1];
                    var temp = borderleft.split(' ');
                    borderleft = temp[1];
                }

                if (bordertop) {
                    for (i = 0; i < 3; i++) {
                        var x = [];
                        x = bordertop.substr(i, 1);

                        if (isNaN(x) == false) {
                            lensbtop = lensbtop + '' + bordertop.substr(i, 1);
                        } else {
                            break;
                        }
                    }
                }

                if (borderleft) {
                    for (i = 0; i < 3; i++) {
                        if (!isNaN(borderleft.substr(i, 1))) {
                            lensbleft = lensbleft + borderleft.substr(i, 1)
                        } else {
                            break;
                        }
                    }
                }

                lensbtop = (lensbtop.length > 0) ? eval(lensbtop) : 0;
                lensbleft = (lensbleft.length > 0) ? eval(lensbleft) : 0;
            }

            function Largeimage(url) {

                $('.temp').remove();
                $('.jqZoomWindow').remove();
                $('.jqZoomPup').remove();
                $('.preload').remove();

                this.url = url;
                this.node = new Image();

                this.loadimage = function() {

                    if (url.indexOf('noimage') != -1 || url.length == 0)
                        return false;

                    if (!this.node)
                        this.node = new Image();

                    this.node.style.position = 'absolute';
                    this.node.style.display = 'none';
                    this.node.style.left = '-5000px';
                    this.node.style.top = '10px';
                    loader = new Loader();

                    if (settings.showPreload && !preloadshow) {
                        loader.show();
                        preloadshow = true;
                    }

                    document.body.appendChild(this.node);
                    this.node.src = this.url; // fires off async
                }

                this.node.onload = function() {

                    this.style.display = 'block';
                    var w = Math.round($(this).width());
                    var h = Math.round($(this).height());

                    this.style.display = 'none';
                    $(this).addClass('temp');
                    //setting scale
                    scale.x = (w / smallimagedata.w);
                    scale.y = (h / smallimagedata.h);

                    if ($('div.preload').length > 0) {
                        $('div.preload').remove();
                    }

                    largeimageloaded = true;

                    if (settings.zoomType != 'innerzoom' && running) {
                        stage = new Stage();
                        stage.activate();
                    }

                    if (running) {
                        //alert('in');
                        lens = new Lens();

                        lens.activate();

                    }

                    if ($('div.preload').length > 0) {
                        $('div.preload').remove();
                    }
                }
                return this;
            }


            Largeimage.prototype.setposition = function() {
                this.node.style.left = Math.ceil(-scale.x * parseInt(lens.getoffset().left) + bleft) + 'px';
                this.node.style.top = Math.ceil(-scale.y * parseInt(lens.getoffset().top) + btop) + 'px';
            };

            Largeimage.prototype.setinner = function(e) {
                this.node.style.left = Math.ceil(-scale.x * Math.abs(e.pageX - smallimagedata.l)) + 'px';
                this.node.style.top = Math.ceil(-scale.y * Math.abs(e.pageY - smallimagedata.t)) + 'px';
                $('div.jqZoomPup img', a).css({ 'position': 'absolute', 'top': this.node.style.top, 'left': this.node.style.left });
            };

            Largeimage.prototype.setcenter = function() {
                this.node.style.left = Math.ceil(-scale.x * Math.abs((smallimagedata.w) / 2)) + 'px';
                this.node.style.top = Math.ceil(-scale.y * Math.abs((smallimagedata.h) / 2)) + 'px';

                $('div.jqZoomPup img', a).css({ 'position': 'absolute', 'top': this.node.style.top, 'left': this.node.style.left });
            };


            function Stage() {

                var leftpos = smallimagedata.l;
                var toppos = smallimagedata.t;
                //creating element and class
                this.node = document.createElement("div");
                $(this.node).addClass('jqZoomWindow');

                $(this.node)
				.css({
				    position: 'absolute',
				    width: Math.round(settings.zoomWidth) + 'px',
				    height: Math.round(settings.zoomHeight) + 'px',
				    display: 'none',
				    zIndex: 10000,
				    overflow: 'hidden'
				});

                switch (settings.position) {
                    case "right":

                        leftpos = (smallimagedata.r + Math.abs(settings.xOffset) + settings.zoomWidth < screen.width)
				? (smallimagedata.l + smallimagedata.w + Math.abs(settings.xOffset))
				: (smallimagedata.l - settings.zoomWidth - Math.abs(settings.xOffset));

                        topwindow = smallimagedata.t + settings.yOffset + settings.zoomHeight;
                        toppos = (topwindow < screen.height && topwindow > 0)
				? smallimagedata.t + settings.yOffset
				: smallimagedata.t;

                        break;
                    case "left":

                        leftpos = (smallimagedata.l - Math.abs(settings.xOffset) - settings.zoomWidth > 0)
				? (smallimagedata.l - Math.abs(settings.xOffset) - settings.zoomWidth)
				: (smallimagedata.l + smallimagedata.w + Math.abs(settings.xOffset));

                        topwindow = smallimagedata.t + settings.yOffset + settings.zoomHeight;
                        toppos = (topwindow < screen.height && topwindow > 0)
				? smallimagedata.t + settings.yOffset
				: smallimagedata.t;

                        break;
                    case "top":

                        toppos = (smallimagedata.t - Math.abs(settings.yOffset) - settings.zoomHeight > 0)
				? (smallimagedata.t - Math.abs(settings.yOffset) - settings.zoomHeight)
				: (smallimagedata.t + smallimagedata.h + Math.abs(settings.yOffset));


                        leftwindow = smallimagedata.l + settings.xOffset + settings.zoomWidth;
                        leftpos = (leftwindow < screen.width && leftwindow > 0)
				? smallimagedata.l + settings.xOffset
				: smallimagedata.l;

                        break;
                    case "bottom":


                        toppos = (smallimagedata.b + Math.abs(settings.yOffset) + settings.zoomHeight < $('body').height())
				? (smallimagedata.b + Math.abs(settings.yOffset))
				: (smallimagedata.t - settings.zoomHeight - Math.abs(settings.yOffset));


                        leftwindow = smallimagedata.l + settings.xOffset + settings.zoomWidth;
                        leftpos = (leftwindow < screen.width && leftwindow > 0)
				? smallimagedata.l + settings.xOffset
				: smallimagedata.l;

                        break;
                    default:

                        leftpos = (smallimagedata.l + smallimagedata.w + settings.xOffset + settings.zoomWidth < screen.width)
				? (smallimagedata.l + smallimagedata.w + Math.abs(settings.xOffset))
				: (smallimagedata.l - settings.zoomWidth - Math.abs(settings.xOffset));

                        toppos = (smallimagedata.b + Math.abs(settings.yOffset) + settings.zoomHeight < screen.height)
				? (smallimagedata.b + Math.abs(settings.yOffset))
				: (smallimagedata.t - settings.zoomHeight - Math.abs(settings.yOffset));

                        break;
                }

                this.node.style.left = leftpos + 'px';
                this.node.style.top = toppos + 'px';
                return this;
            }

            Stage.prototype.activate = function() {

                if (!this.node.firstChild)
                    this.node.appendChild(largeimage.node);

                if (settings.title) {
                    ZoomTitleObj.loadtitle();
                }

                document.body.appendChild(this.node);

                switch (settings.showEffect) {
                    case 'show':
                        $(this.node).show();
                        break;
                    case 'fadein':
                        $(this.node).fadeIn(settings.fadeinSpeed);
                        break;
                    default:
                        $(this.node).show();
                        break;
                }

                //$(this.node).show();

                if ($.browser.msie && $.browser.version < 7) {
                    this.ieframe = $('<iframe class="zoom_ieframe" frameborder="0" src="#"></iframe>')
	          .css({ position: "absolute", left: this.node.style.left, top: this.node.style.top, zIndex: 99, width: settings.zoomWidth, height: settings.zoomHeight })
	          .insertBefore(this.node);
                };

                largeimage.node.style.display = 'block';
            }

            Stage.prototype.remove = function() {
                switch (settings.hideEffect) {
                    case 'hide':
                        $('.jqZoomWindow').remove();
                        break;
                    case 'fadeout':
                        $('.jqZoomWindow').fadeOut(settings.fadeoutSpeed);
                        break;
                    default:
                        $('.jqZoomWindow').remove();
                        break;
                }
            }

            function zoomTitle() {

                this.node = jQuery('<div />')
            				.addClass('jqZoomTitle')
            				.html('' + ZoomTitle + '');

                this.loadtitle = function() {
                    if (settings.zoomType == 'innerzoom') {
                        $(this.node)
            					.css({ position: 'absolute',
            					    top: smallimagedata.b + 3,
            					    left: (smallimagedata.l + 1),
            					    width: smallimagedata.w
            					})
            					.appendTo('body');
                    } else {
                        $(this.node).appendTo(stage.node);
                    }
                };
            }

            zoomTitle.prototype.remove = function() {
                $('.jqZoomTitle').remove();
            }


            function Loader() {

                this.node = document.createElement("div");
                $(this.node).addClass('preload');
                $(this.node).html(settings.preloadText);

                $(this.node)
            				.appendTo("body")
            				.css('visibility', 'hidden');

                this.show = function() {
                    switch (settings.preloadPosition) {
                        case 'center':
                            loadertop = smallimagedata.t + (smallimagedata.h - $(this.node).height()) / 2;
                            loaderleft = smallimagedata.l + (smallimagedata.w - $(this.node).width()) / 2;
                            break;
                        default:
                            var loaderoffset = this.getoffset();
                            loadertop = !isNaN(loaderoffset.top) ? smallimagedata.t + loaderoffset.top : smallimagedata.t + 0;
                            loaderleft = !isNaN(loaderoffset.left) ? smallimagedata.l + loaderoffset.left : smallimagedata.l + 0;
                            break;
                    }

                    //setting position
                    $(this.node).css({
                        top: loadertop,
                        left: loaderleft,
                        position: 'absolute',
                        visibility: 'visible'
                    });
                }
                return this;
            }

            Loader.prototype.getoffset = function() {
                var o = null;
                o = $('div.preload').offset();
                return o;
            }

        });
    }
})(jQuery);

function trim(stringa) {
    while (stringa.substring(0, 1) == ' ') {
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length - 1, stringa.length) == ' ') {
        stringa = stringa.substring(0, stringa.length - 1);
    }
    return stringa;
}
// End ProductClass Zoom
