﻿

var currentDialog = null;


function GetCity(province,ddlCity)
{
   var cityCtrl = $(ddlCity);
   
   PW35COM.Web.EasyWebBase.Get_City(province,GetCityCallBack);

function GetCityCallBack(response)
{
      if(response.error != null){window.alert('服务器忙请您稍后再试'); return;}

      var al = response.value
      
       while( cityCtrl.length>0 ) 
       {
          cityCtrl.remove(0); 
       }
       
       for(var i=0; i<al.length; i++)
       {
           var values = al[i].split('^');
   
           cityCtrl[cityCtrl.length]=new Option( values[1], values[0]);
       }
}
}


function searchFriend()
{
   var url = 'FSearchList.aspx?action=search'
   
   if($F('ddlCity'))
   {
      url = url + '&citycode=' + $F('ddlCity')
   }

   if($F('ddlUpperAge'))
   {
      url = url + '&upperage=' + $F('ddlUpperAge') 
   }

   if($F('ddlLowerAge'))
   {
      url = url + '&lowerage=' + $F('ddlLowerAge')    
   }

  if($F('ddlGender') != 2 )
  {
      url = url + '&gender=' + $F('ddlGender') 
  }

   window.location.href = url;
}

function searchFriendCtrl()
{
   var url = 'FSearchList.aspx?action=search'
   
   if($F('SearchFriend1_ddlCity'))
   {
      url = url + '&citycode=' + $F('SearchFriend1_ddlCity')
   }

   if($F('SearchFriend1_ddlUpperAge'))
   {
      url = url + '&upperage=' + $F('SearchFriend1_ddlUpperAge') 
   }

   if($F('SearchFriend1_ddlLowerAge'))
   {
      url = url + '&lowerage=' + $F('SearchFriend1_ddlLowerAge')    
   }

   if($F('SearchFriend1_ddlGender') != 2 )
   {
      url = url + '&gender=' + $F('SearchFriend1_ddlGender') 
   }

   window.location.href = url;
} 



