﻿// JScript 文件


function getLeft(id) {
    var obj=document.getElementById(id);

    if (obj == null)
        return null;
//        if(document.getElementById(id).style.position.toLowerCase()=='absolute')
//        {
//            return parseInt(document.getElementById(id).style.left);
//        }
//    var mendingObj = obj;
//    var mendingLeft = mendingObj.offsetLeft;
//    while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
//        mendingLeft = mendingLeft + mendingObj.offsetParent.offsetLeft;
//        mendingObj = mendingObj.offsetParent;
//    }
//    return mendingLeft;

    return obj.getBoundingClientRect().left+document.documentElement.scrollLeft;

    
};
function getTop(id) {
    var obj=document.getElementById(id);
    if (obj == null)
        return null;
        
//        if(document.getElementById(id).style.position.toLowerCase()=='absolute')
//        {
//            return parseInt(document.getElementById(id).style.top);
//        }
        
//    var mendingObj = obj;
//    var mendingTop = mendingObj.offsetTop;
//    while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
//        mendingTop = mendingTop + mendingObj.offsetParent.offsetTop;
//        mendingObj = mendingObj.offsetParent;
//    }
//    return mendingTop;

    return obj.getBoundingClientRect().top+document.documentElement.scrollTop;
};



function getLeftByObj(obj) {
 
    if (obj == null)
        return null;
//    var mendingObj = obj;
//    var mendingLeft = mendingObj.offsetLeft;
//    while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
//        mendingLeft = mendingLeft + mendingObj.offsetParent.offsetLeft;
//        mendingObj = mendingObj.offsetParent;
//    }

//    return mendingLeft;
     return obj.getBoundingClientRect().left+document.documentElement.scrollLeft;
};
function getTopByObj(obj) {
 
    if (obj == null)
        return null;
//    var mendingObj = obj;
//    var mendingTop = mendingObj.offsetTop;
//    while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
//        mendingTop = mendingTop + mendingObj.offsetParent.offsetTop;
//        mendingObj = mendingObj.offsetParent;
//    }
//    return mendingTop;
      return obj.getBoundingClientRect().top+document.documentElement.scrollTop;
};


function getWidth(id)
{
   var w;
   var o=document.getElementById(id);
   if(o!=null)
   {
        w=o.offsetWidth;
        if(w==null||w==0)
        {
            w=o.style.width;
        }
   }
   return w;

}


function getHeight(id)
{
   var h;
   var o=document.getElementById(id);
   if(o!=null)
   {
        h=o.offsetHeight;
        if(h==null||h==0)
        {
            h=o.style.height;
        }
   }
   return h;

}



//产生随机数
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
　　　　rnd.seed = (rnd.seed*9301+49297) % 233280;
　　　　return rnd.seed/(233280.0);
};
function rand(number) {
　　　　return Math.ceil(rnd()*number);
};


var getElementsByClassName = function(searchClass,node,tag) {
    if(document.getElementsByClassName){
        return  document.getElementsByClassName(searchClass)
    }else{   
        node = node || document;
        tag = tag || '*';
        var returnElements = []
        var els =  (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag);
        //var i = els.length;
        var i = 0;
        searchClass = searchClass.replace(/\-/g, "\\-");
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        while(++i < els.length){
            if (pattern.test(els[i].className) ) {
                returnElements.push(els[i]);
            }
        }
        return returnElements;
    }
}
//Request["qs"]
function QueryString(qs) { s = location.href; var SharpIndex=s.indexOf("#"); if (SharpIndex!=-1) { s=s.substring(0,SharpIndex); } s = s.replace("?","?&").split("&"); re = ""; for(i=1;i <s.length;i++) { if(s[i].indexOf(qs+"=")==0) { re = s[i].replace(qs+"=",""); } } return re; }

function QueryStringFromStr(s1,qs) 
{
    s = s1.replace("?","?&").split("&"); 
    re = ""; 
    for(var i=0;i <s.length;i++) 
    { 
		var p=s[i].split('=');
        if(p[0]==qs)
         {
            re = p[1]; 
         } 
    } return re; 
}

//把 /转成 <g>
function changetog(str)
{
    var _re=str.replace(/\//ig,'<g>');
    return _re;
}

//把<g>转回 /
function rechangetog(str)
{
    var _re=str.replace(/<g>/ig,'/');
    return _re;
}

 //取checkbox值(radio)
function getCheckBoxValue(InName)
{
	var _re='';
	var o=document.getElementsByName(InName);
	for(var i=0;i<o.length;i++)
	{
		if(o[i].checked==1)
		{
			_re=o[i].value;
		}
 
	}
	return(_re);
}
//给值(radio)
function setCheckBoxValue(InName,va)
{
	var o=document.getElementsByName(InName);
	for(var i=0;i<o.length;i++)
	{
		 if(o[i].value==va)
		 {
			o[i].checked=true;
		 }else
		 {
			o[i].checked=false;
		 }
	}
}

//邮className得到CheckBoxList值
function getCheckBoxListValue(ClassName)
{
    var _re="0";//容个错
    var o=getElementsByClassName(ClassName);
    for(var i=0;i<o.length;i++)
    {
        if(o[i].checked)_re+=','+o[i].value;
    }
    return _re;
}

//邮ClassName还原CheckBoxList
function setCheckBoxList(ClassName,va)
{
    var o=getElementsByClassName(ClassName);
    var arr=va.split(',');
    for(var i=0;i<o.length;i++)
    {
        for(var j=0;j<arr.length;j++)
        {
            if(o[i].value==arr[j])o[i].checked=true;
        }
    }
}

//function correctPNG() 
//  {
//  for(var i=0; i<document.images.length; i++)
//      {
//      var img = document.images[i]
//      var imgName = img.src.toUpperCase()
//      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
//        {
//        var imgID = (img.id) ? "id='" + img.id + "' " : ""
//        var imgClass = (img.className) ? "class='" + img.className + "' " : ""
//        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
//        var imgStyle = "display:inline-block;" + img.style.cssText 
//        if (img.align == "left") imgStyle = "float:left;" + imgStyle
//        if (img.align == "right") imgStyle = "float:right;" + imgStyle
//        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle        
//        var strNewHTML = "<span " + imgID + imgClass + imgTitle
//        + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
//        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
//        + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
//        img.outerHTML = strNewHTML
//        i = i-1
//        }
//      }
//  }
//window.attachEvent("onload", correctPNG);

//写iframe 上标题
function setIFrameTitle(titlename)
{
    parent.document.getElementById('frametitle').innerText=titlename;
}
