function validate() {
var thisf; 
var errstr = "";
	
	if (typeof cvld != 'undefined') {
		
		for(i = 0; i < document.frm.length; i++) {
		thisf = document.frm[i];

		  	if (thisf.type == 'file' && thisf.value.length > 1){
			//	alert(thisf.type+" is type for fld with value of "+thisf.value+" and name is "+thisf.name); 
		  	show_patient_flag = 1;
		  	} 
	
		  	if(cvld[i] != null && cvld[i] != ''){  
				// B   is this variable not supposed to be left blank? 
				if (cvld[i] == 'b' && (thisf.value == '' || thisf.type == 'checkbox' && thisf.checked != true)){ 
				errstr += "* "+cvldmsg[i]+"\r";
				rowbg(cvldrow[i],i);
				}				
				// F  is this FILE variable not supposed to be left blank? (works for file filds too)
				if (cvld[i] == 'f' && thisf.value == ''){ 
		//		alert(i+"* "+cvldmsg[i]);
				var nextf = i+1; 
					if(document.frm[nextf].type != 'hidden'){
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
					}
				}				
				// SB    is this DD list variable not supposed to be left blank? 
				else if (cvld[i] == 'sb' && thisf.options[thisf.options.selectedIndex].value == ''){ 
				errstr += "* "+cvldmsg[i]+"\r";
				rowbg(cvldrow[i],i);
				}
				// EE    is this variable supposed to be in email format
				else if (cvld[i] == 'ee'){
					if (thisf.value.indexOf("@") == -1 || thisf.value.indexOf(".") == -1 || thisf.value.indexOf(" ") != -1){ 
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
					}
				}
				// is this variable supposed to be an EXACT length?
				else if (cvld[i].indexOf("el") != -1) {
				len = cvld[i].substr(cvld[i].indexOf("l")+1, cvld[i].length);
					if(parseInt(len) != thisf.value.length){
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
					}
				}
				// is this variable supposed to be at least a certain length?
				else if (cvld[i].indexOf("l") != -1) {
				len = cvld[i].substr(cvld[i].indexOf("l")+1, cvld[i].length);
					if(parseInt(len) > thisf.value.length){
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
					}
				}
			
		  	}
		}
	}

	if(errstr != ""){
 	alert("Please complete the required fields now before proceeding\n\n"+errstr);
	// window.status = getfocus;
 	eval(getfocus);
 	getfocus = '';
 	recolor = '';
 	nohilite = 1;
 	return false;
 	}
 	else{
   		if(show_patient_flag == 1){
   		show_patient_div();
   		}
 	return true;
 	}
}
// end validate()

var getfocus = '';
var nohilite = 0;
var show_patient_flag = 0;
var outrowid = '';
var recolor = '';
rowcbg = new Array(); 
 
function rowbg(rowid,onoff){
var table = 'formtab'; 
var r=document.getElementById(table).getElementsByTagName( "tr" )[rowid]; 

//alert(rowid+rowcbg[rowid]+" onoff= "+onoff);
	if(rowcbg[rowid] == null || rowcbg[rowid].length < 5){
	rowcbg[rowid] = r.getAttribute('bgcolor'); //r.style["backgroundColor"];
//	alert(rowid+rowcbg[rowid]+" => "+r.style["backgroundColor"]);
	}
	// do color
	if(onoff == 'off'){
	r.style["backgroundColor"]=rowcbg[rowid];
	}
	else if(onoff == 'on' &&  nohilite == 0){
//	r.style["backgroundColor"]='#FFFFCC';
	r.style["backgroundColor"]='#FFF5C3'; // Color Modified as you instructed 
	}
	else if(onoff != 'on' && onoff != 'off')  { // turn red and punish the infidel
	r.style["backgroundColor"]='#FFBBBB';
		if(getfocus == '' && recolor == ''){
// alert(onoff+" != 'on'");
		getfocus = "document.frm["+onoff+"].focus();"; //document.frm["+onoff+"].select();";
		}
		if(outrowid == rowid && recolor == ''){
//alert(rowid+rowcbg[rowid]+" onoff= "+onoff);
		getfocus += " rowbg("+rowid+",3000);";
		recolor = 'done';
		}
	}
		if(onoff == 'on')	outrowid = rowid;

nohilite = 0;
}

