/* THIS FILE CONTAINS CONFIDENTIAL TRADE SECRET INFORMATION
 * Any use without the expressed written approval of * Mervyn L. Cohn or Peter W. Pedrotti, Jr. is prohibited.
 *
 * e-Praise Diamond Appraisal Engine
 * Copyright (C) 2002-2003 Mervyn L. Cohn and Peter W. Pedrotti, Jr.
 * All Rights Reserved
 */

//COOKIE FUNCTIONS

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

//END COOKIE FUNCTIONS

function goback(){ //BACK BUTTON SCRIPT
history.back();
} //check

function Appraise(){ // MAIN APPRAISAL FUNCTION

alert("Tumbler - eCS Script start");
// DEFINE DIAMOND TRADE PARAMETERS
	/*  ($US) This is the supervising appraiser's opinion of the
	 *  current New York Diamond Dealers Club ("The Bourse") value
	 *  of a theoretical 1.000 Carat D-Flawless diamond with ideal
	 *  craftsmanship characteristics, including the Club member's profit.
	 *  This ONE NUMBER is the only money information referred to by
	 *  this program for calibrating value estimates to the current US
	 *  diamond market. Specifically, the program does
	 *  not contain, nor does it consult in any way, any list,
	 *  table or array of current wholesale or retail prices. This
	 *  program assumes that wholesale and retail prices are
	 *  consequences of the Bourse price in this highly controlled trade.
	 *  All adjustments in the value of the subject diamond to account for
	 *  its actual deviations from the abstract ideal are based on
	 *  widely accepted RELATIVE value opinions used by
	 *  qualified gemological appraisers. This: program is NOT
	 *  merely a searchable and customizable retail catalog, but
	 *  an appraisal engine derived from a theory and model of the diamond
	 *  industry's practices and established norms of valuation.:
	 */
	 
	var BourseValue1cDF = 18480 * (1+Math.random()/1000);  // ($US)
	
	/* (%) This is the supervising appraiser's
	 *  opinion of the normal fixed jobber
	 *	markup percentage for diamonds available at
	 *  the Bourse for $15,000 or more.
	 */
	var Jobber15000 = 10; // (%)
	/* (%) This is the supervising appraiser's
	 *  opinion of the normal scalable jobber
	 *	markup percentage for diamonds available at
	 *  the Bourse for exactly $1,000.
	 */
	var Jobber1000 = 25; // (%)
	/* (%) This is the supervising appraiser's
	 *  opinion of the normal fixed retail
	 *	markup percentage for diamonds that wholesale at
	 *	$12,500 or more.
	 */
	var Survey12500 = 34;  // (%)
	/* (%) This is the supervising appraiser's
	 *  opinion of the normal scalable retail
	 *	markup percentage for diamonds that wholesale for
	 *	exactly $200.00.
	 */
	var Survey200 = 108;   // (%)
	var j;
/* Input identifying and bookkeeping data. Populate form fields
 * in Session.asp for transfer to database and to PDF appraisal template.
 */
 	//var ProportionsHRD = document.FrontPage_Form1.ProportionsHRD.value;
		//parent.session.pdformail.ProportionsHRD.value = ProportionsHRD;	
	//var FinishHRD = document.FrontPage_Form1.FinishHRD.value;
		//parent.session.pdformail.FinishHRD.value = FinishHRD;	
	//var FinishHRD = document.FrontPage_Form1.FinishHRD.value;
		//parent.session.pdformail.FinishHRD.value = FinishHRD;
		
	var FullName = document.FrontPage_Form1.FullName.value;
		if (FullName == ""){
		FullName = ("Whom It May Concern");
		}//check
		//document.FrontPage_Form1.FullName.value = (FullName);
		parent.session.pdformail.FullName.value = FullName;
alert("FullName = " + FullName);
alert("1cDF = " + BourseValue1cDF);
	var Jeweler = document.FrontPage_Form1.Jeweler.value;
		alert("JewelerIN = " + Jeweler);
		if (Jeweler == "Jeweler Name"){
		alert("JewelerMID = " + Jeweler);
		Jeweler = "";
		alert("JewelerMID = " + Jeweler);		
		}
		alert("JewelerOUT = " + Jeweler);		
		parent.session.pdformail.Jeweler.value = Jeweler;
		
	var JBTNumber = document.FrontPage_Form1.JBTNumber.value;
		alert("JBTNumberIN = " + JBTNumber);
		if (JBTNumber == "Member Number"){
		alert("JBTNumberIN = " + JBTNumber);
		JBTNumber = "";
		alert("JBTNumberMID1 = " + JBTNumber);
		}
	else{
		JBTNumber = "JBT# " + JBTNumber;
		alert("JBTNumberMID2 = " + JBTNumber);
		}	
	
	var leader;
	if (Jeweler == "" && JBTNumber == ""){
		leader = "";
		alert("leader1 = " + leader);		
		}
	else{
		leader = "Prepared by: ";
		}	
		alert("leaderOUT = " + leader);	
		
	JBTNumber = leader + Jeweler + " " + JBTNumber;
		alert("JBTNumberNoK = " + JBTNumber);
/*
none:					Prepared by: Jeweler's Name K
name:					Prepared by: Pzatz K
JBT#:					Prepared by: Jeweler's NameJBT# 12345678 K
name and JBT#:			Prepared by: AbifJBT# 87654321 K
*/

alert("JBT Number = " + JBTNumber);

var Laboratory = document.FrontPage_Form1.Laboratory.value;
		parent.session.pdformail.Laboratory.value = Laboratory;
alert("Laboratory = " + Laboratory);
	var Mode = document.FrontPage_Form1.Mode.value;
		parent.session.pdformail.Mode.value = Mode;
alert("Mode = " + Mode);
	var Label = document.FrontPage_Form1.Label.value;
		parent.session.pdformail.Label.value = Label;
alert("Label = " + Label);
	var CertType = document.FrontPage_Form1.CertType.value;
		parent.session.pdformail.CertType.value = CertType;
alert("CertType = " + CertType);
	var Description = document.FrontPage_Form1.Description.value;
		parent.session.pdformail.Description.value = Description;
alert("Descripion = " + Description);
	var PaidFor = document.FrontPage_Form1.PaidFor.value;
		parent.session.pdformail.PaidFor.value = PaidFor;
alert("PaidFor = " + PaidFor);
		var GIACut = document.FrontPage_Form1.GIACut.value;
		parent.session.pdformail.GIACut.value = GIACut;	
alert("GIACut = " + GIACut);

	var ID = document.FrontPage_Form1.ID.value;
	
alert ("ID = " + ID);

	if (Mode == "APPRAISAL"){
	for (var i=0; i < document.FrontPage_Form1.keystone.length; i++)
   	{
   	if (document.FrontPage_Form1.keystone[i].checked)
      	{
     	var keystone = document.FrontPage_Form1.keystone[i].value;
      	}
   	}
	}
	else if (Mode == "eCS-Only"){
	keystone = "eCS-Only";
	}

alert("Raw keystone = " + keystone);

		var newKey;
		var newKeyString;
		
if (keystone == "Retail"){
	for (var i=0; i < document.FrontPage_Form1.newKey.length; i++)
   	{
   	if (document.FrontPage_Form1.newKey[i].checked)
      	{
     	newKey = document.FrontPage_Form1.newKey[i].value;
		if (newKey == 2){newKeyString = ' (K)';}
		else {newKeyString = " (" + newKey + 'K)';}
      	}
   	}
	}
else {
	newKey = 2;
	newKeyString = "";
	}

alert("newKey = " + newKey);
alert("newKeyString = " + newKeyString); 
JBTNumber = JBTNumber + "  " + newKeyString;
		alert("JBTNumberFINAL = " + JBTNumber);
alert("JBTNumber = " + JBTNumber);

parent.session.pdformail.JBTNumber.value = JBTNumber;

		var markUp;
		var amount;
			
		if (keystone == "Insurance"){
		ID = "99999999";
			document.FrontPage_Form1.ID.value = ID;
		parent.session.pdformail.ID.value = ID;		
		amount = "39.95";
		markUp = 1;
		Label = "Insurance";
		}

		else if (keystone == "Retail"){
		ID = "77777777";
			document.FrontPage_Form1.ID.value = ID;
		parent.session.pdformail.ID.value = ID;		
		amount = "14.95";
		markUp = newKey;
		Label = "Retail";
		}

		else if (keystone == "eCS-Only"){
		ID = "eCS-Only";
			document.FrontPage_Form1.ID.value = ID;
			parent.session.pdformail.ID.value = ID;		
		//amount = "0.00";
		markUp = 1;
		Label = "'e-Praise Cut Score (eCS) Only'";		
		}

		else {}

		parent.session.pdformail.newKey.value = newKey;
		parent.session.pdformail.keystone.value = keystone;
alert("keystone again: " + keystone);
		parent.session.pdformail.amount.value = amount;
alert("amount again: " + amount);
Set_Cookie("keystone",keystone);
Set_Cookie("amount",amount);
Set_Cookie("Label",Label);
		parent.session.pdformail.markUp.value = markUp;
	var CertNumber = document.FrontPage_Form1.CertNumber.value;
		parent.session.pdformail.CertNumber.value = CertNumber;
alert("CertNumber = " + CertNumber);
	var CertDate = document.FrontPage_Form1.CertDate.value;
		parent.session.pdformail.CertDate.value = CertDate;
alert("CertDate = " + CertDate);
	var Weight = parseFloat(document.FrontPage_Form1.Weight.value);
		parent.session.pdformail.Weight.value = Weight;
alert("Weight = " + Weight);
	var Registry = document.FrontPage_Form1.Registry.value;
		parent.session.pdformail.Registry.value = Registry;
alert("Registry = " + Registry);
	var Inscription = document.FrontPage_Form1.Inscription.value;
		parent.session.pdformail.Inscription.value = Inscription;
alert("Inscription = " + Inscription);
	var CrownPct = document.FrontPage_Form1.CrownPct.value;
		parent.session.pdformail.CrownPct.value = CrownPct;
alert("CrownPct = " + CrownPct);

alert("05 CrownPct = " + CrownPct);

		if (CrownPct == ""){
		CrownPct = (14.9);
		}

alert("06 CrownPct = " + CrownPct);

	var PavilionPct = document.FrontPage_Form1.PavilionPct.value;
		parent.session.pdformail.PavilionPct.value = PavilionPct;

alert("07 PavilionPct = " + PavilionPct);

		if (PavilionPct == ""){
		PavilionPct = (43);
		}

alert("08 PavilionPct = " + PavilionPct);

	var DepthPct = document.FrontPage_Form1.DepthPct.value;
		parent.session.pdformail.DepthPct.value = DepthPct;
		if (DepthPct == ""){
		DepthPct = (CrownPct + PavilionPct);
		}
	var Comment = document.FrontPage_Form1.Comment.value;
		parent.session.pdformail.Comment.value = Comment;
	var pdfEmailTo = document.FrontPage_Form1.pdfEmailTo.value;
	if (pdfEmailTo == ""){
		pdfEmailTo = "Online Result Only";
		}
		parent.session.pdformail.pdfEmailTo.value = pdfEmailTo;
		Set_Cookie("pdfEmailTo",pdfEmailTo);

/* Input characteristic data used to determine value, assigning default values
 * for certs that don't record particular values. Populate form fields
 * in Session.asp for transfer to database and to PDF appraisal template.
 */
	var Shape = document.FrontPage_Form1.Shape.value;
		parent.session.pdformail.Shape.value = Shape;
	var Cut = document.FrontPage_Form1.Cut.value;
		parent.session.pdformail.Cut.value = Cut;
	var Brand = document.FrontPage_Form1.Brand.value;
		parent.session.pdformail.Brand.value = Brand;
	var Width1 = parseFloat(document.FrontPage_Form1.Width1.value);
		parent.session.pdformail.Width1.value = Width1;
	var Width2 = parseFloat(document.FrontPage_Form1.Width2.value);
		parent.session.pdformail.Width2.value = Width2;
	var Depth = parseFloat(document.FrontPage_Form1.Depth.value);
		parent.session.pdformail.Depth.value = Depth;

	var TablePct = document.FrontPage_Form1.TablePct.value;
		parent.session.pdformail.TablePct.value = TablePct;

alert("03 TablePct = " + TablePct);

		if (TablePct == ""){
		TablePct = (57);
		}

alert("04 TablePct = " + TablePct);

	var CrownAngle = document.FrontPage_Form1.CrownAngle.value;

alert("09 Crown Angle = " + CrownAngle);

		if (CrownAngle !== ""){
		CrownAngle = ("%, Angle " + CrownAngle + " degrees");
		}

alert("10 Crown Angle = " + CrownAngle);

		parent.session.pdformail.CrownAngle.value = CrownAngle;

alert("11 Crown Angle = " + CrownAngle);

	var Proportions = document.FrontPage_Form1.Proportions.value;
		parent.session.pdformail.Proportions.value = Proportions;
	var Clarity = document.FrontPage_Form1.Clarity.value;
		parent.session.pdformail.Clarity.value = Clarity;
	var Color = document.FrontPage_Form1.Color.value;
		parent.session.pdformail.Color.value = Color;
	var Finish = document.FrontPage_Form1.Finish.value;
		parent.session.pdformail.Finish.value = Finish;
	var GirdleHRD = document.FrontPage_Form1.GirdleHRD.value;
		parent.session.pdformail.GirdleHRD.value = GirdleHRD;
	var GirdleMin = document.FrontPage_Form1.GirdleMin.value;
		parent.session.pdformail.GirdleMin.value = GirdleMin;
	var GirdleString = (GirdleHRD + GirdleMin + " - ");
	if (Number(GirdleMin)){ //check
		if (GirdleMin <= 0.4){ //check
			GirdleMin = "Extremely Thin";
		}
		else if (GirdleMin <= 1.0){ //check //check
			GirdleMin = "Very Thin";
		}
		else if (GirdleMin <= 1.5){ //check //check
			GirdleMin = "Thin";
		}
		else if (GirdleMin <= 1.7){ //check //check
			GirdleMin = "Slightly Thin";
		}
		else if (GirdleMin <= 3.0){ //check //check
			GirdleMin = "Medium";
		}
		else if (GirdleMin <= 4.5){ //check //check
			GirdleMin = "Slightly Thick";
		}
		else if (GirdleMin <= 5.5){ //check //check
			GirdleMin = "Thick";
		}
		else if (GirdleMin <= 7.0){ //check //check
			GirdleMin = "Very Thick";
		}
		else{ //check //check
			GirdleMin = "Extremely Thick";
		} //check
	} //check

	var Fluorescence = document.FrontPage_Form1.Fluorescence.value;
		parent.session.pdformail.Fluorescence.value = Fluorescence;
	var FluorColor = document.FrontPage_Form1.FluorColor.value;
		parent.session.pdformail.FluorColor.value = FluorColor;
	var Culet = document.FrontPage_Form1.Culet.value;
		parent.session.pdformail.Culet.value = Culet;
	var CuletHRD = document.FrontPage_Form1.CuletHRD.value;
		parent.session.pdformail.CuletHRD.value = CuletHRD;
	var CuletString = Culet + " " + CuletHRD;
		parent.session.pdformail.CuletString.value = CuletString;
	var GirdleMax = document.FrontPage_Form1.GirdleMax.value;
		parent.session.pdformail.GirdleMax.value = GirdleMax;
alert("12 GirdleMax input = " + GirdleMax);
		GirdleString = (GirdleString + GirdleMax);
		if (GirdleMax == "0"){
			GirdleMax = (0.0001);
		}
		if (Number(GirdleMax)){ //check

		if (GirdleMax <= 0.4){ //check
			GirdleMax = "Extremely Thin";
		}
		else if (GirdleMax <= 1.0){ //check //check
			GirdleMax = "Very Thin";
		}
		else if (GirdleMax <= 1.5){ //check //check
			GirdleMax = "Thin";
		}
		else if (GirdleMax <= 1.7){ //check //check
			GirdleMax = "Slightly Thin";
		}
		else if (GirdleMax <= 3.0){ //check //check
			GirdleMax = "Medium";
		}
		else if (GirdleMax <= 4.5){ //check //check
			GirdleMax = "Slightly Thick";
		}
		else if (GirdleMax <= 5.5){ //check //check
			GirdleMax = "Thick";
		}
		else if (GirdleMax <= 7.0){ //check //check
			GirdleMax = "Very Thick";
		}
		else		
		{
		GirdleMax = "Extremely Thick"; //check
		} //check
	}

alert("13 GirdleMax if number = " + GirdleMax);
	var GirdleStyle = document.FrontPage_Form1.GirdleStyle.value;
		parent.session.pdformail.GirdleStyle.value = GirdleStyle;
alert("GirdleStyle = " + GirdleStyle);
	var Polish = document.FrontPage_Form1.Polish.value;
		parent.session.pdformail.Polish.value = Polish;
alert("Polish = " + Polish);
	var Symmetry = document.FrontPage_Form1.Symmetry.value;
		parent.session.pdformail.Symmetry.value = Symmetry;
alert("Symmetry = " + Symmetry);
	var AGSCut = document.FrontPage_Form1.AGSCut.value;
		parent.session.pdformail.AGSCut.value = AGSCut;
alert("AGSCut = " + AGSCut);
alert("14 Format Strings");
// Intermediate string manipulations for display
	var ShapeCutString = (Shape + " " + Cut);
		parent.session.pdformail.ShapeCutString.value = ShapeCutString;
alert("ShapeCutString = " + ShapeCutString);
	//var GirdleString = (GirdleString + " " + GirdleStyle);
		parent.session.pdformail.GirdleString.value = GirdleString;
alert("15 GirdleString = " + GirdleString);
	var DimensionsString = (Width1 + " x " + Width2 + " x " + Depth);
		parent.session.pdformail.DimensionsString.value = DimensionsString;
alert("DimensionsString = " + DimensionsString);
	var FluorescenceString = (Fluorescence + " " + FluorColor);
		parent.session.pdformail.FluorescenceString.value = FluorescenceString;
alert("FluorescenceString = " + FluorescenceString);
	var InscriptionRegistryString = (Inscription + " " + Registry);
		parent.session.pdformail.InscriptionRegistryString.value = InscriptionRegistryString;
alert("InscriptionRegistryString = " + InscriptionRegistryString);
alert("16 Declarations");
// Declare misc. variables for later use
	var ShapeWeightFactor;
	var ShapeDesireFactor;
	var JobberFactor;
alert("17 Random Identifiers");
// RANDOMLY ASSIGNED IDENTIFIER and BAR CODE IDENTIFIER

	var yearpart = (900000); // for year == 2009
	var numpart = Math.round(Math.random() * 99999);
	var wholenumber = (yearpart + numpart);
	var String1 = ("AEUYW");
	var String2 = ("BCDFGHJKLMNPQRSTVXZ");
	var letterone = String1.charAt(Math.round(Math.random() * 4));
	var lettertwo = String2.charAt(Math.round(Math.random() * 18));
    	var letterthree = String2.charAt(Math.round(Math.random() * 18));

	var Identifier = String(letterone + lettertwo + letterthree +"-"+ wholenumber);
alert("18 Identifier = " + Identifier);

	var CodeIdentifier = String(letterone + lettertwo + letterthree + "*" + wholenumber + "*");
alert("19 CodeIdentifier = " + CodeIdentifier);

	var Identifier2;
	var CodeIdentifier2;

		document.FrontPage_Form1.Identifier.value = (Identifier);
		parent.session.pdformail.Identifier.value = (Identifier);
		parent.session.pdformail.Identifier2.value = (Identifier);

		document.FrontPage_Form1.CodeIdentifier.value = (CodeIdentifier);
		parent.session.pdformail.CodeIdentifier.value = (CodeIdentifier);
		parent.session.pdformail.CodeIdentifier2.value = (CodeIdentifier);


	var	CertString = (Laboratory + " " + CertType + ", #" + CertNumber + ", " + CertDate + ":");
		parent.session.pdformail.CertString.value = (CertString);
	var bigpart = (700); // for year = 2007
	var numbpart = Math.round(Math.random() * 99);
	wholenumber = (bigpart + numbpart);
	var stringpart = ("AEUYWBCDFGHJKLMNPQRSTVXZ");
	var letterpart = stringpart.charAt(Math.round(Math.random() * 23));
	var TemporaryIdentifier = String(letterpart + "-" + wholenumber);
		document.FrontPage_Form1.TemporaryIdentifier.value = (TemporaryIdentifier);
		parent.session.pdformail.TemporaryIdentifier.value = (TemporaryIdentifier);
		Set_Cookie("TemporaryIdentifier",TemporaryIdentifier);
alert("20 TemporaryIdentifier = " + TemporaryIdentifier);
alert("21 Date and Time");
//DATE/TIME UTC OF e-Praisal
	var today = new Date();
	var tempDate = today.getUTCDate();
	var tempMonth = today.getUTCMonth();
	var MonthArray = ["0","Jan","1","Feb","2","Mar","3","Apr","4","May","5","Jun","6","Jul","7","Aug","8","Sep","9","Oct","10","Nov","11","Dec"];
		for (j = 0 ; j < MonthArray.length; j++){
	  		if (MonthArray[j] == tempMonth){
	  		var MonthString = MonthArray[j+1];
	  		}
			}
	var tempYear = today.getUTCFullYear();
	var tempHours = String(today.getUTCHours());
		if (tempHours.length < 2){
			tempHours = ("0" + tempHours);
		}
	var tempMinutes = String(today.getUTCMinutes());
		if (tempMinutes.length < 2){
			tempMinutes = ("0" + tempMinutes);
		}
	var tempTimeString = (tempHours + ":" + tempMinutes);
	var ePraiseDate = (tempDate + " " + MonthString + ", " + tempYear + " " + tempTimeString + " GMT");
	document.FrontPage_Form1.ePraiseDate.value = (ePraiseDate);
	parent.session.pdformail.ePraiseDate.value = ePraiseDate;

/* SHAPEFACTORS: These are the retail customer desirability factors
 * relative to a Round Brilliant diamond, for diamonds of different shapes. Also
 * gives the constants used in calculating the approximate weights of the
 * different shapes from their dimensions.
 */
	var ShapeFactors = function(Shape){ // func1
	var ShapeArray = ["Round",1,0.0017005,"Oval",0.814,0.0019050,"Rectangular",0.755,0.0023955,"Square",0.835,0.0022975,"Marquise",0.846,0.0015230,"Navette",0.846,0.0015230,"Boat",0.856,0.0015230,"Pear",0.792,0.0018585,"Teardrop",0.792,0.0018585,"Heart",0.771,0.0015184,"Cushion",0.99,0.00180,"Trillion",0.846,0.00272,"Trilliant",0.846,0.00272,"",1,0.00174];
	for (j = 0 ; j < ShapeArray.length; j++){ // for,
	  if (ShapeArray[j] == Shape){ // if
	  ShapeDesireFactor = ShapeArray[j+1];
	  ShapeWeightFactor = ShapeArray[j+2];
} // final if
} // final for
	ShapeFactorsArray = [ShapeWeightFactor,ShapeDesireFactor];
	return ShapeFactorsArray;
}
	ShapeFactorsArray = new ShapeFactors(Shape);
	ShapeWeightFactor = ShapeFactorsArray[0];
	ShapeDesireFactor = ShapeFactorsArray[1];

alert("22 Shape = " + Shape);
alert("ShapeDesireFactor = " + ShapeDesireFactor);
alert("23 ShapeFactorsArray= " + ShapeFactorsArray);

/* IDEALIZED WEIGHT: This determines whether the subject is too tall
 * or too wide to have a Girdle Percent within the range commonly accepted
 * as representing the "Tolkowsky Ideal Range" of 57.3% to 61.9%.
 * If the stone is too tall, a new height is calculated to bring its ratio
 * to 61.9%; if too wide, a new mean girdle diameter is calculated to bring
 * its ratio to 57.3%. The weight of a stone with the idealized dimensions
 * is calculated using the standard appraiser's formulas. This is the
 * weight that is used to estimate the relative value of the subject. (Its
 * reported weight in Carats is not used except for identification.)
 * In principle, this causes the appraisal to be based on the largest "Ideal"
 * diamond that can be reground from the subject diamond. From time to time,
 * if in the opinion of the supervising appraiser the definition of the
 * "ideal range" changes, these values may simply be edited to reflect
 * current opinion.
 */
	WtCalc = function(Width1, Width2, Depth, ShapeWeightFactor){ //func2
	var GirdleMean = ((Width1 + Width2) / 2);
	var DepthPctCalc;
	DepthPctCalc = ((100 * Depth) / GirdleMean);
	var Divisor, Multiplier;
	if (Shape == "Round" && Cut == "Brilliant"){Divisor = 0.57; Multiplier = 0.63;}//
	else if (Shape == "Round" && Cut == "Modified Brilliant"){Divisor = 0.57; Multiplier = 0.63;}//		
	else if (Shape == "Round" && Cut == "Mine"){Divisor = 0.603; Multiplier = 0.687;}
	else if (Shape == "Round" && Cut == "Old Mine"){Divisor = 0.603; Multiplier = 0.687;}
	else if (Shape == "Round" && Cut == "Premium"){Divisor = 0.57; Multiplier = 0.63;}
	else if (Shape == "Round" && Cut == "European"){Divisor = 0.603; Multiplier = 0.687;}
	else if (Shape == "Round" && Cut == "Old European"){Divisor = 0.603; Multiplier = 0.687;}
			
	else if (Shape == "Square" && Cut == "Radiant"){Divisor = 0.65; Multiplier = 0.76;}
	else if (Shape == "Square" && Cut == "Princess"){Divisor = 0.65; Multiplier = 0.76;}
	else if (Shape == "Square" && Cut == "Modified Brilliant"){Divisor = 0.65; Multiplier = 0.76;}
	else if (Shape == "Square" && Cut == "Asscher"){Divisor = 0.65; Multiplier = 0.76;}
	else if (Shape == "Square" && Cut == "Emerald"){Divisor = 0.60; Multiplier = 0.73;}
	else if (Shape == "Square" && Cut == "Princess Plus"){Divisor = 0.65; Multiplier = 0.760;}
	else if (Shape == "Square" && Cut == "Premium"){Divisor = 0.634; Multiplier = 0.700;}
	
	else if (Shape == "Cushion" && Cut == "Mine"){Divisor = 0.603; Multiplier = 0.687;}	
	else if (Shape == "Cushion" && Cut == "Old Mine"){Divisor = 0.603; Multiplier = 0.687;}		
	else if (Shape == "Cushion" && Cut == "Brilliant"){Divisor = 0.603; Multiplier = 0.687;}	
	else if (Shape == "Cushion" && Cut == "Modified Brilliant"){Divisor = 0.603; Multiplier = 0.687;}

	else if (Shape == "Rectangular" && Cut == "Radiant"){Divisor = 0.65; Multiplier = 0.760;}
	else if (Shape == "Rectangular" && Cut == "Princess"){Divisor = 0.65; Multiplier = 0.760;}
	else if (Shape == "Rectangular" && Cut == "Modified Brilliant"){Divisor = 0.653; Multiplier = 0.760;}
	else if (Shape == "Rectangular" && Cut == "Asscher"){Divisor = 0.653; Multiplier = 0.760;}
	else if (Shape == "Rectangular" && Cut == "Emerald"){Divisor = 0.60; Multiplier = 0.73;}	
	else if (Shape == "Rectangular" && Cut == "Step"){Divisor = 0.60; Multiplier = 0.73;}
	else if (Shape == "Rectangular" && Cut == "Mixed"){Divisor = 0.60; Multiplier = 0.73;}	
	else if (Shape == "Rectangular" && Cut == "Asscher"){Divisor = 0.653; Multiplier = 0.760;}		
		
	else if (Shape == "Oval"){Divisor = 0.60; Multiplier = 0.720;}//
								
	else if (Shape == "Pear"){Divisor = 0.48; Multiplier = 0.75;}//
	
	else if (Shape == "Marquise"){Divisor = 0.48; Multiplier = 0.65;}//
	
	else if (Shape == "Heart"){Divisor = 0.557; Multiplier = 0.600;}//
	
	else if (Shape == "Trillion" || Shape == "Trilliant")
	{Divisor = 0.557; Multiplier = 0.680;
	}	//?
	
	else 
	{alert("Sorry, our formula cannot analyse that shape/cut combination.");
	}

alert("Shape / Ideals = " + Shape + " / " + Cut + " ( " + Multiplier + " / " + Divisor +" )");
		
	var NewGirdle = GirdleMean;
	var NewDepth = Depth;
	
	if (DepthPctCalc < (100 * Divisor)){ // i.e., if<57 div by .57
		NewGirdle = (Depth / Divisor);
		}
		
	if (DepthPctCalc > (100 * Multiplier)){ // i.e., if>63 mult by .63
		NewDepth = (GirdleMean * Multiplier);
		}

alert("Depth = " + Depth);
alert("NewDepth = " +  NewDepth);
alert("GirdleMean = " +  GirdleMean);
alert("NewGirdle = " +  NewGirdle);
alert("Weight = " + Weight);
	
	WtCalcRaw = (Math.pow(GirdleMean, 2) * Depth * 3.52 * ShapeWeightFactor);
	WtCalcRawTemp = (WtCalcRaw * 1000);
	WtCalcRaw = parseInt(WtCalcRawTemp) / 1000;
		//parent.session.pdformail.WtCalcRaw.value = WtCalcRaw;
alert("Calculated Weight Raw = " + WtCalcRaw);
	
	var WtCalc = Math.pow(NewGirdle, 2) * NewDepth * 3.52 * ShapeWeightFactor;
	return WtCalc;
	}

alert("W1: " + Width1 + ", W2: " + Width2 + ", D: " + Depth + ", SWF: " + ShapeWeightFactor);
		WtCalc = WtCalc(Width1, Width2, Depth, ShapeWeightFactor);	
	//if (WtCalc > Weight){WtCalc = Weight;}
	var WtCalcTemp;
	WtCalcTemp = (WtCalc * 1000);
	WtCalc = parseInt(WtCalcTemp) / 1000;
alert("24 Calculated Weight = " + WtCalc);///////////////////////////////////////////////////////////////////////////////////////////
var WtCalcNF = new NumberFormat();
WtCalcNF.setNumber(WtCalc);
WtCalcNF.setPlaces(3);
WtCalc$ = String(WtCalcNF.toFormatted());
	parent.session.pdformail.WtCalc.value = WtCalc$;
	document.FrontPage_Form1.WtCalc.value = (WtCalc$);
alert("WtCalcLastMoment = " + WtCalc);
alert("WeightLastMoment = " + Weight);
	var GScore;
	var GScoreRaw;
	GScore = (WtCalc / Weight);
	GScoreRaw = GScore;
alert("Raw Range = " + GScore);
	if (GScore >= 0.9949 && GScore < 1.0050) {
		GScore = 1.0000;
alert("Mid Range = " + GScore);
		}
	
	if (GScore >= 1.0050){
		GScore = (1 / GScore);
alert("High Range = " + GScore);
		}

alert("Finally = " + GScore);	
	var GScoreNF = new NumberFormat();
	GScoreNF.setNumber(GScore);
	GScoreNF.setPlaces(3);
	GScore = String(GScoreNF.toFormatted());
	parent.session.pdformail.GScore.value = GScore;
		document.FrontPage_Form1.GScore.value = (GScore);
	//parent.session.pdformail.GScoreRaw.value = GScoreRaw;

alert("25 Geometric Quality = " + GScore);
/* CCFACTOR: This locates the subject's clarity and color in a static
 * array of ratios of RELATIVE value as compared with a 1cFD diamond,
 * which is assigned a value of 1.00.
 */

	var CCFactor = function(Color,Clarity){  //func3

	var ClarityArray1 = ["F","a","FL","a","IF","b","VVS-1","c","VVS-2","d","VS-1","e","VS-2","f","SI-1","g","SI-2","h","SI-3","h","I-1","i","I-2","j","I-3","k","AGS 0 (No Comment)","a","AGS 0 (With Comment)","b","AGS 1","c","AGS 2","d","AGS 3","e","AGS 4","f","AGS 5","g","AGS 6","h","AGS 7","i","AGS 8","j","AGS 9","k","loupe clean","a","vvs1","c","vvs2","d","vs1","e","vs2","f","si1","g","si2","h","p1","i","p2","j","p3","k"];

	for (j = 0 ; j < ClarityArray1.length; j++){

	  if (ClarityArray1[j] == Clarity){
	  var ClarityFactorTemp = ClarityArray1[j+1];

alert("26 Clarity = " + Clarity);
alert("27 ClarityFactorTemp = " + ClarityFactorTemp);
	  	  break;
}
}
//ELEVEN CLARITIES
	var ClarityArray2 = ["a",0,"b",1,"c",2,"d",3,"e",4,"f",5,"g",6,"h",7,"i",8,"j",9,"k",10];
	for (j = 0 ; j < ClarityArray2.length; j++){
	  if (ClarityArray2[j] == ClarityFactorTemp){
	  var ClarityFactor = ClarityArray2[j+1];
alert("28 ClarityFactor = " + ClarityFactor);
	  	  break;
}
}
       /////////
	var ColorArray1 = ["D","aa","D-E","bb","E","cc","E-F","dd","F","ee","F-G","ff","G","gg","G-H","hh","H","ii","H-I","jj","I","kk","I-J","ll","J","mm","J-K","nn","K","oo","K-L","pp","L","qq","L-M","rr","M","ss","AGS 0","aa","AGS 0.5","cc","AGS 1","ee","AGS 1.5","gg","AGS 2","ii","AGS 2.5","kk","AGS 3","mm","AGS 3.5","oo","AGS 4","qq","AGS 4.5","ss","exceptional white +","aa","exceptional white","cc","rare white +","ee","rare white","gg","white","ii","very slightly tinted white","kk","slightly tinted white","mm","tinted white","qq","tinted colour","ss","tinted colour 1","ss","tinted colour 2","ss","tinted colour 3","ss"];

	for (j = 0 ; j < ColorArray1.length; j++){
	  if (ColorArray1[j] == Color){
	  var ColorFactorTemp = ColorArray1[j+1];

alert("29 Color = " + Color);
alert("30 ColorFactorTemp = " + ColorFactorTemp);
	  	  break;
}
}
//NINETEEN COLORS
	var ColorArray2 = ["aa",0,"bb",1,"cc",2,"dd",3,"ee",4,"ff",5,"gg",6,"hh",7,"ii",8,"jj",9,"kk",10,"ll",11,"mm",12,"nn",13,"oo",14,"pp",15,"qq",16,"rr",17,"ss",18];
	for (j = 0 ; j < ColorArray2.length; j++){
	  if (ColorArray2[j] == ColorFactorTemp){
	  var ColorFactor = ColorArray2[j+1];
alert("31 ColorFactor = " + ColorFactor);
	  	  break;
}
}
///////////
//color=6, clarity=3, CCFactor=0.34
//ARRAY (18+1 ROWS/colors, 10+1 COLUMNS/clarities)

	var CCTableArray = [
[1.000,0.920,0.800,0.650,0.500,0.400,0.300,0.200,0.120,0.118,0.117],
[0.900,0.800,0.695,0.575,0.460,0.380,0.295,0.200,0.118,0.116,0.115],
[0.800,0.680,0.590,0.500,0.420,0.360,0.290,0.200,0.116,0.114,0.113],
[0.715,0.595,0.525,0.455,0.400,0.345,0.280,0.195,0.114,0.110,0.109],
[0.630,0.530,0.460,0.410,0.380,0.330,0.270,0.190,0.112,0.109,0.108],
[0.560,0.465,0.420,0.375,0.355,0.310,0.260,0.185,0.110,0.107,0.106],
[0.490,0.420,0.380,0.340,0.330,0.290,0.250,0.180,0.108,0.106,0.105],
[0.445,0.385,0.355,0.315,0.305,0.275,0.240,0.180,0.106,0.102,0.101],
[0.400,0.350,0.330,0.290,0.280,0.260,0.230,0.180,0.104,0.100,0.099],
[0.360,0.325,0.295,0.265,0.253,0.240,0.220,0.175,0.100,0.099,0.098],
[0.320,0.300,0.260,0.240,0.225,0.220,0.210,0.170,0.100,0.098,0.097],
[0.280,0.260,0.235,0.220,0.208,0.200,0.185,0.160,0.098,0.097,0.096],
[0.240,0.220,0.210,0.200,0.190,0.180,0.160,0.150,0.096,0.095,0.094],
[0.210,0.195,0.188,0.180,0.170,0.163,0.150,0.135,0.094,0.093,0.092],
[0.180,0.170,0.166,0.160,0.150,0.145,0.140,0.120,0.092,0.091,0.090],
[0.160,0.152,0.148,0.144,0.137,0.133,0.129,0.113,0.090,0.089,0.088],
[0.140,0.135,0.132,0.129,0.123,0.120,0.117,0.107,0.088,0.087,0.086],
[0.120,0.117,0.115,0.113,0.110,0.108,0.106,0.100,0.086,0.085,0.084],
[0.100,0.098,0.096,0.094,0.092,0.090,0.088,0.086,0.084,0.083,0.082]];

	CCFactor = CCTableArray[ColorFactor][ClarityFactor];
	return CCFactor;
}
	CCFactor = CCFactor(Color,Clarity);                                   ///////////////orig
//CCFactor = Matrix(Weight, ColorFactor, ClarityFactor);                //////////////test

alert("32 CC Factor = " + CCFactor);
/* TABLE PERCENT: This assigns a relative value based on how far the subject falls
 * outside the commonly accepted ideal table percent range of 52% to 61%.
 */
	var TablePctFactor = function(TablePct){ //func4
	if ((TablePct == "") || (TablePct == 0)){
		TablePctFactor = 1;
} else if (TablePct < 52){
		TablePctFactor = (1 - ((52 - TablePct) * 0.01));
} else if ((TablePct >= 52) && (TablePct < 62)){
		TablePctFactor = 1;
} else {
		TablePctFactor = (1 - ((TablePct - 61) * 0.01));
}
		return (TablePctFactor);
}
	TablePctFactor = TablePctFactor(TablePct);
alert("33 TablePct = "+TablePct);
alert("34 TablePctFactor = "+TablePctFactor);
/* CROWN PERCENT: This assigns a relative value based on how far the subject falls
 * outside the commonly accepted ideal crown percent range of 14.2% to 16.2%.
 */
	var CrownPctFactor = function(CrownPct){  //func5
	if ((CrownPct == "") || (CrownPct == 0)){
		CrownPctFactor = 1;
}
	else if (CrownPct < 14.2){
		CrownPctFactor = (1 - ((14.2 - CrownPct) * 0.01));
}
	else if ((CrownPct >= 14.2) && (CrownPct < 16.2)){
		CrownPctFactor = 1;
}
	else {
		CrownPctFactor = (1 - ((CrownPct - 16.2) * 0.01));
}
	return (CrownPctFactor);
}
	CrownPctFactor = CrownPctFactor(CrownPct);
alert("35 CrownPct = " + CrownPct);
alert("36 CrownPctFactor = " + CrownPctFactor);
/* PAVILION PERCENT: This assigns a relative value based on how far the subject falls
 * outside the commonly accepted ideal pavilion percent range of 42.2% to 43.8%
 */
	var PavilionPctFactor = function(PavilionPct){  //func6
	if ((PavilionPct == "") || (PavilionPct == 0)){
		PavilionPctFactor = 1;
}
	else if (PavilionPct < 42.2){
		PavilionPctFactor = (1.00 - ((42.2 - PavilionPct) * 0.02));
}
	else if ((PavilionPct >= 42.2) && (PavilionPct < 43.8)){
		PavilionPctFactor = 1.00;
}
	else {
		PavilionPctFactor = (1.00 - ((PavilionPct - 43.8) * 0.01));
}
	return PavilionPctFactor;
}
	PavilionPctFactor = PavilionPctFactor(PavilionPct);
alert("37 PavilionPct = " + PavilionPct);
alert("38 PavilionPctFactor = " + PavilionPctFactor);
/* PROPORTIONS: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's proportions.

 */
	var ProportionsFactor = function(Proportions){// func7
	var ProportionsArray = ["Ideal",1,"Excellent",1,"Very Good",0.99,"Good",0.97,"Medium",0.97,"Fair",0.95,"Poor",0.93,"Very Poor",0.91,"Unusual",0.93,"",1,"very good",1,"good",0.98,"unusual",0.93];
	for (j = 0 ; j < ProportionsArray.length; j++){ // for

	if (ProportionsArray[j] == Proportions){ // if2
		ProportionsFactor = ProportionsArray[j+1];
} // final if2
} // final for
	return (ProportionsFactor);
} // final func
	ProportionsFactor = ProportionsFactor(Proportions);
alert("39 Proportions = " + Proportions);
alert("40 ProportionsFactor = " + ProportionsFactor);

/* FINISH: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's surficial finish.
 */
	var FinishFactor = function(Finish){ // func8
	var FinishArray = ["Ideal",1,"Excellent",1,"Very Good",1,"Good",1,"Medium",1,"Fair",0.99,"Poor",0.98,"Very Poor",0.97,"very good",1,"good",1,"medium",0.99,"poor",0.97,"",1];
	for (j = 0 ; j < FinishArray.length; j++){ // for1
		if (FinishArray[j] == Finish){ // if2
		FinishFactor = FinishArray[j+1];
} // final if2
} // final for1
	return (FinishFactor);
} // final func1
	FinishFactor = FinishFactor(Finish);
alert("41 Finish = " + Finish);
alert("42 FinishFactor = " + FinishFactor);
/* BRAND: This assigns a relative value ratio based on the
 * premium branding of a diamond.
 */
	var BrandFactor = function(Brand){ // func9
	var BrandArray = ["Elarea",1.1,"Gabrielle",1.15,"Hearts on Fire",1.15,"Lazare",1.15,"Millennium",1.15,"Rand",1.15,"Royal Asscher",1.15,"Tycoon",1.1,"8-Star",1.1,"",1];
	for (j = 0 ; j < BrandArray.length; j++){ // for1
		if (BrandArray[j] == Brand){ // if2
		BrandFactor = BrandArray[j+1];
} // final if2
} // final for1
	return (BrandFactor);
} // final func1
	BrandFactor = BrandFactor(Brand);
alert("43 Brand = " + Brand);
alert("44 BrandFactor = " + BrandFactor);

/* GIRDLE THICKNESS: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's minimum and maximum girdle thicknesses.
 */
	var GirdleFactor = function(GirdleMin, GirdleMax){ //func10
	var GirdleArray = ["Extremely Thin",0.92,"Very Thin",0.94,"Slightly Thin",0.96,"Thin",0.98,"Medium",1,"Slightly Thick",1,"Thick",0.98,"Very Thick",0.96,"Extremely Thick",0.94,"None",0.94,"",1,"very good",1,"good",1,"unusual",0.96];
	for (j = 0 ; j < GirdleArray.length; j++){
	  if (GirdleArray[j] == GirdleMin){
	  var GirdleMinFactor = GirdleArray[j+1];
	  }
}
	for (j = 0 ; j < GirdleArray.length; j++){
	  if (GirdleArray[j] == GirdleMax){
	  var GirdleMaxFactor = GirdleArray[j+1];
}
}
	GirdleFactor = ((GirdleMinFactor + GirdleMaxFactor) / 2);

	return (GirdleFactor);
}
	GirdleFactor = GirdleFactor(GirdleMin, GirdleMax);
alert("45 GirdleMin = " + GirdleMin);
alert("46 GirdleMax = " + GirdleMax);
alert("47 GirdleFactor = " + GirdleFactor);

/* GIRDLE STYLE: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's girdle style.
 */
	GirdleStyleFactor = function(GirdleStyle){// func11
	var GirdleStyleArray = ["Faceted",1.02,"faceted",1.02,"Partially Faceted",1.01,"partially faceted",1.01,"Not Faceted",1,"not faceted",1,"Smooth",1,"Polished",1,"polished",1,"None Stated",1,"None",1,"No Style Stated",1,"none",1,"",1];
	for (j = 0 ; j < GirdleStyleArray.length; j++){ // for
	  if (GirdleStyleArray[j] == GirdleStyle){ // if
	  var GirdleStyleFactor = GirdleStyleArray[j+1];
} // final if
} // final for
	  return (GirdleStyleFactor);
} // final func

	GirdleStyleFactor = GirdleStyleFactor(GirdleStyle);
alert("48 GirdleStyle = " + GirdleStyle);
alert("49 GirdleStyleFactor = " + GirdleStyleFactor);
/* CULET SIZE: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's culet size.
 */

	var CuletFactor = function(Culet){ // func 12
	if (Culet=="0")
	{Culet = (0.0001);
	}
		if (Number(1 * Culet)){ // if1
alert("50 Culet is a number, i.e., = " + Culet);
		CuletFactor = (1 - (Culet / 100));
alert("51 CuletFactor = " + CuletFactor);
		return (CuletFactor);

		} // final if1
		else { // else
alert("52 Culet is a string, i.e., = " + Culet);
			var CuletArray = ["Very Small",1,"Small",1,"Medium",0.9975,"Slightly Large",0.99,"Large",0.98,"Very Large",0.96,"Extremely Large",0.92,"Pointed",1,"Closed",1,"None",1,"",1];

								for (j = 0 ; j < CuletArray.length; j++){ // for
										if (CuletArray[j] == Culet){ // if2
								CuletFactor = CuletArray[j+1];
								break;
										} // final if2
								} // final for
					} // final else

		return (CuletFactor);
	} // final func 1
		CuletFactor =   CuletFactor(Culet);
alert("53 Culet = " + Culet);
alert("54 CuletFactor = " + CuletFactor);

/* FLUORESCENCE INTENSITY:This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's fluorescence intensity.
 */
	var FluorescenceFactor = function(Fluorescence){ //func13
	var FluorescenceArray = ["Nil",1,"nil",1,"Negligible",1,"None",1,"Inert",1,"Very Faint",1,"Faint",1,"Very Slight",0.995,"Slight",0.99,"slight",0.99,"Medium",0.985,"medium",0.985,"Moderate",0.985,"moderate",0.985,"Strong",0.98,"strong",0.98,"Very Strong",0.975,"",1];
	for (j = 0 ; j < FluorescenceArray.length; j++){
		if (FluorescenceArray[j] == Fluorescence){
			FluorescenceFactor = FluorescenceArray[j+1];
				  break;
}
}
		return (FluorescenceFactor);
}
	FluorescenceFactor =  FluorescenceFactor(Fluorescence);
alert("55 FluorescenceFactor = " + FluorescenceFactor);
/* FLUORESCENCE COLOR: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's fluorescence color.
 */
	var FluorColorFactor = function(FluorColor){ //func14
	var FluorColorArray = ["None",1,"(None Stated)",1,"Blue",1.01,"Blue-Green",1.005,"Green",1,"Green-Yellow",1,"Yellow",0.98,"Yellow-Orange",0.96,"Orange",0.94,"",1];
	for (j = 0 ; j < FluorColorArray.length; j++){
	  if (FluorColorArray[j] == FluorColor){
	  FluorColorFactor = FluorColorArray[j+1];
	  	  break;
}
}
	  return (FluorColorFactor);
}
	FluorColorFactor = FluorColorFactor(FluorColor);
alert("56 FluorColorFactor = " + FluorColorFactor);

/* POLISH: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's surficial polish.
 */
	var PolishFactor = function(Polish){ // func15
	
alert("Polish argument = " + Polish);	
	
	var PolishArray = ["Ideal",1,"Excellent",1,"Very Good",1,"Good",1,"Medium",1,"Fair",0.99,"Poor",0.98,"Very Poor",0.97,"",1];
	for (j = 0 ; j < PolishArray.length; j++){ // for
	  if (PolishArray[j] == Polish){ // if2
	  PolishFactor = PolishArray[j+1];
	  	  break;
} // final if2
} // final for
	  return (PolishFactor);
} // final func

alert("Polish before call = " + Polish);	
	PolishFactor = PolishFactor(Polish);
alert("57 PolishFactor = " + PolishFactor);

/* SYMMETRY: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's symmetry.
 */
	var SymmetryFactor = function(Symmetry){ //func16
	var SymmetryArray = ["No Major Asymmetry",1,"Table Off Center at 10x",0.96,"Culet Off Center at 10x",0.96,"Girdle Visibly Out of Round",0.96,"Girdle and Table Not Parallel",0.96,"Girdle Obviously Wavy at 10x",0.96,"Ideal",1,"Excellent",1,"Very Good",0.99,"Good",0.98,"Medium",0.97,"Fair",0.97,"Poor",0.96,"Very Poor",0.95,"Unusual",0.96,"",1];
	for (j = 0 ; j < SymmetryArray.length; j++){
	  if (SymmetryArray[j] == Symmetry){
	  SymmetryFactor = SymmetryArray[j+1];
	  	  break;
}
}
	  return (SymmetryFactor);
}
	SymmetryFactor = SymmetryFactor(Symmetry);
alert("58 SymmetryFactor = " + SymmetryFactor);
/* CUT: This assigns a relative value ratio based on the standard
 * terms used to describe a diamond's cutting style.
 */
	var CutFactor = function(Cut){ //func17
	var CutArray = ["(None Stated)",1,"Brilliant",1,"Modified Brilliant",1,"Emerald",1,"Old Mine",0.99,"Princess",1,"Princess Plus",1,"Premium",1,"Radiant",1,"Step",0.99,"Mixed",0.98,"Mine",0.99,"Old Mine",0.99,"European",0.99,"Old European",0.99,"",1];
	for (j = 0 ; j < CutArray.length; j++){
	  if (CutArray[j] == Cut){
	  CutFactor = CutArray[j+1];
	  	  break;
}
}
	  return (CutFactor);
}
	CutFactor = CutFactor(Cut);
alert("59 CutFactor = " + CutFactor);
/* AGS CUT GRADE: This assigns a relative value ratio based on the proprietary numbering system used
 * by American Gemological Laboratories to describe a diamond's combined cut grade.
 */
	var AGSCutFactor = function(AGSCut){ // func18
	var AGSCutArray = ["1",1,"0",1,"2",1,"3",1,"4",1,"5",1,"6",1,"7",1,"8",1,"9",1,"10",1,"",1,"(None Stated)",1];
	for (j = 0 ; j < AGSCutArray.length; j++){ // for
	  if (AGSCutArray[j] == AGSCut){ // if
	  AGSCutFactor = AGSCutArray[j+1];
	  break;
} // final if
} // final for
	  return (AGSCutFactor);
} // final func
	AGSCutFactor = AGSCutFactor(AGSCut);
alert("60 AGSCutFactor = " + AGSCutFactor);
/* IDEAL Bourse VALUE with PSYCHOLOGICAL EFFECT:
 * 1) Determines the slopes of the 0-3 and >3-20 carat sections of the graph from the current value of a 1cDF
 * 2) Determines which section includes the idealized calculated weight of the subject
 * 3) If the subject's idealized weight is 0.6-0.99 carats, adjusts relative value by -17.647%
 * 4) If the subject's idealized calculated weight is 1.0-1.4 carats, adjusts relative value by +17.647%
 * 5) This results in the estimated wholesale value of a theoretical flawless and colorless stone
 *    with the subject's idealized and calculated weight.
 */
	BourseValueIdeal = function(WtCalc){ // func19

	var Billig = 0.82353;
	var Teuer = 1.17647;

	var Slope0 = (BourseValue1cDF * 1.0);
	var Slope1 = (Slope0 * 0.85);
	var Slope2 = ((0.85 * BourseValue1cDF * Billig) - (0.6 * 0.85 * BourseValue1cDF)) / (0.4);
	var Slope3 = ((BourseValue1cDF * 0.85 * 1.4) - (BourseValue1cDF * 0.85 * Teuer)) / (0.4);
	var Slope4 = Slope1;
	var Slope5 = (Slope4 * 0.59);

alert(Slope0 +" " +Slope1 +" " +Slope2 +" " +Slope3 +" " +Slope4 +" " +Slope5);

alert("WtCalcLastMinute = " + WtCalc);
var BourseValueIdeal;
	if (WtCalc < 0.1){
alert('Too small to evaluate');
	BourseValueIdeal = 0;
	}
	else if ((WtCalc >= 0.1) && (WtCalc < 0.6)){
	BourseValueIdeal = (WtCalc * Slope1);
	}
	else if ((WtCalc >= 0.6) && (WtCalc < 1.0)){
	BourseValueIdeal = ((0.6 * Slope1) + ((WtCalc - 0.6) * Slope2)); 
	}
	else if ((WtCalc >= 1.0) && (WtCalc < 1.4)){
	BourseValueIdeal = (((1.0 * Slope1) * Teuer) + ((WtCalc - 1.0) * Slope3));
	}
	else if ((WtCalc >= 1.4) && (WtCalc < 3.0)){
	BourseValueIdeal = (WtCalc * Slope4);
	}
	else if ((WtCalc >= 3.0) && (WtCalc <= 20.0)){
	BourseValueIdeal = ((3.0 * Slope1) + ((WtCalc - 3.0) * Slope5));
	}
	else if (WtCalc > 20.0){
alert('Too large to evaluate');
	BourseValueIdeal = 0;
	}
	else {
	BourseValueIdeal = 99;
	}
	
    return BourseValueIdeal;
    
} // end func
	
alert("WtCalc = " + WtCalc);	
	BourseValueIdeal = BourseValueIdeal(WtCalc);
alert("61 BourseValueIdeal = " + BourseValueIdeal);
/* Bourse VALUE ACTUAL: This adjusts the current estimated Bourse value by all the factors determined above
 * to discount the subject stone's value by all of its deviations from ideal quality.
 */
	var BourseValue = function(WtCalc, ShapeDesireFactor, CCFactor, BrandFactor, PolishFactor, CuletFactor, FluorescenceFactor, FluorColorFactor, SymmetryFactor, CutFactor, AGSCutFactor, FinishFactor, GirdleFactor, CrownPctFactor, TablePctFactor, PavilionPctFactor, ProportionsFactor, GirdleStyleFactor){ // func20
	var AllQualityFactors = (ShapeDesireFactor * CCFactor * BrandFactor * PolishFactor * CuletFactor * FluorescenceFactor * FluorColorFactor * SymmetryFactor * CutFactor * AGSCutFactor * FinishFactor * GirdleFactor * CrownPctFactor * TablePctFactor * PavilionPctFactor * ProportionsFactor * GirdleStyleFactor);
	
alert("AllQualityFactors = " + AllQualityFactors);
	BourseValue = (WtCalc * BourseValueIdeal * AllQualityFactors);
	return (BourseValue);
} // final func

	BourseValue = BourseValue(WtCalc, ShapeDesireFactor, CCFactor, BrandFactor, PolishFactor, CuletFactor, FluorescenceFactor, FluorColorFactor, SymmetryFactor, CutFactor, AGSCutFactor, FinishFactor, GirdleFactor, CrownPctFactor, TablePctFactor, PavilionPctFactor, ProportionsFactor, GirdleStyleFactor);
alert("62 BourseValue = " + BourseValue);
/* JOBBER PROFIT: This uses empirical linear regression values to estimate the
 * jobber's markup depfinaling on the estimated Bourse price of a stone identical to the
 * idealized, calculated subject. If the estimated Bourse price is more than $15,000,
 * the markup is a fixed 10%. For lower prices a sliding scale adjustment is
 * applied.
 */
	var Y1j = ((Jobber1000 / 100) + 1);		// i.e., 1.25
	var Y2j = ((Jobber15000 / 100) + 1);		// i.e., 1.10
	var X1j = 1000;
	var X2j = 15000;
	JobberSlope = ((Y2j - Y1j) / (X2j - X1j));   	// m
	var WSArgument = (BourseValue);   		// x
	var JobberIntercept = 1.3;   			// b empirical
	if (BourseValue <= 15000){ // if
		JobberFactor = ((JobberSlope * WSArgument) + JobberIntercept); // WSArgument (y) = mx + b
} // final if
	else { // else
		JobberFactor = Y2j;  // 10% for all over $15,000
		if (JobberFactor < 1.10){ // if
			JobberFactor = 1.10;
		} // final if
} // final else
	WholesaleValue = BourseValue * JobberFactor;
	alert("63 Wholesale Value = " + WholesaleValue);
	
/* RETAIL: This applies the average retail markups for diamonds available from
 * the jobber for various amounts. The markup is normally 34% for all stones
 * costing the retailer $12,500 and up. The markup scales up to about 300% when
 * extrapolated to a theoretical stone costing $0 wholesale (108% for stones costing
 * exactly $200). These values are edited from time to time to reflect the supervising
 * appraiser's current opinion as to retail trfinals.
 */
 alert("after comment");
	var RetailValues = function(Survey200, Survey12500, WholesaleValue){ // func21
	var Y1 = ((Survey200 / 100) + 1);		// i.e., 2.08
	var Y2 = ((Survey12500 / 100) + 1);		// i.e., 1.34
	var X1 = 200;
	var X2 = 12500;
	var RetailSlope = ((Y2 - Y1) / (X2 - X1));   			// m
	var WSArgument = (WholesaleValue);   				// x
	var RetailIntercept = 2.1;   					// b empirical
	
alert("RetailIntercept = " + RetailIntercept);
	
	if (WholesaleValue <= 12500){ // if

		RetailFactor = ((RetailSlope * WSArgument) + RetailIntercept); // WSArgument (y) = mx + b
		} // final if
	else { // else
		RetailFactor = Y2;  // 34% for all over $12,500
		if (RetailFactor < 1.34){ // if
			RetailFactor = 1.34;
		} // final if
} // final else

alert("markUp = " + markUp );

	RetailValue = (WholesaleValue * Math.pow(RetailFactor, markUp));

alert("64 RetailFactor = " + RetailFactor);
alert("65 Retail Value = " + RetailValue);

	ValuePerCarat = (RetailValue / Weight);
alert("66 Weight (act) = " + Weight);
alert("67 Value per Carat = " + ValuePerCarat);
/* UNCERTIFIED DIAMONDS: This value applies the normal 4.5% surcharge
 * applied by retailers to cover their risks when dealing in uncertified
 * diamonds. It is used only in the abbreviated value estimator provided at e-Praise.com
 * as a convenience for users lacking suitable laboratory certificates,
 * and does not appear in the full appraisal results.
 */
	RetailValueUncert = (RetailValue * 1.045);
alert("69 Uncertified Retail Value = " + RetailValueUncert);

/* FORMAT NUMBERS: All the rest of the code in this JavaScript makes cosmetic
 * adjustments in the appearance of values to appear in the appraisal document.
 */
	var RetailValuesArray = [RetailValue, RetailValueUncert, RetailFactor, WholesaleValue, ValuePerCarat];
	return (RetailValuesArray);
} // final func

	RetailValuesArray = RetailValues(Survey200, Survey12500, WholesaleValue);
	
alert("RetailValuesArray = " + RetailValuesArray);	
	
	RetailValue = RetailValuesArray[0];
	RetailValueUncert = RetailValuesArray[1];
	WholesaleValue = RetailValuesArray[3];
	ValuePerCarat = RetailValuesArray[4];

var RetailNF = new NumberFormat();  //new?
RetailNF.setNumber(RetailValue);
RetailNF.setPlaces(0);
var RV1 = String(RetailNF.toFormatted());
RetailValue=("$US " + RV1 + ".00");
alert("RetailValue" + RetailValue);

var UncertNF = new NumberFormat();
UncertNF.setNumber(RetailValueUncert);
UncertNF.setPlaces(0);
var RV2 = String(UncertNF.toFormatted());
RetailValueUncert=("$US " + RV2 + ".00");

var PerCaratNF = new NumberFormat();
PerCaratNF.setNumber(ValuePerCarat);
PerCaratNF.setPlaces(0);
var RV4 = String(PerCaratNF.toFormatted());
ValuePerCarat=("($US " + RV4 + ".00 per Carat)");

var WholesaleNF = new NumberFormat();
WholesaleNF.setNumber(WholesaleValue);
WholesaleNF.setPlaces(0);
var RV3 = String(WholesaleNF.toFormatted());
WholesaleValue=("$US " + RV3 + ".00");

var ePraiseGrade = ("     Geometric e-Praise Cut Score (eCS) = " + GScore);
var IdealizedWt = ("Idealized Weight = " + WtCalc);

		parent.session.pdformail.ePraiseGrade.value = ePraiseGrade;		
		parent.session.pdformail.IdealizedWt.value = IdealizedWt;

		document.FrontPage_Form1.RetailValue.value = (RetailValue);
		parent.session.pdformail.RetailValue.value = RetailValue;
		
		//sessvars.gross=RetailValue;
		
		document.FrontPage_Form1.RetailValueUncert.value = (RetailValueUncert);
		parent.session.pdformail.RetailValueUncert.value = RetailValueUncert;
		document.FrontPage_Form1.ValuePerCarat.value = (ValuePerCarat);
		parent.session.pdformail.ValuePerCarat.value = ValuePerCarat;
		
		//sessvars.percarat=ValuePerCarat;
		
		document.FrontPage_Form1.WholesaleValue.value = (WholesaleValue);
		parent.session.pdformail.WholesaleValue.value = WholesaleValue;
} // final func0

