	<!-- Begin
	/* This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com
	Created by: Ultimater :: http://ultimiacian.tripod.com/
	Add this snippet to the very beginning of your script. */

	if(!document.getElementById){
	if(document.all)
	document.getElementById=function(){
		if(typeof document.all[arguments[0]]!="undefined")
		return document.all[arguments[0]]
		else
		return null
	}
	else if(document.layers)
	document.getElementById=function(){
		if(typeof document[arguments[0]]!="undefined")
		return document[arguments[0]]
		else
		return null
	}
	}
	// End -->

	browserName=navigator.appName;
	browserVer=parseInt(navigator.appVersion);
	
	if (browserVer > 2) {
	
	Home_R = new Image(95, 55);
	Home_R.src="images/Home_R.gif";
	Home_O = new Image(95, 55);
	Home_O.src="images/Home_O.gif";	
	Home_A = new Image(95, 55);
	Home_A.src="images/Home_A.gif";		
	
	Edit_R = new Image(21, 21);
	Edit_R.src="images/editicon.jpg";
	Add_R = new Image(21, 21);
	Add_R.src="images/addicon.jpg";	
	None_R = new Image(21, 21);
	None_R.src="images/clear.gif";
	
	DashImg = new Image(5, 9);
	DashImg.src="images/SideNavDash.gif";
	ClearImg = new Image(5, 9);
	ClearImg.src="images/Clear.gif";
	
	}
	
	function Dash_Roll(imgName) {
		var el = document.getElementById(imgName);
		if (el != null) {
				el.src = DashImg.src;
		}
	}
		
	function Dash_UnRoll(imgName) {
		var el = document.getElementById(imgName);
		if (el != null) {
				el.src = ClearImg.src;
		}

	}		
	
	function RollIt(imgName) {
		var el = document.getElementById(imgName);
		el.src = eval(imgName + "_O.src");
	}
	
	function UnRollIt(imgName, RorA) {
		var el = document.getElementById(imgName);
		if (RorA == 'A')
		    { el.src = eval(imgName + "_A.src"); }
		else
		    { el.src = eval(imgName + "_R.src"); }
	}
      
function FindMyControl(MyID) {

	var frmElements,i,t,ctl;
	
	// Since the use of master pages mangles the names of child controls, we need a method 
	// of searching through the form elements and returning a reference to the control we are 
	// looking for that control by the name we know it as instead of the dumb-ass name ASP.Net creates.
	// First scan through all of the input elements and look for our control
    frmElements=document.getElementsByTagName('input');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }
   // Still not found, scan through all of the select elements
    frmElements=document.getElementsByTagName('select');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    } 
   
   // Still not found, scan through all of the textarea elements
    frmElements=document.getElementsByTagName('textarea');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }
   
   // Still not found, scan through all of the textarea elements
    frmElements=document.getElementsByTagName('td');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }      
   
   // Still not found, scan through all of the textarea elements
    frmElements=document.getElementsByTagName('img');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }     

   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('div');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }        
    
   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('a');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }      
   
    return false;         

}       

function PositionLayer(LayerName, OffSetX, OffSetY) {

	var imgX;
	var imgY;
	var el;
		
	if (OffSetX == 450 ) { OffSetX = 325 }		// correction
	if (navigator.appVersion.indexOf('MSIE 7') > -1) { OffSetY = OffSetY + 20 } // correct for IE 7
	
	imgX = (document.body.clientWidth / 2);	// find the center of the window
	imgX = imgX - OffSetX
	imgY = OffSetY;
	// adjust for scroll position
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
    var dsoctop=document.all? iebody.scrollTop : pageYOffset
    imgY = imgY + dsoctop;
    
    el = document.getElementById(LayerName);
	el.style.left = imgX + 'px';
	el.style.top = imgY + 'px';
}

function ShowLayer(LayerName) {		

	var BrowserType = "";
	if(document.layers) { BrowserType="NN4" }
	if(document.all) { BrowserType="IE"  }
	if(!document.all && document.getElementById) { BrowserType="NN6" } 
	if (BrowserType=="") { BrowserType="IE"  }	// default to IE, just because....

	if (BrowserType=="IE") { document.all[LayerName].style.visibility = 'visible' }
	if (BrowserType=="NN4") { document.layers[LayerName].visibility = 'visible' }
	if (BrowserType=="NN6") { document.getElementById(LayerName).style.visibility='visible' }
	
}

function CancelLayer(LayerName) {

	// determine our browser type for layer usage
	var BrowserType = "";
	if(document.layers) { BrowserType="NN4" }
	if(document.all) { BrowserType="IE"  }
	if(!document.all && document.getElementById) { BrowserType="NN6" } 
	if (BrowserType=="") { BrowserType="IE"  }	// default to IE, just because....

	if (BrowserType=="IE") { parent.document.all[LayerName].style.visibility = 'hidden' }
	if (BrowserType=="NN4") { parent.document.layers[LayerName].visibility = 'hidden' }
	if (BrowserType=="NN6") { parent.document.getElementById(LayerName).style.visibility='hidden' }
}	

// QUICK SEARCH Scripts ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var PreviousKeyword = '';
var Tmr1;
var BusySearching = false;
var CancelClear = false;
var lnkCnt  = -1;

function DoSearch() {

    var el;
    var CurrentKeyword = '';
    var SiteFlag = '';
    var Action = '';
    var Param = '';
    var CustNo = '';
    
    clearTimeout(Tmr1);
       
    el = FindMyControl('hdCustNoForSearching');
    CustNo = el.value;
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = FindMyControl('txtQuickSearch');
    CurrentKeyword = el.value;
        
    if (PreviousKeyword != CurrentKeyword && CurrentKeyword.length >= 2 ) {
        //Catalog.QuickSearchCatalog(SiteFlag, CurrentKeyword, Action, Param, CustNo, DrawQuickSearchResults, ErrorHandler, TimeOutHandler);
    }

    PreviousKeyword = CurrentKeyword;
    BusySearching = true;
    lnkCnt  = -1;
    Tmr1 = setTimeout('DoSearch()', 300);

}

function StopSearch() {

    clearTimeout(Tmr1);
    Tmr1 = setTimeout('ClearSearchResults()', 600);
    
}

function ClearSearchResults() {
    
    var el;
    clearTimeout(Tmr1);
    if ( CancelClear == false ) {
        el = document.getElementById('divSearchResults');
        el.style.visibility = 'hidden';
        el.innerHTML = '';
        BusySearching = false;
    }
    else
    {
        CancelClear = false;
        Tmr1 = setTimeout('ClearSearchResults()', 2000);
    }

}

function fnTrapKD(ev) {

	var kc = 0;
	var BrowserType = '';
	var el;
	
	if ( BusySearching == false ) { return };
	
	// determine our browser type 
	if(document.layers) { BrowserType='NN4' }
	if(document.all) { BrowserType='IE'  }
	if(!document.all && document.getElementById) { BrowserType='NN6' } 
	
	if ( BrowserType == 'IE' ) { kc = event.keyCode }
		else { kc =((ev.which)||(ev.keyCode)) }
		
	if ( kc == 40 ) { // Down Arrow
        // increment link cnt
        lnkCnt += 1;	
	    el = document.getElementById('lnkQS' + lnkCnt);
	    if ( el != null ) { 
	        el.focus(); 
	        CancelClear = true;
	        // highlight  current cell
	        el = document.getElementById('tdQS' + lnkCnt);
	        if ( el != null ) { el.className = 'tdQS_Title_Selected'; }
	        // un-highlight previous
	        el = document.getElementById('tdQS' + (lnkCnt - 1));
	        if ( el != null ) { el.className = 'tdQS_Title'; }
	        }	    
	}
	
	if ( kc == 38 ) { // Up Arrow
        // decrement link cnt
        lnkCnt -= 1;
        if ( lnkCnt < 0 ) { el = FindMyControl('txtQuickSearch'); el.focus(); BusySearching = false; PreviousKeyword = ''; return; }
	    el = document.getElementById('lnkQS' + lnkCnt);
	    if ( el != null ) { 
	        el.focus(); 
	        CancelClear = true;
	        // highlight  current cell
	        el = document.getElementById('tdQS' + lnkCnt);
	        if ( el != null ) { el.className = 'tdQS_Title_Selected'; }
	        // un-highlight previous
	        el = document.getElementById('tdQS' + (lnkCnt + 1));
	        if ( el != null ) { el.className = 'tdQS_Title'; }
	        }	    
	}	
	
}

