
///////////////////////////////////////////////////////////////////////////

var url;
var xmlHttpFreePred,xmlHttpLogin,xmlHttpRegister;
var xmlHttpUpdateBirthDetails;
var xmlHttpUpdateUsermaster;
var xmlHttpdataentry,xmlHttpUpdateenduser;

//global declarations
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
function updateEndUser()
{
  pagename='indian-astrology/free-predictions/updateenduser.php';
  url=pagename;
  predprocess('updateenduser');
}
function updateMemberService(birthdata)
{
  //alert("entered to function");		
  pagename='indian-astrology/free-predictions/updateFdavlandEnduser.php';
  //alert(pagename);
  //url=pagename+'?'+_params;
  url=pagename;
  //alert('start'+url);
  predprocess('updatebirthdetails');
}
function updateServiceUsermaster()
{
  //alert("entered to function");		
  pagename='indian-astrology/free-predictions/updateUsermaster.php';
  //alert(pagename);
  //url=pagename+'?'+_params;
  url=pagename;
 // alert('start'+url);
  predprocess('updateusermaster');
	
}
function getfreeprediction(_params)
{
  
  
  pagename='indian-astrology/free-predictions/getpersonalizedpred.php';
  url=pagename+'?'+_params;
  //alert(_params);
  predprocess('freeprediction');
    
}
function checklogin(_params)
{
  
 
   pagename='common/logincheck.php';
   url=pagename+'?'+_params;
   
  predprocess('login');
    
}
function checkregistration(_params)
{
  
 
   pagename='common/register_user.php';
   url=pagename+'?paramval='+_params;
   
  predprocess('register');
    
}
function checkdataentry(_params)
{
  
 
   pagename='common/freepred_insregdetails.php';
   url=pagename+'?paramval='+_params;
   //alert(url);
   
  predprocess('dataentry');
    
}


function editprofile(_params)
{
   pagename='indian-astrology/free-predictions/edit-profile.php';
   url=pagename+'?'+_params;
   
   predprocess('edit');
	
}

///////////////////////////////////////////////////////////////////////////
// retrieves the XMLHttpRequest object

function createXmlHttpRequestObject()
{
var reqHttp;
if(window.ActiveXObject)
{
	try
	{
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		reqHttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	}
	catch (e)
	{
		reqHttp = false;
	}
}
// if running Mozilla or other browsers
else
{
	try
	{
		reqHttp = new XMLHttpRequest();
		
	}
	catch (e)
	{
		reqHttp = false;
	}
}
if (!reqHttp)
	alert("Error creating the XMLHttpRequest object.");
else
	return reqHttp;
}
//////////////////////////////////////////////////////////////////////

function predprocess(reqtype)
{
	if (reqtype=='freeprediction')
	{
	
			xmlHttpFreePred = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			
			if (xmlHttpFreePred.readyState == 4 || xmlHttpFreePred.readyState == 0)
			{
			xmlHttpFreePred.open("GET",url,true);
			
			xmlHttpFreePred.onreadystatechange = handleServerResponseForPred;
			xmlHttpFreePred.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('predprocess()', 1000);
			}
		
}
else if (reqtype=='login')
{
		xmlHttpLogin = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			
			if (xmlHttpLogin.readyState == 4 || xmlHttpLogin.readyState == 0)
			{
			xmlHttpLogin.open("GET",url,true);
			
			xmlHttpLogin.onreadystatechange = handleServerResponseForLogin;
			xmlHttpLogin.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('predprocess()', 1000);
			}
		
}

else if (reqtype=='register')
{
		xmlHttpRegister = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			
			if (xmlHttpRegister.readyState == 4 || xmlHttpRegister.readyState == 0)
			{
			xmlHttpRegister.open("GET",url,true);
			
			xmlHttpRegister.onreadystatechange = handleServerResponseForRegister;
			xmlHttpRegister.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('predprocess()', 1000);
			}
		
}
else if (reqtype=='edit')
{
		xmlHttpEdit = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			
			if (xmlHttpEdit.readyState == 4 || xmlHttpEdit.readyState == 0)
			{
				xmlHttpEdit.open("GET",url,true);
			
				xmlHttpEdit.onreadystatechange = handleServerResponseForEdit;
				xmlHttpEdit.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('predprocess()', 1000);
			}
		
}
else if (reqtype=='updatebirthdetails')
	  {
		  	//alert("entered to update");
			xmlHttpUpdateBirthDetails = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			//alert('inside process');
			if (xmlHttpUpdateBirthDetails.readyState == 4 || xmlHttpUpdateBirthDetails.readyState == 0)
			{
			xmlHttpUpdateBirthDetails.open("GET",url,true);
			
			xmlHttpUpdateBirthDetails.onreadystatechange = handleServerResponseForUpdateBirthDetails;
			xmlHttpUpdateBirthDetails.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('process()', 1000);
			}
		}
else if (reqtype=='updateusermaster')
	  {
		  	//alert("entered to update");
			xmlHttpUpdateUsermaster = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			//alert('inside process');
			if (xmlHttpUpdateUsermaster.readyState == 4 || xmlHttpUpdateUsermaster.readyState == 0)
			{
			xmlHttpUpdateUsermaster.open("GET",url,true);
			
			xmlHttpUpdateUsermaster.onreadystatechange = handleServerResponseForUpdateUsermaster;
			xmlHttpUpdateUsermaster.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('process()', 1000);
			}
		}
else if (reqtype=='updateenduser')
	  {
		  	
			xmlHttpUpdateenduser = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			if (xmlHttpUpdateenduser.readyState == 4 || xmlHttpUpdateenduser.readyState == 0)
			{
			xmlHttpUpdateenduser.open("GET",url,true);
			
			xmlHttpUpdateenduser.onreadystatechange = handleServerResponseForUpdateenduser;
			xmlHttpUpdateenduser.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('process()', 1000);
			}
		}

else if (reqtype=='dataentry')
{
		xmlHttpdataentry = createXmlHttpRequestObject();
			// proceed only if the xmlHttp object isn't busy
			
			if (xmlHttpdataentry.readyState == 4 || xmlHttpdataentry.readyState == 0)
			{
			xmlHttpdataentry.open("GET",url,true);
			
			xmlHttpdataentry.onreadystatechange = handleServerResponseFordataentry;
			xmlHttpdataentry.send(null);
	
			}
			else
			{
			// if the connection is busy, try again after one second
 			t = setTimeout('predprocess()', 1000);
			}
		
}

}

