// JavaScript Document

 $(document).ready(function() {
                    
					$("#btnSignup").click(function () {
						$.prompt(
txt,{callback: mycallbackform, loaded: checkall,
								 submit: mysubmitfunc,
								 buttons: { Subscribe:true }
								}); 
					});
					$("#lnkUnsub").click(function () {
						$.prompt(
txt2,{callback: mycallbackform,
								 submit: mysubmitfunc2,
								 buttons: { Unsubscribe:true }
								}); 
					});
					
					
               });

var txt = '<h3  >Register for Alerts</h3>Email:&nbsp;<input type="text" id="email"  name="email" value="" /><table style="margin:20px 0 0 0;"><tr><th>Choose Your Alerts</th><th></th></tr><tr><td>Receive All:</td><td><input type="checkbox" id="chkAll" name="chkAll"  value="1"></td></tr><tr><td width="120px"><b>Investors Releases:</b></td><td><input type="checkbox" id="investor" name="investor" value="1"></td></tr><tr><td><b>Press Releases:</b></td><td>Select Country</td></tr><tr><td>Asia</td><td><input type="checkbox" name="CountryId" value="1" /></td></tr><tr><td>Australia</td><td><input type="checkbox" name="CountryId" value="2" /></td></tr><tr><td>Canada</td><td><input type="checkbox" name="CountryId" value="3" /></td></tr><tr><td>China</td><td><input type="checkbox" name="CountryId" value="4" /></td></tr><tr><td>Europe</td><td><input type="checkbox" name="CountryId" value="5" /></td></tr><tr><td>Ireland</td><td><input type="checkbox" name="CountryId" value="6" /></td></tr><tr><td>New Zealand</td><td><input type="checkbox" name="CountryId" value="7" /></td></tr><tr><td>Singapore</td><td><input type="checkbox" name="CountryId" value="8" /></td></tr><tr><td>United Kingdom</td><td><input type="checkbox" name="CountryId" value="9" /></td></tr><tr><td>United States</td><td><input type="checkbox" name="CountryId" value="10" /></td></tr></table>';

var txt2 = 'Email: &nbsp;<input type="text" id="unsubemail"  name="unsubemail" value="" />';
function mysubmitfunc(v,m,f){
	
      an = m.children('#email');
	  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
      if(f.email == "" || !emailReg.test(f.email) ){
            an.css("border","solid #ff0000 1px");
            return false;
      };
	
		if ($("input:checked").length==0){

            $("input:checkbox").css("border","solid #ff0000 1px");
            return false;
      };
	  $.post("/common/service/act_subscribeemail.cfm",
   				{ email: f.email,investor: f.investor,CountryId:f.CountryId},
   					function(data){
								   
							
							an.after('<b>Success</b><p>Your email address has subscribed.</p>');											
						
   					}
				 );
      return true;
} 
function mysubmitfunc2(v,m,f){
	
      an = m.children('#unsubemail');
	  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
      if(f.unsubemail == "" || !emailReg.test(f.unsubemail) ){
            an.css("border","solid #ff0000 1px");
            return false;
      };
	  $.post("/common/service/act_subscribeemail.cfm",
   				{ unsubemail: f.unsubemail},
   					function(data){
								   
							
							an.after('<b>Success</b><p>Your email address has unsubscribed.</p>');											
						
   					}
				 );
      return true;
} 
function mycallbackform(v,m,f){
	if(v != undefined)
	$.prompt('Thank You!');
}

function checkall(v,m,f){
	$('#chkAll').click(	   function(){
						   $("input[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
						   })
}

jQuery.fn.center = function () { 
    this.css("position","absolute"); 
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); 
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); 
    return this; 
} 


