function getHTTPObject()
	{
		 var xmlhttp;
		 try
		 {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		 }
		 catch (e)
		 {
			  try
			  {
				   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  }
			  catch (E)
			  {
				   xmlhttp = false;
			  }
		 }
	
		 if ( ! xmlhttp && typeof XMLHttpRequest != 'undefined')
		 {
			  try
			  {
				   xmlhttp = new XMLHttpRequest();
			  }
			  catch (e)
			  {
				   xmlhttp = false;
			  }
		 }
		 return xmlhttp;
	}
	
	function trim(stringToTrim) 
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
		
	function nullvalue(val1,val2)
	{
		//alert(val1);
		//alert(val2);
		var value1=new Array();
		value1 = val1.split("!");
		value2 = val2.split("!");
		var alt = "";
		for(i=1 ; i< value1.length ; i++)
		{
			var x = document.forms[value1[0]].elements[value1[i]].value;
			a = x.length;
				 
			for(j=0;j< x.length;j++)
			{
				if(x.charAt(j)=="" || x.charAt(j)=="")
				a = a-1;
			}
			if(a==0)
			{
				alt = alt +	value2[i-1] + "\n";
			}
		}
		if(alt=="")
		{
			//return true;
		}
		else
		{
			alert('Please enter following\n\n' + alt);
			return false;
		}
	}
	
	function editprofile()
	{
		var action = "editprofile";
		if(nullvalue('edit_profile!name!txtAddress!email','- Name!- Address!- E-mail')==false)
		{
			return false;
		}
		if(echeck(document.getElementById('email').value)==false)
		{
			return false;
		}
		var val = document.edit_profile;
		var name = val.name.value;
		var add = val.txtAddress.value;
		var add1 = val.txtAddress1.value;
		var email = val.email.value;
		var comment = val.comment.value;

		var xmlHttp = getHTTPObject();
		var xmlObj = new Object();
		xmlHttp.open("GET", "update_profile.php?action=" + action + "&name=" + name + "&add=" + add + "&add1=" + add1 + "&email=" + email + "&comment=" + comment, false);
		xmlHttp.send(xmlObj);
		xmlDocument = xmlHttp.responseText;
		if(trim(xmlDocument)=="true")
		{
			//return echeck(document.getElementById('email').value);
			document.getElementById("msg").style.display = "block";
			return true;
		}
		else
		{
			alert("Profile has not been update");
			return false;
		}
	}
	
	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 confirmpass()
	{	
		if(nullvalue('change_pass!opass!pass!cpass','- Old Password!- New Password!- Confirm Password')==false)
		{
			return false;
		}
		oldpass(document.getElementById("opass").value);
		
		var pass = document.getElementById("pass").value;
		var cpass = document.getElementById("cpass").value;	
		
		if(pass != cpass)
		{
			alert("New Password and Confirm Password is not matched");
			return false;
		}
		else
		{
			var action = "conpass";
			var xmlHttp = getHTTPObject();
			var xmlObj = new Object();
			xmlHttp.open("GET", "update_profile.php?action=" + action + "&newpass=" + pass, false);
			xmlHttp.send(xmlObj);
			xmlDocument = xmlHttp.responseText;
			if(trim(xmlDocument)=="true")
			{
				document.getElementById("msg").style.display = "block";
				return true;
			}
			else
			{
				alert("Password has not been update");
				return true;
			}
			return false;			
		}
		
	}
	
	function oldpass(oldpass)
	{
		//alert(oldpass);
		var action = "oldpass";
		var xmlHttp = getHTTPObject();
		var xmlObj = new Object();
		xmlHttp.open("GET", "update_profile.php?action=" + action + "&oldpass=" + oldpass, false);
		xmlHttp.send(xmlObj);
		xmlDocument = xmlHttp.responseText;
		//alert(trim(xmlDocument));
		if(trim(xmlDocument)=="false")
		{
			alert("Please enter correct Old Password");
			return false;
		}
	}

	function forgotpass(action,username)
	{
		//alert(username);
		//alert(action);
		var xmlHttp = getHTTPObject();
		var xmlObj = new Object();
		xmlHttp.open("GET", "update_profile.php?username=" + username + "&action=" + action, false);
		xmlHttp.send(xmlObj);
		xmlDocument = xmlHttp.responseText;
		//alert(xmlDocument);
		if(trim(xmlDocument)=="true")
		{
			document.getElementById('showmsg').style.display = "block";
			return true;
		}
		else
		{
			return false;
		}
	}
