﻿/// <reference path="jquery-1.2.6.js" />
var ExBeauty = {
  _width: 192,
   _speed: 300,
  //发表评论
  CheckComment:function(form) {
      if ($("#ddl_EnvironmentLevel").val().length == 0) {
		    alert("请选择环境的点评分！");
		    $("#ddl_EnvironmentLevel").focus();
		    return false;
  	  }
  	  if ($("#ddl_ServiceLevel").val().length == 0) {
		    alert("请选择服务的点评分！");
		    $("#ddl_ServiceLevel").focus();
		    return false;
  	  }
  	   if ($("#ddl_PriceLevel").val().length == 0) {
		    alert("请选择价位的点评分！");
		    $("#ddl_PriceLevel").focus();
		    return false;
  	  }
  	  if ($("#content").val().length == 0) {
		    alert("内容不能为空！");
		    $("#content").focus();
		    return false;
  	  }
  		if ($("#content").val().length > 300) {
		    alert("内容太长了！");
		    return false;
	    }
  		if (form.hidename1==null) {
		     tb_show('','#TB_inline?height=400&width=680&inlineId=div_Review_Login&modal=true',false);
		    return false;
  	  }
	  var data = $("#commentForm").serialize();
    UserOpr.submitForm("commenting.ashx",data);
  },
  //回复内容
  reviewFocus:function(id){
    if(location.href.toLowerCase().indexOf("default.aspx")==-1){
        location.href="Default.aspx?id="+id+"#review";
    }else{
       location.href="#review";
    }
    document.getElementById("content").focus();
 },
  //根据省获得城市
  getCity:function(countryID){
    $.get("BeautyIndex.aspx?cid="+countryID+"&action=getCity&"+Math.random()*100000,function(list){
      var arry1 = list.split(",");
      ExBeauty.ddlRemoveAllItem('DropDownList2');
      document.getElementById("DropDownList2").add(new Option("请选择城市",""));
      for(var i=0;i<arry1.length;i++)
      {
          var text = arry1[i].split("|");
          if(text[0]!="")
          {    
              document.getElementById("DropDownList2").add(new Option(text[0],text[1]));
          }
      }
    });
  },
  ddlRemoveAllItem:function(ddl){
          document.getElementById(ddl).length=0;
  }
}

