function addParticipant()
{

  id  = (Math.round((Math.random()*10000))); // random from 0 to 10000
  // HTML for shirt select element
  shirtSelect = "<select name=\"participants["+id+"][shirt]\" ><option value=\"\" >" 
              + "</option><option value=\"S\" >S</option><option value=\"M\" >"
              + "M</option><option value=\"L\" >L</option>"
              + "<option value=\"XL\" >XL</option></select>"; 
   
  
  // HTML for shareholder select element
  sholderSelect = "<input type=\"radio\" name=\"participants["+id+"][shareholder]\" id=\"c_ea70\""
                + "value=\"0\" id=\"s_ea"+id+"\" />"
                + "<label for=\"s_ea"+id+"\">yes</label><br />"
                + "<input type=\"radio\" name=\"participants["+id+"][shareholder]\" id=\"c_ea71\""
                + "value=\"1\" id=\"s_eb"+id+"\" />"
                + "<label for=\"s_eb"+id+"\">no</label>";

  // HTML for company select element
  companySelect = "<input type=\"radio\" name=\"participants["+id+"][company]\" id=\"c_ea70\""
                + "value=\"0\" id=\"c_ea"+id+"\"  />"
                + "<label for=\"c_ea"+id+"\">yes</label><br />"
                + "<input type=\"radio\" name=\"participants["+id+"][company]\" id=\"c_ea71\""
                + "value=\"1\" id=\"c_eb"+id+"\" />"
                + "<label for=\"c_eb"+id+"\">no</label>";
  // add row to table
  addRow("ptable-id",
               Array("input","name:participants["+id+"][participant_name]","type:text","size:20","value:"), 
               Array("innerHTML",shirtSelect),
               Array("input","name:participants["+id+"][amount_collected]","size:8","maxlength:8","type:text"),
               Array("input","name:participants["+id+"][additional_donation]","size:8","maxlength:8","type:text"),
               Array("innerHTML", sholderSelect),
               Array("innerHTML",companySelect),
               Array("input","name:"+id,"type:button", "value:Delete", "func:deleteParticipant('ptable-id', this)"));
  //moreSort++;
  pCount++;  
  return true;
}


function deleteParticipant(tableId, bttn)
{
    pId = bttn.name;
    // remove table row
    delRow(tableId, bttn);
    pCount--;  
}


// adds a row to an existing table 
// creating HTML elements within table cells
// input: - string tableId = id attribute of table
//        - array(s) of HTML element(s) to add to table cells. 
//          Format [a]: Array(HTMLElement,"attribute:value") -
//                      You may pass any number of "attribute:value" 
//                      pairs. "func:fname(args)" adds a function fname
//                      (triggered by onclick event).
//          Format [b]: Array("innerHTML","string") - the "string" is set
//                      to TD.innerHTML property.
// author: shakirj
function addRow(tableId) //v2.3
{
  var tbody = document.getElementById(tableId).getElementsByTagName('tbody')[0];
  var row   = document.createElement('TR');
  var args  = addRow.arguments;
  var cells = Array();
  var elems = Array();
  var attrName ="", attrValue ="", p="";

  for (var i=0; i < args.length-1; i++) {
    cells[i] = document.createElement('TD');
    if (args[i+1][0].indexOf('innerHTML')!=-1) {
      cells[i].innerHTML = args[i+1][1];    
    }
    else {
      elems[i]  = document.createElement(args[i+1][0]);

      for (var j=1; j < args[i+1].length; j++ ) {
        p = args[i+1][j].indexOf(":");
        attrName  = args[i+1][j].substring(0,p);
        attrValue = args[i+1][j].substring(p+1);
        if (attrName.indexOf("func") !=-1) { 
          //elems[i].onclick = function(){delRow(tableId, this);};
          elems[i].onclick = function(){ eval(attrValue);};
        }
        else {
          elems[i].setAttribute(attrName,attrValue);
        }
      } //end for
      cells[i].appendChild(elems[i]);
    } //end else
    row.appendChild(cells[i]);
  }
  tbody.appendChild(row);
} // end addRow()


// deletes a row from an existing table
function delRow(tableId, bttn)
{
  var row   = bttn.parentNode.parentNode;
  var tbody = document.getElementById(tableId).getElementsByTagName('tbody')[0];
  tbody.removeChild(row);
}



// Form Compendium f20 (06-12-2005)
// Format Number
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Format a number, such as a date or phone number as required.

// Options to verify each input 'onblur'
// or a number of specified inputs on Submit or other event.

// Date formats of mm/dd/yyyy and dd/mm/yyyy
// may be checked for valid day, month and year.

// There may be as many applications on a page as required.

// Application Notes

// The format is specified as a string
// and passed to the function 'f20FormatNumber()' on the onkeyup event of a text box
// e.g.
// <input name="" size="10" value="Phone Number" onkeyup="f20FormatNumber(this,'(~~~) ~~~~~~'),'Blur or All';" >
// Parameter 0 may be the FormatNumber input object (this)
// or the unique ID name of the FormatNumber input element.

