//those vars are for split pane
var g_fIsPublic = false;
var g_iPreview = 2;
var g_iViewWidth = 187;
var g_iViewHeight = 343;
//var zones defines the zones that are to be reloaded
var zones = "";
//var submitInd indicates whether or not to submit the request
//refer to function addEvents() for the usage of this var
var submitInd = true;
//open/close tool bar
var g_iGroup = 0;
var g_oTimer = null;
function voidSetAccBar(iGroup, bGradual) {
	if (!document.getElementById("tblGroup")) {
    return;
  }
    
  var bShowNext = (arguments.length > 2) ? arguments[2] : false;
  if(g_iGroup == iGroup && bShowNext) {
    if (iGroup < 10)
      voidSetAccBar(iGroup + 2, bGradual, true);
    else
      voidSetAccBar(0, bGradual, true);
      
    return;
  }
  
  g_iGroup = iGroup;
  var oGroupTab = document.getElementById("tblGroup");
  var oGroupCount = Math.floor((oGroupTab.rows.length)/2);
  var iAvailHeight = oGroupTab.offsetHeight - oGroupTab.rows[0].offsetHeight- oGroupTab.rows[1].offsetHeight - 2;
  for (var i=0; i<oGroupTab.rows.length-1; i++) {
    if (i == iGroup) {
	  oGroupTab.rows[++i].style.display = "";
      
      if (bGradual) {
       // voidGradualHigh(oGroupTab.rows[i], iAvailHeight - oGroupCount*28);
      }
      else {
        //oGroupTab.rows[i].style.height = eval(iAvailHeight - oGroupCount*28) + "px";
      }
    }
    else {
      oGroupTab.rows[++i].style.display = "none";
      //oGroupTab.rows[i].style.height = "2px";
    }
  }
}


function DateAdd(interval,number,date){
		alert(date);
	alert(date.getFullYear())
	switch(interval.toLowerCase()){
		case "y": return new Date(date.setFullYear(date.getFullYear()+number));
		case "m": return new Date(date.setMonth(date.getMonth()+number));
		case "d": return new Date(date.setDate(date.getDate()+number));
		case "w": return new Date(date.setDate(date.getDate()+7*number));
		case "h": return new Date(date.setHours(date.getHours()+number));
		case "n": return new Date(date.setMinutes(date.getMinutes()+number));
		case "s": return new Date(date.setSeconds(date.getSeconds()+number));
		case "l": return new Date(date.setMilliseconds(date.getMilliseconds()+number));
	} 
}
function DateDiff(interval,date1,date2){
	alert(date2.getTime());
	alert(date1.getTime());
	var long = date2.getTime() - date1.getTime(); 
	alert(long);
	switch(interval.toLowerCase()){
		case "y": return parseInt(date2.getFullYear() - date1.getFullYear());
		case "m": return parseInt((date2.getFullYear() - date1.getFullYear())*12 + (date2.getMonth()-date1.getMonth()));
		case "d": return parseInt(long/1000/60/60/24);
		case "w": return parseInt(long/1000/60/60/24/7);
		case "h": return parseInt(long/1000/60/60);
		case "n": return parseInt(long/1000/60);
		case "s": return parseInt(long/1000);
		case "l": return parseInt(long);
	}
}

function IsDate(dateval){
	var arr = new Array();
	
	if(dateval.indexOf("-") != -1){
		arr = dateval.toString().split("-");
	}else if(dateval.indexOf("/") != -1){
		arr = dateval.toString().split("/");
	}else{
		return false;
	}
	
	//yyyy-mm-dd || yyyy/mm/dd
	if(arr[0].length==4){
		var date = new Date(arr[0],arr[1]-1,arr[2]);
		if(date.getFullYear()==arr[0] && date.getMonth()==arr[1]-1 && date.getDate()==arr[2]){
			return true;
		}
	}
	//dd-mm-yyyy || dd/mm/yyyy
	if(arr[2].length==4){
		var date = new Date(arr[2],arr[1]-1,arr[0]);
		if(date.getFullYear()==arr[2] && date.getMonth()==arr[1]-1 && date.getDate()==arr[0]){
			return true;
		}
	}
	//mm-dd-yyyy || mm/dd/yyyy
	if(arr[2].length==4){
		var date = new Date(arr[2],arr[0]-1,arr[1]);
		if(date.getFullYear()==arr[2] && date.getMonth()==arr[0]-1 && date.getDate()==arr[1]){
			return true;
		}
	}
	
	return false;
}

