
 
 
 
// ---------------------------------------------------------
// Validate ranking questions: each value used exactly once.
 
function rankem(question, q_size,qnoDisplay) {
// copyright 2002 Kent Rauch
 
 var aLert1 = "";
 var aLert2 = "";
 
 // supports up to 26 items to be ranked -- extend this array to increase
 var cal = "A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z";
 cal = cal.split('.');
 
 var a = 0;
 
 var irate = "rink" + question;
 
 eval(irate + " = new Object();");
 
 var myrate = "";
 if (document.forms['survey'].elements['totalans'+question] != null){
	q_size = document.forms['survey'].elements['totalans'+question].value;
 }
 
 for (var x = 0; x < q_size; ++x) {
  //myrate = "f"+question+"-"+cal[x];
  myrate = "f"+question+"-"+(x+1);
 
  //eval(irate + "[" + x + "] = document.survey." + myrate + ".selectedIndex");
  eval(irate + "[" + x + "] = document.survey.elements['" + myrate + "'].selectedIndex");
  if (eval(irate + "[" + x + "]")) {
   ++a;
   for (var y = 0; y < x; ++y) {
    if (eval(irate + "[" + y + "]") == eval(irate + "[" + x + "]")) {
     aLert1 = "Question "+ qnoDisplay +": please use each ranking only once.\n";
    }
   }
  }
 }
 
 if (document.forms['survey'].elements['r'+question] != null){
	if (a != q_size){
  		aLert2 = "Question " + qnoDisplay +":please rank all items.\n";
 	}
 }
 
 var aLert = aLert1 + aLert2;
 
 if (aLert) {
  alert(aLert);
  return true;
//  badrank = true;
 }
 
 
}
  
  
  
  
function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789.';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return false;  // Enter
if (whichCode == 8) return true;  // Enter
if (whichCode == 0) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
return true;
}
 
  
    function disableEnterKey() 
    {
      return !(window.event && window.event.keyCode == 13);
    }
	
	
	function getRadioValue(radio) {
		for (index=0; index<radio.length; index++)
		{ if (radio[index].checked) return radio[index].value; }
		return null;
	}
	
 
// VALIDATE FORM
	
function checkRequired()
{
		badrank = true;
		  
		for (fieldno=1;fieldno<100;fieldno++){
			selected=0;
			selected2=0;
			
			if (document.forms['survey'].elements['t'+fieldno] != null){
				type = document.forms['survey'].elements['t'+fieldno].value;
				type = type.charAt(0)
				
				if (document.forms['survey'].elements['qnodisplay'+fieldno] != null){
					qnoDisplay = document.forms['survey'].elements['qnodisplay'+fieldno].value;
				}
				
				//check ranking questions
				if (type == 9){
					if (rankem(fieldno,4,qnoDisplay)) {return false;}
				}
				
				//check multiple text box questions
				if (type == 8){
					count = document.forms['survey'].elements['count'+fieldno].value;
					
					for (i=1;i<=count;i++){
						if (document.forms['survey'].elements['r'+fieldno+'-'+i] != null){
							if (document.forms['survey'].elements['f'+fieldno+'-'+i].value == ''){
								alert('Please answer question '+qnoDisplay+' and all other questions marked with a *');
								return false;
							}
						}
					}
		
				}
				
				
				//Check other questions
						
				if (document.forms['survey'].elements['r'+fieldno] != null){
					qnoDisplay = document.forms['survey'].elements['qnodisplay'+fieldno].value;	
					type = document.forms['survey'].elements['t'+fieldno].value;
					type = type.charAt(0)
					
					if (type == 1){
						if (document.forms['survey'].elements['f'+fieldno].checked){
							return true;
						}
	//dropdown				
	
	selected2 = document.forms['survey'].elements['f'+fieldno].selectedIndex
	if (selected2 == 0) {selected2=null;}
	
	//list vertically (radio buttons)				
						selected = getRadioValue(document.forms['survey'].elements['f'+fieldno]);
						if (selected == null && selected2 == null) {
							
												
 
							if (document.forms['survey'].elements['f'+fieldno+'-OTHER'] != null){
								if (document.forms['survey'].elements['f'+fieldno+'-OTHER'].value == ''){	
									alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
									return false;
								}
							}
							else{
								alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
								return false;
							}
						
						}	
					}
					
					
					if (type == 2){
						for (i=1;i<100;i++){
							if (document.forms['survey'].elements['f'+fieldno+'-'+i] != null)
								if (document.forms['survey'].elements['f'+fieldno+'-'+i].checked){
									selected=1;
								}	
						}
						
		
						if (selected==0){
							if (document.forms['survey'].elements['f'+fieldno+'-OTHER'] != null){
								if (document.forms['survey'].elements['f'+fieldno+'-OTHER'].value == ''){	
									alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
									return false;
								}
							}
							else {
								alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
								return false;
							}
						}
			
					}
					
					
					if (type == 3 | type == 7){
					
						if (document.forms['survey'].elements['f'+fieldno].selectedIndex == 0){
							alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
							return false;
						}					
					}
					
					
					if (type == 4){
					
						if (document.forms['survey'].elements['f'+fieldno].value == ''){
							alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
							return false;
						}
					}
					
					
					if (type == 6){
						count = document.forms['survey'].elements['count'+fieldno].value;
						
						for (i=1;i<=count;i++){
							if (document.forms['survey'].elements['f'+fieldno+'-'+i] != null){
								selected = getRadioValue(document.forms['survey'].elements['f'+fieldno+'-'+i]);
								if (selected == null) {
									//check the other box as well
									if (document.forms['survey'].elements['f'+fieldno+'-'+i+'-OTHER'] != null){
										if (document.forms['survey'].elements['f'+fieldno+'-'+i+'-OTHER'].value == ''){
											alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
											return false;
										}
									}else{
																	
										alert('Please answer question '+qnoDisplay+' and all other questions marked with an *');
										return false;
									}
								
								}
							}	
						}
						
					}
	
					
					
				}
			}
		}
		
	}
	
	function deselectRadio(radioName){
		//alert(radioName);
		setCheckedValue(document.forms['survey'].elements[radioName],10);
	}
 
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
 
 
 
  //-->
  
  

