function addRow(r,target){

	var root = r.parentNode;//the root
	var allRows = root.getElementsByTagName('tr');//the rows' collection
	var cRow = allRows[1].cloneNode(true)//the clone of the 1st row
	var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row

	for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)

		cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length));
		
		if (cInp[i].value!='+'){
		
			cInp[i].value='';
	
		}
	
	}

	var parts_total = parseInt(document.getElementById(target).value);
	document.getElementById(target).value = parts_total+1;

	root.appendChild(cRow);//appends the cloned row as a new row

}

function add_eqpt(target,index){

	var poststr = "";
	
	poststr += 'page=eqpt_form&';
	
	poststr += 'index=' + index;

	document.getElementById('equipment_total').value = index;

	new Ajax.Updater(target, 'form_include.php', { method: 'get', parameters: poststr } );

}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function process_form(){

	var errors = "";
	
	if(document.getElementById('Contact_FirstName').value == ""){
	
		errors += "Please enter your first name.\n";
	
	}
	
	if(document.getElementById('Contact_LastName').value == ""){
	
		errors += "Please enter your last name.\n";
	
	}
	
	if(document.getElementById('Contact_Company').value == ""){
	
		errors += "Please enter your company.\n";
	
	}
	
	if(document.getElementById('Contact_WorkPhone').value == "" || document.getElementById('Contact_WorkPhone').value.length < 10){
	
		errors += "Please enter your work phone.\n";
	
	}

	if(echeck(document.getElementById('Contact_Email').value)==false || document.getElementById('Contact_Email').value == "" || document.getElementById('Contact_Email').value == null){
	
		errors += "Please enter a valid Email Address.\n";
	
	}
	
	if(errors == ""){
	
		var poststr = "";

		var selObj = document.getElementById('LocationPreference');
		var selIndex = selObj.selectedIndex;
		
		poststr += 'LocationPreference=' + encodeURI(selObj.options[selIndex].value) + '&';
		
		poststr += 'Comments=' + encodeURI(document.getElementById('Comments').value) + '&';
		
		var allInp=document.getElementsByTagName('input');

		for(var i=0;i<allInp.length;i++){
		
			if (allInp[i].type == 'radio'){
			
				if (allInp[i].checked){
				
					poststr += allInp[i].name + '=' + encodeURI(allInp[i].value) + '&';
				
				}
			
			}
			else{
			
				poststr += allInp[i].name + '=' + encodeURI(allInp[i].value) + '&';

			}

		}
		
		poststr += 'page=process_form&';
		
		new Ajax.Updater('form_response', 'form_include.php', { method: 'get', parameters: poststr } );
		
	}
	else{
	
		alert(errors);
	
	}
	
}