function DrawQuickSearchResults(results) {

    var el;
    var HTML;
    var T;
    var KeywordHold;
    var classname;
    var link;
        
    el = document.getElementById('divSearchResults');
    el.style.visibility = 'visible';
    
    // run the rows
    HTML = '<table>';
    for (var i = 0; i < results.length; i++) {
        HTML += '<tr>';
        T = results[i].FAMILY_NAME;
        KeywordHold = PreviousKeyword;
        T = HighlightSearchTerm(T, KeywordHold);
        // set class name
        if ( (i % 2) == 0 ) { classname = 'tdQS_Title' }
            else { classname = 'tdQS_Title_gray' }
        // build up link
        link = 'ItemPage.aspx?Selected_Category=' + results[i].CATEGORY_ID + '&FAMILY_ID=' + results[i].FAMILY_ID + '&ST=' + escape(KeywordHold);
        if ( results[i].ItemNo.length > 0 ) { link = link + '&PreSelectedItemNo=' + results[i].ItemNo }
        
        link = 'javascript: QuickLinkNav(\'' + escape(link) + '\')';
                    
        HTML += '<td class="' + classname + '" id="tdQS' + i + '"><a href="' + link + '" id="lnkQS' + i + '">' + T + '</a>';
        // History icon
        if ( results[i].History != '' ) { HTML += '&nbsp;<img src="images/History-Icon.png" width="19" height="17" align="absmiddle" title="History" />'; }
        // Restrictions icon
        if ( results[i].Restrictions != '' ) { HTML += '&nbsp;<img src="images/Restriction-Icon.png" width="19" height="17" align="absmiddle" title="Restricted" />'; }        
        // Promotion icon
        if ( results[i].Promotion != '' ) { HTML += '&nbsp;<img src="images/Promo-Icon.png" width="19" height="17" align="absmiddle" title="Promotion" />'; }                
        // Quote only icon
        if ( results[i].Quote_Only = 0 ) { HTML += '&nbsp;<img src="images/Quote-Icon.png" width="19" height="17" align="absmiddle" title="Quote only" />'; }                        
        HTML += '</td>';
        HTML += '</tr>';
    }

    HTML += '<tr>';
    HTML += '<td class="tdQS_Title" id="tdQS' + i + '">&nbsp;<br /><a href="javascript: GatherNGo();" id="lnkQS' + results.length + 1 + '"><span class=spReplaceText><b>... click here for a complete list of results</b></span></a></td>';
    HTML += '</tr>';
    
    HTML += '</table>';
        
    el.innerHTML = HTML;

}

function HighlightSearchTerm(TextIn, SearchTerm) {

    var TextOut = '';
    var Pos;
    var Len
    var frag;
    var safetyCnt = 0;
    
    Pos = 0;
    Len = TextIn.length;
    
    while (Pos < Len) {
        frag = TextIn.substring(Pos, Pos + SearchTerm.length)
        if (frag.toUpperCase() == SearchTerm.toUpperCase() ) {
            TextOut = TextOut + '<span class=spReplaceText>' + frag + '</span>';
            Pos = Pos + SearchTerm.length;
        }
        else {
            TextOut = TextOut + TextIn.substring(Pos, Pos + 1);
            Pos = Pos + 1;
        }
        
        safetyCnt += 1;
        if ( safetyCnt > 200 ) { Pos = 9999 };
    
    }
    
    return TextOut;

}

function ErrorHandler(result) {
    var msg = result.get_exceptionType() + "\r\n";
    msg += result.get_message() + "\r\n";
    msg += result.get_stackTrace();
    alert(msg);
}

