﻿// JScript 文件
//公共变量
var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
/*
                var url="http://www.shengmd.net";
				var pLocation=parent.location+"";
				var tLocation=window.location+"";
				if (pLocation!=tLocation){
					if (pLocation.length>=url.length){
						if (pLocation.substr(0,url.length).toLowerCase()!=url.toLowerCase()){
							alert("地址不能直接输入");
							top.location.href="/soft/index.htm";
						}
					}
					else{
						alert("地址不能直接输入");
						top.location.href="/soft/index.htm";
					}
				}
				else{
					alert("地址不能直接输入");
					top.location.href="/soft/index.htm";
				}

*/

//－－－－－－－－－－－翻页类－－－－－－－－－－－－－－//
//属性  1.currentPage - 当前页码
//      2.pageCount - 页面总数
//      3.pageSize - 每一页显示个数
//      4.recordCount - 记录总数
//－－－－－－－－－－－－－－－－－－－－－－－－－－－//
function ChangePage_Property(Id){
    this.currentPage = 1;
    this.pageCount = 1;
    this.pageSize = 20;
    this.recordCount = 0;
    this.Id = Id;
    this.CheckPage=function(topage){
                if (topage<1 || topage>this.pageCount){
                    alert("指定页码不存在，页码范围是(1 - " + this.pageCount + ")");
                    return false;
                }
                return true;
    }
    
    this.Start = function(o,index,go){
        
        if (go.toLowerCase() == "false"){
            return false;
        }
        var tempPage = this.currentPage;
        switch (index){
            case 0:
                tempPage = 1;
                break;
            case 1:
                tempPage = tempPage - 1;
                break;
            case 2:
                tempPage = tempPage + 1;
                break;
            case 3:
                tempPage = this.pageCount;
                break;
            case 4:
                try{
                    tempPage = $("txtCurrentPage").value;
                }
                catch(e){
                    tempPage = $(this.Id + "_txtCurrentPage").value;
                }
        }
        
        if(this.CheckPage(tempPage)){
            $(this.Id + "_PageIndex").value = tempPage;
            if ($b(document,this.Id + "_changepage_btnGoto",0,"INPUT")){
                $b(document,this.Id + "_changepage_btnGoto",0,"INPUT").click();    //执行对应的linkbutton的点击事件
            }
            else{
                var url=$b(document,this.Id + "_PageUrl",0,"INPUT").value;
                var pagePos = url.indexOf("&page=")
                
                if (pagePos>0){
                    var pageC = url.indexOf("&",pagePos+1)
                    if (pageC>0){
                        url=url.substring(0,pagePos)+"&page=" +tempPage + url.substr(pageC);
                    }
                    else{
                        url=url.substring(0,pagePos)+"&page=" +tempPage;
                    }
                }
                else{
                    var pagePos = url.indexOf("?page=")
                    if (pagePos>0){
                        pageC = url.indexOf("&",pagePos+1)
                        if (pageC>0){
                            url=url.substring(0,pagePos)+"?page=" +tempPage + url.substr(pageC);
                        }
                        else{
                            url=url.substring(0,pagePos)+"?page=" +tempPage;
                        }
                    }
                    else{
                        if (url.indexOf("?")>0){
                            url=url+"&page=" +tempPage;
                        }
                        else{
                             url=url+"?page=" +tempPage;
                       }
                    }
                }
                window.location=url;
            }
            return true;
        }
        else{
            $(this.Id + "_txtCurrentPage").value = this.currentPage;
            return false;
        }
    }
}

function GotoPage(o,max){
    if (event.keyCode==13){
        if(IsNumeric(o.value,o)){
            if (parseInt(o.value)>=1 && parseInt(o.value)<=max){
                return true;
            }
            else{
                alert("页面转向范围是(1-" + max + ")，请正确输入");
                return false;
            }
        }
    }
    return false;
}



/*添加事件执行函数*/
function addObjectEvent(objId,eventName,eventFunc)
{
    var targetObj = null
    if (objId!="window" && objId!="document"){
	    targetObj = document.getElementById(objId);
	}
	else{
	    targetObj = eval(objId);
	}
	if(targetObj)
	{
		if(targetObj.attachEvent)
		{
		    try{
			    targetObj.attachEvent(eventName,eventFunc);
			}
			catch(e){
			    alert(e.description);
			}
		}
		else if(targetObj.addEventListener)
		{
			eventName = eventName.toString().replace(/on(.*)/i,'$1');
			targetObj.addEventListener(eventName,eventFunc,true);
		}
	}
	
}

function $(id){
    return document.getElementById(id);
}

//在对象o中找到name属性后部分为lastpart的控件
function $b(o,lastpart,index,tagName){
    if (tagName=="" || tagName==null){
        tagName="*";
    }
    for(i=0;i<o.getElementsByTagName(tagName).length;i++){
        var oc = o.getElementsByTagName(tagName)[i];
        var str = oc.id;
        if (index==1){
            var str = oc.name;
        }
        if (typeof(str)!='undefined'){
            if (str!= "" && str.length>=lastpart.length){
                if (str.substr(str.length-lastpart.length)==lastpart){
                    return oc;
                }
            }
        }
    }
    return null;

}

