// JavaScript Document

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 E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}
	
function useradd(){
var emailID=document.userformadd.email;

if (document.userformadd.fullname.value==""){
	alert("Please Enter User FullName.");
	userformadd.fullname.focus();
	return false;
}

if (document.userformadd.uid.value==""){
	alert("Please Enter UserID.");
	userformadd.uid.focus();
	return false;
}
if (document.userformadd.pwd.value==""){
	alert("Please Enter User Password.");
	userformadd.pwd.focus();
	return false;
}
if (document.userformadd.email.value==""){
	alert("Please Enter User Email.");
	userformadd.email.focus();
	return false;
}
if (echeck(emailID.value)==false){
	
		emailID.value="";
		emailID.focus();
		return false;
	}
if (document.userformadd.actype.value==""){
	alert("Please Enter User Account Type.");
	userformadd.actype.focus();
	return false;
}
if (document.userformadd.actype.value==1){
	if (document.userformadd.exdate.value==""){
	alert("Please Select Account Expire Date.");
	userformadd.exdate.focus();
	return false;
	}
}
///
var flag=0;
		
		for(i=1;i<=8;i++){
			if(eval("document.userformadd.chk"+i)){
				if(eval("document.userformadd.chk"+i).checked==true){
				flag=i;
				break;
				}
			}	
		}
		//alert("me2"+flag);
		/* This is changed very recently
		if(flag==0){
			alert("Please select Module Permission");
			return false;
			}
			*/
///
/*if((document.userformadd.chk1) && (document.userformadd.chk2) && (document.userformadd.chk3) && (document.userformadd.chk4)){

	if(document.userformadd.chk1.checked==false && document.userformadd.chk2.checked==false && document.userformadd.chk3.checked==false && document.userformadd.chk4.checked==false){
		alert("Please Select Module Permission");
		//userformadd.chk1.focus();
		return false;
	}
}else if((document.userformadd.chk1) && !(document.userformadd.chk2)){

	if(document.userformadd.chk1.checked==false){
		alert("Please Select Module Permission");
		//userformadd.chk1.focus();
		return false;
	}
}else if(!(document.userformadd.chk1) && (document.userformadd.chk2)){

	if(document.userformadd.chk2.checked==false){
		alert("Please Select Module Permission");
		//userformadd.chk1.focus();
		return false;
	}
}else{
	alert("No Module to Show.Can't create User");
	
		return false;
}
/*if(document.userformadd.chk1){
	if(document.userformadd.chk1.checked==true){
		if (document.userformadd.chk11.checked==false && document.userformadd.chk12.checked==false ){
			alert("Please Select Module Related Permission");
			userformadd.chk11.focus();
			return false;
		}
	}
}*/
return true;
}

function useredit(){
var emailID=document.userform.email;

if (document.userform.fullname.value==""){
	alert("Please Enter User FullName.");
	userform.fullname.focus();
	return false;
}

if (document.userform.uid.value==""){
	alert("Please Enter UserID.");
	userform.uid.focus();
	return false;
}
if (document.userform.pwd.value==""){
	alert("Please Enter User Password.");
	userform.pwd.focus();
	return false;
}
if (document.userform.email.value==""){
	alert("Please Enter User Email.");
	userform.email.focus();
	return false;
}
if (echeck(emailID.value)==false){
	
		emailID.value="";
		emailID.focus();
		return false;
	}
if (document.userform.actype.value==""){
	alert("Please Enter User Account Type.");
	userform.actype.focus();
	return false;
}
if (document.userform.actype.value==1){
	if (document.userform.exdate.value==""){
	alert("Please Select Account Expire Date.");
	userform.exdate.focus();
	return false;
	}
}
return true;
}
function logincheck(){
	if(document.frmlogin.auid.value==""){
		alert("Please Enter UserName");
		frmlogin.auid.focus();
		return false;
	}
	if(document.frmlogin.apwd.value==""){
		alert("Please Enter Password");
		frmlogin.apwd.focus();
		return false;
	}
	
	if(document.getElementById('captcha').value == "") {
		alert("OOPs !! Please Enter Verification Code");
		document.getElementById('captcha').focus();
		return false;
	}
		
	if(document.getElementById('cap_code').value != document.getElementById('captcha').value) {
		alert("OOPs !! Verification Code Mismatch");
		document.getElementById('captcha').focus();
		return false;
	}	

return true;
}


 
 function opendetail(idField){
        var stdOptions = "resizable=yes,directories=no,left=10,top=10,toolbar=no,status=no,location=no,menubar=no";
		var url = "user_detail.php?uid=" + idField ; 
        var options = stdOptions + ",width=550,height=450,scrollbars=yes"; 
		window.open(url,"ModificationDetail",options); 
}