 function vldmemberInfoForm(){//  <SERGEY>
// REGISTARTION >>  user info screen validation
	alertMsg = '';		
	if (document.getElementById('memberInfoForm')){
		with (memberInfoForm){			
			//whitening	
			var allFields = Array('m_email', 'm_emailconfirm', 'm_pass', 'm_passconfirm', 'm_fname','m_lname', 'm_address', 
					'm_city', 'm_state', 'm_zip','m_phone', 'm_country', 'm_pos', 'm_den');
				//	, 'm_custom1', 'm_custom2', 'm_custom3', 'm_custom4'); 
			for (var i = 0; i < allFields.length; i++)
				whiteDist(allFields[i]);
			//end whitening			
			if (!isEmail(m_email.value)){			  
				addError('Primary Email not a valid e-mail address');
				redDist("m_email");	
			}else{				
				if (!valid_match('Primary Email and Confirm Primary Email', m_email.value, m_emailconfirm.value)){
					redDist("m_email");	
					redDist("m_emailconfirm"); 
				}		
			}		 					
			if (!valid_required('Password',  m_pass.value))
				redDist("m_pass");
			if (!valid_match('Password and Password Confirm', m_pass.value, m_passconfirm.value)){
				redDist("m_pass");	
				redDist("m_passconfirm");
			}		
			if (!valid_required('First Name',  m_fname.value))
				redDist("m_fname");		
			if (!valid_required('Last Name',  m_lname.value))
				redDist("m_lname");		
			if (!valid_required('Church Name',  m_chname.value))
				redDist("m_chname");					
			if (!valid_required('Address',  m_address.value))
				redDist("m_address");				
			if (!valid_required('City',  m_city.value))
				redDist("m_city");
			if (!valid_required('State',  m_state.value))
				redDist("m_state");
			if (!valid_required('Zip',  m_zip.value))
				redDist("m_zip");
			if (!valid_required('Phone',  m_phone.value))
				redDist("m_phone");		
			if (!valid_required('Country',  m_country.value))
				redDist("m_country");	
			if (m_pos.value == ""){
				addError('Please select your Position');
				redDist("m_pos");
			}
			if (m_den.value == ""){
				addError('Please select your Denomination');
				redDist("m_den");
			}
		/*	if (!valid_required('Custom1',  m_custom1.value))
				redDist("m_custom1");	
			if (!valid_required('Custom2',  m_custom2.value))
				redDist("m_custom2");		
			if (!valid_required('Custom3',  m_custom3.value))
				redDist("m_custom3");		
			if (!valid_required('Custom4',  m_custom4.value))
				redDist("m_custom4");	
		*/		
			//AJAX checking on email dupletes				
			var url = '/registration/checkEmail';
			new Ajax.Request(url,
			{
				method:'post',
				asynchronous: false,
				parameters: {email: $('m_email').value},
				onComplete: function(transport) {
					if(transport.responseText.match(/exist/)) {
						redDist("m_email");
						addError('Email address is already registered to another user.');						
					}										
				}
			});
			//AJAX checking end	
		}
	}
	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == '';
}

