﻿// JScript 文件
///url是地址，2  Eid 元素ID
function Ajax(url,Eid)
{
    this.xmlHttp;
    function createXmlHttpRequest()
    {
        if(window.ActiveXObject)
        {
           try {xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");}
      catch (e){
                try {xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
              }
         }
        else if(window.XMLHttpRequest)
        {
            xmlHttp= new XMLHttpRequest();
            if (xmlHttp.overrideMimeType){xmlHttp.overrideMimeType("text/xml");}
         }
    }
    function callback()
    {  
        if(xmlHttp.readyState==4)
            if(xmlHttp.status==200)
            {
            if(document.getElementById(Eid)!=null){
            document.getElementById(Eid).innerHTML=xmlHttp.responseText;}
            }
    }
    createXmlHttpRequest();
    xmlHttp.open("get",url,true);
    xmlHttp.onreadystatechange=function(){callback();}
    xmlHttp.send(null);
    
}


//根据地址返回值
function AjaxUpdateImgName(url)
{
var valOK="1";
    function createXmlHttpRequest()
    {
        if(window.ActiveXObject)
        {
            return new ActiveXObject("Msxml2.XMLHTTP");
         }
        else if(window.XMLHttpRequest)
        {
            return new XMLHttpRequest();
         }
    }
    
    function callback()
    {  
        if(xmlHttp.readyState==4)
            if(xmlHttp.status==200)
            {
            if(xmlHttp.responseText!=null && xmlHttp.responseText!="undefined")
            valOK=xmlHttp.responseText;
            
            }
            
    }
    var xmlHttp=createXmlHttpRequest();
    xmlHttp.onreadystatechange=function(){callback();}
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
    return valOK;
}

var timerID = null
var timerRunning = false
function MakeArray(size) 
{
    this.length = size;
    for(var i = 1; i <= size; i++)
    {
        this[i] = "";
    }
    return this;
}
function stopclock (){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false
}
function showtime () {
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var day = now.getDay();
    Day = new MakeArray(7);
    Day[0]="星期天";
    Day[1]="星期一";
    Day[2]="星期二";
    Day[3]="星期三";
    Day[4]="星期四";
    Day[5]="星期五";
    Day[6]="星期六";
    var timeValue = "";
    //timeValue +=  year + "年";
    timeValue += ((month < 10) ? " " : "") + month + "月"+date+"日  ";
    timeValue += (Day[day]) + " ";
    timeValue += ((hours <= 24) ? hours : hours - 12);
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    //timeValue += (hours < 12) ? " AM" : " PM";
    document.getElementById("NowTime").innerHTML = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true
}
function startclock() {
    stopclock();
    showtime()
}

function setCookie(name, value) //cookies设置 
{ 
var argv = setCookie.arguments; 
var argc = setCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null; 
if(expires!=null) 
{ 
var LargeExpDate = new Date (); 
LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
} 
document.cookie = name + "=" + escape(value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString())); 
}


//取cookies值
function getCookie(name){
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	    else return null;
}
//取cookies值
function GetCookie2(Name)
{
   var search2 = Name + "=";
   var returnvalue = "";
   if (document.cookie.length > 0) 
   {
      offset = document.cookie.indexOf(search2);
   if (offset != -1)
   { 
   offset += search2.length;
         end = document.cookie.indexOf(";", offset); 
   if (end == -1)
            end = document.cookie.length;
         returnvalue=unescape(document.cookie.substring(offset,end));
       }
    }
    return returnvalue;
}
//----用户退出或登录
function login()
{
    if(GetCookie2("user")=="" && GetCookie2("userCName")=="")
    {
        window.location.href="/member/login.aspx?url="+window.location.href;
   }
   else
   {
   var url=""+Math.random();
   url=url.substr(2,4);
   window.location.href="/indexout1"+url+".html";
    //window.location.href="/index.aspx?out=1"+Math.random();
   }
}
function loginDIV()
{
    openLayer('/UserControl/LoginDIV.aspx','用户登录','380','160');
}
//-------------

///邮政编码
function codeId(str)
{
    reg=/\d{6}/
    return reg.test(str);
}
///手机号码
function phoneId(str)
{
    reg=/^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15[89]\d{8}$/;
    return reg.test(str);
}
///固定电话
function firm_phone(str)
{
    reg=/(\(\d{3}\)|\d{3}-)?\d{6}/;
    return reg.test(str);
}
//Email邮箱
function MailId(str)
{
    reg=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    return reg.test(str);
}
//是否存在中文
function IsChina(str)
{
// 正则表达式对象
 var re = new RegExp("[\\u4e00-\\u9fa5]", "");
 // 验证是否刚好匹配
 var yesorno = re.test(str);
return yesorno;

//    reg=[\u4e00-\u9fa5];
//    return reg.test(str);
}
//设置文本为空
function setText(obj,val)
{
    if(obj.value==val)
    {
        obj.value="";
    }
}
//设置文本不为空
function blurText(obj,val)
{
    if(obj.value=="")
    {
        obj.value=val;
    }
}

//中文转换成拼音
function trans(){
	var cc=document.form1.code.value;
	var str='';
	var s;
	for(var i=0;i<cc.length;i++){
	//alert(cc.charAt(i)+" = "+cc.charCodeAt(i));
		if(pydic.indexOf(cc.charAt(i))!=-1&&cc.charCodeAt(i)>200){
			s=1;
			while(pydic.charAt(pydic.indexOf(cc.charAt(i))+s)!=","){
				str+=pydic.charAt(pydic.indexOf(cc.charAt(i))+s);
				s++;
			}

			str+=" ";
		}
		else{
			str+=cc.charAt(i);
		}
	}
	return str;
}

//动态建 iframe
function CreateIFrameDIV(url,width,height)
{

   HiddenInput();
   var src=url;
   var sWidth,sHeight; 
   sWidth=parent.document.body.offsetWidth; 
   sHeight=parent.document.body.offsetHeight<window.screen.availHeight?window.screen.availHeight+20:parent.document.body.offsetHeight+20;

   var bgObj=parent.document.createElement("div"); 
   bgObj.setAttribute('id','bgDivIFrame'); 
   bgObj.style.position="absolute"; 
   bgObj.style.top="0"; 
   bgObj.style.background="#cccccc"; 
   bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=2,opacity=90,finishOpacity=40)"; 
   bgObj.style.opacity="0.6"; 
   bgObj.style.left="0"; 
   bgObj.style.width=sWidth + "px"; 
   bgObj.style.height=sHeight + "px"; 
   bgObj.style.zIndex = "10000"; 
 
   parent.document.body.appendChild(bgObj);  

   var Form=parent.document.createElement("div"); 
   Form.setAttribute('id','FormDiv'); 
   Form.style.position="absolute"; 
   Form.style.top="25%";
   Form.style.marginTop = -75+document.documentElement.scrollTop+"px";
   Form.style.background="#FFFFFF"; 
   Form.style.border="3px solid #F7DA9B";
   Form.style.left=(sWidth-width)/2; 
   Form.style.width=width + "px"; 
   Form.style.height=height + "px"; 
   Form.style.zIndex = "10001"; 
   Form.innerHTML="<iframe id='openFrame' src='"+src+"' frameborder='0' scrolling='no' width='"+width+"' height='"+height+"' style='margin:5px'/>";
   parent.document.body.appendChild(Form);
                    
}
function movepage2()
{
    parent.document.body.removeChild(parent.document.getElementById("bgDivIFrame"));
    parent.document.body.removeChild(parent.document.getElementById("FormDiv"));
    ShowInput();
}

