﻿// *** Cycle IMAGE code start  *****
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];}
}
// *** Cycle IMAGE code end  *****

// *** Number Formatting begin ***
function stripStuff(fld) {
	fld = fld.replace(",", "");
	fld = fld.replace("$", "");
	fld = fld.replace("%", "");
	return fld;
}

function stripZeroDecimals(fld) {
	fld = fld.toFixed(2);
	fld2=fld;
	for(var i= fld.lastIndexOf("."); i<fld.length; i++) {
		if (fld2.substring(fld2.length-1,fld2.length)==0) {
			fld2=fld2.substring(0,fld2.length-1);
		} else if (fld2.substring(fld2.length-1,fld2.length)==".") {
			fld2=fld2.substring(0,fld2.length-1);
			return fld2;
		} else {
			return fld2;
		}
	}
	return fld2;
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
}
// *** Number Formatting end ***

// ***  popImage code start  ***
// Set the horizontal and vertical position for the popup
PositionX = 100;
PositionY = 100;
// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;
// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;
var edOrgWin;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	
	function popImage(imageURL,imageTitle){
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
			writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
			close();		
		}
	}
	
	function popWin(URL,Title,dfltWidth,dfltHeight){
		PosX = 100;
		PosY = 100;
		var opt='toolbars=no,directories=no,status=no,menubar=0,scrollbars=no,width='+dfltWidth+',height='+dfltHeight+',left='+PosX+',top='+PosY;
			listing = window.open(URL,"mywindow",opt);
			listing.top;
	}
	
	function popWinAd(URL,Title,dfltWidth,dfltHeight){

		var opt='toolbars=no,directories=no,status=no,menubar=0,scrollbars=yes,width=1000,height=1200,left=20,top=5';
//		edOrgWin = window.open(URL,"edOrg",opt);
	if(edOrgWin)	edOrgWin.close();
//		edOrgWin = window.open(URL,"edOrg",opt);
		edOrgWin = window.open(URL,"edOrg",opt);
		edOrgWin.top;

	}
		
	
// ***  popImage code end  ***


function noChange(element,message) {	// 28 Mar 2002
	if(message){	alert(message+"\n\nDirect editing of this field is not allowed!");
	} else {alert("Direct editing of this field is not allowed!");
	}
}

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
{
   return RTrim(LTrim(str));
}


function numericCheck(fld){
  nr1=fld.value;
  flg=0;
  str="";
  spc=""
  arw="";

  for (var i=0;i<nr1.length;i++){
        if (fld.name=="price" || fld.name=="rent"){
                cmp="$0123456789.,"
        }else{cmp="0123456789."}

   tst=nr1.substring(i,i+1)
   if (cmp.indexOf(tst)<0){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+="_";}
  }

  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }

   alert(nr1+"\r"+arw+"\rI'm sorry. This entry must be a number. Found "
   +flg+" unacceptable: "+str);
fld.value=""
  }

 }












function normalizeInputs(myForm)
{
  pReplyDest= "the "+myForm.repTo.options[myForm.repTo.selectedIndex].text;
  if(myForm.repTo.options[myForm.repTo.selectedIndex].value == "webSite")
    pReplyDest+= " (no input needed)";
  if((myForm.repTo.options[myForm.repTo.selectedIndex].value == "noRep") || 
     (myForm.repTo.options[myForm.repTo.selectedIndex].value == "webSite")) {
    blankndisable(myForm.dest);
    if(myForm.repTo.options[myForm.repTo.selectedIndex].value == "noRep") {
      pReplyDest= "a Reply Type above before entering a destination";
      pReply="a Reply Type below before entering reply text";
      blankndisable(myForm.rep1);
      blankndisable(myForm.rep2);
      blankndisable(myForm.rep3);
      blankndisable(myForm.rep4);
      blankndisable(myForm.rep5);
      blankndisable(myForm.rep6);
      checkMessageLength(myForm);
      return true;
    }
  } else {
    myForm.dest.disabled= false;
  }
  pReply= "a reply the recipient may choose";
  enable(myForm.rep1);
  enable(myForm.rep2);
  enable(myForm.rep3);
  enable(myForm.rep4);
  enable(myForm.rep5);
  enable(myForm.rep6);
  return true;
}

