﻿function fnGetWindowWidth(){
    var vh = 0;
    var _dEt = document.documentElement;
    var _dBx = document.body;
    if(typeof window.innerWidth=='number')vh = window.innerWidth;
    else{
      if(_dEt&&_dEt.clientWidth)vh = _dEt.clientWidth;
      else{
           if(_dBx&&_dBx.clientWidth)vh = _dBx.clientWidth;
		    }
       }
    if(!vh||vh<100)vh =100;
     return vh;
}

function fnGetWindowHeight(){
    var vh = 0;
    var _dEt = document.documentElement;
    var _dBy = document.body;
    if(typeof window.innerHeight=='number')vh = window.innerHeight;
    else{
      if(_dEt&&_dEt.clientHeight)vh = _dEt.clientHeight;
      else{
           if(_dBy&&_dBy.clientHeight)vh = _dBy.clientHeight;
		    }
       }
    if(!vh||vh<100)vh =100;
     return vh;
}
function $(obj)
{
	if (typeof(obj) == 'object')
	{
		return obj;
	}
	else
	{
		return document.getElementById(obj);
	}	
}

function Search(txtid, url)
{
    if ($(txtid).value.length > 0)
    {

        window.location.href = url.replace('{$Keyword}', escape($(txtid).value));
    }
}

function KeyupSearch(txtid,url,evt)
{
    evt = window.event ? window.event : evt;
    if (evt.keyCode == 13)
    {
        if ($(txtid).value.length > 0)
        {
            window.location.href = url.replace('{$Keyword}', escape($(txtid).value));
        }
    }
}

/***************************************************
查换子串.
***************************************************/
function Instr(sStr, sSubStr)
{
    var arrCheckedValue = sStr.split(',');
    for (var i=0; i<arrCheckedValue.length; i++)
    {
        if (arrCheckedValue[i] == sSubStr)
        {
            return true;
        }
    }
	return false;
}
function RemoveStr(sStr, sSubStr)
{
	var arrCheckedValue = sStr.split(',');
	var sNewStr = "";
    for (var i=0; i<arrCheckedValue.length; i++)
    {
        if (arrCheckedValue[i] != sSubStr)
        {
            if (sNewStr == "")
            {
				sNewStr = arrCheckedValue[i];
            }
			else
			{
				sNewStr += "," + arrCheckedValue[i];
			}
        }
    }
	return sNewStr;
}

function CheckCommentPost()
{
    if (typeof FCKeditorAPI == 'undefined')
        return false;
    var oEditor = FCKeditorAPI.GetInstance('txtCommentContent');
    var content = oEditor.GetXHTML(true); 
    content = content.replace(/\s/gi,'');
    if (content.length < 1)
    {
        alert('评论内容不能为空哦~');
        return false;
    }
    return true;
}
function CheckReplyPost()
{
    if (typeof FCKeditorAPI == 'undefined')
        return false;
    var oEditor = FCKeditorAPI.GetInstance('txtReplyContent');
    var content = oEditor.GetXHTML(true); 
    content = content.replace(/\s/gi,'');
    if (content.length < 1)
    {
        alert('回复内容不能为空哦~');
        return false;
    }
    return true;
}
function CheckBookPost()
{
    if (typeof FCKeditorAPI == 'undefined')
        return false;
    var oEditor = FCKeditorAPI.GetInstance('txtBookContent');
    var content = oEditor.GetXHTML(true); 
    content = content.replace(/\s/gi,'');
    if (content.length < 1)
    {
        alert('留言内容不能为空哦~');
        return false;
    }
    return true;
}

function ActiveTab(tabID)
{
    $("div1_l1").style.display = 'none';
    $("div1_l2").style.display = 'none';
    $("l1").className = 'TabNavOff';
    $("l2").className = 'TabNavOff';
    $("div1_" + tabID).style.display = 'block';
    $(tabID).className = 'TabNavOn';
}

