
function switchOn(imgName) {
  eval ('document.' + imgName + '.src = "http://www.pelicanparts.com/graphics/' + imgName + '_On.gif"');
}
function switchOff(imgName) {
  eval ('document [imgName].src = "http://www.pelicanparts.com/graphics/transparent.gif"');  }

function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=800');
self.name = "mainWin";
}

function PartWindow(url) {
sealWin=window.open(url,"PartWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=400');
self.name = "mainWin";
}

function FreeShip() {
url = 'http://www.pelicanparts.com/support/FreeShipping.htm';
FreeShipWin=window.open(url,"FreeShipWindow",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=700,height=600');
self.name = "mainWin";
}

function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString()
	}
	else
		expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=.pelicanparts.com;";
}
function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++)
		{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0)
			{
			out = "+"; // replace this
			add = " "; // with this
			temp = "" + c.substring(nameEQ.length,c.length)
			while (temp.indexOf(out)>-1) {
				pos= temp.indexOf(out);
				temp = "" + (temp.substring(0, pos) + add + 
				temp.substring((pos + out.length), temp.length));
				}
			return temp;	
			}
		}
	return null;
	}

function deleteCookie(name) {
	saveCookie(name,"",-1);
}

function init(){

initPelican();

//saveCookie('CurrentYEAR','1993',1);
//saveCookie('CurrentMAKE','BMW',1);
//saveCookie('CurrentMODEL','325is',1);

//saveCookie('YEAR1','1998',1);
//saveCookie('MAKE1','Nissan',1);
//saveCookie('MODEL1','Pathfinder',1);

//saveCookie('YEAR2','1993',1);
//saveCookie('MAKE2','BMW',1);
//saveCookie('MODEL2','325is',1);

//saveCookie('YEAR3','1974',1);
//saveCookie('MAKE3','Porsche',1);
//saveCookie('MODEL3','914-6',1);

//saveCookie('YEAR4','1988',1);
//saveCookie('MAKE4','Buick',1);
//saveCookie('MODEL4','Skylark',1);

//CheckCookie();

}

function CheckCookie(){

var CurrentCookieMake = readCookie('CurrentMAKE');
var CurrentCookieYear = readCookie('CurrentYEAR');
var CurrentCookieModel = readCookie('CurrentMODEL');
var CurrentCookieModel_Id = readCookie('CurrentMODEL_ID');
var CurrentCookieMake_Id = readCookie('CurrentMAKE_ID');
var LinkShareCode = readCookie('LinkShareCode');

if (LinkShareCode != null && document.getElementById('LinkShare'))
	{
	document.all.LinkShare.innerHTML = '<font style="font-family: Verdana,Arial, Helvetica, sans-serif; text-decoration : none; color : #800000; font-size : 14px; font-weight: bold">Express Phone Code: ' + LinkShareCode + '&nbsp;&nbsp;</font>';
	}

var YourCar = '';
if (CurrentCookieYear != null){YourCar = CurrentCookieYear + ' '}
if (CurrentCookieMake != null){YourCar = YourCar + CurrentCookieMake + ' '}
if (CurrentCookieModel != null){YourCar = YourCar + CurrentCookieModel}

if (CurrentCookieYear != null && CurrentCookieMake != null && CurrentCookieModel != null)
	{
	document.all.SelectCar.innerHTML = YourCar + '<br><a class="VehicleSelect" href="http://www.pelicanparts.com/cgi-bin/ppexpress/ppe_drivewerks.cgi?command=SelectCar">Change Vehicle</a>';
	var PreviousCar = '<select onChange="ChangePrevCar();" NAME="PrevCar" style="width: 120px; font-family: Verdana; font-style: normal; font-size: 6pt" size="1">'
	PreviousCar += '<option>Previous Cars</option>';
	for (i=1;i<6;i++)
		{
		eval ("var MAKE = readCookie('MAKE" + i + "')");
		eval ("var MODEL = readCookie('MODEL" + i + "')");
		eval ("var YEAR = readCookie('YEAR" + i + "')");
		if (YEAR != null){YEAR = YEAR.substr(2,2);}
		if (MAKE != null)
			{
			PreviousCar += '<option value = ' + i + '>' + YEAR + ' ' + MAKE + ' ' + MODEL + '</option>';
			}
		}
	document.all.PreviousCar.innerHTML = PreviousCar + '</select>';
	document.all.MakeMessage.innerHTML = 'Your Car:'; 
	}
}
function ChangePrevCar(){
	i = ChooseCar.PrevCar.value;
	eval ("var MAKE = readCookie('MAKE" + i + "')");
	eval ("var MODEL = readCookie('MODEL" + i + "')");
	eval ("var YEAR = readCookie('YEAR" + i + "')");
	eval ("var MODEL_ID = readCookie('MODEL_ID" + i + "')");	
	eval ("var MAKE_ID = readCookie('MAKE_ID" + i + "')");

	var CurrentYEAR = readCookie('CurrentYEAR');
	var CurrentMAKE = readCookie('CurrentMAKE');
	var CurrentMODEL = readCookie('CurrentMODEL');
	var CurrentMODEL_ID = readCookie('CurrentMODEL_ID');
	var CurrentMAKE_ID = readCookie('CurrentMAKE_ID');				
	
	saveCookie('CurrentYEAR',YEAR,1);
	saveCookie('CurrentMAKE',MAKE,1);
	saveCookie('CurrentMODEL',MODEL,1);
	saveCookie('CurrentMODEL_ID',MODEL_ID,1);
	saveCookie('CurrentMAKE_ID',MAKE_ID,1);
	
	eval("saveCookie('MAKE" + i + "',CurrentMAKE,1)");
	eval("saveCookie('YEAR" + i + "',CurrentYEAR,1)");	
	eval("saveCookie('MODEL" + i + "',CurrentMODEL,1)");
	eval("saveCookie('MODEL_ID" + i + "',CurrentMODEL_ID,1)");
	eval("saveCookie('MAKE_ID" + i + "',CurrentMAKE_ID,1)");
	CheckCookie();
}
//PELICAN PARTS FUNCTIONS HERE
function zoom_popup(){
    page = 'http://www.pelicanparts.com/cgi-bin/zoom_pic/zoom_pic3.cgi?PW=450&PH=337&GS=4&CF=main&ACT=display&COL=JPM&PIC=PEL-020-055-99';
    target_window = window.open(page,'target_window','resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,height=550,width=600');
}