function embeddedbadDisplayNone(){
	document.getElementById("basicInfo").style.display="none";
	document.getElementById("hzInfo").style.display="none";
	document.getElementById("blsjInfo").style.display="none";
	document.getElementById("ylqxInfo").style.display="none";
	document.getElementById("blsjpj").style.display="none";			
}
function showInformation(tabName){	
	document.detailForm.action="embeddedbad.do?method=showTab&showTab="+tabName;	
    ajaxAnywhere.formName="detailForm";
	ajaxAnywhere.areas="detailZone";
	ajaxAnywhere.submitAJAX();			   
}
function subchklink() // 
{
	
	var enter=true;
	var info=document.getElementById("info2");
	var msg="";
	if(document.getElementById('info.link_title').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入网站名称;";enter=false
	}
	if(document.getElementById('info.link_content').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入网站网址;";enter=false
	}
	
	if(enter==false){
		info.innerHTML=msg;
		return false;
	}else{
	return true;
	}

} 
function subchkjj() // 
{
	document.getElementById('info.jj_content').value = window.content_html.getHTML();
	var enter=true;
	var info=document.getElementById("info2");
	var msg="";
	if(document.getElementById('info.jj_title').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的标题;";enter=false
	}
	if(document.getElementById('info.jj_content').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的内容;";enter=false
	}
	
	if(enter==false){
		info.innerHTML=msg;
		return false;
	}else{
	return true;
	}

} 
function subchkzn() // 
{
	document.getElementById('info.zn_content').value = window.content_html.getHTML();
	var enter=true;
	var info=document.getElementById("info2");
	var msg="";
	if(document.getElementById('info.zn_title').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的标题;";enter=false
	}
	if(document.getElementById('info.zn_content').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的内容;";enter=false
	}
	
	if(enter==false){
		info.innerHTML=msg;
		return false;
	}else{
	return true;
	}

} 
function subchkzc() // 
{
	document.getElementById('info.zc_content').value = window.content_html.getHTML();

	var enter=true;
	var info=document.getElementById("info2");
	var msg="";
	if(document.getElementById('info.zc_haoma').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入文件号;";enter=false
	}
	if(document.getElementById('info.zc_title').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的标题;";enter=false
	}
	if(document.getElementById('info.zc_content').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的内容;";enter=false
	}
	
	if(enter==false){
		info.innerHTML=msg;
		return false;
	}else{
	return true;
	}
} 
function subchkgg() // 
{
	document.getElementById('info.gg_content').value = window.content_html.getHTML();
	var enter=true;
	var info=document.getElementById("info2");
	var msg="";
	if(document.getElementById('info.gg_title').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的标题;";enter=false
	}
	if(document.getElementById('info.gg_content').value.match(/^\s*$/g)){//如果未输入，提示
		msg+="　　请输入您的内容;";enter=false
	}
	
	if(enter==false){
		info.innerHTML=msg;
		return false;
	}else{
	return true;
	}

} 


function searchLossStorage(searchvalue){
	if(document.detailForm.selectType.value==searchvalue){
		window.open("page.do?object=searchstorage&goodsId="+document.detailForm.goodsId.value+"&sequenceNo="+document.detailForm.sequenceNo.value);
	}
}
//this function adds the onmouseover, onmouseout and onclick events to 
//the data pane in every row
function changeOutstockSelectType(){
	document.detailForm.selectType.value = document.headForm.newSelectType.value;
}
function changeLossSelectType(){
	
	document.detailForm.sequenceNo.value = "";
	document.detailForm.selectType.value = document.headForm.newSelectType.value;
	document.headForm.action="loss.do?method=changeType";
	ajaxAnywhere.formName="headForm";
	ajaxAnywhere.areas="detailZone";
	ajaxAnywhere.submitAJAX();	
	
	
}
function changeReceieveSelectType(){
	document.detailForm.sequenceNo.value = "";
	document.detailForm.selectType.value = document.headForm.newSelectType.value;
	document.headForm.action="receieve.do?method=changeType";
	ajaxAnywhere.formName="headForm";
	ajaxAnywhere.areas="detailZone";
	ajaxAnywhere.submitAJAX();	
	
	
}

function searchEmbeddedGoods(){
	window.open("page.do?object=searchqxxx&qxsx=embedded&searchContent="+document.detailForm.goodsId.value);
}

function searchNewEmbeddedGoods(){
	if(event.keyCode==13)
		{
		window.open("page.do?object=searchqxxx&qxsx=embedded&searchContent="+document.detailForm.goodsId.value);
		}
}

function searchOneoffGoods(){
	window.open("page.do?object=searchqxxx&qxsx=oneoff&searchContent="+document.detailForm.goodsId.value);
}

function searchNewOneoffGoods(){
	if(event.keyCode==13)
		{
		window.open("page.do?object=searchqxxx&qxsx=oneoff&searchContent="+document.detailForm.goodsId.value);
		}
}

function searchQxxxContent(){
	ajaxAnywhere.onAfterResponseProcessing = function(){
		for(var i=0;i<2;i++)
		document.errorForm.searchContent.focus();
	}
	document.errorForm.SearchQxxxButton.click();
	ajaxAnywhere.onAfterResponseProcessing = function(){
	}
}

function searchGoods(){
	window.open("page.do?object=searchqxxx&searchContent="+document.detailForm.goodsId.value);
}



function changeTrStyle(highlightcolor,object){
	if(object){
		if(object.length){
			for(var i=0;i<object.length;i++){
				var trId= object[i].value;
				if(object[i].checked){
					document.getElementById(trId).style.backgroundColor=highlightcolor;
					//alert("aa:"+document.getElementById(trId).style.backgroundColor);
				}
				else{
				//alert("bb:"+trId);
				//alert(trId);
				document.getElementById(trId).style.backgroundColor='#f5f5f5';
				}
			}
		}else{
			var trId= object.value;
			document.getElementById(trId).style.backgroundColor=highlightcolor;
		}
	}
}

function searchNewGoods(){
	if(event.keyCode==13)
		{
		ajaxAnywhere.formName="detailForm";
		ajaxAnywhere.areas="detailZone";
		document.detailForm.action="page.do?object=searchqxxx&searchContent="+document.detailForm.goodsId.value;
		ajaxAnywhere.submitAJAX();
		}
}