function ShowShopCommentReply(cid, cityPath)
{
    if ($('fraReply' + cid).style.display == 'block')
    {
        $('fraReply' + cid).style.display = 'none';
    }
    else
    {
        $('fraReply' + cid).style.display = 'block';
    }
    if ($('fraReply' + cid).src == '')
    {
        $('fraReply' + cid).src = cityPath + 'Shop/CommentReply_' + cid + '.shtml';
    }
}
//企业纠错
function DebugCompany(cityPath,cid,cname)
{
    if (!$('DebugControl'))
    {
        var DebugControl = document.createElement("iframe");
        DebugControl.id = 'DebugControl';
        DebugControl.frameBorder = 0;
        DebugControl.allowTransparency = true;
        DebugControl.height = 280;
        DebugControl.width = 380;
        document.body.appendChild(DebugControl);
        
        window.onscroll = function(){
            $('DebugControl').style.top = document.documentElement.scrollTop + 200 + 'px';
            $('DebugControl').style.left = document.body.clientWidth/2 - 200 + 'px';
        }
    }
    else
    {
        DebugControl = $('DebugControl');
    }
    DebugControl.src = cityPath + 'Shop/' + cid + '/Debug/?' + escape(cname);
    DebugControl.style.position = 'absolute';
    DebugControl.style.display = 'block';
    DebugControl.style.top = document.documentElement.scrollTop + 200 + 'px';
    DebugControl.style.left = document.body.clientWidth/2 - 200 + 'px';
    DebugControl.style.zIndex = 10009;
    CreatBackground();
}
function CloseDebugControl()
{
    $('DebugControl').style.display = 'none';
    CloseBackground();
}

//注册页js
//地图取点回调
function GetMapXY(x,y)
{
    document.getElementById('hdx').value = x;
    document.getElementById('hdy').value = y;
    document.getElementById('isGetMyPointdiv').className= 'AdressYes';
    document.getElementById('isGetMyPointdiv').innerHTML = '已选择';
    document.getElementById('isGetMyPointimg').src = document.getElementById('isGetMyPointimg').src.replace('/GetAdressNo.gif','/GetAdressYes.gif');
    CloseMapIframe();
}
//城市选择更改
function ClearMapXY()
{
    document.getElementById('hdx').value = '';
    document.getElementById('hdy').value = '';
    document.getElementById('isGetMyPointdiv').className= 'AdressNo';
    document.getElementById('isGetMyPointdiv').innerHTML = '未选择';
    document.getElementById('isGetMyPointimg').src = document.getElementById('isGetMyPointimg').src.replace('/GetAdressYes.gif','/GetAdressNo.gif');
}
//调出选点地图
function ChooseMyPlace(skinpath)
{
    var citycode = document.getElementById('dplCityCode').value
    CreateMapIframe(skinpath+citycode+'/Map/');
}
function ChooseOwner(citypath)
{
    CreateMapIframe(citypath+'Map/t_owner_');
}
//实体ID选择回调
function GetOwnerID(oid, title)
{
    $('txtMCI_OwnerName').value = title;
    $('txtMCI_OwnerID').value = oid;
    CloseMapIframe();
}
//用户注册检测提交数据
function CheakRegisterData()
{
    var edushivalidate = new EdushiValidate();
    edushivalidate.inputString = document.getElementById('txtLoginName').value;
    if(!edushivalidate.isLoginName(4,16))
    {
        alert('请输入正确的用户名');
        document.getElementById('txtLoginName').focus();
        return false;
    }
    edushivalidate.inputString = document.getElementById('txtPassword').value;
    if(!edushivalidate.isPassword(6,20))
    {
        alert('请输入正确的密码');
        document.getElementById('txtPassword').focus();
        return false;
    }
    if(document.getElementById('txtPassword').value!=document.getElementById('txtRePassword').value)
    {
        alert('两次密码输入不一致。');
        document.getElementById('txtRePassword').focus();
        return false;
    }
//    if(document.getElementById('hdx').value==''|| document.getElementById('hdy').value=='')
//    {
//        alert('请选择你的位置。');
//        return false;
//    }
   return true;
}

