// JavaScript Document function handleHttpResponse() { if (http.readyState == 4) { if(http.status==200) { var results=http.responseText; if(results<1) { alert('Sorry! The nickname already exists, try another name.') ; return false; } else if (results>0) { alert('Nick name has been saved. Thank you!'); document.form1.submit(); } } } } function getHTTPObject() { var xmlhttp; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); if (!xmlhttp){ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object function validate() { if(document.form1.fname.value=="") { alert("Name must be filled out!"); document.form1.fname.focus(); return false; } if(document.form1.sname.value=="") { alert("Surame must be filled out!"); document.form1.sname.focus(); return false; } var dt=document.form1.month.value + "/" + document.form1.date.value + "/" + document.form1.year.value; if (isDate(dt)==false) {return false;} if(document.form1.license.value=="") { alert("License must be filled out!"); document.form1.license.focus(); return false; } if(document.form1.phone0.value=="") { alert("Phone must be filled out!"); document.form1.phone0.focus(); return false; } else if (document.form1.phone0.value!="") { if(isNaN(document.form1.phone0.value)) { document.form1.phone0.value=''; alert("Enter numbers only"); document.form1.phone0.focus(); return false; } } if(document.form1.phone1.value=="") { alert("Phone must be filled out!"); document.form1.phone1.focus(); return false; } else if (document.form1.phone1.value!="") { if(isNaN(document.form1.phone1.value)) { document.form1.phone1.value=''; alert("Enter numbers only"); document.form1.phone1.focus(); return false; } } if(document.form1.email.value=="") { alert("Email must be filled out!"); document.form1.email.focus(); return false; } else if (document.form1.email.value!="") { if(!echeck(document.form1.email.value)) { document.form1.email.value=''; document.form1.email.focus(); return false; } } if(document.form1.add.value=="") { alert("Address must be filled out!"); document.form1.add.focus(); return false; } if(document.form1.suburb.value=="") { alert("Suburb must be filled out!"); document.form1.suburb.focus(); return false; } if(document.form1.zip.value=="") { alert("Postcode must be filled out!"); document.form1.zip.value=""; document.form1.zip.focus(); return false; } if(isNaN(document.form1.zip.value)) { alert("Enter Numericals for Postcode"); document.form1.zip.value=""; document.form1.zip.focus(); return false; } if(document.form1.university.value=="") { alert("University name must be filled out!"); document.form1.university.focus(); return false; } var c = 'order[]' ; if (radio(c, "Check your order!")==false) { document.getElementById('order').focus(); return false; } if(document.form1.knowledge.value=="") { alert("Select your knowledge"); document.form1.knowledge.focus(); return false; } if(document.form1.nominate.value=="") { alert("Nickname should be filled out!"); document.form1.nominate.focus(); return false; } else if (document.form1.nominate.value!="") { if(!duplicateName(document.form1.nominate.value)) { return false; } } return true; } //Ajax validation******************************************************* function duplicateName(name) { //document.getElementById(dName).style.visibility='visible'; //alert(name) ; http.open("GET", "duplicate_name.php?name="+name , true); http.onreadystatechange = handleHttpResponse; http.send(null); } //************************************************************************* function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1) { alert("Invalid email address") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { alert("Invalid email address") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { alert("Invalid email address") return false } if (str.indexOf(at,(lat+1))!=-1) { alert("Invalid email address") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { alert("Invalid email address") return false } if (str.indexOf(dot,(lat+2))==-1) { alert("Invalid email address") return false } if (str.indexOf(" ")!=-1) { alert("Invalid email address") return false } return true; } //date validation -------------------------------------- function isExpiryDate(month, year, alerttxt) { // alert(year); today = new Date(); expiry = new Date(year, month); //alert(expiry); if (today.getTime() > expiry.getTime()) { alert(alerttxt) return false; } else { //alert("success") return true; } } //--------------------------------------------------------- //------------------------------Date validation mm/dd/yyyy---------------- var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strMonth=dtStr.substring(0,pos1) var strDay=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ alert("The date format should be : mm/dd/yyyy") return false } if (isNaN(day) == true || strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ alert("Please enter a valid day") document.getElementById('fdate').value=""; document.getElementById('fdate').focus(); return false } if (isNaN(month) == true || strMonth.length<1 || month<1 || month>12){ alert("Please enter a valid month") document.getElementById('fmonth').value=""; document.getElementById('fmonth').focus(); return false } if (isNaN(year) == true || strYear.length != 4 || year==0 || yearmaxYear){ alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear) document.getElementById('fyear').value=""; document.getElementById('fyear').focus(); return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ alert("Please enter a valid date") return false } return true } //----------------------------------------------------- //for autotab ---------------------------------------------------- function autotab(current,to){ if (current.getAttribute && current.value.length==current.getAttribute("maxlength")) { to.focus() } } //----------------------------------------------------------------- //For radio boxes function radio(radname,alerttxt) { //alert(chkname); var inputs = document.getElementsByTagName("input"); a=0; for(var t = 0;t < inputs.length;t++){ if(inputs[t].type == "radio" && inputs[t].checked == true && inputs[t].name===radname) { a=1; } } //alert(a) ; if(a==0) { alert(alerttxt); return false ; }else { return true ; } } //-----------------------------------------------------------------