/*  A little Javascript Lib
*   Written by Peter Graber, www.grabers.com
*
*/


window.onload = prepare;

function prepare() {
	//Step 1 - add simple behavior to credit card payment type radio buttons
	document.getElementById('paytype1').onclick = function() {
			hide('ccFieldSet');
			}
			
	document.getElementById('paytype2').onclick = function() {
			hide('ccFieldSet');
			}
	var ccType = document.getElementById('paytype3');
			ccType.onclick = function() {
				show('ccFieldSet');
				}

		if( prepare2() != null ) {
	
	return true
	
	}
	
}


function checkData(data) {

				
}




	/*  This still needs to be developed
	
	
	//First - Define an Errors array for storage;
	var errors = new Array();
	
	//Second - Create an array storing common validated widget names and validation types.
	var validationWidgets = new Array();
	
		//Names of submitters or people's full name
		validationWidgets[1] = new Array();
		validationWidgets[1]['name'] = "Full_Name";
		validationWidgets[1]['vType'] = "text";
		
		validationWidgets[2] = new Array();
		validationWidgets[2]['name'] = "Contributor_Name"
		validationWidgets[2]['vType'] = "text";
			
		
		//Email Addresses
		validationWidgets[3] = new Array();
		validationWidgets[3]['name'] = "Contributor_Email";
		validationWidgets[3]['vType'] = 'text';
		
		validationWidgets[4] = new Array();
		validationWidgets[4]['name'] = "Email_Address";
		validationWidgets[4]['vType'] = 'text';
		
		
	 //Street Addresses
		validationWidgets[5] = new Array();
		validationWidgets[5]['name'] = "Street_Address";
		validationWidgets[5]['vType'] = 'text';
		
	//Cities
		validationWidgets[6] = new Array();
		validationWidgets[6]['name'] = "City";
		validationWidgets[6]['vType'] = 'text';
		
	//States
		validationWidgets[7] = new Array();
		validationWidgets[7]['name'] = "State";
		validationWidgets[7]['vType'] = 'text';
		
	//Zips
		validationWidgets[8] = new Array();
		validationWidgets[8]['name'] = "Zip";
		validationWidgets[8]['vType'] = 'text';
	
	//Phones
		validationWidgets[9] = new Array();
		validationWidgets[9]['name'] = "Telephone";
		validationWidgets[9]['vType'] = 'text';
					
	//Faxs
		validationWidgets[10] = new Array();
		validationWidgets[10]['name'] = "Facsimile";
		validationWidgets[10]['vType'] = 'text';
			
	//CC Names
		validationWidgets[11] = new Array();
		validationWidgets[11]['name'] = "Name_on_Card";
		validationWidgets[11]['vType'] = 'text';

	//CC Streets
		validationWidgets[12] = new Array();
		validationWidgets[12]['name'] = "Billing_Street";
		validationWidgets[12]['vType'] = 'text';

  //CC Citys
		validationWidgets[13] = new Array();
		validationWidgets[13]['name'] = "Billing_City";
		validationWidgets[13]['vType'] = 'text';
		
	//CC States
		validationWidgets[14] = new Array();
		validationWidgets[14]['name'] = "Billing_State";
		validationWidgets[14]['vType'] = 'text';

	//CC Zips
		validationWidgets[15] = new Array();
		validationWidgets[15]['name'] = "Billing_Zip";
		validationWidgets[15]['vType'] = 'number';
		
	//CC Number
		validationWidgets[15] = new Array();
		validationWidgets[15]['name'] = "Card_Number";
		validationWidgets[15]['vType'] = 'number';
			
		
//Next - Cycle through the elements and validate
	
	for(var i=1; i <= form.elements.length -1; i++) {
	    
			var widget =  form.elements[i].name;
	
			if (validatedElement(validationWidgets,widget)) {
			  
				switch (validationWidgets[i]['vType']) {
					 
					 case 'number':
					 			return isEmpty(form.elements[i].value);
					 
					 default:  //text
					 			if (isEmpty(form.elements[i].value)) {
										errors[isEmpty(form.elements[i].name)] = 1;
										}
			 			 }
			}
 	}
	
 //Now
  

}


function validatedElement(validateds, widget) {
		for(var a= 1; a < validateds.length; a++) {
			
			if(validateds[a]['name'] == widget) {
				return true;
				}
				
			 else {
			 	continue;
				}
		return false;	
	}
}


*/



function show(element) {
	  var a = document.getElementById(element);
		a.style.display = 'block';
}


function hide(element) {
	  var a = document.getElementById(element);
		a.style.display = 'none';
}





function isEmpty(element) {
		var a = element
		
		if(a.length < 2) {
				return true;
				}
				
		for (var j=0; j < a.length+1; j++) {
		  var c = a.charAt(j);
			if(c == '\n' || c =='\t'){
			return true
			}	
		}
		
		return false;
}


function cleanUp(number) {
		
			var total = null;
			total = (number == Math.floor(number) ? number + '.00' : ( (number*10 == Math.floor(number*10)) ? number + '0' : number));
			total = total +'';
			//This deals with Javascript's math errors.
			var decPt = total.indexOf('.', 0) + 3;			
			total = total.substr(0,decPt);
			return total;
}