function Start(page) {
	target_window = window.open(page,'target_window','resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,height=550,width=600');
	}
function ClearSearch(form){
	eval ('var test = document.' + form + '.description.value');
	if (test == 'Enter Description' || test == 'Enter Description or Part Number'){eval ('document.' + form + '.description.value=""');}
	}
function initPelican()
	{
	SetPelicanLocations();
	}	
	
function SetPelicanLocations()
	// THIS FUNCTION READS THE CURRENT PAGE LOCATION AND SETS SOME COOKIES SO THE SEARCH ENGINE KNOWS WHERE TO SEARCH
	// COOKIE #1 - SITE = P for PORSCHE, B for BMW
	{
	var SITE = '';
	
	// CHECK to see if user came from one of the end catalog pages (catalog/shopcart/Z153/POR_Z153_BRKhyd_pg1.htm)
	var MyREGExp = /catalog\/shopcart\/.{4}\//i;
	if (MyREGExp.test(location.pathname) == true)
		{
		test = MyREGExp.exec(location.pathname);
		SetRecentSections(test[0].substr(test[0].length-5,4));
		
		var MyREGExp = /catalog\/shopcart\/.{4}\/POR_.{4}_.{6}/i;
		if (MyREGExp.test(location.pathname) == true)
			{
			test = MyREGExp.exec(location.pathname)
			saveCookie('LastTemplate',test[0].substr(test[0].length-6,6));
			test2 = test[0].substr(17,1);
			if (test2 == 'B' || test2 == 'U' || test2 == 'V' || test2 == 'W' || test2 == 'X' || test2 == 'Y' || test2 == 'Z')
				{SITE = test[0].substr(17,1);}
			}
		}
		
	// CHECK to see if user just came from one of the main catalog sections (catalog/shopcart/Z153_catalog.htm)
	var MyREGExp = /catalog\/shopcart\/.{4}_catalog\.htm/i;
	if (MyREGExp.test(location.pathname) == true)
		{
		test = MyREGExp.exec(location.pathname);
		SetRecentSections(test[0].substr(test[0].length-16,4));
		test2 = test[0].substr(17,1);
		if (test2 == 'B' || test2 == 'U' || test2 == 'V' || test2 == 'W' || test2 == 'X' || test2 == 'Y' || test2 == 'Z')
			{SITE = test[0].substr(17,1);}
		}
		
	// CHECK to see if user came from the newly created SubCats (catalog/shopcart/SubCat/Z153-Brakes.htm)
	var MyREGExp = /catalog\/shopcart\/SubCat\/.{4}-/i;
	if (MyREGExp.test(location.pathname) == true)
		{
		test = MyREGExp.exec(location.pathname);
		SetRecentSections(test[0].substr(test[0].length-5,4));
		test2 = test[0].substr(24,1);
		if (test2 == 'B' || test2 == 'U' || test2 == 'V' || test2 == 'W' || test2 == 'X' || test2 == 'Y' || test2 == 'Z')
			{SITE = test[0].substr(24,1);}
		}				
	// SET SITE COOKIE IF NOT SET YET
	var Match2 = /cgi\-bin/i;
	if (!(Match2.test(location.pathname)) && SITE == '')
		{
		var Match = /\/BMW\//i;
		if (Match.test(location.pathname))
			{
			SITE = 'B';
			saveCookie('SITE','B');
			//window.status = 'BMW';
			}
		else
			{
			SITE = 'P';
			saveCookie('SITE','P');
			//window.status = 'PORSCHE';
			}
		}
	if (SITE != '')
		{saveCookie('SITE',SITE);}	
	}