function TimeOutHandler(result) {
    alert("Timeout :" + result);
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.,$-";
   var IsNumber=true;
   var Char;
   
   if (sText == '' || sText == null ) { return false }
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

var _MessageBoxType;

function AddToCart(MessageBoxType) {

    var el;
    var t;
    var OkToGo = false;
    var QuoteOnly;
    var tDbl;
    var elConversion;
    var Conversion;
    var validateConversion;
    
    var SiteFlag, CustNo, Q_ID, OrderID, LineNum, strLItemNo, Qty, UnitPrice, LItemNo, ItemName, Family_ID, Selected_Category;
    var SizeRequired,ColorRequired;
    
    _MessageBoxType = MessageBoxType;
    
    // get our size and color requirement flags
    el = document.getElementById('hdSizeRequired');
    if ( el.value == 'True' ) { SizeRequired = true }
        else { SizeRequired = false }
    el = document.getElementById('hdColorRequired');
    if ( el.value == 'True' ) { ColorRequired = true }
        else { ColorRequired = false }         
    // validate that correct size and colors are selected
    if ( SizeRequired == true && ColorRequired == true ) {
        el = FindMyControl('selSize');
        t = el[el.selectedIndex].value;
        t = t.split('|');
        if ( t.length != 7 ) { alert('Please select a product size option.\n\nThe product size selection is located above the \"Add to Cart\" button.'); return; }
        el = FindMyControl('selColor');
        t = el[el.selectedIndex].value;
        t = t.split('|');
        if ( t.length != 7 ) { alert('Please select a color option.\n\nThe product color selection is located above the \"Add to Cart\" button.'); return; }
    }
    if ( SizeRequired == true && ColorRequired == false ) {
        el = FindMyControl('selSize');
        t = el[el.selectedIndex].value;
        t = t.split('|');
        if ( t.length != 7 ) { alert('Please select a product size option.\n\nThe product size selection is located above the \"Add to Cart\" button.'); return; }
    }    
    if ( SizeRequired == false && ColorRequired == true ) {
        el = FindMyControl('selColor');
        t = el[el.selectedIndex].value;
        t = t.split('|');
        if ( t.length != 7 ) { alert('Please select a color option.\n\nThe product color selection is located above the \"Add to Cart\" button.'); return; }
    }  
    if ( SizeRequired == false && ColorRequired == false ) {
        el = FindMyControl('selSize');
        t = el[el.selectedIndex].value;
        t = t.split('|');
        if ( t.length != 7 ) { alert('Please select a product size option.\n\nThe product size selection is located above the \"Add to Cart\" button.'); return; }
    }       
    // validate that something was selected
    if ( t.length != 7 ) { alert('Please select a product size option.\n\nThe product size selection is located above the \"Add to Cart\" button.'); return; }
    LItemNo = t[1];
    UnitPrice = t[2];
    UnitPrice = UnitPrice.replace('$', '');
    
    // validate qty
    validateConversion = false;
    el = FindMyControl('txtQty');  // for qty
    elConversion = FindMyControl('hdQty_Conversion'); // for conversion attribute
    if ( elConversion != false ) {
        validateConversion = true;
    }
    if ( IsNumeric(el.value) == false ) {
        alert('The quantity you have provided does not appear to be a valid number.\n\nPlease review your quantity value and make sure that is a valid number.');
        return;
    }
    Qty = el.value;
    if ( validateConversion ) {
        t = elConversion.value;
        if ( IsNumeric(t) == false ) { t = 10 }
        Conversion = parseInt(t);
        Qty = parseInt(Qty);
        if ( (Qty % Conversion) > 0 ) {
            alert('This item must be ordered in multiples of ' + String(Conversion) + '.  Please adjust the quantity you have entered to be a multiple of ' + String(Conversion) + '.');
            return;
        }
        
    }

    // grab our required values
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    el = FindMyControl('hdQ_ID');
    Q_ID = el.value;
    el = FindMyControl('hdOrderID');
    OrderID = el.value;
    LineNum = 1;
    el = document.getElementById('divMfr');
    strLItemNo = el.innerHTML;
    el = FindMyControl('hdItemName');
    ItemName = el.value;
    el = FindMyControl('hdFamily_ID');
    Family_ID = el.value;
    el = FindMyControl('hdSelected_Category');
    Selected_Category = el.value;
    el = FindMyControl('hdQuoteOnly');
    QuoteOnly = el.value;
    
    // we have a new method for determining if it is quote only or not - 5/14/2009
    // if there's not price, then it's quote, if there is a price then it's to cart
    tDbl = parseFloat(UnitPrice);
    if (tDbl <= 0 ) { QuoteOnly = 'True' }
        else { QuoteOnly = 'False' }
    
    // add via an ajax call
   Catalog.AddLineItem(SiteFlag, CustNo, Q_ID, OrderID, LineNum, strLItemNo, Qty, UnitPrice, LItemNo, ItemName, Family_ID, Selected_Category, QuoteOnly, AddToCartResults, ErrorHandler, TimeOutHandler);
     
}

function PromptForQuantity(MessageBoxType, LItemNo, ItemName, Family_ID, Selected_Category, QuoteOnly) {

    var el;
    var CartLink;
    
    // save these values
    el = document.getElementById('hdItemName');
    el.value = ItemName;
    
    grayOut(true);
    el = document.getElementById('divQuantityPromptMsg');
    el.innerHTML = 'Please enter a quantity for <b>' + ItemName + '</b>:';
    el = document.getElementById('divQuantityPrompt');
    el.style.visibility = 'visible';
    el = document.getElementById('lnkQuantityPrompt');
    if (el != null) {
        CartLink = "javascript: AddSpecificItemToCart('" + MessageBoxType + "', '" + LItemNo + "', '" + ItemName + "', '" + Family_ID + "', '" + Selected_Category + "', '" + QuoteOnly + "'); ";
        el.href = CartLink;
    }  


}

function HideQuantityPrompt() {
    el = document.getElementById('divQuantityPrompt');
    el.style.visibility = 'hidden';
    grayOut(false);
}


function AddSpecificItemToCart(MessageBoxType, LItemNo, ItemName, Family_ID, Selected_Category, QuoteOnly) {

    var el;
    var t;
    var OkToGo = false;
    var QuoteOnly;
    var tDbl;
    var elConversion;
    var Conversion;
    var validateConversion;
    var Qty = 1;
    var UnitPrice = 0.00;
    var strLItemNo = '';
    
    var SiteFlag, CustNo, Q_ID, OrderID, LineNum, strLItemNo, Qty, UnitPrice, LItemNo, ItemName, Family_ID, Selected_Category;
    var SizeRequired,ColorRequired;
    
    _MessageBoxType = MessageBoxType;
    
    HideQuantityPrompt()    
    
    // save these values
    el = document.getElementById('hdItemName');
    el.value = ItemName;
    
    // grab our required values
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    el = FindMyControl('hdQ_ID');
    Q_ID = el.value;
    el = FindMyControl('hdOrderID');
    OrderID = el.value;
    LineNum = 1;
    el = FindMyControl('txtQuantityPrompt');
    if ( el != false ) {
        Qty = el.value;
        if ( IsNumeric(Qty) == false ) {
            Qty = 1;
            el.value = 1;
        }
        else {
            Qty = parseInt(Qty);
        }    
        
    }
    
    // add via an ajax call
   Catalog.AddLineItem(SiteFlag, CustNo, Q_ID, OrderID, LineNum, strLItemNo, Qty, UnitPrice, LItemNo, ItemName, Family_ID, Selected_Category, QuoteOnly, AddToCartResults, ErrorHandler, TimeOutHandler);
     
}

function AddToCartResults(results) {

    var el;
    var HTML;
    var CartLink;
    var t;
    
    if ( results.substring(0, 5) != 'ERROR' ) {
        // show success message
        el = FindMyControl('hdItemName');
        HTML = '<b>' + el.value + '</b> was successfully added to your cart.';
        // results will contain a line count and quote/order id since it may be knew
        results = results.split('|');
        if ( results.length == 3 ) {
            // set quote count
            el = FindMyControl('divQuoteCnt');
            el.innerHTML = '(' + results[0] + ')';
            // set new id in cookie
            if ( results[1] == 'Q_ID' ) {
                document.cookie = 'Q_ID=' + results[2];
            }
            else {
                document.cookie = 'OrderID=' + results[2];
            }                
        }
        
    }
    else {
        HTML = results;
    }

    if ( _MessageBoxType == 'Regular' ) {
        if ( document.cookie.indexOf('DoNotShow=Yes') == -1 ) {
            grayOut(true);
            el = document.getElementById('divItemPageMsg');
            el.innerHTML = HTML;
            el = document.getElementById('divItemPageMsgLayer');
            el.style.visibility = 'visible';
            el = FindMyControl('hdCartLink');
            CartLink = el.value;
            el = FindMyControl('lnkViewCart');
            if (el != false) {
                el.href = CartLink;
            }
        }
    }        
    else {
        // only show this pop-up if they have not told you not to
        if ( document.cookie.indexOf('DoNotShow=Yes') == -1 ) {
            grayOut(true);
            el = FindMyControl('hdItemName');
            t = el.value;
            el = document.getElementById('spProductName');
            el.innerHTML = t;
            el = document.getElementById('divAddToQuoteMsgLayer');
            el.style.visibility = 'visible';
            el = FindMyControl('hdCartLink');
            CartLink = el.value;
            el = FindMyControl('lnkViewCart_Quote');
            if (el != false) {
                el.href = CartLink;
            }  
            el = FindMyControl('lnkViewCart');
            if (el != false) {
                el.href = CartLink;
            }                  
        }
        
        
    }
    
}

function HideItemPageMsg() {
    el = document.getElementById('divItemPageMsgLayer');
    el.style.visibility = 'hidden';
    grayOut(false);
}

function HideAddToQuoteMsgLayer() {
    el = document.getElementById('divAddToQuoteMsgLayer');
    el.style.visibility = 'hidden';
    grayOut(false);
}

function ToggleDoNotShow() {

    if ( document.cookie.indexOf('DoNotShow=Yes') > -1 ) {
        document.cookie = 'DoNotShow=No';
    }
    else {
        document.cookie = 'DoNotShow=Yes';
    }

}

function ToggleDoNotShowQuote() {

    if ( document.cookie.indexOf('DoNotShowQuote=Yes') > -1 ) {
        document.cookie = 'DoNotShowQuote=No';
    }
    else {
        document.cookie = 'DoNotShowQuote=Yes';
    }
    
}

function RemoveCartItem(Action, ID) {
    
    var el;
    
    el = FindMyControl('hdCartAction');
    el.value = Action
    
    el = FindMyControl('hdCartParam');
    el.value = ID
    
    el.form.submit();
    
}

function UpdateCart() {

    var el;
    
    el = FindMyControl('hdCartAction');
    el.value = "Update"
    
    el.form.submit();

}

function EmptyQuoteCart() {

    var el;
    
    if ( confirm('Are you sure you want to remove all items from your cart.\n\nClick Ok to continue or Cancel.') ) {
        el = FindMyControl('hdCartAction');
        el.value = "EmptyQuoteCart"
        el.form.submit();    
    }   
    
}

var _CalcStarted = false;
var _tmrPricingCalc;
var _Qty1_Price = 0;
var _ItemNo = '';

function SetItemDetails () {

    var el;
    var t;
    var SizeRequired;
    var ColorRequired;
    var img;
    var imgTag;
    var el2;
    var w;
    var h;
    var Size;
    var Color;
    var priceBreaks;
    var MyPrice;
      
    // get our size and color requirement flags
    el = document.getElementById('hdSizeRequired');
    if ( el.value == 'True' ) { SizeRequired = true }
        else { SizeRequired = false }
    el = document.getElementById('hdColorRequired');
    if ( el.value == 'True' ) { ColorRequired = true }
        else { ColorRequired = false }         
    // validate that correct size and colors are selected
    if ( SizeRequired == true && ColorRequired == true ) {
        el = FindMyControl('selColor');
        t = el[el.selectedIndex].value;
        t = t.split('|');
    }
    if ( SizeRequired == true && ColorRequired == false ) {
        el = FindMyControl('selSize');
        t = el[el.selectedIndex].value;
        t = t.split('|');
    }    
    if ( SizeRequired == false && ColorRequired == true ) {
        el = FindMyControl('selColor');
        t = el[el.selectedIndex].value;
        t = t.split('|');
    }  
    if ( SizeRequired == false && ColorRequired == false ) {
        el = FindMyControl('selSize');
        t = el[el.selectedIndex].value;
        t = t.split('|');
    }  
    // change size
    el = FindMyControl('selSize');
    Size = el[el.selectedIndex].text;
    if ( Size == 'Size' ) { Size = '' }
    el = document.getElementById('divSize');
    el.innerHTML = Size;
    // change color
    el = FindMyControl('selColor');
    Color = el[el.selectedIndex].text;
    if ( Color == 'Color' ) { Color = '' }
    el = document.getElementById('divColor');
    el.innerHTML = Color;   
    
    if ( t.length == 7 ) { 
            
            el = document.getElementById('divMfr');
            el.innerHTML = t[0];
            el = document.getElementById('divAHI');
            el.innerHTML = t[1];
            _ItemNo = t[1];
            el = document.getElementById('divPrice');
            if ( el != null ) { 
                MyPrice = t[2];
                if ( MyPrice.indexOf('.') > 0 ) {
                    MyPrice = MyPrice.substring(MyPrice.indexOf('.') + 1, MyPrice.length);
                    if ( MyPrice.length >= 4 && MyPrice.substring(MyPrice.length - 2, MyPrice.length) == '00' ) { 
                        MyPrice = t[2];
                        MyPrice = MyPrice.substring(0, MyPrice.length - 2);
                    } else {
                        MyPrice = t[2];
                    }                    
                }                
                el.innerHTML = MyPrice; 
            }
            el = document.getElementById('divQtyUnitPrice');
            if ( el != null ) { el.innerHTML = t[2]; }
            el = document.getElementById('divMyItemNo');
            if ( el != null ) { el.innerHTML = t[6]; }            
            // hide price if it is zero
            
            if ( t[2] == '$0.00' || t[2] == '$0.0000'  ) {
                el = document.getElementById('divPrice');
                if ( el != null ) { el.style.display   = 'none'; }
                el = document.getElementById('divWhyNoPrice');
                if ( el != null ) { el.style.display   = 'block'; }
                // set Add to cart or add to quote button
                el = FindMyControl('imgAddBtn');
                var QuoteBtn = new Image(115, 20);
	            QuoteBtn.src="images/AddToQuote.gif";
	            el.src = QuoteBtn.src;                
	            el = FindMyControl('lnkAddToCart');
	            el.href = "javascript: AddToCart('QuoteThing');"
	            _Qty1_Price = 0;
                el = document.getElementById('divQtyUnitPrice');
                if ( el != null ) { el.innerHTML = '<center><span style="font-size: 7pt; color: #990000;">Quote Item</span></center>'; }	            
	            
            }
            else {
                el = document.getElementById('divPrice');
                if ( el != null ) { el.style.display   = 'block'; }
                el = document.getElementById('divWhyNoPrice');
                if ( el != null ) { el.style.display   = 'none'; }
                // set Add to cart or add to quote button
                el = FindMyControl('imgAddBtn');
                var CartBtn = new Image(115, 20);
	            CartBtn.src="images/AddToCart.gif";
	            el.src = CartBtn.src;
	            el = FindMyControl('lnkAddToCart');
	            el.href = "javascript: AddToCart('Regular');"
	            _Qty1_Price = t[2];
	            _Qty1_Price = _Qty1_Price.replace('$', '');
	            _Qty1_Price = parseFloat(_Qty1_Price);
            }
            // set image
            img = t[3];
            img = img.replace('}', '\\');
            img = img.replace('}', '\\');
            img = img.replace('}', '\\');
            w = parseInt(t[4]);
            h = parseInt(t[5]);
            if (img.indexOf('.') > 0 && w > 0 ) {
            
                imgTag = '<img src="GetItemImage.aspx?i=' + escape(img) + '" width="' + w + '" height="' + h + '" alt="" />';
                el2 = document.getElementById('divItemImage');
                if ( el2 != null ) { el2.innerHTML = imgTag; }
                
            }
                       
    }
    
    // Start pricing calc if pricing present
    if ( _Qty1_Price != 0 && _CalcStarted == false) {
        _tmrPricingCalc = setTimeout('CalcPrice()', 500);
    }
            
    // set flash message
    t = LookupFlashMessage(_ItemNo);
    el = document.getElementById('divFlashMsg');
    if ( el != null ) {
        if ( t != '' ) {
            el.innerHTML = '<span style="color: #990000;">' + t + '</span>';
        }
        else {
            el.innerHTML = '';
        }
    }

}

function LookupFlashMessage(ItemNo) {

    var el;
    var FlashMessages;
    var spT;
    
    el = FindMyControl('hdFlashMessages');
    FlashMessages = el.value.split('|');
        
    for(i=0;i<=FlashMessages.length-1;i++)
    {
        spT = FlashMessages[i].split(',');
        if ( ItemNo == spT[0] ) { return spT[1] }
    } 

    return '';    
    
}

function CalcPrice() {

    var el;
    var priceBreaks;
    var spT;
    var BreakQty;
    var BreakPrice = '';
    var TotalPrice = 0;
    var html;
    var longHtml;
    var c;
    
    // Get our Qty
    el = document.getElementById('txtQty');
    Qty = el.value;
    if ( Qty == '' ) { Qty = 1; }
    if ( IsNumeric(Qty) == false ) {
        Qty = 1;
        el.value = 1;
    }
    else {
        Qty = parseInt(Qty);
    }    
    // Get price breaks
    priceBreaks = GetPriceBreaks(_ItemNo);
    
    if ( priceBreaks == 'None' ) {
        BreakPrice = _Qty1_Price;
    }
    else {
        // loop through the price breaks and find our qty
        BreakPrice = 0;
        for(i=0;i<=priceBreaks.length-1;i++)
        {
            spT = priceBreaks[i].split('-');
            BreakQty = parseInt(spT[0]);
            if ( Qty >= BreakQty ) {
                BreakPrice = spT[1];
                BreakPrice = BreakPrice.replace('$', '');
                BreakPrice = BreakPrice.replace(',', '');
                BreakPrice = parseFloat(BreakPrice);
            }
      
        } 
        // loop through again and draw the list
        html = '<div style="margin-bottom: 8px; color: #555555;"><b>Available Price Breaks:</b></div><table><tr>';
        longHtml = '<div style="margin-bottom: 8px; color: #555555;"><b>All Available Price Breaks:</b></div><table><tr>'
        for(i=0;i<=priceBreaks.length-1;i++) 
        {
            spT = priceBreaks[i].split('-');
            if ( i % 2 == 0 ) { c = 'tdPBWhite' } else { c = 'tdPBGrey' }
            if ( i <= 3 ) { html = html + '<td class="' + c + '"><b>' + spT[0] + '</b><br />' + spT[1] + '</td>'; }
            longHtml = longHtml  + '<td class="' + c + '"><b>' + spT[0] + '</b><br />' + spT[1] + '</td>';
        }
        html = html + '</tr></table>'
        if ( priceBreaks.length > 4 ) {
            html = html + '<div style="margin: 8px 0px 0px 0px; font-size: 8pt;"><a href="javascript: ShowLongPriceBreaks();"><b>view all available price breaks &gt;&gt;</b></a></div>';
        }
        longHtml = longHtml + '</tr></table>'
        // if no price breaks, set this default message
        if ( priceBreaks.length <= 1 ) { html = "NO PRICE BREAKS FOR THIS ITEM"; longHtml = html; }
        // set short html for price breaks
        el = document.getElementById('divPriceBreaks');
        if ( el != null ) { el.innerHTML = html }
        // set long html
        el = document.getElementById('divLongPriceBreaksHTML');
        if ( el != null ) { el.innerHTML = longHtml }
    }   
    
    // calc it 
    
    TotalPrice = BreakPrice * Qty
    el = document.getElementById('divQtyTotalPrice');
    if ( el != null ) { el.innerHTML = '$' + FormatNumber(TotalPrice, 4, true, false, true); }
    
    // Set the price
    el = document.getElementById('divQtyUnitPrice');
    if ( el != null ) { el.innerHTML = '$' + FormatNumber(BreakPrice, 4, true, false, true); }
    
    _tmrPricingCalc = setTimeout('CalcPrice()', 500);
}

function GetPriceBreaks(ItemNo) {

    var el;
    var pbString;
    var pb;
    
    el = FindMyControl('hdPriceBreaks');
    pbString = el.value;
    if ( pbString == '' ) { return 'None' }
    pb = pbString.split('|**EOL**');
    pbString = '';
    for(i=0;i<=pb.length-1;i++)
    {
        if ( pb[i].substring(0, ItemNo.length) == ItemNo ) {
            pbString = pb[i];
        }
    }
    if ( pbString != '' ) {
        pbString = pbString.replace(ItemNo + '|', '');
        pb = pbString.split('|');
        return pb;
    }
    else {
        return 'None';
    }
    
    
}

function ShowLongPriceBreaks() {

    var el;
    el = document.getElementById('divLongPriceBreaks');
    el.style.visibility = 'visible';

}

function HideLongPriceBreaks() {
    el = document.getElementById('divLongPriceBreaks');
    el.style.visibility = 'hidden';
}



var CurrentlySelectedText;

function RemoveAllItems(el_name) {
    var i;
    var el;
    
    el = FindMyControl(el_name);
    // grab the currently selected text
    CurrentlySelectedText = el[el.selectedIndex].text;
    for(i=el.options.length-1;i>=0;i--)
    {
        el.remove(i);
    }
}

function AddItem(el_name, txt, val) {

    var el;
    var optn;
    
    el = FindMyControl(el_name);
    optn = document.createElement('OPTION');
    optn.text = txt;
    optn.value = val;
    el.options.add(optn);
    
}

function ResetCurrentlySelectedText(el_name) {

    var i;
    var el;

    el = FindMyControl(el_name);
    for(i=0;i<=el.options.length-1;i++)
    {
        if (el.options[i].text == CurrentlySelectedText) {
            el.selectedIndex = i;
        }
    }

}


function ChangeShippingAddress() {

    var el;
    var SelectedShippingAddress;
    
    el = FindMyControl('selAltShipping');
    SelectedShippingAddress = el[el.selectedIndex].value;
    
    location.href = 'Checkout.aspx?SelectedShippingAddress=' + SelectedShippingAddress;
    
}

function ShowAddNewShippingAddress() {

    var el;
    el = document.getElementById('divAddNewShipping');
    el.style.visibility = 'visible';

}

function AddNewShippingAddress() {

    var el;
    
    el = FindMyControl('txtShipToName');
    if ( el.value.length <= 1 ) { alert('A valid ship to name is required.'); return; }
    el = FindMyControl('txtshipToAddress');
    if ( el.value.length <= 1 ) { alert('A valid address is required.'); return; }
    el = FindMyControl('txtShipToCity');
    if ( el.value.length <= 1 ) { alert('A valid city is required.'); return; }   
    el = FindMyControl('selShipToState');
    if ( el.selectedIndex <= 0 ) { alert('A valid state selection is required.'); return; }       
    el = FindMyControl('txtShipToZip');
    if ( el.value.length <= 1 ) { alert('A valid zip code is required.'); return; }   
    el = FindMyControl('hdCheckoutAction');
    el.value = 'AddAddress';
    el.form.submit()
             
}

function CompleteOrder() {

}

function CompleteQuote() {

    var el;
    
    // validate required fields
    el = FindMyControl('txtFirst_Name');
    if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid first name is required.'); return; }
    el.style.backgroundColor = '#ffffff';
    el = FindMyControl('txtLast_Name');
    if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid last name is required.'); return; }
    el.style.backgroundColor = '#ffffff';
    el = FindMyControl('txtPhone');
    if ( el.value.length < 10 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid phone number is required.'); return; }
    el.style.backgroundColor = '#ffffff';
    // Customer Number 
    el = FindMyControl('chkCustomer');
    if (el.checked == true ) {
        el = FindMyControl('txtCustomerNumber');
        if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A customer number is required when you select that you are a customer.  You may enter zeros if you do not know your customer number.'); return; }
        el.style.backgroundColor = '#ffffff';
    }
    el = FindMyControl('txtAddress1');
    if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid address is required.'); return; }
    el.style.backgroundColor = '#ffffff';
    el = FindMyControl('txtCity');
    if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid city is required.'); return; }
    el.style.backgroundColor = '#ffffff';
    el = FindMyControl('selState');
    if ( el.selectedIndex <= 0 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid state selection is required.'); return; }  
    el.style.backgroundColor = '#ffffff';
    el = FindMyControl('txtZip');
    if ( el.value.length <= 1 ) { el.style.backgroundColor = '#fbcdcf'; alert('A valid zip code is required.'); return; }
    el.style.backgroundColor = '#ffffff';

    
    el.form.submit();   
    
    
}

function SwapBGStyle(el, SiteFlag, BGStyle) {

    if ( BGStyle == 'Clear' ) {
        el.style.backgroundImage = 'url(images/' + SiteFlag + '/Username_BG.gif)';
    }
    else
    {
        if ( el.value.length <= 0 ) { el.style.backgroundImage = 'url(images/' + SiteFlag + '/Password_BG.gif)'; }
    }

}

function ToggleCustomerNumberTextBoxThatAppearsJustBelowThisCheckbox() {
    
    var el;
    
    el = FindMyControl('chkCustomer');
    if (el.checked == true ) {
        el = document.getElementById('trCustomerNumber');
        el.style.visibility = 'visible';
    }
    else {
        el = document.getElementById('trCustomerNumber');
        el.style.visibility = 'hidden';    
    }
    
}

function GatherNGo() {

    var CurrentKeyword;
    
    el = FindMyControl('txtQuickSearch');
    CurrentKeyword = el.value;
    
    if ( CurrentKeyword == 'PRODUCT SEARCH' ) { CurrentKeyword = PreviousKeyword; }
    
    if ( PreviousKeyword.length < 2 ) { alert('You must provide a valid search term to conduct a search.  Please enter a search term that is at least 2 characters in length to continue.'); return; }
    
    location.href = 'SearchResults.aspx?Keyword=' + PreviousKeyword;

}

function ToggleSort(NewSortColumn) {

    var el;
    var Keyword;
    var SortAorD;
    
    el = FindMyControl('hdSortAorD');
    if ( el.value == 'ASC' ) { SortAorD = 'DESC' }
        else { SortAorD = 'ASC' }
    el = FindMyControl('hdKeyword');
    Keyword = el.value;
    location.href = 'SearchResults.aspx?Keyword=' + escape(Keyword) + '&SortColumn=' + NewSortColumn + '&SortAorD=' + SortAorD;
        
}

function ShowContactForm() {

 PositionLayer('divContactForm', 250, 150);
 ShowLayer('divContactForm');
 grayOut(true);
 
}

function SubmitContactUs() {

    var el;
    var el2;
        
    el = FindMyControl('txtName');
    if ( el.value.length <= 3 ) {
        alert('A valid name is required to use the Contact Us Form.\n\nPlease enter a valid name to continue.'); return;
    }
    el = FindMyControl('txtEmail');
    el2 = FindMyControl('txtPhone');
    if ( el.value.length <= 4  && el2.value.length <= 5 ) {
        alert('Either a valid email or phone number is required to use the Contact Us Form.\n\nPlease enter either a valid email or phone number to continue.'); return;
    }
    el = FindMyControl('txtMessage');
    if ( el.value.length <= 3 ) {
        alert('A valid message is required to use the Contact Us Form.\n\nPlease enter a valid message to continue.'); return;
    }    
    el = FindMyControl('hdAction');
    el.value = 'ContactForm';
    el.form.submit();
       

}

function PresetItemNo(ItemNo) {

    var el;
    var selIdx = -1;
    var t;
    var GotOne = false;
    
    // preselect sizes    
    selIdx = -1;
    el = FindMyControl('selSize');
    if ( el != false ) {
       
        for (var i=0; i < el.length; i++) {
            t = el.options[i].value;
            t = t.split('|');
            if ( ItemNo == t[1] ) { selIdx = i; }
        }
       
       if ( selIdx > -1 ) {
            el.selectedIndex = selIdx;
            SetItemDetails();
            GotOne = true;
       }
       
    }
  
    // preselect color    
    selIdx = -1;
    el = FindMyControl('selColor');
    if ( el != false ) {
        
        for (var i=0; i < el.length; i++) {
            t = el.options[i].value;
            t = t.split('|');
            if ( ItemNo == t[1] ) { selIdx = i; }
        }
        
       if ( selIdx > -1 ) {
            el.selectedIndex = selIdx;
            SetItemDetails();
            GotOne = true;
       }
    }    
    
    // in order to prevent all the sizes showing, Toggle the sizes using the current color
    if (GotOne == true ) {
        el = FindMyControl('selColor');
        ToggleSizes(el);
    }
    
    el = document.getElementById('divPrice');
    if ( el != null ) {
        if ( el.innerHTML == '0' ) {
            // hide price 
            el = document.getElementById('divPrice');
            if ( el != null ) { el.style.display   = 'none'; }
            el = document.getElementById('divWhyNoPrice');
            if ( el != null ) { el.style.display   = 'block'; }
        }

    }

    
}

var _WorkingTemplateID; 

function AddToTemplate() {

    var el;
    var t;
    var tDbl;
    var PricingError = false;
        
    var SiteFlag, CustNo, Qty, ID, strLItemNo, ItemNo;
    
    // see if this item has a price
    el = document.getElementById('divPrice');
    if ( el == null ) { PricingError = true };
    if ( el != null ) {
        if ( el.style.display == 'none' || el.style.display == '' ) { PricingError = true };
    }
    if ( PricingError == true ) {
        alert('Only priced items may be added to a template.  Please double check your size and/or color options to ensure you have a priced item.');
        return;
    }    
    
    el = FindMyControl('selTemplates');
    if ( el.value == 'New' ) {
        PositionLayer('divCreateNewTemplate', 250, 150);
        ShowLayer('divCreateNewTemplate');
        return;
    }
    if ( el.value == '0' ) {
        alert('Please select a template to add the current item to \nor select <<Create New Template>> to create a new template.');
        return;
    }
    ID = el.value;
    _WorkingTemplateID = ID;
    // validate qty
    el = FindMyControl('txtQty');
    if ( el == false ) {
        el = FindMyControl('selQty');
    }
    if ( IsNumeric(el.value) == false ) {
        alert('The quantity you have provided does not appear to be a valid number.\n\nPlease review your quantity value and make sure that is a valid number.');
        return;
    }
    Qty = el.value;
    // grab our required values
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    el = document.getElementById('divMfr');
    strLItemNo = el.innerHTML;
    el = document.getElementById('divAHI');
    ItemNo = el.innerHTML;
    // add via an ajax call
    Catalog.AddItemToTemplate(SiteFlag, CustNo, ID, strLItemNo, ItemNo, Qty, AddToTemplateResults, ErrorHandler, TimeOutHandler);
     
}

function AddToTemplateResults(results) {

    var el, ItemName, HTML, TemplateName;
    
    if ( results == '0' ) {
        el = FindMyControl('hdItemName');
        ItemName = el.value;
        el = FindMyControl('selTemplates');
        TemplateName = el.options[el.selectedIndex].text;
        HTML = '<b>' + ItemName + '</b> was successfully added to your cart <b>' + TemplateName + '</b> template.';
        el = document.getElementById('divTemplateMsg');
        el.innerHTML = HTML;
        el = document.getElementById('divTemplateMsgLayer');
        el.style.visibility = 'visible';
        el = FindMyControl('lnkTemplateMsg');
        if (el != false) {
            el.innerHTML = 'View Template';
            el.href = 'ViewTemplate.aspx?ID=' + _WorkingTemplateID;
        }
        el = FindMyControl('lnkTemplateOk');
        if (el != false) {
            el.href = 'javascript: HideTemplateMsg();';
        }        
        
        
    }
    else {
        alert(results);
    }

}

var _TemplateName;

function CreateNewTemplate() {

    var el;
    var t;
    var OkToGo = false;
    var QuoteOnly;
    var tDbl;
    
    var SiteFlag, CustNo, Name, Description;
    
    // grab our values
    el = FindMyControl('txtTemplate_Name');
    if ( el.value.length <= 1 ) {
        alert('A valid template name is required.  Please enter a valid template name to continue.');
        return;
    }
    Name = el.value;
    el = FindMyControl('txtTemplate_Description');
    Description = el.value;
    // grab our required values
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    // just store this value
    _TemplateName = Name;
    
    // add via an ajax call
    Catalog.CreateNewTemplate(SiteFlag, CustNo, Name, Description, CreateNewTemplateResults, ErrorHandler, TimeOutHandler);
        
    CancelLayer('divCreateNewTemplate');   

}

function CreateNewTemplateResults(results) {

    var el;
    var HTML;
    var TemplateLink;
    var Name;
    
    if ( results.substring(0, 5) != 'ERROR' ) {
        // show success message
        HTML = 'Your template named <b>' + _TemplateName + '</b> was successfully created.';
        // add the newly added item as an element of the selTemplates
        el = FindMyControl('selTemplates');
        if ( el != false ) {
            var opt = document.createElement("option");        
            opt.text = _TemplateName;
            opt.value = results;
            el.options.add(opt);
            // pre select it
            for (var i = 0; i < el.length; i++) {
                if ( el.options[i].value == results ) {
                    el.selectedIndex = i;
                }
            }            
        }
        
    }
    else {
        HTML = results;
    }
    el = document.getElementById('divTemplateMsg');
    el.innerHTML = HTML;
    el = document.getElementById('divTemplateMsgLayer');
    el.style.visibility = 'visible';
    el = FindMyControl('lnkTemplateMsg');
    if (el != false) {
        el.href = 'javascript: AddToTemplate();';
        el.innerHTML  = 'Add Item to Template';
        //el.href = 'http://order4.animalhealthpros.com/Templates/TempMain.asp';
    }
    el = FindMyControl('lnkTemplateOk');
    if (el != false) {
        el.href = 'javascript: ConfirmTemplateAdd();';
    }    
    
}

function ConfirmTemplateAdd() {

    if ( confirm('If you wish to add the current item to your newly created template, be sure to click \"Add Item to Template\" on this screen.\n\nClick \"Cancel\" to continue and not add the current item to your template.') ) {
        return;
    }
    HideTemplateMsg();
    return;
    

}

function HideTemplateMsg() {
    el = document.getElementById('divTemplateMsgLayer');
    el.style.visibility = 'hidden';
}

function CheckAll() {

      var inputs = document.getElementsByTagName ('input');
      if (inputs) {
        for (var i = 0; i < inputs.length; ++i) {
          if (inputs[i].type == 'checkbox')
                {
                    inputs[i].checked = true;
                } 
          }        
      }    

}

function UnCheckAll() {

      var inputs = document.getElementsByTagName ('input');
      if (inputs) {
        for (var i = 0; i < inputs.length; ++i) {
          if (inputs[i].type == 'checkbox')
                {
                    inputs[i].checked = false;
                } 
          }        
      }

  }
  
function DeleteSelectedTemplateItems() {

      var ToBeDeleteds = '';
      var el;
      var GotOne = false;
                  
      var inputs = document.getElementsByTagName ('input');
      if (inputs) {
        for (var i = 0; i < inputs.length; ++i) {
          if (inputs[i].type == 'checkbox')
                {
                    if ( inputs[i].checked == true ) { ToBeDeleteds = ToBeDeleteds + inputs[i].value + ','; GotOne = true; }
                } 
          }        
      }
      
    if ( GotOne == false ) { alert('You must select at least one item in order to delete.'); return; }
    
    if ( confirm('Are you sure you want to delete the selected items.\n\nClick \"Ok\" to continue or cancel.') ) {
        el = FindMyControl('hdAction');
        el.value = 'DeleteSelectedItems';
        el = FindMyControl('hdParam');
        el.value = ToBeDeleteds;
        el.form.submit();
    }    
}

function DeleteTemplate() {

    if ( confirm('Are you sure you want to delete this template.\n\nClick \"Ok\" to continue or cancel.') ) {
        el = FindMyControl('hdAction');
        el.value = 'DeleteTemplate';
        el.form.submit();
    }    
    
}

function AddSelectedTemplateItemsToCart() {

    var el;
    var elConversion;
    var CustNo;
    var Q_ID;
    var OrderID;
    var ItemsList = '';
    var Qty;
    var T;
    var GotOne = false;

    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    el = FindMyControl('hdQ_ID');
    Q_ID = el.value;
    el = FindMyControl('hdOrderID');
    OrderID = el.value;
          
      var inputs = document.getElementsByTagName ('input');
      if (inputs) {
        for (var i = 0; i < inputs.length; ++i) {
            if ( inputs[i].id.indexOf('_Qty') > 0 ) {
                Qty = inputs[i].value;
                if ( IsNumeric(Qty) == true && Qty != '' ) {
                        GotOne = true
                        // before we continue adding, we need to validate that this item does not have a QTY restriction
                        elConversion = FindMyControl(inputs[i].id.replace('_Qty', '_Conversion'));
                        if (elConversion != false) {
                        
                        
                            T = elConversion.value;
                            if (IsNumeric(T) == false) { T = 10 }
                            Conversion = parseInt(T);
                            Qty = parseInt(Qty);
                            if ((Qty % Conversion) > 0) {
                                inputs[i].style.backgroundColor = "IndianRed";
                                alert('This highlighted item must be ordered in multiples of ' + String(Conversion) + '.  Please adjust the quantity you have entered to be a multiple of ' + String(Conversion) + '.');
                                return;
                            }
                            else {
                                inputs[i].style.backgroundColor = "White";
                            }
                        
                        
                        }
                        el = FindMyControl(inputs[i].id.replace('_Qty', '_SelectedParams'));
                        T = el.value
                        T = T.replace('{Qty}', Qty)
                        ItemsList = ItemsList + T + '|*|';
                
                }
            }

          }        
      }

      
    if ( GotOne == false ) {
        alert('Make sure you have entered a quantity on at least one item that you would like to add to your cart.');
        return;
    }
    
    // add via an ajax call
   Catalog.AddMultipleLineItem(CustNo, Q_ID, OrderID, ItemsList, AddSelectedTemplateItemsToCartResults, ErrorHandler, TimeOutHandler);
}

function AddSelectedTemplateItemsToCartResults(results) {

    var el;
    var HTML;
    var CartLink;
    var T;
    
    if ( results.substring(0, 5) != 'ERROR' ) {
        results = results.split('|*|');
        if ( results.length == 7 ) {
            // set quote count
            el = FindMyControl('divQuoteCnt');
            el.innerHTML = '(' + results[5] + ')';
            // set new ids in cookie
            if ( results[1] != '0' ) {
                document.cookie = 'Q_ID=' + results[1];
            }
            if ( results[3] != '0' ) {
                document.cookie = 'OrderID=' + results[3];
            }
            HTML = "<p>The following items were successfully added to your cart:</p>";
            HTML = HTML + "<p><b>";
            T = results[6];
            T = T.split('|');
            for (var i = 0; i < T.length; i++) {
                HTML = HTML + T[i] + '<br />';
            }
            HTML = HTML + "</b></p>";
            
            
        }
        
    }
    else {
        HTML = results;
    }
    el = document.getElementById('divTemplateMsg');
    el.innerHTML = HTML;
    el = document.getElementById('divTemplateMsgLayer');
    el.style.visibility = 'visible';
    
    el = FindMyControl('hdCartLink');
    CartLink = el.value;
    el = FindMyControl('lnkTemplateMsg');
    if (el != false) {
        el.href = CartLink;
    }
    el = FindMyControl('lnkTemplateOk');
    if (el != false) {
        el.href = 'javascript: HideTemplateMsg();';
    }        
    
    
    el = FindMyControl('lnkCart');
    if (el != false) {
        el.href = CartLink;
    }    
 

}

var _HavePrice = false;

function AddSelectedItemsToCart() {

    var el;
    var CustNo;
    var Q_ID;
    var OrderID;
    var ItemsList = '';
    var Qty;
    var T;
    var GotOne = false;
    var elConversion;

    el = FindMyControl('hdCustNo');
    CustNo = el.value;    
    el = FindMyControl('hdQ_ID');
    Q_ID = el.value;
    el = FindMyControl('hdOrderID');
    OrderID = el.value;
    _HavePrice = false;
          
      var inputs = document.getElementsByTagName ('input');
      if (inputs) {
        for (var i = 0; i < inputs.length; ++i) {
            if ( inputs[i].id.indexOf('_Qty') > 0 ) {
                Qty = inputs[i].value;
                inputs[i].value = 0;  //clear it for the next pass/use
                if ( Qty == '0' ) { Qty = ''; }
                if ( IsNumeric(Qty) == true && Qty != '' ) {
                        GotOne = true
                        
                        // before we continue adding, we need to validate that this item does not have a QTY restriction
                        elConversion = FindMyControl(inputs[i].id.replace('_Qty', '_Conversion'));
                        if (elConversion != false) {
                        
                        
                            T = elConversion.value;
                            if (IsNumeric(T) == false) { T = 10 }
                            Conversion = parseInt(T);
                            Qty = parseInt(Qty);
                            if ((Qty % Conversion) > 0) {
                                inputs[i].style.backgroundColor = "IndianRed";
                                alert('This highlighted item must be ordered in multiples of ' + String(Conversion) + '.  Please adjust the quantity you have entered to be a multiple of ' + String(Conversion) + '.');
                                return;
                            }
                            else {
                                inputs[i].style.backgroundColor = "White";
                            }
                        
                        
                        }                        
                        
                        // check for price, we now have to show 1 of 30 different pop ups based on the presence of a price
                        el = document.getElementById(inputs[i].id.replace('_Qty', '_Price'));
                        if ( el != null ) {
                            T = el.innerHTML;
                            if ( T.indexOf('$') > -1 ) { _HavePrice = true }
                        }
                        
                        el = FindMyControl(inputs[i].id.replace('_Qty', '_SelectedParams'));
                        T = el.value
                        T = T.replace('{Qty}', Qty)
                        ItemsList = ItemsList + T + '|*|';
                }
            }

          }        
      }
      
    if ( GotOne == false ) {
        alert('Make sure you have entered a quantity on at least one item that you would like to add to your cart.');
        return;
    }

    // add via an ajax call
   Catalog.AddMultipleLineItem(CustNo, Q_ID, OrderID, ItemsList, AddSelectedItemsToCartResults, ErrorHandler, TimeOutHandler);
}

function AddSelectedItemsToCartResults(results) {

    var el;
    var HTML;
    var CartLink;
    var cartName;
    var T;
    
    if ( _HavePrice == true ) { cartName = 'cart' } else { cartName = 'quote' }
    
    if ( results.substring(0, 5) != 'ERROR' ) {
        results = results.split('|*|');
        if ( results.length == 7 ) {
            // set quote count
            el = FindMyControl('divQuoteCnt');
            el.innerHTML = '(' + results[5] + ')';
            // set new ids in cookie
            if ( results[1] != '0' ) {
                document.cookie = 'Q_ID=' + results[1];
            }
            if ( results[3] != '0' ) {
                document.cookie = 'OrderID=' + results[3];
            }
            HTML = "<p>The following items were successfully added to your " + cartName + ":</p>";
            HTML = HTML + "<p><b>";
            T = results[6];
            T = T.split('|');
            for (var i = 0; i < T.length; i++) {
                HTML = HTML + T[i] + '<br />';
            }
            HTML = HTML + "</b></p>";
            
        }
        
    }
    else {
        HTML = results;
    }    
 
    if ( _HavePrice == true ) {
        if ( document.cookie.indexOf('DoNotShow=Yes') == -1 ) {   
        
            el = document.getElementById('divSearchCartMsg');
            el.innerHTML = HTML;
            PositionLayer('divSearchCartMsgLayer', 300, 300);
            el = document.getElementById('divSearchCartMsgLayer');
            el.style.visibility = 'visible';
            grayOut(true);
            
            el = FindMyControl('hdCartLink');
            CartLink = el.value;
            el = FindMyControl('lnkTemplateMsg');
            if (el != false) {
                el.href = CartLink;
            }
               
            el = FindMyControl('lnkCart');
            if (el != false) {
                el.href = CartLink;
            }    
            
        }
    } else {
        if ( document.cookie.indexOf('DoNotShowQuote=Yes') == -1 ) {       
        
            grayOut(true);
            el = document.getElementById('spProductName');
            el.innerHTML = HTML;
            el = document.getElementById('divAddToQuoteMsgLayer');
            el.style.visibility = 'visible';
            el = FindMyControl('hdCartLink');
            CartLink = el.value;
            el = FindMyControl('lnkViewCart_Quote');
            if (el != false) {
                el.href = CartLink;
            } 
        }       
}
 
}

function HideSearchCartMsg() {
    el = document.getElementById('divSearchCartMsgLayer');
    el.style.visibility = 'hidden';
    grayOut(false);
}

function GetSearchingFor() {

    var el;

    document.forms[0].submit();    

}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    var pageWidth = getW() + 'px'; 
    var pageHeight = getH() + 'px';
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } 
  else {
     dark.style.display='none';
    }
}

function getW(){
    var w;
    if(document.innerWidth){ w=document.innerWidth;
    } else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
    } else if(document.body){ w=document.body.clientWidth; }
    return w;
}