function showprice(){ //  <SERGEY>
// REGISTARTION >> price logic with checkboxes and radios at 3 step of registration	
	counter = 0; wapyearprice = 0; wapquarterprice = 0; wapmonthprice = 0;
	wwryearprice = 0; wwrquarterprice = 0; wwrmonthprice = 0;
	sssyearprice = 0; npyearprice = 0; 	   ssyearprice = 0;							
	wspyearprice = 0; wsmonthprice = 0;    wwyearprice = 0;
	fullprice = 0;
	
	// checking on discount
	if (document.productAreasForm.wapcheck.checked && document.productAreasForm.wapradio[0].checked)
		counter = counter + 1;
	if (document.productAreasForm.ssscheck.checked) 
		counter = counter + 1;
	if (document.productAreasForm.npcheck.checked) 
		counter = counter + 1;
	if (document.productAreasForm.sscheck.checked)
		counter = counter + 1;
	if (document.productAreasForm.wscheck.checked && document.productAreasForm.wsradio[0].checked)
		counter = counter + 1;
	if (document.productAreasForm.wwrcheck.checked	&& document.productAreasForm.wwrradio[0].checked)
		counter = counter + 1;
		
	//checking for only year radios were cosen
	if (document.productAreasForm.wapcheck.checked && document.productAreasForm.wapradio[1].checked)
		counter = 0;	
	if (document.productAreasForm.wapcheck.checked && document.productAreasForm.wapradio[2].checked)
		counter = 0;		
	
	if (document.productAreasForm.wscheck.checked && document.productAreasForm.wsradio[1].checked)
		counter = 0;
	
	if (document.productAreasForm.wwrcheck.checked	&& document.productAreasForm.wwrradio[1].checked)
		counter = 0;
	if (document.productAreasForm.wwrcheck.checked	&& document.productAreasForm.wwrradio[2].checked)
		counter = 0;
		
	if ( counter > 1 ){
			discount = 0.85;
			discounter = 0.15;		
	}else{
			discount = 1;
			discounter = 0;		
	}	
	//start summing 
	if (document.productAreasForm.wapcheck.checked == true){
		elementShow('wapradio0');
		elementShow('wapradio1');
		elementShow('wapradio2');
		elementShow('a_wap');
		
		
		if (document.productAreasForm.wapradio[0].checked)
			wapyearprice = 179.99;								
		if (document.productAreasForm.wapradio[1].checked)									
			wapquarterprice = 45.95;																						
		if (document.productAreasForm.wapradio[2].checked)						
			wapmonthprice = 19.99;							
	} else {	
		elementHide('wapradio0');
		elementHide('wapradio1');
		elementHide('wapradio2');
		elementHide('a_wap');		
	}
	
	if (document.productAreasForm.wwrcheck.checked == true){
		elementShow('wwrradio0');
		elementShow('wwrradio1');
		elementShow('wwrradio2');
		elementShow('a_wwr');		
		
		if (document.productAreasForm.wwrradio[0].checked)
			wwryearprice = 199.99;								
		if (document.productAreasForm.wwrradio[1].checked)									
			wwrquarterprice = 59.99;																						
		if (document.productAreasForm.wwrradio[2].checked)						
			wwrmonthprice = 19.99;							
	} else {	
		elementHide('wwrradio0');
		elementHide('wwrradio1');
		elementHide('wwrradio2');
		elementHide('a_wwr');
		
	}
	
	
	if (document.productAreasForm.ssscheck.checked){
		sssyearprice = 199.99;
		elementShow('a_sss');	
	}else
		elementHide('a_sss');
		
	if (document.productAreasForm.npcheck.checked){		
		npyearprice = 59.99;
		elementShow('a_np');	
	}else
		elementHide('a_np');
	
	if (document.productAreasForm.sscheck.checked){	
		ssyearprice = 59.99;
		elementShow('a_ss');	
	}else
		elementHide('a_ss');
		
	if (document.productAreasForm.wscheck.checked == true){
		elementShow('wsradio0');
		elementShow('wsradio1');					
		if (document.productAreasForm.wsradio[0].checked)
			wspyearprice = 89.99;								
		if (document.productAreasForm.wsradio[1].checked)	
			wsmonthprice = 9.99;
		elementShow('a_ws');		
	} else {	
		elementHide('wsradio0');
		elementHide('wsradio1');			
		elementHide('a_ws');
	}
	
							

	// total 
	buffy = Math.round((wapyearprice + sssyearprice + npyearprice + ssyearprice + wspyearprice + wwryearprice) * 100) / 100;
	document.productAreasForm.Byearprice.value =  buffy;
	document.all.Byear.innerHTML = '$ ' + document.productAreasForm.Byearprice.value;						
	

	buffq = Math.round((wapquarterprice + wwrquarterprice) * 100) / 100;
	document.productAreasForm.Bquarterprice.value = buffq;
	document.all.Bquarter.innerHTML ='$ ' + document.productAreasForm.Bquarterprice.value;						
	
	
	buffm = Math.round((wsmonthprice + wapmonthprice + wwrmonthprice) * 100) / 100;
	document.productAreasForm.Bmonthprice.value = buffm;
	document.all.Bmonth.innerHTML ='$ ' + document.productAreasForm.Bmonthprice.value;		

	// discount
	Ddbuffy = Math.round((buffy * discounter) * 100) / 100;
	document.all.Dyear.innerHTML ='$ ' + Ddbuffy;						
	
/*	Ddbuffq = Math.round((buffq * discounter) * 100) / 100;	
	document.all.Dquarter.innerHTML ='$ ' + Ddbuffq;						
	Ddbuffm = Math.round((buffm * discounter) * 100) / 100;	
	document.all.Dmonth.innerHTML ='$ ' + Ddbuffm;
*/	
	// discounted
	dbuffy = Math.round((buffy * discount) * 100) / 100;
	document.productAreasForm.yearprice.value =  dbuffy;
	document.all.year.innerHTML ='$ ' + document.productAreasForm.yearprice.value;	

	dbuffq = Math.round((buffq * discount) * 100) / 100;
	document.productAreasForm.quarterprice.value = dbuffq;
	document.all.quarter.innerHTML ='$ ' + document.productAreasForm.quarterprice.value;						
	
	dbuffm = Math.round((buffm * discount) * 100) / 100;
	document.productAreasForm.monthprice.value = dbuffm;
	document.all.month.innerHTML ='$ ' + document.productAreasForm.monthprice.value;		
				
	//	first payment
	if (document.productAreasForm.wapcheck.checked && document.productAreasForm.wapradio[0].checked  //if all are checked price is $399.95
			&& document.productAreasForm.ssscheck.checked 
			&& document.productAreasForm.npcheck.checked 
			&& document.productAreasForm.sscheck.checked
			&& document.productAreasForm.wscheck.checked && document.productAreasForm.wsradio[0].checked 
			&& document.productAreasForm.wwrcheck.checked && document.productAreasForm.wwrradio[0].checked){	
		
		Ddbuffy = Math.round((buffy - 399.95) * 100) / 100;
		document.all.Dyear.innerHTML ='$ ' + Ddbuffy;
		
		document.all.year.innerHTML ='$ 399.95';
		document.productAreasForm.fullprice.value = 399.95;
		document.all.fullpr.innerHTML ='BONUS $ ' + document.productAreasForm.fullprice.value + ' for full yearly subscription';	
		
		

	}else{
		fullprice = dbuffy + dbuffq + dbuffm;
		fullprice = Math.round((fullprice) * 100) / 100;
		document.productAreasForm.fullprice.value = fullprice;
		document.all.fullpr.innerHTML ='$ ' + document.productAreasForm.fullprice.value;				
	}	
}	

