
	function changePerPage(num, url) {
		window.location = url+num;
	}
	
	function changePage(num, url) {
		window.location = url+num;
	}

function setActiveTab(e)
{
  document.getElementById('tab1').className = ''
  document.getElementById('tab1content').style.display = 'none'
  document.getElementById('tab2').className = ''
  document.getElementById('tab2content').style.display = 'none'
  document.getElementById('tab3').className = ''
  document.getElementById('tab3content').style.display = 'none'
  document.getElementById('tab4').className = ''
  document.getElementById('tab4content').style.display = 'none'
  e.className = 'selected'
  document.getElementById(e.id+'content').style.display = 'block'
}

function addToCart(str)
{
  document.getElementById('add-to-cart-products').value=str
  document.getElementById('add-to-cart-form').submit()
}

function removeFromCart(id)
{
  if(confirm('Are you sure you want to remove this product from your cart?'))
  {
    document.getElementById('remove-from-cart-product').value=id
    document.getElementById('remove-from-cart-form').submit()
  }
}

function removeBundleFromCart(num)
{
  if(confirm('Are you sure you want to remove this package from your cart?'))
  {
    document.getElementById('remove-from-cart-bundle').value=num
    document.getElementById('remove-from-cart-form').submit()
  }
}

function fullImage(img)
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('/fullpic.php?"+img+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizeable=1');");
}

function emailProduct(productid)
{
	sender = document.getElementById('email-form-sender').value
	emailfrom = document.getElementById('email-form-emailfrom').value
	emailto = document.getElementById('email-form-emailto').value
	message = document.getElementById('email-form-message').value
	
	if(emailto == '') return;
	
	request = 'sender='+sender+'&emailfrom='+emailfrom+'&emailto='+emailto+'&message='+message+'&productid='+productid
	
	ajax.request('email.product.php', 'email-form-confirm', request)
}

function setVehicleCookie(year, make, model)
{
   if(isInt(year) && isInt(make) && isInt(model))
   {
     var today = new Date();
     var expire = new Date();
     nDays = 60;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     vehicle = year+'-'+make+'-'+model
    
     document.cookie = "vehicle="+vehicle
                     + ";expires="+expire.toGMTString();
   }
}

function unsetVehicleCookie()
{
  document.cookie = "vehicle=null;expires=-1000"
}

function compareSelected()
{
  checkboxes = document.getElementsByName('compare')
  
  loc = "/compare/"
  
  for(i=0; i<checkboxes.length; i++)
  {
    if(checkboxes[i].checked)
    {
      loc += checkboxes[i].value+','
    }
  }
  
  window.location = loc
}

function activatePackageBuilder()
{
  document.getElementById('hidden-packages-form').style.display='block'
  document.getElementById('package-msg').innerHTML = '<h3 style="text-align:center;">Choose one of each accessory to this hitch for maximum savings!</h3>'
}

function updatePrimaryImage(img, ssl)
{
  wrapper = document.getElementById('primary-image-wrapper')

	protocol = ssl ? "https://" : "http://";
  wrapper.innerHTML 
  = '<a href="javascript:fullImage(\''+img+'\')">'
  + ' <img style="padding:0; margin:0;" class="primary-image" src="'+protocol+'hfi-assets.kdsi.net/product_img/170/'+img+'"/>'
  + '</a>'
  + '<a href="javascript:fullImage(\''+img+'\')" class="click-for-instructions">'
  +			'<img src="/img/camera.gif" class="search-glass"/>'
  +			'<span style="font-size: 12px;">View Larger Image</span>'
  +		'</a>';
}

