// ©2003 Syncata
//© 2002 Syncata for American Honda Motor Corporation
//**********************************************************************
//Filename		:   rjane004.js
//Author		:   Viv Coorapati
//Date/Time		:   5/14/2003
//Purpose		:   To maintain all the common JS functions used across
//			    the phase 3 related pages
//Revisions		:
//Date		Name		Description
//**********************************************************************

//Browser Check
var isNS4 = (document.layers) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

// Added by Nisheeth
function goToBack(frmName, strPageName)
{
	//alert ("strPageName-->" + strPageName);
	var intDot = strPageName.indexOf(".");
	strPageName = strPageName.substring(0,intDot) +'.asp';
	//alert ("strPageName-->" + strPageName.toUpperCase());
	if (strPageName.toUpperCase() == 'TABSELECTION.ASP')
	{
	strPageName = "/asp/tabselection.asp"
	}
	//alert ("strPageName-->" + strPageName);
	frmName.action = strPageName;
	frmName.method = "post";
	frmName.submit();
}

function getcookie(cookiename) {
 	var cookiestring=""+document.cookie;
 	var index1=cookiestring.indexOf(cookiename);
 	if (index1==-1 || cookiename=="") return ""; 

 	var index2=cookiestring.indexOf(';',index1); 
	if (index2==-1) index2=cookiestring.length; 

 	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
	//alert (unescape(cookiestring.substring(index1+cookiename.length+1,index2)));
}

function goBack(frmName, strPageName)
{
	history.go(-1);
}

function switchPage(frmName, strPageName)
{
/*
This function is used to redirect the page from one page to the another.
Parameters: frmName - The form name of the object where it gets created
			strPageName - The page that needs to be displayed
*/	
	//alert('got here in switchpage');
	frmName.action = strPageName;
	// Method added by nisheeth
	frmName.method="post";
	frmName.submit();
	//document.forms[frmName].action=strPageName;
 	//document.forms[frmName].submit();
}

function changeVehicle(frmPageForm, strUser)
{
	var strCaseName;
	if (strUser == "WEBUser")
	{
		strCaseName = 'PARTSLANDING';
	}
	else //strUser is an IRF User
	{
		strCaseName = 'PARTSVIN';
	}
	frmPageForm.tab.value = strCaseName;
	frmPageForm.action = "/asp/tabSelection.asp";
	frmPageForm.method = "post";
	frmPageForm.submit();
}

function swapImage(strImgCtrlName,blnMouseOver)
{
/*
This function is used to change the images on mouse over and out
Parameters: strImgCtrlName - The name of the image tag
			blnMouseOver - True for mouse over and False for mouse out
*/			
	if(window.document.images) 
	{
		if(blnMouseOver)
			window.document.images[strImgCtrlName].src = "/images/" + strImgCtrlName + "_on.gif";
		else
			window.document.images[strImgCtrlName].src = "/images/" + strImgCtrlName + "_off.gif";
	}
}


function disableRightClick(e) 
{
	return true;
}

function GetStyleObject(strId){
/*
This function supports to draw the border for the images and this function is provided by 
Genex.
*/
	if (document.getElementById){
		return document.getElementById(strId).style;
	}
	else if(document.layers){
		return document.layers[strId];
	}
	else if(document.all){
		return document.all[strId].style;
	}
	else{
		alert("In order to view this site, you must have a version 4.0 browser or higher.")
		return false;
	}
}