/* NumberFormat 1.0.3
 * v1.0.3 - 23-March-2002
 * Credit:  http://www.mredkj.com
 */

/* NumberFormat -The constructor
 * num - The number to be formatted
 */
function NumberFormat(num){
	// member variables
	this.num;
	this.numOriginal;
	this.isCommas;
	this.isCurrency;
	this.currencyPrefix;
	this.places;
	// external methods
	this.setNumber = setNumberNF;
	this.toUnformatted = toUnformattedNF;
	this.setCommas = setCommasNF;
	this.setCurrency = setCurrencyNF;
	this.setCurrencyPrefix = setCurrencyPrefixNF;
	this.setPlaces = setPlacesNF;
	this.toFormatted = toFormattedNF;
	this.getOriginal = getOriginalNF;
	// internal methods
	this.getRounded = getRoundedNF;
	this.preserveZeros = preserveZerosNF;
	this.justNumber = justNumberNF;
	// setup defaults
	this.setNumber(num);
	this.setCommas(true);
	this.setCurrency(true);
	this.setCurrencyPrefix('$');
	this.setPlaces(2);
}

/* setNumber - Sets the number
 * num - The number to be formatted
 */
function setNumberNF(num){
	this.numOriginal = num;
	this.num = this.justNumber(num);
}

