



window.servercontentPath="";
//window.onerror = new Function("return true")

/**
open new Window
2001-10 by hide
*/
function openWin(w,h,fileUrl) {
	var scrLeft=(screen.width-w)/2;
	var scrTop=(screen.height-h)/2;
	var param = 'top='+scrTop+',left='+scrLeft+',toolbar=0,location=0,status=0,menubar=0,resizable=1, scrollbars=1,width='+w+',height='+h+''
	return window.open(fileUrl,"newwin",param);
}
/** END */


function buttonOver() {
	var obj = event.srcElement;
	if(obj.tagName == "IMG") {
		obj = obj.parentElement
	}
	if(obj.tagName == "TD") {
		with(obj) {
			bgColor = "#CFDAE1";
			borderColor='#446679';
		}
	}
}
function buttonOut() {
	var obj = event.srcElement;
	if(obj.tagName == "IMG") {
		obj = obj.parentElement
	}
	if(obj.tagName == "TD") {
		with(obj) {
			bgColor = "";
			borderColor='';
		}
	}
}

function popWin(url){
	if(url==null){
		var el = event.srcElement;
		var href = event.srcElement.href;
		while(el.tagName!="A"){
			el = el.parentElement;
			href = el.href;
		}
		url = href;
	}
	if(url==null){
		return false;
	}
	var win =  window.open(url,"pop","status=0,resizable=1,scrollbars=1,center=1");
	win.focus();
	event.returnValue = false;
	return win;

}

function writeDateOfToday(){
	document.write("" + (new Date()).getYear() + "&#24180;" + ((new Date()).getMonth()+1)+ "&#26376;" + (new Date()).getDate() + "&#26085;" )
}

function openDialog(url, w, h){
	if(url==null){
		var el = event.srcElement;
		var href = event.srcElement.href;
		while(el.tagName!="A"){
			el = el.parentElement;
			href = el.href;
		}
		url = href;
	}
	if(url==null){
		return false;
	}
        var width = (w==null?250:w);
        var height = (h==null?250:h);
        var lef = (window.screen.width-width)/2;
        var top = (window.screen.width-height)/2;
        //var sFeatures = "dialogWidth:" + width + "px;dialogHeight=" + height + "px;status:0;resizable:1;scrollbars:1;center:1"
        var sFeatures = "width=" + width + ",height=" + height + ",status=0,resizable=1,scrollbars=1,center=1"
	return window.open(url, "newwin", sFeatures);;
}
/*
 * 显示对话框
 * 返回窗口对象
 */
function openDialog(url, windowname, width, height){
	if(url==null){
		var el = event.srcElement;
		var href = event.srcElement.href;
		while(el.tagName!="A"){
			el = el.parentElement;
			href = el.href;
		}
		url = href;
	}
        windowname = (windowname==null?"dialog":windowname);
        width = (width==null?300:width);
        height = (height==null?250:height);
        var left = (window.screen.availWidth-width)/2;
        var top = (window.screen.availHeight-height)/2;
        var sFeatures = "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",status=1,resizable=1, scrollbars=1,center=1";
	return window.open(url, windowname , sFeatures);
}

function showHelp(title, content,  width, height){
  var arr = new Array();
  arr[0] = title;
  arr[1] = content;
  var url = window.servercontentPath + "/_pub/help.html";
  var sFeatures = "dialogWidth:" + width + "px;dialogHeight:" + height + "px; center:1; status:0"
  window.showModalDialog(url, arr,  sFeatures);
}

function tab(text,oId) {
		this.text = text;
		this.oId = oId;
}

function tabPage() {
		this.tabs = new Array();
		this.addTabs = function(text,oId) {
			this.tabs[this.tabs.length++] = new tab(text,oId);
		}
		this.tabColumns = null;
		this.init = function(defaultTab) {
			var o = document.createElement("div");
			o.id = "oDiv";
			for(var i=0;this.tabs.length>i;i++) {
				if(typeof(this.tabs[i].oId)!="undefined" && defaultTab!=this.tabs[i].oId) {
					document.getElementById(this.tabs[i].oId).style.display = "none";
				}
				var span = document.createElement("span");
				with(span) {
					innerText = this.tabs[i].text;
					className = "tab";
					setAttribute("oId",this.tabs[i].oId)
					onclick = function() {
						var _o = document.getElementById("oDiv").getElementsByTagName("SPAN");
						for(var i=0;_o.length>i;i++) {
							document.getElementById(_o[i].oId).style.display = _o[i].oId==this.oId?"":"none";
						}
					}
					onmouseover = function() {
						this.style.backgroundColor = "#DAE6F9";
					}
					onmouseout = function() {
						this.style.backgroundColor = "#FFFCF2";
					}
				}
				o.appendChild(span);
			}
			var p = document.createElement("p");
			o.appendChild(p);
			document.getElementById(this.tabs[0].oId).insertAdjacentElement("beforeBegin",o)
		}
	}


function selectAll(){
          var o = event.srcElement;
          var oForm = o.form;
          for(var i=0;oForm.elements.length>i;i++) {
            if(oForm.elements[i].type=="checkbox") {
              oForm.elements[i].checked = o.checked;
            }
          }
        }