function imageSelected(count, image) {
	
	for(i=1; i<5; i++) {
		if(i == count) {
			document.getElementById('image'+i).style.display = 'block';
			document.getElementById('view-large-image').href = 'javascript:fullImage(\''+image+'\')';
			document.getElementById('primary-image-link').href = 'javascript:fullImage(\''+image+'\')';
		} else {
			if(document.getElementById('image'+i)) {
				document.getElementById('image'+i).style.display='none';
			}
		}	
	}

	
}
function showProduct(pn, show, ssl)
{
  if(ssl == true)
  {
  	secure = 'true'
  }
  else
  {
  	secure = 'false'
  }
  
  request = 'partnumber='+pn+'&secure='+secure
  
  if(show)
  {
    timer=setTimeout("ajax.request('show.product.php', 'product-"+pn+"',request)",300);
  }
  else if(timer)
	{
	  clearTimeout(timer);
	  timer=null;
	  document.getElementById('product-'+pn).innerHTML = ''
	}  
	else
	{
	 document.getElementById('product-'+pn).innerHTML = ''
	}

}

function showCart(pnstr, show)
{
  pns = new Array()
  pns = pnstr.split(',')
  
  pnArrayStr = ''
  for(i=0; i<pns.length; i++)
  {
    pnArrayStr += '&pns[]='+pns[i] 
  }
  
  request = 'thing=thing'+pnArrayStr
  if(show)
  {
    timer=setTimeout("ajax.request('show.cart.php', 'show-cart',request)",300);
  }
  else if(timer)
	{
	  clearTimeout(timer);
	  timer=null;
	  document.getElementById('show-cart').innerHTML = ''
	}  
	else
	{
	 document.getElementById('show-cart').innerHTML = ''
	} 
}

function toggleBillingInfo(checked)
{
  billingTable = document.getElementById('billing-info')
  billingInputs = billingTable.getElementsByTagName('input')
  billingSelects = billingTable.getElementsByTagName('select')
  
  shippingTable = document.getElementById('shipping-info')
  shippingInputs = shippingTable.getElementsByTagName('input')
  shippingSelects = shippingTable.getElementsByTagName('select')

  if(checked)
  {
    for(i=0; i<billingInputs.length; i++)
    {
      billingInputs[i].value = shippingInputs[i].value
    }
    
    for(j=0; j<billingSelects.length; j++)
    {
      billingSelects[j].value = shippingSelects[j].value
    }
  }
  else
  {
    for(i=0; i<billingInputs.length; i++)
    {
      billingInputs[i].disabled = false
    }
    
    for(j=0; j<billingSelects.length; j++)
    {
      billingSelects[j].disabled = false
    }  
  }
}

function showCartShipping(productIds, zipCode)
{
  if(zipCode != '')
  {
		if(zipCode.length < 5)
		{
			return alert('Your zip code must be 5 digits in length')
		}
    shippingCalc = document.getElementById('shipping-calc')
    shippingCalc.innerHTML = '<h4>Contacting UPS...</h4>';
    shippingCalc.style.height = '160px';
    img = document.getElementById('enter-zipcode-img')
    img.src = '/img/select_shipping.gif';
    request = 'productIds='+productIds+'&zipcode='+zipCode
    ajax.request('calc.shipping.php', 'shipping-calc', request);
  }
}

//
//	Show product shipping
//-----------------
	function showProductShipping(zipCode, productId)
	{

		
		if(zipCode.length != 5) {
			return alert('Please enter a 5 digit zip code.');
		}
    
	//	zipCode = String(parseInt(zipCode));	
	
		shippingCalc = document.getElementById('shipping-calc')
		shippingCalc.innerHTML = '<h4>Contacting UPS...</h4>';
		
		ajax.request('calcProductShipping', 'shipping-calc', 
			'zip='+zipCode+'&product_id='+productId);
		return;
	}

function showReviewShipping(productIds, zipCode)
{
  if(zipCode != '')
  {
    request = 'productIds='+productIds+'&zipcode='+zipCode
    ajax.request('calc.shipping.php', 'shipping-calc', request);
  }
}