function getH(){
    var h;
    if(document.innerHeight){ h=document.innerHeight;
    } else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
    } else if(document.body){ h=document.body.clientHeight; }
    return h;
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}




function ShowForgotMessage() {

    var el;
    el = document.getElementById('divForgotMsgLayer');
    el.style.visibility = 'visible';

}

function HideForgotMessage() {
    el = document.getElementById('divForgotMsgLayer');
    el.style.visibility = 'hidden';
}

var _PrevBGColor;
var _ItemNo;
var _ItemLong;
var _CustNo;

function ShowMyItemNoEditButtons(MyItemNo, MyID) {

    var el;
    
    el = document.getElementById('td' + MyID);
    if (el == null ) { el = document.getElementById('tdMyItemNo'); }
    _PrevBGColor = el.style.backgroundColor;
    el.style.backgroundColor = '#ffffce';
    
    // set image
    el = document.getElementById('img' + MyID);
    if ( MyItemNo == '' ) { el.src = Add_R.src; }
        else { el.src = Edit_R.src; }    

}

function HideMyItemNoEditButtons(MyItemNo, MyID) {

    var el;
    
    el = document.getElementById('td' + MyID);
    if (el == null ) { el = document.getElementById('tdMyItemNo'); }
    el.style.backgroundColor = _PrevBGColor
    
    // set image
    el = document.getElementById('img' + MyID);
    el.src = None_R.src; 

}

