function formValidate(frm) { var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if(frm.username.value == "" && frm.action=='add') { alert("Please enter User Name"); frm.username.focus(); return false; } else if(frm.password.value == "" && frm.action=='add') { alert("Please specify Password"); frm.password.focus(); return false; } else if(frm.password.value != frm.cpassword.value) { alert("Password and Confirm Password Don't Match"); frm.password.focus(); return false; } else if(frm.flag.value==0 && frm.action=='add') { alert("Username Already Exists"); frm.user_name.focus(); return false; } else if(frm.full_name.value == "") { alert("Please enter Full Name"); frm.full_name.focus(); return false; } else if(frm.email.value == "") { alert("Please enter email"); frm.email.focus(); return false; } else if (!(filter.test(frm.email.value))) //This condition checks the valid email. { alert("Please Enter a Valid Email Address"); frm.email.focus(); return false; } else return true; } function checkAvailable(username) { if (window.XMLHttpRequest) http_request = new XMLHttpRequest(); else if (window.ActiveXObject) http_request = new ActiveXObject("Microsoft.XMLHTTP"); url ='http://www.reliancemotors.com.na/secure/actions/users.action.php?action=checkAvailable&username='+username; //window.open(url); try { http_request.open('GET', url,true); } catch(err){alert(err.toString());} http_request.onreadystatechange = handleResponseUsername; try { http_request.send(null); } catch(err){alert(err.toString());} } function handleResponseUsername() { var xmldoc = http_request.responseXML; if(http_request.readyState == 4 ) { if(xmldoc.getElementsByTagName('FLAG')[0].firstChild.data==1) { document.getElementById("msgAvl").innerHTML = 'Username Already Exisits' document.getElementById("flag").value = 0; } else if(xmldoc.getElementsByTagName('FLAG')[0].firstChild.data==0) { document.getElementById("msgAvl").innerHTML = 'Username Available' document.getElementById("flag").value = 1; } } } /* AJAX CALLING FUNCTION FOR POPULATING EDIT */ function editUser(id) { if (window.XMLHttpRequest) http_request = new XMLHttpRequest(); else if (window.ActiveXObject) http_request = new ActiveXObject("Microsoft.XMLHTTP"); url ='http://www.reliancemotors.com.na/secure/actions//users.action.php?action=edit&id='+id; // window.open(url); try { http_request.open('GET', url,true); } catch(err){alert(err.toString());} http_request.onreadystatechange = handleResponseUser; try { http_request.send(null); } catch(err){alert(err.toString());} } function handleResponseUser() { var xmldoc = http_request.responseXML; if(http_request.readyState == 4 ) { if(xmldoc.getElementsByTagName('user_id')[0].hasChildNodes()) document.getElementById("user_id").value = xmldoc.getElementsByTagName('user_id')[0].firstChild.data; else document.getElementById("user_id").value = ""; if(xmldoc.getElementsByTagName('username')[0].hasChildNodes()) document.getElementById("username").value = xmldoc.getElementsByTagName('username')[0].firstChild.data; else document.getElementById("username").value = ""; if(xmldoc.getElementsByTagName('full_name')[0].hasChildNodes()) document.getElementById("full_name").value = xmldoc.getElementsByTagName('full_name')[0].firstChild.data; else document.getElementById("full_name").value = ""; if(xmldoc.getElementsByTagName('email')[0].hasChildNodes()) document.getElementById("email").value = xmldoc.getElementsByTagName('email')[0].firstChild.data; else document.getElementById("email").value = ""; if(xmldoc.getElementsByTagName('designation')[0].hasChildNodes()) document.getElementById("designation").value = xmldoc.getElementsByTagName('designation')[0].firstChild.data; else document.getElementById("designation").value = ""; if(xmldoc.getElementsByTagName('phone')[0].hasChildNodes()) document.getElementById("phone").value = xmldoc.getElementsByTagName('phone')[0].firstChild.data; else document.getElementById("phone").value = ""; document.getElementById("username").disabled = true; document.getElementById("action").value = "update"; document.getElementById("button").value = "Update"; } }