function searchNextGoods(){
	if(event.keyCode==13)
		{
			ajaxAnywhere.onAfterResponseProcessing = function(){
				if(!document.getElementById("searchqxxxDiv")){
					document.detailForm.goodsId.focus();
					document.detailForm.goodsId.blur();
				}
				ajaxAnywhere.onAfterResponseProcessing = function(){
				}
			}
			document.searchForm.searchButton.click();
		}
}

function searchQxlb(content){
	ajaxAnywhere.formName="detailForm";
	ajaxAnywhere.areas="qxlbZone";
	document.detailForm.action="page.do?object=searchqxlb&searchType="+content;
	ajaxAnywhere.submitAJAX();
}

function nextTab(){
		if(event.keyCode==13){
			event.keyCode = 9;
		}
}
	
function searchNewStorages(){
	if(event.keyCode==13)
		{
		ajaxAnywhere.formName="detailForm";
		ajaxAnywhere.areas="detailZone";
		document.detailForm.action="page.do?object=searchstorage&goodsId="+document.detailForm.goodsId.value+"&sequenceNo="+document.detailForm.sequenceNo.value;
		ajaxAnywhere.submitAJAX();	
		}
}

function clickSearchQxxx(){
	if(event.keyCode==13){
		ajaxAnywhere.onAfterResponseProcessing = function(){
				var object =document.detailForm.goodsId;
				for(var i=0;i<2;i++)
				object.focus();
				ajaxAnywhere.onAfterResponseProcessing = function(){
				}
			}
		document.errorForm.searchQxxx.click();
	}
}

function clickSearchStorage(){
	if(event.keyCode==13){
		ajaxAnywhere.onAfterResponseProcessing = function(){
				var object =document.detailForm.sequenceNo;
				for(var i=0;i<2;i++)
				object.focus();
				ajaxAnywhere.onAfterResponseProcessing = function(){
				}
			}
		document.errorForm.searchStorage.click();
	}
}

function addDetail(){
	if((event.keyCode==13)&&(event.ctrlKey))
		document.detailForm.addDetailButton.click();
}
	
function searchStorages(){
		window.open("page.do?object=searchstorage&goodsId="+document.detailForm.goodsId.value+"&sequenceNo="+document.detailForm.sequenceNo.value);
}
function doChangeDetail(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="detailZone";
	ajaxAnywhere.submitAJAX();					
}

function doChangeListheadDetail(){
	ajaxAnywhere.formName="headlistForm";
	ajaxAnywhere.areas="headZone,detailZone,listZone";
	ajaxAnywhere.submitAJAX();	
}
function doChangeCheckReceieveDetail(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="detailZone,passZone,detailContentZone";
	ajaxAnywhere.submitAJAX();
}
	
function doChangeContentDetail(){
	ajaxAnywhere.formName="detailForm";
	ajaxAnywhere.areas="detailContentZone";
	ajaxAnywhere.submitAJAX();
	}
function searchTypeSearch(){
		ajaxAnywhere.formName="headForm";
		ajaxAnywhere.areas="listZone";
		ajaxAnywhere.submitAJAX();					
	}



function overTab(me){
	if(me.className != "left_bottom_selected"){
		me.className="left_bottom_over";
	}
}

function outTab(me){
	if(me.className != "left_bottom_selected"){
		me.className="left_bottom_default";
	}
}