function updateSubTotal(amount, page, type)
{
  if(page == 'cart')
  {
  	
    subTotal = document.getElementById('sub-total')
    origSubTotal = document.getElementById('original-sub-total').innerHTML
    newSubTotal = parseFloat(origSubTotal) + parseFloat(amount)
    subTotal.innerHTML = newSubTotal.toFixed(2);
    
    shippingCost = document.getElementById('shipping-cost')
    shippingCost.innerHTML = 'Shipping Cost ('+type+'): $' + amount
    
    document.getElementById('enter-zipcode-img').style.display = 'none'
    document.getElementById('or-h2').style.display = 'none'
  }
  
  if(page == 'auth')
  {
    orderTotal = document.getElementById('order-total')
    origOrderTotal = document.getElementById('orig-order-total').value
    newOrderTotal = parseFloat(origOrderTotal) + parseFloat(amount)
    orderTotal.innerHTML = newOrderTotal.toFixed(2);
    
    shippingCost = document.getElementById('shipping-display')
    shippingCost.innerHTML = amount
    
    document.getElementById('shipping-type').innerHTML = type
    
    document.getElementById('purchase-amount').value = newOrderTotal.toFixed(2)
    
    /*
    request = "type=updateShippingAmount&amount="+amount+"&userid="+userid
    ajax.request('update.field.php', 'none', request)
    */
  }
}


/* Pop Up credit card verification numbers */
function cardVerification()
{
window.open( "/cc-verification-number.htm", "myWindow6", 
"status = 1, height = 700, width = 700, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}


/* Pop up GW, GTW, etc information */
function PopupGTW()
{
window.open( "/gtw-tw-capacities.htm", "myWindow7", 
"status = 1, height = 800, width = 700, resizable = 0, scrollbars = 1, left=200, top=100, screenX=200, screenY=100" )
}

/* Pop Up We Stop Fraud */
function weStopFraud()
{
window.open( "/we-stop-fraud.htm", "myWindow8", 
"status = 1, height = 200, width = 550, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

/* Pop Up for Hitch Package Promo */
function packagePromo()
{
window.open( "/hitch-package-promo.htm", "myWindow9", 
"status = 1, height = 500, width = 500, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

/* Pop Up for Free Shipping Promo */
function shippingPromo()
{
window.open( "/free-shipping-promo.htm", "myWindow10", 
"status = 1, height = 375, width = 500, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

/* Pop Up for Our Commitment Promo */
function commitPromo()
{
window.open( "/our-commitment-to-you.htm", "myWindow19", 
"status = 1, height = 500, width = 700, resizable = 0, left=200, top=100, screenX=200, screenY=100, scrollbars=yes" )
}

/* Pop Up for Instructions */
function displayInstructions(str)
{
	var instructions = str;
window.open( "http://assets.iqestores.com/hitch_instructions/N"+instructions+".pdf", "myWindow10", 
"width=780,height=570,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=10,left=10" )
}



/*
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('/cc-verification-number.htm', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizeable=1');");
}
*/


function showRightSidebarInfo(content, productid)
{
	div = document.getElementById(productid+'-info');
	div.innerHTML = unescape(decodeURI(content));
}


/* footer popups */

function Popupss() {
window.open( "/secure-site.htm", "myWindow2", 
"status = 1, height = 300, width = 400, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

function Popuppg() {
window.open( "/privacy-guaranteed.htm", "myWindow5", 
"status = 1, height = 300, width = 400, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

function Popupcc() {
window.open( "/payment-methods.htm", "myWindow", 
"status = 1, height = 450, width = 400, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

function Popupsr() {
window.open( "/safe-and-reliable.htm", "myWindow4", 
"status = 1, height = 480, width = 400, resizable = 0, left=200, top=100, screenX=200, screenY=100" )
}

function Popupse() {
window.open( "/safe-shopping-guar.htm", "myWindow6", 
"status = 1, height = 660, width = 400, resizable = 0, left=200, top=80, screenX=200, screenY=80" )
}

//limit text input on gift card form
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
