﻿// JScript 文件

//去除字符串的所有空格
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
//去除字符串左边的空格
String.prototype.LTrim = function() 
{ 
    return this.replace(/(^\s*)/g, ""); 
} 
//去除字符串右边的空格
String.prototype.RTrim = function() 
{ 
    return this.replace(/(\s*$)/g, ""); 
}

//判断是否为IE浏览器的参数

var isIE = !-[1,];

function GetLanguageValue(id)
{
    var LInfo = "";
    
    if(id)
    {
        var controlObj = document.getElementById(id);
        
        if(controlObj)
        {
            LInfo = controlObj.value;
        }
    }
    
    return LInfo;
}


function LimitLen(id,len)
{
    var txt = document.getElementById(id);      
    if(txt.value.length > len)
    {
        txt.blur();
        txt.value = txt.value.substring(0,len);
        txt.focus();
        if(nowlanguage=="zh_CN"){
            ShowHtmlMsg('您输入的字数超过了'+ len + '字！','',true,false,null,null,null);
        }
        else{
             ShowHtmlMsg('Number of words you enter more than'+ len,'',true,false,null,null,null);
        }
    }
    
}

//关闭发送消息框，并重置限制字符数
function closeMsg()
{
    document.getElementById("sendpopid").style.display = "none";
    document.getElementById("msgcontent").innerHTML = "";
    document.getElementById("msgcontent").value = "";
    document.getElementById("msgRemCount").innerHTML = "200";
}

function HanderMyFriend(uid,itype,iReload,Msg)
{  
    var cmd=itype==1?'del':'add';
	jQuery.ajax({
		type:'GET',
		url:'AjaxService/hdgetfriends.ashx',
		data:{"cmd":cmd,"uid":uid},
		success:function(resout){
			//将字符串转换成JSON
			var userJson= jQuery.json.decode(resout);
			if(userJson)
			{	
			    ShowHtmlMsg(userJson.msg,'',true,false,null,null,null, true, null, "success");
				
			}
		},
		error:function(err){
			//jQuery.AjaxWaitHide('#wait');
			//显示错误信息
			ShowHtmlMsg(err,'',true,false,null,null,null);
		}
	});
}
    

/***********************************
*       控制子菜单
*参数：
*evn：事件实体
*subContentFstr：子菜单id后缀
*state：状态
*fother：是否排他
*classname：类名
*closeAll：关闭全部状态
*************************************/

function SubMenuJs(evn,subContentFstr,state,fother,classname,closeAll)
{
    var menuMid;
    if(fother)
    {
        jq('.'+classname).each(function(){jq(this).hide()});
    }
    if(!closeAll)
    {
        if(state)
        {
            jq('#'+evn.id+subContentFstr).show();
            menuMid = setTimeout(function(){jq('#'+evn.id+subContentFstr).hide("fast");clearTimeout(menuMid);},4000);
           
        }else{
            jq('#'+evn.id+subContentFstr).hide();
        }
    }
}

/************************************************
*           tab标签与div
*参数：
*evn：当前控件
*selectCss：选中的tab样式class，无则传"",最好不要null，下同
*selectStyle：选中的tab样式style
*outCss：未选中的tab样式class
*outStyle：未选中的tab样式style
*content_F：容器的id后缀
*tabParentID：tab父标签id
*tabCName：tab容器名称，如li
*必须：容器必须使用tab的ID做前缀
*
*************************************************/

function DivTbaInfoContent(evn,selectCss,selectStyle,outCss,outStyle,content_F,tabParentID,tabCName)
{

    var tempObj;
    jq('#'+tabParentID+'>'+tabCName).each(function(){
                                      tempObj=jq(this);
                                      if(tempObj[0].id==evn.id)
                                      {
                                            //应该被选中
                                            jq('#'+tempObj[0].id+content_F).show();
                                            if(selectStyle.length>0)
                                            {
                                                tempObj.attr("style",selectStyle);
                                            }
                                            if(selectCss.length>0)
                                            {
                                                tempObj.attr("class",selectCss);
                                            }
                                      }else{
                                            //应该是不被选中
                                            jq('#'+tempObj[0].id+content_F).hide();
                                            if(outStyle.length>0)
                                            {
                                                tempObj.attr("style",outStyle);
                                            }
                                            if(outCss.length>0)
                                            {
                                                tempObj.attr("class",outCss);
                                            }
                                      }
    
    
    });
}

