function checkInputBox(controlId, displayMessage){
	if (trimAll(document.getElementById(controlId).value) == ""){
		alert(displayMessage);
		document.getElementById(controlId).focus();
		return false;
	}
	return true;
}

function checkPasswords(controlId1, controlId2){
	if (document.getElementById(controlId1).value != document.getElementById(controlId2).value){
		alert("Password and Confirm Password must be same");
		return false;
	}
	else{
		return true;
	}
}

function validateEmail(roSource){
	var lsValue = new String(roSource.value);
	if ((lsValue != "") && ((lsValue.indexOf("@")==-1) || (lsValue.indexOf(".")==-1))){
		return showMessage(roSource, 'Invalid Email Address', true);
	}
	else{
		return showMessage(roSource, '', false);
	}
}

function trimAll(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function checkEmail(controlId){
	var lsValue = new String(document.getElementById(controlId).value);
	if ((lsValue != "") && ((lsValue.indexOf("@")==-1) || (lsValue.indexOf(".")==-1))){
		alert('Invalid Email Address');
		document.getElementById(controlId).focus();
		return false;
	}
	return true;
}

function validateForm ( form ) {
   for ( var e = 0; e < form.elements.length; e ++ ) {
      var el = form.elements [ e ];
      if ( el.type == 'text' || el.type == 'textarea' || 
         el.type == 'password' || el.type == 'file' ) {
         // check text fields
         if ( el.value == '' ) {
            alert ( 'Please fill out the ' + el.name + ' field' );
            el.focus ( );
            return false;
         }
      }
      else if ( el.type.indexOf ( 'select' ) != -1 ) {
         // check selectable dropdown menus
         if ( el.selectedIndex == -1 ) {
            alert ( 'Please select a value for ' + el.name );
            el.focus ( );
            return false;
         }
      }
      else if ( el.type == 'radio' ) {
         // check radio button groups
         var group = form [ el.name ];
         var checked = false;
         if ( !group.length ) checked = el.checked;
         else
            for ( var r = 0; r < group.length; r ++ )
               if ( ( checked = group [ r ].checked ) )
            break;
         if ( !checked ) {
            alert ( 'Please check one of the ' + 
            el.name + ' buttons' );
            el.focus ( );
            return false;
         }
      }
      else if ( el.type == 'checkbox' ) {
         // check checkbox groups
         var group = form [ el.name ];
         if ( group.length ) {
            var checked = false;
            for ( var r = 0; r < group.length; r ++ )
               if ( ( checked = group [ r ].checked ) )
            break;
            if ( !checked ) {
               alert ( 'Please check one of the ' + 
               el.name + ' checkboxes' );
               el.focus ( );
               return false;
            }
         }
      }
   }
   return true;
}

function checkAnswers(form){
	var pass = true;
	var myArray = new Array();
	var index = 0;
	
	for ( var e = 0; e < form.elements.length; e ++ ) {
	  var el = form.elements [ e ];
	  if ( el.type == 'radio' ) {
		 myArray[index] = el.name;
		 index++;
	  }
	}
	for (var counter = 0; counter < myArray.length; counter++){
		if(! hasASelection(myArray[counter]) ){
			alert("Please select your answer");
			pass = false;
			break;
		}
	}
	
	return pass;
}

function hasASelection(groupName){
	var elms = document.getElementsByName(groupName);
	for(var k=0, elm;elm=elms[k];k++)
	if(elm.checked) return true;
	return false;
}