function show_patient_div() {
	if(document.all.loading.style){
	document.all.loading.style.bottom = screen.height/2-150;
	document.all.loading.style.left = screen.width/2-150;
	document.all.loading.style.visibility ="visible";
	}
	else if(document.layers){
	document.layers.loading.bottom = screen.height/2-150;
	document.layers.loading.left = screen.width/2-150;
	document.layers.loading.visibility = "visible";
	}
	 
}

// i kept this here to check out the diff later...
function FormatAmount(amt,CommaDelimiter){
if (amt.indexOf(".")){
splt_amt=amt.split(".");
amt=splt_amt[0];
}
amt = amt.replace(/\D/g,""); 
 var samt = new String(amt);
 if (samt.length < 3) { return samt; } 
 for (var i = 0; i < Math.floor((samt.length-(1+i))/3); i++)
 {
   samt = samt.substring(0,samt.length-(4*i+3)) + CommaDelimiter + samt.substring(samt.length-(4*i+3));
 }
 return samt;
}



function bull_fill(){
f = document.frm; //array as one letter
if(f.flybulls.value != ''){
alert("Clear the list below if you want to redraw the bullet list from fields above");
return;
}
var out = "";
 if(f.price.value != '' && bull_fill_chk("price") == 1) out += "* $"+FormatAmount(f.price.value,",")+"\n";
 if(f.sqfeet.value != '' && bull_fill_chk("sqfeet") == 1) out += "* "+f.sqfeet.value+" Square Feet\n";
 if(f.lotsize.value != '' && bull_fill_chk("lotsize") == 1) out += "* Lot Size: "+f.lotsize.value+"\n";
 if(f.yrBuilt.value != '' && bull_fill_chk("yrBuilt") == 1) out += "* Built in "+f.yrBuilt.value+"\n";
 if(f.bedrooms.value != '' && bull_fill_chk("bedrooms") == 1) out += "* "+f.bedrooms[f.bedrooms.selectedIndex].text+" Bedrooms\n";
 if(f.bathrooms.value != '' && bull_fill_chk("bathrooms") == 1) out += "* "+f.bathrooms[f.bathrooms.selectedIndex].text+" Bathrooms\n";
 if(f.garage.value != '' && bull_fill_chk("garage") == 1) out += "* "+f.garage[f.garage.selectedIndex].text+" Garage\n"; 
 if(f.propTax.value != '' && bull_fill_chk("propTax") == 1) out += "* Taxes: $"+FormatAmount(f.propTax.value,",")+"\n";
 if(f.heating.value != '' && bull_fill_chk("heating") == 1) out += "* "+f.heating[f.heating.selectedIndex].text+" Heating\n";
 if(f.cooling.value != '' && bull_fill_chk("cooling") == 1) out += "* "+f.cooling[f.cooling.selectedIndex].text+"\n";
 if(f.water.value != '' && bull_fill_chk("water") == 1) out += "* "+f.water[f.water.selectedIndex].text+" Water\n";
 if(f.sewer.value != '' && bull_fill_chk("sewer") == 1) out += "* "+f.sewer[f.sewer.selectedIndex].text+"\n";
chks = ":"; 
f.flybulls.value = out;
// alert("Your property vital stats are now in the field below for submission for the the print flyer. Please make any adjustments you need to directly below so your flyer will be perfect for production.");
}

 var chks = ":";
function bull_fill_chk(fld){
var strout2; var strout; var thisf;
  if(chks == ":"){
	for(i = 0; i < document.frm.length; i++) {
	thisf = document.frm[i]; 
		if(thisf.type == 'checkbox' && thisf.checked == true){
		chks += thisf.value+":"; 
		}
	}
  }
	if(chks.indexOf(fld) != -1)
	return 1;
}
		