/******************************************************
*             点击标题控制内容显示
*参数：
*evn：事件出发对象，调用时传this，或document.getElementById('..');
*needHideTitle：点击标题后显示内容，是否需要隐藏标题
*state：状态,true:内容显示，false:内容隐藏
*firstTitleId：第一个标题的id，
*使用注意：建议标题与内容ID需要对应，如标题：title_1对应title_1_content,title_2对应title_2_content...
*建议页面中id使用前缀加下划线与编号，如前缀title,id即为：title_1,title_2....
*必须：内容容器的id使用标题id作为前缀，后缀使用_content。
******************************************************/

function ClickDivShowHide(evn,needHideTitle,state,firstTitleId)
{

    if(state)
    {
        if(needHideTitle)
        {
            jq('#'+evn.id).hide();
        }
        jq('#'+evn.id+'_content').show();
        if(evn.id!=firstTitleId)
        {
            ClickDivShowHide(document.getElementById(firstTitleId),needHideTitle,false,firstTitleId);
        }
    }else{
        if(needHideTitle)
        {
            jq('#'+evn.id).show();
        }
        jq('#'+evn.id+'_content').hide();
    }

}

/**
*
*       xinyu.hong   2010.01.26
*
*本脚本主要是前台使用，作用：优化页面载入时，使用异步，同时分页控件修正，使用客户端脚本控制
*
*
*参数说明：
*currentpage   当前页
*allcount      总条数
*pagesize      页面容量
*pagertype     显示页范围
*cllbackFun    回调函数名，主要是用来调用异步方法时候的中间方法方法，有调用页面提供，方法中主要是接受参数，然后调用异步方法即可，回传参数：需要跳转到的页码
*divObjName    显示分页控件的div名
*changeLine    当页面不够宽时，选择换行，传true;
*goTextBoxId   跳转框的ID，主要针对家园中多个分页时传值过来，默认可不传此参数
lan            语言
**/

function BuildPagersInfo(currentpage,allcount,pagesize,pagertype,cllbackFun,divObjName,changeLine,goTextBoxId,lan)
{
	var divObj = document.getElementById(divObjName);
	var pageAll=0;
	var pageStart;
	var pgeEnd;
	var tempId;
	divObj.innerHTML='';
	var str="";
	if(allcount==0)
	{
	}else{
		if(allcount%pagesize==0)
		{
			pageAll = Math.floor(allcount/pagesize);
		}else{
			pageAll = Math.floor(allcount/pagesize)*1+1*1;
		}
		if(isNaN(currentpage))
		{
		    currentpage=1;
		}else{
		    
		}
		if(currentpage<1)
		{
		    currentpage=1;
		}
		if(currentpage>pageAll)
		{
		    currentpage = pageAll;
		}
		if(currentpage<=Math.floor(pagertype/2)+1)
		{
			pageStart=1;
			if(pageAll<=pagertype)
			{
				pgeEnd=pageAll;
			}else{
				pgeEnd=pagertype;
			}
		}else if(pageAll-currentpage<=Math.floor(pagertype/2))
		{
			pgeEnd=pageAll;
			pageStart=pageAll-pagertype+1;
			if(pageStart<=0)
			{
				pageStart=1;
			}
		}else{
			pageStart = currentpage - Math.floor(pagertype / 2);
			pgeEnd = currentpage*1 + Math.floor(pagertype / 2)*1;
			
		}
		str+='<ul>';
		
		    if(currentpage==1)
		    {
			    str+='<li><a disabled="disabled" style="color:#ACA899; text-decoration:none;">|<<</a></li>';
		    }else{
			    str+='<li><a href="#"  style="text-decoration:none;" onclick="javascript:return '+cllbackFun+'(1);" >|<<</a></li>';
		    }
		
		    if(currentpage==1)
		    {
			    str+='<li><a disabled="disabled" style="color:#ACA899; text-decoration:none;"><</a></li>';
		    }else{
			    str+='<li><a href="#"  style="text-decoration:none;" onclick="javascript:return '+cllbackFun+'('+(currentpage*1-1*1)+');" ><</a></li>';
		    }
		
		for(var index = pageStart; index<=pgeEnd;index++)
		{
			if(currentpage==index)
			{
				str+='<li><span class="current"><font color="blue">'+index+'</font></span></li>';
			}else{
				str+='<li><a href="#" onclick="javascript:return '+cllbackFun+'('+(index)+');">'+index+'</a></li>';
			}
		}
		
		    if(currentpage==pageAll)
		    {
			    str+='<li><a disabled="disabled" style="color:#ACA899; text-decoration:none;">></a></li>';
		    }else{
			    str+='<li><a href="#"  style="text-decoration:none;" onclick="javascript:return '+cllbackFun+'('+(currentpage*1+1*1)+');" >></a></li>';
		    }
		
		
		    if(currentpage==pageAll)
		    {
			    str+='<li><a disabled="disabled" style="color:#ACA899; text-decoration:none;">>>|</a></li>';
		    }else{
			    str+='<li><a href="#"  style="text-decoration:none;" onclick="javascript:return '+cllbackFun+'('+pageAll+');" >>>|</a></li>';
		    }
		
		if(changeLine)
		{
		    str+='</ul><br><ul>';
		}
		
		if(lan=="en_US")
		{
		    str+='<li>'+currentpage+'/'+pageAll+'</li>';
		    str+='<li><span class="stat">&nbsp;Go to page&nbsp;<input type="text"';
		}else{
		    str+='<li>'+currentpage+'/'+pageAll+'</li>';
		    str+='<li><span class="stat">&nbsp;转至第&nbsp;<input type="text"';
		}
		if(goTextBoxId!=null)
		{
		    str+='id="'+goTextBoxId+'"';
		    tempId=goTextBoxId;
		}else{
		    str+='id="gotoPager"';
		    tempId="gotoPager";
		}
		    str+='class="messageP inputtext"  style="width:10px;" /></span></li>';
		str+='<li>';
		str+="<input type=button id=Button1 class=mihome_seach_wq value=GO style='cursor:pointer;'  onclick=\"javascript:return "+cllbackFun+"(document.getElementById('"+tempId+"').value,"+pageAll+");\" />";
		str+='</li>';
		str+='</ul>';
		
	}
	divObj.innerHTML=str;
	
}

