
ActiveTipVar = 0; // Sets up the variable that counts the pictures.
var ActiveTipArray = new Array(); // Sets up the active array.
for (loop=0; loop < TipVar; loop++) {
  ActiveTipArray[ActiveTipVar++] = new FixTip(TipArray[loop].TipIDVal, TipArray[loop].TipTxtVal);
}
ActiveIPVar = 0;
ActiveInitPriceArray = new Array(); //Sets up the active Price array.
// alert ("InitPriceVar = " + InitPriceVar);
for (loop=0; loop < InitPriceVar; loop++) {
  ActiveInitPriceArray[ActiveIPVar++] = new FixInitPrice(initPriceArray[loop].IPReg, initPriceArray[loop].IPOFA, initPriceArray[loop].IPCERF, initPriceArray[loop].IPvWD, initPriceArray[loop].IPThy, initPriceArray[loop].IPEcho, initPriceArray[loop].IPHltr, initPriceArray[loop].IPDlute, initPriceArray[loop].IPLivr, initPriceArray[loop].IPWAE, initPriceArray[loop].IPProgst, initPriceArray[loop].IPBrcel, initPriceArray[loop].IPHlthCrt, initPriceArray[loop].IPImmBstr, initPriceArray[loop].IPWrmChk, initPriceArray[loop].IPImplnt, initPriceArray[loop].IPSono, initPriceArray[loop].IPPxray, initPriceArray[loop].IPReproEx, initPriceArray[loop].IPAddFd, initPriceArray[loop].IPWhlpBox, initPriceArray[loop].IPBoxBdg, initPriceArray[loop].IPClnSup, initPriceArray[loop].IPPstPrtChk, initPriceArray[loop].IPDock, initPriceArray[loop].IPPupFd, initPriceArray[loop].IPPupWorm, initPriceArray[loop].IPPupVac, initPriceArray[loop].IPPvWD, initPriceArray[loop].IPCrop, initPriceArray[loop].IPAntibio, initPriceArray[loop].IPPostSup, initPriceArray[loop].IPTat, initPriceArray[loop].IPMC, initPriceArray[loop].IPLitrReg, initPriceArray[loop].IPPupReg, initPriceArray[loop].IPTempTest, initPriceArray[loop].IPFutNomLitr, initPriceArray[loop].IPFutNomPup, initPriceArray[loop].IPToys, initPriceArray[loop].IPBuyerKit, initPriceArray[loop].IPHtLmps, initPriceArray[loop].IPTimeOff, initPriceArray[loop].IPECsect, initPriceArray[loop].IPMidwife);
}

	function customToolTip(target, e, itemTip)
		{
			//itemTip is the ID of the tip to display eg: BBD1
			tipBefore='<table width=200 border="1" cellspacing="0" cellpadding="5" bgcolor="AACCFF" bordercolor="#000000"><tr><td><ilayer id="tt2" class="tooltip">';
            tipAfter='</ilayer></td></tr></table>';
			//BBD = Basic Breeding Decision
			//ABD = Additional Breeding Decision
			//PEM = Pre-Breeding Exam and Medical
			//PIM = Pre-Breeding Insemination Method
			//PBE = Post Breeding Expenses
			//WE = Whelping Expenses
			//PWE = Post Whelping Expenses
			//APE = Additional Puppy Expenses
			//MIS = Miscelleneous Expenses
			//OPE = Other possible Expenses   case "a": case "b":
			//alert ("theTip = " + theTip);  //For Testing
			var theTip = FindTip(itemTip);  //THis retrieves the actual Tip Text for the item.
			
			if(e==null) {
				e = window.event;
			}
                  cH= window.innerHeight;
                  cW= window.innerWidth;
                  cX= e.pageX;
                  cY= e.pageY;
                  sL= window.pageXOffset;
                  sT= window.pageYOffset;
						
			var myTip = document.createElement('div');
			myTip.style.backgroundColor = 'blue';
			myTip.style.color = 'white';
			myTip.style.padding = '2px';
			myTip.style.width= '200px';
			myTip.style.position='absolute';
			myTip.style.zIndex='5';
			//myTip.style.top= (e.pageY ? e.pageY : e.clientY)+'px';
			//myTip.style.left=(e.pageX ? e.pageX : e.clientX)+'px';
			if(cX+sL>cW/2)
                myTip.left=cX+sL-210;
            else
                myTip.left=cX+sL+10;

            if(cY+sT>cH/2)
                myTip.style.Top=cY+sT-40;
            else
                myTip.style.Top=cY+sT+10;

			
			// myTip.style.Top = (target.offsetTop - 80)+'px';
            // myTip.style.left = target.offsetWidth/2 + 'px';
			myTip.setAttribute('id', 'myToolTip');
			//myTip.innerHTML = theTip;
            myTip.innerHTML=tipBefore+theTip+tipAfter;
			target.appendChild(myTip);
		}


	function hideToolTip(target)
	{
		try
		{
		var myTool = document.getElementById('myToolTip');
		target.removeChild(myTool);
		}
		catch(err){}
	}
	
	function FindTip(itemTip) { // Searches for the correct ToolTip.
	  //itemTip is the ID of the tip to be displayed eg: BBD1
	  TotalFound = 0;
	  SearchString = itemTip;
	  for (loop=0; loop < TipVar ; loop++) {
		TipID = ActiveTipArray[loop].TipIDVal;
		TipDesc = ActiveTipArray[loop].TipTxtVal;
		SearchResult = TipID.indexOf(SearchString);
		if (SearchResult != "-1") {
		  //WHen tip is found break out of loop and return the TipDesc value of the TipID.
		  if (TipID == SearchString) {
		  	return TipDesc;
		  }
		//} else {
		//	TipDesc = "Sorry there is No Additional Information on this item.";
		//	return TipDesc;
		}
	  }
	}
	
	function loadselects()
	{
		var _selects = document.getElementsByTagName("select");
		for (var i = 0; i < _selects.length; i++)
		{
			var options = selectsdata[_selects[i].id.substr(3)];
			if (null != options)
			{
				_selects[i].options.length = 0;
				for(var opt in options)
				{
					_selects[i].options.add(new Option(opt, options[opt]));
				}
			}
		}
	}

	function FindInitPrice(selRegion) { // Searches for the correct Region and prices.
	  //selRegion is the ID of the region to be displayed eg: NE
	  TotalFound = 0;
	  // var IPRegVal = 0;
	  SearchString = selRegion;
		//  	alert ("SearchString is  " + SearchString + "TheInitPriceVar is  " + InitPriceVar);
	  for (loop=0; loop < InitPriceVar ; loop++) {
		var IPRegVal = ActiveInitPriceArray[loop].IPReg;
	    // alert ("In Find Init Price " + ActiveInitPriceArray[loop].IPReg);
		SearchResult = IPRegVal.indexOf(SearchString);
		if (SearchResult != -1) {
		  //WHen region is found break out of loop and return the index value of the region.
		  if (IPRegVal == SearchString) {
			return loop;
			//return SearchResult;
		  }
		//} else {
		//	TipDesc = "Sorry there is No Additional Information on this item.";
		//	return TipDesc;
		}
	  }
	}