function confirmdelete(url,msg){
		window.status = 'Delete';
	var del= confirm (msg);

		if(del){
						 window.location.href = url;
		}
	else{
//		alert('User Deletion Cancelled');
		}
}	


function banner_frame(){
 if (self != top){
 location = '/';
 }
}
        function txt_front(sflag){
                if (document.frm.front_head != null){
                 if (document.frm.front_head.value == "Front Headline"){
                 document.frm.front_head.value = "";
                 }
                }
         if(sflag == 'submit'){
         window.blur();
         }
        }

function ccon(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="FFFFFF";}}
function ccoff(oTd) {if (!oTd.contains(event.toElement)) {oTd.bgColor="E9F8FC";}}
		
// dblue = "#1b81c8" Lblue="#daf5f1" turq="#138b91" lturq="#cff2f1" >
		
		
function AppWin(url, wname, pl, pt) {

location=url;
return;


var w = 780;
var h = 550;
pt = pt - 5; // height tweak
 // Nav 4 gives true screen pos %, while default assumes % on 640X480
 if (parseInt(navigator.appVersion) >= 4) {
   if((screen.availWidth * .85) > w) { w = screen.availWidth * .85;  }
   if((screen.availHeight * .85) > h) { h = screen.availHeight * .85; }
 winX = (screen.availWidth - w)*pl*.01;
 winY = (screen.availHeight - h)*pt*.01;
 }
aWin = window.open(url, wname,'scrollbars=yes,status=yes,resizable=yes,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
 if (aWin.focus) {
 aWin.focus();
 }
}

function PopWin(url, wname, w, h, pl, pt) {
var winX = pl;
var winY = pt;
 // Nav 4 gives true screen pos %, while default assumes % on 640X480
 if (parseInt(navigator.appVersion) >= 4) {
 winX = (screen.availWidth - w)*pl*.01;
 winY = (screen.availHeight - h)*pt*.01;
 }
pWin = window.open(url, wname,'scrollbars=yes,status=no,dependent,resizable=yes,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
 if (pWin.focus) {
 pWin.focus();
 }
}

function popDesc(menuName,on,l,t) {
var DL_bNS4=(document.layers);
var DL_bNS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
var DL_bDOM=(document.getElementById);
var DL_bIE=(document.all);
var DL_bIE4=(DL_bIE && !DL_bDOM);
var DL_bMac = (navigator.appVersion.indexOf("Mac") != -1);
var DL_bIEMac=(DL_bIE && DL_bMac);
var DL_bIE4Mac=(DL_bIE4 && DL_bMac);
var DL_bNS =(DL_bNS4 || DL_bNS6);

                if (on) {
                        if (DL_bNS4) {
                        document.layers[menuName].left = l;
                        document.layers[menuName].top = t;
                        document.layers[menuName].visibility = "show";
                        } 
					    else {
						   if(DL_bDOM)
		                   DL_oLayer=document.getElementById(menuName);
					       else
					       DL_oLayer = window[menuName];
                        DL_oLayer.style.left = l;
                        DL_oLayer.style.top = t;
                        DL_oLayer.style.visibility="visible";
                        }
                } else {
                        if (DL_bNS4) {
                        document.layers[menuName].visibility = "hide";
                        } 
						else {
						   if(DL_bDOM)
		                   DL_oLayer=document.getElementById(menuName);
					       else
					       DL_oLayer = window[menuName];
                        DL_oLayer.style.visibility="hidden";
                        }
                }

}

/*
Pungo Spell Copyright (c) 2003 Billy Cook, Barry Johnson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


// Public functions --------------------------------

// spellCheck - spell check a field
function spellCheck( formName, fieldName, spelltext ) {

   var h_spellform = document.forms['spell_form'];
   h_spellform.spell_formname.value = formName;
   h_spellform.spell_fieldname.value = fieldName;
   h_spellform.spellstring.value = document.forms[formName][fieldName].value;
   openSpellWin(650, 400);
   h_spellform.submit();
   return true;
}

// Private functions -------------------------------

// globals
var wordindex = -1;
var offsetindex = 0;
var ignoredWords = Array();

function openSpellWin(width, height) {
  window.open("", "spellWindow", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width+',height='+height+'\'');
}

// mispelled word object
//
function misp(word, start, end, suggestions) {
   this.word = word;               // the word
   this.start = start;             // start index
   this.end = end;                 // end index
   this.suggestions = suggestions; // array of suggestions
}

// replace the word in the misps array at the "wordindex" index.  The
// misps array is generated by a PHP script after the string to be spell
// checked is evaluated with pspell
//
function replaceWord() {
   var frm = document.fm1;
   var strstart = '';
   var strend;

   // if this isn't the beginning of the string then get all of the string
   // that is before the word we are replacing
   if ( misps[ wordindex ].start != 0 )
       strstart = mispstr.slice( 0, misps[ wordindex ].start + offsetindex);

   // get the end of the string after the word we are replacing
   strend = mispstr.slice( misps[ wordindex ].end + 1 + offsetindex);
  
   // rebuild the string with the new word
   mispstr = strstart +  frm.changeto.value  + strend;

   // update offsetindex to compensate for replacing a word with a word
   // of a different length.
   offsetindex += frm.changeto.value.length - misps[ wordindex ].word.length;

   // update the word so future replaceAll calls don't change it
   misps[ wordindex ].word = frm.changeto.value;

   nextWord(false);
}

// replaces all instances of currently selected word with contents chosen by user. 
// note: currently only replaces words after hilighted word.  I think we can re-index
// all words at replacement or ignore time to have it wrap to the beginning if we want
// to.
//
function replaceAll() {
   var frm = document.fm1;
   var strstart = '';
   var strend;
   var idx;
   var origword;
   var localoffsetindex = offsetindex;

   origword = misps[ wordindex ].word;

   // reindex everything past the current word
   for (idx = wordindex; idx < misps.length; idx++) {
      misps[ idx ].start += localoffsetindex;
      misps[ idx ].end += localoffsetindex;
   }

   // testing
   localoffsetindex = 0;

   for (idx = 0; idx < misps.length; idx++) {

      if (misps[ idx ].word == origword) {
         if ( misps[ idx ].start != 0 )
            strstart = mispstr.slice( 0, misps[ idx ].start + localoffsetindex);
   
   
         // get the end of the string after the word we are replacing
         strend = mispstr.slice( misps[ idx ].end + 1 + localoffsetindex);
        
         // rebuild the string with the new word
         mispstr = strstart +  frm.changeto.value  + strend;
      
         // update offsetindex to compensate for replacing a word with a word
         // of a different length.
         localoffsetindex += frm.changeto.value.length - misps[ idx ].word.length;

      }
      // we have to re-index everything after replacements
      misps[ idx ].start += localoffsetindex;
      misps[ idx ].end += localoffsetindex;
   }

   // add the word to the ignore array
   ignoredWords[ origword ] = 1;

   // reset offsetindex since we reindexed
   offsetindex = 0;

   nextWord(false);
}

// hilight the word that was selected using the nextWord function
//
function hilightWord() {
   var strstart = '';
   var strend;

   // if this isn't the beginning of the string then get all of the string
   // that is before the word we are replacing

   if ( misps[ wordindex ].start != 0 )
       strstart = mispstr.slice( 0, misps[ wordindex ].start + offsetindex);

   // get the end of the string after the word we are replacing

   strend = mispstr.slice( misps[ wordindex ].end + 1 + offsetindex);

   // rebuild the string with a span wrapped around the misspelled word 
   // so we can hilight it in the div the user is viewing the string in


   //var divptr = document.getElementById("strview");
   var divptr = iFrameBody;

   divptr.innerHTML = '';
   divptr.innerHTML = strstart;

   divptr.innerHTML +=  "<span class='hilight' id='h1'>" + misps[ wordindex ].word + "</span>" + htmlToText(strend);
   
   //if (document.getElementById("h1").scrollIntoView)
      //document.getElementById("h1").scrollIntoView();

   divptr.innerHTML = divptr.innerHTML.replace(/_\|_/g, "<br>");
}


// called by onLoad handler to start the process of evaluating misspelled
// words
//
function startsp() {
   nextWord(false);
}

function getCorrectedText() {
   return mispstr;
}

// display the next misspelled word to the user and populate the suggested
// spellings box
//
function nextWord(ignoreall) {
   var frm = document.fm1;
   var sug = document.fm1.suggestions;
   var sugidx = 0;
   var newopt;
   var isselected = 0;

   // push ignored word onto ingoredWords array
   if (ignoreall)
      ignoredWords[ misps[ wordindex ].word ] = 1;

   // update the index of all words we have processed
   // This must be done to accomodate the replaceAll function.
   if (wordindex >= 0) {
      misps[ wordindex ].start += offsetindex;
      misps[ wordindex ].end += offsetindex;
   }

   // increment the counter for the array of misspelled words
   wordindex++;

 

   // draw it and quit if there are no more misspelled words to evaluate
   if (misps.length <= wordindex) {
      iFrameBody.innerHTML = mispstr;
      iFrameBody.innerHTML = iFrameBody.innerHTML.replace(/_\|_/g, "<br>");
      
      clearBox( sug );
      alert('Spell checking complete.');
      frm.change.disabled = true;
      frm.changeall.disabled = true;
      frm.ignore.disabled = true;
      frm.ignoreall.disabled = true;

      // put line feeds back
      mispstr = mispstr.replace(/_\|_/g, "\n");

      // get a handle to the field we need to re-populate
      window.opener.document.forms[spell_formname][spell_fieldname].value = mispstr;
      window.close();
      return true;
   }


   // check to see if word is supposed to be ignored
   if (ignoredWords[ misps[ wordindex ].word ] == 1) {
       nextWord(false);
       return;
   }

   // clear out the suggestions box
   clearBox( sug );

   // re-populate the suggestions box if there are any suggested spellings for the word
   if (misps[ wordindex ].suggestions.length) {
      for (sugidx = 0; sugidx < misps[ wordindex ].suggestions.length; sugidx++) {
         if (sugidx == 0)
            isselected = 1;
         else
            isselected = 0;
         newopt = new Option(misps[ wordindex ].suggestions[sugidx], misps[ wordindex ].suggestions[sugidx], 0, isselected); 
         sug.options[ sugidx ] = newopt;

         if (isselected) {
            frm.changeto.value = misps[ wordindex ].suggestions[sugidx];
            frm.changeto.select();
         }
      }
   }
   hilightWord();
}

function htmlToText(thetext) {
   // disable for now
   return thetext;

   var re = /\</g;
   var re2 = /\>/g;
   var re3 = /\n/g;
   var re4 = /\ /g;
   
   thetext = thetext.replace(re, "&lt;");                          
   thetext = thetext.replace(re2, "&gt;");
   thetext = thetext.replace(re3, "<br>");
   thetext = thetext.replace(re4, "&nbsp;");

   return thetext;
}

// remove all items from the suggested spelling box
// 
function clearBox( box ) {
  var length = box.length;

  // delete old options -- rememeber that select
  //                       boxes automatically re-index
  for (i = 0; i < length; i++) {
     box.options[0] = null;
  }
}


// NEW LOOK/FEEL template picker additions 7/6/2004
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ShowPanel(newPanel) {
	document.getElementById("panel"+curPanel).style.display = "none";
	//document.images["tab"+curPanel].src = tabOff[curPanel].src;
	
	document.getElementById("panel"+newPanel).style.display = "block";
	//document.images["tab"+newPanel].src = tabOn[newPanel].src;
	curPanel = newPanel;
}