function doZoom(size,idStr){
    if (idStr=="" || idStr==null){
        idStr = "NewsContet";
    }
    var d = $b(document,idStr,0,"DIV");
    if (d){
        d.style.fontSize=size + "px";
    }
}
function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;
}

//截取字符串首尾空字符
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}


//删除一条记录
function deleteRow(o,msg){
    var op = o.parentNode;
    var message = msg!="" && isNaN(parseInt(msg)) ? msg : "删除信息确认，点击\"确定\"将执行删除操作";
    for(i=0;i<op.getElementsByTagName("a").length;i++){
        var temp=op.getElementsByTagName("a")[i];
        if (temp.id.toLowerCase().indexOf("lbtdelete")>=0){
            return confirm(message);
            return false;
        }
    }
}


//得到对象的左坐标
function findPosX(obj) {

    var curleft = 0;

    if (obj.offsetParent) {

        while (obj) {

	        curleft += obj.offsetLeft;

	        obj = obj.offsetParent;

        }   

    } else if (obj.x) curleft += obj.x;

    return curleft;

}   

//得到对象的上坐标
function findPosY(obj) {

    var curtop = 0;

    if (obj.offsetParent) {
        while (obj) {
	        curtop += obj.offsetTop;

	        obj = obj.offsetParent;

        }   

    } else if (obj.y) curtop += obj.y;

    return curtop;

}

function ResizeImg(obj,w,h){
    var l = 1
    var iw = obj.width;
    var ih = obj.height;
    if (iw>w){
        l = iw/w;
        iw = w;
        ih = ih/l;
    } 

    if (ih>h){
        l = ih/h;
        ih = h;
        iw = iw/l;
    } 
    if(iw==0){iw=w;}
    if(ih==0){ih=h;}
    obj.width = iw;
    obj.height = ih;
}

function IsNumeric(v,o){
	var tmp = parseInt(v);
	if (isNaN(tmp)){
		alert("此处应输入整数，请重新输入");
		return false;
	}
	if (tmp!=v){
		alert("你输入的值中带有字母，将被截断");
		if (o!=null){
			o.value=tmp;
		}
		return true;
	}
	return true;
}

//选择或取消选择选中记录function CheckAll(o,c,index){    if (index==0){        for(i=0;i<o.form.elements.length;i++){            if (o.form.elements[i].name==c){                if (!o.form.elements[i].disabled){                    o.form.elements[i].checked = o.checked;                    //DisabledListText(o.form.elements[i]);                }            }        }    }    else{        //DisabledListText(o);        for(i=0;i<o.form.elements.length;i++){            if (o.form.elements[i].name==o.name){                if (!o.form.elements[i].checked){                    $(c).checked = false;                    return;                }            }        }        if ($(c)!=null){            $(c).checked = true;        }    }}

function simplescroll(c, config) {
	this.config = config ? config : {start_delay:30, speed: 30, delay:30, scrollItemCount:1};
	this.container = document.getElementById(c);
	this.pause = false;
	var _this = this;
	
	this.init = function() {
		_this.scrollTimeId = null;
		setTimeout(_this.start,_this.config.start_delay);
	}
	
	this.start = function() {
		var d = _this.container;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		if(line_height<=20){line_height=22;}
		if(d.scrollHeight-d.offsetHeight>0) _this.scrollTimeId = setInterval(_this.scroll,_this.config.speed)
	};
	
	this.scroll = function() {
		if(_this.pause)return;
		var d = _this.container;
		d.scrollTop+=2;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		if(line_height<=20){line_height=22;}
		if(d.scrollTop%(line_height*_this.config.scrollItemCount)<=1){
			d.scrollTop=0;
			for(var i=0;i<_this.config.scrollItemCount;i++){d.appendChild(d.getElementsByTagName('li')[0]);}
			clearInterval(_this.scrollTimeId);
			setTimeout(_this.start,_this.config.delay);
		}
	}
	
	this.container.onmouseover=function(){_this.pause = true;}
	this.container.onmouseout=function(){_this.pause = false;}
}

//firefox自动换行
function toBreakWord(str,intLen){
    var strContent=str;
    var strTemp="";
    while(strContent.length>intLen){
        strTemp+=strContent.substr(0,intLen)+"<br>";
        strContent=strContent.substr(intLen,strContent.length);
    }
    if (strTemp==""){
        strTemp=str;
    }
    else{
        if (strContent!=""){
            strTemp+=strContent
        }
        else{
            if (strTemp.substr(strTemp.length-4,4)=="<br>"){
                strTemp = strTemp.substr(0,strTemp.length-4)
            }
        }
    }
    return strTemp;
}

function onKeyPressBlockNumbers(e)
{
    var key = window.event ? e.keyCode:e.which;
    return key;
//    var keychar = String.fromCharCode(key);
//    alert(keychar);
//    reg = /\d/;
//    return !reg.test(keychar);
}