//隐藏页面下拉控件
function HiddenInput()
{
     var objs = document.getElementsByTagName("select"); 
     for(i=0;i<objs.length;i++)
     {
      objs[i].style.display='none';;
     }
}

function ShowInput()
{
     var objs = document.getElementsByTagName("select"); 
     for(i=0;i<objs.length;i++)
     {
      objs[i].style.display='';
     }
}

function copyUrl()
{ 
    var clipBoardContent=this.location.href;
    window.clipboardData.setData("Text",clipBoardContent);
    alert("复制成功!");
} 
   
//获得对像
function GetObj(objName){
if(document.getElementById){
return eval('document.getElementById("' + objName + '")');
}else if(document.layers){
return eval("document.layers['" + objName +"']");}
else{return eval('document.all.' + objName);}
}

function AddUser()//刷新用户是否在线
{
    var userExist;
    try{userExist = new ActiveXObject("MSXML2.XMLHTTP");}catch (e){
        userExist= new ActiveXObject("Microsoft.XMLHTTP");}
    userExist.open("get","/Ajax/userExist.aspx?temp="+Math.random(), true);
    userExist.send(null);
}
AddUser();
setInterval("AddUser();", 360000);

//按回车执行的按键
function Ryankeydown(btnId){
if(event.keyCode==13)
{
 document.getElementById(btnId).click();
if(event.preventDefault) event.preventDefault();
else{event.returnValue=false};
}
}
function search(obj)
{
    var searchValue=GetObj(obj).value;
    if(searchValue!="" && searchValue!="产品关键字")
    {
        AjaxUpdateImgName("/Ajax/MenuTree.aspx?AddSearch="+searchValue);//记录搜索信息
        if(IsChina(searchValue))
        window.location.href="/member/Search.aspx?key="+encodeURIComponent(searchValue);
        else
        window.location.href="/member/Search.aspx?SearchProNO="+encodeURIComponent(searchValue);
    }
    else
    alert("请输入搜索内容！");
    
    if(event.preventDefault) event.preventDefault();
    else{event.returnValue=false};
}
function searchTextKey(obj)
{
    document.getElementById("searchKey").innerText=document.getElementById(obj).title;
    displaysearch();
}
function displaysearch()
{
    if(document.getElementById("searchUL").style.display=="none")
    document.getElementById("searchUL").style.display="block";
    else
    document.getElementById("searchUL").style.display="none";
}