function ddInit(){
	var sourceDiv = document.getElementById("sourceDiv");
	var distDiv = document.getElementById("distDiv");
	var itemCount = 0;
	if(sourceDiv != null){
		var sourceDD = new YAHOO.util.DD("sourceDiv", "group1");
		var sourceTables = sourceDiv.getElementsByTagName("table");
		if(sourceTables != null && sourceTables.length == 1){
			var sourceTable = sourceTables[0];
			sourceTable.onselectstart = function () { return false; };
			if(sourceTable.id.indexOf("sourceList") > -1){
				itemCount = sourceTable.rows.length;
			}
		}
	}
	if(distDiv != null){
		var distDD = new YAHOO.util.DD("distDiv", "group1");
		var distTables = distDiv.getElementsByTagName("table");
		if(distTables != null && distTables.length == 1){
			var distTable = distTables[0];
			distTable.onselectstart = function () { return false; };
			if(distTable.id.indexOf("distList") > -1){
				itemCount = itemCount + distTable.rows.length;
			}
		}
	}
	if(itemCount > 0){
		var items = new Array();
		for(var i = 0; i < itemCount; i++){
			items[i] = new ygDDList("item" + i, "group1");
			items[i].setDragElId("dragElement");
		}
	}
}
function pickOption(e, me){
	var event = e ? e : window.event;
	var currentRow = me.parentNode.parentNode;
	var rowIndex = currentRow.rowIndex;
	var rowCount = currentRow.parentNode.rows.length;
	var listBox = currentRow.parentNode.parentNode;
	var rowBox = document.getElementById(listBox.id + ":" + rowIndex + ":selectedInd");
	for(var i = 0; i <rowCount; i++){
		document.getElementById(listBox.id + ":" + i + ":selectedInd").checked = false;
		listBox.rows[i].className = "ddNormal";
	}
	document.getElementById(listBox.id + ":" + rowIndex + ":selectedInd").checked = true;
	currentRow.className = "ddSelected";
}
var lastPosition = -1;
var lastShift = false; // previous select holding the Shift key?
function pickOptions(e, me){
	var event = e ? e : window.event;
	var currentRow = me.parentNode.parentNode; // the current "tr" object
	var rowIndex = currentRow.rowIndex; // current row index
	var rowCount = currentRow.parentNode.rows.length; // row count for the container table
	var listBox = currentRow.parentNode.parentNode; // the container table
	
	//listBox.id = "mainForm:sourceList";
	var rowBox = document.getElementById(listBox.id + ":" + rowIndex + ":selectedInd"); // the current hidden checkbox
	//alert(me.parentNode.parentNode.parentNode.id);
	
	if(event.ctrlKey && !event.shiftKey){
		lastShift = false;
		var currentBox = document.getElementById(listBox.id + ":" + rowIndex + ":" + "selectedInd")
		if(currentBox.checked){
			currentBox.checked = false;
			currentRow.className = "ddNormal";
		}else{
			currentBox.checked = true;
			currentRow.className = "ddSelected";
		}
	}else if(event.shiftKey && !event.ctrlKey){
		lastPosition = lastPosition == -1 ? currentRow : lastPosition;
		if(!lastShift){
			for(var b = 0; b < rowCount; b++){
				document.getElementById(listBox.id + ":" + b + ":" + "selectedInd").checked = false;
				listBox.rows[b].className = "ddNormal";
			}
		}
		if(rowIndex >= lastPosition){
			if(!document.getElementById(listBox.id + ":" + rowIndex + ":" + "selectedInd").checked){
				for(var c = lastPosition; c <= rowIndex; c++){
					document.getElementById(listBox.id + ":" + c + ":" + "selectedInd").checked = true;
					listBox.rows[c].className = "ddSelected";
				}
			}else{
				for(var c = lastPosition; c < rowIndex; c++){
					document.getElementById(listBox.id + ":" + c + ":" + "selectedInd").checked = false;
					listBox.rows[c].className = "ddNormal";
				}
			}
		}else{
			if(!document.getElementById(listBox.id + ":" + rowIndex + ":" + "selectedInd").checked){
				for(var f = rowIndex; f <= lastPosition; f++){
					document.getElementById(listBox.id + ":" + f + ":" + "selectedInd").checked = true;
					listBox.rows[f].className = "ddSelected";
				}
			}else{
				for(var g = rowIndex + 1; g <= lastPosition; g++){
					document.getElementById(listBox.id + ":" + g + ":" + "selectedInd").checked = false;
					listBox.rows[g].className = "ddNormal";
				}
			}
		}
		lastShift = true;
	}else{
		lastShift = false;
		for(var i = 0; i < rowCount; i++){
			document.getElementById(listBox.id + ":" + i + ":selectedInd").checked = false;
			listBox.rows[i].className = "ddNormal";
		}
		document.getElementById(listBox.id + ":" + rowIndex + ":selectedInd").checked = true;
		currentRow.className = "ddSelected";
	}
	lastPosition = rowIndex;
	currentRow.focus();
	
	
	
	

}

function collapse(me, targetId){
	var id = me.id;
	var prefix = id.substring(0, id.lastIndexOf(":"));
	var target = document.getElementById(prefix + ":" + targetId);
	if(target.style.display == "block"){
		me.src = "../images/arrowright.gif";
		me.parentNode.parentNode.parentNode.parentNode.className = "infoHidden";
		target.style.display = "none";
	}else{
		me.src = "../images/arrowdown.gif";
		me.parentNode.parentNode.parentNode.parentNode.className = "infoShow";
		target.style.display = "block";
	}
}

function enterSubmit(e, me) {
	var event = e ? e : window.event;
	if (event.keyCode == 13) {
		//ajaxAnywhere.areas = "contentZone";
		me.form.submit();
	}
}


function initLiveHelp(){
	new YAHOO.util.DD("liveHelpDiv",1).setHandleElId("liveHelpDivHeader");
}

function closeLiveHelpDiv(){
	$("liveHelpDiv").style.display = "none";
}

function showLiveHelpDiv(){
	$("liveHelpDiv").style.display = "block";
}

function showAccountMenu(menuId,event){
	var actionMenu;
	// find the table object and the context menu object
	var tableElements = document.getElementsByTagName("table");
	for(var a = 0; a < tableElements.length; a++){
		if(tableElements[a].id.indexOf(menuId) > -1 ){
			actionMenu = tableElements[a];
			break;
		}
	}
	if (event == null) event = window.event;
	// document.body.scrollTop does not work in IE
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
	
	// hide the menu first to avoid an "up-then-over" visual effect
	actionMenu.style.display = 'none';
	actionMenu.style.left = event.clientX + scrollLeft - 10 + 'px';
	actionMenu.style.top = event.clientY + scrollTop - 3 + 'px';
	actionMenu.style.display = 'block';
}

function showSearchMenu(menuId,event){
	var actionMenu;
	// find the table object and the context menu object
	var tableElements = document.getElementsByTagName("table");
	for(var a = 0; a < tableElements.length; a++){
		if(tableElements[a].id.indexOf(menuId) > -1 ){
			actionMenu = tableElements[a];
			break;
		}
	}
	if (event == null) event = window.event;
	// document.body.scrollTop does not work in IE
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
	
	// hide the menu first to avoid an "up-then-over" visual effect
	actionMenu.style.display = 'none';
	actionMenu.style.left = event.clientX + scrollLeft - 10 + 'px';
	actionMenu.style.top = event.clientY + scrollTop - 3 + 'px';
	actionMenu.style.display = 'block';
}