function handleServerResponseForUpdateBirthDetails()
{
	//alert('handle');
	
				if (xmlHttpUpdateBirthDetails.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpUpdateBirthDetails.status == 200)
		                   {
		
			                       var updstatus =  xmlHttpUpdateBirthDetails.responseText;
								   //alert(updstatus);
								   popup(0);
								   //document.getElementById("divpopup").style.display='none';
								   //document.getElementById("blackout").style.display='none';

									
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
				 	
	           }
	
 }
 
 function handleServerResponseForUpdateUsermaster()
{
	//alert('handle');
	
				if (xmlHttpUpdateUsermaster.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpUpdateUsermaster.status == 200)
		                   {
		
			                       var birthdata =  xmlHttpUpdateUsermaster.responseText;
								   //alert(birthdata);
								   document.getElementById("divpopup").style.display='none';
								   document.getElementById("blackout").style.display='none';

									
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
				  
	           }
	
 }

 function handleServerResponseFordataentry()
{

	
				if (xmlHttpdataentry.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpdataentry.status == 200)
		                   {
									
									_data=xmlHttpdataentry.responseText;
									//alert(_data);
									
									
									if (_data == 'REGOK')
									{
										window.location="http://www.clickastro.com/freeprediction.php";
									}
									else
									{
									    //alert(_data);
										document.getElementById("regiserror").innerHTML  =_data;	
									}
										
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                   
	           }
	
 }

