
var email_service_url = "/service.php?option=email_page";
var email_share_webservice_url = SITEROOT + "/webservices/email"; 
var context_root = "AmgenWyethApp-NewEnbrelProj-context-root";
var loader = SITEROOT + "/images/shell/loader.gif";	
var email_popup_containter = '<div id="email_page_popup" class="standard_popup" style="display:none; position: absolute;"> \
<div id="standard_popup_iefix"></div> \
<a href="#" id="top_button" class="canceller"><img src="'+SITEROOT+'/images/shell/btn_close_x.gif" /></a> \
<div class="inner_iefix"></div><div class="inner"> \
<h1>E-mail this page to a friend.</h1><br/>\
<p>Enter your e-mail address, your friend\'s e-mail address,<br/>and click the Send Button.</p> \
<div id="error_popup_msg" class="error_msg">Please correct the fields marked in red</div> \
<br/> \
<div class="error_container"> \
<label>Your E-mail</label> \
<input name="your_email" id="your_email"  type="text" class="text val_required val_email" maxlength="255" /> \
</div><div class="error_container"> \
<label>Friend\'s E-mail</label> \
<input name="friend_email" id="friend_email" type="text" class="text val_required val_email" maxlength="255" /><div id="loader_image"/> \
</div> \
<br/><img src="'+SITEROOT+'/images/shell/btn_submit_whitebg.gif" class="rollover" id="submit_email" style="margin: 0 0 -3px -4px;"/> \
<br/> \
<p><div class="footnote">Amgen and Pfizer will not use this information for any other purpose.</div></p> \
<input name="page" id="page" type="hidden" class="text" maxlength="255" /> \
</div> \
<div class="bottom_iefix"></div><div class="bottom"></div> \
</div>';

var email_success_popup_containter = '<div id="email_success_popup_containter" class="standard_popup" style="display:none; position: absolute;"> \
<div id="standard_popup_iefix"></div> \
<a href="#" id="top_button" class="canceller"><img src="'+SITEROOT+'/images/shell/btn_close_x.gif" /></a> \
<div class="inner_iefix"></div><div class="inner"> \
<h2 class="email_success">Your e-mail was sent successfully.</h2><br/>\
<br/> \
<a href="#" class="more" style="margin: 0 0 3px -0;">SEND ANOTHER E-MAIL</a><br/> \
<a href="#" class="canceller">RETURN TO ENBREL.COM</a> \
</div> \
<div class="bottom_iefix"></div><div class="bottom"></div> \
</div>';

var email_page_init = function()
{
        //alert("inside email_page_init");
	// insert the container
	 $('div#main').after(email_popup_containter);
	 $('div#main').after(email_success_popup_containter);
	 // add click events

	 $('div#email_page_popup input#page')[0].value= document.location.href;
	 $('ul#utility_nav li.email').click(function() {
            utilityTrack('emailFriend');
            //show_email_pop();
         });
	// $('div#email_page_popup img#submit_email').click(send_email);
         
         
         
         $('div#email_page_popup img#submit_email').click(function(e)
	 {	
             if (validate_popup_form()) {
                send_email();
	 	e.preventDefault();
             }
          });

         
         
	 //$('img#submit_email').click(send_email);
         
}

var show_email_pop = function(e)
{
	$('div#email_page_popup a.canceller').click(hide_interstitial);
	evokeModalDialog.setBgColor("#FFFFFF");
	evokeModalDialog.show("email_page_popup");
}

var hide_email_pop = function(e)
{

}


var email_show_result = function(data){
}


var send_email = function(e)
{
    var p_to = $('div#email_page_popup input#friend_email').val();
    var p_from = $('div#email_page_popup input#your_email').val();
    //alert(" to :" + p_to +  " from :" +  p_from);
            //if (validate_popup_form()) {
            //if((p_to != null && p_to.length > 0) && (p_from != null && p_from.length > 0)){
                $("div#loader_image").html("<center><img src=\"" + loader + "\"\/></center>");
                var params = "";
                params = "?frm_email_To=" + p_to
                params += "&frm_email_From=" + p_from;
                params += "&frm_email_AppForm=" + "application_share";
                params += "&frm_email_Page=" + window.location;
                //alert("window.location="+window.location);
                try {
                      $.getJSON(email_share_webservice_url + params, email_show_result);
                        $("div#loader_image").html("");
                } catch(error){
                      alert('email webservice error: '+error)
                }
                        
            //} else {
                //alert("show error state");
//                return false;
            //}

	evokeModalDialog.hide();
	 $('div#email_success_popup_containter a.more').click(function(e)
	 {	
	 	e.preventDefault();
	 	
                //$('div#email_page_popup input#friend_name')[0].value = "";
                $('div#email_page_popup input#your_email')[0].value = "";
                $('div#email_page_popup input#friend_email')[0].value = "";
                evokeModalDialog.hide();
                show_email_pop();
             });


	 $('div#email_success_popup_containter a.canceller').click(hide_interstitial);
	evokeModalDialog.setBgColor("#FFFFFF");
	evokeModalDialog.show("email_success_popup_containter");
}



var check_service_sitesearch = function(){
    //restful service call getsearchterms
    //alert("check_service_sitesearch");
    var term = $('input#search_box_results').val();
    //alert("service call as : " + gs_service_url + params);
    
    if(term != null && term.length > 0){
        //alert("term=" + term);
        var params = "";
        var psz = $('select#page_size_sitesearch').val();
        params = "?terms=" + term + params;
        params += "&pagesize=" + psz;
        params += "&startpage=" + current_page;
        try {
              $.getJSON(search_service_url + params, sitesearch_show_result);
        } catch(error){
              alert('error:'+error)
        }
    } else {
        //alert("no search term?");
        $("div#search_pages").html("");
    }
    
}