function closeErrorMessages(me) {
	var errorMessages = me.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	if (errorMessages != null) {
		errorMessages.parentNode.removeChild(errorMessages);
	}
}
function closeErrorMessages2(me) {
	var errorMessages = me.parentNode.parentNode;
	if (errorMessages != null) {
		errorMessages.parentNode.removeChild(errorMessages);
	}
}
function enterConfirmKey(event,confirmId,cancelId){
	if(event==null) event=window.event;
	var ele;
	if(event.keyCode==13){//Enter key pressed
		ele=document.getElementById(confirmId);
		if(ele){
			ele.click();
		}
		event.keyCode=null;//clear key event
	}else if(event.keyCode==27){//Esc key pressed
		ele=document.getElementById(cancelId);
		if(ele){
			ele.click();
		}
		event.keyCode=null;//clear key event
	}else{
		//other key let event fllow up to uplevel.
	}
}

/**
 * getElements(classname, tagname, root):
 * Return an array of DOM elements that are members of the specified class,
 * have the specified tagname, and are descendants of the specified root.
 *
 * If no classname is specified, elements are returned regardless of class.
 * If no tagname is specified, elements are returned regardless of tagname.
 * If no root is specified, the document object is used. If the specified
 * root is a string, it is an element id, and the root
 * element is looked up using getElementsById()
 */
function getElementsByClassName(classname, tagname, root) {
    // If no root was specified, use the entire document
    // If a string was specified, look it up
    if (!root) root = document;
    else if (typeof root == "string") root = document.getElementById(root);

    // if no tagname was specified, use all tags
    if (!tagname) tagname = "15-";

    // Find all descendants of the specified root with the specified tagname
    var all = root.getElementsByTagName(tagname);

    // If no classname was specified, we return all tags
    if (!classname) return all;

    // Otherwise, we filter the element by classname
    var elements = [];  // Start with an empty array
    for(var i = 0; i < all.length; i++) {
        var element = all[i];
        if (isMember(element, classname)) // isMember() is defined below
            elements.push(element);       // Add class members to our array
    }

    // Note that we always return an array, even if it is empty
    return elements;

    // Determine whether the specified element is a member of the specified
    // class. This function is optimized for the common case in which the
    // className property contains only a single classname. But it also
    // handles the case in which it is a list of whitespace-separated classes.
    function isMember(element, classname) {
        var classes = element.className;  // Get the list of classes
        if (!classes) return false;             // No classes defined
        if (classes == classname) return true;  // Exact match

        // We didn't match exactly, so if there is no whitespace, then
        // this element is not a member of the class
        var whitespace = /\s+/;
        if (!whitespace.test(classes)) return false;

        // If we get here, the element is a member of more than one class and
        // we've got to check them individually.
        var c = classes.split(whitespace);  // Split with whitespace delimiter
        for(var i = 0; i < c.length; i++) { // Loop through classes
            if (c[i] == classname) return true;  // and check for matches
        }

        return false;  // None of the classes matched
    }
}

function getFirstElementByClassName(classname,tag,root){
	var eles=getElementsByClassName(classname,tag,root);
	if(eles.length>0){
		return eles[0];
	}else{
		return null;
	}
}

function createFullScreenMask(id){
	var mask=document.createElement("div");
	mask.className="divFullScreenMask";
	mask.id=id;
	var parentEl=document.getElementsByTagName("BODY")[0];
	parentEl.appendChild(mask);
	return mask;
}

function createPlaceHolder(id){
	var placeHolder=document.createElement("div");
	placeHolder.className="divPlaceHolder";
	placeHolder.id=id;
	var parentEl=document.getElementsByTagName("BODY")[0];
	parentEl.appendChild(placeHolder);
	return placeHolder;
}


var _mainTicketPanel, _proxyObject;
var _positionY=0;
var _positionX=0;
var _newSize=200;
var _lastSize=_newSize;
var _maxSize=document.body.offsetHeight-180;
var _iframe;
//This function trigered when use drag the middle panel in the ticket main portion.
function startResize(event,parentId,dragId){
	var mybody=document.getElementById("mybody");
	mybody.style.cursor="move";
	_mainTicketPanel=document.getElementById(parentId);
	_proxyObject=document.getElementById("pageResizePanelProxy");
	dragObj=document.getElementById(dragId);
	if(event==null) event=window.event;
	_positionY= event.clientY; // remember the current position.
	_positionX= 210;
	_iframe=document.getElementById("iframeText");
	if(_iframe){
		_iframe.style.display="none";
	}
	document.onmousemove= function (event){
		// the list size can't less than 20 px or more than screen size;
		if(_positionY==0){
			return false;
		} // not ready, do nothing
		if(event==null) event=window.event;
		_newSize=_lastSize - (_positionY*1-event.clientY*1);
		//window.status=_newSize+"; pY:"+_positionY +"; clientY:"+event.clientY;
		if(_newSize<20 || _newSize>_maxSize){
			return false;
		}
		_proxyObject.style.display="block";
		_proxyObject.style.top=event.clientY;
		_proxyObject.style.left=_positionX;
		return false;
	}
	document.onmouseup= function (event){
		var mybody=document.getElementById("mybody");
		mybody.style.cursor="default";
		if(event==null) event=window.event;
		_positionY= event.clientY;
		if(_newSize<20){
			_newSize=20;
		}else if(_newSize>_maxSize){
			_newSize=_maxSize;
		};
		_mainTicketPanel.rows[0].style.height=_newSize;
		_lastSize=_newSize;
		_proxyObject.style.display="none";
		if(_iframe){
			_iframe.style.display="block";
		}
		document.onmousemove='';
		document.onmouseup='';
		//alert('released');
		return false;
		//window.status="";
	}
}