function EditMyItemNo(MyItemNo, ItemNo, ItemLong, CustNo, MyID) {

     var el,left,top;    
     
     // if itemno is zero, then lookup
     if ( ItemNo == '0' ) {
            el = document.getElementById('divAHI');
            ItemNo = el.innerHTML;     
            el = document.getElementById('divMfr');
            ItemLong = el.innerHTML;
     }
     
     // save these values
     _ItemNo = ItemNo;
     _CustNo = CustNo;
     _ItemLong = ItemLong;
    
    // set our value in the form 
    el = document.getElementById('txtMyItemNo');   
    el.value = MyItemNo;
 
    // Find the form and set it's POS
    el = document.getElementById('img' + MyID);
    if (el != null) {
         t = findPos(el);
         left = parseInt(t[0]);
         top = parseInt(t[1]);
    }  
    else {
        left = 100;  
        top = 100; 
    }       
    
    left = left - 80;
    top = top + 3;  
    
    el = document.getElementById('divEditMyItemNo');   
    el.style.top = String(top) + 'px';
    el.style.left = String(left) + 'px';
    el.style.visibility = 'visible';
    
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function SaveMyItemNo() {

    var el;
    var MyItemNo;
    
    el = document.getElementById('txtMyItemNo');   
    MyItemNo = el.value;
    
    // set this in the HTML page
    el = document.getElementById('td' + _ItemNo);   
    if (el == null ) { el = document.getElementById('tdMyItemNo'); }
    el.innerHTML = MyItemNo;
    
    CancelLayer('divEditMyItemNo');
    
   
    Catalog.SaveMyItemNo(MyItemNo, _ItemNo, _ItemLong, _CustNo, SaveMyItemNoResults, ErrorHandler, TimeOutHandler);
        
}

function SaveMyItemNoResults(results) {

    if ( results != 'Ok' && results != '' && results != '0' ) { alert(results); }
}

function QuickLinkNav(link) {

    recordOutboundLink(link, 'Quick Link', 'Nav');
}

function recordOutboundLink(link, category, action) {
  try {
  
    //var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-10233532-1']); _gaq.push(['_setDomainName', '.animalhealthpros.com']); _gaq.push(['_setAllowHash', false]); _gaq.push(['_trackPageview']); (function () { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
    _gaq.push(['_trackEvent', category, action, link]);
    setTimeout('document.location = "' + link + '"', 500)
    
  } catch(err){}
}

function DoInvoiceSearch() {

    var el;
    var SiteFlag = '';
    var Action = '';
    var Param = '';
    var CustNo = '';
    var Date1 = '';
    var Date2 = '';
        
    clearTimeout(Tmr1);
    
    // Get dates and params   
    el = FindMyControl('hdCustNoForSearching');
    CustNo = el.value;
    el = FindMyControl('hdSiteFlag');
    SiteFlag = el.value;
    el = document.getElementById('txtDate1');
    Date1 = el.value;
    el = document.getElementById('txtDate2');
    Date2 = el.value;    
    SiteFlag = el.value;    
    
    if ( Date1.length > 4 ) {
        el = document.getElementById('divDateRange');
        el.innerHTML = 'Transactions from ' + Date1 + ' through ' + Date2;
    }
    
    
    el = document.getElementById('imgWaiting');
    el.style.visibility = 'visible';
    
    Catalog.SearchInvoices(SiteFlag, CustNo, Date1, Date2, Param, DrawInvoiceSearchResults, ErrorHandler, TimeOutHandler);

}

function DrawInvoiceSearchResults(results) {

    var el;
    var HTML;
    var T;
    var KeywordHold;
    var classname;
    var link;
    
    // hide the waiting image
    el = document.getElementById('imgWaiting');
    el.style.visibility = 'hidden';    
        
    // run the rows
   HTML = '<table class="tblIS">';
   HTML += '<tr>';
    HTML += '<td class="tdIS_CH">&nbsp;</td>';
    HTML += '<td class="tdIS_CH">Order Date</td>';
    HTML += '<td class="tdIS_CH">Order Number</td>';
    HTML += '<td class="tdIS_CH">Order Type</td>';
    HTML += '<td class="tdIS_CH">Customer PO</td>';        
    HTML += '<td class="tdIS_CH">Shipped To</td>';                
    HTML += '<td class="tdIS_CH">Total</td>';                
    HTML += '</tr>';    
    // Run the rows
    for (var i = 0; i < results.length; i++) {
        HTML += '<tr>';
        // set class name
        if ( (i % 2) == 0 ) { classname = 'tdIS_Title' }
            else { classname = 'tdIS_Title_gray' }
        // build up link
        link = 'javascript: ShowInvoiceAsHTML(\'' + results[i].CustomerNumber + '\', \'' + results[i].StartLineID + '\', \'' + results[i].EndLineID + '\');';
                    
        HTML += '<td class="' + classname + '"><a href="' + link + '" id="lnkQS' + i + '">Details</a></td>';
        // Order Date
        HTML += '<td class="' + classname + '">' + results[i].OrderDate + '</td>';
        // Order Number
        HTML += '<td class="' + classname + '">' + results[i].OrderNumber + '</td>';
        // Order Type
        HTML += '<td class="' + classname + '" title="' + results[i].DocTypeDescription + '">' + results[i].OrderType + '</td>';
        // Customer PO
        HTML += '<td class="' + classname + '">' + results[i].CustomerPO + '</td>';        
        // Shipped To
        HTML += '<td class="' + classname + '">' + results[i].ShippedTo + '</td>';                
        // Total
        HTML += '<td class="' + classname + '" align="right">$' + results[i].Total + '</td>';                
        HTML += '</tr>';
    }

   
    HTML += '</table>';
    
    el = document.getElementById('divResults');        
    el.innerHTML = HTML;

}

function ShowInvoiceAsHTML(CustomerNumber, StartLineID, EndLineID) {

    var el;
    
    el = document.getElementById('hdStartLineID');
    el.value = StartLineID;
    
    el = document.getElementById('hdEndLineID');
    el.value = EndLineID;
    
    Catalog.GetInvoice(CustomerNumber, StartLineID, EndLineID, "HTML", DrawInvoice, ErrorHandler, TimeOutHandler);    
}

function DrawInvoice(results) {

    var el;

    grayOut(true);

    PositionLayer('divInvoiceDetail', 550, 50)
    
    el = document.getElementById('divInvoiceLines');
    el.innerHTML = '<pre style="font-size: 8pt;">' + results + '</pre>';
    
}

function HideInvoiceDetail() {

    var el;

    grayOut(false);

    el = document.getElementById('divInvoiceDetail');
    el.style.left = '-1500px';
    
}

function HideSelectDateRange() {

    el = document.getElementById('divSelectDateRange');
    el.style.left = '-1500px';
}

function ShowDateRange() {
        PositionLayer('divSelectDateRange', 550, 450)
}

function SetDateRange(Range_Type) {

    var date1;
    var date2;
    var el;
   
    date1 = new Date;
    date2 = new Date;
    
    if (Range_Type == '30' ) { date1.setDate(date1.getDate() - 30); }
    if (Range_Type == '60' ) { date1.setDate(date1.getDate() - 60); }
    if (Range_Type == '90' ) { date1.setDate(date1.getDate() - 90); }
    
    el = document.getElementById('txtDate1');
    el.value = date1.getMonth() + 1 + '/' + date1.getDate() + '/' + date1.getFullYear();
    el = document.getElementById('txtDate2');
    el.value = date2.getMonth() + 1 + '/' + date2.getDate() + '/' + date2.getFullYear();
    
    DoInvoiceSearch()
    
}

function PrintInvoiceDetail() {

    var CustNo,StartLineID,EndLineID,el,link;
    var PDFWindow;
    
    el = FindMyControl('hdCustNoForSearching');
    CustNo = el.value;
    
    el = document.getElementById('hdStartLineID');
    StartLineID = el.value;
    
    el = document.getElementById('hdEndLineID');
    EndLineID = el.value;
    
    link = 'PDFme.aspx?Mode=Invoice&S=' + StartLineID + '&E=' + EndLineID;
    
    // pop-up preview URL
	PDFWindow = window.open(link, 'PDF', 'scrollbars=auto,width=800,height=570,toolbar=no,location=no,directories=no,location=no;status=no,resizable=yes');
    PDFWindow.focus()
        
}

function DownloadHistory() {

    var el,link;
    var PDFWindow;
    var Date1,Date2;
    
    el = document.getElementById('txtDate1');
    Date1 = el.value;
    el = document.getElementById('txtDate2');
    Date2 = el.value;
    
    link = 'PDFme.aspx?Mode=History&Date1=' + Date1 + '&Date2=' + Date2;
    
    // pop-up preview URL
	PDFWindow = window.open(link, 'PDF', 'scrollbars=auto,width=800,height=570,toolbar=no,location=no,directories=no,location=no;status=no,resizable=yes');
    PDFWindow.focus()
    
}

function SubmitBillingUpdateForm() {
    var el;
    
    document.forms[0].submit();
}

function ShowAddressBook() {

    grayOut(true);
    PositionLayer('divAddressBook', 300, 100);

}

function HideAddressBook() {

    grayOut(false);
    PositionLayer('divAddressBook', -1200, 100);

}

function TurnMeGrey(tdID) {

    var el;
    
    // reset all to white
	var frmElements,i,t,ctl;
	
   // Still not found, scan through all of the textarea elements
    frmElements=document.getElementsByTagName('td');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        if (t.indexOf('tdAddressManagerRow') > -1 )
            { frmElements[i].className = 'tdAddressManagerRow' }
    }          
    
    // turn the selected one to grey    
    el = document.getElementById(tdID);
    if ( el != null ) {
        el.className = 'tdAddressManagerRowGrey';
    }        
    
}

