	function verify_element(elem, msg, numeric) {
		if (elem.type != null) {
			lType = elem.type;
			lFocus = elem;
		} else {
			lType = elem[0].type;
			lFocus = elem[0];
		}
		valid = true;

		switch (lType) {
			// Text fields
			case "text":
			case "textarea":
				if (elem.value == "") {valid=false;}
				if (numeric && isNaN(parseInt(elem.value))) (valid=false);  // test to see if value is a number
				break;

			// Drop-down validation, Assume first option is "Please select from List"
			case "select-one":
			case "select-multiple":
				if (elem.selectedIndex == 0) {valid=false;}
				break;

			// Checkbox validation
			case "checkbox":
				valid = false;
				if (elem.length == null) {
					if (elem.checked) {
						valid = true;
					}
				}
				else {
					for (counter = 0; counter < elem.length; counter++) {
						if (elem[counter].checked) {
							valid = true;
						}
					}
				}
				break;
		
			// Radio validation
			case "radio":
				valid = false;
				if (elem.length == null) {
					if (elem.checked) {
						valid = true;
					}
				}
				else {
					for (counter = 0; counter < elem.length; counter++) {
						if (elem[counter].checked) {
							valid = true;
						}
					}
				}
				break;
		}

		if (!valid) {
			alert(msg);
			lFocus.focus();
			lRet = false;
		} else {
			lRet = true;
		}

		return lRet;
	}

	function email_check(elem) {

		var str=elem.value;
		lFocus = elem;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
			lFocus.focus();
		   	alert("Invalid E-mail ID")
		   	return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			lFocus.focus();
		   	alert("Invalid E-mail ID")
		   	return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			lFocus.focus();
		    	alert("Invalid E-mail ID")
		    	return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			lFocus.focus();
		    	alert("Invalid E-mail ID")
		    	return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			lFocus.focus();
		    	alert("Invalid E-mail ID")
		    	return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			lFocus.focus();
		    	alert("Invalid E-mail ID")
		    	return false
		 }
		
		 if (str.indexOf(" ")!=-1){
			lFocus.focus();
		    	alert("Invalid E-mail ID")
		    	return false
		 }

 		 return true					
	}

	function email_samecheck(elem1, elem2) {
		var str1 = elem1.value;
		var str2 = elem2.value;
		lFocus = elem2;
		if (str1.toLowerCase() == str2.toLowerCase()) {
			lFocus.focus();
			alert("Please input correct referral E-mail")
		    	return false
		}

 		return true					
	}

	function showNextByRadioBtn (elem1,elem2) {
		var counter = 0;
		var fillin = 0;
		divItem = document.getElementById(elem2);
		if (elem1 == 'q1') {
			for (i = 0; i < document.survey_form.q1_home.length; i++) {
				if (document.survey_form.q1_home[i].checked) {
					counter++; 
					break;
				}
			}
                	for (i = 0; i < document.survey_form.q1_work.length; i++) {
                        	if (document.survey_form.q1_work[i].checked) {
                                	counter++;
                                	break;
                        	}
                	}
                	for (i = 0; i < document.survey_form.q1_car.length; i++) {
                        	if (document.survey_form.q1_car[i].checked) {
                               		counter++;
                                	break;
                        	}
                	}
			if (counter >= 3) {
				divItem.style.display = "block"; 
			}

		} else if (elem1 == 'q2') {
                        for (i = 0; i < document.survey_form.q2_home.length; i++) {
                                if (document.survey_form.q2_home[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
                        for (i = 0; i < document.survey_form.q2_work.length; i++) {
                                if (document.survey_form.q2_work[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
                        for (i = 0; i < document.survey_form.q2_car.length; i++) {
                                if (document.survey_form.q2_car[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
                        if (counter >= 3) {
                                divItem.style.display = "block";
                        }

		} else if (elem1 == 'q3') {
                        for (i = 0; i < document.survey_form.q3_op.length; i++) {
                                if (document.survey_form.q3_op[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
			if (trim(document.survey_form.q3_other.value) != '') {
				document.survey_form.q3_op[document.survey_form.q3_op.length-1].checked = true;
                               	divItem.style.display = "block";
                        } else if (counter >= 1 && !document.survey_form.q3_op[document.survey_form.q3_op.length-1].checked) {
                               	divItem.style.display = "block";
                		document.survey_form.q3_other.value = '';
                        }
		} else if (elem1 == 'q4') {
                        for (i = 0; i < document.survey_form.q4_op.length; i++) {
                                if (document.survey_form.q4_op[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
                        if (counter >= 1) {
                                divItem.style.display = "block";
				document.survey_form.q5_number.focus();
                        }
		} else if (elem1 == 'q7') {
                        for (i = 0; i < document.survey_form.q7_op.length; i++) {
                                if (document.survey_form.q7_op[i].checked) {
                                        counter++;
                                        break;
                                }
                        }
                        if (counter >= 1) {
                                divItem.style.display = "block";
				document.survey_form.q8_answer.focus();
                        }
		}


	}

	function showNextByRadioBtnAndInput (elem1,elem2) {
		if (elem1 == 'q3' && elem2 == '') {
			document.survey_form.q3_other.focus();
		} else {
			divItem = document.getElementById(elem2);
		}

                if (elem1 == 'q3' && trim(document.survey_form.q3_other.value) != '') {
			document.survey_form.q3_op[document.survey_form.q3_op.length-1].checked = true;
                        divItem.style.display = "block";
		}
	}

	function showNextByInput (elem1,elem2,elem3) {
                divItem = document.getElementById(elem2);

                if (elem1 == 'q5') {
                	var number = parseInt(document.survey_form.q5_number.value);
                	if (number == 0 || isNaN(number)) {
				divItem.style.display = "block";
				document.survey_form.q6_answer.focus();
                                divItem = document.getElementById('q7');
                                divItem.style.display = "none";
                                divItem = document.getElementById('q8');
                                divItem.style.display = "none";
                                divItem = document.getElementById('q9');
                                divItem.style.display = "none";
				document.survey_form.q10_answer.value = '';
                                divItem = document.getElementById('q10');
                                divItem.style.display = "none";
                		divItem = document.getElementById('submit_key');
                                divItem.style.display = "none";
			} else if (!isNaN(number) && number > 0) {
                		divItem = document.getElementById(elem3);
				divItem.style.display = "block";
                		divItem = document.getElementById('q6');
				divItem.style.display = "none";
				document.survey_form.q10_answer.value = '';
                		divItem = document.getElementById('q10');
				divItem.style.display = "none";
                		divItem = document.getElementById('submit_key');
				divItem.style.display = "none";
			}
		} else if (elem1 == 'q6' && trim(document.survey_form.q6_answer.value) != '') {
			divItem.style.display = "block";
			document.survey_form.q10_answer.focus();
		} else if (elem1 == 'q8' && trim(document.survey_form.q8_answer.value) != '') {
                        divItem.style.display = "block";
			document.survey_form.q9_answer.focus();
                } else if (elem1 == 'q9' && trim(document.survey_form.q9_answer.value) != '') {
                        divItem.style.display = "block";
			document.survey_form.q10_answer.focus();
                } else if (elem1 == 'q10' && document.survey_form.q10_answer.value.length == 3) {
                        divItem.style.display = "block";
                }
	}

	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}

	function RTrim( value ) {
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}

	function trim( value ) {
		return LTrim(RTrim(value));
	}
