<!--
function Validate(frm) {
		if (frm){
			iCount = frm.length 
			for(iPos=0;iPos < iCount;iPos++){
				obj = frm.elements[iPos]
				
				if ( (obj.lang != null) && (obj.lang == 'y')  ){
					if (obj.value.length < 1){
						alert(obj.name + " is required.");
						obj.focus();
						return false;
					}
				}
			}
			
		}
		else{
			alert("Failed to set form");
			return false;
		}
		
	    if (frm.email){
		    if (emailCheck(frm.email.value)==false) {
		            frm.email.focus();
		            return false;
		    }
	    }
	  //      if (phoneValidation(frm.phone.value)==false) {
	  //              frm.phone.focus();
	  //              return false;
	  //      }

		if (frm.requestType){
			switch (frm.requestType.value)
			{
			case "Demo Request":
			  frm.comment.value = frm.requestType.value + "ed for " + frm.company.value
			  frm.emailTo.value = "sales"
			  break
			case "Registration Request":
			  frm.comment.value = frm.requestType.value + "ed for " + frm.company.value
			  frm.emailTo.value = "sales"
			  break
			case "Download Request":
			  frm.comment.value = frm.requestType.value + "ed for " + frm.company.value
			  frm.emailTo.value = "sales"
			  break
			case "Sales":
			  frm.emailTo.value = "sales"
			  break
			case "Partner":
			  frm.emailTo.value = "marketing"
			  break
			case "Support":
			  frm.emailTo.value = "support"
			  break
			case "Jobs":
			  frm.emailTo.value = "dnetcareers"
			  break
			case "Other":
			  frm.emailTo.value = "sales"
			  break
			case "survey_070918":
			  break
			default:
			  frm.emailTo.value = "sales"
			  break
			}
		}


//	alert(frm.email.value + "/n" + frm.requestType.value);

		// special processing to go to "bad login" path if no login servlet available. only if "tester2@desknetinc.com" is entered.
		if ((frm.email) && (frm.failurePage) && (frm.email.value == "tester2@desknetinc.com")){
    		frm.returnPage.value = frm.failurePage.value
        }

 	    if (location.hostname){
            if (frm.returnPage.value.substr(0, 4) != "http") {  // make sure the return page is fully qualified
            	frm.returnPage.value=location.href.substr(0, location.href.lastIndexOf("/") + 1) + frm.returnPage.value;
            }
 	    	if (location.hostname.indexOf("desknetinc.com") != -1) {
	            if ((location.href.toLowerCase().indexOf("www-staging") != -1) && (frm.action.substr(frm.action.length - 4, 4) != "test")) { // if we're in staging call the test servlet
	            	frm.action = frm.action + "test";
	            }
			}else{  // looks like it's running from someplace remote... just go to the thankyou page
	        	if (auditForm(frm)){
            		window.location = frm.returnPage.value
        			return false;
	            }else{
          			return false;
            	}
		    }
		}else{  // looks like it's running from a local file since there is no server info... just go to the thankyou page
        	if (auditForm(frm)){
        		window.location = frm.returnPage.value
    			return false;
            }else{
        		return false;
        	}
	    }

        
        if (frm.email.value == "tester@desknetinc.com"){
        	return auditForm(frm);
        }
        
		return true;
	}
	
function auditForm (frm){
    var msg="";
	iCount = frm.length 
	for(iPos=0;iPos < iCount;iPos++){
		obj = frm.elements[iPos]
		if ((obj.name != null) && (obj.type != "checkbox")){
			if (obj.value.length > 0) msg = msg + obj.name + "=" + obj.value + "\n"
		}
	}
	if (confirm("location.hostname=" + location.hostname + "\n" + "formAction=" + frm.action + "\n" + "location.href=" + location.href + "\n\n" + msg)){
		return true;
	}else{
		return false;
	}
}

function emailCheck (emailStr) {

		emailStr = emailStr.toLowerCase();

        var checkTLD=1;
        var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
        var emailPat=/^(.+)@(.+)$/;
        var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
        var validChars="\[^\\s" + specialChars + "\]";
        var quotedUser="(\"[^\"]*\")";
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
        var atom=validChars + '+';
        var word="(" + atom + "|" + quotedUser + ")";
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
        var matchArray=emailStr.match(emailPat);
        if (matchArray==null) {
                alert("Invalid Email Format ");
                return false;
        }
        var user=matchArray[1];
        var domain=matchArray[2];
        for (i=0; i<user.length; i++) {
                if (user.charCodeAt(i)>127) {
                        alert("Ths username contains invalid characters.");
                        return false;
                }
        }
        for (i=0; i<domain.length; i++) {
                if (domain.charCodeAt(i)>127) {
                        alert("Ths domain name contains invalid characters.");
                        return false;
                }
        }
        if (user.match(userPat)==null) {
                alert("The username doesn't seem to be valid.");
                return false;
        }
        var IPArray=domain.match(ipDomainPat);
        if (IPArray!=null) {
                for (var i=1;i<=4;i++) {
                        if (IPArray[i]>255) {
                                alert("Destination IP address is invalid!");
                                return false;
                        }
                }
                return true;
        }
        var atomPat=new RegExp("^" + atom + "$");
        var domArr=domain.split(".");
        var len=domArr.length;
        for (i=0;i<len;i++) {
                if (domArr[i].search(atomPat)==-1) {
                        alert("The domain name does not seem to be valid.");
                        return false;
                }
        }
        if (checkTLD && domArr[domArr.length-1].length!=2 && 
                domArr[domArr.length-1].search(knownDomsPat)==-1) {
                        alert("The address must end in a well-known domain or two letter " + "country.");
                        return false;
        }
        if (len<2) {
                alert("This address is missing a hostname!");
                return false;
        }
        return true;
  }