/* toUnformatted - Returns the number as just a number.
 * If the original value was '100,000', then this method will return the number 100000
 * v1.0.2 - Modified comments, because this method no longer returns the original value.
 */
function toUnformattedNF(){
	return this.num;
}

/* getOriginal - Returns the number as it was passed in, which may include non-number characters.
 * This function is new in v1.0.2
 */
function getOriginalNF(){
	return this.numOriginal;
}

/* setCommas - Sets a switch that indicates if there should be commas
 * isC - true, if should be commas; false, if no commas
 */
function setCommasNF(isC){
	this.isCommas = isC;
}

/* setCurrency - Sets a switch that indicates if should be displayed as currency
 * isC - true, if should be currency; false, if not currency
 */
function setCurrencyNF(isC){
	this.isCurrency = false;
}

/* setCurrencyPrefix - Sets the symbol that precedes currency.
 * cp - The symbol
 */
function setCurrencyPrefixNF(cp){

	this.currencyPrefix = cp;
}

/* setPlaces - Sets the precision of decimal places
 * p - The number of places. Any number of places less than or equal to zero is considered zero.
 */
function setPlacesNF(p){
	this.places = p;
}

/* toFormatted - Returns the number formatted according to the settings (a string)
 */
function toFormattedNF(){
	var pos;
	var nNum = this.num; // v1.0.1 - number as a number
	var nStr;            // v1.0.1 - number as a string
	// round decimal places
	nNum = this.getRounded(nNum);
	nStr = this.preserveZeros(Math.abs(nNum)); // this step makes nNum into a string. v1.0.1 Math.abs
	if (this.isCommas)
	{
		pos = nStr.indexOf('.');
		if (pos == -1)
		{
			pos = nStr.length;
		}
		while (pos > 0)
		{
			pos -= 3;
			if (pos <= 0) break;  // added braces
			nStr = nStr.substring(0,pos) + ',' + nStr.substring(pos, nStr.length);
		}
	}
	nStr = (nNum < 0) ? '-' + nStr : nStr; // v1.0.1
	if (this.isCurrency)
	{
		// add dollar sign in front
		nStr = this.currencyPrefix + nStr;
	}
	return (nStr);
}

