// JScript source code

// Added by Nisheeth
var strPreviousPage;
strPreviousPage = getcookie("PreviousPage");
function setType(name)
{
/*
This function takes the search Type forthe user
The parameter of the function is the name ofthe radio button selected 
*/	
  document.getElementById("searchType").Text = name;
}

function clearText()
{
/*
This function clears the text from the search box
*/
	//Modified by Nisheeth for Issue 333. Now the text should be cleared only when the user lands here for the first time.
	// i.e. in case "Enter Search Term Here " is written in the text box only then it should be cleared when the user clicks in the box.
	if (document.getElementById("txtSearch").value == "Enter Search Term Here")
	{
		document.getElementById("txtSearch").value = "";	
	}
}

function gotoPage(targetPage)
	{
	/*
	This function submits the form data to the target asp page
	The parameter passed is the name of the asp page
	*/
	document.frmSearch.searchStatus.value="TRUE";
	switchPage(document.frmSearch,targetPage);
	}

// For swapping the images, on mouseover, to give Hover effect 
function SwapRowImage(imgSrc, imgName, type)
{
	if (type == 'ON')
	{
		imageon = new Image();
    		imageon.src = imgName;
        	document.images[imgSrc].src = imageon.src;
	}

	if (type == 'OFF')
	{
	    	imageoff = new Image();
    		imageoff.src  = imgName;
	        document.images[imgSrc].src = imageoff.src;
	}
}

function submitForm(frmForm)
{	
 /*
  This function submits the form data to rjane008.asp
  Changed by Rajesh (02-June-2005) for MR1 task no 80
 */	
	var strSearchText = frmForm.txtSearch.value;
	// Checking that the search text has been entered by the user.
	if (strSearchText == '' || strSearchText == 'Enter Search Term Here')
	{	
		if (frmForm.searchBy.value=='PartNumber')
		{
        	alert ("Please enter Part Number.");
		}
		else
		{
			alert ("Please enter Parts Description.");
		}
		return;
	}
	else
	{
		if (frmForm.searchBy.value=='PartNumber' && strSearchText.length < 5)
		{
			alert ("Please enter first five characters of Part Number.");
			frmForm.txtSearch.focus();
			return;
		}

		if (frmForm.searchBy.value=='PartNumber')
		{
        	frmForm.searchOption.value = frmForm.Radio1.value;
		}
		else
		{
			if (frmForm.Radio1.checked == true) 
			{	// Setting the searchOption into a hidden variable
				frmForm.searchOption.value = frmForm.Radio1.value; 
			}
			if (frmForm.Radio2.checked == true) 
			{	// Setting the searchOption into a hidden variable
				frmForm.searchOption.value = frmForm.Radio2.value; 
			}
		}
	}
	// Setting TRUE into searchStatus (a hidden var) to indicate that the form is submitted.
	frmForm.searchStatus.value = "TRUE";
	frmForm.action='rjane008.asp';
	frmForm.submit();
}

function closeDIV()
{
 
 document.getElementById('divMoreInfo').innerHTML = '';
 document.getElementById('divMoreInfo').style.display = 'none';
}

