// JavaScript Document
function isNull(aStr)
{
   var index;
   for (index=0; index < aStr.length; index++)
		   if (aStr.charAt(index) != ' ')
				   return false;
   return true;
}

//For checking invalid E-Mail address

function isEmail(aStr)
       {
               var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/;
               if(!reEmail.test(aStr))
               {
                       return false;
               }
               return true;
       }
//----------------------------------------------------
// check Date between.
//----------------------------------------------------

 function days_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = (date2_ms - date1_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}

//----------------------------------------------------
// email validation 
//----------------------------------------------------

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					
	}

//----------------------------------------------------
// Check blanck E-mail Validatin 
//----------------------------------------------------

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

//----------------------------------------------------
// HTTP object for implemeting AJAX 
//----------------------------------------------------

function getHTTPObject() {

     var xmlhttp;

     xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");

    return xmlhttp;

 }

//----------------------------------------------------
// handling server response function 
//----------------------------------------------------

function checkAll(checkflag){
	
    obj =  document.details_form.elements["check[]"];
	
	
   if (checkflag == "true") {
	
	  for (i = 0; i < obj.length ; i++) {
	    	obj[i].checked = true;
	  }
   }
    else {
			for (i = 0; i <obj.length; i++) {
				obj[i].checked = false; 
	         }
	       
  }
	return true;
}




//----------------------------------------------------
// validating admin users
 //----------------------------------------------------
 function validate()
 {
  
		if(document.registationForm.nick_name.value=="")
		{
		 blank();
		  document.getElementById('nick_error').innerHTML="Enter the Nick Name";
		  document.registationForm.nick_name.focus();
		  return false
		}
		  if(document.registationForm.first_name.value=="")
		{
		 blank();
		  document.getElementById('first_error').innerHTML="Enter the First Name";
		  document.registationForm.first_name.focus();
		  return false
		}
		/*if(document.registationForm.first_name.value=="")
		{
		  alert("Enter the First Name");
		  document.registationForm.first_name.focus();
		  return false
		}
		if(document.registationForm.last_name.value=="")
		{
		  alert("Enter the Last Name");
		  document.registationForm.last_name.focus();
		  return false
		}*/
		if(document.registationForm.password.value=="")
		{
			blank();
		  document.getElementById('pass_error').innerHTML="Enter the Password";
		  document.registationForm.password.focus();
		  return false
		}
		if(document.registationForm.password.value.length <4 )
		{
		blank();
		  document.getElementById('pass_error').innerHTML="Enter your password at least 4 characters";
		  document.registationForm.password.focus();
		  return false
		}
	
		if(document.registationForm.password.value!=document.registationForm.con_password.value)
		{
		 blank();
		  document.getElementById('cpass_error').innerHTML="Enter the Same Password";
		  document.registationForm.con_password.focus();
		  return false
		}
		if(document.registationForm.email.value=="")
		{
		blank();
		    document.getElementById('email_error').innerHTML="Enter the  E-mail Address";
		  document.registationForm.email.focus();
		  return false
		}
		if(!isEmail(document.registationForm.email.value))
		{
			blank();
			document.getElementById('email_error').innerHTML="Please enter a valid E-mail Address";
		     document.registationForm.email.focus();
			return false;
		}
	/*	if(document.registationForm.birth_day.value=="")
		{
		  alert("Enter the Birth Day");
		  document.registationForm.birth_day.focus();
		  return false
		}
		if(document.registationForm.birth_month.value=="")
		{
		  alert("Enter the Birth month");
		  document.registationForm.birth_month.focus();
		  return false
		}
		if(document.registationForm.birth_year.value=="")
		{
		  alert("Enter the Birth Year");
		  document.registationForm.birth_year.focus();
		  return false
		}
		*/
		if(document.registationForm.country.value=="")
		{
		  blank();
		  document.getElementById('country_error').innerHTML="Select the Country";
		  document.registationForm.country.focus();
		  return false
		}
		if(document.registationForm.city.value=="Enter City Name")
		{
		  blank();
		  document.getElementById('country_error').innerHTML="Enter the City Name";
		  document.registationForm.city.focus();
		  return false
		}
		if(!document.registationForm.term.checked)
		{
			blank();
			document.getElementById('p_error').innerHTML="Please Check I agree to Jivelo terms of use and policy";
			 document.registationForm.term.focus();
			return false;
		}
		
		 return true;
}

function blank(){
	document.getElementById('p_error').innerHTML="";
	document.getElementById('country_error').innerHTML="";
	document.getElementById('email_error').innerHTML="";
	document.getElementById('cpass_error').innerHTML="";
	document.getElementById('pass_error').innerHTML="";
	document.getElementById('nick_error').innerHTML="";
	document.getElementById('first_error').innerHTML="";
	
}

<!------------------------------ Change Password validation----------------------------------->
function chkin()
{

	if(document.frmchngpass.txtOldPassword.value=="")
		{
			alert("Old Password cannot be Blank");
			document.frmchngpass.txtOldPassword.focus();
			return false;
		}	
	if(document.frmchngpass.txtNewPassword.value=="")
		{
			alert("New Password cannot be Blank");
			document.frmchngpass.txtNewPassword.focus();
			return false;
		}	
	
	return true;
}

/***************************/
function chechmail()
{
	if(isNull(document.formEmail.mess.value))
	{
		alert("!Please enter the Messages");
		document.formEmail.mess.focus();
		return false;
	}
	return true;
}

/*****************************  User login ***************************************/
function loginUser()
{
	
	if(isNull(document.loginform.email.value))
	{
		alert("Please enter E-mail id");
		document.loginform.email.focus();
		return false;
	}
	if(!isEmail(document.loginform.email.value))
	{
		alert("Please enter a valid e-mail id");
		document.loginform.email.focus();
		return false;
	}
	if(isNull(document.loginform.password.value))
	{
		alert("Please enter a  password");
		document.loginform.password.focus();
		return false;
	}
	return true;
}

/*****************************  User forgate Password ***************************************/
function forgetPass()
{
	if(!isEmail(document.forgetForm.email.value))
	{
		alert("Please enter a valid e-mail id");
		document.forgetForm.email.focus();
		return false;
	}
	if(document.forgetForm.email.value=="")
	{
		alert("Please enter a valid e-mail id");
		document.forgetForm.email.focus();
		return false;
	}	
	return true;
}
//--------------- Clear city filed -------------------------------------

function cityfieldnull()
	{
		if(document.registationForm.city.value=='Enter City Name' )
		{
			document.registationForm.city.value="";
		}
	}
	
/*****************************  My Experience ***************************************/
function checkExperience()
{
	if(document.form1.textfield1.value=="")
	{
		alert("Please enter the title name");
		document.form1.textfield1.focus();
		return false;
	}
	if(document.form1.fromDate.value=="")
	{
		alert("Please enter the day");
		document.form1.fromDate.focus();
		return false;
	}
	/*if(document.form1.month.value=="")
	{
		alert("Please enter the month");
		document.form1.month.focus();
		return false;
	}
	if(document.form1.year.value=="")
	{
		alert("Please enter the year");
		document.form1.year.focus();
		return false;
	}
	*/
	if(document.form1.textfield2.value=="")
	{
		alert("Please enter the Where did it happen?");
		document.form1.textfield2.focus();
		return false;
	}
	if(document.form1.textfield3.value=="")
	{
		alert("Please enter the Is this a");
		document.form1.textfield3.focus();
		return false;
	}
	if(document.form1.textarea1.value=="")
	{
		alert("Please enter the write your experience");
		document.form1.textarea1.focus();
		return false;
	}
	
	return true;
}