function ShowProductPhoto(pid)
{
    var iCount = $('ltlProductCount').innerHTML * 1;
    var iCurrentIndex = $('spnCurrentIndex').innerHTML * 1;
    var o = null;
    if (pid > 0)
    {
        for (var i=0; i<_ProductList.length; i++)
        {
            if (_ProductList[i].ID == pid)
            {
                o = _ProductList[i];
                iCurrentIndex = o.Index;
                break;
            }
            $('pIndex' + i).style.border = 'solid 2px #ccc';
        }
    }
    else
    {
        if (pid == 0)
        {
            //下一张
            if (iCurrentIndex >= iCount)
            {
                iCurrentIndex = 1;
            }
            else
            {
                iCurrentIndex ++;
            }
            o = _ProductList[iCurrentIndex-1];
        }
        else
        {
            //上一张
            if (iCurrentIndex <= 1)
            {
                iCurrentIndex = iCount;
            }
            else
            {
                iCurrentIndex --
            }
            o = _ProductList[iCurrentIndex-1];
        }
    }
    if (o != null)
    {
        for (var i=0; i<_ProductList.length; i++)
        {
            $('pIndex' + i).style.border = 'solid 2px #ccc';
        }
        $('pIndex' + (iCurrentIndex-1)).style.border = 'solid 2px green';
        $('spnCurrentIndex').innerHTML = iCurrentIndex;
        $('ltlProductTitle').innerHTML = o.Title;
        $('ltlProductInfo').innerHTML = o.Info;
        $('imgProductPhoto').src = o.Photo;
    }
}

function ShowProductPhoto1(pid)
{
    var o = null;
    var imgs=document.getElementsByName("img");
    for(var i=0;i<imgs.length;i++)
    {
        imgs[i].style.border="solid 1px #75796c";
    }    
    if (pid > 0)
    {
        for (var i=0; i<_ProductList.length; i++)
        {
            if (_ProductList[i].ID == pid)
            {
               o=_ProductList[i];
               break;
            }
        }
    }
    else
    {
    
    }
    if (o != null)
    {
        for(var i=0;i<_ProductType.length;i++)
        {
            if(o.TypeID==_ProductType[i].TypeID)
            {
            if(IsPostBack)
            {
                IsPostBack=false;
                ShowTypePhoto(o.TypeID);
            }
            $('lbProductType').innerText=_ProductType[i].Name;
            $('lbProductType').ID="pType"+_ProductType[i].Index;
            
            if(_ProductType[i].Index==_ProductType.length)
            {
                $('down').src="images/images/EPS2.jpg";
            }
            if(_ProductType[i].Index==1)
            {
                $('up').src="images/EPS1.jpg";
            }
            }
        }
        if($('imgID' + o.ID)!=null)
        {
            $('imgID' + o.ID).style.border = 'solid 1px red';
        }
        $('lbProductTitle').innerHTML = o.Title;
        $('lbProductInfo').innerHTML = o.Info;
        $('imgPhoto').src = o.Photo;
    }
}

function ShowTypePhoto(typeid)
{
    var photos="";
    var count=0;
    var index=1;
    Products="";
    $("photolist").innerHTML="";
    for (var i=0; i<_ProductList.length; i++)
    {
        if(typeid==_ProductList[i].TypeID)
        {
            count++;
            if(Products=="")
                Products=_ProductList[i].ID;
            else
                Products=Products+","+_ProductList[i].ID;
            if(count<=pagesize)
            {
                if(photos=="")
                    photos="<li><img name='img' style='cursor:pointer;' id='imgID"+_ProductList[i].ID+"' width='83px' height='63px'  src='"+_ProductList[i].Photo+"' onclick='ShowProductPhoto1("+_ProductList[i].ID+")' /></li>";
                else
                    photos+="<li><img name='img' style='cursor:pointer;' id='imgID"+_ProductList[i].ID+"' width='83px' height='63px' src='"+_ProductList[i].Photo+"' onclick='ShowProductPhoto1("+_ProductList[i].ID+")' /></li>";
            }
        }
    }
    if(count <= pagesize)
        pagecount=1;
    else
    {
        if(count%pagesize>0)
            pagecount=parseInt(count/6)+1;
        else
            pagecount=parseInt(count/6);
    }
    $("lbpage").innerText=index+"/"+pagecount;
    $("photolist").innerHTML=photos;
}

