/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){

	$('a.delete_ref_btn').live('click',function(){
		
		$.getJSON(
			siteUrlAdmin+$(this).attr("id"),
			function(response){
				var innerContent = '<ol class="fieldset article-list clearfix">';
				if (response.length > 0) {
					for(ind=0; ind<response.length; ind++) {
						innerContent+= '<li class="field"><a href="#"> '+response[ind].title+' </a> <span><a href="#" class="delete_ref_btn" id="myaccount/deletereference/'+response[ind].user_alert_id+'">Delete</a></span></li>';
					}
				}
				else {
					innerContent+= '<li>None</li>';
				}
				innerContent+= '</ol>';
				
				$('#listContainer').html(innerContent);
				
			}
		);
		return false;
	});

	$('#nocontact').click(function(){
		if($('#nocontact').attr('checked')) {
			$('#email').attr("checked", "");
			$('#sms').attr("checked", "");
		}
	});

    $('#email').click(function() {
        $('#nocontact').attr("checked", "");
    });
    
    $('#sms').click(function() {
        $('#nocontact').attr("checked", "");

    });


      $('input[value=Update]').click(function (){
         
      
            
           if($('#sms').attr('checked')) {

                phone1 = $('input#phone1').val();
                phone2 = $('input#phone2').val();
                phone3 = $('input#phone3').val();
                phone4 = $('input#phone4').val();

                if (phone2.length == 3 && phone3.length == 3 && phone1.length <= 2 && phone4.length == 4){
                    cellphone = phone1+phone2+phone3+phone4;

                    if ((/^\d+$/).test(cellphone))
                    {
                        error = false;
                    } else {
                        error = true;
                    }

                } else { error = true; }

                if (error){
                      alert("The cell phone is invalid");
                      return false;
                } else {
                       return true;
                }


           }

      });

});
   