/************************************************************************
******************** Generic Form Verification Function *****************
************************************************************************/
function verify_form(f)
{
    var msg;
    var empty_fields="";
    var errors="";
    var temp = "";
    var strTemp = "";
	var SomeEdited = true;
	
	if (f.thisorthat) {
		var thisthat = f.thisorthatfields.split(",");

		SomeEdited = false;
		for(var i = 0; i < thisthat.length; i++) {
		  var e = eval("f." + thisthat[i]);
		  
		  //alert(e.name + " " + e.optional);
			if (((e.type == "text") || (e.type == "textarea") || (e.type == "file"))) {
				if (isblank(e)) {
				  empty_fields += "\n       " + e.id;
				  continue;
				} else {
				  SomeEdited = true;
				  break;
				}
			}
		}
		

	}

    msg  = "__________________________________________________\n\n";
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "__________________________________________________\n\n";

    if (!SomeEdited) {
      msg += "- atleast one of these fields is required:" + empty_fields + "\n";
      alert(msg);
      return false;
    }

	empty_fields = "";

    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

      //alert(e.name + " " + e.optional);

	   if (e.type == "select-one" && e.optional == false) {
			if (e.selectedIndex == -1) {
			  empty_fields += "\n       " + e.id;
			  
			  continue;
			}
	   }

	   if (e.type == "hidden" && e.optional == false) {
			if (isblank(e)) {
			  empty_fields += "\n       " + e.id;
			  
			  continue;
			}
	   }


	   if (((e.type == "text") || (e.type == "textarea") || (e.type == "file") || (e.type == "password")) && e.optional == false) {
			if (isblank(e)) {
			  empty_fields += "\n       " + e.id;
			  
			  continue;
			}
		}

	   if ((e.type == "text") || (e.type == "textarea") || (e.type == "password")) {
			if (isblank(e)) {
			  strTemp = "";
			} else {
			  strTemp = e.value;
			}
		}	   	

   
	   if (e.dependents) {
			if (((e.type == "text") || (e.type == "textarea") || (e.type == "file"))) {
				if (!isblank(e)) {
				  var dependents = e.dependentfields.split(",");
		
				  for(var j = 0; j < dependents.length; j++) {
					var d = eval("f." + dependents[j]);
					  
					//alert(e.name + " " + e.optional);
					if (((d.type == "text") || (d.type == "textarea") || (d.type == "file"))) {
						if (isblank(d)) {
						  errors += "\n- The field '" + d.id + "' is required if you entered a value for " + e.id;
						}
					}
				  }
				}
			}
	   }		

	   if (e.passwordcheck) {
		   var r = f.password2;
			if (e.value != r.value) {
				errors += "\n- The passwords don't match."
			}
	   }



	   if(strTemp.length > 0){
			if (e.isNumeric || (e.min != null) || (e.max != null)) {
			  var v = parseFloat(e.value);
			  if (isNaN(e.value) ||
				  ((e.min != null) && (v < e.min)) ||
				  ((e.max != null) && (v > e.max))) {
			
				   errors += "\n- The field '" + e.id + "' must be a number";
				   e.value = ""
			
				   if (e.min != null)
					  errors += " that is greater than " + e.min;
				   if (e.max != null && e.min != null)
					  errors += " and less than " + e.max;
				   else if (e.max != null)
					  errors += " that is less than " + e.max;
			
				   errors += "\n";
			  }
			}	  
	   }

	   if(strTemp.length > 0){
			if (e.isPhone) {
			  var objRegExp  = /^[1-9]\d{2}\-\d{3}\-\d{4}$/;
		  
			  //check for valid us phone format xxx-xxx-xxxx
			  if (!objRegExp.test(e.value)) {
				errors += "\n- The field '" + e.id + "' must be a phone number in the format xxx-xxx-xxxx";
			  }
		   }
	   }

	   if(strTemp.length > 0){
			if (e.isSSN) {
			  var objRegExp  = /^\d{3}\-\d{2}\-\d{4}$/;
		  
			  //check for valid ssn format xxx-xxx-xxxx
			  if (!objRegExp.test(e.value)) {
				errors += "\n- The field '" + e.id + "' must be a Social Security in the format xxx-xx-xxxx";
				e.value = "";
			  } 			  
		   }
	   }


 	   if(strTemp.length > 0){
			if (e.isEmail) {
			  var objRegExp  = /(^[a-z]([a-zA-Z0-9_\-\.]*)@([a-zA-Z0-9_\-\.]*)([.][a-z]{3})$)|(^[a-z]([a-zA-Z0-9_\-\.]*)@([a-zA-Z0-9_\-\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/;
			  
			  //check for valid email
			  if (!objRegExp.test(e.value)) {
				errors += "\n- The field '" + e.id + "' is not valid format ";
			  }
		   }
	   }		
    }

    if (empty_fields) {
      msg += "- the following required field(s) are empty or not selected:" + empty_fields + "\n";
      alert(msg);
      return false;
    }

    if (errors) {
      msg += errors + "\n";
      alert(msg);
      return false;
    }

	return true;
   /*for(var i = 0; i < f.length; i++) {
       e = f.elements[i];

		if ((e.type == "text") || (e.type == "textarea"))
		   {e.value = CleanApostrophe(e.value);}
   }*/
}

/************************************************************************
************************* Blank Field Check *****************************
************************************************************************/
function isblank(s)
{
	if ((s.value == null) || (trim(s.value) == ""))
		return true;
	else 
		return false;
}


/* Check if date is a valid date */
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

/* Check Field is Integer */
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

/* Check if chars in string s are in bag (array of chars) */
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++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}


function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function isCurrency(f)

{
	var nNum = 0;			// Total numbers for currency value.
	var nDollarSign = 0;	// Total times a dollar sign occurs.
	var nDecimal = 0;		// Total times a decimal point occurs.
	var nCommas = 0;		// Total times a comma occurs.
	var txtLen;				// Length of string passed.
	var xTxt;				// Assigned object passed.
	var sDollarVal;			// Assigned dollar amount with or without commas.
	var bComma;
	var decPos;				// Assigned value of numbers or positions after decimal point.
	var nNumCount = 0;		// Total number between commas.
	var i;					// For forloop indexing.
	var x;					// Assigned each indivual character in string.

	// Set the xTxt variable to the object passed to this function.

	// Assign the length of the string to txtLen.

	xTxt = f;
	txtLen = f.value.length

	for(i = 0; i < txtLen; i++)
	{
		// Assign charater in substring to x.

		x = xTxt.value.substr(i, 1);
		if(x == "$")
			nDollarSign = nDollarSign + 1; // Sum total times dollar sign occurs.
		else if(x == ".")
			nDecimal = nDecimal + 1; // Sum total times decimal point occurs.
		else if(x == ",")
			nCommas = nCommas + 1; // Sum total times comma occurs.
		else if(parseInt(x) >= 0 || parseInt(x) <= 9)
			nNum = nNum + 1; // If the character is a number sum total times a number occurs.
		else
		{
			// Error occurs if any other character value is in the string
			// othere then the valid characters.
			alert("ERROR! \n\nYou have entered an illegal value!\nPlease enter only: Dollar" +
				  " Signs, Commas, Decimal Points, and numbers between 0...9!");
			return false;
		} // end else
	} // end for

	if(nDollarSign > 1)
	{
		alert("ERROR! \n\nYou have entered more then one dollar sign!\nPlease only enter one!");
		return false;
	} // end if

	if(nDecimal > 1)
	{
		alert("ERROR! \n\nYou have entered more then one decimal point!\nPlease only enter one!");
		return false;
	} // end if

	if(nDollarSign == 1)
	{
		// Make sure dollar sign in the first character in string
		// if there is a dollar sign present.
		if(xTxt.value.indexOf("$") != 0)
		{
			alert("ERROR!  \n\nThe dollar sign you entered is not in the correct position!");
			return false;
		} // end if
	}// end if

	if(nDecimal == 1)
	{
		// Get the number of numbers after the decimal point in
		// the string if there is a decimal point present
		decPos = (txtLen - 1) - xTxt.value.indexOf(".");

		// Floating point cannot be more then two.
		// Valid format after decimal point.

		/**********************************/
		/*   $#.##, $#.#, $.#, $#., $.##  */

		/**********************************/

		if(decPos > 2)
		{
			alert("ERROR! \n\nThe decimal point you entered is not in the correct position!");
			return false;
		} // end if
	} // end if

	if(nCommas == 0)
	{
		// If no commas are present value is a valid US
		// currency.
		return true;
	}
	else
	{
		// Get total number of dollar number(s), removing
		// floating point numbers or cents.
		nNum = nNum - decPos;

		// Determine if dollar sign is in string so to be
		// removed.
		// After determining dollar sign, assign sDollarVal
		// numbers and comma(s)

		if(xTxt.value.indexOf("$", 0) == 0)
			sDollarVal = xTxt.value.substr(1, (nNum + nCommas));
		else
			sDollarVal = xTxt.value.substr(0, (nNum + nCommas));

		// Determine if a zero is the first number or if a
		// comma is the first or last character in the string.

		if(sDollarVal.lastIndexOf("0", 0) == 0 )
		{
			alert("ERROR! \n\nYou cannot start the dollar amount out with a zero!");
			return false;
		}
		else if(sDollarVal.lastIndexOf(",", 0) == 0)
		{
			alert("ERROR! \n\nYou cannot start the dollar amount out with a comma!");
			return false;
		}
		else if(sDollarVal.indexOf(",", (sDollarVal.length - 1)) == (sDollarVal.length - 1))
		{
			alert("ERROR! \n\nYou cannot end the dollar amount with a comma!");
			return false;
		}
		else
		{
			// Initialize bComma indicating a comma has not been
			// occured yet.

			bComma = false;
			for(i = 0; i < sDollarVal.length; i++)
			{
				// Assign charater in substring to x.
				x = sDollarVal.substr(i, 1);
				if(parseInt(x) >= 0 || parseInt(x) <= 9)
				{
					// If x is a number add one to the number counter.
					nNumCount = nNumCount + 1;

					// Sense comma(s) are present number counter cannot
					// be more then three before the first or next comma.

					if(nNumCount > 3)
					{
						alert("ERROR! \n\nYou have a mis-placed comma!");
						return false;
					} // end if
				}
				else
				{
					// If the number counter is less then three and
					// the comma indicator is true the comma is either
					// mis-placed or there are not enough values.

					if(nNumCount != 3 && bComma)
					{
						alert("ERROR! \n\nYou have a mis-placed comma!");
						return false;
					} // end if

					// Reset the number counter back to zero.
					nNumCount = 0;


					// Set the comma indicator to true indicating
					// that the first comma has been found and that
					// there now MUST be three numbers after each
					// comma until the loop hits the end.

					bComma = true;
				} // end if
			} // end for

			// Determine if after the loop ended that there
			// was a total of three final numbers after the
			// last comma.

			if(nNumCount != 3 && bComma)
			{
				alert("ERROR! \n\nYou have a mis-placed comma!");
				return false;
			} // end if
		} // end if
	} // end if

	// Return true indicating that the value is a valid
	// currency.
	return true;
}

/* Check if there are any inavlid characters in a field */
function CleanApostrophe(myString)
{
   var pattern = /'/g;
   var newString = myString.replace(pattern,"''");
   return newString;
}

/* Trim function */
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

/* Check if column selected if selected submit form */
function CheckAndSubmit(checkString)
{
	var col = document.forms.getselection.selection;

	if (col.options[col.selectedIndex].text != checkString) { 
		//alert(col.options[col.selectedIndex].text);
		document.getselection.submit();
	}
}

/* Check if column selected if selected submit form */
function GoToLink(element)
{
    var gotolink;
	gotolink = document.getElementById(element).value;
	//alert(document.getElementById(element).value);
	
	if (gotolink != "") {
		document.location.href="#" + gotolink;
	}
	
}

function GoTo(gotolink)
{
	
	if (gotolink != "") {
		document.location.href=gotolink;
	}
	
}

function ComparePasswords(orig, copy, formname)
{
	var origtext = eval("document.forms." + formname + "." + orig + ".value");
	var copytext = eval("document.forms." + formname + "." + copy + ".value");
	
	if (origtext != copytext)
		alert ("The two passwords don't match. Please re-enter.");
}

function ChangeShipToInfo(formname)
{
	var EditForm = eval("document.forms." + formname);
	var isCopyText = EditForm.same.checked;

	var ShipState = EditForm.bstate.options[EditForm.bstate.selectedIndex].value;

	if (isCopyText) {
		if (EditForm.bstate.value == "NJ") {
			EditForm.saddr1.value = EditForm.baddr1.value;
			EditForm.saddr2.value = EditForm.baddr2.value;
			EditForm.scity.value = EditForm.bcity.value;
			//EditForm.sstate.selectedIndex =	EditForm.bstate.selectedIndex;
			EditForm.szip.value = EditForm.bzip.value;
		} else {
			alert("We are currently shipping only to NJ");
			EditForm.same.checked = false;
		}
	} else {
		EditForm.saddr1.value = "";
		EditForm.saddr2.value = "";
		EditForm.scity.value = "";
		EditForm.szip.value = "";
		EditForm.sstate.selectedIndex =	0;
	}
}

// Functions for creating cascading drop down menus --- START
function update(e, dd)
{
	for (j=1; j < dd.length; j++)
	{
		dd[j][0] = true;
	}

	for (j=1; j < dd[0].length; j++)
	{
		for (i=1; i < dd.length; i++)
		{
			current = dd[i][j].split("|");
			value = current[0];
			choice = current[0];
			if (current.length == 2) choice = current[1];
			if (value != document[dd[0][0]][dd[0][j]][document[dd[0][0]][dd[0][j]].selectedIndex].value) dd[i][0] = false;
		}
		if (e == document[dd[0][0]][dd[0][j]])
		{
			dropdown(j+1,dd);
			for (k=j+2; k < dd[0].length; k++)
			{
				document[dd[0][0]][dd[0][k]].length = 0;
			}
			break;
		}
	}
}

function dropdown(item,dd)
{
	var pre1 = "";
	var j = 1;
	document[dd[0][0]][dd[0][item]].options.length = 0;
	document[dd[0][0]][dd[0][item]].options[0] = new Option('Select ' + dd[0][item], '');
	document[dd[0][0]][dd[0][item]].options[0].selected = true;
	for (i=1; i < dd.length; i++)
	{
		if (dd[i][0] || item == 1)
		{
			current = dd[i][item].split("|");
			value = current[0];
			choice = current[0];
			if (current.length == 2) choice = current[1];
			if (value != pre1)
			{
				var op = new Option(choice, value);
				document[dd[0][0]][dd[0][item]].options[j] = op;
				j++;
				pre1 = value;
			}
		}
	}
}

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
// Functions for creating cascading drop down menus --- END

//Turn Layer Visibility on/off
function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	
	style2.display = style2.display=="block" ? "none":"block";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display=="block" ? "none":"block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display=="block" ? "none":"block";
	}
}

