var url;
var params;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	{
	  // Internet Explorer
	  try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
 return xmlHttp;
}

function regfun()
{
	xmlHttp=GetXmlHttpObject();
	Path='register/regdietinfo.php';
	xmlHttp.open("GET",Path,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			ResponseData1=xmlHttp.responseText;
			document.getElementById('smartcentercontent').innerHTML = ResponseData1;						
		}
	}
	xmlHttp.send(null);	
	return false;
}


function processreg1(fname,lname,email,paswd,yrborn,aid)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
 var url="register/regnewsletter.php";
 url=url+"? fname="+fname+"&lname="+lname+"&email="+email+"&paswd="+paswd+"&yrborn="+yrborn+"&aid="+aid;
 xmlHttp.open("GET",url,true);
 xmlHttp.onreadystatechange=function()
 {
	 if (xmlHttp.readyState==4)
	 {
		document.getElementById("smartcentercontent").innerHTML=xmlHttp.responseText;	
	 }
 }
 xmlHttp.send(null);
}


function processdietfun(age,gender,height,heightms,HeightM,weight,WeightM,goal,goalweight,weeklywtlose,wactlevel,lisactlevel)
{
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Your browser does not support AJAX!");
  return;
 } 
 var url="register/regpersonalinfo.php";
 url=url+"? age="+age+"&gender="+gender+"&height="+height+"&heightms="+heightms+"&HeightM="+HeightM+"&weight="+weight+"&WeightM="+WeightM+"&goal="+goal+"&goalweight="+goalweight+"&weeklywtlose="+weeklywtlose+"&wactlevel="+wactlevel+"&lisactlevel="+lisactlevel;
 xmlHttp.open("GET",url,true);
 xmlHttp.onreadystatechange=function()
 {
	if (xmlHttp.readyState==4)
	{
		document.getElementById("smartcentercontent").innerHTML=xmlHttp.responseText;
	}
 }
 xmlHttp.send(null);	
}

function processnewsfun(newsletteropt,dietval,healthymenuval,customworkval,aid)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
 var url="register/regresult.php";
 url=url+"?newsletteropt="+newsletteropt+"&dietval="+dietval+"&healthymenuval="+healthymenuval+"&customworkval="+customworkval+"&aid="+aid;
  xmlHttp.open("GET",url,true);
  xmlHttp.onreadystatechange=function()
  {
	if (xmlHttp.readyState==4)
	{
		document.getElementById("smartcentercontent").innerHTML=xmlHttp.responseText;
	}
  }
 xmlHttp.send(null);	
}


function processsmartdietfun(age,gender,height,heightms,HeightM,weight,WeightM,goal,goalweight,weeklywtlose,wactlevel,lisactlevel,aid)
{
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
   alert ("Your browser does not support AJAX!");
   return;
 } 
 var url="freedietprofilesave.php";
 url=url+"? age="+age+"&gender="+gender+"&height="+height+"&heightms="+heightms+"&HeightM="+HeightM+"&weight="+weight+"&WeightM="+WeightM+"&goal="+goal+"&goalweight="+goalweight+"&weeklywtlose="+weeklywtlose+"&wactlevel="+wactlevel+"&lisactlevel="+lisactlevel;
 xmlHttp.open("GET",url,true);
 xmlHttp.onreadystatechange=function()
 {		
	if (xmlHttp.readyState==4)
	{
		document.getElementById("contentright").innerHTML=xmlHttp.responseText;
	}
 }
 xmlHttp.send(null);	
}


function processcreditinfo(firstname,lastname,ccardnumber,user_cardtype,ccardnumber,ccexpmonth,ccexpyear,cvv2Number,address,city,state,zip,country,mobilenumber,mobilebrand,mobilecarrier,aid)
{
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
   alert ("Your browser does not support AJAX!");
   return;
 } 
 var url="register/paymentinfosave.php";
 url=url+"? firstname="+firstname+"&lastname="+lastname+"&ccardnumber="+ccardnumber+"&user_cardtype="+user_cardtype+"&ccardnumber="+ccardnumber+"&ccexpmonth="+ccexpmonth+"&ccexpyear="+ccexpyear+"&cvv2Number="+cvv2Number+"&address="+address+"&city="+city+"&state="+state+"&zip="+zip+"&country="+country+"&mobilenumber="+mobilenumber+"&mobilebrand="+mobilebrand+"&mobilecarrier="+mobilecarrier+"&aid="+aid;
 xmlHttp.open("GET",url,true);
 xmlHttp.onreadystatechange=function()
 {
	if (xmlHttp.readyState==4)
	{
		document.getElementById("smartcentercontent").innerHTML=xmlHttp.responseText;
	}
 }
 xmlHttp.send(null);	
}

