//timer for special offer display on cat items page.
var sptimer=null;

function popWin(page,name,w,h)
{
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = ((screen.height) ? (screen.height-h)/2 : 0) - 50;
	var showLocation='no';
	
	if(name=='_cart')
		showLocation='yes';
		
  var w = window.open(page,name,'scrollbars=yes,toolbar=no,statusbar=1,location='+showLocation+',width='+w+',height='+h+',resizable=yes'+',top='+TopPosition+',left='+LeftPosition);
}

function popWinToolbar(page,name,w,h)
{
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = ((screen.height) ? (screen.height-h)/2 : 0) - 50;
	var showLocation='no';
	
	if(name=='_cart')
		showLocation='yes';
		
  var w = window.open(page,name,'menubar=1,scrollbars=yes,toolbar=yes,statusbar=1,location='+showLocation+',width='+w+',height='+h+',resizable=yes'+',top='+TopPosition+',left='+LeftPosition);
}

var compatModelTimerId = null;

function showModels(obj,item)			
{
	var theY = findPosY(obj);				
	var theX = findPosX(obj);					
	var e = document.getElementById('compatModels');				
	var url = '/ecom/accessories.htm?action=getItemModels';
	var params = 'view=catalog/compatible_models&item_id='+item;
	e.style.display="block";
	e.style.top=(theY+20)+'px';
	e.style.left=(theX)+'px';	
	e.innerHTML="<p>Loading...</p>";

    $.ajax( {
        type: "POST",
        cache: false,
        url: url,
        data: params,
        timeout: 5000,
        success: function(newHtml) {
            $("#compatModels").html(newHtml);
        }
    });
}

function hideModels()			
{				
	var e = document.getElementById('compatModels');				
	e.style.display="none";							
}	

function reportError(request)
{
	var e = document.getElementById('compatModels');				
	e.innerHTML='Sorry. There was a problem retrieving models.';			
	setTimeout("hideModels()",5000);
}

function findPosX(obj)
{	
	var curleft=0; 
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{	
	var curtop=0; 
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function showOffers(itemId, type)			
{	
	var title ="Instant Savings";
	if(type=='sp') title ="Special Offer";		

	var txt ='<center><span class="TextBoldUnderline" style="color:#990000">'+title+'</span></center>'+document.getElementById(type+'_text_'+itemId).innerHTML;
	ddrivetip(txt);	
}

function hideOffers()			
{				
	hideddrivetip();
}	