var diffX=0;
var diffY=0;
function operateBox(dragItemId){
	//alert(dragItemId);
	var dragItem=document.getElementById(dragItemId);
	if(dragItem==null) return false;
	dragItem.onmousedown=function(event){
		dragItem.style.cursor="move";
		if(event==null) event=window.event;
		diffX=event.clientX-dragItem.offsetLeft;
		diffY=event.clientY-dragItem.offsetTop;
		if(event.button==1){
			document.onmousemove=function(event){
				if(event==null) event=window.event;
				dragItem.style.left=event.clientX-diffX;
				dragItem.style.top=event.clientY-diffY;
			};
			
			document.onmouseup=function(event){
				setDragItemInRange(dragItemId);
				document.onmousemove='';
				document.onmouseup='';
				dragItem.onmousedown='';
				dragItem.style.cursor="default";
			};

		}
	};
	
 }
function operateBoxNoInRange(dragItemId){
	//alert(dragItemId);
	var dragItem=document.getElementById(dragItemId);
	if(dragItem==null) return false;
	dragItem.onmousedown=function(event){
		dragItem.style.cursor="move";
		if(event==null) event=window.event;
		diffX=event.clientX-dragItem.offsetLeft;
		diffY=event.clientY-dragItem.offsetTop;
		if(event.button==1){
			document.onmousemove=function(event){
				if(event==null) event=window.event;
				dragItem.style.left=event.clientX-diffX;
				dragItem.style.top=event.clientY-diffY;
			};
			
			document.onmouseup=function(event){
				//setDragItemInRange(dragItemId);
				document.onmousemove='';
				document.onmouseup='';
				dragItem.onmousedown='';
				dragItem.style.cursor="default";
			};

		}
	};
	
 }

  function setDragItemInRange(dragItemId){
	var oDragItem=document.getElementById(dragItemId);
	var iBodyW=document.body.clientWidth;
	var iBodyH=document.body.clientHeight;
	var iDownX=oDragItem.offsetLeft;
	var iDownX2=iDownX+oDragItem.offsetWidth;
	var iDownY=oDragItem.offsetTop;
	var iDownY2=iDownY+oDragItem.offsetHeight;
	if(iDownX<=0){oDragItem.style.left=1;}
	if(iDownY<=0){oDragItem.style.top=1;}
	if(iDownX2>=iBodyW){oDragItem.style.left=iBodyW-oDragItem.offsetWidth-1;}
	if(iDownY2>=iBodyH){oDragItem.style.top=iBodyH-oDragItem.offsetHeight-1;}
  }

   function isOverDragTarget(dragItemId){
	var oDragItem=document.getElementById(dragItemId);
	var iBodyW=document.body.clientWidth;
	var iBodyH=document.body.clientHeight;
	var iDownX=oDragItem.offsetLeft;
	var iDownX2=iDownX+oDragItem.offsetWidth;
	var iDownY=oDragItem.offsetTop;
	var iDownY2=iDownY+oDragItem.offsetHeight;
	return (iDownX>=0 && iDownX2<=iBodyW && iDownY>=0 && iDownY2<=iBodyH);
 }
 function doSearch(){
		var object = document.errorForm.detailId;
		if(object.length){
			for(var i=0;i<object.length;i++){
				if(object[i].checked){
					window.opener.detailForm.goodsId.value=object[i].value;
					window.opener.searchForm.searchButton.click();
					window.close();
					break;
				}
			}
		}
		else{
			window.opener.detailForm.goodsId.value=object.value;
			window.opener.searchForm.searchButton.click();
			window.close();
		}
	}
function doSearchQxxx(){
	var object = document.errorForm.detailId;
	if(object){
		if(object.length){
			for(var i=0;i<object.length;i++){
				if(object[i].checked){
					document.detailForm.goodsId.value=object[i].value;
					document.searchForm.searchButton.click();
					//document.errorForm.closeQxxx.click();
					break;
				}
			}
		}
		else{
			document.detailForm.goodsId.value=object.value;
			document.searchForm.searchButton.click();
			//document.errorForm.closeQxxx.click();
		}
	}
}
function doSearchStorage(){
	var object = document.errorForm.detailId;
	if(object){
			if(object.length){
				for(var i=0;i<object.length;i++){
					if(object[i].checked){
						document.detailForm.storageId.value=object[i].value;
						document.searchForm.searchStorageButton.click();
						//window.close();
						break;
					}
				}
			}else{
				document.detailForm.storageId.value=object.value;
				document.searchForm.searchStorageButton.click();
				//window.close();		
			}
		}
}
function checkreceievePasstype(){
		document.mainForm.action="checkreceieve.do";
		ajaxAnywhere.formName="mainForm";
		ajaxAnywhere.areas="bodyZone";
		ajaxAnywhere.submitAJAX();					
	}
function checkreceieve(){
		document.mainForm.action="checkreceieve.do?method=check";
		ajaxAnywhere.formName="mainForm";
		ajaxAnywhere.areas="bodyZone";
		ajaxAnywhere.submitAJAX();					
	}
