﻿// JScript File

function getValue(ctrlId)
{
    var _ctrl = document.getElementById(ctrlId);
    if(_ctrl)
    {
        if(_ctrl.tagName == "SPAN")
            return _ctrl.innerText;
        else if(_ctrl.tagName == "DIV")
            return _ctrl.innerHTML;
        else
            return _ctrl.value;
    }
    else
    {
        return "";
    }
}

function setValue(ctrlId,ctrlValue)
{
    var _ctrl = document.getElementById(ctrlId);
    if(_ctrl == null)return;
    
    if(_ctrl.tagName == "SPAN" || _ctrl.tagName == "DIV")
        _ctrl.innerHTML = ctrlValue;
    else if(_ctrl.type == "select-one")
    {
        if(_ctrl.options.length >1)
            _ctrl.value = ctrlValue;
        else
        {
            var values = ctrlValue.split('$');
            if(values.length == 2)
                 _ctrl.options.add(new Option(values[0],values[1]));
            else
                 _ctrl.options.add(new Option(controlValue,controlValue));
        }
    }
    else if(_ctrl.type == "checkbox")
    {
        if(controlValue == "true")
            _ctrl.checked = true;
        else
            _ctrl.checked = false;
    }
    else
        _ctrl.value = ctrlValue;
}

    //提交某个FORM
function FormSubmit(TheFormID)
{
		 var FormNoID = document.getElementById(TheFormID);	     
		 		if (FormNoID != null)
		        {
                FormNoID.submit();
		        }  
}
    //提交某个FORM,同时关闭某个DIV
function FormSubmitHideDiv(TheDivID,TheFormID)
{
 var mm=confirm('你确定了吗？');
 if(mm)
 { 
	    var NoID = document.getElementById(TheDivID);	
		    if (NoID != null)
		        {
                NoID.className="Hide";
		        }
		var FormNoID = document.getElementById(TheFormID);	     
		 		if (FormNoID != null)
		        {
                FormNoID.submit();
		        }  
  }
}

    //提交某个A标鉴,同时隐藏某个ID
function ASubmitHideID(The_ID,TheClassName)
{
 var mm=confirm('你确定了吗？');
 if(mm)
 { 
	    var NoID = document.getElementById(The_ID);	
		    if (NoID != null)
		        {
                NoID.className=TheClassName;
		        } 
  }
  return mm;
}
function ButtonOpenUrl(thUrl)
{
   window.location.href=thUrl;
   return false;
}
//按钮提交页面
    function ButtonSubmit(TheUrl)
    {
     var mm=confirm('你确定了吗？');
        if(mm)
            {
//            window.frames['iframeForm'].location=TheUrl; 
            window.frames['iframeForm'].location.href=TheUrl; 
            }
    }
    function ButtonSubmit(TheUrl,ThDivID)
    {
     var mm=confirm('你确定了吗？');
        if(mm)
            {
            var NoID = document.getElementById(ThDivID);	
		    if (NoID != null)
		        {
                NoID.className="Hide";
		        } 
//            window.frames['iframeForm'].location=TheUrl; 
            window.frames['iframeForm'].location.href=TheUrl; 
            }
    }
//设置某个DIV的ClassName
function SetDivClassName(TheDivID,TheClassName)
{
    var TheDivNoIDB = document.getElementById(TheDivID);
    if(TheDivNoIDB!=null)
    {	
        TheDivNoIDB.className=TheClassName;
    }
  
}
//隐藏或者显示某个DIV
function HideShowDiv(TheDivID)
{
    var TheDivNoIDB = document.getElementById(TheDivID);	
    if(TheDivNoIDB.className=="Show" ||TheDivNoIDB.className=="")
        TheDivNoIDB.className="Hide";
    else
        TheDivNoIDB.className="Show";
        return false;
}
//隐藏某个DIV
function ShowHideDiv(TheDivID,TheClassName)
{
    var TheDivNoIDB = document.getElementById(TheDivID);	
    var The_Class=TheClassName+" Hide";
    if(TheDivNoIDB.className!="Hide" && TheDivNoIDB.className!=The_Class )
        TheDivNoIDB.className="Hide";
    else
    {
        if(TheClassName!="")
            TheDivNoIDB.className=TheClassName+" Show";
        else
            TheDivNoIDB.className="Show";
    }
    return false;
}

