
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 Match2 = /cgi\-bin/i;
	if (!(Match2.test(location.pathname)))
		{
		var Match = /\/BMW\//i;
		if (Match.test(location.pathname))
			{
			saveCookie('SITE','B');
			//window.status = 'BMW';
			}
		else
			{
			saveCookie('SITE','P');
			//window.status = 'PORSCHE';
			}
		}
		
	// GET THE ARRAY OF RECENTLY VISITED Sections
	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));
			}
		}
		
	// CHECK to see if user just came from one of the main catalog sections
	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));
		}
	// CHECK to see if user came from the newly created SubCats
	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));
		}				
	}
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;
}			

//	
