﻿  function change_image(f)
  {
        document.getElementById(f).src=document.getElementById(f).src+"?nowtime="+new Date().getTime();
  }
  function show(URL){
   var cHeight=document.body.scrollHeight > document.body.clientHeight ?document.body.scrollHeight:document.body.clientHeight;
    var bgObj=document.createElement("div");    
    bgObj.setAttribute('id','FormLayer');
    bgObj.style.position="absolute";
    bgObj.style.top="0px";
    bgObj.style.background="white";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width="100%";
    bgObj.style.height=cHeight+"px";
    document.body.appendChild(bgObj);
    var txt=document.createElement("p");
    txt.setAttribute("id","msgTxt");
    txt.innerHTML="<iframe  width=100% height=100% frameborder=0 src='"+URL+"'></iframe>";
    document.getElementById("FormLayer").appendChild(txt);
    return false;
}


function waiting(){
    var msgw,msgh,bordercolor;
    msgw=350;
    msgh=120;
    bordercolor="#336699";
    titlecolor="#99CCFF";

    var sWidth,sHeight,cHeight;
    sWidth=document.body.clientWidth;
    sHeight=document.body.offsetHeight;
    cHeight=document.body.scrollHeight > document.body.clientHeight ?document.body.scrollHeight:document.body.clientHeight;
    var bgObj=document.createElement("div");
    bgObj.setAttribute('id','tempbgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top="0";
    bgObj.style.background="#777";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=0,finishOpacity=25";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width=sWidth + "px";
    bgObj.style.height=cHeight + "px";
    document.body.appendChild(bgObj);
    var msgObj=document.createElement("div")//这个是大盒
    msgObj.setAttribute("id","msgDiv");
    msgObj.setAttribute("align","center");
    msgObj.style.position="absolute";
    msgObj.style.background="white";
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.border="1px solid " + bordercolor;
    msgObj.style.width=msgw + "px";
    msgObj.style.height=msgh + "px";
    msgObj.style.top=(document.documentElement.scrollTop + (sHeight-msgh)/2) + "px";
    msgObj.style.left=(sWidth-msgw)/2 + "px";
    var title=document.createElement("h4");
    title.setAttribute("id","msgTitle");
    title.setAttribute("align","right");
    title.style.margin="0";
    title.style.padding="3px";
    title.style.background=bordercolor;
    title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
    title.style.opacity="0.75";
    title.style.border="1px solid " + bordercolor;
    title.style.height="18px";
    title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color="white";
    title.style.cursor="pointer";
    document.body.appendChild(msgObj);
    document.getElementById("msgDiv").appendChild(title);
    var txt=document.createElement("p");
    txt.style.margin="1em 0"
    txt.setAttribute("id","msgTxt");
    txt.innerHTML="<br>正在执行中,请稍候......";
    document.getElementById("msgDiv").appendChild(txt);
}   

function isEmpty(value) //判断表单值是否为空
{    
//debugger;
     var isValid =validRegExp(/^$/,value)  
     if(value == null) isValid = true;   
     return isValid;     
}

//function validRegExp(pattern,str)
//{
//      var regstr=pattern;
//      var reg=new RegExp(regstr);
//      return reg.test(str) ? true : false;      
//}

function   getUrlParam(key){  
//debugger; 
    var reg =   new   RegExp("(^|&)" + key + "=([^&]*)(&|$)");   
    var r   =    window.location.search.substr(1).match(reg); 
    return r != null ?  decodeURI(r[2]) : null;
    //if   (r!=null)   return   unescape(r[2]);   return   null;   
} 




function compareDate(beginDateValue, endDateValue){
    var beginDate = new Date(beginDateValue.replace("-",",")).getTime() ;
    var endDate = new Date(endDateValue.replace("-",",")).getTime() ;
    if(!isEmpty(beginDateValue) && !isEmpty(endDateValue)){
        if(beginDate > endDate){
            return false;
        }
    }
    return true;
}

function isChinese(nameValue) //中文值检测
{
    if(nameValue.length == 0)
    return false;
    for(i = 0; i < nameValue.length; i++) {
    if(nameValue.charCodeAt(i) > 128)
    return true;
    }
    return false;
}  


//删除左右两端的空格
function trim(str)
{  
    return str.replace(/(^\s*)|(\s*$)/g,"");
}
//删除左边的空格
function ltrim(str)
{  
    return str.replace(/(^\s*)/g,"");
}
//删除右边的空格
function rtrim(str)
{  
    return str.replace(/(\s*$)/g,"");
}
function isEmail(str)
{  
  
//    var reg = /w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*

	var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
//	var re = new RegExp(reg);
    return validRegExp(reg,str);
}

function isPassword(obj)
{
    //6~20个由字母数字下划线组成的密码
    var reg = /^[A-Za-z0-9]{1}([A-Za-z0-9]|[._]){5,20}$/;
    var isValid = validRegExp(reg, obj.value);
    return isValid ? true : false; 
}
function isUserName(str)
{
    var regu = /^[-_A-Za-z0-9]{4,20}$/;
    var re = new RegExp(regu);
    return re.test(str);
}
//function isEmpty(obj) //判断表单值是否为空
//{    
//     var isValid =validRegExp(/^$/,obj.value)     
//     return isValid;     
//}

function validRegExp(pattern,str)
{
      var regstr=pattern;
      var reg=new RegExp(regstr);
      return reg.test(str) ? true : false;      
}
function isDecimal(v){
    return validRegExp(/^\d+(\.\d+)?$/,v);
}
function PreviewImg(imgFile)
{

//新的预览代码，支持 IE6、IE7。
var newPreview = document.getElementById("newPreview");
newPreview.innerText="";
var imgDiv = document.createElement("div");
document.body.appendChild(imgDiv);
imgDiv.style.width = "118px"; 
imgDiv.style.height = "127px";
imgDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)"; 
imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile;
newPreview.appendChild(imgDiv);

var showPicUrl = document.getElementById("showPicUrl");
showPicUrl.innerText=imgFile;
newPreview.style.width = "80px";
newPreview.style.height = "60px";

}