function marque(width,height,marqueName,marqueCName){

	   this.marqueesHeight = height;
	   this.stopscroll     = false;
       this.currentTop     = 0;
	   this.stoptime       = 0;
	   this.preTop     = 0; 
	   this.currentTop = 0; 
	   
	   this.scrollElem     = $(marqueName);                //document.getElementById(marqueName);
	   
	   this.scrollElem.style.width     =  width;
	   this.scrollElem.style.height    =  this.marqueesHeight;
	   this.scrollElem.style.overflow  = 'hidden';
	   this.scrollElem.noWrap          =  true;
	   

//	  scrollElem.onmouseover = new Function('stopscroll = true');
//	  scrollElem.onmouseout  = new Function('stopscroll = false');

	  this.stop =  function()
	  {
	     this.stopscroll = true;
	  }
	  
      this.run = function()	  
	  {
	     this.stopscroll = false;
	  }
	  
	  this.init_srolltext = function()
	  {
	     Event.observe(this.scrollElem,'mouseover',this.stop.bind(this));
	     Event.observe(this.scrollElem,'mouseout', this.run.bind(this));
	    
	     this.scrollElem.scrollTop = 0;
         setInterval(this.scrollUp.bind(this), 24);
	  }
	  
	  this.scrollUp = function()
	  {
        if(this.stopscroll) return;
         
         this.currentTop += 1;
         if(this.currentTop == this.marqueesHeight+1) 
         {
           this.stoptime += 1;
           this.currentTop -= 1;
           if(this.stoptime == (this.marqueesHeight)*4) 
              {//停顿时间
                this.currentTop = 0;
                this.stoptime = 0;
              }
         }
         else
         {
             this.preTop = this.scrollElem.scrollTop;
             this.scrollElem.scrollTop += 1;
             if(this.preTop == this.scrollElem.scrollTop)
             {
               this.scrollElem.scrollTop = this.marqueesHeight;
               this.scrollElem.scrollTop += 1;
             }
         }
      }
	  
	  this.leftElem = $(marqueCName);
	  this.scrollElem.appendChild($(marqueCName).cloneNode(true));
		  
	  this.init_srolltext();
  }
  
 function displaySendMessageDialog(from,to,nickname)
  {
      $('msgReciver').innerHTML = '<span>' + nickname + '</span>';
      $('txtTitle').value = '';
      $('sendMessageDialog').senderID = from;
      $('sendMessageDialog').reciverID = to;
      $('msgText').value        = '';
  
      displayDivModelDialog('ia','sendMessageDialog');
   } 
  
   function sendMessage()
   {
      var error = false;
      
      clearInfo('txtTitle')   
      if($F('txtTitle').strip() == '')
      {
         error = true;
         writeInfo('txtTitle','不能为空',null);
      }
      else if($F('txtTitle').strip().length > 30)
      {
         error = true;
         writeInfo('txtTitle','字数不能超过30个',null);
      }
      
      clearInfo('msgText')
      if($F('msgText').strip() == '')
      {    
         error = true;
         writeInfo('msgText','不能为空',null);
      }
      else if($F('msgText').strip().length > 200)
      {
         error = true;
         writeInfo('msgText','字数不能超过30个',null);
      }
   
      if(error)return !error
   
     PW35_Home.findFriend.Garden_FindFriend_BasePage.SendMessage( $('sendMessageDialog').senderID,$('sendMessageDialog').reciverID,$F('txtTitle').strip(),$F('msgText').strip(),sendMessageCallBack)
   
      closeDivModelDialog('ia','sendMessageDialog');
      
      return true;
   }
  
   function sendMessageCallBack(response)
   {
       if(response.error != null){window.alert(response.error); return;}
   
       window.alert(response.value);
   }
 
 
  function displayValidateFriendDialog(from,to,nickname)
  {
      $('validateMsgReciver').innerHTML = '<span>' + nickname + '</span>';
      $('validateFriendDialog').senderID = from;
      $('validateFriendDialog').reciverID = to;
      $('validateMsg').value           = '';
  
      displayDivModelDialog('ia','validateFriendDialog');
  }
  
  function sendValidateFriendInfo()
  {
      var error = false;
      
      clearInfo('validateMsg')
      if($F('validateMsg').strip() == '')
      {    
         error = true;
         writeInfo('validateMsg','不能为空',null);
      }
      else if($F('validateMsg').strip().length > 200)
      {
         error = true;
         writeInfo('validateMsg','字数不能超过30个',null);
      }
   
      if(error)return !error
   
     PW35_Home.findFriend.Garden_FindFriend_BasePage.SendValidateInfo($('validateFriendDialog').senderID,$('validateFriendDialog').reciverID, $F('validateMsg').strip(),sendValidateFriendInfoCallBack)
   
      closeDivModelDialog('ia','validateFriendDialog');
      
      return true;    
  }
  
  function sendValidateFriendInfoCallBack(response)
  { 
       if(response.error != null){window.alert(response.error); return;}
   
       window.alert(response.value);
  }
 
 
  function addFriend(from,to)
  {
     PW35_Home.findFriend.Garden_FindFriend_BasePage.addFriend(from,to,addFriendCallBack);
  }
  
  function addFriendCallBack(response)
  {
       if(response.error != null){window.alert(response.error); return;}
   
       window.alert(response.value);
  }
   
  function sendMail()
  {
     displayDivModelDialog("ia","invitefriend");
  }
  

  function showShowBroadCast(id)
  {
      $("showbroadcast_wait").style.display="";
      $("showbroadcast_content").style.display="none";
  
      displayDivModelDialog("ia","showbroadcast");   
      
      getBroadCast(id);
  }
  
  function getBroadCast(id)
  {
     PW35_Home.findFriend.Garden_FindFriend_BasePage.GetBroadCastByID(id,getBroadCastCallBack);
  }
  
  function getBroadCastCallBack(response)
  {
       if(response.error != null){window.alert(response.error); return;}
       
       var al = response.value
  
       $('showbroadcast_content_broadcast').innerHTML = al[0];
       $('showbroadcast_content_username').innerHTML = al[1];
       
       $('showbroadcast_content').style.display = "";
       $("showbroadcast_wait").style.display    ="none";
  }
  
  
  function displayDivModelDialog(backgroupDiv,dialogDiv)
  {
       if(navigator.appName=="Microsoft Internet Explorer"){
           var pageOption=document.getElementsByTagName("select");
			for(var i=0;i<pageOption.length;i++){
				pageOption[i].style.visibility = "hidden";
			}
		}
      
      var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body; 
      
      $(backgroupDiv).style.display = 'block';
      $(dialogDiv).style.display = 'block';
      //document.getElementsByTagName('html')[0].style.overflow="hidden"
  
      var bodyClientWidth  = $(bdy).clientWidth;
      var bodyClientHeight = $(bdy).clientHeight;
 
      $(backgroupDiv).style.height = ((bdy.scrollHeight>bodyClientHeight)?bdy.scrollHeight:bodyClientHeight)+"px";
      $(backgroupDiv).style.width  = ((bdy.scrollWidth>bodyClientWidth)?bdy.scrollWidth:bodyClientWidth)+"px";
     
      var bodyScrollTop     =  bdy.scrollTop
  
      var dialogTop    =  (bodyClientHeight - $(dialogDiv).offsetHeight)/2;  
      
      var dialogLeft   =  (bodyClientWidth - $(dialogDiv).offsetWidth)/2;
       
      //var dialogScrollTopAndTop = bodyScrollTop + dialogTop
  
      //(新)加入滚动相对定部的做标     
      
       $(dialogDiv).dialogTop = dialogTop
      
      dialogTop = bodyScrollTop + dialogTop

      if( dialogLeft < bdy.scrollLeft)
      {
          dialogLeft = bdy.scrollLeft
      }
  
      if( dialogTop < bdy.scrollTop )
      {
          dialogTop = bdy.scrollTop
      }
  
      var computedialogLeft = bdy.clientWidth - $(dialogDiv).offsetWidth  +  bdy.scrollLeft
  
      var computedialogTop  = bdy.clientHeight - $(dialogDiv).offsetHeight +  bdy.scrollTop 
  
      if(dialogLeft>computedialogLeft)dialogLeft = computedialogLeft;
  
      if(dialogTop>computedialogTop)dialogTop = computedialogTop;
 
      $(dialogDiv).style.left = dialogLeft + "px";
  
      $(dialogDiv).style.top  = dialogTop  + "px";
  
      //设置当前对话框     
      
       currentDialog = $(dialogDiv);
  }
     function closeDivModelDialog(backgroupDiv,dialogDiv)
  {
         currentDialog = null;
        
         if(navigator.appName=="Microsoft Internet Explorer")
          {
            var pageOption=document.getElementsByTagName("select");
			for(var i=0;i<pageOption.length;i++){
				pageOption[i].style.visibility = "visible";
			}
		}
        
        $(backgroupDiv).style.display = 'none';
        $(dialogDiv).style.display = 'none'; 
       
        //document.getElementsByTagName('html')[0].style.overflow="auto"
  }
  
 
 function writeInfo(id, info,color)
 {
    if($(id) == null)
      return;
   
    if($(id).nextSibling != null && $(id).nextSibling.infoType == 'info')
    {
       $(id).nextSibling.innerHTML = info
    }
    else
    { 
       errorElement = document.createElement('span');
       
       errorElement.style.backgroundColor =  'orange'   //color;
       
       errorElement.innerHTML = info;
    
       errorElement.infoType = 'info' 
       
       if($(id).nextSibling != null)
       {
         if($(id).parentNode == null)return; 
          $(id).parentNode.insertBefore(errorElement,$(id).nextSibling)
       }
       else
       {
          if($(id).parentNode == null)return;
          $(id).parentNode.appendChild(errorElement);
       }
    }
 }

function clearInfo(id)
{
  if( !($(id).nextSibling == null || $(id).nextSibling.infoType == 'undefined')  )
  {
     if($(id).nextSibling.infoType == 'info')
     {
         if($(id).parentNode == null)return;
         $(id).parentNode.removeChild($(id).nextSibling)
     }
  }
}

window.onscroll = function(){

   if(currentDialog == null)return;

   var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body; 
    
   currentDialog.style.top  = ( bdy.scrollTop +  currentDialog.dialogTop)+'px'; 

}

