﻿//js定义类型
var regList = {
	code:/^\d{1,6}?$/,
	number:/^[0-9]*$/,
	pcode:/^((\d{1,15})|(\d{1,18})|(\d{1,17}x))?$/,
	mobile:/^1[358]\d{9}$/,
	tell:/^((0[0-9]{2,3})-)(\d{7,8})?$/,
	username:/^[0-9a-zA-Z\u4e00-\u9fa5(_)(@)]*$/,
	vcode:/^[A-Za-z0-9]{4}$/,
	password:/^[A-Za-z0-9~`!@#$%\^&\*()\=\+_\-\.]*$/,
	chinese:/^[\u4e00-\u9fa5]*$/,
	url:/[A-Za-z0-9_\-\.\/\:]*$/,
	price:/^[0-9\.]*$/,
	mail:/^[\w-]+(\.[\w-]+)*@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/,
	kongge:/(^\s*)|(\s*$)/g,
	faifa:/([.\\n]*){5,200}/,
	zip:/^[0-9]{6}$/
}

//取得字符长度
function JHshStrLen(sString)
{
var sStr,iCount,i,strTemp;
iCount = 0 ;
sStr = sString.split("");
for (i = 0 ; i < sStr.length ; i ++)
{
strTemp = escape(sStr[i]);
if (strTemp.indexOf("%u",0) == -1) // 表示是汉字
{
iCount = iCount + 1 ;
}
else
{
iCount = iCount + 2;
}
}
return iCount ;
}

function tiaozhuan(spath)
{

window.location.href=''+ spath+'';

}
/*------前台添加购物车 ------*/


function shoppingcart(url)
{
	$.ajax({
		type: "post",
		url: url,
		success: function(msg){
						window.location.href=''+ msg +'';
				 
		                       }
	
	})
	
}

	/*------前台ajax无提示，无返回 ------*/
function ajax_noback(url,flag)
{
	$.ajax({
		type: "post",
		url: url,
		success: function(msg){			 
		if(flag==1)
		{
		window.location.href='/shtml/checkout.htm';	
		}
		
				  
		                       }
	
	})
	
}

	/*------前台搜索分类显示 ------*/
function getAjaxSelectData(url,id){	
	$.ajax({
		type: "post",
		url: url,
		beforeSend:function(){
		     document.getElementById(id).length=0;
				document.getElementById(id).options[0]=new Option('---数据读取中...---','');
		},
		success: function(msg){ 
			   var returnData=msg;
					var returnDataLineArr;
					var returnDataArr=returnData.split("||");
                       document.getElementById(id).disabled=false;
					for(var i = 0; i <= returnDataArr.length-1; i++) {
						returnDataLineArr=returnDataArr[i].split("|");
						document.getElementById(id).options[i]=new Option(returnDataLineArr[1], returnDataLineArr[0]);
				
				
				}
		}
	
	})
	 
}
	/*------前台加载loading函数 ------*/

function getxponse(url,id){
	$.ajax({
		type: "post",
		url: url,
		beforeSend:function(){
			$("#"+id)[0].innerHTML="<div class='loading'> </div>";
		},
		success: function(msg){
		  
			   document.getElementById(id).innerHTML=msg;
		                       },
							   
	    error: function()
               {
                  $("#"+id)[0].innerHTM="查询出错，请重试";
				    
               }					   
	
	})
}
 	/*------前台加载loading函数 ------*/
//flag ,0不显示进度，1图片方式，2文字方式
function get_loading(url,id,flag){
	$.ajax({
		type: "post",
		url: url,
		 
		beforeSend:function(){
			if(flag==1)
			{
				$("#"+id)[0].innerHTML="<div class='loading'> </div>";
			}
			else if(flag==2)
			{
				$("#"+id).text("数据查询中... ...");
				
			}
			
		},
		 
		success: function(msg){
		  
			   $("#"+id)[0].innerHTML=msg;
		                       }
	
	})
}
 
	/*------前台购物车调用 ------*/
function ajax_shopping()
{
	eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6 5="/1/2.3?4=0";',62,7,'1|ajax|ajax_shopping|ashx|flag|myurl|var'.split('|'),0,{}))
	
 	$.ajax({
		type: "post",
		url: myurl,
		success: function(msg){ 
		                          $("#shopping_str")[0].innerHTML=msg;
		                        }
	
	})
}

/*------前台html调用 ------*/
function get_html_ajax(url,id)
{
	 	
		
 	$.ajax({
		type: "post",
		url: url,
		success: function(msg){ 
		                        
							 
								document.getElementById(id).innerHTML=msg;
								
							 
		                        }
	
	})
		
}



/*------前台分类菜单调用 ------*/

function emotion_(i,flag)
{
	 $("#pp"+i)[0].style.display="none";
	if(flag==2)
	{
	   $("#p"+i)[0].style.display="block"
	}
 
	
  
}



function setMoutTimeOut_(i,flag)
{	
  if(flag==2)
	{
       $("#p"+i)[0].style.display="none"
	}
	
	$("#pp"+i)[0].style.display="block"
}


function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
	value=value+"|";
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
	var ss=getCookie(name);
	if(ss.indexOf(value) == -1)
	{
		document.cookie = name + "="+ss+ escape (value) + ";expires=" + exp.toGMTString();
	}
	
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function remove_css(id,css)
{
	
	$(id).removeClass(css).html("");
}
 function loadcity(shengid){
         
         if(shengid!="")
         {
		   getAjaxSelectData("/ajax/ajax_city.ashx?flag=checkshi&shengid="+ shengid +"","user_info_city");
		   document.getElementById("user_info_xian").disabled="false";
		  
		  }
		  else
		  {
		  document.getElementById("user_info_city").disabled="false";
		  document.getElementById("user_info_xian").disabled="false";
		  }
		  
		  
                             
        }
		function loadxian(shengid){
         
        if(shengid!="")
         {
		    document.getElementById("user_info_xian").disabled="true";
		  getAjaxSelectData("/ajax/ajax_city.ashx?flag=xian&shengid="+ shengid +"","user_info_xian");
		  
		  }
		  else
		  {
		  document.getElementById("user_info_xian").disabled="false";
		  
		  }
        
                  
        }


function cssmenu(id)
{
  
  for(var i=1;i<=9;i++)
  {
	
	if(i==id)
	   {
		 $("#cssdata"+id).addClass("href_first"+id);
		}
		else
		
		{
			
			 $("#cssdata"+i).removeClass("href_first"+i);
		}
	
	  
  }

	
}

 
$(document).ready(function() {
 
 try
 {
 
 
			 for(var i=1;i<=9;i++)
			 {
				 
				 if(i==4)
				    {
			     $('#cssdata'+i).mouseover(function () {                
				             $("#p_menu").removeClass("hide");
                     });
			 
			    }
				else
				{
			  $('#cssdata'+i).mouseover(function () {                
				             $("#p_menu").addClass("hide");
                     });
			
			  $('#cssdata'+i).mouseout(function () {                
				             $("#p_menu").addClass("hide");
                     }); 
			  
			  $("#p_menu").mouseout(function () {                
				             $("#p_menu").addClass("hide");
                     }); 
			 }
			 }
			 
			 }
			 catch(e)
			 {}
			 
			 
			 })
 
 
 
 function fav_dell(id)
 {

			$.ajax({
		type: "post",
		url: "/ajax/add_fav.ashx?flag=shanchu&id="+ id +"",
		success: function(msg){
						if(msg!="")
						{
							window.location.href=msg;
							
							}
						else
						{
					        window.location.href='/user/user_favorite.htm';
						}
		                       }
	
	})	 
	 
}

function js_number_ch(str)
{
	str= str.toFixed(2);
	return str;
}
function ip_sx(str,s)
{
getxponse("/ajax/xian_ip.ashx?ipstr="+ str +"",s);

}