function SetRecentSections(section)
	{
	var RecentSections = readCookie('RecentSections');

	eval("var mytest = /" + section + "/i;");
	if (!(mytest.test(RecentSections)))
		{ 
		if (RecentSections == null){RecentSections = section + '-';}
		else {RecentSections = RecentSections + section + '-';}
		RecentSections = RecentSections.substr(0,50);
		saveCookie('RecentSections',RecentSections);
		}
	saveCookie('LastVisited',section);
	window.status = RecentSections;	
	}
function OEMPopUp(e,part_number){
if (e)
	{
	var Xdiff = e.screenX - e.offsetX;
	var Ydiff = e.screenY - e.offsetY + 25;
	}
else
	{
	Xdiff = 200;
	Ydiff = 200;
	}	
	page = 'http://www.pelicanparts.com/cgi-bin/ppexpress/OEM_Part_Number_Display.cgi?pn=' + part_number;
	eval ("OEM_PopUp = window.open(page,'target_window','resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,height=100,width=200,top=" + Ydiff + ",left=" + Xdiff + "')");
	return false;
}

function ImagePopUp(e,part_number,url){
if (e)
	{
	var Xdiff = e.screenX - e.offsetX;
	var Ydiff = e.screenY - e.offsetY + 25;
	}
else
	{
	Xdiff = 200;
	Ydiff = 200;
	}
if (part_number)
	{
	page = 'http://www.pelicanparts.com/euro/cgi-bin/smart/imgdsply.cgi?html=Y&pn=' + part_number;
	eval ("Image_PopUp = window.open(page,'target_window','resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,height=400,width=400,top=" + Ydiff + ",left=" + Xdiff + "')");	
	}
if (url)
	{
	page = 'http://www.pelicanparts.com/euro/cgi-bin/smart/imgdsply.cgi?html=Y&url=' + url;
	eval ("Image_PopUp = window.open(page,'target_window','resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,height=600,width=600,top=" + Ydiff + ",left=" + Xdiff + "')");	
	}

	return false;
}			

// ########################################################################
	function findPosX(obj)
	  {
	    var curleft = 0;
	    if(obj.offsetParent)
	        while(1) 
	        {
	          curleft += obj.offsetLeft;
	          if(!obj.offsetParent)
	            break;
	          obj = obj.offsetParent;
	        }
	    else if(obj.x)
	        curleft += obj.x;
	    return curleft;
	  }
// ########################################################################	
	  function findPosY(obj)
	  {
	    var curtop = 0;
	    if(obj.offsetParent)
	        while(1)
	        {
	          curtop += obj.offsetTop;
	          if(!obj.offsetParent)
	            break;
	          obj = obj.offsetParent;
	        }
	    else if(obj.y)
	        curtop += obj.y;
	    return curtop;
	  }
// ########################################################################	
var PosX = null;
var PosY = null;
var FloaterWidth = null;
var FloaterHeight = null;
var linkWidth = null;
var linkHeight = null;