function vldproductAreasForm(){ //  <SERGEY>
// REGISTARTION >> subscriptions form validation	
	alertMsg =''
	//if all are checked price is $399.95
	if (document.productAreasForm.wapcheck.checked 
				&& document.productAreasForm.ssscheck.checked 
				&& document.productAreasForm.npcheck.checked 
				&& document.productAreasForm.sscheck.checked
				&& document.productAreasForm.wscheck.checked 
				&& document.productAreasForm.wwrcheck.checked){
		return alertMsg == '';
	}else{					
		if (document.getElementById('productAreasForm')){
			with (productAreasForm){	
				whiteDist("wap");
				whiteDist("ws");
				if (document.productAreasForm.wapcheck.checked){
					if (!document.productAreasForm.wapradio[0].checked 
							&& !document.productAreasForm.wapradio[1].checked
							&& !document.productAreasForm.wapradio[2].checked){
						addError('You should choose pay period for Worship Alive Plus Area');
						redDist("wap");
					}	
				}	
				if (document.productAreasForm.wwrcheck.checked){
					if (!document.productAreasForm.wwrradio[0].checked 
							&& !document.productAreasForm.wwrradio[1].checked
							&& !document.productAreasForm.wwrradio[2].checked){
						addError('You should choose pay period for Worship Alive Remix Area');
						redDist("wwr");
					}	
				}	
				if (document.productAreasForm.wscheck.checked){	
					if (!document.productAreasForm.wsradio[0].checked 
							&& !document.productAreasForm.wsradio[1].checked){						
						addError('You should choose pay period for Worship Share Area'); 	
						redDist("ws");
					}	
				}
			}	
		}
	}	
	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == '';
}

function chooseAll(){ // <SERGEY>
// REGISTARTION >> checking all radios -  bonus payment
	document.productAreasForm.wapcheck.checked = true;
		document.productAreasForm.wapradio[0].checked = true; 
	document.productAreasForm.wwrcheck.checked = true;
		document.productAreasForm.wwrradio[0].checked = true; 
	document.productAreasForm.ssscheck.checked = true;
	document.productAreasForm.npcheck.checked = true;
	document.productAreasForm.sscheck.checked = true;
	document.productAreasForm.wscheck.checked = true;
		document.productAreasForm.wsradio[0].checked = true;
	
	showprice();	
}
	