function moveSelect(select1,select2,selectAll,add,remove,removeAll) {
	var oOriginal = document.getElementById(select1);
	var oTarget = document.getElementById(select2);
        var oSelectAll = document.getElementById(selectAll);
	var oAdd = document.getElementById(add);
	var oRemove = document.getElementById(remove);
        var oRemoveAll = document.getElementById(removeAll);
	oOriginal.ondblclick = oAdd.onclick = function(){
		for(var i=0;oOriginal.options.length>i;i++) {
			q:if(oOriginal.options[i].selected) {
				for(var l=0;oTarget.options.length>l;l++) {
					if(oTarget.options[l].text==oOriginal.options[i].text) {
						break q;
					}
				}
				oTarget.options.length++;
				oTarget.options[oTarget.length-1].text = oOriginal.options[i].text;
                                oTarget.options[oTarget.length-1].value = oOriginal.options[i].value;
			}
		}
	}
        oSelectAll.onclick=function(){
        	for(var i=0;oTarget.options.length>i;i++){
                	oTarget.options.remove(i);
                        i--;
                }
                for(var i=0;oOriginal.options.length>i;i++){
                	oTarget.options.length++;
                	oTarget.options[i].text = oOriginal.options[i].text;
                        oTarget.options[i].value = oOriginal.options[i].value;
                }
        }
	oTarget.ondblclick = oRemove.onclick = function(){
		for(var i=0;oTarget.options.length>i;i++) {
			if(oTarget.options[i].selected) {
				oTarget.options.remove(i);
				i--;
			}
		}
	}
        oRemoveAll.onclick=function(){
        	for(var i=0;oTarget.options.length>i;i++){
                	oTarget.options.remove(i);
                        i--;
        	}
        }
}

function findByCodeFromServer(url, func, query){
  showLoading();
  try{ 

	var oScript = document.createElement("script");
    oScript.src = window.servercontentPath + url + "?function=" + func + "&rndCode="+Math.random() + "&" + query;
    document.body.appendChild(oScript);
  }catch(e){
	alert(e.description);
  }
} 

function callBackFromServer(func, args){
   try{
	eval(func + "(args);" );
   }catch(e){
   	alert("Error: callBackFromServer: "+func+": " +e.description);
   }
   hideLoading();
}


function listByCode(callbackfunc, t, code){
  try{
	findByCodeFromServer("/maindoc/loadByCode.js.jsp", callbackfunc,  "code=" + code + "&type=" + t);
  }catch(e){
	alert(e.description);
  }
}

function showLoading(){
	if(document.all["loading"]){
        		with(document.all["loading"]){
        			style.display="";
                                		style.left=(document.body.clientWidth-parseInt(style.width))/2;
                                		style.top=(document.body.clientHeight-parseInt(style.height))/2;
                        	}
	}
}

function hideLoading(){
	if(document.all["loading"])document.all["loading"].style.display="none";
}
function moveSelect(select1,select2,selectAll,add,remove,removeAll) {
	var oOriginal = document.getElementById(select1);
	var oTarget = document.getElementById(select2);
    var oSelectAll = document.getElementById(selectAll);
	var oAdd = document.getElementById(add);
	var oRemove = document.getElementById(remove);
    var oRemoveAll = document.getElementById(removeAll);
    
	oOriginal.ondblclick = oAdd.onclick = function(){
	        var indexes = new Array();
      	    for(var i=0;oOriginal.options.length>i;i++) {
			    if(oOriginal.options[i].selected) {
				    oTarget.options.length++;
				    oTarget.options[oTarget.length-1].text = oOriginal.options[i].text;
                    oTarget.options[oTarget.length-1].value = oOriginal.options[i].value;
                    indexes[indexes.length]=i;
                    //alert(i);
			    }
		    
		    }
		    for(var i=indexes.length-1; i>=0;i--){
                	oOriginal.options.remove(indexes[i]);
            }
	}
    oSelectAll.onclick=function(){
            for(var i=0;oOriginal.options.length>i;i++){
                	oTarget.options.length++;
                	oTarget.options[oTarget.length-1].text = oOriginal.options[i].text;
                    oTarget.options[oTarget.length-1].value = oOriginal.options[i].value;
            }
            for(var i=0;oOriginal.options.length>i;i++){
                	oOriginal.options.remove(i);
                	 i--;
            }
    }
	oTarget.ondblclick = oRemove.onclick = function(){
	        var indexes = new Array();
      	    for(var i=0;oTarget.options.length>i;i++) {
			    if(oTarget.options[i].selected) {
				    oOriginal.options.length++;
				    oOriginal.options[oOriginal.length-1].text =oTarget.options[i].text;
                    oOriginal.options[oOriginal.length-1].value = oTarget.options[i].value;
                    indexes[indexes.length]=i;
			    }
		    
		    }
		    for(var i=indexes.length-1; i>=0;i--){
                	oTarget.options.remove(indexes[i]);
            }

	}
    oRemoveAll.onclick=function(){
            for(var i=0;oTarget.options.length>i;i++){
                	oOriginal.options.length++;
                	oOriginal.options[oOriginal.length-1].text = oTarget.options[i].text;
                    oOriginal.options[oOriginal.length-1].value = oTarget.options[i].value;
            }
            for(var i=0;oTarget.options.length>i;i++){
                	oTarget.options.remove(i);
                	 i--;
            }
    }
}

function listStOrder(callbackfunc,storeno,vendorcode,date){
  try{
	findByCodeFromServer("/maindoc/listStOrder.js.jsp", callbackfunc,  "storeno=" + storeno +"&vendorcode="+vendorcode+ "&date=" + date);
  }catch(e){
	alert(e.description);
  }
}
function listStOrder2(callbackfunc,storeno,vendorcode,date,orderNo){
  try{
	findByCodeFromServer("/maindoc/listStOrder2.js.jsp", callbackfunc,  "storeno=" + storeno +"&vendorcode="+vendorcode+ "&date=" + date+"&orderNo=" + orderNo);
  }catch(e){
	alert(e.description);
  }
}