// The sting charactors '~' will be replaced by the numbers typed in the text box
// Parameter 2 'Blur or All' will dictate if the input is verified on blur or  on Submit or other event.
// 'Blur' will verify the input 'onblur'
// 'All'  will verify the input on Submit or other event.
// 'BlurAll' will verify the input on both 'blur' and Submit or other event.
// If the parameter is not specified verification will not occur.

// The Check All Function f20CheckAll()
// Calling f20CheckAll() will verify all FormatNumber input which inclue 'All'
// The function will return 'true' if all are correct or 'false' if any are incorrect.

// The facility would normally be initialise from the first 'keyup' event of the FormatNumber input
// However it may also be initialise from a <BODY> or window onload event calling  function 'f20InitFormatNumber('
// e.g.
// <body onload="f20InitFormatNumber('*ID*','~~/~~/~~~~','All');" >
// where
// *ID* = the unique ID name of FormatNumber input element (string)

// Verification of Date
// The f20FormatNumber() call requires an additional parmeter
// e.g.
// <input name="" size="15" value="mm/dd/yyyy" style="color:gray;" onkeyup="f20FormatNumber(this,'~~/~~/~~~~','Blur',['mm/dd/yyyy',2000,2008]);" >
// Parameter 4 is an array
// parameter 4 field 0 = the required date format 'mm/dd/yyyy' or 'dd/mm/yyyy'  (string)
// parameter 4 field 1 = (optional) the minimum permitted year                  (digits)
// parameter 4 field 2 = (optional) the maximum permitted year                  (digits)

// If field 1 is omitted the min and max years will default to custonising variables f20MinYear & f20MaxYear
// There can be any number of applications on a page each with a unique format

// All variable, function etc. names are prefixed with 'f20' to minimise conflicts with other JavaScripts

// The functional code(about 3K) is best as an external JavaScript.

// Tested with IE6 and Mozilla FireFox


// Customising Variables
var f20InitialColor='gray';
var f20TypingColor='blue';
var f20CompleteColor='black';
var f20WarningColor='RED';
var f20MinYear=1800;
var f20MaxYear=3000;

// Functional Code

// NO NEED to Change
var f20Temp,f20Lgth,f20War,f20CkAllCk;
var f20CkAllAry=new Array();

function f20InitFormatNumber(f20obj,f20tem,f20m,f20date){
 if (typeof(f20obj)=='string'){ f20obj=document.getElementById(f20obj); }
 f20FormatNumber(f20obj,f20tem,f20m,f20date);
 f20obj.style.color=f20InitialColor;
 f20obj.value=f20obj.txt;
}

function f20FormatNumber(f20obj,f20tem,f20m,f20date){
 if (typeof(f20obj)=='string'){ f20obj=document.getElementById(f20obj); }
 f20obj.txt=f20obj.value;
 f20obj.style.color=f20TypingColor;
 f20re = /\D/g;
 f20obj.value=f20obj.value.replace(/\D/g,'');
 f20Temp=f20tem;
 for (f200=0;f200<f20obj.value.length;f200++){
  f20Lgth=f20Temp.indexOf('~');
  f20Temp=f20Temp.replace('~',f20obj.value.charAt(f200));
 }
 if (f20obj.value.length>0&&(f20Lgth<0||f20obj.value.length==f20tem.match(/~/g).length)){
  f20obj.value=f20Temp.substring(0,f20tem.length);
  f20obj.style.color=f20CompleteColor;
 }
 if (f20Lgth>=0&&f20obj.value.length>0){
  f20obj.value=f20Temp.substring(0,f20Lgth+1);
 }
 f20obj.date=f20date;
 f20obj.lgth=f20tem.length;
 if (f20m){
  if (f20m.toLowerCase().match('b')){ f20AddBlur(f20obj); }
  if (f20m.toLowerCase().match('a')&&!f20obj.ckall){ f20obj.ckall=true; f20CkAllAry[f20CkAllAry.length]=f20obj; }
 }
 f20AddFocus(f20obj);
}