function vldccInfoForm(){// <SERGEY>
// REGISTARTION >> credit card form validation 
	alertMsg ='';	
	var allFields = Array('m_ccnum', 'm_cname', 'm_ccaddress', 'm_cczip', 'm_ccode'); 
	m_ccnum		=  $('m_ccnum');
	m_cname		=  $('m_cname');
	m_ccaddress =  $('m_ccaddress');
	m_cczip		=  $('m_cczip');
	m_ccode		=  $('m_ccode');
	for (var i = 0; i < allFields.length; i++)
		whiteDist(allFields[i]);	
	
	if (document.getElementById('ccInfoForm')){	
		//Credit Card Number
		//var cc_regexp = /^\w{12,22}$/;				
		var cc_regexp = /^\d{12,22}$/;		
		
		if (!cc_regexp.test(m_ccnum.value)){
			addError('Credit Card Number-Wrong Format. Only numbers are allowed. No spaces or other characters can be used');			 
			redDist("m_ccnum");
		}					
		if (!valid_required('Name on Card',  m_cname.value))
				redDist("m_cname");	
		var sc_regexp = /^\d{3,4}$/;
		if (!sc_regexp.test(m_ccode.value)){
			addError('Security Code-Wrong Format');
			redDist("m_ccode");
		}
	}
	if (!valid_required('Address on Card',  m_ccaddress.value))
		redDist("m_ccaddress");		
	if (!valid_required('Zip on Card',  m_cczip.value))
		redDist("m_cczip");		
		
	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == '';
}
function subscribesForm(){
	alertMsg ='';	

	//var radio_wap 	= eval("document.getElementById('subscribeForm').elements.wapradio");
	//var radio_ws 	= eval("document.getElementById('subscribeForm').elements.wsradio");
	if(document.getElementById('subscribeForm').elements.area.value == 'wap')
		if(getRadioValue('wapradio') == -1)
			alertMsg += '\n\r Please choose a time period: Yearly, Quarterly or Monthly.';
	if(document.getElementById('subscribeForm').elements.area.value == 'ws')
		if(getRadioValue('wsradio') == -1)
			alertMsg += '\n\r Please choose a time period: Yearly or Monthly.';
	if(document.getElementById('subscribeForm').elements.area.value == 'wwr')
		if(getRadioValue('wwrradio') == -1)
			alertMsg += '\n\r Please choose a time period: Yearly, Quarterly or Monthly.';


	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == '';
}
/**
 * @author Eugene Zaritskiy
 *  
 * Function run alert
 *
 */


function selectThreeDD(){
	alertMsg = '';
	var allElem = Array('lectionary','year','church_event');
	for (var i = 0; i < allElem.length; i++) {
		whiteDist(allElem[i]);
	}
	
	if(document.getElementById('dropForm').elements.lectionary.value == ""){
		redDist('lectionary');
		alertMsg += '\r\nPlease, choose Lectionary.';
	}
	if(document.getElementById('dropForm').elements.year.value == ""){
		redDist('year');
		alertMsg += '\r\nPlease, choose Year.';
	}
	if(document.getElementById('dropForm').elements.church_event.value == ""){
		redDist('church_event');
		alertMsg += '\r\nPlease, choose Sunday.';
	}


	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == ''; 
} 
/**
 * @author Eugene Zaritskiy
 *  
 * Function run alert
 *
 */

function selectThreeDDS(){
	alertMsg = '';
	var allElem = Array('scripture', 'chapter');
	for (var i = 0; i < allElem.length; i++) {
		whiteDist(allElem[i]);
	}

	if(document.getElementById('dropFormS').elements.scripture.value == ""){
		redDist('scripture');
		alertMsg += '\r\nPlease, choose Scripture.';
	}

	if(document.getElementById('dropFormS').elements.chapter.value == ""){
		redDist('chapter');
		alertMsg += '\r\nPlease, choose Chapter.';
	}

	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == ''; 
} 

/**
 * @author Eugene Zaritskiy
 *  
 * Function run alert
 *
 */

function selectArea(){
	alertMsg = '';
	whiteDist('area');

	if(document.getElementById('dropFormArea').elements.area.value == ""){
		redDist('area');
		alertMsg += '\r\n Please choose a product area.';
	}

	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == ''; 
} 

/**
 * @author Eugene Zaritskiy
 *  
 * Function run alert
 *
 */
				
function selectThreeDDT(){
	alertMsg = '';
	var elem = 'topic';
	whiteDist(elem);
	if(document.getElementById('dropFormT').elements.topic.value == ""){
		redDist('topic');
		alertMsg += '\r\nPlease, choose Topic.';
	}
	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == ''; 

}
/**
 * @author Eugene Zaritskiy
 *  
 * Function run alert
 *
 */

function selectThreeDDK(){
	alertMsg = '';
	var elem = 'keyword';
	whiteDist(elem);

	if(document.getElementById('dropFormK').elements.keyword.value == ""){
		redDist('keyword');
		alertMsg += '\r\nPlease, choose Keyword.';
	}
	if (alertMsg != '')
		alert('Errors:\r\n' + alertMsg);
	return alertMsg == '';
	
}