var UserOpr={
 _flag:false,
 //表单提交
 submitForm:function(url,data){
    if(UserOpr._flag)return;
    UserOpr._flag = true;
    $.post(url, data,function(val){
        if(val=="ok"){
          location.replace(location.href);
        }else{
          alert(val);
        }
        UserOpr._flag = false;
    });
 },
 loginValidate:function(){
   if ($("#txt_userName").val().length == 0) {
	    alert("请填写您的用户名！");
	    $("#txt_userName").focus();
	    return false;
	  }
		  if ($("#txt_pwd").val().length == 0) {
	    alert("请填写您的用户密码！");
	    $("#txt_pwd").focus();
	    return false;
	  }
	  return true;
 },
 //登录
  CheckLogin:function(form){
    if(UserOpr.loginValidate()){
      var data = $("#commentForm").serialize()+"&txt_userName="+$("#txt_userName").val()+"&txt_pwd="+$("#txt_pwd").val();
      UserOpr.submitForm("commenting.ashx",data);
    }
  },
  //注册
  CheckReg:function(form){
    var txt_name = $('#txt_name').val();
    var txt_password = $('#txt_password').val();
    var txt_repeat_pwd = $('#txt_repeat_pwd').val();
    var txt_code = $('#txt_code').val();
    var emailReg= /^\w+((-\w+)|(\.\w+)|(\+\w+)|(\.\+\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if (txt_name == '') {
        alert('请输入您的用户名');
        $('#txt_name').focus();
        return false;
    } else if (!(/^([\u4e00-\u9fa50-9A-Za-z_-]{1,20})+$/).test(txt_name) || (/^([0-9])+$/).test(txt_name)) {
        alert('用户名只能由中文、字母、数字、下划线、减号20个字符组成,且不能为纯数字');
        $('#txt_name').focus();
        return false;
    } else if (txt_password == '') {
        alert('请输入密码!');
        $('#txt_password').focus();
        return false;
    } else if (txt_password.length < 6) {
        alert('密码不能少于六位数');
        $('#txt_password').focus();
        return false;
    } else if (txt_repeat_pwd == '') {
        alert('请再次输入密码!');
        $('#txt_repeat_pwd').focus();
        return false;
    } else if (txt_password != txt_repeat_pwd) {
        alert('两次密码不一致，请重新输入');
        $('#txt_repeat_pwd').focus();
        return false;
     }else if($('#txt_email').val()==''){
      alert('请输入您电子邮箱！');
      $('#txt_email').focus();
      return false;
    } else if($('#txt_email').val()!=''&&!emailReg.test($('#txt_email').val())){
       alert('请输入正确的邮箱格式！');
       $('#txt_email').focus();
       return false;
    } else if (txt_code == '') {
        alert('请输入验证码');
        $('#txt_code').focus();
        return false;
    }
    document.getElementById("HideName").value = "0"; //注册用户  明名发送。 1为匿名发送
    var data = $("#commentForm").serialize()+"&txt_name="+$("#txt_name").val()+"&txt_password="+$("#txt_password").val()+"&txt_repeat_pwd="+$("#txt_repeat_pwd").val()+"&txt_code="+$("#txt_code").val()+"&txt_email="+$("#txt_email").val();
    UserOpr.submitForm("commenting.ashx",data);
  }
}

//按比例压缩图
var ImageOpr = {
  flag:false,
  //iwidth 定义允许图片宽度，当宽度大于这个值时等比例缩小
  //iheight 定义允许图片高度，当宽度大于这个值时等比例缩小
  DrawImage:function(ImgD,iwidth,iheight){
    var image=new Image();
    image.src=ImgD.src;
     if(image.width>0 && image.height>0){
        flag=true;
        if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){ 
              ImgD.width=iwidth;
              ImgD.height=(image.height*iwidth)/image.width;
            }else{
              ImgD.width=image.width; 
              ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }
        else{
          if(image.height>iheight){ 
            ImgD.height=iheight;
            ImgD.width=(image.width*iheight)/image.height; 
          }else{
            ImgD.width=image.width; 
            ImgD.height=image.height;
          }
            ImgD.alt=image.width+"×"+image.height;
        }
      }
   }
}


//院店图片动画
function Marquee(name,speed,splittime,width) {  
  this.interval;
  this.timeid1;  
  this.num = 1;
  this.stopscroll = false;
  var self = this;
  var wrapObj = document.getElementById(name + "_wrap");
  var contentObj = document.getElementById(name + "_content");
  var rightObj = document.getElementById(name + "_right");  
  var leftObj = document.getElementById(name + "_left");
  var left_button = document.getElementById(name+"_left_button");
  var right_button = document.getElementById(name+"_right_button");
  this.rank = Math.floor(contentObj.offsetWidth/width);
 
  if(this.rank > 2){
    rightObj.innerHTML = contentObj.innerHTML;
  }

  this.ScrollLeft = function() {
     if(self.stopscroll==true) return;
	   if(rightObj.offsetWidth-wrapObj.scrollLeft<=0){ 
  		  wrapObj.scrollLeft-=contentObj.offsetWidth;	     
	   }else{ 
		  wrapObj.scrollLeft+=speed;
		  
	   } 
	  
  };
  this.ScrollRight = function() {
     if(self.stopscroll==true) return;
     if(rightObj.offsetWidth-wrapObj.scrollLeft>=contentObj.offsetWidth) {
		    wrapObj.scrollLeft+=contentObj.offsetWidth;
     }else{ 
		    wrapObj.scrollLeft-=speed;
	   } 
  };
  this.Start = function() {
    self.interval = setInterval(self.ScrollLeft,1);
  };
  this.StartLeft = function() {
    self.interval = setInterval(self.ScrollLeft,1);
  };
  this.StartRight = function() {
    self.interval = setInterval(self.ScrollRight,1);
  };
  this.Stop = function() {
    clearInterval(self.interval);
    clearTimeout(self.timeid1);
  };
  this.ClickLeft = function() {
    self.Stop();
    self.interval = setInterval(self.ScrollLeft,1);
  }
  this.ClickRight = function() {
    self.Stop();
    self.interval = setInterval(self.ScrollRight,1);
  }
  if(left_button) {
    left_button.onclick = function() { self.ClickLeft(); }
  }
  if(right_button) {
    right_button.onclick = function() { self.ClickRight(); }
  }
  wrapObj.onmouseover = function() { self.stopscroll=true; };
  wrapObj.onmouseout = function() { self.stopscroll=false; };
  self.timeid1 = setTimeout(self.Start,splittime);
}
//漂浮广告
var fixedDiv = {
    stmnGAP1 : 70,
    stmnGAP2 : 325,
    stmnBASE : 800,
    stmnActivateSpeed : 200,
    stmnScrollSpeed : 10,
    stmnTimer:0,
    RefreshStaticMenu:function() {
      var stmnStartPoint, stmnEndPoint, stmnRefreshTimer;
      stmnStartPoint = parseInt(document.getElementById('STATICMENU').style.top, 10);
      stmnEndPoint = document.documentElement.scrollTop + fixedDiv.stmnGAP2;      
      if (stmnEndPoint < fixedDiv.stmnGAP1) stmnEndPoint = fixedDiv.stmnGAP1;      
      stmnRefreshTimer = fixedDiv.stmnActivateSpeed;
      if ( stmnStartPoint != stmnEndPoint ) {      
        stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 15 );
        document.getElementById('STATICMENU').style.top = parseInt(document.getElementById('STATICMENU').style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount );
        //document.getElementById('STATICMENU').style.left = document.documentElement.scrollWidth - fixedDiv.stmnBASE * 2;        
        stmnRefreshTimer = fixedDiv.stmnScrollSpeed;
      }           
      stmnTimer = setTimeout ("fixedDiv.RefreshStaticMenu();", stmnRefreshTimer);
    },
    InitStaticMenu:function() {
      document.getElementById('STATICMENU').style.top = document.documentElement.scrollTop + fixedDiv.stmnBASE;
      document.getElementById('STATICMENU').style.left = document.documentElement.scrollWidth/2 - fixedDiv.stmnBASE/2;
    }
};