function doAddEmbeddeduse(){
	var object = document.receieveForm.objectId;
	if(object){
		if(object.length){
			for(var i=0;i<object.length;i++){
				if(object[i].checked){
					document.receieveForm.action="receieve.do?method=addEmbeddeduse&embeddeduseId="+object[i].value;
					ajaxAnywhere.formName="receieveForm";
					ajaxAnywhere.areas="bodyZone";
					ajaxAnywhere.submitAJAX();
					//document.errorForm.closeQxxx.click();
					break;
				}
			}
		}
		else{
					document.receieveForm.action="receieve.do?method=addEmbeddeduse&embeddeduseId="+object.value;
					ajaxAnywhere.formName="receieveForm";
					ajaxAnywhere.areas="bodyZone";
					ajaxAnywhere.submitAJAX();
			//document.errorForm.closeQxxx.click();
		}
	}
}
///////////yaojian use  this js  kenty use
function yaojianshowDetail(){
	ajaxAnywhere.formName="headForm";
	ajaxAnywhere.areas="contentZone";
	ajaxAnywhere.submitAJAX();					
}

function changeto(highlightcolor) {
	source = event.srcElement;
	if (source.tagName == "TR" || source.tagName == "TABLE") {
		return;
	}
	while (source.tagName != "TD") {
		source = source.parentElement;
	}
	if (source.style.backgroundColor != highlightcolor && source.id != "ignore") {
		source.style.backgroundColor = highlightcolor;
	}
}
function changetoTR(highlightcolor) {
	source = event.srcElement;
	if (source.tagName == "TABLE") {
		return;
	}
	while (source.tagName != "TR") {
		source = source.parentElement;
	}
	if (source.style.backgroundColor != highlightcolor && source.id != "ignore") {
		source.style.backgroundColor = highlightcolor;
	}
}
function changetoTD(highlightcolor) {
	source = event.srcElement;
	if (source.tagName == "TABLE") {
		return;
	}
	while (source.tagName != "TD") {
		source = source.parentElement;
	}
	if (source.style.backgroundColor != highlightcolor && source.id != "ignore") {
		source.style.backgroundColor = highlightcolor;
	}
}
function onclickTR(object,pagenum,actionname)
{
	ajaxAnywhere.formName='mainForm';
	ajaxAnywhere.areas='ddZone';
	document.mainForm.action=actionname+'.do?typeParam=showcurrentpage&&objectid='+object+"&&pageNum="+pagenum;
	ajaxAnywhere.submitAJAX();
}
function onclickEmbeddedbadTR(object,pagenum,actionname)
{
	ajaxAnywhere.formName='mainForm';
	ajaxAnywhere.areas='ddZone,listZone';
	document.mainForm.action=actionname+'.do?typeParam=showcurrentpage&&objectid='+object+"&&pageNum="+pagenum;
	ajaxAnywhere.submitAJAX();
}
function onclickTD(goods_id,hospital_id,pagenum,actionname,searchwho)
{
	ajaxAnywhere.formName='mainForm';
	ajaxAnywhere.areas='ddZone';
	document.mainForm.action=actionname+'.do?typeParam=showcurrentpage&&goodsId='+goods_id+"&&hospitalId="+hospital_id+"&&pageNum="+pagenum+"&&searchwho="+searchwho;
	ajaxAnywhere.submitAJAX();
}
function showdownsubmit()
{
	var object = document.mainForm.checkId;
	if(document.mainForm.downsubmit.flag=='false')
	{
		
		if(object){
		if(object.length)
		{
			for(var i=0;i<object.length;i++){
				if(object[i].checked)
				{
					document.mainForm.downsubmit.disabled=false;
					break;
				}
				else
				{
					document.mainForm.downsubmit.disabled=true;
				}
			}
		}
		else
		{
			if(object.checked)
				{
					document.mainForm.downsubmit.disabled=false;
				}
				else
				{
					document.mainForm.downsubmit.disabled=true;
				}
		}
		
	}
	}
}
// checkbox all
function checkboxAll(itemName)
{
	var item = document.mainForm.checkId;
	if(item.length)
	{
		for (var i=0; i<item.length; i++)
		{
			item[i].checked = true;
		}
	}
	else
	{
		item.checked = true;
	}
	
}

 //checkbox no
function checkboxNoAll(itemName)
{
	var item = document.mainForm.checkId;
	if(item.length)
	{
		for (var i=0; i<item.length; i++)
		{
			item[i].checked = false;
		}
	}
	else
	{
		item.checked = false;
	}
}
// checkbox all
function checkboxAll2(itemName,item)
{
//	var item = document.headlistForm.checkId;
	if(item.length)
	{
		for (var i=0; i<item.length; i++)
		{
			item[i].checked = true;
		}
	}
	else
	{
		item.checked = true;
	}
	
}

 //checkbox no
function checkboxNoAll2(itemName,item)
{
//	var item = document.mainForm.checkId;
	if(item.length)
	{
		for (var i=0; i<item.length; i++)
		{
			item[i].checked = false;
		}
	}
	else
	{
		item.checked = false;
	}
}
////////////////////////
function addDetailClick(){
	if(event.keyCode==13)
		{
	document.detailForm.addDetailButton.click();
	}
}

function doshowEmbeddedbad(){
	ajaxAnywhere.formName="mainForm";
	document.mainForm.action="yjhs.do?method=showEmbeddedbadContent";
	ajaxAnywhere.areas="headZone";
	ajaxAnywhere.submitAJAX();
}

function doshowPatient(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="headZone";
	document.mainForm.action="yjhs.do?method=showPatientContent";
	ajaxAnywhere.submitAJAX();
}
function doshowHospital(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="headZone";
	document.mainForm.action="yjhs.do?method=showHospitalContent";
	ajaxAnywhere.submitAJAX();
}

