// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//Rjs debugger
Ajax.Responders.register({
  // log the beginning of the requests
  onCreate: function(request, transport) {
    new Insertion.Bottom('debug', '<p><strong>[' + new Date().toString() + '] accessing ' + request.url + '</strong></p>')
  },

  // log the completion of the requests
  onComplete: function(request, transport) {
    new Insertion.Bottom('debug', 
    '<p><strong>http status: ' + transport.status + '</strong></p>' +
    '&lt;pre>' + transport.responseText.escapeHTML() + '&lt;/pre>')
  }
});

  // JavaScript Document
function basic_validate()
{   
    var fname=document.getElementById('member_info_first_name').value
    var lname=document.getElementById('member_info_last_name').value
    var uname=document.getElementById('member_user_name').value  
    var password=document.getElementById('member_password').value      
    var cpassword=document.getElementById('member_password_confirmation').value   
    var mail=document.getElementById('member_info_mail_id').value   
    if(fname=="" || fname==" ")//validate the Name
	{
		alert("Enter First Name");
		document.getElementById('member_info_first_name').focus();
		return false;
	}

	if (fname.length > 0)
	{
		var ch=0;
		u=0;
		for (i=0;i<fname.length;i++)
		{
				if ((fname.charCodeAt(i) >= 65 && fname.charCodeAt(i) <= 90)||(fname.charCodeAt(i) >= 97 && fname.charCodeAt(i) <= 122)|| fname.charCodeAt(i) == 32|| fname.charCodeAt(i) == 46)
				{
				}
				else
				{
					u=u+1;
				}
				
		}
	}
	if (u>0)
	{
	alert ("Enter Only Text in First Name");
	document.getElementById('member_info_first_name').focus();
	return false;
	} 

    if(lname=="" || lname==" ")//validate the Name
	{
		alert("Enter Last Name");
		document.getElementById('member_info_last_name').focus();
		return false;
	}

	if (lname.length > 0)
	{
		var ch=0;
		u=0;
		for (i=0;i<lname.length;i++)
		{
				if ((lname.charCodeAt(i) >= 65 && lname.charCodeAt(i) <= 90)||(lname.charCodeAt(i) >= 97 && lname.charCodeAt(i) <= 122)|| lname.charCodeAt(i) == 32|| lname.charCodeAt(i) == 46)
				{
				}
				else
				{
					u=u+1;
				}
				
		}
	}
	if (u>0)
	{
	alert ("Enter Only Text in Last Name");
	document.getElementById('member_info_last_name').focus();
	return false;
	} 


    if(uname=="" || uname==" ")//validate the Name
	{
		alert("Enter Last Name");
		document.getElementById('member_user_name').focus();
		return false;
	}
    if(password=="" || password==" ")
	{
		alert("Enter Password");
		document.getElementById('member_password').focus();
		return false;
	}
	if(cpassword != "")
	{
        if(password != cpassword )
    	{
    		alert("Enter Password and Confirm Password is not equal");
    		document.getElementById('member_password_confirmation').focus();
    		return false;
    	}	
	}	
if( mail == "")//validate the mail
{
	alert ("Enter your Email Address");
	document.getElementById('member_info_mail_id').focus();
	return false;
}
else
{
at_pos=mail.indexOf("@")
dot_pos=mail.indexOf(".")
if(mail.charAt(at_pos-1)==".")
{
	alert("Enter Valid  Email Address")
	document.getElementById('member_info_mail_id').focus();
	return false;
}

if(mail.charAt(at_pos+1)==".")
{
	alert("Enter Valid  Email Address")
	document.getElementById('member_info_mail_id').focus();
	return false;
}
if(mail.charAt(at_pos+1)=="")
{
	alert("Enter Valid  Email Address")
	document.getElementById('member_info_mail_id').focus();
	return false;
}
if(mail.charAt(dot_pos+1)=="")
{
	alert("Enter Valid  Email Address");
	document.getElementById('member_info_mail_id').focus();
	return false;
}
if(mail.charAt(mail.length-1)==".")
{
	alert("Enter Valid  Email Address");
	document.getElementById('member_info_mail_id').focus();
	return false;
}

if(at_pos<1 || dot_pos<1)
{
	alert("Missing '@' and '.' in  Email Address")
	document.getElementById('member_info_mail_id').focus();
	return false;
}
else
{
	u=0;
	p=0;
	q=0;
	
	for(var i=0;i<mail.length;i++)
	{
		if ((mail.charCodeAt(i) >= 64 && mail.charCodeAt(i) <= 90)||(mail.charCodeAt(i) >= 97 && mail.charCodeAt(i) <= 122)||(mail.charCodeAt(i) >= 48 && mail.charCodeAt(i) <= 57)||(mail.charCodeAt(i)==95)||(mail.charCodeAt(i)==46))
		{
		if(mail.charAt(i)=="@")
		{
		p=p+1
		}
		if(i > at_pos )
		{
		if(mail.charAt(i) == ".")
		{
		q=q+1	
		}
		}
	}
	else
	{
		u=u+1
	}
	}
	if(q==0)
	{
		alert("Enter Valid  Email Address");
		document.getElementById('member_info_mail_id').focus();
		return false;
	}
	if (p>1)
	{
		alert (" Email Address must have only one '@'")
		document.getElementById('member_info_mail_id').focus();
		return false;
	}

	if (u>0)
	{
		alert ("Special Characters are not allowed")
		document.getElementById('member_info_mail_id').focus();
		return false;
	}
	}
} 
return true;
}