//这个方法必须调用   /TopicShare/JS/jquery-1.3.2.min.js   这个JS文件
function btnSutClick(txtContent,op){
        var param={'context':encodeURI($("#"+txtContent).val())};
        //var param = $("#form1").serialize();  //序列化表单
         $.post("/hander/CategoryProduct.ashx?op="+op+"&ss="+Math.random(),param,function(data){
            $("#txtGetContent").val(decodeURI(eval(data)));
        });
}
//如果没有登录就问是否登录
var existuser="0";
function ExistLogin()
{
    if(GetCookie2("user")=="" && existuser!="1")
    if(confirm("请您登录或注册后才能进行此操作！"))
        loginDIV();
    existuser="1";
}

function createCookie(name,value,days,Tdom){
var Tdom=(Tdom)?Tdom:"/";
if(days){
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();}else{
var expires="";}
document.cookie=name+"="+value+expires+"; path="+Tdom;}
function readCookie(name){
var nameEQ=name+"=";
var ca=document.cookie.split(';');
for(var i=0;i<ca.length;i++){
var c=ca[i];
while(c.charAt(0)==' '){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}}
return null;}

//分享到指定的网站上去
function shareWeb(id)
{
    if(id==1)
    window.open("http://v.t.sina.com.cn/share/share.php?title="+encodeURIComponent(window.location.href)+"&url="+encodeURIComponent(document.title)+"&source=bookmark&appkey=2992571369","_blank");//新浪微薄
    if(id==2)
    window.open("http://www.kaixin001.com/repaste/share.php?rtitle="+encodeURIComponent(document.title)+"&rurl="+encodeURIComponent(window.location.href)+"&rcontent="+encodeURIComponent(document.title)+"","_blank");//开心网
    if(id==3)
    window.open("http://share.renren.com/share/buttonshare.do?link="+encodeURIComponent(window.location.href)+"&title="+encodeURIComponent(document.title)+"","_blank");//人人网
    if(id==4)
    window.open("http://www.douban.com/recommend/?url="+encodeURIComponent(window.location.href)+"&title="+encodeURIComponent(document.title)+"","_blank");//豆瓣
}
function RoleKeyWord(obj)
{
    var roleStr="\\,/,:,*,<,>,|,;".split(",");
    var IsOk=true;
    for(var i=0;i<roleStr.length;i++)
    {
        if(obj.value.indexOf(roleStr[i])>0)
        {
            IsOk=false;
            obj.value=obj.value.replace(roleStr[i],"");
        }
    }
    if(!IsOk)
    {alert("输入框不能输特殊字符如“\\,/,:,*,<,>,|,;”");obj.focus();}
}