// executed automatically when a message is received from the server
function handleServerResponseForPred()
{

	
				if (xmlHttpFreePred.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpFreePred.status == 200)
		                   {
									
									_data=xmlHttpFreePred.responseText;
									//alert(_data);
			                       
								   var mySplitResult =_data.split('|');
	    	                        document.getElementById("prediction").innerHTML  = mySplitResult[0];
									document.getElementById("startdate").innerHTML  = mySplitResult[1];
									document.getElementById("enddate").innerHTML  = mySplitResult[2];
									document.getElementById("date_value").innerHTML  = 'Predictions From: '+'<span style="color:#FF6600; font-size:14px;">'+mySplitResult[4]+'</span>  Till: '+'<span style="color:#FF6600; font-size:14px;">'+mySplitResult[5]+'</span';
									document.getElementById("birthdata").innerHTML  = mySplitResult[6];
									document.getElementById("mybirthdata").innerHTML  = mySplitResult[7];
									//alert(mySplitResult[7]);
									var pointer=mySplitResult[3];
									
								   //smilyes start
									var img_folder='classic';
	                              var smiley=pointer.split("#");
				document.getElementById('imgsmiley_1').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[1].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';
				document.getElementById('imgsmiley_2').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[2].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';
				document.getElementById('imgsmiley_3').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[3].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';


				document.getElementById('txtsmiley1').innerHTML=smiley[1];
				document.getElementById('txtsmiley2').innerHTML=smiley[2];
				document.getElementById('txtsmiley3').innerHTML=smiley[3];
				var smileyarr=smiley[1].replace(/^\s+|\s+$/g,"").toLowerCase()+"#"+smiley[2].replace(/^\s+|\s+$/g,"").toLowerCase()+"#"+smiley[3].replace(/^\s+|\s+$/g,"").toLowerCase();
				if(smiley.length >4)
				{

				smileyarr=smileyarr+"#"+smiley[4].replace(/^\s+|\s+$/g,"").toLowerCase();
				document.getElementById('imgsmiley_4').style.display='block';
				document.getElementById('imgsmiley_4').src="http://www.clickastro.com/indian-astrology/free-predictions/images/"+img_folder+"/smilie_"+smiley[4].replace(/^\s+|\s+$/g,"").toLowerCase()+".gif";
				document.getElementById('txtsmiley4').innerHTML=smiley[4];
				}
				else
				{
				document.getElementById('imgsmiley_4').style.display='none';
				document.getElementById('txtsmiley4').innerHTML='';
				}
								   //smilyes end
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                     document.getElementById("prediction").innerHTML  = '' ;
	           }
	
 }

 function getsmilyes(pointer)
{
var img_folder='classic';
	var smiley=pointer.split("#");
				document.getElementById('imgsmiley_1').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[1].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';
				document.getElementById('imgsmiley_2').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[2].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';
				document.getElementById('imgsmiley_3').src='http://www.clickastro.com/indian-astrology/free-predictions/images/'+img_folder+'/smilie_'+smiley[3].replace(/^\s+|\s+$/g,"").toLowerCase()+'.gif';

				document.getElementById('txtsmiley1').innerHTML=smiley[1];
				document.getElementById('txtsmiley2').innerHTML=smiley[2];
				document.getElementById('txtsmiley3').innerHTML=smiley[3];
				var smileyarr=smiley[1].replace(/^\s+|\s+$/g,"").toLowerCase()+"#"+smiley[2].replace(/^\s+|\s+$/g,"").toLowerCase()+"#"+smiley[3].replace(/^\s+|\s+$/g,"").toLowerCase();
				if(smiley.length >=4)
				{

				smileyarr=smileyarr+"#"+smiley[4].replace(/^\s+|\s+$/g,"").toLowerCase();
				document.getElementById('imgsmiley_4').style.display='block';
				document.getElementById('imgsmiley_4').src="http://www.clickastro.com/indian-astrology/free-predictions/images/"+img_folder+"/smilie_"+smiley[4].replace(/^\s+|\s+$/g,"").toLowerCase()+".gif";
				document.getElementById('txtsmiley4').innerHTML=smiley[4];
				}
				else
				{
				document.getElementById('imgsmiley_4').style.display='none';
				document.getElementById('txtsmiley4').innerHTML='';
				}
}
 
function handleServerResponseForLogin()
{

	
				if (xmlHttpLogin.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpLogin.status == 200)
		                   {
									
									_data=xmlHttpLogin.responseText;
									//alert(_data);
									var logindata=_data.split("#");
									if (logindata[0] == 'LOGINOK')
									{
										//alert(logindata[1]);
										document.getElementById("logindetails").style.display='none';
										document.getElementById("dailypred").style.display='block';
										timedRefresh(1000);
										getfreeprediction(logindata[1]);
									}
									else
									document.getElementById("loginerror").innerHTML  =logindata[0] ;
										
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                   
	           }
	
 }
 function handleServerResponseForRegister()
{

	
				if (xmlHttpRegister.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpRegister.status == 200)
		                   {
									
									_data=xmlHttpRegister.responseText;
									//alert(_data);
									var regdata=_data.split("#");
									if (regdata[0] == 'REGOK')
									{
										//alert(regdata[1]);
										document.getElementById("regdetails").style.display='none';
										document.getElementById("dailypred").style.display='block';
										getfreeprediction(regdata[1]);
									}
									else
									document.getElementById("regerror").innerHTML  =regdata[0] ;
									
									
										
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                   
	           }
	
 }
  function handleServerResponseForEdit()
{

	
				if (xmlHttpEdit.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpEdit.status == 200)
		                   {
									
									var _data=xmlHttpEdit.responseText;
									//alert(_data);
									if (_data == 1){
									 popup(1);//2010apr20
									}
									
									
									
										
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                   
	           }
	
 }
 

 
 function handleServerResponseForUpdateenduser()
{

	
				if (xmlHttpUpdateenduser.readyState == 4)
	            {
                  // status of 200 indicates the transaction completed successfully
		                 if (xmlHttpUpdateenduser.status == 200)
		                   {
									
									_data=xmlHttpUpdateenduser.responseText;
									
									var regdata=_data.split("#");
									if (regdata[0] == 'OK')
									{
										
										document.getElementById("dailypred").style.display='block';
										getfreeprediction(regdata[1]);
									}
																		
										
		                    }
                            // a HTTP status different than 200 signals an error
	             }
	             else
	           {
		                   
	           }
	
 }
