package astrology.findyourfate.com;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import org.json.JSONException;
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.app.DatePickerDialog;
import android.app.Fragment;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TimePicker;

public class compatreading extends Fragment {
	
	public compatreading(){}
	  EditText mEdit;
	Button btn;
	Spinner mDrawerList,mDrawerList1; 
	 EditText timer;
	 EditText timer1;
	Spinner counspin;
		WebView webView;
			EditText edittext;
	EditText edittext1;
	RadioButton male,male2;
	 EditText fullname,city,state,date,time,email,conemail,pcity,full2,city2,state2,time2,date2,compat;
	 RadioGroup pay ,sex,sex2;
	Spinner country,coun2,pcountry;
	String am_pm;
	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"; 

	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
         Bundle savedInstanceState) {
 
        View rootView = inflater.inflate(R.layout.compatibility, container, false);
         
        webView = (WebView)rootView.findViewById(R.id.myview); 
        
        final AlertDialog.Builder alt_bld = new AlertDialog.Builder(getActivity());
        
     fullname=(EditText)rootView.findViewById(R.id.fullname);
     full2=(EditText)rootView.findViewById(R.id.fullname2);
     city=(EditText)rootView.findViewById(R.id.city);
     state=(EditText)rootView.findViewById(R.id.state);
     country=(Spinner)rootView.findViewById(R.id.spinner1);
     pcountry=(Spinner)rootView.findViewById(R.id.spinner2);
     date=(EditText)rootView.findViewById(R.id.dateofbirth);
     time=(EditText)rootView.findViewById(R.id.time);
     email=(EditText)rootView.findViewById(R.id.email);
     conemail=(EditText)rootView.findViewById(R.id.conemail);
     pcity=(EditText)rootView.findViewById(R.id.pcity);
     city2=(EditText)rootView.findViewById(R.id.city2);
     state2=(EditText)rootView.findViewById(R.id.state2);
     time2=(EditText)rootView.findViewById(R.id.timer);
     date2=(EditText)rootView.findViewById(R.id.birth);
     compat=(EditText)rootView.findViewById(R.id.compat);
     pay=(RadioGroup)rootView.findViewById(R.id.payable);
     sex=(RadioGroup)rootView.findViewById(R.id.sex);
     sex2=(RadioGroup)rootView.findViewById(R.id.sex2);
     coun2=(Spinner)rootView.findViewById(R.id.ctspinner);
     male=(RadioButton)rootView.findViewById(R.id.m);
     male2=(RadioButton)rootView.findViewById(R.id.m2);
    

     btn = (Button)rootView .findViewById(R.id.button1);
     btn.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
         	
        	 String user = email.getText().toString();
        	 String fname=fullname.getText().toString();
        	 String cit=city.getText().toString();
        	 String coun=country.getSelectedItem().toString();
        	 String stat=state.getText().toString();
        	 String datt=date.getText().toString();
        	 String tim=time.getText().toString();
        	 String cemail=conemail.getText().toString();
        	 String pcit=pcity.getText().toString();
        	 String pcoun=pcountry.getSelectedItem().toString();
        	 int value = sex.getCheckedRadioButtonId();
        	 
        	 String gen;
            //checking the id of the selected radio
            if(value == male.getId())
            {
                gen="Male";
            }
            else
            {
              gen="Female";
            }
        	  
            	String fulname=full2.getText().toString();
            	String cit2=city2.getText().toString();
            	String cou2=coun2.getSelectedItem().toString();
            	String stat2=state2.getText().toString();
            	String datt2=date2.getText().toString();
            	String tim2=time2.getText().toString();
            	String compati=compat.getText().toString();
            	int value2 = sex2.getCheckedRadioButtonId();
           String gen2;
           if(value2 == male2.getId())
           {
               gen2="Male";
           }
           else
           {
             gen2="Female";
           }
           
            	String format= "person 1"+"<br/>"
	            		+"Fullname :" +fname +"<br />"
	            		+"Gender : " +gen + "<br/>"
	  	            	+"City : " +cit + "<br/>"
	            	    +"State/Province : " +stat + "<br/>"
	            	    +"Country of Birth : " +coun + "<br/>"
	            	    +"Date of Birth : " +datt + "<br/>"
	            	    +"Time of Birth : " +tim + "<br/>"
	                	+"E-mail Address : " +user + "<br/>"
	                	+"Confirm E-mail Address : " +cemail + "<br/>"
	            	    +"Present City : " +pcit + "<br/>"
	            	    +"Present country : " +pcoun + "<br/>"
	            	    +"person 2"+"<br/>"
	            	    +"Fullname :" +fulname +"<br />"
	            	    +"Gender : " +gen2 + "<br/>"
	  	        	    +"City : " +cit2 + "<br/>"
 	            	    +"State/Province : " +stat2 + "<br/>"
 	            	    +"Country of Birth : " +cou2 + "<br/>"
 	            	    +"Date of Birth : " +datt2 + "<br/>"
 	            	    +"Time of Birth : " +tim2 + "<br/>"
 	            	   +"Compatibility for : " +compati+ "<br/>"
 	            	    +"Payment Details : PayPal - USD 10 " + "<br/>";
	            	
	            	
	            	if( fullname.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person1-fullname")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 fullname.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 fullname.setFocusable(true);
	            	}	

	            	else if( city.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person1-city")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 city.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 city.setFocusable(true);
	            	}	
	            	else if( state.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person1-state")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 state.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 state.setFocusable(true);
	            	}	
	            	
	            	else if( date.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person1-date of birth")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 date.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 date.setFocusable(true);
	            	}	
	            	else if( time.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person1-time of birth")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 time.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 time.setFocusable(true);
	            	}	
	            	else if(email.getText().toString().length() == 0 )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please enter your email address")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						email.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 email.setFocusable(true);
	            	}	
	            	
	            	else if(conemail.getText().toString().length() == 0 )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please enter your confirm email id")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						conemail.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 conemail.setFocusable(true);
	            	}
	            	
	            	else if(country.getSelectedItem().toString().equals("--Select--"))
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please select person1- Country")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 country.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 country.setFocusable(true);
	            	}
	            	else if(pcity.getText().toString().length() == 0)
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please select person1- present city")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 pcity.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 pcity.setFocusable(true);
	            	}
	            	
	            	else if(pcountry.getSelectedItem().toString().length() == 0)
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please select person1- present country")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 pcountry.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 pcountry.setFocusable(true);
	            	}
	            	
	            	else if( full2.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person2-fullname")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 full2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 full2.setFocusable(true);
	            	}	

	            	else if( city2.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person2-city")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 city2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 city2.setFocusable(true);
	            	}	
	            	else if( state2.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person2-state")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 state2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 state2.setFocusable(true);
	            	}	
	            	else if(coun2.getSelectedItem().toString().equals("--Select--"))
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please select person2- Country")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 coun2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 coun2.setFocusable(true);
	            	}
	            	else if( date2.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person2-date of birth")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 date2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 date2.setFocusable(true);
	            	}	
	            	else if( time2.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter person2-time of birth")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 time2.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 time2.setFocusable(true);
	            	}	
	            	
	            	else if(compat.getText().toString().length() == 0  )
	            	{
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage(" Enter compatibility details")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						 compat.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		 compat.setFocusable(true);
	            	}	
	            	else if (! email.getText().toString().matches("[a-zA-Z0-9._-]+@[a-z]+\\.[a-z]+"))
	                {
	            		 alt_bld.setTitle("Alert Message");
	            		 alt_bld.setMessage("Please enter valid email address")
	            		 .setCancelable(false)
	            					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            					 public void onClick(DialogInterface dialog, int id) {
	            						email.requestFocus(); 
	            					 }
	            					 });
	            		 AlertDialog alert = alt_bld.create();
	            		 alert.setTitle("Alert Message");
	            		 alert.setIcon(R.drawable.alert);
	            		 alert.show();
	            		email.setFocusable(true);
	                }
	            	else if(!(conemail.getText().toString().length() == email.getText().toString().length()))
	            	{
	            		alt_bld.setTitle("Alert Message");
	            		alt_bld.setMessage("Please enter correct confirmation email address")
	            		.setCancelable(false)
	            		.setPositiveButton("OK", new DialogInterface.OnClickListener() {
	            			public void onClick(DialogInterface dialog, int id) {
	            				conemail.requestFocus(); 
	            			}
	            		});
	            		AlertDialog alert = alt_bld.create();
	            		alert.setTitle("Alert Message");
	            		alert.setIcon(R.drawable.alert);
	            		alert.show();
	            		conemail.setFocusable(true);
	            	}	


	            	else if( !(fullname.getText().toString().length() == 0)  ||!(city.getText().toString().length() == 0) ||!(state.getText().toString().length() == 0) ||!(date.getText().toString().length() == 0)||!(time.getText().toString().length() == 0)|| !country.getSelectedItem().toString().equals("--Select--")||!(email.getText().toString().length() == 0) ||! !(conemail.getText().toString().length() == 0)|| !(pcity.getText().toString().length() == 0)|!(pcountry.getSelectedItem().toString().length() == 0)||!(full2.getText().toString().length() == 0)  ||!(city2.getText().toString().length() == 0) ||!(state2.getText().toString().length() == 0) ||!(date2.getText().toString().length() == 0)||!(time2.getText().toString().length() == 0)|| !coun2.getSelectedItem().toString().equals("--Select--") ||!(compat.getText().toString().length() == 0)  )
	            	{
	            		
	            		
	            		 try {   
                      	   
	            			 GMailSender sender = new GMailSender(user,format,"Compatibility Reading - Confirmation Details  - findyourfate.com apps");
			                  
	            		//	 sender.sendMail("Names Correction - Confirmation Details  - findyourfate.com apps",  format,                              user,                                   "analyst@findyourfate.com");  
			                   } catch (Exception e) {   
				                         Log.e("SendMail", e.getMessage(), e);   
				                     }
				            		 
	            	 	 Intent intent = new Intent(getActivity(), 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("10.00"), "USD", "Compatibility Reading - Payment Confirmation Details - findyourfate.com Apps");
	     	            	
	            	        Intent intent1 = new Intent(getActivity(), 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);
	            	 

	            	}
				}

		private void startService(Intent intent) {
			// TODO Auto-generated method stub
			
		}
           });
       		
        edittext=(EditText)rootView.findViewById(R.id.dateofbirth); 
        edittext1=(EditText)rootView.findViewById(R.id.birth); 
        timer=(EditText)rootView.findViewById(R.id.time); 
        timer1=(EditText)rootView.findViewById(R.id.timer); 
        final Calendar myCalendar = Calendar.getInstance();

        
        final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                // TODO Auto-generated method stub
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabel();
            }
            private void updateLabel() {

	            String myFormat = "dd/MM/yyyy"; //In which you need put here
	            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

	            edittext.setText(sdf.format(myCalendar.getTime()));
	             }
	          };
        final DatePickerDialog.OnDateSetListener date2 = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                // TODO Auto-generated method stub
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabel();
            }
            private void updateLabel() {

	            String myFormat = "dd/MM/yyyy"; //In which you need put here
	            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

	            edittext1.setText(sdf.format(myCalendar.getTime()));
	            
	            }
	           };
        edittext.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    new DatePickerDialog(getActivity(), date, myCalendar
                            .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                            myCalendar.get(Calendar.DAY_OF_MONTH)).show();
                }
            });
           edittext1.setOnClickListener(new OnClickListener() {

               @Override
               public void onClick(View v) {
                   // TODO Auto-generated method stub
                   new DatePickerDialog(getActivity(), date2, myCalendar
                           .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                           myCalendar.get(Calendar.DAY_OF_MONTH)).show();
               }
           });

           timer.setOnClickListener(new OnClickListener() {

	             @Override
	             public void onClick(View v) {
	                 // TODO Auto-generated method stub
	                 Calendar mcurrentTime = Calendar.getInstance();
	                 int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
	                 int minute = mcurrentTime.get(Calendar.MINUTE);
	                 TimePickerDialog mTimePicker;
	                 mTimePicker = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
	                     @Override
	                     public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
	                    	 if(selectedHour < 12) {
	                             am_pm = "AM";
	                         } else {
	                             am_pm = "PM";
	                         }
	                         timer.setText( "" + selectedHour + ":" + selectedMinute+ "" + am_pm);
	               
	                     }
	                 }, hour, minute, true);
	                 mTimePicker.setTitle("Select Time");
	                 mTimePicker.show();

	             }
	         });
           timer1.setOnClickListener(new OnClickListener() {

	             @Override
	             public void onClick(View v) {
	                 // TODO Auto-generated method stub
	                 Calendar mcurrentTime = Calendar.getInstance();
	                 int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
	                 int minute = mcurrentTime.get(Calendar.MINUTE);
	                 TimePickerDialog mTimePicker;
	                  mTimePicker = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
	                     @Override
	                     public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
	                    	 if(selectedHour < 12) {
	                             am_pm = "AM";
	                         } else {
	                             am_pm = "PM";
	                         }
	                         timer1.setText( "" + selectedHour + ":" + selectedMinute+ "" + am_pm);
	               
	                     }
	                 }, hour, minute, true);
	                 mTimePicker.setTitle("Select Time");
	                 mTimePicker.show();

	             }
           });
      
        mDrawerList = (Spinner)rootView.findViewById(R.id.spinner1);  
        mDrawerList1 = (Spinner)rootView.findViewById(R.id.spinner2);  
         counspin = (Spinner)rootView.findViewById(R.id.ctspinner);
       
        String[] items = getResources().getStringArray(R.array.country_array);
    
        final ArrayList<String> list = new ArrayList<String>();
         for (int i = 0; i < items.length; ++i) {
           list.add(items[i]);
         }
         
         final StableArrayAdapter adapter = new StableArrayAdapter(getActivity(),android.R.layout.simple_spinner_dropdown_item, list);
         
         mDrawerList.setAdapter(adapter);
         mDrawerList1.setAdapter(adapter);
         counspin.setAdapter(adapter);
          return rootView;  
              }  
	class StableArrayAdapter extends ArrayAdapter<String> {

	    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

	    public StableArrayAdapter(Context context, int textViewResourceId,
	        List<String> objects) {
	      super(context, textViewResourceId, objects);
	      for (int i = 0; i < objects.size(); ++i) {
	        mIdMap.put(objects.get(i), i);
	      }
	    }

	    @Override
	    public long getItemId(int position) {
	      String item = getItem(position);
	      
	      return mIdMap.get(item);
	    }

	    @Override
	    public boolean hasStableIds() {
	      return true;
	    }

	  }
	
	 public void onActivityResult (int requestCode, int resultCode, Intent data) {
         if (resultCode == Activity.RESULT_OK) {
             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.");
             getActivity().finish();
             Intent int_spa = new Intent(getActivity(),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.");
         }
     }
	 @Override
	    public void onDestroy() {
	        stopService(new Intent(getActivity(), PayPalService.class));
	        super.onDestroy();
	    }
	private void stopService(Intent intent) {
		// TODO Auto-generated method stub
		
	}
	} 