     function Check( reg, str )
    {
	    if( reg.test( str ) ){return true;}
	    return false;
    }
    //判断邮箱合法性
    function checkeamil( str )
    {
	    var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	    return Check( reg, str );
    }

    jQuery.fn.extend({
  RemoveAddCSS: function(css) {
    return this.each(function()
     {     $(this).removeClass().addClass(css);    });
  }
});    
/*打分效果*/
function over(Grade)
{
var rating=Grade.data.rat;
var offerid=Grade.data.OfferID;
for(var i=1;i<=10;i++)
{
if(i<=rating)
    if((i%2)==0)
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/rmove.png");
   else
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/lmove.png");
else
    if(i%2==0)
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/rout.png");
   else
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/lout.png");
}
$("#ratmsg"+offerid).text(rating);
}

function out(event)
{
var offerid=event.data.OfferID;
var rating=$("#hidGrade_"+offerid).text();
for(var i=1;i<=10;i++)
{
if(i<=rating)
    if((i%2)==0)
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/rmove.png");
   else
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/lmove.png");
else
    if(i%2==0)
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/rout.png");
   else
        $("#Rat_"+offerid+"_"+i).attr("src","/images/rating/lout.png");
}
$("#ratmsg"+offerid).text(rating);
}

function Ratclick(event)
{
//$("#hidGrade_"+event.data.OfferID).text(event.data.rat)
var offerid=event.data.OfferID;
var rat=event.data.rat;
$.getJSON("/Ajax/AjaxRate.ashx",{OfferID:offerid,Rating:rat},function(json){
//$("#showrat_"+offerid).fadeOut(300); 
$("#showrat_"+offerid).hide();
$("#showrat_"+offerid).html("");
for(var i=1;i<=10;i++)
{
if(i<=json.rating)
    if((i%2)==0)
      $("#showrat_"+offerid).append("<img src='/images/rating/rmove.png' />");
   else
      $("#showrat_"+offerid).append("<img src='/images/rating/lmove.png' />");
else
    if(i%2==0)
        $("#showrat_"+offerid).append("<img src='/images/rating/rout.png' />");
   else
       $("#showrat_"+offerid).append("<img src='/images/rating/lout.png' />");
}

$("#showrat_"+offerid).fadeIn(700); 
//$("#hiderat_"+offerid+">div").eq(1).fadeOut(100); 
$("#hiderat_"+offerid+">div").eq(1).hide();
if(json.msg=="ok")
$("#hiderat_"+offerid+">div").eq(1).html("Thank you! Your vote has been registered.");
else
$("#hiderat_"+offerid+">div").eq(1).html("Sorry, you can only rate an offer once a month.");
$("#hiderat_"+offerid+">div").eq(1).fadeIn(700); 
}); 
}

 $(document).ready(function(){
$("img[out]").mouseover(function(){
$(this).attr("src","images/"+$(this).attr("over"))
}).mouseout(function(){
$(this).attr("src","images/"+$(this).attr("out"))
}); 
   $("#btnsearch").css("cursor","pointer").click(function(){
      if($("#txtsearch").val()!="")
               window.location="Search_"+$("#txtsearch").val().replace(" ","_")+".aspx";
            else
            {
            alert('not empty');
            $("#txtsearch").focus();
            }
      });

//隐藏,显示
$(".showrat").each(function(){
$(this).click(function(){
$("#"+$(this).attr("show")).slideToggle(400);
});
});
$(".hiderat").each(function(){
$(this).click(function(){
$("#"+$(this).attr("hide")).slideUp(400);
});
});

$("div[OfferID]>img").not("[OfferID]").attr("align","absbottom").each(function(){
$(this).bind("mouseover",{rat: $(this).attr("value"),OfferID:$(this).parent().attr("OfferID")},over).bind("mouseout",{OfferID:$(this).parent().attr("OfferID")},out).bind("click",{rat:$(this).attr("value"),OfferID:$(this).parent().attr("OfferID")},Ratclick).css("cursor","pointer"); 
});

  var chk_n=true;
        var chk_ye=true;
        var chk_fe=true;
var chk_name;
var chk_youemail;
var chk_friendemai;
//Name    
$(":input[fname]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("fname")).text("Please enter your name.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("fname")).text("Your name can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_n=false;
            }
	        else
	        {
	                $("#"+$(this).attr("fname")).text("OK").RemoveAddCSS("OkMsg");
	                chk_n=true;
	                chk_name=$(this).val();
            }
    });
});