function doshowProprietor(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="headZone";
	document.mainForm.action="yjhs.do?method=showProprietorContent";
	ajaxAnywhere.submitAJAX();
}
function doshowProducer(){
	ajaxAnywhere.formName="mainForm";
	ajaxAnywhere.areas="headZone";
	document.mainForm.action="yjhs.do?method=showProducerContent";
	ajaxAnywhere.submitAJAX();
}

function doAddQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone";
	document.qxlbForm.action="page.do?object=addQxlb";
	ajaxAnywhere.submitAJAX();
}

function doDelQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone";
	document.qxlbForm.action="page.do?object=delQxlb";
	ajaxAnywhere.submitAJAX();
}

function decideQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone,jyfwlbZone";
	document.qxlbForm.action="clientapply.do?method=decideQxlbs";
	ajaxAnywhere.submitAJAX();
}

function addCert(){
	ajaxAnywhere.formName="detailForm";
	ajaxAnywhere.areas="certZone";
	document.detailForm.action="client.do?method=addCert";
	ajaxAnywhere.submitAJAX();
}

function delCert(){
	ajaxAnywhere.formName="detailForm";
	ajaxAnywhere.areas="certZone";
	document.detailForm.action="client.do?method=delCert";
	ajaxAnywhere.submitAJAX();
}

//kenty use for check file name

function upcheck_filetype(objectname)
{
	var filename=document.getElementById("file").value;
	
	if(filename=="")
	{
		alert("\u8bf7\u9009\u62e9\u4e0a\u4f20\u6587\u4ef6\uff01\uff01\uff01\uff01");	
		return false;	
		
	}
	else
	{
		var strtype=filename.substring(filename.lastIndexOf(".")+1,filename.length);
		var filefirst=filename.substring(filename.lastIndexOf("\\")+1,filename.lastIndexOf("."));
		var tempfilename=filefirst.substring(0,filefirst.lastIndexOf("-"));
		strtype=strtype.toLowerCase();
		if(strtype=="xls"&&tempfilename==objectname)
		{
			return true;
		}
		else
		{
			alert("\u8fd9\u79cd\u7c7b\u578b\u4e0d\u5141\u8bb8\u4e0a\u4f20\uff0c\r\n"+
			"\u6216\u8005\u8bf7\u786e\u5b9a\u4e0a\u4f20\u7684\u6587\u4ef6\u662f\u5426\u4ee5 \""+ objectname+"-\"\u5f00\u5934\u7684xls\u8868");
			return false;
		}
	}
}
function secBoard(n) 
	{ 
		for(i=0;i<secTable.cells.length;i++) 
		secTable.cells[i].className="sec1"; 
		secTable.cells[n].className="sec2"; 
		for(i=0;i<mainTable.tBodies.length;i++) 
		mainTable.tBodies[i].style.display="none"; 
		mainTable.tBodies[n].style.display="block"; 
	} 
	
	

function checkNotNull(object)
{
	var flag=0;
	var e = object.elements;
	for(var i=0;i < e.length;i++)
	{
		var obj = e[i];
		if(obj.mustcheck=='must')
		{		
			if(!obj.value.length&&flag==0)
			{
				alert("\u8bf7\u5728\u7ea2\u8272\u6846\u5185\u586b\u4e0a\u76f8\u5173\u6570\u636e");
				obj.focus();
				flag=1;
			}
			obj.style.borderColor = "red";
			if(obj.value.length)
				obj.style.borderColor = "window";
		}
	}
}
function checkclientapplyPasstype(){
		document.mainForm.action="checkclientapply.do";
		ajaxAnywhere.formName="mainForm";
		ajaxAnywhere.areas="bodyZone";
		ajaxAnywhere.submitAJAX();					
	}
	function doAddapplyQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone";
	document.qxlbForm.action="page.do?object=addapplyQxlb";
	ajaxAnywhere.submitAJAX();
}

function doDelapplyQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone";
	document.qxlbForm.action="page.do?object=delapplyQxlb";
	ajaxAnywhere.submitAJAX();
}

function decideapplyQxlb(){
	ajaxAnywhere.formName="qxlbForm";
	ajaxAnywhere.areas="qxlbZone,jyfwlbZone";
	document.qxlbForm.action="client.do?method=decideQxlbs";
	ajaxAnywhere.submitAJAX();
}	
function doPrintgoods(){
	var object = document.goodsForm.goodsId;
	var hascheck = false
	if(object){
		if(object.length){
			for(var i=0;i<object.length;i++){
				if(object[i].checked){
					window.open('showsuperviseplan.do?method=printgoods&goodsId='+object[i].value
					+'&startDate='+document.headForm.startDate.value+'&endDate='+document.headForm.endDate.value);
					hascheck = true;
					break;
				}
			}
			if(!hascheck)
				alert("\u8bf7\u9009\u62e9\u8981\u6253\u5370\u7684\u5668\u68b0");
		}
		else{
				window.open('showsuperviseplan.do?method=printgoods&goodsId='+object.value
				+'&startDate='+document.headForm.startDate.value+'&endDate='+document.headForm.endDate.value);
		}
	}
}

function delQxReport(){
	var objectId=document.dd.objectId.value;
	if(objectId){
		ajaxAnywhere.formName='mainForm';
		ajaxAnywhere.areas='listZone,ddZone';
		document.mainForm.action='qxreport.do?typeParam=delete&objectid='+document.dd.objectId.value;
		ajaxAnywhere.submitAJAX();
	}else{
		alert("\u8bf7\u5148\u9009\u62e9\u8981\u5220\u9664\u7684\u5217");
	}
}
	