// VARIABLE DECLARATIONS

var pFrom= "your name"
var pReplyDest= "an email address"
var pSubject= "the subject"
var pMessage= "the message"
var pReply= "a reply the recipient may choose"
var pClaimCheck = "a Claim Check Number"

var pEntryPrompt = "Please enter "
var pUSPhone = "10-digit U.S. phone number (like 5105551212)."
var iUSPhone = "This field must be a 10-digit U.S. phone number (like 5105551212). Please re-enter it now."
var iMessage= "You must enter a message."
var iClaimCheck= "This field must a 5 digit number."

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;
var digitsClaimCheck = 5;
 
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- .";
// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;

var defaultEmptyOK = false


function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";
 
    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


// isInteger( string )
function isInteger (s)
{   var i;
 
    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
 
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
 
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
 
        if (!isDigit(c)) return false;
    }
 
    // All characters are numbers.
    return true;
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
 


// Display data entry prompt string s in status bar.
function promptEntry (s)
{   window.status = pEntryPrompt + s
}


// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.
 
function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}


// takes USPhone, a string of 10 digits
// and reformats as (123) 456-789
 
function reformatUSPhone (USPhone)
{   
    //return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
    return (reformat (USPhone, "",10))
}
 

// isUSPhoneNumber (STRING s [, BOOLEAN emptyOK])
//
function isUSPhoneNumber (s)
{   if (isEmpty(s))
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function isClaimCheck (s)
{   if (isEmpty(s))
       if (isClaimCheck.arguments.length == 1) return defaultEmptyOK;
       else return (isClaimCheck.arguments[1] == true);
    return (isInteger(s) && s.length <= digitsClaimCheck)
}

// Removes all characters which appear in string bag from string s.
 
function stripCharsInBag (s, bag)
 
{   var i;
    var returnString = "";
 
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
 
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) {
            returnString += c;
       }
    }
 
    return returnString;
}
 

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
 

// checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid US Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkUSPhone (theField, emptyOK)
{
   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else {
       var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) {
	  warnInvalid(theField,iUSPhone);
          return false;
       } else {
          // if you don't want to reformat as (123) 456-789, comment next line out
          // theField.value = reformatUSPhone(normalizedPhone)
	  theField.value= normalizedPhone;
          return true;
       }
    }
}

function checkEMail (theField)
{
  var s= theField.value;
  if (isEmpty(s)) return true;
  var addrOkay= (s.indexOf('@')!= -1) && (s.indexOf('.')!= -1);
  if(!addrOkay) {
	alert("To receive replies and/or confirmations via e-mail, you must enter a valid e-mail address.");
//	theField.value="";
	theField.focus();
	return false;
  } else
	return true;
}

function checkForValidConfo(theBox)
{
  if(theBox.checked &&
     isEmpty(theBox.form.replynumber.value) &&
     isEmpty(theBox.form.replyemail.value)) {
    theBox.checked= false;
    alert("You must enter a reply destination before asking for confirmations");
    theBox.form.replynumber.focus();
    return false;
  }
  return true;
}

function checkForReplyAddr(theForm)
{
  var rep1val= theForm.rep1.value;
  if(//!isEmpty(rep1val) &&
     !isEmpty(theForm.twoWayPTNs.value) &&
     isEmpty(theForm.replynumber.value) &&
     isEmpty(theForm.replyemail.value))
    return confirm("You have not included a Nextel phone number or email address for replies; you will be able to read replies only from the web site.  Be sure to write down your claim number. Click 'Cancel' to add a reply destination.");
  else
    return true;
}

function checkClaimCheck (theField, emptyOK)
{   if (checkClaimCheck.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  if (!isClaimCheck(theField.value, false))
          return warnInvalid (theField, iClaimCheck);
       else
          return true;
    }
}