var FirstPassInd = 0;
var TatIndxVal = 0;
var MCIndxVal = 0;

function setInitPrice(theForm, ldval, LCAIVal, OVVal)
{
	loadselects();
	// Based on the region selected, the initial values for each region will be set here.
	// The Form values are also cleared here on entry into the form.
	theForm.selNoPups.selectedIndex = 5;
	if(ldval == ""){
		var NARegion="ZZ";
	} else {
		//var NARegion=ldval;
		//alert ( "The Region  Value is  " + theForm.selERegion.value);
		var NARegion=theForm.selERegion.value;
	    if (ldval != "XX") {
		   var IPindex = FindInitPrice(NARegion);
		}
	}
	
	if (LCAIVal == "XX") {
		if (theForm.RGLCAI[0].checked) { 
			var covtype = "LC";
		} else if (theForm.RGLCAI[1].checked) {
			var covtype = "AI";
		} else {
	    	var covtype = LCAIVal;
		}
	} else {
		var covtype = LCAIVal;
	}
	if(OVVal == "" || OVVal == 0) {
		theForm.selROfficeVisit.selectedIndex = 6;
	}
	//alert (NARegion);
	if( NARegion == "XX" ) {
		theForm.selROFA.selectedIndex = -1;
		theForm.selRCERF.selectedIndex = -1;
		theForm.selRvWD.selectedIndex = -1;
		theForm.selRThyroid.selectedIndex = -1;
		theForm.selREcho.selectedIndex = -1;
		theForm.selRHolter.selectedIndex = -1;
        theForm.selRLiver.selectedIndex = -1;
		theForm.selRWAE.selectedIndex = -1;
		theForm.selRProgest.selectedIndex = -1;
		theForm.selRBruce.selectedIndex = -1;
		theForm.selRWorm.selectedIndex = -1;
		theForm.selRImmune.selectedIndex = -1;
		theForm.selRHealthCert.selectedIndex = -1;
		
		theForm.selRImplant.selectedIndex = -1;
		theForm.selCollect.selectedIndex = -1;
		theForm.selRSonogram.selectedIndex = -1;
		theForm.selRXRay.selectedIndex = -1;
		theForm.selRExam.selectedIndex = -1;
		theForm.selDilute.selectedIndex = -1;
		theForm.selRAddFood.selectedIndex = -1;
		theForm.selRPPVisit.selectedIndex = -1; 
		theForm.selPRDock.selectedIndex = -1;
		theForm.selRPFood.selectedIndex = -1;
		theForm.selPRWorm.selectedIndex = -1;
		theForm.selPRVac.selectedIndex = -1;
		theForm.selPRvWD.selectedIndex = -1;
		theForm.selPRCrop.selectedIndex = -1;
		theForm.selPRAntibio.selectedIndex = -1;
		theForm.selPPostSup.selectedIndex = -1;
		theForm.selPRChip.selectedIndex = -1;
		FirstPasInd = -1;
		TatIndxVal = -1;  //Makes this index global;
		MCIndxVal = -1;  //Makes this index global;
		theForm.selRTempTest.selectedIndex = -1;
		theForm.selRCsect.selectedIndex = -1;

		// the following items are region independant
		theForm.selStud.selectedIndex = -1;
		theForm.selBTranspt.selectedIndex = -1;
		theForm.selSemen.selectedIndex = -1;
		theForm.selSHipSemen.selectedIndex = -1;
		theForm.selCollect.selectedIndex = -1;
		theForm.selPLtrReg.selectedIndex = -1;
		theForm.selPupReg.selectedIndex = -1;
		theForm.selFutNom.selectedIndex = -1;
		theForm.selFutNomPup.selectedIndex = -1;
		theForm.selWhelpBox.selectedIndex = -1;
		theForm.selBoxBedding.selectedIndex = -1;
		theForm.selClean.selectedIndex = -1;
		theForm.selPToys.selectedIndex = -1;
		theForm.selPBuyerKit.selectedIndex = -1;
		theForm.selHeatLmp.selectedIndex = -1;
		theForm.selWeeksOff.selectedIndex = -1;
		theForm.selSalaryWeek.selectedIndex = -1;
		theForm.selMidWife.selectedIndex = -1;

		theForm.txtNoPups2.value = theForm.selNoPups.value;
		
	} else {
		//Call the Search Init Price Function to get the proper line of the InitPrice Array;
		//alert ("IPindex is " + IPindex);
		theForm.selROFA.selectedIndex = ActiveInitPriceArray[IPindex].IPOFA;
		theForm.selRCERF.selectedIndex = ActiveInitPriceArray[IPindex].IPCERF;
		theForm.selRvWD.selectedIndex = ActiveInitPriceArray[IPindex].IPvWD;
		theForm.selRThyroid.selectedIndex = ActiveInitPriceArray[IPindex].IPThy;
		theForm.selREcho.selectedIndex = ActiveInitPriceArray[IPindex].IPEcho;
		theForm.selRHolter.selectedIndex = ActiveInitPriceArray[IPindex].IPHltr;
		theForm.selDilute.selectedIndex = ActiveInitPriceArray[IPindex].IPDlute;
        theForm.selRLiver.selectedIndex = ActiveInitPriceArray[IPindex].IPLivr;
		theForm.selRWAE.selectedIndex = ActiveInitPriceArray[IPindex].IPWAE;
		theForm.selRProgest.selectedIndex = ActiveInitPriceArray[IPindex].IPProgst;
		theForm.selRBruce.selectedIndex = ActiveInitPriceArray[IPindex].IPBrcel;
		theForm.selRHealthCert.selectedIndex = ActiveInitPriceArray[IPindex].IPHlthCrt;
		theForm.selRImmune.selectedIndex = ActiveInitPriceArray[IPindex].IPImmBstr;
		theForm.selRWorm.selectedIndex = ActiveInitPriceArray[IPindex].IPWrmChk;
	//theForm.selSemen.selectedIndex = ActiveInitPriceArray[IPindex].;
		theForm.selRImplant.selectedIndex = ActiveInitPriceArray[IPindex].IPImplnt;
		theForm.selRSonogram.selectedIndex = ActiveInitPriceArray[IPindex].IPSono;
		theForm.selRXRay.selectedIndex = ActiveInitPriceArray[IPindex].IPPxray;
		theForm.selRExam.selectedIndex = ActiveInitPriceArray[IPindex].IPReproEx;
		theForm.selRAddFood.selectedIndex = ActiveInitPriceArray[IPindex].IPAddFd;

		theForm.selRPPVisit.selectedIndex = ActiveInitPriceArray[IPindex].IPPstPrtChk;
		theForm.selPRDock.selectedIndex = ActiveInitPriceArray[IPindex].IPDock;
		theForm.selRPFood.selectedIndex = ActiveInitPriceArray[IPindex].IPPupFd;
		theForm.selPRWorm.selectedIndex = ActiveInitPriceArray[IPindex].IPPupWorm;
		theForm.selPRVac.selectedIndex = ActiveInitPriceArray[IPindex].IPPupVac;
		theForm.selPRvWD.selectedIndex = ActiveInitPriceArray[IPindex].IPPvWD;
		theForm.selPRCrop.selectedIndex = ActiveInitPriceArray[IPindex].IPCrop;
		theForm.selPRAntibio.selectedIndex = ActiveInitPriceArray[IPindex].IPAntibio;

		theForm.selPPostSup.selectedIndex = ActiveInitPriceArray[IPindex].IPPostSup;
		
		//theForm.selPRChip.selectedIndex = ActiveInitPriceArray[IPindex].IPMC;
		theForm.selPRChip.selectedIndex = 0;
		TatIndxVal = ActiveInitPriceArray[IPindex].IPTat;  //Makes this index global;
		MCIndxVal = ActiveInitPriceArray[IPindex].IPMC;  //Makes this index global;
		if (FirstPassInd == -1) {
			FirstPasInd = 0;
		} else {
			FirstPassInd = 1;
		}
		theForm.selRTempTest.selectedIndex = ActiveInitPriceArray[IPindex].IPTempTest;
		theForm.selPLtrReg.selectedIndex = ActiveInitPriceArray[IPindex].IPLitrReg;
		theForm.selPupReg.selectedIndex = ActiveInitPriceArray[IPindex].IPPupReg;
		theForm.selFutNom.selectedIndex = ActiveInitPriceArray[IPindex].IPFutNomLitr;
		theForm.selFutNomPup.selectedIndex = ActiveInitPriceArray[IPindex].IPFutNomPup;
		theForm.selRCsect.selectedIndex = ActiveInitPriceArray[IPindex].IPECsect;
	  //Region Independant items
		theForm.selWhelpBox.selectedIndex = ActiveInitPriceArray[IPindex].IPWhlpBox;
		theForm.selBoxBedding.selectedIndex = ActiveInitPriceArray[IPindex].IPBoxBdg;
		theForm.selClean.selectedIndex = ActiveInitPriceArray[IPindex].IPClnSup;
		theForm.selPToys.selectedIndex = ActiveInitPriceArray[IPindex].IPToys;
		theForm.selPBuyerKit.selectedIndex = ActiveInitPriceArray[IPindex].IPBuyerKit;
		theForm.selHeatLmp.selectedIndex = ActiveInitPriceArray[IPindex].IPHtLmps;
		theForm.selWeeksOff.selectedIndex = ActiveInitPriceArray[IPindex].IPTimeOff;
		theForm.selMidWife.selectedIndex = ActiveInitPriceArray[IPindex].IPMidwife;
		// theForm.selSalaryWeek.selectedIndex = ActiveInitPriceArray[IPindex].;

		calcsubtotBreedDec(document.frmBreedingCost)
		calcsubtot(document.frmBreedingCost);
		// Need the LCAIVal to pass to the calcStudSubTotal ROutine
		// The implant Semen field is region dependant.
	 	//alert ("Insem Type = " + covtype);
		setLCAI(theForm)
		if (covtype == "LC" ) {
			calcSubTotLCAI(theForm, "LC")
		} else if (covtype == "AI" ) {
			calcSubTotLCAI(theForm, "AI")
		}
		calcSubTotPostBreed(theForm, NARegion)
		calcSubTotWhelp(theForm, NARegion)
		calcSubTotPostWhelp(theForm, NARegion, theForm.selNoPups.value)
		setIDCost(theForm, NARegion, theForm.selNoPups.value, "X")
		calcMiscSubTot(theForm)
		calcOther(theForm, NARegion)

		theForm.txtNoPups2.value = theForm.selNoPups.value;		
	}
}