//YouEmail    
$(":input[fyouemail]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("fyouemail")).text("Please enter your email.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("fyouemail")).text("Your email can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_ye=false;
            }
	        else
	        {
	        if(checkeamil($(this).val()))
	                {
	                $("#"+$(this).attr("fyouemail")).text("OK").RemoveAddCSS("OkMsg");
	                chk_ye=true;
	                  chk_youemail=$(this).val();
	                }
	                else
	                {
	                $("#"+$(this).attr("fyouemail")).text("Your email is invalid.").RemoveAddCSS("ErrorMsg");
	                chk_ye=false;
	                }
            }
    });
});

//FriendEmail    
$(":input[ffriendemail]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("ffriendemail")).text("Please enter your friend's email.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("ffriendemail")).text("Your friend's email can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_fe=false;
            }
	        else
	        {
	        if(checkeamil($(this).val()))
	                {
	                $("#"+$(this).attr("ffriendemail")).text("OK").RemoveAddCSS("OkMsg");
	                chk_fe=true;
	                 chk_friendemai=$(this).val();
	                }
	                else
	                {
	                $("#"+$(this).attr("ffriendemail")).text("Your friend's email is invalid.").RemoveAddCSS("ErrorMsg");
	                chk_fe=false;
	                }
            }
    });
});

       
      $("img[btnfriend]").each(function(){
      $(this).click(function(){

      var lname=$(this).attr("btnfriend");
      var p_title=$("a[email='"+lname+"']").attr("title");
      var p_url=$("a[email='"+lname+"']").attr("href");
      $("#txtName_"+lname+","+"#txtYouEmail_"+lname+","+"#txtFriendEmail_"+lname).trigger('blur');
                      if( chk_n && chk_ye && chk_fe){
                    $.get("/Ajax/AjaxEmail.ashx", { Name: chk_name, From:chk_youemail,To:chk_friendemai,Title:p_title,Url:p_url}); 

                    $("#tb_"+lname).parent().append("<div class=\"divtt\">Thank you! An email has been sent to your friend.</div>");
                    $("#tb_"+lname).html("");
                }
                else{
                        return false;
                }
      
      }).css("cursor","pointer");
      }); 
   
   
   $("img[showtab]").each(function(){
   $(this).click(function(){
 
   if($(this).attr("showtab")=="Popular")
   {
   $("#Popular").show();
   $("#Recent").hide();
   $("#Picked").hide();
   $("img[showtab=Popular]").attr("src","Images/default_project_popularoffers_on.png");
   $("img[showtab=Recent]").attr("src","Images/default_project_recentoffers.png");
   $("img[showtab=Picked]").attr("src","Images/default_project_pickedoffers.png"); 
    
   if($("#spPopular").html()=="0")
{
$.get("/Ajax/AjaxPopular.aspx", function(data){
$("#Popular").html(data);
newbind();
$("#spPopular").html("1");
}); 
}
   }
   else if($(this).attr("showtab")=="Recent")
   {
   $("#Popular").hide();
   $("#Recent").show();
   $("#Picked").hide();
      $("img[showtab=Popular]").attr("src","Images/default_project_popularoffers.png");
   $("img[showtab=Recent]").attr("src","Images/default_project_recentoffers_on.png");
   $("img[showtab=Picked]").attr("src","Images/default_project_pickedoffers.png");
   }
   else
   {
   $("#Popular").hide();
   $("#Recent").hide();
   $("#Picked").show();
      $("img[showtab=Popular]").attr("src","Images/default_project_popularoffers.png");
   $("img[showtab=Recent]").attr("src","Images/default_project_recentoffers.png");
   $("img[showtab=Picked]").attr("src","Images/default_project_pickedoffers_on.png");
   if($("#spPicked").html()=="0")
{  
$.get("/Ajax/AjaxPicked.aspx", function(data){
$("#Picked").html(data);
newbind();
$("#spPicked").html("1");
}); 
}

   }

   });
   }).css("cursor","pointer");

