// JavaScript Document   
function login_det_chk(ids)
{
	if(document.getElementById('login_for').value=='Employee')
	{
		$('#emp_log_det').show('slow').fadeIn('slow');
		$('#cli_log_det').hide('slow').fadeOut('slow');
	}
	else if(document.getElementById('login_for').value=='Client')
	{
		$('#cli_log_det').show('slow').fadeIn('slow');
		$('#emp_log_det').hide('slow').fadeOut('slow');
	}
}
function validat_log_det()
{	
	var letters1=/^[A-Za-z][A-Za-z0-9.\_\-\' ]+$/;
	
	if(document.getElementById('login_for').value=='')
	{
		alert('Please Select the Login Member');  
		document.getElementById('login_for').focus();  
		return false; 
	}
	if(document.getElementById('login_for').value=='Employee')
	{
		if(document.getElementById('emp_name').value=='')
		{
			alert('Please Select the Employee Name');  
			document.getElementById('emp_name').focus();  
			return false; 
		}
		if(document.getElementById('user_name').value=='')
		{
			alert('Please Enter the User Name ');  
			document.getElementById('user_name').focus();  
			return false; 
		}
		else if(letters1.test(document.getElementById('user_name').value)==false)  
		{
			alert('User Name must have Alphanumeric only');  
			document.getElementById('user_name').focus();  
			return false;  
		}	
	}
	else if(document.getElementById('login_for').value=='Client')
	{
		if(document.getElementById('cli_name').value=='')
		{
			alert('Please Select the Client Name');  
			document.getElementById('cli_name').focus();  
			return false; 
		}
		if(document.getElementById('cli_user_name').value=='')
		{
			alert('Please Enter the Client User Name ');  
			document.getElementById('cli_user_name').focus();  
			return false; 
		}
		else if(letters1.test(document.getElementById('cli_user_name').value)==false)  
		{
			alert('User Name must have Alphanumeric only');  
			document.getElementById('cli_user_name').focus();  
			return false;  
		}	
	}
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(document.getElementById('login_for').value=='Employee')
	{
		var user_name1=document.getElementById('user_name').value;
		var log_val='Employee';
		var foc_val=document.getElementById('user_name');
	}
	else if(document.getElementById('login_for').value=='Client')
	{
		var user_name1=document.getElementById('cli_user_name').value;
		var log_val='Client';
		var foc_val=document.getElementById('cli_user_name');
	}
	//alert("karun");
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{			
			//document.getElementById("si"+ival).innerHTML=xmlhttp.responseText;
			var responseText = xmlhttp.responseText;						
			//alert(responseText);
			if(responseText==0)
			{
				alert("This User Name Already Exist");
				foc_val.focus();
			} 
			else
			{
				var where_to= confirm("Do you really want to Submit the Data?");
				if (where_to== true)
				{
					document.login_det.submit();
				}
				else
				{
					return false;	
				}
			}				
		}
	}				
	var queryString='?u_name='+user_name1+'&lo_val='+log_val;
	//alert(queryString);				
	xmlhttp.open("GET","ajax/user_name_check_AJAX.php"+queryString,true);
	xmlhttp.send();
}

function form_rest() //this is for reset the forms
{
	var where_to= confirm("Do you really want to Reset the Data?");
	if (where_to== true)
	{
		window.location.reload();
	}
	else
	{
	 	return false;	
	}
}
function des_change(ids)
{
	//alert (ids);
	if (ids=="")
	{		
		return;
	} 
	else if(ids==1)
	{
		var val_det=document.getElementById('emp_name').value;
	}
	else if(ids==2)
	{
		var val_det=document.getElementById('cli_name').value;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var result=xmlhttp.responseText;
			//alert(result);
			if(ids==1)
			{				
				var detail_val=result.split("split_1");			
				document.getElementById("designation").value=detail_val[0];
				document.getElementById("email_id").value=detail_val[1];
			}
			else if(ids==2)
			{
				document.getElementById("cli_email_id").value=result;
			}
		}
	}
	var queryString="?ival="+ids+'&id_val='+val_det; 
	//alert(queryString);
	xmlhttp.open("GET","ajax/designation_get_AJAX.php"+queryString,true);
	xmlhttp.send();
}

function validat_mail()
{
	var mail = /(([a-zA-Z0-9\-?\.?]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})(\W?[,;]\W?(?!$))?)+$/i;
	if(document.getElementById("mail_id").value == '')
	{
		alert("Please Enter the Mail id's");
		document.getElementById("mail_id").focus();
		return false;
	}
	else if(document.getElementById("mail_id").value != '')
	{
		if(mail.test(document.getElementById('mail_id').value)==false)  
		{
			alert("Please Enter the Correct Mail ID's");  
			document.getElementById('mail_id').focus();  
			return false;  
		}	
	}
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.mail_det.submit();
	}
	else
	{
		return false;	
	}
}