function UpType()
{
    var count=_ProductType.length;

    var index=$('lbProductType').ID.replace("pType","");
    
    var index=parseInt(index)+1;
    if(index>count)
    {
        return
    }
    if(index==_ProductType.length)
    {
        $('down').src="images/EPS2.jpg";
        $('up').src="images/EPS11.jpg";
    }
    else
    {
        $('down').src="images/EPS22.jpg";
        $('up').src="images/EPS11.jpg";
    }
    for(var i=0;i<count;i++)
    {
        if(index==_ProductType[i].Index)
        {
            break;
        }
    }
    
   ShowTypePhoto(_ProductType[i].TypeID);
   $('lbProductType').innerText=_ProductType[i].Name;
   $('lbProductType').ID="pType"+_ProductType[i].Index;
}

function DownType()
{
    var count=_ProductType.length;
    var index=$('lbProductType').ID.replace("pType","");
    var index=parseInt(index)-1;
    if(index==0)
    {
        return;
    }
    if(index==1)
    {
        $('up').src="images/EPS1.jpg";
        $('down').src="images/EPS22.jpg";
    }
    else
    {
        $('up').src="images/EPS11.jpg";
        $('down').src="images/EPS22.jpg";
    }
    
    for(var i=0;i<count;i++)
    {
        if(index==_ProductType[i].Index)
        {
            break;
        }
    }
    ShowTypePhoto(_ProductType[i].TypeID);
    $('lbProductType').innerText=_ProductType[i].Name;
    $('lbProductType').ID="pType"+_ProductType[i].Index;
}

    function uppage1()
    {
        var count=0;
        var index=$("lbpage").innerText.split('/')[0];
        var spage=$("lbpage").innerText.split('/')[1];
        var photos="";
        index=parseInt(index)-1;
        if(index==0)
        {
            return;
        }
        if(index==1)
        {
            $("imgup").src="images/up.jpg";
            $("imgdown").src="images/down1.jpg";
        }
        else
        {
           $("imgup").src="images/up1.jpg";
           $("imgdown").src="images/down1.jpg";
        }
        var p=Products.split(',');
        var flag=(index-1)*pagesize;
        for(var i=flag;i<p.length;i++)
        {
            count++;
            if(count<=pagesize)
            {
            if(photos=="")
                photos="<li><img name='img' id='imgID"+GetProductInfo(p[i]).ID+"' width='83px' height='63px'  src='"+GetProductInfo(p[i]).Photo+"' onclick='ShowProductPhoto1("+GetProductInfo(p[i]).ID+")' /></li>";
            else
                photos+="<li><img name='img' id='imgID"+GetProductInfo(p[i]).ID+"' width='83px' height='63px' src='"+GetProductInfo(p[i]).Photo+"' onclick='ShowProductPhoto1("+GetProductInfo(p[i]).ID+")' /></li>";
            }
        }
        $("photolist").innerHTML=photos;
        $("lbpage").innerText=index+"/"+spage;
    }
    function downpage1()
    {
        var count=0;
        var index=$("lbpage").innerText.split('/')[0];
        var spage=$("lbpage").innerText.split('/')[1];
        var photos="";
        index=parseInt(index)+1;
        if(index>parseInt(spage))
        {
            return ;
        }
        if(index==parseInt(spage))
        {
            $("imgdown").src="images/down.jpg";
            $("imgup").src="images/up1.jpg";
        }
        else
        {
            $("imgdown").src="images/down1.jpg";
            $("imgup").src="images/up1.jpg";
        }
        var p=Products.split(',');
        var flag=(index-1)*pagesize;
        for(var i=flag;i<p.length;i++)
        {
            count++;
            if(count<=pagesize)
            {
            if(photos=="")
                photos="<li><img name='img' id='imgID"+GetProductInfo(p[i]).ID+"' width='83px' height='63px'  src='"+GetProductInfo(p[i]).Photo+"' onclick='ShowProductPhoto1("+GetProductInfo(p[i]).ID+")' /></li>";
            else
                photos+="<li><img name='img' id='imgID"+GetProductInfo(p[i]).ID+"' width='83px' height='63px' src='"+GetProductInfo(p[i]).Photo+"' onclick='ShowProductPhoto1("+GetProductInfo(p[i]).ID+")' /></li>";
            }
        }
        $("photolist").innerHTML=photos;
        $("lbpage").innerText=index+"/"+spage;
    }
    
    function GetProductInfo(pid)
    {
        var o=null;
        for(var i=0;i<_ProductList.length;i++)
        {
            if(pid==_ProductList[i].ID)
            {
                o=_ProductList[i];
            }
        }
        return o;
    }

