﻿// JScript File

function validateForm(theForm){
var elmstr = "";
var digits = "0123456789";
var failed = 0;

if(theForm.cname.value==""){alert('Please enter your name');theForm.cname.focus();return false;};

//email
if (theForm.email.value == "") {
	alert("Please enter Your Email Address!");
	theForm.email.focus();
	return false;
}

elmstr = theForm.email.value + "";
if (elmstr.indexOf("@") == "-1" || elmstr.indexOf(".") == "-1" || elmstr == "" || (elmstr.charAt((elmstr.length - 4)) != "." && elmstr.charAt((elmstr.length - 3)) != ".") || elmstr.length < 6 || elmstr.charAt(elmstr.indexOf("@") + 1) == ".") {
failed = 1;
if (failed == 1){
alert("Please enter a valid Email Address!");
return false;
}
}


//phone
if (theForm.phone.value !="") {
elmstr = theForm.phone.value + "";
if (elmstr.length != 12){
	failed = 1;
	}
    for (var i = 0; i < elmstr.length; i++) {
		if ((i < 3 && i > -1) || (i > 3 && i < 7) || (i > 7 && i < 12)) {
            if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9"){
			failed = 1;
			}
		}	else if (elmstr.charAt(i) != "-"){
			failed = 1;
		}
	}
if (failed == 1){
	alert("Please enter your Phone Number in ###-###-#### format!");
	theForm.phone.focus();
	return false;
}
}

//alert(theForm.ostype[theForm.ostype.length-1].checked);

if(theForm.ostype[theForm.ostype.length-1].checked && theForm.ostype_other.value=="") {
		alert("you selected 'other' for operating system\nbut didn't specify what it was");
		theForm.ostype_other.focus();
		return false;
		};

var anyChecked = false
for (var i = 0; i < theForm.ostype.length; i++) {
	if (theForm.ostype[i].checked) {
		anyChecked = true
		};
	};
	if (!anyChecked) {
	alert("Please check off one box corresponding to your operating system");
	return false;
	};
	

}

function showOther(theObj){
if (theObj.checked) 
    {ShowContent('otherField');}
    else
        {HideContent('otherField');}
}

function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "inline";
}