function f20Blur(f20,f20obj){
 if (f20obj){ f20=f20obj; }
 else { f20=this; }
 f20.style.color=f20CompleteColor;
 if (f20.value.length<f20.lgth){
  if (f20.value.length<1){ f20.value='Please Complete'; }
  f20CkAllCk=false
  f20Warning(f20,'Please Complete the');
 }
 if (!f20.date){ return; }
 f20s=f20.date[0].charAt(2);
 f20y=parseInt(f20.value.split(f20s)[2]);
 if (f20.date[0].charAt(0)=='m'){
  f20d=parseInt(f20.value.split(f20s)[1]);
  f20m=parseInt(f20.value.split(f20s)[0]);
 }
 else {
  f20d=parseInt(f20.value.split(f20s)[0]);
  f20m=parseInt(f20.value.split(f20s)[1]);
 }
 f20mess='';
 f20md=new Date(f20y,f20m,1,-1).getDate();
 if (!f20.date[1]){
  f20.date[1]=f20MinYear;
  f20.date[2]=f20MaxYear;
 }
 if (f20y<f20.date[1]||f20y>f20.date[2]){
   f20mess='Incorrect Year';
 }
 else if (f20m<1||f20m>12){
  f20mess='Incorrect Month';
 }
 else if (f20d<1||f20d>f20md){
  f20mess='Incorrect Day';
 }
 if (f20mess!=''){
  f20Warning(f20,f20mess);
 }
}

function f20CheckAll(){
 f20CkAllCk=true;
 for (f200=0;f200<f20CkAllAry.length;f200++){
  f20Blur(null,f20CkAllAry[f200]);
 }
 return f20CkAllCk;
}

function f20Warning(f20obj,f20mess){
 f20obj.style.color=f20WarningColor;
 alert(f20mess+'\nsee the '+f20WarningColor+'\nField');
 f20War=true;
 f20CkAllCk=false
 f20obj.focus();
}

function f20Color(){
 if (!f20War){ this.style.color=f20TypingColor; }
 f20War=false;
}

function f20EventAdd(f20o,f20t,f20f) {
 if ( f20o.addEventListener ){ f20o.addEventListener(f20t, function(e){ f20o[f20f](e);}, false); }
 else if ( f20o.attachEvent ){ f20o.attachEvent('on'+f20t,function(e){ f20o[f20f](e); }); }
 else {
  var f20Prev=f20o["on" + f20t];
  if (f20Prev){ f20o['on'+f20t]=function(e){ f20Prev(e); f20o[f20f](e); }; }
  else { f20o['on'+f20t]=f20o[f20f]; }
 }
}

function f20AddBlur(f20){
 if (f20.addblur){ return; }
 f20.addblur=f20Blur;
 f20EventAdd(f20,'blur','addblur');
}

function f20AddFocus(f20){
 if (f20.addfocus){ return; }
 f20.addfocus=f20Color;
 f20EventAdd(f20,'focus','addfocus');
}



/*******************New Format phone number***************************/
/*
var pnumber = "";

function formatPhone(obj)
{
	 
		pnumber = obj.value;
		
		if(pnumber.length == 3)
		{
			pnumber = "(" + pnumber + ")";
			obj.value = pnumber;
			
		}
		else if(pnumber.length == 8)
		{
			pnumber = (pnumber + "-");
			obj.value = pnumber;
			
		}
		//safari fix: move cursor to the end of text
		
		//IE
		if(obj.createTextRange)
		{
			var range = obj.createTextRange();
			range.moveStart("character", obj.value.length);
			range.moveEnd("character", obj.value.length);
			range.select();
			
		}
		else if (this.textbox.setSelectionRange) 
		{
        	obj.setSelectionRange(obj.value.length, 0);
		}
		
        obj.focus();
	 
}
*/

var prev_num = "";

function phone_move_next(obj,max_length, next_id)
{
	if(has_integer(obj))
	{
		prev_num = obj.value;
		if(obj.value.length == max_length)
		{
			prev_num = "";
			document.getElementById(next_id).focus();
		}
	}
	else if(isBlank(obj.value))
	{
		prev_num = "";
	}
	else
	{
		obj.value = prev_num;
	}
	
	document.getElementById("bill_phone").value = "(" + document.getElementById("bill_phone1").value + ")" + 
					document.getElementById("bill_phone2").value + "-" +
					document.getElementById("bill_phone3").value;
					
	document.getElementById("ship_phone").value = "(" + document.getElementById("ship_phone1").value + ")" + 
					document.getElementById("ship_phone2").value + "-" +
					document.getElementById("ship_phone3").value;
	
}

/**
*Used to fight the endless fight against spam
* switches the value of the form to the correct submit address 
**/
function switchform()
{
	var contact_form = document.contact_form;
	
	//alert(contact_form.keypressed.value);
	// Bad Bot, Bad...
	if (contact_form.keypressed.value == "true" && contact_form.field1.value == "")
	{
		contact_form.action = "../../contactus.php";
	}

}

function has_integer(obj)
{
	var val = obj.value;
	
	if (isBlank(val))
	{
		return false;
	}
	for(var i=0;i<val.length;i++)
	{
		if(!isDigit(val.charAt(i)))
		{
			return false;
		}
	}
	return true;
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

	
function trim(STRING)
{
	STRING = ltrim(STRING);
	return rtrim(STRING);
}

function rtrim(STRING)
{
	while(STRING.charAt((STRING.length -1))==" ")
	{
		STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


function ltrim(STRING)
{
	while(STRING.charAt(0)==" ")
	{
		STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}