// NO LONGER Requires ListOnBC, 
// Now requires class ListOn

var OldRow        = "";
var OldColor      = "";
var NoDel         = new Array();
var oStatus=window.status;

function LoadFlash(){ // Workaround for Flash in IE.  Define fv1-fv6 in LoadFlashVars.js, which is not shared.
 document.write(fv1 + '\n');
 document.write(fv2 + '\n');
 document.write(fv3 + '\n');
 document.write(fv4 + '\n');
 document.write(fv5 + '\n');
 document.write(fv6 + '\n');
 document.write('</object>\n');
}

function ValidateSearch(theField,EnterMess){
 if (!EnterMess) EnterMess = "";
 if (theField.value == "" || theField.value == EnterMess){
  alert("Please enter a word or phrase to search for");
  theField.focus();
  return false;
 }
 return true;
}

function ShowStatus(theMess,theForm){
 if (!theForm) theForm=document.entryform;
 if (theForm){
  if (theForm.DisplayStatus){
   theForm.DisplayStatus.value=theMess;
  }
 }
 oStatus = window.status;
 window.status = theMess;
 return true;
}

function RestoreStatus(theForm){
 if (!theForm) theForm=document.entryform;
 if (theForm){
  if (theForm.DisplayStatus){
   theForm.DisplayStatus.value=oStatus;
  }
 }
 window.status = oStatus;
 return true;
}

function BlankStatus(theForm){
 if (!theForm) theForm=document.entryform;
 if (theForm){
  if (theForm.DisplayStatus){
   theForm.DisplayStatus.value='';
  }
 }
 window.status = '';
 return true;
}

function ListOn(theID) {
 wasListClass = document.getElementById(theID).className;
 document.getElementById(theID).className = "ListOn";
}

function ListOff(theID) {
 document.getElementById(theID).className = wasListClass;
}

function NewListOn(theObj) {
 wasListClass = theObj.className;
 theObj.className = "ListOn";
 ShowStatus(theObj.title);
}

function NewListOff(theObj) {
 theObj.className = wasListClass;
 RestoreStatus();
}

function RotateImage(theObj, thePrefix, MaxNum) {
 CurrentNum = theObj.src.substr(theObj.src.length-5,1)
 if (CurrentNum == MaxNum) {
  NextNum=1;
 }else{
  NextNum = eval(CurrentNum) +1;
 }
 
 NextSrc = thePrefix +NextNum +".jpg";
 theObj.src=NextSrc;
}

function ToggleImage(theObj,Image1,Image2) {
 if (theObj.src.search(Image1)>=0 ) {
  theObj.src=Image2;
 }else{
  theObj.src=Image1; 
 }
}
/////////////////////////////////////////////////////////////////////////// GENERIC EDITING

function CheckFocus(Checkfield,trueFocus,falseFocus){     // Moves focus to field based on whether checkbox is checked
 if (Checkfield.checked) {
  trueFocus.focus();
 }else{
  falseFocus.focus();
 }
}

function CheckFocusBlank(Checkfield, Focusfield, Blankfield){
 if (Checkfield.checked){
  Focusfield.focus(); 
 }else{
  Blankfield.value="";
 }
}

function DollarFormat(Num,Width,Cents) {
// Pass Cents as "CENTS" if you want to force the value returned 
// to contain cents even if Num does not.
// Pass Cents as "NO" if you want to round to the nearest $
	
	var theNumber = parseInt(Num);
	
// This version returns blank Num is NaN 
	if ( isNaN(theNumber)) {
		return " ";
	}

	end = "";
//	if (Width < Num.length) Width = 0;
	
	if (Cents == "NO") {
		Num = "" + Math.round(Num);
		
	}else{
		dec = Num.indexOf(".");
		if (dec > -1) end += Num.substring(dec,Num.length);
		
		if (end.length >3) {
			var theCents = Math.round(end.substring(1,3) + "." + end.substring(3,end.length));
			end = "." + theCents;
		}
			 
		if ( (end.length >1 && end.length <3) || Cents == "CENTS"){
			trailing = ".00";
			end += trailing.substring(end.length,3);
		}
		
		Num = "" + theNumber;
	}
	
	var temp1 = "";
	var temp2 = "";
	var count = 0;
	for (var k = Num.length-1; k >= 0; k--) {
		var oneChar = Num.charAt(k);
		if (count == 3) {
			temp1 += ",";
			temp1 += oneChar;
			count = 1;
			continue;
		}else {
			temp1 += oneChar;
			count ++;
	   }
	}
	
	for (var k = temp1.length-1; k >= 0; k--) {
		var oneChar = temp1.charAt(k);
		temp2 += oneChar;
	}
	
	var TotLength = temp2.length +end.length;
	
	if (TotLength < Width){
		var Spaces = "            ";
		temp2 = Spaces.substring(1,Width -TotLength) +temp2;
	}
	temp2 = "$" + temp2 + end;
	return temp2;
}