//Turn Layer Visibility off
function hideLayer(whichLayer)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	
	style2.display = "none";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = "none";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = "none";
	}
}

//Turn Layer Visibility on
function showLayer(whichLayer)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	
	style2.display = "block";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = "block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = "block";
	}
}




//Function called to disable optional=false fields
function disable_optional(f)
{

    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];
	  
	  e.optional = true;
	}
	//alert("no of element: " + allFormElements.length);
}

//Change text inside an item
function writeit(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

/* Open new window */
function OpenNewWindow(URL, title, width, height, toolbar, statusbar, resizable)
{
	var imgWindow;
	var features;
	
	features = "'alwaysRaised=1,toolbar=" + toolbar + ",location=0,status=" + statusbar + ",menubar=0,scrollbars=1,width=" + width + ",height=" + height + ",top=20,left=20,resizable=" + resizable + "'";
	//alert(features);
	imgWindow=window.open(URL, title, features);
	return imgWindow;

}

/* change class */
function changeClass(id1, newClass, id2, state) {
	identity=document.getElementById(id1);
	identity.className=newClass;
	
	if (state == 'visible') 
		show(id2);
	else 
		hide(id2);
}

/* Get Options Value */
function ReturnOptionValue(optionname) {
	element = document.getElementById(optionname);
		
	if (element.selectedIndex > -1)
		return(element.options[element.selectedIndex].value) ;
	else
		return(0) ;
}

/* Get Options text */
function ReturnOptionText(optionname) {
	element = document.getElementById(optionname);
	
	if (element.selectedIndex > -1)
		return(element.options[element.selectedIndex].text) ;
	else
		return(null) ;
}

/* Get Radio Button Value */
function ReturnRadio(formname, radioname) {

	var radioelement = document.forms[formname].elements[radioname];
	var rad_val = null;

	if (!radioelement)
		return null;

	if (radioelement.length) {
		for (var i=0; i < radioelement.length; i++)
			if (radioelement[i].checked)
			  rad_val = radioelement[i].value;
	} else {
		if (radioelement.checked)
		  rad_val = radioelement.value;
	}
	
	return rad_val;

}

/* Get Checked Radio Button Index */
function ReturnRadioIndex(formname, radioname) {

	var radioelement = document.forms[formname].elements[radioname];
	var rad_val = null;

	if (!radioelement)
		return null;

	if (radioelement.length) {
		for (var i=0; i < radioelement.length; i++)
			if (radioelement[i].checked)
			  rad_val = i;
	} else {
		if (radioelement.checked)
		  rad_val = 0;
	}
	
	return rad_val;

}


/*Return Currency Given a Number */
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 + '.' + cents);
	return (((sign)?'':'-') + '$' + num);
}	