function LoadFck(textBox, rootPath, citycode)
{
    var oDiv = textBox.parentNode;
    var id = textBox.name;
    var city = citycode ? citycode : '';
    oDiv.innerHTML = '' +
    '<input type="hidden" id="' + id + '" name="' + id + '" value="' + textBox.value + '" /><input type="hidden" id="' + id + '___Config" value="HtmlEncodeOutput=false&FormatSource=true&EdushiCityCode=' + city + '" /><iframe id="' + id + '___Frame" src="' + rootPath + 'fckeditor/editor/fckeditor.html?InstanceName=' + id + '&Toolbar=Basic" width="' + textBox.style.width.replace('px','') + '" height="' + textBox.style.height.replace('px','') + '" frameborder="no" scrolling="no"></iframe>';
}

//验证贴子主题提交
function CheckTopicPost()
{
    if ($('txtTitle').value.length < 5)
    {
        alert('主题标题不能少于 5 个字符');
        $('txtTitle').focus();
        return false;
    }
    if ($('dplTopicSmallTypeList').options[$('dplTopicSmallTypeList').selectedIndex].value == '')
    {
        alert('您必须选择一个贴子小类');
        $('dplTopicSmallTypeList').focus();
        return false;
    }
    if (typeof FCKeditorAPI == 'undefined')
        return false;
    var oEditor = FCKeditorAPI.GetInstance('txtPostContent');
    var content = oEditor.GetXHTML(true); 
    if (content.length < 5)
    {
        alert('主题内容不能少于 5 个字符');
        return false;
    }
    return true;
}
function CheckNewsData()
{
    if ($('txtLT_Title').value.length < 1)
    {
        alert('资讯标题不能为空');
        $('txtLT_Title').focus();
        return false;
    }
    if ($('dplTopicSmallTypeList').options[$('dplTopicSmallTypeList').selectedIndex].value == '0')
    {
        alert('您必须选择一个资讯标签');
        $('dplTopicSmallTypeList').focus();
        return false;
    }
    if (typeof FCKeditorAPI == 'undefined')
        return false;
    var oEditor = FCKeditorAPI.GetInstance('txtPostContent');
    var content = oEditor.GetXHTML(true); 
    if (content.length < 1)
    {
        alert('资讯内容不能为空');
        return false;
    }
    return true;
}
//载入贴子分类
function LoadTopicType(iParentID, subtypeId, cityPath)
{
    if (iParentID*1 < 1)
    {
        var l = $(subtypeId).options.length;
        for (var i=0; i<l; i++)
        {
            $(subtypeId).remove(0);
        }
        var option = document.createElement('option');
        $(subtypeId).options.add(option);
        option.text = '请选择小类';
        option.value = '';
        return;
    }
    var ajax = new Ajax();
    ajax.get(cityPath + 'DataHandler/GetData/topictype?ParentID=' + iParentID + "&rnd=" + Math.round(Math.random()*10000)
        ,function(xmlObj){
            if (xmlObj != null)
            {
                var count = $(subtypeId).options.length;
                for (var i=0; i<count; i++)
                {
                    $(subtypeId).remove(0);
                }
                
                var arr = eval(xmlObj.responseText);
                for (var i=0; i<arr.length; i++)
                {
                    var option = document.createElement('option');
                    $(subtypeId).options.add(option);
                    option.text = arr[i].Title;
                    option.value = arr[i].ID;
                }
            }
            else
            {
                alert('数据加载失败.');
            }
        }
    );
}