function JSForgot(f)
{ 
	if(!ValidEmail(f.email))
	{ 
		//alert("Plase enter a valid email address");  
		f.email.focus();return false;
	}
	xmlHttp=GetXmlHttpObject();
	Path='processfpassword.php?email='+f.email.value;

	xmlHttp.open("GET",Path,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			ResponseData1=xmlHttp.responseText;
			if(ResponseData1.search("authorized") != -1) {
				alert('Unauthorised Access.');
			} else {
				alert('Your password was successfully sent to your mailbox.');	
			}
			//document.getElementById('smartcentercontent').innerHTML = ResponseData1;						
		}
	}
	xmlHttp.send(null);	
	return false;
}


function chpassword(f)
{ 	 
	if(f.oldpassword.value=='') { alert("Please enter your old password."); f.oldpassword.focus(); return false;}
	if(!empty(f.newpassword,'new password')) { f.newpassword.focus(); return false;}		
	xmlHttp=GetXmlHttpObject();
	Path="process_chpassword.php?email="+f.email.value+"&oldpassword="+f.oldpassword.value+"&newpassword="+f.newpassword.value;
	xmlHttp.open("GET",Path,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			ResponseData1=xmlHttp.responseText;
			if(ResponseData1.search("authorized") != -1) {
				alert('Unauthorised Access.');
			} else {
				alert('Your password has been changed successfully.');	
			}
		//document.getElementById('smartcentercontent_changepassword').innerHTML = ResponseData1;						
		}
	}
	xmlHttp.send(null);	
	return false;	
}

function profilepage_chpassword(f) {
	if(f.oldpassword.value=='') { alert("Enter your old password."); f.oldpassword.focus(); return false;}
	if(!empty(f.newpassword,'new password')) { f.newpassword.focus(); return false;}
}


function fpasswd(f)
{
	xmlHttp=GetXmlHttpObject();
	Path='forgotpassword.php';
	xmlHttp.open("GET",Path,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			ResponseData1=xmlHttp.responseText;
			document.getElementById('smartcentercontent').innerHTML = ResponseData1;						
		}
	}
	xmlHttp.send(null);	
	return false;
}


function changepasswd(f)
{
	xmlHttp=GetXmlHttpObject();
	Path='change_password.php';

	xmlHttp.open("GET",Path,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			ResponseData1=xmlHttp.responseText;
			document.getElementById('smartcentercontent_changepassword').innerHTML = ResponseData1;						
		}
	}
	xmlHttp.send(null);	
	return false;
}


// To check the Email ID for correctness
/**	 FUNCTION EMAILVALIDATION(element) 	 **/

  function ValidEmail(Element)
  {
		Flag  = 1;
		count = 0;
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
		
		if(Element.value.length > 0)
		{
			for (var i=0; i<Element.value.length; i++)
			{
				temp = Element.value.substring(i, i+1);
	
				if (alp.indexOf(temp) == -1)
				{
					Flag = 0;
				}
			} // closing the for loop
		}
		else
		{
			Flag = 0;
		}
	
		for(var i=0; i <= Element.value.length; i++)
		{
			if(Element.value.charAt(0)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(Element.value.length-1)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(i)=='@') 
			{
				count = count + 1;

				if(count>1)
				{
					Flag = 0;
					break;
				}
			  
				if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
				{
					Flag = 0;
					break;
				}
			}
			if(Element.value.indexOf('@')==-1)
			{
				Flag = 0;		    	
				break;
			}
			if(Element.value.charAt(0)=='.')
			{
				Flag = 0;
				break;
			}
			if(Element.value.indexOf('.')==-1)
			{
				Flag = 0;		    	
				break;
			}
		  } //closing the for loop
		
		if(Element.value.charAt(Element.value.length-1) == '.')
			Flag = 0;
			
		if(Flag != 1)
		{
			alert("Invalid Email Address.\nValid Characters are [a-z][A-Z][0-9][ _ @ . - ].");
			Element.focus();
			return 0;
		}	
		else
			return 1;
	}

/**	 END OF FUNCTION EMAILVALIDATION(element) 	 **/