// JavaScript Document



function back() 
{
    history.go(-1);
}

function validateAdminLogin()
{
	if( document.frmAdminLogin.email.value=="" )
	{
		alert("Login email field can not be empty");
		document.frmAdminLogin.email.focus();
		return false;
	}
	if (!echeck(document.frmAdminLogin.email.value))
	{ 
		validity = false; 
		alert('Please enter valid email id!'); 
		frmAdminLogin.email.focus();
	   	return false;
	}
	if( document.frmAdminLogin.password.value=="" )
	{
		alert("Login password field can not be empty");
		document.frmAdminLogin.password.focus();
		return false;
	}
}

function ValidateNum(input,event)
{
	var keyCode = event.which ? event.which : event.keyCode;
	if((parseInt(keyCode)>=48 && parseInt(keyCode)<=57) || parseInt(keyCode)==46)
	{
		return true;
	}
	return false;
}

function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		//trace(lat)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
			
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
		if(lstr==ldot+1)
	    return false
 		 return true					
	}

function checkPassword()
{
 	if (document.getElementById('pass').value === document.getElementById('cpass').value)
	{ // Checks if theyre the same
		if(document.getElementById('pass').value.length < 8)
		{ // Checks for atleast 8 characters long
			alert("Password must be atleast 8 characters long");
			return false;
		}
	} 
	else 
	{
		alert("You must confirm your password.");
		return false;
	}
}
 
function validate_admin_type()
{
	if( document.frmAdminType.type.value=="" )
	{
		alert("Admin type can not be empty");
		document.frmAdminType.type.focus();
		return false;
	}
	if( document.frmAdminType.description.value=="" )
	{
		alert("Admin type description can not be empty");
		document.frmAdminType.description.focus();
		return false;
	}
}
  
function verify_email(email)
{
	//alert(email);
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      //document.myForm.time.value=xmlHttp.responseText;
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText=="TRUE")
			{
				document.getElementById('err_msg').style.display='block';
				document.getElementById('err_msg').innerHTML =  "Email ID Already Exists";
				document.frmMember.email.value='';
				document.getElementById('err_msg_avail').style.display='none';
				document.frmMember.email.focus();
			}
			else
			{
				document.getElementById('err_msg').style.display='none';
				document.getElementById('err_msg_avail').style.display='block';
				document.getElementById('err_msg_avail').style.display='Available';
				document.getElementById('err_msg').innerHTML =  "";
			}
	  }
    }

	var url="ajax.php?page=admUser&email=" + email;
	//alert(url);
	xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
  }


function verify_thought_event(str)
{ 
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      //document.myForm.time.value=xmlHttp.responseText;
			//alert(xmlHttp.responseText);
			 
				document.getElementById('idThought').style.display='block';
				document.getElementById('idThought').innerHTML =  xmlHttp.responseText; 
			 
	  }
    }

	var url="ajax.php?page=thought_event&str=" + str;
	//alert(url);
	xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
  }