function phoneValidation(phone) {
        var matchArr = phone.match(/^(\d{3})-?\d{3}-?\d{4}$/);
        var numDashes = phone.split('-').length - 1;
        
        if (matchArr == null || numDashes == 1) {
                alert('Invalid Phone. Must be 10 digits or in the form NNN-NNN-NNNN.');
                return false;
        }else if (parseInt(matchArr[1],11)==0) {
                alert("Invalid Phone: Phone number's can't start with 000.");
                return false;
        }
        
        return true;
  }
  
function ManageMultiSelect(fromFld, toFld) {
//alert("fromFld=" + fromFld.name + "  value=" + fromFld.value + "\ntoFld=" + toFld.name + "  value=" + toFld.value);
	if ((fromFld.type == "checkbox") || (fromFld.type == "radio")){
		var pos = toFld.value.indexOf(fromFld.value);
		if (fromFld.checked){ // need to make sure it's in the list
			if (pos == -1){ // field is not in the list, add it
				if (toFld.value.length != 0){ // only add the preceding comma if the list is not empty
					toFld.value = toFld.value + ",";
				}
				toFld.value = toFld.value + fromFld.value;
			}else{ // field is in the list
				// it's already there.
			}
		
		}else{ //need to make sure it's not in the list
			if (pos == -1){ // field is not in the list
				// it's already not there.
			}else{ // field is in the list, remove it
				toFld.value = toFld.value.substr(0, pos) + toFld.value.substr(pos + fromFld.value.length)
				toFld.value = toFld.value.replace(",,",",") // remove double commas
				if (toFld.value.substr(0, 1) == ","){ //remove leading comma
					toFld.value = toFld.value.substr(1)
				}
				if (toFld.value.substr(toFld.value.length - 1, 1) == ","){ //remove trailing comma
					toFld.value = toFld.value.substr(0, toFld.value.length -1)
				}
			}
		}
	}
}


window.document.onmousedown = ProcessMouseClick;
function ProcessMouseClick(e){
  //* This code is in here to make testing easier. 
  //* Put an x in the name field and then right click, everything gets filled in.  
  //* I really hate typing things over and over.

        if (event.button == 2 || event.button == 3)
        {
                var frm = document.forms[0];
                if (frm.first_name.value == "x")
                        {
                               	if (frm.salutation) frm.salutation.value="Prof.";
                                if (frm.first_name) frm.first_name.value="Website";
                                if (frm.last_name) frm.last_name.value="Tester";
                                if (frm.jobtitle) frm.jobtitle.value="Brewmaster";
                                if (frm.company) frm.company.value="DeskNet Inc.";
                                if (frm.street) frm.street.value="10 Exchange Place, 20th Floor";
                                if (frm.city) frm.city.value="Jersey City";
                                if (frm.state) frm.state.value="NJ";
                                if (frm.zip) frm.zip.value="07302";
                                if (frm.email) frm.email.value="tester@desknetinc.com";
                                if (frm.phone) frm.phone.value="123-456-7890";
                                if (frm.comment) frm.comment.value="This stuff is GREAT!!! How can I sign up?";
                                if ((frm.requestType) && (frm.requestType.req != null)) frm.requestType.value="Other";
                                if (frm.prefDateTime) frm.prefDateTime.value="Tuesday Morning.";
                                if (frm.question1) frm.question1.value="5";
                                if (frm.question2) frm.question2.value="5";
                                if (frm.question3) frm.question3.value="5";
                                if (frm.question4) frm.question4.value="5";
                                if (frm.question5) frm.question5.value="5";
                                if (frm.question6) frm.question6.value="5";
                                if (frm.question7) frm.question7.value="5";
                                if (frm.question8) frm.question8.value="5";
                                if (frm.question9) frm.question9.value="5";
                                if (frm.q1_comments) frm.q1_comments.value="comments...";
                                if (frm.q2_comments) frm.q2_comments.value="comments...";
                                if (frm.q3_comments) frm.q3_comments.value="comments...";
                                if (frm.q4_comments) frm.q4_comments.value="comments...";
                                if (frm.q5_comments) frm.q5_comments.value="comments...";
                                if (frm.q6_comments) frm.q6_comments.value="comments...";
                                if (frm.q7_comments) frm.q7_comments.value="comments...";
                                if (frm.q8_comments) frm.q8_comments.value="comments...";
                                if (frm.q9_comments) frm.q9_comments.value="comments...";
                                if (frm.q10_comments) frm.q10_comments.value="comments...";
                                if (frm.q11_comments) frm.q11_comments.value="comments...";
                                return false;
                        }
        }
  return(true);
  }
  -->