function SetUpdateForm(updateType, CustNo, Name, Address, Address2, City, State, Zip) {

    var el;
    var ShowStyle = 'table-row';

    if (navigator.appVersion.indexOf('MSIE 7') > 0 || navigator.appVersion.indexOf('MSIE 8') > 0 || navigator.appVersion.indexOf('MSIE 9') > 0) { ShowStyle = 'inline'; }
    else { ShowStyle = 'table-row'; }   
    
    ShowStyle = 'table-row'; 

    document.getElementById('txtName').value = Name;
    document.getElementById('txtAddress').value = Address;
    document.getElementById('txtAddress2').value = Address2;
    document.getElementById('txtCity').value = City;
    el = FindMyControl('selState');
    for(i=0;i<=el.options.length-1;i++)
    {
        if (el.options[i].text == State) {
            el.selectedIndex = i;
        }
    }
    document.getElementById('txtZip').value = Zip;    
    
    el = FindMyControl('hdAB_Param');
    el.value = updateType;
    
    el = FindMyControl('hdAB_CustNo');
    el.value = CustNo;    
    
    if ( updateType == 'add' ) {
        el = document.getElementById('trPhone');
        el.style.display = ShowStyle;
        el = document.getElementById('trInCity');
        el.style.display = ShowStyle;
        el = document.getElementById('trCounty');
        el.style.display = ShowStyle;   
        TurnMeGrey('');     
    } else {
        el = document.getElementById('trPhone');
        el.style.display = 'none';
        el = document.getElementById('trInCity');
        el.style.display = 'none';
        el = document.getElementById('trCounty');
        el.style.display = 'none';
    }    
}