function MakeNumber(theStr){
 var DollarSpot= theStr.indexOf("$");
 
 if (DollarSpot>=0){
  var stripped = theStr.substring(DollarSpot +1);
 }else{
  var stripped = theStr;
 }
 
 var aStr = stripped.split(",");
 var PureNum="";
 for (var i = 0; i < aStr.length; i++) {
  PureNum = PureNum +aStr[i];
 }
 
 return parseFloat(PureNum);
}

////////////////////////////////////////////////////////////////////   OTS ORDERING and SHIPPING
/*
function UpdateOrder(){
 var isChanged = document.Orders.isChanged.value;
 theURL = "../UpdateOrder.cfm?gotoURL=Checkout.cfm&isChanged=" +isChanged;
 window.location=theURL;
} 
*/
function Add2Order(prodID){
 var prodField="Add" +prodID;
 theGuest = document.getElementById(prodField).value;
 if (!theGuest){
  alert("You are using either a very old or non-standard browser, which cannot place a secure order.  Please call " +OrderPhone+ " to place your order over the telephone.");
  return false;
 }
 if (theGuest=="New"){
  theNextURL = "MyAccount/GuestList.cfm?action=ADD&gotoURL=" +thisURL+ "&NewOrder=" +prodID;
 }else{
  theNextURL = "AddOrder.cfm?gotoURL=" +thisURL+ "&p=" +prodID +"&g=" +theGuest;  
 }

 // If user selected an item that uses aXtra (cf array, e.g.,  used for Cranberry Creations) we have to set xField's value
  if (document.getElementById("x" +prodID+ "_1")){
  	for (var i = 1;i <=3; i++) {
    xField = document.getElementById("x" +prodID+ "_" +i);
    if (xField){       // For pages on which we mix Cranberry Creations with other contents
     if (xField.checked){xValue=xField.value;}
    }
   }
   theNextURL = theNextURL +"&x=" +xValue;
  }
 
 window.location=theNextURL;
 return true;
}

function MustBeNumber(theID){
 theVal = document.getElementById(theID).value;
 if (isNaN(theVal)){
  alert("Please Enter a Number");
  document.getElementById(theID).select();
  return false;

 }else{
  OrderChanged();
  return true;
 }
}

function OrderChanged() {
 document.Orders.isChanged.value=1;
}

function SetShipCost(theKey){
 prodField  = "prod"  +theKey;
 shipField  = "ship"  +theKey;
 orderField = "order" +theKey;
 scField    = "sc"    +theKey;
  
 prodTotal  = MakeNumber(document.getElementById(prodField).value);
 shipValue  = document.getElementById(shipField).value;

 Dols=shipValue.indexOf("$")
 if (Dols >0){
  aShip    =shipValue.split("$");
  ShipCost =aShip[1];
 }else{
  aShip    =shipValue.split("%");
  ShipCost =Math.round(aShip[1]*prodTotal);
 }
 newOrderTot = prodTotal +parseFloat(ShipCost);

 document.getElementById(scField).value    = DollarFormat(ShipCost+"",10,"CENTS");
 document.getElementById(orderField).value = DollarFormat(newOrderTot+"",10,"CENTS");
 OrderChanged();
}

//////////////////////////////////////////////////////////////////  WINDOWS

function LoginParent() {
 camefrom.document.loginform.username.focus();
 window.close(); 
}

function MoveParent(newURL){
	camefrom.location=newURL;
	window.close(); 
}

function PictureWindow(theImage,theDescrip) {
 if (theDescrip) {
  theURL = "BigPicture.cfm?theImage=" +theImage +"&theDescrip=" +theDescrip;
 }else{
  theURL = "BigPicture.cfm?theImage=" +theImage;
 }

	if (!window.Big_window||Big_window.closed) { 
		Big_window = window.open(theURL,"Bigw","scrollbars,resizable,width=600,height=500"); 
	}else{
		Big_window.location =theURL;
		Big_window.focus();
	}	
 return false;
//	Big_window.camefrom = self;
}


function ImageLinkWin() {
	if (!window.Img_window||Img_window.closed) { 
		Img_window = window.open("ImageLink.cfm","Imgw","scrollbars,resizable,width=600,height=500"); 
	}else{
		Img_window.location =theURL;
		Img_window.focus();
	}	
 return false;
}

function PortraitWindow(theImage,theTitle) {
 theURL="PortraitWindow.cfm?Image=" +theImage
      + "&Title=" +theTitle;

	if (window.portrait_window) {portrait_window.close();}

	portrait_window = window.open(theURL,"LargePortrait","resizable,width=425,height=475");
	portrait_window.camefrom = self;
}
 
function HelpWindow(theURL,WinSize) {
 if (!WinSize){WinSize= "width=600,height=400";}
 WinAttributes = "scrollbars,resizable," +WinSize;
 
	if (!window.Help_window||Help_window.closed) { 
		Help_window = window.open(theURL,"Help",WinAttributes);
	}else{
		Help_window.location =theURL;
		Help_window.focus();
	}	
	Help_window.camefrom = self;
 return false;
}

////////////////////////////////////////////////////////////////////   MM
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