/* getRounded - Used internally to round a value
 * val - The number to be rounded
 */
function getRoundedNF(val){
	var factor;
	var i;
	// round to a certain precision
	factor = 1;
	for (i=0; i<this.places; i++)
	{	factor *= 10; }
	val *= factor;
	val = Math.round(val);
	val /= factor;
	return (val);
}

/* preserveZeros - Used internally to make the number a string
 * 	that preserves zeros at the final of the number
 * val - The number
 */
function preserveZerosNF(val){
	var i;
	// make a string - to preserve the zeros at the final
	val = val + '';
	if (this.places <= 0) {return val;} // leave now. no zeros are necessary - v1.0.1 less than or equal
	var decimalPos = val.indexOf('.');
	if (decimalPos == -1)
	{
		val += '.';
		for (i=0; i<this.places; i++)
		{

			val += '0';
		}
	}
	else
	{
		var actualDecimals = (val.length - 1) - decimalPos;
		var difference = this.places - actualDecimals;
		for (i=0; i<difference; i++)
		{
			val += '0';
		}
	}
	return val;
}

/* justNumber - Used internally to parse the value into a floating point number.
 * If the value is not set, then return 0.
 * If the value is not a number, then replace all characters that are not 0-9, a decimal point, or a negative sign.
 *
 *  Note: The regular expression cleans up the number, but doesn't get rid of - and .
 *  Because all negative signs and all decimal points are allowed,
 *  extra negative signs or decimal points may corrupt the result.
 *  parseFloat will ignore all values after any character that is NaN.
 *
 *  A number can be entered using special notation.
 *  For example, the following is a valid number: 0.0314E+2
 *
 * This function is new in v1.0.2
 */
function justNumberNF(val){
	val = (val==null) ? 0 : val;
	// check if a number, otherwise try taking out non-number characters.
	if (isNaN(val))
	{
		var newVal = parseFloat(val.replace(/[^\d\.\-]/g, ''));
		// check if still not a number. Might be undefined, '', etc., so just replace with 0.
		// v1.0.3
		return (isNaN(newVal) ? 0 : newVal);
	}
	// return 0 in place of infinite numbers.
	// v1.0.3

	else if (!isFinite(val))
	{
		return 0;

  }
	return val;
} // final justnumNF