function ValidateAddressBookEntry() {

    var el;
    var CustNo, Name, Address, Address2, City, State, Zip, Phone, InCity, County;
    var updateType;
    
    Name = document.getElementById('txtName').value;
    if ( Name.length <= 2 ) { alert('Name is a required field.'); return; }
    Address = document.getElementById('txtAddress').value;
    if ( Address.length <= 2 ) { alert('Address is a required field.'); return; }
    Address2 = document.getElementById('txtAddress2').value;
    City = document.getElementById('txtCity').value;
    if ( City.length <= 2 ) { alert('City is a required field.'); return; }
    el = FindMyControl('selState');
    State = el[el.selectedIndex].value;
    Zip = document.getElementById('txtZip').value; 
    if ( Zip.length <= 2 ) { alert('Zip is a required field.'); return; }
    Phone = document.getElementById('txtPhone').value; 
    el = FindMyControl('selInCity');
    InCity = el[el.selectedIndex].value;
    County = document.getElementById('txtCounty').value; 
   
    el = FindMyControl('hdAB_Param');
    updateType = el.value;
    
    if ( updateType == 'add' ) {
        if ( Phone.length <= 2 ) { alert('Phone is a required field.'); return; }
        if ( County.length <= 2 ) { alert('County is a required field.'); return; }
    }       
    
    el = FindMyControl('hdAB_CustNo');
    CustNo = el.value;
    
    Catalog.UpdateAddress(CustNo, updateType, Name, Address, Address2, City, State, Zip, Phone, InCity, County, UpdateAddressResults, ErrorHandler, TimeOutHandler);        
}

