/*
 * Additional Global JavaScript Definitions
 */
function getCdef()
{
   now = new Date();
   hours = now.getHours();
   minutes = now.getMinutes();
   seconds = now.getSeconds();
   milliseconds = now.getMilliseconds();
   cDef = hours + "_" + minutes + "_" + seconds + "_" + milliseconds;
   return cDef;
}
function encode( str )
{
   return escape(str).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}
function trim(str)
{
var i=0,p = str.length-1;
while(str.charAt(i)==' ' || str.charAt(i) == '\n') i++;
while(str.charAt(p)==' ' || str.charAt(p) == '\n') p--;
if(i>p) return '';
return str.substring(i,p+1);
}
// a = retailer
// upi = unique product id
// e = member store
function shopUniqueProduct ( a, upi, e )
{
	return shop( a, e, null, null, null, null, null, null, null, null, upi );
}
function shopProduct ( a, p, e )
{
	return shop( a, e, p, null, null, null, null, null, null, null, null );
}
function shopAp( a, ap )
{
	return shop( a, null, null, null, null, null, null, null, null, null, null, ap );
}
// a = retailer
// e = member store
// p = product
// s = special offer
// mp = list product
// item = ebay itemId
// banner = bannerId
// fp = featured product
// ed = ebay daily deal url
// ls = local store id
// upi = unique product id
// ap = placement
function shop ( a, e, p, s, mp, item, banner, fp, ed, ls, upi, ap )
{
   var theUrl = "shop.do?m=1&cd=" + getCdef() + "&a=" + a;
   if ( e != null )
   {
      theUrl = theUrl + "&e=" + e;
   }
   if ( p != null )
   {
      theUrl = theUrl + "&p=" + p;
   }
   if ( s != null )
   {
      theUrl = theUrl + "&s=" + s;
   }
   if ( mp != null )
   {
      theUrl = theUrl + "&mp=" + mp;
   }
   if ( item != null )
   {
      theUrl = theUrl + "&item=" + item;
   }
   if ( banner != null )
   {
      theUrl = theUrl + "&banner=" + banner;
   }
   if ( fp != null )
   {
      theUrl = theUrl + "&fp=" + fp;
   }
	if ( ed != null )
	{
		theUrl = theUrl + "&ed=" + encodeURIComponent( ed );
	}
	if ( ls != null )
	{
		theUrl = theUrl + "&ls=" + ls;
	}
	if ( upi != null )
	{
		theUrl = theUrl + "&upi=" + upi;
	}
	if ( ap != null )
	{
		theUrl = theUrl + "&ap=" + ap;
	}
   var theWin = window.open( theUrl, "_blank" );
   theWin.focus();
   return false;
}
function sChk(img, maxW) // sizecheck images
{
   if ( img.width >= img.height )
   {
      if ( img.width > maxW )
      {
	 img.width = maxW;
      }
   }
   else
   {
      if ( img.height > maxW )
      {
	 img.height = maxW;
      }
   }
}
function sChkAll()
{
   sChkAll( 100 );
}
function sChkAll( maxW )
{
//var maxW = 100;
//alert( 'in schkAll. maxW=' + maxW );
   var imageCount = document.images.length;
   for ( i = 0; i < imageCount; i++ )
   {
      var img = document.images[ "pimg" + i ];
      if ( img && img != null )
      {
	 sChk( img, maxW );
      }
   }
}
function shareFb( url, text )
{
	shareFb( url, text, true );
}
function shareFb( url, text, openNewWindow )
{
	if ( openNewWindow )
	{
		window.open( 'http://www.facebook.com/share.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(text) );
	}
	else
	{
		window.location.href = 'http://www.facebook.com/share.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(text);
	}
}
function shareTwitter( url, text )
{
	shareTwitter( url, text, true );
}
function shareTwitter( url, text, openNewWindow )
{
	if ( openNewWindow )
	{
		window.open( 'http://twitter.com/home?status='+encodeURIComponent(text)+'+'+encodeURIComponent(url) );
	}
	else
	{
		window.location.href = 'http://twitter.com/home?status='+encodeURIComponent(text)+'+'+encodeURIComponent(url);
	}
}
function openInquiryWindow( theUrl )
{
   window.open(theUrl, "_blank","height=700,width=750,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
   return false;
}
// ajax pagination functions
function goPageAjax( page, maxPerPage, total, pagingUrl, container )
{
	var row = page * maxPerPage;
	if ( pagingUrl.indexOf( "?" ) == -1 )
		pagingUrl = pagingUrl + "?start=";
	else
		pagingUrl = pagingUrl + "&start=";
	xhtml.ajaxLoad( pagingUrl + row + "&total=" + total, container, true );
}

function addToFaves( id, ebayStoreFlag )
{
   var theUrl = "addToFavorites.do?cd=" + getCdef() + "&id=" + id + "&eb=" + ebayStoreFlag;
   var theWin =
      window.open( theUrl, "bcUpdateFaves","status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=1000,height=550");
   theWin.focus();
   return false;
}

function removeFromFaves( id, ebayStoreFlag )
{
   var theUrl = "removeFromFavorites.do?cd=" + getCdef() + "&id=" + id + "&eb=" + ebayStoreFlag;
   var theWin =
      window.open( theUrl, "bcUpdateFaves","status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=1000,height=550");
   theWin.focus();
   return false;
}
function setQC( id, ebayStoreFlag )
{
   var theUrl = "setQuickCrumb.do?cd=" + getCdef() + "&id=" + id + "&eb=" + ebayStoreFlag;
   var theWin =
      window.open( theUrl, "bcSetQuickCrumb","width=1000,height=600");
   theWin.focus();
   return false;
}
function zoomPhoto(id)
{
   theWin = window.open( "zoomPhoto.jsp?cd=" + getCdef() + "&id=" + id, "zoomPhoto","status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=680,height=540");
   theWin.focus();
}