function LTrim(VALUE)
{
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


//Modified by Rajesh (23-May-2005) for MR1 (to display partno)
function showMoreInfo(illustrationId, partDesc, partRefComment, loGrp, hiGrp, colorDesc, strOrigin, strEmission,partNo,msrp,dealerprice,bIRFUser,bShowPrice,strDIYCode,iCount,strPartModCD)
{
	var sRefNo, sPArtDesc, sPartRefCommon, sColorDesc, sLo, sHi,sPartNo;
	var width, height, xPos, yPos, s_url;
	var sText='';
	
	

	if (!((partRefComment=='') && (loGrp == '') && (hiGrp == '') && (colorDesc=='') && (strOrigin=='') && (strEmission=='')))
	{
	
		sText = '<table width="352" cellspacing="0" cellpadding="0" bgcolor="#BDC9CD" border="1" bordercolorlight="#c1c1c1"  bordercolor="#d2d2d2" style="filter: Alpha(opacity=95)"><tr><td width="352" height="150" bgcolor="#BDC9CD" class="black">';
		sText += '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width = "2%">&nbsp;&nbsp;</td><td width = "90%" style="FONT-WEIGHT: bolder;FONT-SIZE: 12px;" class="listviewredtext"><b>' + LTrim(partDesc) + '</b></td><td width = "8%" valign="top" align="right" width="5%"><a href="#" onclick="javascript:closeDIV();"><img src="../images/es_1_glo_icon_close.gif" width="47" height="13" align="right" border="0"></a></td></tr></table>';
		sText += '<table cellspacing="0" cellpadding="0" width="345" border="0" bgcolor="#BDC9CD" style="filter:Alpha(opacity=95);">';
		//sText += '<tr><td width="1%">&nbsp;</td><td colspan="2">&nbsp;</td></tr>';
		
		 //if dealer price is less than 5% of MSRP then show dealer price only
		if ((isNaN(parseFloat(dealerprice))==false) && (isNaN(parseFloat(msrp))==false))
		{
		
			if (dealerprice >= (msrp-(msrp*0.05))) 
			{
				if (bIRFUser.toString()=="true")
				{
					if (bShowPrice != null)
					{
						if (String(bShowPrice).toLowerCase()=='true')
						{	
							sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + dealerprice + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' Dealer Price</td></tr>';
						}
					}
					else
					{
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + dealerprice + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' Dealer Price</td></tr>';
					}
				}			
				else
				{
					if (!((strPartModCD =='X') || (strPartModCD =='D') || (strPartModCD =='W') || (strPartModCD =='x') || (strPartModCD =='d') || (strPartModCD =='w') || (dealerprice == '')))
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + dealerprice + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' Dealer Price</td></tr>';
				}
			}
			else
			{
			
			if (bIRFUser.toString()=="true")
			{
				if (bShowPrice != null)
				{
					if (String(bShowPrice).toLowerCase()=='true')
					{
						if (!((strPartModCD =='X') || (strPartModCD =='D') || (strPartModCD =='W') || (strPartModCD =='x') || (strPartModCD =='d') || (strPartModCD =='w') || (dealerprice == '')))
							sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + msrp + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' MSRP</td></tr>';
					}
				}
				else
				{ 
					if (!((strPartModCD =='X') || (strPartModCD =='D') || (strPartModCD =='W') || (strPartModCD =='x') || (strPartModCD =='d') || (strPartModCD =='w') || (dealerprice == '')))
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + msrp + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' MSRP</td></tr>';	
				}
			}
			else
				{
					if (!((strPartModCD =='X') || (strPartModCD =='D') || (strPartModCD =='W') || (strPartModCD =='x') || (strPartModCD =='d') || (strPartModCD =='w') || (dealerprice == '')))
					{
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + msrp + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' MSRP</td></tr>';
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> $' + dealerprice + '</td><td width="80%" align="left" class="bodyCopyBold">' + ' Dealer Price</td></tr>';
						sText += '<tr><td width="1%">&nbsp;</td><td width="19%" class="amount"> ' + round(parseInt((msrp-dealerprice)*(100/msrp)),0) + '%</td><td width="80%" align="left" class="bodyCopyBold">' + ' Your Savings</td></tr>';
					}
				}

			}
			if ( (strPartModCD =='X') || (strPartModCD =='D') || (strPartModCD =='W') || (strPartModCD =='x') || (strPartModCD =='d') || (strPartModCD =='w') || (dealerprice == ''))
			{
			sText += '<tr><td width="1%">&nbsp;</td><td colspan="2">&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan="2" valign="top" align="left" class="greytext"><font color="FF0000">Discontinued, please call dealer.</FONT><BR><BR></td></tr>';
			}
			else{
				if (bIRFUser.toString()=="true")
				{
				sText += '<tr><td width="1%">&nbsp;</td><td colspan="2">&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan="2" valign="top" align="left">&nbsp;<a href="#" onclick="javascript:addToCart(' + "\'" + partNo + "\'" + ',' + "\'" + msrp + "\'" + ',' + "\'" + partDesc  + "\'" + ',' + "\'" +  strDIYCode + "\'" + ',' + "\'" + 'orderedQty' + iCount + partNo + "\'" + ');closeDIV();"><img src="../images/es_1_btn_addToCart.gif" width="91" height="25" border="0"></a></td></tr>';
				}
				else
				{
				sText += '<tr><td width="1%">&nbsp;</td><td colspan="2">&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan="2" valign="top" align="left">&nbsp;<a href="#" onclick="javascript:addToCart(' + "\'" + partNo + "\'" + ',' + "\'" + dealerprice + "\'" + ',' + "\'" + partDesc  + "\'" + ',' + "\'" +  strDIYCode + "\'" + ',' + "\'" + 'orderedQty' + iCount + partNo + "\'" + ');closeDIV();"><img src="../images/es_1_btn_addToCart.gif" width="91" height="25" border="0"></a></td></tr>';
				}
			}
		}
		else
		{
			sText += '<tr><td width="1%">&nbsp;</td><td colspan="2">&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan="2" valign="top" align="left">&nbsp;</td></tr>';
		}
		
		sText += '<tr><td width="2%">&nbsp;</td><td colspan="2" valign="top" align="left" class="bodyCopyList"><table border="0" width="100%" cellpadding="0" cellspacing="0">';
		
		sText += '<tr><td width="40%" class="blacktextbold">PartNumber:</td><td width="60%">' + partNo + '</td></tr>';

		if (illustrationId.toUpperCase() != 'REFNUMBER')
		{
		 sText += '<tr><td width="40%" class="blacktextbold">Reference Number:</td><td width="60%">' + illustrationId + '</td></tr>';
		}
		   
		sText += '<tr><td width="40%" class="blacktextbold">Part Ref Comment:</td><td width="60%">' + partRefComment + '</td></tr>';
		sText += '<tr><td width="40%" class="blacktextbold">VIN Low:</td><td width="60%">' + loGrp + '</td></tr>';
		sText += '<tr><td width="40%" class="blacktextbold">VIN High:</td><td width="60%">' + hiGrp + '</td></tr>';
		sText += '<tr><td width="40%" class="blacktextbold">Color Description:</td><td width="60%">' + colorDesc + '</td></tr>';
		sText += '<tr><td width="40%" class="blacktextbold">Origin:</td><td width="60%">' + strOrigin + '</td></tr>';
		sText += '<tr><td width="40%" class="blacktextbold">Emission:</td><td width="60%">' + strEmission + '</td></tr>';
		
		sText += '</table></td></tr><tr><td>&nbsp;</td></tr></table></td></tr></table>';
		
		
		//alert(sText);
		document.getElementById('divMoreInfo').innerHTML = sText;
		document.getElementById('divMoreInfo').style.top = document.body.scrollTop + 160;
		document.getElementById('divMoreInfo').style.display = '';
	}

}

function showImage(partNumber)
{
	var width, height, xPos, yPos, s_url;
	b_large = false;
	s_url = 'rjane010.asp?PartNo=' +  partNumber + '&popup=1&frmName=SEARCH';
	
		if (!b_large)
		{
			width=455;
			//height=465;
			height=205;
			//commented by Anil on 08/14/05 to open image popup at the center of screen
			//xPos=150;
			xPos= (screen.width/2)- (width/2);
			yPos=40;
		}
		else
		{
			width=420;
			//height=415;
			height=205;
			//commented by Anil on 08/14/05 to open image popup at the center of screen
			//xPos=150;
			xPos= (screen.width/2)- (width/2);
			yPos=60;
		}
	g_popupwin = OpenImageWindow(s_url, xPos, yPos, width, height);
}

function OpenImageWindow(str, x, y, w, h)
		{
			ie = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
			return window.open(str, "g_popupwin", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,height='+h+',width='+w+','+((ie)?"left":"screenX")+'='+x+','+((ie)?"top":"screenY")+'='+y, true);
		}

function OpenInfoWindow(str, x, y, w, h)
		{
			ie = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
			return window.open(str, "g_popupwin", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height='+h+',width='+w+','+((ie)?"left":"screenX")+'='+x+','+((ie)?"top":"screenY")+'='+y, true);
		}

function ChangeOptions(strOption)
{
/*
Author : Rajesh Agarwal
Date : 02-June-2005
Purpose :This function takes the search by for the user
Parameter :The parameter of the function is the name of the radio button selected 
*/	
  if (strOption=='PartNumber')
  {

	document.getElementById('lblDesc').innerHTML='Enter Part Number';
	document.getElementById('Radio1').disabled=true;
    document.getElementById('Radio2').disabled=true;
	document.getElementById('Radio1').checked=true;
	document.getElementById('Radio2').checked=false;

  }	
  else
  {
	document.getElementById('lblDesc').innerHTML='Enter Parts Description';	
	document.getElementById('Radio1').disabled=false;
    document.getElementById('Radio2').disabled=false;
	document.getElementById('Radio1').checked=true;
  }
    document.getElementById('txtSearch').value='Enter Search Term Here';
	document.getElementById("searchBy").value = strOption;  
}