function UpdateAddressResults(results) {

    var el;
    
    el = FindMyControl('hdAB_Param');
    updateType = el.value;
    
    if ( updateType == 'add' ) {
        document.getElementById('txtName').value = '';
        document.getElementById('txtAddress').value = '';
        document.getElementById('txtAddress2').value = '';
        document.getElementById('txtCity').value = '';
        el = FindMyControl('selState');
        el.selectedIndex = 0;
        document.getElementById('txtZip').value = ''; 
        document.getElementById('txtPhone').value = '';
        document.getElementById('txtCounty').value = '';
    }       

    alert(results);
    
}

function SaveCheckerSetting(Setting) {

    var el;
    var SettingValue = '';
    var CustNo;
    
    el = FindMyControl('hdCustNoForSearching');
    CustNo = el.value;    
    
    if ( Setting == 'HideQuoteItems') {
        el = FindMyControl('chkHideQuoteItems');
        if ( el.checked == true ) { SettingValue = 'Yes' }
            else { SettingValue = 'No' }
        Catalog.UpdateCustomerCheckerSetting(CustNo, Setting, SettingValue, SaveCheckerSettingResults, ErrorHandler, TimeOutHandler);        
    }
}

function SaveCheckerSettingResults(results) {
    if ( results != 'Ok' ) { alert(results) }
}