//ready结束
  });

function newbind()
{
$("img[out]").mouseover(function(){
$(this).attr("src","images/"+$(this).attr("over"))
}).mouseout(function(){
$(this).attr("src","images/"+$(this).attr("out"))
}); 
   $("#btnsearch").css("cursor","pointer").click(function(){
      if($("#txtsearch").val()!="")
               window.location="Search_"+$("#txtsearch").val().replace(" ","_")+".aspx";
            else
            {
            alert('not empty');
            $("#txtsearch").focus();
            }
      });

//隐藏,显示
$(".showrat").each(function(){
$(this).click(function(){
$("#"+$(this).attr("show")).slideToggle(400);
});
});
$(".hiderat").each(function(){
$(this).click(function(){
$("#"+$(this).attr("hide")).slideUp(400);
});
});

$("div[OfferID]>img").not("[OfferID]").attr("align","absbottom").each(function(){
$(this).bind("mouseover",{rat: $(this).attr("value"),OfferID:$(this).parent().attr("OfferID")},over).bind("mouseout",{OfferID:$(this).parent().attr("OfferID")},out).bind("click",{rat:$(this).attr("value"),OfferID:$(this).parent().attr("OfferID")},Ratclick).css("cursor","pointer"); 
});

//Name    
$(":input[fname]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("fname")).text("Please enter your name.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("fname")).text("Your name can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_n=false;
            }
	        else
	        {
	                $("#"+$(this).attr("fname")).text("OK").RemoveAddCSS("OkMsg");
	                chk_n=true;
	                chk_name=$(this).val();
            }
    });
});

//YouEmail    
$(":input[fyouemail]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("fyouemail")).text("Please enter your email.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("fyouemail")).text("Your email can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_ye=false;
            }
	        else
	        {
	        if(checkeamil($(this).val()))
	                {
	                $("#"+$(this).attr("fyouemail")).text("OK").RemoveAddCSS("OkMsg");
	                chk_ye=true;
	                  chk_youemail=$(this).val();
	                }
	                else
	                {
	                $("#"+$(this).attr("fyouemail")).text("Your email is invalid.").RemoveAddCSS("ErrorMsg");
	                chk_ye=false;
	                }
            }
    });
});

//FriendEmail    
$(":input[ffriendemail]").each(function(){
 $(this).focus(function(){
            $("#"+$(this).attr("ffriendemail")).text("Please enter your friend's email.").RemoveAddCSS("ClkMsg");
        }).blur(function(){
                if($(this).val()=="")
            {
        	        $("#"+$(this).attr("ffriendemail")).text("Your friend's email can not be empty!").RemoveAddCSS("ErrorMsg");
	                chk_fe=false;
            }
	        else
	        {
	        if(checkeamil($(this).val()))
	                {
	                $("#"+$(this).attr("ffriendemail")).text("OK").RemoveAddCSS("OkMsg");
	                chk_fe=true;
	                 chk_friendemai=$(this).val();
	                }
	                else
	                {
	                $("#"+$(this).attr("ffriendemail")).text("Your friend's email is invalid.").RemoveAddCSS("ErrorMsg");
	                chk_fe=false;
	                }
            }
    });
});

       
      $("img[btnfriend]").each(function(){
      $(this).click(function(){

      var lname=$(this).attr("btnfriend");
      var p_title=$("a[email='"+lname+"']").attr("title");
      var p_url=$("a[email='"+lname+"']").attr("href");
      $("#txtName_"+lname+","+"#txtYouEmail_"+lname+","+"#txtFriendEmail_"+lname).trigger('blur');
                      if( chk_n && chk_ye && chk_fe){
                    $.get("/Ajax/AjaxEmail.ashx", { Name: chk_name, From:chk_youemail,To:chk_friendemai,Title:p_title,Url:p_url}); 

                    $("#tb_"+lname).parent().append("<div class=\"divtt\">Thank you! An email has been sent to your friend.</div>");
                    $("#tb_"+lname).html("");
                }
                else{
                        return false;
                }
      
      }).css("cursor","pointer");
      }); 
}