//广告图切换效果。
function DivChange(name,splittime,count,ismove,changed_callback)
{
    this.count = count;
    this.splittime = splittime;
    this.now = 0;
    this.name = name;
    this.timeid1;
    this.timeid2;
    this.ismove = ismove;
    this.changed_callback = changed_callback;
    this.next_button = document.getElementById(name+"_next_button");
    this.previous_button = document.getElementById(name+"_previous_button");
    this.isplay = true;
    var self = this;
    this.SetFocus = function() {
		if(self.now>=self.count) self.now=0;
		self.now = self.now+1;
        self.SelectLayer(self.now);
    };
	this.SelectLayer = function(i) {
      for(var j=1;j<=self.count;j++) {
        try
		    {
		    		document.getElementById(name+"_panel_"+j).filters[0].apply();  //by cookie
            document.getElementById(name+"_panel_"+j).filters[0].play();  //by cookie
            if (j==i) {
               
                document.getElementById(name+"_panel_"+j).style.display="block";
                //document.getElementById(name+"__"+j).style.display="block";
            } else {
		        document.getElementById(name+"_panel_"+j).style.display="none";
		        //document.getElementById(name+"_panel_"+j).style.display="block";
            }
        }catch(e)
		    {}
      }
      if(typeof self.changed_callback == "function")
      {
        self.changed_callback(i);
      }
    };
    this.ChangeImg = function() {
        if(self.isplay)
        {
            self.timeid1 = setTimeout(self.SetFocus,self.splittime);
        }
        self.timeid2 = setTimeout(self.ChangeImg,self.splittime);
    };
	this.ChangeImg();
    
    this.Stop = function()
    {
        clearTimeout(this.timeid1);
        clearTimeout(this.timeid2);
    };
    this.Start = function()
    {
        this.ChangeImg();
    };
    this.Reset = function()
    {
        this.Stop();
        this.Start();
    };
    
	if(this.ismove!=1)
	{
        if(this.next_button)
        {
            this.next_button.onclick = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onclick = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onclick = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    else
    {
        if(this.next_button)
        {
            this.next_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onmouseover = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
				    }
				    now_button.onmouseout = function()
				    {
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    for(var j=1;j<=count;j++)
    {
		try
		{
			var now_panel = document.getElementById(name+"_panel_"+j);
			if(now_panel)
			{
				now_panel.onmouseover = function()
				{
					self.Stop();
				}
				now_panel.onmousemove = function()
				{
					self.Stop();
				}
				now_panel.onmouseout = function()
				{
					self.Start();
				}
			}
		}catch(e)
		{}
    }
};

var Cookie = {
    GetValue: function(name) {
        var value = null;
        var cookie = document.cookie;
        var cookies = cookie.split(";");
        $.each(cookies, function(i) { 
            var cookieName = cookies[i].substring(0, cookies[i].indexOf("="));
            if (cookieName.replace(/(^\s*)|(\s*$)/g, "") == name) {
                value = cookies[i].substring(cookies[i].indexOf("=") + 1);
            }
        });
        return value;
    },
    SetValue: function(name, value, expires) {
        document.cookie = name + "=" + escape(value) + (expires == null || expires == undefined ? "" : "; expires=" + expires.toGMTString())
    }
};
