﻿$(document).ready(function(){
				
       _initLogin();
	   
	   _initKeyup();
	   
	   _initFinddream();

})
function  _initLogin(){
	
   $("#butLogin").click(function(){
								 
	   var name;
	   
	   var pass;
	   
	   name = $(".login-left input:first").val();
	   
	   pass = $(".login-left input:last").val();
	   
	   if(name==""||pass=="")
	   {
		  alert("请输入用户名和密码");   
	   }
	   else
	   {
		     <!-- start -->
						$.post(
					   "/login/login",
						{name:name,pass:pass},
						 function(msg)
							{
							  if(msg=="nouser")
							  {
								 $(".login-left input:first").val("");
								 
								 $(".login-left input:last").val("");
								 
								 alert("此用户不存在");
							 }
							 else if(msg=="nopasswd")
							 {
								  alert("密码错误,请重新输入密码");
								  
								  $(".login-left input:last").val("");
							 }
							 else
							 {  
							     if(url=="")
								 {
							        window.location.href = '/'+msg;
								 }
								 else if(url=="garden")
								 {
								   window.location.href = '/'+msg+'/manage/dreamadd';
								 }
								 else
								 {
								    window.location.href = url;
								 }
							 }
					    });
			  <!-- end -->
	   }
	
	})
}
function _initKeyup(){
	
	if($.browser.msie)
	{
	    $(document).keyup(function(){
			if(window.event.keyCode==13)
			{
			   $("#butLogin").click();
			}	
		})
	}
	else
	{
          $(document).keydown(function(event){
									   
			  if(event.keyCode==13){ 					 
			      $("#butLogin").click();
			  }
	      })
	}
}

function _initFinddream(){
	
	$(".collection a:last").click(function(){
		   <!-- start -->
				$.getJSON(
			   "/action/randdream",
				 function(msg)
					{
						if(msg.id>0&&msg.domain!="")
						{
							 window.location.href = '/'+msg.domain+'/dream/dream/mid/'+msg.id;
					    }
						else
						{
							 window.location.href = '/willprouds';
						}
					}
				);
           <!-- end -->							   
	})

}

function AddFavorite(sURL,sTitle) {

       try{
            window.external.addFavorite(sURL, sTitle);
       }
       catch (e)       
	   {
         try         
		   {
                window.sidebar.addPanel(sTitle, sURL, "");
           }

           catch (e){

               alert("加入收藏失败，请使用Ctrl+D进行添加");
           }

       } } 



function AddFavorite(sURL,sTitle) {

       try{
            window.external.addFavorite(sURL, sTitle);
       }
       catch (e)       
	   {
         try         
		   {
                window.sidebar.addPanel(sTitle, sURL, "");
           }

           catch (e){

               alert("加入收藏失败，请使用Ctrl+D进行添加");
           }

 } } 