function ShowAllText(MainID)
{
    if (MainID != "")
	{   
	    var NoID = document.getElementById("L"+MainID);	
		    if (NoID != null)
		        {
		            if (NoID.style.display=="none")
		                {	NoID.style.display="block";}
		            else{NoID.style.display="none";}
		        }
		       
	    var NoID2 = document.getElementById("A"+MainID);	
		    if (NoID2 != null)
		        {
		            if (NoID2.style.display=="none")
		                {	NoID2.style.display="block";}
		            else{NoID2.style.display="none";}
		        }
	}
}
function CloseAllText(MainID)
{
 var mm=confirm('你确定了吗？');
 if(mm)
 {
    if (MainID != "")
	{   
	    var NoID = document.getElementById(MainID);	
		    if (NoID != null)
		        {
                NoID.style.display="none";
		        }
		       
	}
  }
  return mm;
}
function CloseAllTextNew(MainID)
{
 var mm=confirm('你确定了吗？');
 if(mm)
 {
    if (MainID != "")
	{   
	    var NoID = document.getElementById(MainID);	
		    if (NoID != null)
		        {
                NoID.style.display="none";
		        }
		       
	}
  }
  return mm;
}

/**Array的自定义操作
 是否包含Item**/
Array.prototype.contains = function(varElement){
    var result = false;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == varElement) {
            result = true;
            break;
        }
    }
    return result;
}

/**删除Item **/
Array.prototype.deleteElement = function(varElement){
    var numDeleteIndex = -1;
    for (var i = 0; i < this.length; i++) {
        /**严格比较，即类型与数值必须同时相等**/
        if (this[i] === varElement) {
            this.splice(i, 1);
            numDeleteIndex = i;
            break;
        }
    }
    return numDeleteIndex;
}

/**返回字符串：xxx,xxx,xxx格式**/
Array.prototype.toStr = function(){
    var result = "";
    for (var i = 0; i < this.length; i++) {
        result += this[i] + ",";
    }
    return result;
}

   function openNewWeb(webUrl)
   {
       window.location.href=webUrl;
     return false;
   }
    function WindowReload()
    {
        location.reload();
    }
    
 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, "");
}

// replace如果替换数据时，默认只替换第一个。　　如果在替换的时候加上： / 替换内容 /g 就能实现全部替换

//将某个元素移动到屏幕中央 
function resetControlToCenter(controlId, controlWidth, controlHeight){
    if (!document.getElementById(controlId)) 
        return;
    if (controlWidth) 
        document.getElementById(controlId).style.width = controlWidth;
    if (controlHeight) 
        document.getElementById(controlId).style.height = controlHeight;
    document.getElementById(controlId).style.top = (document.documentElement.scrollTop +
    (document.documentElement.clientHeight - document.getElementById(controlId).offsetHeight) / 2) +
    "px";
    
    document.getElementById(controlId).style.left = (document.documentElement.scrollLeft +
    (document.documentElement.clientWidth - document.getElementById(controlId).offsetWidth) / 2) +
    "px";
}

function resetControlToCenterNew(TheDivID, TheWidth,TheHeight){
    if (TheWidth == "") {
        TheWidth = 600;
    }
    var scrollPos;
    if (typeof window.pageYOffset != 'undefined') {
        scrollPos = window.pageYOffset;
    }
    else 
        if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
            scrollPos = document.documentElement.scrollTop;
        }
        else 
            if (typeof document.body != 'undefined') {
                scrollPos = document.body.scrollTop;
            }
    
    
    var Browser_Name = navigator.appName;
    var is_IE = (Browser_Name == "Microsoft Internet Explorer");
    var is_NN = (Browser_Name == "Netscape");
    
    var prodtldiv = document.getElementById(TheDivID);
    if (is_NN) {
        prodtldiv.style.top = (window.screenY+TheHeight)/2 + "px";
        prodtldiv.style.left = ((window.screen.width - TheWidth) / 2) + "px";
    }
    else 
        if (is_IE) {

            prodtldiv.style.top = (window.screen.height - TheHeight) / 2;
            prodtldiv.style.left = (window.screen.width - TheWidth) / 2;
        }
}


function reloadCurrentPage()
{
  window.location.href =window.location.href +"#currenta";
//window.location.reload();
//window.navigate(window.location.href +"#currenta");
}