/* Show all form values */
function ShowFormValues(formname) {
	
	var vfrmElements = document.forms[formname].elements;
	var vinNumElements = vfrmElements.length;
	var vtxOutput
	
	for (i=0; i<vinNumElements; i++) {
		vfrmElement = vfrmElements[i];
		vtxOutput = vtxOutput + "[" + vfrmElement.name + " " + vfrmElement.type + " " + vfrmElement.value + "], \n"; // This line produces an Error.
		
	}
	alert (vinNumElements + " Elements are :" + vtxOutput);	
	
}

//Check if an object is an Array
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

//Check if an object is an Array
function inStr(haystack, needle) {
   if (haystack.indexOf(needle) == -1)
      return false;
   else
      return true;
}


//Insert text at curson position
//Usage: insertAtCursor(document.formName.fieldName, ‘this value’);
function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
	myField.focus();
	sel = document.selection.createRange();
	sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
	var startPos = myField.selectionStart;
	var endPos = myField.selectionEnd;
	myField.value = myField.value.substring(0, startPos)
	+ myValue
	+ myField.value.substring(endPos, myField.value.length);
	} else {
	myField.value += myValue;
	}
}

//Change Visibility of object
function toggleVisibility(whichLayer) {
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	
	style2.visibility = style2.visibility=="hidden" ? "visible":"hidden";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.visibility = style2.visibility? "":"block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.visibility = style2.visibility? "":"block";
	}
} 


// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// ugly workaround for missing support for selectorText in Netscape6/Mozilla
// call onLoad() or before you need to do anything you would have otherwise used
// selectorText for.
var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
	if((navigator.userAgent.indexOf("Gecko") == -1) ||
	   (ugly_selectorText_workaround_flag)) {
		return; // we've already been here or shouldn't be here
	}
	var styleElements = document.getElementsByTagName("style");
	
	for(var i = 0; i < styleElements.length; i++) {
		var styleText = styleElements[i].firstChild.data;
		// this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
		// error in IE5, so we include the open brace and then strip it
		allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
	}

	for(var i = 0; i < allStyleRules.length; i++) {
		// probably insufficient for people who like random gobs of 
		// whitespace in their styles
		allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
	}
	ugly_selectorText_workaround_flag = true;
}


// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	var n = document.getElementById(i);
	var s = eval("n.style." + p);

	// try inline
	if((s != "") && (s != null)) {
		return s;
	}

	// try currentStyle
	if(n.currentStyle) {
		var s = eval("n.currentStyle." + p);
		if((s != "") && (s != null)) {
			return s;
		}
	}
	
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[y] == i) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) ||
						   (rules[y].selectorText == i)) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleByTag: given an element type, style property and 
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
	if(g) {
		var elements = document.getElementsByTagName(e);
		for(var i = 0; i < elements.length; i++) {
			elements.item(i).style[p] = v;
		}
	} else {
		var sheets = document.styleSheets;
		if(sheets.length > 0) {
			for(var i = 0; i < sheets.length; i++) {
				var rules = sheets[i].cssRules;
				if(rules.length > 0) {
					for(var j = 0; j < rules.length; j++) {
						var s = rules[j].style;
						// selectorText broken in NS 6/Mozilla: see
						// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
						ugly_selectorText_workaround();
						if(allStyleRules) {
							if(allStyleRules[j] == e) {
								s[p] = v;
							}			
						} else {
							// use the native selectorText and style stuff
							if(((s[p] != "") && (s[p] != null)) &&
							   (rules[j].selectorText == e)) {
								s[p] = v;
							}
						}

					}
				}
			}
		}
	}
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		for(var i = 0; i < sheets.length; i++) {
			var rules = sheets[i].cssRules;
			if(rules.length > 0) {
				for(var j = 0; j < rules.length; j++) {
					var s = rules[j].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[j] == e) {
							return s[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((s[p] != "") && (s[p] != null)) &&
						   (rules[j].selectorText == e)) {
							return s[p];
						}
					}

				}
			}
		}
	}


	// if we don't find any style sheets, return the value for the first
	// element of this type we encounter without a CLASS or STYLE attribute
	var elements = document.getElementsByTagName(e);
	var sawClassOrStyleAttribute = false;
	for(var i = 0; i < elements.length; i++) {
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if((node.attributes.item(j).nodeName == 'class') ||
			   (node.attributes.item(j).nodeName == 'style')){
			   sawClassOrStyleAttribute = true;
			}
		}
		if(! sawClassOrStyleAttribute) {
			return elements.item(i).style[p];
		}
	}
}

//Add New Contact Window
function AddNewContact() {
	OpenNewWindow('../managepeople/mp.php', 'ManagePeople', 775, 700, 0, 1, 1)
}

//Add New Comapany Window
function AddNewCompany() {
	OpenNewWindow('../managecompany/mc.php', 'ManageCompany', 775, 700, 0, 1, 1)
}

//Comma Separator for Numbers
function AddComma(SS) {
    var T = "", S = String(SS), L = S.length - 1, C, j, P = S.indexOf(".") - 1;
    if (P < 0) {
        P = L;
    }
    for (j = 0; j <= L; j++) {
        T += (C = S.charAt(j));
        if ((j < P) && ((P - j) % 3 == 0) && (C != "-")) {
            T += ",";
        }
    }
    return T;
}

//Remove Comma Separator for numbers
function RemComma(S) {
	var T = S.replace(/,/g, '')
	return T
}


