/*************************
定义全局变量
*************************/
var screenwidth;
var screenheight;
screenwidth = screen.width;
screenheight = screen.height;
var tkfpop_opacityspeed=5;//背景透明度
var tkfpop_opacitydegree=2;//背景透明度加速度
var tkfpop_innerHTML="";

/*************************
TKF Frame
*************************/
var tkf={
//变量

//start method 
$:function(id){return document.getElementById(id)}
,p$:function p$(string){document.write(string);}
,rnd:function rnd(n){return Math.floor(Math.random()*n);}
,tagArr:function(o,name){return o.getElementsByTagName(name)}
,att:function(o,name,fun){return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);}
,style:function(o){	return o.currentStyle || document.defaultView.getComputedStyle(o,null);}
,offsetLT:function(o){var x = 0, y = 0;do { x += o.offsetLeft, y += o.offsetTop; } while (o = o.offsetParent);return { 'x' : x, 'y' : y };}
,dElement:function(){ return	document.documentElement || document.body;}
,rewriteAtt:function(formerObj,newObj){for(var i in newObj){formerObj[i]=newObj[i];}return formerObj;}
//取消错误
,killErrors:function killErrors() {return true;}
//计算字符串的长度，汉字占两个字符
,StringLength:function StringLength(str){return str.replace(/[^\x00-\xff]/g,"**").length}
//用來儲存目前已輸入多少字 計算字數
,checkCount:function checkCount(obj,maxChr,displaySpan){
        var countobj='';var nowChr = 0;nowChr = StringLength(obj.value);
        var willChr=maxChr-nowChr;
        if(displaySpan!=''){countobj=document.getElementById(displaySpan);}
        if(willChr>0 && willChr!=maxChr){if(displaySpan!=''){countobj.innerHTML="可输入"+willChr+"字";}}
        else if(willChr==maxChr){if(displaySpan!=''){countobj.innerHTML="可输入"+maxChr+"字";}}
        else {if(displaySpan!=''){countobj.innerHTML="字数已到最大限制";}obj.value=obj.value.substr(0,maxChr)}
}
,displayOpacity:function displayOpacity(id, n) {
	if(!tkf.$(id)) {return;}
	if(n >= 0) {n -= 10;tkf.$(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + n + ')';tkf.$(id).style.opacity = n / 100;setTimeout('displayOpacity(\'' + id + '\',' + n + ')', 50);} 
	else {tkf.$(id).style.display = 'none';tkf.$(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';tkf.$(id).style.opacity = 1;}
}
//弹出成功提示
,showAlert:function showSuccessDiv(width,height,divhtml,classname,isShowClose){
        var obj = document.getElementById("successDiv"); 
        //obj.style.filter = "Alpha(Opacity=1)";	
        obj.style.display = "block"; obj.className ="tkfpopbox";
        obj.style.position = "absolute"; obj.style.zindex = "999"; 
        obj.style.width = width + "px"; obj.style.height = height + "px"; 
        var Position = getPosition(); 
        leftadd = (Position.width-width)/2; topadd = (Position.height-height)/2; 
        obj.style.top = (Position.top + topadd) + "px"; obj.style.left = (Position.left + leftadd) + "px"; 
        var str="";
        if(isShowClose){str+="<a href=\"javascript:void(0);\" onclick='document.getElementById(\"successDiv\").style.display=\"none\"' class=\"close\" title=\"关闭\">关闭</a>";}
        str+="<p class='"+classname+"'>"+divhtml+"</p>";
        str+="<div style='display:block;clear:both;'></div>";
        obj.innerHTML=str;
}
//弹出自动隐藏的提示信息
,showmsg:function showmsg(width,height,divhtml,divclassname){
//    if(document.readyState=="complete")
//       {
//        var newid="msg_"+rnd(10000);
//        var newDiv = document.createElement("DIV");
//        newDiv.id = newid;        
//        $(document.body).append(newDiv); 

        var newDiv =tkf.$("tkfmsg");
        newDiv.className = divclassname; 
        newDiv.style.position = "absolute"; 
        newDiv.style.zindex = "16999"; 
        newDiv.style.width = width + "px"; 
        newDiv.style.height = height + "px"; 
        var Position = tkf.getPosition(); 
        leftadd = (Position.width-width)/2; 
        topadd = (Position.height-height)/2; 
        
	    var pbegin = (Position.top + topadd) ; 
	    var pend = (Position.top + topadd/6); 
        
        newDiv.style.top = pbegin; 
        newDiv.style.left = (Position.left + leftadd) + "px"; 
        var str="";
        //str+="<a href=\"javascript:void(0);\" onclick='document.getElementById(\"successDiv\").style.display=\"none\"' class=\"close\" title=\"关闭\">关闭</a>";
        str+="<div class='innerdiv'>"+divhtml+"</div>";
        str+="<div style='display:block;clear:both;'></div>";
        newDiv.innerHTML=str;
        newDiv.style.display = "block"; 
        setTimeout(function () {showmsgdo(newDiv,pbegin, pend, 0, 1000)}, 1);
        //$("#"+newid).animate({opacity: 1.0}, msecondnum).fadeOut("slow",function(){$(this).remove();}); 
//    }
}
,showusermsg:function showusermsg(){tkf.$("showusermsg").src="http://service.shuaiche.com/user/showusermsg.aspx";}
,showmsgdo:function showmsgdo(obj,b, e, a, t) {
	step = (b - e) / 15;
	newp = (parseInt(obj.style.top) - step);
	if(newp > e) {
		obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + a + ')';
		obj.style.opacity = a / 100;
		obj.style.top = newp + 'px';
		setTimeout(function () {showmsgdo(obj,b, e, a += 10, t)}, 10);
	} else {
		obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
		obj.style.opacity = 1;
		setTimeout("displayOpacity(\'"+obj.id+"\', 100)", t);
		//$("#"+obj.id).animate({opacity: 1.0}, 1000).fadeOut("slow",function(){$(this).remove();}); 
		//$("#"+obj.id).animate({opacity: 1.0}, 1000).fadeOut("slow"); 
	}
}
//输入的只能是数字和小数点
,clearNoNum:function clearNoNum(obj) { 
        obj.value = obj.value.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符 
        obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是. 
        obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的. 
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
}
//用于在控件上执行正则表达式
,regInput:function regInput(obj, reg, inputStr){var docSel = document.selection.createRange();if (docSel.parentElement().tagName != "INPUT"){return false;}oSel = docSel.duplicate();oSel.text = "";var srcRange = obj.createTextRange();oSel.setEndPoint("StartToStart", srcRange);var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);return reg.test(str);}
//判断是否是空或者空格
,checkspace:function checkspace(checkstr) {var str = '';for(i = 0; i < checkstr.length; i++) {str = str + ' ';}return (str == checkstr);}
//功能：判断是否在逗号分割的字符串内,参数：逗号分割的字符串，字符串
,checkStringInArrayStrings:function checkStringInArrayStrings(strings,str){if(strings=="")return false;var arrayStrings=strings.split(",");for (j = 0; j < arrayStrings.length; j++){if(str==arrayStrings[j]){return true;}}return false;}
//功能：去掉字符串右的逗号
,TrimRightDot:function TrimRightDot(str){if(str=="")return str;if(str.substring(str.length-1,str.length)==","){return str.substring(0,str.length-1);}else{return str;}}

//功能：将文本框中的字符串变成html
,TxtToHtml:function TxtToHtml(str){while (str.indexOf("\n") != -1){str = str.substring(0, str.indexOf("\n")) + "<br>" + str.substring(str.indexOf("\n") + 1);}return str;}
//检查邮箱是否正确
,IsMail:function IsMail(ChkStr) {var isEmail1= /^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w+$/;var isEmail2= /^.*@[^_]*$/;return ((isEmail1.test(ChkStr)) && (isEmail2.test(ChkStr)));}
//展开和折叠层
,deploy:function deploy(ID){obj=document.getElementById(ID);if(obj.style.display=="none"){obj.style.display="";}else{obj.style.display="none";}return false;}
//动态关闭div
,closediv:function closediv(o){  
    var Intervalclosediv;o.style.height = o.clientHeight;var cy = parseInt(o.style.height);
    if(cy > 5){o.style.height = (cy - Math.ceil(cy/5)) +"px";Intervalclosediv = setInterval(function(){closediv(o)},100);}
    else{clearInterval(Intervalclosediv);o.style.display="none";}
}
//判断是否定义
,isVarDefined:function isVarDefined(obj) {if(typeof(obj) == "undefined") {return false;} else {return true;}}
//确保div有个最小值
,minheight:function minheight(ID,height){obj=document.getElementById(ID);if(obj){if(obj.offsetHeight <height){obj.style.height=height+"px";}}}
//图片按比例缩放 调用：<img src="图片" onload="javascript:tkf.DrawImage(this)">
,DrawImage:function DrawImage(ImgD,iwidth,iheight){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
    {
        if(image.width/image.height>= iwidth/iheight)
        {
            if(image.width>iwidth)
            {
            ImgD.width=iwidth;
            }
        }
        else
        {
            if(image.height>iheight){ImgD.height=iheight;}
        }
    }
} 
//约束图片宽度
,fixImagesWidth:function fixImagesWidth(_id,_maxwidth){var elem=document.getElementById(_id);var images=elem.getElementsByTagName("img");for(var i=0;i<images.length;i++){if(images[i].offsetWidth > _maxwidth){images[i].style.width=_maxwidth+"px";}}}
//图片预览
,previewPhoto:function previewPhoto(pfile){
    var photoName=pfile.value;var i = photoName.lastIndexOf(".");var strExt = photoName.substring(i);
    if (strExt.toLowerCase() == ".gif" || strExt.toLowerCase() == ".jpg" || strExt.toLowerCase() == ".jpeg")
    {var htm = "<img border=0 width=200px src='" + photoName + "' onload='tkf.DrawImage(this);' />";
    document.getElementById("PicUpload1_divPhoto").innerHTML =htm;}
    else{document.getElementById("PicUpload1_divPhoto").innerHTML = "图片格式不正确，必须是gif、jpg或者jpeg";}
}

//对象的绝对位置var x=getOJ(obj)[0];var y=getOJ(obj)[1];
,getOJ:function getOJ(e){var t = [e.offsetLeft,e.offsetTop];if(e=e.offsetParent){var r = getOJ(e);t[0] += r[0];t[1] += r[1];}return t;}  
//得到对象的位置
,getPosition:function getPosition() {var top = document.documentElement.scrollTop; var left = document.documentElement.scrollLeft; var height = document.documentElement.clientHeight; var width = document.documentElement.clientWidth; return {top:top,left:left,height:height,width:width}} 
//Colour pallete top offset
,getOffsetTop:function getOffsetTop(elm) {var mOffsetTop = elm.offsetTop;var mOffsetParent = elm.offsetParent;while(mOffsetParent){mOffsetTop += mOffsetParent.offsetTop;mOffsetParent = mOffsetParent.offsetParent;}return mOffsetTop;}
//Colour pallete left offset
,getOffsetLeft:function getOffsetLeft(elm) {var mOffsetLeft = elm.offsetLeft;var mOffsetParent = elm.offsetParent;while(mOffsetParent) {mOffsetLeft += mOffsetParent.offsetLeft;mOffsetParent = mOffsetParent.offsetParent;}return mOffsetLeft;}

/*************************
 * 功能：复选框全选
 * 调用示例：页面复选框，如：struts标签 <html:multibox property="checkFlag">0</html:multibox>或html标签 <input type="checkbox" name="checkFlag" value="0">   
 * 按钮或者连接中增加onclick事件，如：<input type="button" name="checkAll" value="全选" onclick="checkAll('checkFlag')">
*************************/
,checkAll:function checkAll(checkBoxName){var checkBox = document.getElementsByName(checkBoxName);for (var i = 0; i < checkBox.length; i++){var temp = checkBox[i];temp.checked = true;}}
//功能：复选框全不选
,checkNone:function checkNone(checkBoxName){var checkBox = document.getElementsByName(checkBoxName);for (var i = 0; i < checkBox.length; i++){var temp = checkBox[i];temp.checked = false;}}
//功能：复选框反选
,checkReverse:function checkReverse(checkBoxName){var checkBox = document.getElementsByName(checkBoxName);for (var i = 0; i < checkBox.length; i++){var temp = checkBox[i];temp.checked = !temp.checked;}}
//复制
,copyToClipBoard:function copyToClipBoard(){var clipBoardContent="";clipBoardContent+=this.location.href;window.clipboardData.setData("Text",clipBoardContent);alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");} 
,copyToClipBoard:function copyToClipBoard(clipBoardContent){window.clipboardData.setData("Text",clipBoardContent);}


//获取页面的内容
,GetAjax:function GetAjax(url){
		var faileStr = "";
		var xmlHttp;
		try{xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){
			try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return faileStr;}
		}
		try{xmlHttp.Open("GET",url,false);xmlHttp.Send();strRtn = xmlHttp.responseText;if(strRtn != null && strRtn != ""){return strRtn;}}
		catch(e){return faileStr;}
		return faileStr;}

/*更换标签显示样式*/ 
,setTab:function setTab(name,cursel,n){ 
        for(i=1;i<=n;i++){ 
        var menu=document.getElementById(name+"_"+i); 
        var con=document.getElementById(name+"_"+i+"_con"); 
        menu.className=i==cursel?"hover":""; 
        con.style.display=i==cursel?"block":"none"; }} 
    
/*更换标签显示样式*/ 
,setTab1:function setTab1(name,cursel){ 
        var divObj=tkf.$(name);
        var arr=divObj.getElementsByTagName('li') ;  
        for(var i=0 ;i<arr.length+1;i++){
        var menu=tkf.$(name+"_"+i); 
        var con=tkf.$(name+"_"+i+"_con"); 
        if(menu){menu.className=i==cursel?"hover":""; }
        if(con){con.style.display=i==cursel?"block":"none"; }}}

//打开窗口
,windowopen:function windowopen(sUrl,iWidth,iHeight,sResize){
        if(iWidth==0)iWidth=600
        if(iHeight==0)iHeight=450	  
        if(sResize=="yes"){l = (screenwidth - iWidth)/2-5;t = (screenheight - iHeight)/2-20;}
        else{l = (screen.width - iWidth)/2-5;t = (screen.height- iHeight)/2-20;sResize = "no";}
        var ff_submain = window.open("","","scroll=auto,resizable=" + sResize + ",status=1,width="+iWidth+",height="+iHeight+",left="+l+",top="+t)
        if (sUrl!=""){ff_submain.document.location.href = sUrl}
        }

//菜单操作
,change_menu:function change_menu(id,content_id,num,total_ztc_menu,menu_on,menu_off){
        for (var i=1;i<=total_ztc_menu;i++){
        tkf.$(id+i).className=menu_off;
        tkf.$(content_id+i).style.display='none';
        }
        tkf.$(id+num).className=menu_on;
        tkf.$(content_id+num).style.display='block';
        }

//显示TKF菜单
,showtkfpop:function showtkfpop(width,height,html,classname){ 
        var obj = document.getElementById("tkfpop"); 
        obj.style.filter = "Alpha(Opacity=1)";	
        obj.style.display = "block"; 
        obj.style.position = "absolute"; 
        obj.style.zindex = "999"; 
        obj.style.width = width + "px"; 
        obj.style.height = height + "px"; 
        obj.innerHTML="<div id=\"tkfpopctrl\"><a href=\"javascript:hidetkfpop()\">关闭</a></div><div class='"+classname+"' id=\"tkfpopdata\">"+html+"</div>";
        var Position = getPosition(); 
        leftadd = (Position.width-width)/2; 
        topadd = (Position.height-height)/2; 
        obj.style.top = (Position.top + topadd) + "px"; 
        obj.style.left = (Position.left + leftadd) + "px"; 
        var tkfpop_innerHTML=obj.innerHTML;
        inter_showbox = setInterval(tkfpop_show,20);	//加载lightbox淡入效果JS，加载计时
        //    window.onscroll = function ()
        //    { 
        //        var Position = getPosition(); 
        //        obj.style.top = (Position.top + topadd) +"px"; 
        //        obj.style.left = (Position.left + leftadd) +"px"; 
        //    }; 
        }

//显示TKF窗口
,tkfpop_show:function tkfpop_show(){
        var obj = document.getElementById("tkfpop"); 
        tkfpop_opacityspeed=tkfpop_opacityspeed+3;										//透明加速度递增公式
        tkfpop_opacitydegree=tkfpop_opacitydegree+tkfpop_opacityspeed;							//透明度递增公式
        obj.style.filter = "Alpha(Opacity=" + tkfpop_opacitydegree + ")";  	//背景透明度递增
        obj.style.opacity = tkfpop_opacitydegree/10000;							//兼容FireFox
        if (tkfpop_opacitydegree>=80 )											//判断结束条件
        {clearInterval(inter_showbox);										//清空计时
        tkfpop_opacitydegree=40;													//重置背景透明度
        tkfpop_opacityspeed=0;														//重置背景透明加速度
        obj.style.filter = "Alpha(Opacity=100)";						//显示窗口，置为不透明
        }
        }
,hidetkfpop:function hidetkfpop(){ document.getElementById("tkfpop").style.display = "none"; } 

//上传图片pop窗体
,showuppicpop:function showuppicpop(objtxtid,board,aimimg){
        var popwidth=480;
        var popheight=400;
        var d="<iframe frameborder='0'  width='"+popwidth+"px' height='"+(popheight-20)+"px' src='/control/uppic/index.aspx?aimImg="+aimimg+"&p="+board+"&isneedclosepop=1&txtPicPath="+objtxtid+"&zipWidth=100&zipHeight=100&k=500'></iframe>";
        showtkfpop(popwidth,popheight,d,"m0");
        }

//选择地区pop窗体
,showselareapop:function showselareapop(board,maxnum,txtids,txttitles,divhtml){
        var popwidth=580;
        var popheight=360;
        var d="<iframe frameborder='0'  width='"+popwidth+"px' height='"+(popheight-20)+"px' src='/control/selarea/index.aspx?txtids="+txtids+"&txttitles="+txttitles+"&divhtml="+divhtml+"&p="+board+"&isneedclosepop=1'></iframe>";
        showtkfpop(popwidth,popheight,d,"m0");
        }

//加为好友的pop窗体
,showjoinfriendpop:function showjoinfriendpop(userid){
            var popwidth=400;
            var popheight=270;
            var d="<iframe frameborder='0'  width='"+popwidth+"px' height='"+(popheight-20)+"px' src='/control/joinfriend/index.aspx?ruid="+userid+"'></iframe>";
            showtkfpop(popwidth,popheight,d,"m0");
        }
        
,showselcomppop:function showselcomppop(allowcompids,txtcontrolcompid,txtcontrolcompname,board){
        var popwidth=580;
        var popheight=460;
        var d="<iframe frameborder='0'  width='"+popwidth+"px' height='"+(popheight-20)+"px' src='/control/selcomp/index.aspx?allowcompids="+allowcompids+"&p="+board+"&isneedclosepop=1&txtcontrolcompid="+txtcontrolcompid+"&txtcontrolcompname="+txtcontrolcompname+"'></iframe>";
        showtkfpop(popwidth,popheight,d,"m0");
        }
//设为首页
,setHomePage:function setHomePage(obj){obj.style.behavior='url(#default#homepage)';obj.setHomePage(window.location.href);}        
//end method 
};






