// JavaScript Document
function validateCompForm(){
	//question
	/*if (!$$('input:checked[type="radio"][name="horseAge"]').pluck('value').length > 0)
	{
		alert('Please answer the question');
		new Effect.Highlight('question',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		
		return false;	
	}*/
	
	var sduration = 1;
	var soffset = -5;
	
	//firstname
	if (!JSLNotNull($('firstname'), "Please enter your first name.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('firstname',{duration:sduration,offset:soffset});			
		return false;	
	}
	if (!JSLIsTextOnlyWithHyphens($('firstname'), "Please enter text only for your first name.")) { 
		new Effect.Highlight('firstname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('firstname',{duration:sduration,offset:soffset});				
		return false;	
	}	
	//surname
	if (!JSLNotNull($('surname'), "Please enter your surname.")) { 
		new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('surname',{duration:sduration,offset:soffset});			
		return false;	
	}
	if (!JSLIsTextOnlyWithHyphens($('surname'), "Please enter text only for your surname.")) { 
		new Effect.Highlight('surname',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('surname',{duration:sduration,offset:soffset});				
		return false;	
	}
	//contact
	if (!JSLIsPhone($('contact'), "Please enter a valid daytime telephone number.")) { 
		new Effect.Highlight('contact',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('contact',{duration:sduration,offset:soffset});				
		return false;
	}
	
	//Email
	if (!JSLCheckIsEmail($('email'), "Please enter a valid email address.")) { 
		new Effect.Highlight('email',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('email',{duration:sduration,offset:soffset});				
		return false;
	}
	/*
	if (!$$('input:checked[type="radio"][name="newsregEmailType"]').pluck('value').length > 0)
	{
		alert('Please choose whether this is your personal or practice email address?');
		new Effect.Highlight('newsregEmailType',{startcolor:'#FAB320', endcolor:'#FFFFFF'});				
		return false;	
	}
	
	//contact mobile
	if (!JSLIsPhone($('contactMobile'), "Please enter a valid mobile number.")) { 
		new Effect.Highlight('contactMobile',{startcolor:'#FAB320', endcolor:'#FFFFFF'});				
		return false;
	}
	
	
	
	if (!JSLSelected($('usertitle'), "Please enter your title.")) { 
	 	new Effect.Highlight('usertitle');
		return false; 
	}
	*/
	//practicename
	if (!JSLNotNull($('practicename'), "Please enter your practice name.")) { 
		new Effect.Highlight('practicename',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('practicename',{duration:sduration,offset:soffset});			
		return false;	
	}
	//practicename
	if (!JSLNotNull($('postcode'), "Please enter your practice postcode.")) { 
		new Effect.Highlight('postcode',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('postcode',{duration:sduration,offset:soffset});				
		return false;	
	}
	
	//practicetype
	if(!$('smallanimalonly').checked&&!$('smallanimalequine').checked&&!$('equineonly').checked&&!$('other').checked){
		doAlert('Please select your practice type');
		new Effect.Highlight('practicetype',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('practicetype',{duration:sduration,offset:soffset});				
		return false;	
	}
	/*var iTotalCheckedPType = 0;
	if($('smallanimalonly').checked){
		iTotalCheckedPType = iTotalCheckedPType + 1;
	}
	if($('smallanimalequine').checked){
		iTotalCheckedPType = iTotalCheckedPType + 1;
	}
	if($('equineonly').checked){
		iTotalCheckedPType = iTotalCheckedPType + 1;
	}
	if($('other').checked){
		iTotalCheckedPType = iTotalCheckedPType + 1;
	}
	if(iTotalCheckedPType>1){
		doAlert('Please select only one practice type');	
		new Effect.Highlight('practicetype',{startcolor:'#FAB320', endcolor:'#FFFFFF'});				
		return false;	
	}*/
	
	
	
	
	//positionheld
	
	if(!$('vet').checked&&!$('nurse').checked&&!$('receptionist').checked&&!$('otherpos').checked){
		doAlert('Please select your position');
		new Effect.Highlight('positionheld',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('positionheld',{duration:sduration,offset:soffset});			
		return false;	
	}
	/*var iTotalCheckedPosition = 0;
	if($('vet').checked){
		iTotalCheckedPosition = iTotalCheckedPosition + 1;
	}
	if($('nurse').checked){
		iTotalCheckedPosition = iTotalCheckedPosition + 1;
	}
	if($('receptionist').checked){
		iTotalCheckedPosition = iTotalCheckedPosition + 1;
	}
	if($('otherpos').checked){
		iTotalCheckedPosition = iTotalCheckedPosition + 1;
	}
	if(iTotalCheckedPosition>1){
		doAlert('Please select only one position');	
		new Effect.Highlight('positionheld',{startcolor:'#FAB320', endcolor:'#FFFFFF'});				
		return false;
	}*/
	
	
	
	//fulltimevets 
	
	if (!JSLNotNull($('fulltimevets'), "Please enter a number only into the 'How many full time vets do you have in practice?' field")) { 
		new Effect.Highlight('fulltimevets',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('fulltimevets',{duration:sduration,offset:soffset});			
		return false;	
	}
	
	if (!JSLIsInteger($('fulltimevets'), "Please enter a number only into the 'How many full time vets do you have in practice?' field")) { 
		new Effect.Highlight('fulltimevets',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('fulltimevets',{duration:sduration,offset:soffset});			
		return false;	
	}
	
	if (!JSLCheckLength($('fulltimevets'), "Please enter a maximum of 2 numbers into the 'How many full time vets do you have in practice?' field",3)) { 
		new Effect.Highlight('fulltimevets',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('fulltimevets',{duration:sduration,offset:soffset});				
		return false;	
	}
	
	//fulltimevets 
	
	if (!JSLNotNull($('primaryvaccinations'), "Please enter a number only into the 'How many primary vaccinations does the practice perform per week?' field")) { 
		new Effect.Highlight('primaryvaccinations',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('primaryvaccinations',{duration:sduration,offset:soffset});			
		return false;	
	}
	
	if (!JSLIsInteger($('primaryvaccinations'), "Please enter a number only into the 'How many primary vaccinations does the practice perform per week?' field")) { 
		new Effect.Highlight('primaryvaccinations',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('primaryvaccinations',{duration:sduration,offset:soffset});			
		return false;	
	}
	
	if (!JSLCheckLength($('primaryvaccinations'), "Please enter a maximum of 2 numbers into the 'How many primary vaccinations does the practice perform per week?' field",4)) { 
		new Effect.Highlight('primaryvaccinations',{startcolor:'#FAB320', endcolor:'#FFFFFF'});	
		new Effect.ScrollTo('primaryvaccinations',{duration:sduration,offset:soffset});			
		return false;	
	}
	
	//petinsurancepomotions
	if($('petinsuranceyes').checked){
	  if(!$('petplan').checked&&!$('tvis').checked&&!$('petprotect').checked&&!$('other4').checked){
		  doAlert('Please select who you promote');
		  new Effect.Highlight('petinsurancepomotions',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		  new Effect.ScrollTo('petinsurancepomotions');				
		  return false;	
	  }
	}
	
	//petinsurancepomotions
	if($('petplan').checked){
	  if(!$('ar').checked&&!$('na').checked){
		  doAlert('Please select whether you are an Appointed Representative (AR) or a Non-authorised practice (NA)');
		  new Effect.Highlight('petplanoptionsgroup',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		  new Effect.ScrollTo('petplanoptionsgroup');				
		  return false;	
	  }
	}
	
	//wholesaler
	if(!$('nvs').checked&&!$('dunlops').checked&&!$('centaur').checked&&!$('other3').checked){
		doAlert('Please select your wholesaler');
		new Effect.Highlight('wholesaler',{startcolor:'#FAB320', endcolor:'#FFFFFF'});
		new Effect.ScrollTo('wholesaler',{duration:sduration,offset:soffset});				
		return false;	
	}
	
	document.forms['frmComp'].submit();
}

function toggleInput(el1,el2,state){
	var e1 = document.getElementById("" +  el1 +  "");
	var e2 = document.getElementById("" +  el2 +  "");
	if(state=='yes'){
	  if(e1.checked){
		 e2.style.visibility="visible";
		 e2.style.display="block";
	  }
	  else{
		  e2.style.visibility="hidden";
		  e2.style.display="none";
	  }
	}
	else{
		e2.style.visibility="hidden";
		e2.style.display="none";
	}
}

// radioToggle parameter values:
// true = allows current checkbox to deselect itself
// false = prevents current checkbox from deselecting itself (radio input default behaviour) [default]

function simRadio(current,group,el,state,toggle){
	//alert(current);
	var radioToggle = toggle;
	var g = group.split(',');
	var c = document.getElementById("" +  current +  "");
	for(i=0;i<g.length;i++){
		a = document.getElementById("" +  g[i] +  "");
		if(c!=a){
			a.checked=false;
		}
	}
	if(radioToggle){
	if(!c.checked){
	c.checked=false;
	}
	else{
		c.checked=true;
	}
	}
	else{
		c.checked=true;
	}
	if(document.getElementById("" +  el +  "")){
		toggleInput(current,el,state);	
	}
}

function doAlert(sString){
	/*$('alertholder').style.display = 'none';
	$('alertholder').innerHTML = sString;
	new Effect.Appear('alertholder');*/
	alert(sString);
}