/**********************************************
Ajax类
***********************************************/
function Ajax() {
	var xmlObj = false;
	var CBfunc,ObjSelf;
	ObjSelf=this;
	try { xmlObj=new XMLHttpRequest; }
	catch(e) {
		try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
		catch(e2) {
			try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e3) { xmlObj=false; }
		}
	}
	if (!xmlObj) return false;
	if(arguments[0]) this.url=arguments[0]; else this.url="";
	if(arguments[1]) this.callback=arguments[1]; else this.callback=function(obj){return};
	if(arguments[2]) this.content=arguments[2]; else this.content="";
	if(arguments[3]) this.method=arguments[3]; else this.method="POST";
	if(arguments[4]) this.async=arguments[4]; else this.async=true;
	this.send=function() {
		var purl,pcbf,pc,pm,pa;
		if(arguments[0]) purl=arguments[0]; else purl=this.url;
		if(arguments[1]) pc=arguments[1]; else pc=this.content;
		if(arguments[2]) pcbf=arguments[2]; else pcbf=this.callback;
		if(arguments[3]) pm=arguments[3]; else pm=this.method;
		if(arguments[4]) pa=arguments[4]; else pa=this.async;
		if(!pm||!purl||!pa) return false;
		xmlObj.open (pm, purl, pa);
		if(pm=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlObj.onreadystatechange=function() {
			if(xmlObj.readyState==4) {
				if(xmlObj.status==200) {
					pcbf(xmlObj);
				}
				else {
					pcbf(null);
				}
			}
		}
		if(pm=="POST")
			xmlObj.send(pc);
		else
			xmlObj.send("");
	}
	this.get=function() {
		var purl,pcbf;
		if(arguments[0]) purl=arguments[0]; else purl=this.url;
		if(arguments[1]) pcbf=arguments[1]; else pcbf=this.callback;
		if(!purl&&!pcbf) return false;
		this.send(purl,"",pcbf,"GET",true);
	}
	this.post=function() {
		var fo,pcbf,purl,pc,pm;
		if(arguments[0]) fo=arguments[0]; else return false;
		if(arguments[1]) pcbf=arguments[1]; else pcbf=this.callback;
		if(arguments[2])
			purl=arguments[2];
		else if(fo.action)
			purl=fo.action;
		else
			purl=this.url;
		if(arguments[3])
			pm=arguments[3];
		else if(fo.method)
			pm=fo.method.toLowerCase();
		else
			pm="post";
		if(!pcbf&&!purl) return false;
		pc=this.formToStr(fo);
		if(!pc) return false;
		if(pm) {
			if(pm=="post")
				this.send(purl,pc,pcbf,"POST",true);
			else
				if(purl.indexOf("?")>0)
					this.send(purl+"&"+pc,"",pcbf,"GET",true);
				else
					this.send(purl+"?"+pc,"",pcbf,"GET",true);
		}
		else
			this.send(purl,pc,pcbf,"POST",true);
	}

	this.formToStr=function(fc) {
		var i,query_string="",and="";
		for(i=0;i<fc.length;i++) {
			e=fc[i];
			if (e.name!='') {
				if (e.type=='select-one') {
					element_value=e.options[e.selectedIndex].value;
				}
				else if (e.type=='checkbox' || e.type=='radio') {
					if (e.checked==false) {
						continue;	
					}
					element_value=e.value;
				}
				else {
					element_value=e.value;
				}
				element_value=encodeURIComponent(element_value);
				query_string+=and+e.name+'='+element_value;
				and="&";
			}
		}
		return query_string;
	}
}