function moveoverOnImage(strDivName,intZIndexIncrement){
/*
This function supports to initiate to draw the border for the images and this function is provided by 
Genex.
*/
	var objStyle;
	objStyle = GetStyleObject(strDivName);
	objStyle.zIndex = parseInt(objStyle.zIndex) + intZIndexIncrement;
}




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 checkVIN(strVINNo)
{
/*
Purpose :This function will validate the VIN no according to the business logic
Parameters :strVINNo: This is VIN No entered by the user.
*/		
var i;
var iCheckDigit;
var intSumOfValue;
var intConvertedValue;
var intRemainder;
var arrPosition = new Array(16);
arrPosition[0]=8;
arrPosition[1]=7;
arrPosition[2]=6;
arrPosition[3]=5;
arrPosition[4]=4;
arrPosition[5]=3;
arrPosition[6]=2;
arrPosition[7]=10;
arrPosition[8]=0;
arrPosition[9]=9;
arrPosition[10]=8;
arrPosition[11]=7;
arrPosition[12]=6;
arrPosition[13]=5;
arrPosition[14]=4;
arrPosition[15]=3;
arrPosition[16]=2;

strVINNo = strVINNo.toUpperCase();
intSumOfValue=0;
if (strVINNo.length != 0)
{
	if (strVINNo.length != 17)
	{
		alert("Invalid length of VIN No.");
		return false;
	}

	if(strVINNo.indexOf('I')>-1 || (strVINNo.indexOf('Q')>-1) || (strVINNo.indexOf('O')>-1))
	{
		alert("I,Q and O are invalid characters for VIN Number");
		return false;
	}

	iCheckDigit=strVINNo.charAt(8);

	if (isNaN(iCheckDigit))
	{
		iCheckDigit=GetConvertedValue(strVINNo.charAt(8));
	}
		
	for (i=0;i<17;i++)
	{
		if(isNaN(strVINNo.charAt(i)))
		{
			intConvertedValue= GetConvertedValue(strVINNo.charAt(i));
		}
		else
		{
			intConvertedValue=strVINNo.charAt(i);
		}
		intSumOfValue = intSumOfValue+(intConvertedValue * arrPosition[i]);
	}
	intRemainder=getModValue(intSumOfValue,11);
	
	if (parseInt(intRemainder) != parseInt(iCheckDigit))
	{		
		if ((intRemainder==10) && (strVINNo.charAt(8)=="X"))
		{			
			//return true;	
		}
		else
		{
			alert("Invalid VIN Number\nPlease enter a proper VIN");
			return false;
		}
	}
	//else	// Commented by Nisheeth As this was blocking the functioning of the Submit button on rjane002.asp page.	
		return true;
}
else  // length of vin is 0
{
	alert("Please enter a valid VIN.");
	return false;
}

function GetConvertedValue(cVal)

{
/* 
	Purpose	:This function will convert the alphabatical value to the corresponding numeric.
	Parameters	:cVal:Character like A,B etc.
*/	
	
	if (cVal=="A" || cVal=="J")
	{
		return 1;
	}
	else if (cVal=="B" || cVal=="K" || cVal=="S")
	{
		return 2;
	}
	else if (cVal=="C" || cVal=="L" || cVal=="T")
	{
		return 3;
	}
	else if (cVal=="D" || cVal=="M" || cVal=="U")
	{
		return 4;
	}
	else if (cVal=="E" || cVal=="N" || cVal=="V")
	{
		return 5;
	}
	else if (cVal=="F" || cVal=="W")
	{
		return 6;
	}
	else if (cVal=="G" || cVal=="P" || cVal=="X")
	{
		return 7;
	}
	else if (cVal=="H" || cVal=="Y")
	{
		return 8;
	}
	else if (cVal=="R" || cVal=="Z" )
	{
			return 9;
	}
}

function getModValue(divisee,base)
{
	
	/*
	Purpose  :This function returns the Remainder of the calculation.
	Parameters :cVal:Position of the value.
*/	
	return Math.round(divisee - (Math.floor(divisee/base)*base));
}
}

//This function disables the right click functionality of the mouse
//The parameter passed is the right click of the mouse.
function disableRightClick(e) 
{
	if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	if (document.layers) window.captureEvents(Event.MOUSEUP);

	if (navigator.appName == 'Netscape' && (parseInt(e.which) == 3 || parseInt(e.which) == 2))
	{
		alert("No Right click functionality present!");
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && 	(event.button == 2 || event.button == 3)) 
	{
		alert("No Right click functionality present!");
		//document.frmBlockDetails.back.focus();
		return false;
	}
	return true;
}

function OpenDivisionSelectionPopup()
{
	var iWidth;
	var iHeight;
	var iLeft;
	var iTop;
	//This function opens a pop up screen to allow the logged in IRF user to select a division (honda/acura)
	if (navigator.appName == 'Netscape')
	{
		iWidth = 435;
		iHeight = 210;
	}
	else
	{
		iWidth = 430;
		iHeight = 240; 
	}
	
	iLeft = (screen.width/2)- (iWidth/2);
	iTop = (screen.height/2)- (iHeight/2);
	
	//window.open('/EPC/ASP/rjane020.asp',"",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + iWidth + ',height=' + iHeight + ',left=250,top=300');

	window.open('/EPC/ASP/rjane020.asp',"",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft + ',top=' + iTop);
	

	//var ie = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
	//window.open(str, "Select Division", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height='205',width='405','+((ie)?"left":"screenX")+'='150','+((ie)?"top":"screenY")+'='40, true);
	
}