function PopUpMessage(anchor,message,ImageSrc,NegativeYoffset,NegativeXoffset)
	{
	if (ImageSrc == null)
		{document.getElementById('FloaterWindowMessageSpan').innerHTML = FloaterWindowMessage[message];}
	else
		{
		document.getElementById('FloaterWindowMessageSpan').innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" ><tr><td align=center><img border=0 src="' + ImageSrc + '"></td></tr></table>';
		}	
	PosX = findPosX(document.getElementById(anchor));
	PosY = findPosY(document.getElementById(anchor));
	if (NegativeYoffset != null) // USED TO RAISE SOME OF THE POPUP BOXES LIKE 3-DAY SHIPPING POPUP
		{PosY = PosY - NegativeYoffset}
	if (NegativeXoffset != null) 
		{PosX = PosX - NegativeXoffset}
	FloaterWidth  = document.getElementById('FloaterWindowTable').offsetWidth;
	FloaterHeight = document.getElementById('FloaterWindowTable').offsetHeight;
	linkWidth  = document.getElementById(anchor).offsetWidth;
	linkHeight = document.getElementById(anchor).offsetHeight;
	if (PosX + linkWidth - FloaterWidth > 0) // OPEN ON THE LEFT
		{document.getElementById('FloaterWindow').style.left = PosX + linkWidth - FloaterWidth;}
	else	
		{document.getElementById('FloaterWindow').style.left = PosX;}
	if (PosY - FloaterHeight + 25 < yScroll)
		{document.getElementById('FloaterWindow').style.top = yScroll + 5}
	else if (PosY - FloaterHeight + 25 < 0)
		{document.getElementById('FloaterWindow').style.top = 5}
	else
		{document.getElementById('FloaterWindow').style.top = PosY - FloaterHeight + 25;}
	document.getElementById('FloaterWindow').style.visibility = 'visible'
	}
				
function PopUpMessageClose(e)
	{
	captureMousePosition(e);
	PosX = findPosX(document.getElementById('FloaterWindowTable'));
	PosY = findPosY(document.getElementById('FloaterWindowTable'));
	FloaterWidth  = document.getElementById('FloaterWindowTable').offsetWidth;
	FloaterHeight = document.getElementById('FloaterWindowTable').offsetHeight;
	if (xMousePos < PosX)
		{	document.getElementById('FloaterWindow').style.visibility = 'visible'}

	}

// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page
var yScroll = 2; // position of scroll bar

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
		yScroll = window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
		yScroll = document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
		yScroll = window.pageYOffset;
    }
}
//	##########################################################
	
var FloaterWindowMessage = new Array();
FloaterWindowMessage["OEM_SUPPLIER"] = '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" > \
  <tr> \
    <td width="1%" bgcolor="#000080" height="27">&nbsp;</td> \
    <td width="133%" colspan="2" bgcolor="#000080" height="27"> \
    <font face="Arial" size="4" color="#FFFFFF">Original Equipment Manufacturer</font></td> \
  </tr> \
  <tr> \
    <td width="1%" height="1">&nbsp;</td> \
    <td width="61%" height="1">&nbsp;</td> \
    <td width="1%" height="1">&nbsp;</td> \
  </tr> \
  <tr> \
    <td color="#FFFFFF" colspan=3 align="left" height="1" width="" valign="top"> \
    <font size="2" face="Arial" color="#000080"><b>What does OEM mean?</b><br><br>\
	While browsing our catalog, you will notice some items are marked with a German flag and an "OEM Supplier" tag. This allows you to quickly identify which brand is or was the Original Equipment Manufacturer at the time of the vehicle\'s assembly, or for a car manufacturer\'s spare parts supply.<br><br>\
  </tr> \
  </table>';

// ############################################################
// NEW FLOATING POPUP CODE ADDED 12-19-08
	function MouseOverCatalogImage(ImageURL,ImageId){
		PosX = findPosX(document.getElementById(ImageId));
		PosY = findPosY(document.getElementById(ImageId));
		//document.getElementById('ColorSelector_Big').style.visibility = 'visible';
		document.getElementById('BigColorSwatchImage').src = 'http://www.pelicanparts.com/graphics/parts_diagrams1.gif';
		//alert(ImageURL);
		//document.getElementById('BigColorSwatchInfo').innerHTML = 'TEST';
		//document.getElementById('BigColorSwatch').style.visibility = 'visible';
		//hideall();

	}
	
