
$(document).ready(function(){

var user_is_on_iphone = navigator.userAgent.match(/like Mac OS X/i);

if (user_is_on_iphone) { return; }


/**********This builds the form  ********************************/

$("body").append('<div id="container_reg" style="display:none"><div id="top"> <input class="closebtn" id="close" src="http://eyeondelivery.net/APG_Play/images/buttom.gif" type="image"/></div><div class="reg" id="reg"><form id="form" name="form" method="post"><table align="center" border="0" cellpadding="0" cellspacing="0" width="520" ><tbody><tr><td>Email*<label class="error" id="email_error">This field is invalid</label></td></tr> <tr><td><input name="email" id="email" class="input" size="55" type="text"/></td></tr><tr><td>First Name<label class="error" id="firstname_error">This field is invalid</label</td></tr><tr><td><input name="firstname" id="firstname" class="input" size="55" type="text"/></td> </tr> <tr><td>Last Name<label class="error" id="lastname_error">This field is invalid</label> </td></tr><tr><td><input name="lastname" id="lastname" class="input" size="55" type="text"a /></td></tr><tr><td class="zzz">*required</td></tr><tr><td><input name="Submit" id="submit_btn" src="http://eyeondelivery.net/APG_Play/images/submitBtn" class="btn" value="SUBMIT" type="image" /> </td></tr> </tbody></table></form></div> <div id="bottom"><input src="http://eyeondelivery.net/APG_Play/images/clickToClose.png" name="Click to Close" value="Click to Close" class="closebtn" type="image"/> </div> </div><div id="thankYouContainer" class="thankYouContainer"><div id="thankyou"><input src="http://eyeondelivery.net/APG_Play/images/buttom.gif" class="closeThankYou" id="close2" type="image"/></div> <div id="bottom2"><input name="Click to Close" src="http://eyeondelivery.net/APG_Play/images/clickToClose.png" value="Click to Close" class="closeThankYou2" type="image"/></div></div>'); 

/****************************************************************************************************/









/***************This adds style to the elements of the form ***********************************/  

$("#container_reg").css({'position' : 'absolute','bottom' : '0','margin-right' : '0','right' : '0','width' : '520px'});

$("#thankYouContainer").css({'position' : 'absolute', 'bottom' : '0', 'margin-right' : '0', 'right' :'0', 'width' :'520px'});

$(".zzz").css({'font-size':'11px'}); 

$(".input").css({'background-color':'#e2ded','border':'none','height':'15px','width':'384px'}); 

$("#close").css({'position':'relative','right':'-480px','width':'15px','height':'15px','background-image':'url(http://eyeondelivery.net/APG_Play/images/buttom.gif)','background-repeat':'no-repeat','margin-top':'10px','margin-right':'10px','border':'none'});

$("#close2").css({'position':'relative','right':'-480px','width':'15px','height':'15px','background-image':'url(http://eyeondelivery.net/APG_Play/images/buttom.gif)','background-repeat':'no-repeat','margin-top':'10px','margin-right':'10px','border':'none'});

$("#top").css({'width':'520px','height':'241px','background-image':'url(http://eyeondelivery.net/APG_Play/images/AP-PopOver-9.gif)','background-repeat':'no-repeat'});

$("#reg").css({'position':'relative','width':'520px','height':'200px','float':'left','background-color':'#7f6b6b'});

$("#form table").css({'width':'520px','height':'110px','float':'left','font-size':'14px','color':'white','padding-left':'70px','margin-top':'10px'}); 

$("#bottom").css({'width':'520px','height':'39px','float':'left','background-color':'#e2dede','text-align':'center','color':'#4e4e50','padding-top':'20px'});

$("#bottom2").css({'width':'520px','height':'39px','float':'left','background-color':'#e2dede','text-align':'center','color':'#4e4e50','padding-top':'20px'});

$("#submit_btn").css({'height':'23px'});

$("#thankyou").css({'width':'520px','height':'396px','background-image':'url(http://eyeondelivery.net/APG_Play/images/AP-PopOver-9.1.gif)','background-repeat':'no-repeat'});

$("label.error").css({'font-weight':'normal','color':'red','width':'140px'}); 

/*********************************************************************************/



  //alert("so this is working kinda");

  

  $('.error').hide();

  $("#thankYouContainer").hide();









/***This handles the close buttons for the regular window and the thank you window*****/

     $(".closebtn").click(function() {



// no idea what in the world insertXClose.php does, but it always throws an error...

//         $.ajax({

//               type: "POST",

//                url:"http://eyeondelivery.net/APG_Play/insertXClose.php",

//                success: function() {

//                        $('#container_reg').hide();

//             }

//          });



	$('#container_reg').hide();



         return false; 

     });

    $(".closeThankYou").click(function(){

           $('#thankYouContainer').hide();

           return false;

    }); 

    $(".closeThankYou2").click(function(){

        $('#thankYouContainer').hide();

        return false;

     }); 

/*******************************************************************************************/

   







     if($('#container_reg').is(':hidden')){

          $('#container_reg').slideDown(1500); 

     }

     else{

          $('#container_reg').slideUp(1500); 

}











    



/*******************submit button clicked yay********************************************/     

$(".btn").click(function() {

        //alert("so the button was clicked"); 

/*Validation checking*/

      var email = $("input#email").val(); 

             var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

             if(email==""){

                  $("label#email_error").show();

                  $("input#email").focus(); 

                  return false; 

             }

            if(!emailReg.test(email)){

                  $("label#email_error").show(); 

                  $("input#email").focus(); 

                  return false; 

             }

        var fname = $("input#firstname").val(); 

             if(fname==""){

                   $("label#firstname_error").show();

                   $("input#firstname").focus();

                   return false;

             }



        

        var lname = $("input#lastname").val(); 

             if(lname==""){

                    $("label#lastname_error").show(); 

                    $("input#lastname").focus();

                    return false; 

             }

/*inputting all the info into insert*/ 

        var dataString = 'fname=' + fname + '&lname=' + lname + '&email=' +email;

        //alert(dataString); 

    $.ajax({

          type: "POST",

          url:"http://eyeondelivery.net/APG_Play/insert.php",

          data: dataString, 

          success: function() {

                $('#container_reg').fadeOut(1000); 

                $('#thankYouContainer').fadeIn(1000);

          },

          error:function (xhr, ajaxOptions, thrownError){

                $('#container_reg').fadeOut(1000); 

                $('#thankYouContainer').fadeIn(1000);

        } 

     });

    

    return false; 





    });

/********************************************************************************************/





 



});