var sIds ='';//选中的id集合
function checkAllItem(o,name){//o:全选checkbox对象this, name：列表项中的checkbox的name属性值
    if(o.checked){
        var oCbxItem = document.getElementsByName(name);
        for(var i = 0; i < oCbxItem.length; i++){
            if(oCbxItem.item(i).disabled){
                oCbxItem.item(i).checked = false;
            }else if(!oCbxItem.item(i).checked){                
                oCbxItem.item(i).checked = true;
                sIds +=  oCbxItem.item(i).value + ',';  
            }                      
        }

    }else{
        var oCbxItem = document.getElementsByName(name);
         sIds = "";
        for(var i = 0; i < oCbxItem.length; i++){
            oCbxItem.item(i).checked = false;           
        }
    }
}
//
function checkItem(o, allcbxId){//列表项中的checkbox的选择事件,o:列表项中的checkbox对象(this),allcbxId:全选checkbox的id属性值
//debugger;
    var oCbxAllItem = document.getElementById(allcbxId);
    if(!oCbxAllItem) return;
    if(oCbxAllItem.checked) {
        oCbxAllItem.checked = oCbxAllItem.checed & 0;        
    }
    if(o.checked){
        if(sIds != "" && sIds != "undefined"){
            
                sIds = sIds.replace(o.value + ",","");
        }
        sIds += o.value + ',';          
    }else{
        if(sIds != "" && sIds != "undefined"){            
             sIds = sIds.replace(o.value + ",","");
        }
    }
}
function isInteger(v){
   var regx = /^\d+$/;
   return validRegExp(regx,v);
}
function filterBadChar(s){
    var regx = /^[^*&^%$#@\\\/]$/;
    return validRegExp(regx,s);
}

function isDecimal(v){
    var regx = /^^\d+(\.\d+)?$/;
    return validRegExp(regx,v);
}
function previewImage(imageOptions) {
//    imageOptions = {
//        src :  '/DefaultPicture/middlegroud_issue_product_picture1.gif',
//        containerId : 'previewImageContainer',
//        width : '80px',
//        height : '60px'
//    };//    
    if (imageOptions.containerId == "undefined"){
        return false;
    }
    var oContainer = document.getElementById(imageOptions.containerId); 
    oContainer.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"; 
    oContainer.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =  imageOptions.src == "undefined" ? "/DefaultPicture/middlegroud_issue_product_picture1.gif" : imageOptions.src; 
    oContainer.style.width = imageOptions.width == "undefined" ? "80px" : imageOptions.width; 
    oContainer.style.height = imageOptions.height == "undefined" ? "60px" : imageOptions.height; 
}

function Load(type,url,width,height,bgColor,bgOpacity){
//debugger;
    if(type == null || typeof type != "string"){
        return;
    }
    this.type = type;
    this.url = url && url != null ? url : "";
    this.width = width && width != null ? width : "154";
    this.height = height &&  height != null ? height : "32"; 
    this.bgBoxId = "";
    this.dialogBoxId = "";
    this.dragMeBoxId = "";
     this.bgOpacity = bgOpacity && bgOpacity != null ? bgOpacity :50;
     this.bgColor = bgColor && bgColor != null ? bgColor :"#000000";
}
Load.prototype.loading = function(){
     /**第一步：创建DIV遮罩层。*/
	   //debugger;
		var sWidth,sHeight;
		sWidth = window.screen.availWidth;
		//屏幕可用工作区高度： window.screen.availHeight;
		//屏幕可用工作区宽度： window.screen.availWidth;
		//网页正文全文宽：     document.body.scrollWidth;
		//网页正文全文高：     document.body.scrollHeight;
		if(window.screen.availHeight > document.body.scrollHeight){  //当高度少于一屏
			sHeight = window.screen.availHeight;  
		}else{//当高度大于一屏
			sHeight = document.body.scrollHeight;   
		}
		//创建遮罩背景
		var oBgBox = document.createElement("div");
		this.bgBoxId = "bgBox";
		oBgBox.setAttribute('id','bgBox');
		oBgBox.style.position = "absolute";
		oBgBox.style.top = "0";
		oBgBox.style.left = "0";
		oBgBox.style.background = this.bgColor;//"#000000";
		oBgBox.style.filter = "Alpha(opacity="+this.bgOpacity+");";
		oBgBox.style.opacity = "0.3";
		oBgBox.style.width = sWidth + "px";
		oBgBox.style.height = sHeight + "px";
		oBgBox.style.zIndex = "990";
		

    /**第二步：动态创建对话框，使弹出div居中打开。*/
        var dailogWidth=this.width,dailogHeight=this.height, bordercolor = "#336699";
    
        var oDialogBox=document.createElement("div")//
        this.dialogBoxId = "dialogBox";
        oDialogBox.setAttribute("id","dialogBox");
        oDialogBox.setAttribute("align","center");
        oDialogBox.style.position="absolute";
        oDialogBox.style.zIndex="999";
        oDialogBox.style.background="#eee";
        oDialogBox.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
        //oDialogBox.style.filter = "Alpha(opacity=100);";
        oDialogBox.style.border="4px solid " + bordercolor;
        oDialogBox.style.width= dailogWidth + "px";
        oDialogBox.style.height= dailogHeight + "px";
        //oBgBox.style.zIndex = "1";       

        
        var page_width = pageWidth(); 
		var page_height = pageHeight();
		var page_left = leftPosition();
		var page_top = topPosition();

		var dialogBox_top = page_top + (page_height / 2) - (dailogHeight / 2); //计算上边距
		var dialogBox_left = page_left + (page_width / 2) - (dailogWidth / 2); //计算左边距

		oDialogBox.style.left = dialogBox_left + "px";  //拼接上 单位"px"
		oDialogBox.style.top =  dialogBox_top + "px";
		oDialogBox.style.display = "block";  //设置弹出div显示		        
      
        document.body.appendChild(oBgBox);
        document.body.appendChild(oDialogBox);
        
        if(this.type.toLowerCase() == "image"){
             
            var oImage = document.createElement("img");
            oImage.setAttribute("id","imgLoading");
            oImage.setAttribute("src",this.url);
            document.getElementById("dialogBox").appendChild(oImage);
        }else if(this.type.toLowerCase() == "iframe"){
           
            var titleHeight = 20;
             var sHtml = "<div id=\"divTitle\" style=\"text-align:right;margin:0 auto;background-color:#003366;width:"+dailogWidth+"px; height:"+titleHeight+"px;\"><span title=\"关闭对话框\" onclick=\"Load.prototype.remove();\" style=\"cursor:pointer;margin-right:1px;color:#fff; text-align:right;\">[关闭]</span></div>";
             sHtml += "<div id=\"divFrameContainer\" style=\"width:"+dailogWidth+"px; height:"+(parseInt(dailogHeight)  - titleHeight)+"px;\"></div>";
             document.getElementById("dialogBox").innerHTML=sHtml;
             this.dragMeBoxId = "divTitle";
//            var oTitle = document.createElement("div");
//            oTitle.setAttribute("id","divTitle");
//            oTitle.style.width = dailogWidth;
//            oTitle.style.height = titleHeight.toString()+"px";
//            oTitle.style.background="#ff0000";
//            oDialogBox.appendChild(oTitle);
//            var oFrameContainer = document.createElement("div");
//            oFrameContainer.setAttribute("id","divFrameContainer");
//            oFrameContainer.style.width = dailogWidth;
//            oFrameContainer.style.height = (parseInt(dailogHeight)  - titleHeight)+ "px";
//            oFrameContainer.style.background="#ff0000";
//            oDialogBox.appendChild(oFrameContainer);
//            var oFrame = document.createElement("iframe");
//            oFrame.setAttribute("id","iframeLoading");
//            oFrame.setAttribute("src",this.url);
//            oFrame.setAttribute("scrolling","0");
//            oFrame.setAttribute("frameborder","0");
//            oFrame.setAttribute("marginheight","0");
//            oFrame.setAttribute("marginwidth","0");            
//            document.getElementById("dialogBox").appendChild(oFrame);
            $("#divFrameContainer").load(this.url);//""
        }
        
}
Load.prototype.remove = function(){
    //debugger;
    var bgBoxId = this.bgBoxId ? this.bgBoxId :"bgBox";
    var dialogBoxId = this.dialogBoxId ? this.dialogBoxId :"dialogBox";
    var oBgBox = document.getElementById(bgBoxId);
    var oDialogBox = document.getElementById(dialogBoxId);
    if( oBgBox != null) document.body.removeChild(oBgBox); 
    if( oDialogBox != null) document.body.removeChild(oDialogBox); 
   
}
var Drag = {
	obj : null,
	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},
	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}
		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
// 计算当前窗口的宽度 //
function pageWidth(){
			 return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// 计算当前窗口的高度 //
function pageHeight(){
			 return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// 计算当前窗口的上边滚动条//
function topPosition(){
			  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// 计算当前窗口的左边滚动条//
function leftPosition(){
			 return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

//解决外嵌样式style , 用js获取不到的问题。
function getStyle(elem, name){
    if(elem.style[name]){
        return elem.style[name];
    }else if(elem.currentStyle){	//ie
        return elem.currentStyle[name];
    }else if(document.defaultView && document.defaultView.getComputedStyle){	//w3c
        name = name.replace(/([A-Z])/g,"-$1");
        name = name.toLowerCase();				
        var s = document.defaultView.getComputedStyle(elem,"");
        return s && s.getPropertyValue(name);
    }
    return null;
}
