package astrology.findyourfate.com;

import java.io.File;
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
import com.google.analytics.tracking.android.EasyTracker;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;

public class nadireading extends Activity {
	// private AdView mAdview;
	 private AdLayout adView;
	public nadireading(){}
 
		RadioButton pay;
		Button btn,selectbtn;
		int m=25;
		WebView webview;
		String path;
		String fname="myfile.xml";
		int count=0;
		private ImageView attachImage = null;
		private byte[] image = null;
		private static final int SELECT_IMAGE = 1;
		private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_NO_NETWORK;
	    private static final String CONFIG_CLIENT_ID = "GB7QEWLT4JRQ6";
	    private static final String CONFIG_RECEIVER_EMAIL = "stanley@findyourfate.com"; 
	    private EasyTracker easyTracker = null;
	
	protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);

	        setContentView(R.layout.nadireading);
			//  mAdview = (AdView) findViewById(R.id.adView);
		    //    mAdview.setAdListener(new ToastAdListener(this));
	        AdRegistration.setAppKey("fbce94eb2ff347e5a855d4496106f125");
		 	   this.adView = (AdLayout) findViewById(R.id.ad_view);
			AdTargetingOptions adOptions = new AdTargetingOptions();
			AdRegistration.enableLogging(false);
			 AdRegistration.enableTesting(false);
		        easyTracker = EasyTracker.getInstance(nadireading.this);
	        Intent intent = new Intent(this, PayPalService.class);	        
	        intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
	        intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
	        intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
	        startService(intent);
	        
	   	final String fname =getIntent().getStringExtra("firstname");
	   	final String lname =getIntent().getStringExtra("lastname");
	   	final String add =getIntent().getStringExtra("address");
	   	final String city =getIntent().getStringExtra("city");
	   	final String dob =getIntent().getStringExtra("dob");
	   	final String user =getIntent().getStringExtra("email");
	   	final String country =getIntent().getStringExtra("country");
	   	final String conmail =getIntent().getStringExtra("confemail");
	  	webview=(WebView)findViewById(R.id.myview);
	   	attachImage= (ImageView)findViewById(R.id.imageView1);
	 
	   	final CheckBox[] chkArray = new CheckBox[18];
	   chkArray[0] = (CheckBox) findViewById(R.id.checkBox1);
	   chkArray[1] = (CheckBox) findViewById(R.id.checkBox2); 
	   chkArray[2] = (CheckBox) findViewById(R.id.checkBox3); 
	   chkArray[3] = (CheckBox) findViewById(R.id.checkBox4); 
       chkArray[4]=(CheckBox)findViewById(R.id.checkBox5);
	   chkArray[5]=(CheckBox)findViewById(R.id.checkBox6);
	   chkArray[6]=(CheckBox)findViewById(R.id.checkBox7);
	   chkArray[7]=(CheckBox)findViewById(R.id.checkBox8);
	   chkArray[8]=(CheckBox)findViewById(R.id.checkBox9);
	   chkArray[9]=(CheckBox)findViewById(R.id.checkBox10);
	   chkArray[10]=(CheckBox)findViewById(R.id.checkBox11);
	   chkArray[11]=(CheckBox)findViewById(R.id.checkBox12);
	   chkArray[12]=(CheckBox)findViewById(R.id.checkBox13);
	   chkArray[13]=(CheckBox)findViewById(R.id.checkBox14);
	   chkArray[14]=(CheckBox)findViewById(R.id.checkBox15);
	   chkArray[15]=(CheckBox)findViewById(R.id.checkBox16);
	   chkArray[16]=(CheckBox)findViewById(R.id.checkBox17); 
	   chkArray[17]=(CheckBox)findViewById(R.id.checkBox18);
       pay=(RadioButton)findViewById(R.id.payment);
       btn=(Button)findViewById(R.id.button1);
       selectbtn=(Button)findViewById(R.id.btn_select);
   	
      selectbtn.setOnClickListener(new OnClickListener() {
	        public void onClick(View arg0) {
	        	
	        	Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");
	        	startActivityForResult(intent, SELECT_IMAGE);
	        }
	    });
       
       
       final AlertDialog.Builder alt_bld = new AlertDialog.Builder(nadireading.this);
       
       		chkArray[0].setChecked(true);
       		chkArray[0].setClickable(false);
       		chkArray[1].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
         if (chkArray[1].isChecked())
               {
        	   	count+=1;
        	   	m+=20;
        		pay.setText("PayPal - USD " +m);
             
               }
           else if (!chkArray[1].isChecked())
           {
        	   	count-=1;
        	   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
           
           }
       });
       
	chkArray[2].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[2].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[2].isChecked())
           {
    		 
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
           }
       });
      chkArray[3].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[3].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[3].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
          }
       });
      chkArray[4].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	   if (chkArray[4].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[4].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
           }
       });
      chkArray[5].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[5].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[5].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
       }
       });  
      chkArray[6].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	   if (chkArray[6].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[6].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
       }
       });
      chkArray[7].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[7].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[7].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
      }
       });
      chkArray[8].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[8].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[8].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
           }
       });
      chkArray[9].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[9].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[9].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
          }
       });
      chkArray[10].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[10].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[10].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
            }
       });
      chkArray[11].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[11].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[11].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
          }
       });
      chkArray[12].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[12].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[12].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
           }
       });
      chkArray[13].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[13].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[13].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          } 
          
          }
       });
      chkArray[14].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[14].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[14].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
           }
       });
      chkArray[15].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[15].isChecked())
           {
    		   	count+=1;
    		   	m+=20;
        		pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[15].isChecked())
           {
    		   	count-=1;
    		   	m-=20;
    			pay.setText("PayPal - USD " +m);
          }  
           }
       });
      chkArray[16].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[16].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (! chkArray[16].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
          } 
        }
       });
      chkArray[17].setOnClickListener(new OnClickListener()
       {
       public void onClick(View v)
           {
    	
    	   if (chkArray[17].isChecked())
           {
    		   count+=1;
    		   m+=20;
    		   pay.setText("PayPal - USD " +m);
           } 
    	   else if (!chkArray[17].isChecked())
           {
    		   count-=1;
    		   m-=20;
    		   pay.setText("PayPal - USD " +m);
    	    } 
           }
       });
    
    btn.setOnClickListener(new View.OnClickListener() {
   		
   		@Override
   		public void onClick(View v) {
   			// TODO Auto-generated method stub
   			String payment=pay.getText().toString();
   			
   		  String choosedcanto1 = "",choosedcanto2 = "",choosedcanto3 ="",choosedcanto4 = "",choosedcanto5 = "",choosedcanto6 = "",choosedcanto7 = "",choosedcanto8 = "",choosedcanto9 = "",choosedcanto10= "",choosedcanto11 = "",choosedcanto12 = "",choosedcanto13= "",choosedcanto14 = "",choosedcanto15 = "",choosedcanto16 = "",choosedcanto17 = "";
   		  
   		for (int i=0, n=chkArray.length;i<n;i++) 
   		{
   		  if (chkArray[1].isChecked()) 
   		  {
   			  choosedcanto1=chkArray[1].getText().toString();
   		  }
   		  if (chkArray[2].isChecked()) 
   		  {
   			  choosedcanto2=chkArray[2].getText().toString();
   		  }
   		 if (chkArray[3].isChecked()) 
  		  {
   			 choosedcanto3=chkArray[3].getText().toString();
  		  }
   		 if (chkArray[4].isChecked()) 
 		  {
   			 choosedcanto4=chkArray[4].getText().toString();
 		  }
   		 if (chkArray[5].isChecked()) 
 		  {
   			 choosedcanto5=chkArray[5].getText().toString();
 		  }
   		 if (chkArray[6].isChecked()) 
 		  {
   			 choosedcanto6=chkArray[6].getText().toString();
 		  }
   		 if (chkArray[7].isChecked()) 
 		  {
   			 choosedcanto7=chkArray[7].getText().toString();
 		  }
   		 if (chkArray[8].isChecked()) 
 		  {
   			 choosedcanto8=chkArray[8].getText().toString();
 		  }
   		 if (chkArray[9].isChecked()) 
 		  {
   			 choosedcanto9=chkArray[9].getText().toString();
 		  }
   		 if (chkArray[10].isChecked()) 
 		  {
   			 choosedcanto10=chkArray[10].getText().toString();
 		  }
   		 if (chkArray[11].isChecked()) 
 		  {
   			 choosedcanto11=chkArray[11].getText().toString();
 		  }
   		 if (chkArray[12].isChecked()) 
 		  {
   			 choosedcanto12=chkArray[12].getText().toString();
 		  }
   		 if (chkArray[13].isChecked()) 
 		  {
   			 choosedcanto13=chkArray[13].getText().toString();
 		  }
   		 if (chkArray[14].isChecked()) 
 		  {
   			 choosedcanto14=chkArray[14].getText().toString();
 		  }
   		 if (chkArray[15].isChecked()) 
		  {
   			 choosedcanto15=chkArray[15].getText().toString();
		  }
   		 if (chkArray[16].isChecked()) 
		  {
   			 choosedcanto16=chkArray[16].getText().toString();
		  }
   		 if (chkArray[17].isChecked()) 
		  {
   			 choosedcanto17=chkArray[17].getText().toString();
		  }
   		}
   			String format= "First Name :" +fname +"<br />"
   						+"Last Name :" +lname + "<br />"
   						+"Address :" +add + "<br />"
   						+"City : " +city + "<br/>"
   						+"Country of Birth : " +country + "<br/>"
   						+"Date of Birth : " +dob + "<br/>"
   						+"Present Country : " +country + "<br/>"
   						+"E-mail Address : " +user + "<br/>"
   						+"Confirm E-mail Address : " +conmail + "<br/>"
   						+"1st canto:This we call General Reading which covers all aspects of your life and is a summary of the other following cantos." + "<br/>"
   						+" Selected Cantos:"+ "<br/>" +choosedcanto1 +"<br/>"+ choosedcanto2 +"<br/>"+choosedcanto3 +"<br/>"+choosedcanto4 +"<br/>"+choosedcanto5 +"<br/>"+choosedcanto6 +"<br/>"+choosedcanto7 +"<br/>"+choosedcanto8 +"<br/>"+choosedcanto9 +"<br/>"+choosedcanto10 +"<br/>" +choosedcanto11 +"<br/>"+choosedcanto12 +"<br/>"+choosedcanto13+"<br/>"+choosedcanto14 +"<br/>"+choosedcanto15+"<br/>"+choosedcanto16 +"<br/>"+choosedcanto17 +"<br/>"
   						+"Details :" + payment+ "<br/>";
   
   
   if(count<5)
   {
	   alt_bld.setTitle("Alert Message");
		 alt_bld.setMessage("Please Select Atleast 5 canto's")
 		 .setCancelable(false)
 					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
 					 public void onClick(DialogInterface dialog, int id) {
 					 }
 					 });
 		 AlertDialog alert = alt_bld.create();
 		 alert.setTitle("Alert Message");
 		 alert.setIcon(R.drawable.alert);
 		 alert.show();
   }
     else if(attachImage.getDrawable()==null)
    	{
     		 alt_bld.setTitle("Alert Message");
     		 alt_bld.setMessage("Please upload your Thumb image")
     		 .setCancelable(false)
     					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
     					 public void onClick(DialogInterface dialog, int id) {
     						selectbtn.requestFocus(); 
     					 }
     					 });
     		 AlertDialog alert = alt_bld.create();
     		 alert.setTitle("Alert Message");
     		 alert.setIcon(R.drawable.alert);
     		 alert.show();
     		 selectbtn.setFocusable(true);
     	}
   		else if(!(attachImage.getDrawable()==null)){	
   			 try {   
   				 GMailSender sender = new GMailSender(user,format,"Nadi Reading - Confirmation Details  - findyourfate.com apps",path );
                 } catch (Exception e) {   
                 Log.e("SendMail", e.getMessage(), e);   
             } 
   		   Intent intent = new Intent(nadireading.this, PayPalService.class);
           
           intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
           intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
           intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
            
           startService(intent);
           
      	 PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(m), "USD", "Nadi Reading - Payment Confirmation Details - findyourfate.com Apps");
     	    
           Intent intent1 = new Intent(nadireading.this, PaymentActivity.class);
            
           intent1.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
           intent1.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
           intent1.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
            
           // It's important to repeat the clientId here so that the SDK has it if Android restarts your 
           // app midway through the payment UI flow.
           intent1.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "credential-from-developer.paypal.com");
           intent1.putExtra(PaymentActivity.EXTRA_PAYER_ID, "your-customer-id-in-your-system");
           intent1.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
            
           startActivityForResult(intent1, 0);
    			 }	
   		}
    		
   	});
	// mAdview.loadAd(new AdRequest.Builder().build());
    this.adView.loadAd(adOptions);
	} 
	
	@Override
    public void onStart() {
        super.onStart();
        EasyTracker.getInstance(this).activityStart(this);
    }
	@Override
    public void onStop() {
        super.onStop();
        EasyTracker.getInstance(this).activityStop(this);
    }
    @Override
	public void onBackPressed() {
	            	 nadireading.this.finish();
	}

	@Override
		public boolean onCreateOptionsMenu(Menu menu) {
			getMenuInflater().inflate(R.menu.main, menu);
			return true;
		}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	if (item.getItemId() ==R.id.drawer)
				{
					Intent int_sear = new Intent(this,MainActivity.class);
			        int_sear.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			        startActivity(int_sear);
					}
			  else if (item.getItemId() ==R.id.service)
			  {
			  		Intent int_ser = new Intent(this,ourservices.class);
			  		int_ser.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			  		startActivity(int_ser);
			  }
			  else if (item.getItemId() ==R.id.astrology)
			  {
				File myFile = new File(getFilesDir() + "/" + fname);
			      if (myFile.exists()) 
			            {
				        	try {
				    			
				        		FileInputStream file = new FileInputStream(new File(getFilesDir() + "/" + fname));
					             
					            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
					             
					            DocumentBuilder builder =  builderFactory.newDocumentBuilder();
					             
					            Document xmlDocument = builder.parse(file);
					 
					            XPath xPath =  XPathFactory.newInstance().newXPath();
					   
					            System.out.println("*************************");
					            String   expression = "/root/zodiac";
					          	System.out.println(expression);
					            NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
					            for (int i = 0; i < nodeList.getLength(); i++) {
					            String value=nodeList.item(i).getLastChild().getNodeValue(); 
					            if(value.length() == 0)
					               {
					            	   Intent int_ast = new Intent(this,astology.class);
					            	   int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					            	   startActivity(int_ast);
					               }
					               else
					               {
					            	   Intent in= new Intent(this,horoscope.class);
					            	   in.putExtra("key", value);
					            	   in.putExtra("modeday","Today");							
					            	   startActivity(in);
						     
					            	}
					            }   

							}catch (FileNotFoundException e) {
					            e.printStackTrace();
							} catch (SAXException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (ParserConfigurationException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (XPathExpressionException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}			

			            }
			 	        else
			            {
			            	 Intent int_ast = new Intent(this,astology.class);
					            int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					            startActivity(int_ast);
					    }
		
		}
		 else if (item.getItemId() ==R.id.setup)
		 {
			File myFile1 = new File(getFilesDir() + "/" + fname);
			
				if (myFile1.exists()) 
			      {
				     try {  	
				        	FileInputStream file = new FileInputStream(new File(getFilesDir() + "/" + fname));
					              
					        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
					             
					        DocumentBuilder builder =  builderFactory.newDocumentBuilder();
					             
					        Document xmlDocument = builder.parse(file);
					 
					        XPath xPath =  XPathFactory.newInstance().newXPath();
					   
					       System.out.println("*************************");
					       String   expression = "/root/zodiac";
					       System.out.println(expression);
					       String   expressio = "/root/dob";
						   System.out.println(expressio);
						         
						  NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
						            
				 for (int i = 0; i < nodeList.getLength(); i++) {
						            	
					 String value=nodeList.item(i).getFirstChild().getNodeValue(); 
					 NodeList nodeList1 = (NodeList) xPath.compile(expressio).evaluate(xmlDocument, XPathConstants.NODESET);
					 for (int i1 = 0; i1 < nodeList1.getLength(); i1++) {
				    String val=nodeList1.item(i1).getLastChild().getNodeValue(); 
							     if(value.length() == 0)
					               {
					               Intent int_ast = new Intent(this,astology.class);
						           int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						           startActivity(int_ast);
					               }
					               else
					               {
									Intent in= new Intent(this,setuppage.class);
									in.putExtra("date",val);
									in.putExtra("key", value);
									startActivity(in);
						       	}
							   		}   
						            }
			           }catch (FileNotFoundException e) {
				            e.printStackTrace();
						} catch (SAXException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (ParserConfigurationException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (XPathExpressionException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
			            }
				       else
			            {
			            	 Intent int_ast = new Intent(this,astology.class);
					         int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					         startActivity(int_ast);
			            } 
		}
		 else if (item.getItemId() == R.id.exit)
		  {
			 AlertDialog.Builder builder = new AlertDialog.Builder(this);
			    builder.setMessage("Are you sure  want to exit?")
			           .setCancelable(false)
			           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			               public void onClick(DialogInterface dialog, int id) {
			            	   Intent intent = new Intent(Intent.ACTION_MAIN);
			   		    	intent.addCategory(Intent.CATEGORY_HOME);
			   		    	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			   		    	startActivity(intent);
			               }
			           })
			           .setNegativeButton("No", new DialogInterface.OnClickListener() {
			               public void onClick(DialogInterface dialog, int id) {
			                    dialog.cancel();
			               }
			           });
			    AlertDialog alert = builder.create();
			    alert.show();
		  }
	/*	 else if (item.getItemId() == R.id.share)
		 {
				Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
		    	emailIntent.setType("text/plain");
		    	emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Astrology by findyourfate.com");
		        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hi,I would like to suggest, this  Astrology by findyourfate.com App to you. \n Click this Link to Download app \"http://goo.gl/iexPxk\"\n\n Regards");
		    	startActivity(emailIntent);  
		 }	
		 else if (item.getItemId() == R.id.in)
		  {
			  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(nadireading.this);
			    alertDialogBuilder.setTitle("Horoscope Compatibility");
			
			           alertDialogBuilder.setMessage("Compatibility of zodiac signs for love and romantic relationship. Search what zodiac signs are compatible. Find quality results here!No two sun signs are alike and totally compatible. A degree of incompatibility always exists because that is how we have been made.Marriages are made in heaven BUT!!! Compatible Love Matches are made here through this app.The paid in-app compatibility report is \"the best buy\".");
			     alertDialogBuilder.setPositiveButton("Open",new DialogInterface.OnClickListener() {
			        	   
			        	                   public void onClick(DialogInterface dialog,int id) {
			        	                	   final String appPackageName = "compatibility.findyourfate.com"; // getPackageName() from Context or Activity object
			        	                	   try {
			        	                	       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
			        	                	   } catch (android.content.ActivityNotFoundException anfe) {
			        	                	       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
			        	                	   }
			        	                   }
			        	                   });
			          alertDialogBuilder.setNeutralButton("Already/Never",new DialogInterface.OnClickListener() {
			                  public void onClick(DialogInterface dialog,int id) {	  
			                    //  MainActivity.this.finish();
			                	  dialog.cancel();
			                  }
			  
			              });
			  
			            // set negative button: No message
					alertDialogBuilder.setNegativeButton("Later",new DialogInterface.OnClickListener() {
		
			                  public void onClick(DialogInterface dialog,int id) {
			                      // cancel the alert box and put a Toast to the user
			                      dialog.cancel();                    
			                  }
			
			              });
			           AlertDialog alertDialog = alertDialogBuilder.create();
			 
			           // show alert
			           alertDialog.show();			  
			      } */
				 else
				 {
					 
				 }
       
			return true;
     	}
		public boolean fileExistance(String fname){
			File myfile = getBaseContext().getFileStreamPath(fname);
			return myfile.exists();
		}
		@Override
		public void onActivityResult(int requestCode, int resultCode, Intent data) {
			super.onActivityResult(requestCode, resultCode, data);
			if (resultCode == Activity.RESULT_OK) {
				if (requestCode == SELECT_IMAGE) {
					Uri selectedImageUri = data.getData();
					//OI FILE Manager
					String  filemanagerstring = selectedImageUri.getPath();
					//MEDIA GALLERY
					String  selectedImagePath = getPath(selectedImageUri);
					if (selectedImagePath != null) {
						path = selectedImagePath;
					} else {
						path = filemanagerstring;
					}
					Util.debug("Imagepath: '" + path + "'.");
					Bitmap bitmap = Util.decodeBitmap(path, 800);
					image = Util.bitmapToBytes(bitmap);
					attachImage.setImageBitmap(bitmap);
				}
				else
				{
					PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        	 
					 if (confirm != null) {
		    	            try {
		    	                Log.i("paymentExample", confirm.toJSONObject().toString(4));

		    	                // TODO: send 'confirm' to your server for verification.
		    	                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
		    	                // for more details.

		    	            } catch (JSONException e) {
		    	                Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
		    	            }
		    	        }
		    	            
		    	            else if (resultCode == Activity.RESULT_CANCELED) {
		    		             Log.i("paymentExample", "The user canceled.");
		    		             this.finish();
		    		            // Intent int_spa = new Intent(this,ourservices.class);
		    			         //   int_spa.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    			           // startActivity(int_spa);
		    		         }
		    		         else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
		    		             Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
		    		         }
		    	        }
		    	        	}
		    	        	 
		    	  
			  }
		private String getPath(Uri uri) {
			String[] projection = {MediaStore.Images.Media.DATA};
			Cursor cursor =nadireading.this.managedQuery(uri, projection, null, null, null);
			if (cursor != null) {
				// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
				// THIS CAN HAPPEN IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
				int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
				cursor.moveToFirst();
				return cursor.getString(column_index);
			} else {
				return null;
			}
		}
	}