function checkMessageLength(element,returnElement,charLimit){
//alert(element.value.length);
	var count = element.value.length;
	returnElement.value = count;

	if( element== "result") {var count = form.result.value.length; form.countResult.value = count;	}
	if( count > charLimit ){	alert("This page exceeds the "+charLimit+" character limit. Please edit your text.");	}
}

function formatFuel(form) {
	form.Fuel.value="kjd";
}

function validate(form,checkLength){
	if( validate.arguments.length == 1) checkLength = true;
	if( form.message.value.length == 0 ){
		alert("You must enter a message.");
		form.message.focus();
		return false;
	}
	if( checkUSPhone(form.to01,false) && checkMessageLength(form,checkLength,true) ){
		return true;
	}
	return false;
}

function validateGroupAddrs(form, checkLength){
	if( validateGroupAddrs.arguments.length == 1) checkLength = true;
	if(form.to01.options[0].value == "null"){
		alert("You must enter at least one phone number.");
		form.newnumber.focus();
		return false;
	}
	for ( var i = 0; i < form.to01.length; i++){
		form.to01.options[i].selected=true;
		if( checkUSPhone(form.to01.options[i],true) ){
			if( isEmpty(form.to01.options[i].value)) {
				alert("You must enter at least one phone number.");
				form.newnumber.focus();
				return false;
			}
		}
	}
	return true;
}

function validateGroupMessage(form, checkLength, splitcheck){
	if( form.message.value.length == 0 || 
		form.message.value=="Enter message here up to 500 Characters." ||
		form.message.value=="Enter message here up to 267 Characters."){
		alert("You must enter a message.");
		form.message.value="";
		form.message.focus();
		return false;
	}
	if (!checkMessageLength(form,checkLength,splitcheck)){
		return false;
	}
	return true;
}

function clearFields(form){
	for ( var i=0; i< form.elements.length; i++ ){
		form.elements[i].value = "";
	}
	form.elements[0].focus();
}

function checkPhoneClaimCheck(phone,claimCheck){
	if( isEmpty(phone.value) && isEmpty(claimCheck.value) ) return true;
	return checkUSPhone(phone,false) && checkClaimCheck(claimCheck,false);
}

function validateClaimCheck(form){
	if( checkPhoneClaimCheck(form.phone01,form.claimCheck01) &&
		checkPhoneClaimCheck(form.phone02,form.claimCheck02) &&
		checkPhoneClaimCheck(form.phone03,form.claimCheck03) &&
		checkPhoneClaimCheck(form.phone04,form.claimCheck04) &&
		checkPhoneClaimCheck(form.phone05,form.claimCheck05) &&
		checkPhoneClaimCheck(form.phone06,form.claimCheck06) ){
		if( isEmpty(form.phone01.value) && isEmpty(form.claimCheck01.value) &&
			isEmpty(form.phone02.value) && isEmpty(form.claimCheck02.value) &&
			isEmpty(form.phone03.value) && isEmpty(form.claimCheck03.value) &&
			isEmpty(form.phone04.value) && isEmpty(form.claimCheck04.value) &&
			isEmpty(form.phone05.value) && isEmpty(form.claimCheck05.value) &&
			isEmpty(form.phone06.value) && isEmpty(form.claimCheck06.value) ){
			alert("You must enter at least one phone number and claim check pair.");
			form.phone01.focus();
			return false;
		}
		return true;
	}
	return false;
}

  function nav_LOV (url) {
       var msg = window.open
                (url,
                 "Popup",
                 "toolbar=no,location=no,directories=no,status=no,menubar=no,alwaysraised=yes," +
                 "scrollbars=no,resizeable=no," +
                 "height=300," +
                 "width=530," +
                 "left=20,top=20");
    }

function clear9messages(formobj)
{
	for (var i = 1; i <=9; ++i) {
		var name="message"+i;
		formobj[name].value= "";
	}
}

bname = navigator.appName;
bver = parseInt(navigator.appVersion);
blegal = ((bname == "Netscape" && bver >= 3) || (bname == "Microsoft Internet Explorer" && bver >= 4));