///去除空格
String.prototype.trim= function()  
{  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

    function InitDom(xml,currentPage,language)
    {  
        Thislanguage=language;
        var speakForInfo = jq("#speakFor_hidden").val();
        var unSpeakForInfo = jq("#unSpeakFor_hidden").val();
        var objHtml = jq('#ulApps');
        objHtml.html('');
       
        var root = jq(xml).find('root');
        var allCount = root.attr('count');
        var date = root.attr('Date');
        var logins=root.attr('loginstat');
        var tbody = jq('#ulApps');
        
        var body='';
        var obj;
        var id;
        var sumBuy = root.attr('sumBuy');
        var widgetrate = root.attr('widgetrate');
        var noResult = root.attr('NoResult');
        var introduce = root.attr('introduce');
        var review = root.attr('review');
        var speakFor = root.attr('speakFor');
        var RecommendToFriend = root.attr('RecommendToFriend');
        var detial = root.attr('detial');
        var assort= root.attr("assort");
        var lan = root.attr('lan');
        var UpW = root.attr('UpW');
        if(allCount>0)
        {
            BuildPagersInfo(currentPage,allCount,10,5,'ChangePager','footPager',false,null,lan);

            if(jq(root).find('widget').size()>0)
            {
                var index = 1;
                var count = jq(root).find('widget').size();
                var bodyHtml = []; 
                  bodyHtml[bodyHtml.length] = '<div class="widgetlist_content"  style="clear:both; ">';
                  bodyHtml[bodyHtml.length] = '<ul  style="list-style-type: none; width:680px; ">';
                jq(root).find('widget').each(function(){
                                                        obj=jq(this);
                                                        id = obj.attr("id");
                                                        bodyHtml[bodyHtml.length] = '<li>';
                                                        bodyHtml[bodyHtml.length] = '       <div style="width: 330px; height: 220px;">';
                                                        bodyHtml[bodyHtml.length] = '           <div style="float: left;  width:150px; height:202px; margin-top:6px; border:solid 1px #dcdcdc; padding:1px;">';
                                                        bodyHtml[bodyHtml.length] = '               <a href="widgetinfo.aspx?wid='+id+'"><img style="cursor:pointer; border-style:solid;"  src="'+obj.attr('iconurl')+'"  width ="150px" height ="202px"  /></a>'
                                                        bodyHtml[bodyHtml.length] = '           </div>';
                                                        bodyHtml[bodyHtml.length] = '           <div id="divAppCom" style="float: left; padding-left: 15px; width: 150px; height: 200px;">';
                                                        bodyHtml[bodyHtml.length] = '           <div class="divAppTitle" style="height:25px;">';
                                                        bodyHtml[bodyHtml.length] = '               <a href="widgetinfo.aspx?wid='+id+'" class="greenline span_q_blue" style="display:block; width:114px; height:21px; font-weight:bold; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" title="' + obj.attr('fullname')+'">' + obj.attr('name')+'</a></div>';
                                                        bodyHtml[bodyHtml.length] = '           <div style="height:25px;">';
                                                        bodyHtml[bodyHtml.length] = '               '+ date +':'+obj.attr('time')+'</div>';
                                                        
                                                        
                                                        bodyHtml[bodyHtml.length] = '           <div style="height:25px;"> <div  style="width:59px;height:11px;overflow:hidden; margin-top:0px;"><img id="userscoreimg" src="App_Themes/White/default/images/m-stars'+obj.attr('star')+'.png"></div> </div>';
                                                        
                                                        
                                                        bodyHtml[bodyHtml.length] = '           <div style="height:25px;">';
                                                        bodyHtml[bodyHtml.length] = '               '+assort+': <a href="widgetlist.aspx?sid='+ obj.attr('assortid') + '&tid=0&bangct=0" class="span_q_blue span_q_underline"><span>'+obj.attr('assort')+'</span></a></div>';
                                                        bodyHtml[bodyHtml.length] = '           <div style="height:25px;">';
                                                        bodyHtml[bodyHtml.length] = '               '+widgetrate+': <span style="font-size:12px;" class = "span_q_blue">'+obj.attr('price')+'</span></div>';
                                                        bodyHtml[bodyHtml.length] = '           <div style="height:25px;">';
                                                        bodyHtml[bodyHtml.length] = '               '+sumBuy+': <span id="spanCount_'+id+'" style="vertical-align:top"  class = "span_q_blue">'+obj.attr('speak')+'</span></div>';
                                                        bodyHtml[bodyHtml.length] = '           <div style="vertical-align: middle; height:25px;">';
                                                        
                                                        if(obj.attr("canview") == "true")
                                                        {
                                                            bodyHtml[bodyHtml.length] = '  <img src="App_Themes/White/default/images/search.jpg" style="position:relative;top:6px;"/> ';
                                                            bodyHtml[bodyHtml.length] = '               <a  id="A1" class="span_q_blue span_q_underline"  href="javascript:Preview('+obj.attr("id")+');" style="margin-left: 10px;">'+review+'</a>';
                                                        }
                                                        bodyHtml[bodyHtml.length] = '   </div>';
                                                        if(logins=='true')
                                                        {
                                                       
                                                            if(obj.attr('speakFor')==unSpeakForInfo)
                                                            {
                                                                
                                                                bodyHtml[bodyHtml.length] = '<div id="divtt_'+ id +'" class="div_StyleOff" >';
                                                                bodyHtml[bodyHtml.length] = '<span  id="divca1_'+id+'"  ></span></div>';
                                                            }
                                                            else
                                                            {
                                                                bodyHtml[bodyHtml.length] = '<div id="divtt_'+ id +'" onclick="bespeak('+id+')" class="div_StyleOn" style="cursor:pointer " >';
                                                                bodyHtml[bodyHtml.length] = '<span id="divca1_'+id+'" ></span></div>';
                                                            }
                                                            
                                                        }
                                                        else
                                                        {
                                                            bodyHtml[bodyHtml.length] = '<div id="divtt_'+ id +'" onclick="showloginpop(null,\''+language+'\')" class="div_StyleOn" style="cursor:pointer " >';
                                                            bodyHtml[bodyHtml.length] = '<span id="btnBespeak1"></span></div>';
                                                        }

                                                        bodyHtml[bodyHtml.length] = '       </div>';
                                                        bodyHtml[bodyHtml.length] = '</li>';
                                                   
                                                        });
                                                        bodyHtml[bodyHtml.length] = '       </ul>';
                                                        bodyHtml[bodyHtml.length] = '</div>';
                   body = bodyHtml.join("");
                
            

            }
            jq('#select_sort').show();
        }
        else
        {
            jq('#select_sort').hide();
            jq('#footPager').hide();
            body = '<div  style="margin-top: 10px; padding-top: 0;margin-left:20px;"><span class="span_q_blue"><strong>'+noResult+'</strong></span></div>';
        }
        objHtml.html(body);
    }