﻿document.write("<scri"+"pt type='text/javascript' src='../Js/ymPrompt.js'></scr"+"ipt>"); 
document.write("<link rel='stylesheet' id='skin' type='text/css' href='../Images/skin/qq/ymPrompt.css' />"); 
document.write("<scri"+"pt type='text/javascript' src='../Js/AJAX.js'></scr"+"ipt>"); 
/*关于AJAX超时提示*/   
function EndRequestHandler(sender, args)        
{
    if (args.get_error() != undefined)            
    {                      
        if(args.get_error().message.substring(0, 51) == "Sys.WebForms.PageRequestManagerParserErrorException")                
        {              
            ymPrompt.alert('您的操作超时了！');                    
            /*刷新当前页面*/
            window.location.reload()
        }                
        else                
        {  
            ymPrompt.alert("发生错误，原因可能是网络延迟！");              
            /*刷新当前页面*/
            window.location.reload()
        }
        args.set_errorHandled(true);            
    }        
}
/*焦点转移*/
function VerifyOnKeyUp(bool,Name,NextName,Type)
{   
    if(window.event.keyCode==13)
    {
        var obj;             
        if(bool)            
        {
            if(!Verify(false,document.getElementById(Name),Type))
            {            
                obj = document.getElementById(Name);
            }  
            else
            {
                obj = document.getElementById(NextName);
            }             
        }       
        else
        {        
            obj = document.getElementById(NextName);
        }
        obj.select();
        obj.focus();         
    }    
}

/*数值*/
function NumValueVerify(maxValue,minValue,value)
{
    if(isNaN(maxValue))
    {
        return false;
    }
    else if(isNaN(minValue))
    {
        return false;
    }
    else if(isNaN(value))
    {
        return false;
    }                        
    var max = parseFloat(maxValue);
    var min = parseFloat(minValue);
    var num = parseFloat(value);
    if(!NoNullVerify(max))
    {
        if(num > maxValue)
        {
            return false;
        }
    }
    if(!NoNullVerify(min))
    {
        if(num < min)
        {
            return false;
        }
    }
    return true;
}


/*提交验证*/        
function SaveVerify()
{              
    for(var i = 0; i < form1.elements.length; i++)
    {
        var obj = form1.elements[i];         
        /*是否需要认证*/
        if(obj.IsRequired != null)
        {                
            if(obj.IsRequired == "false" && (obj.value == null || obj.value == ""))
            {   
                /*可为空*/                                             
                continue;                        
            }
            else if(obj.IsRequired == "true" && (obj.value == null || obj.value == ""))
            {
                /*必填*/
                if(!NoNullVerify(obj.ExceptionMessageOne))
                {
                    ymPrompt.alert(obj.ExceptionMessageOne);
                }
                else if(!NoNullVerify(obj.ItemNameID))
                {
                    var message = document.getElementById("messageOne").value;
                    var name = document.getElementById(obj.ItemNameID).innerText;
                    name = name.substring(0,name.length-1);
                    ymPrompt.alert(message+name);
                }
                else
                {
                    ymPrompt.alert("Error!");
                }                        
                obj.focus();
                obj.select();
                return false;                        
            }       
            else
            {
                /*开始验证*/     
                var ok = false;
                if(obj.VerifyType == "NumValue")
                {                        
                    ok = NumValueVerify(obj.MaxValue,obj.MinValue,obj.value);                
                }
                else
                {
                    ok = Verify(obj,obj.VerifyType);
                }                    
                if(ok == false)
                {
                    if(!NoNullVerify(obj.DefaultValue))
                    {
                        obj.value = obj.DefaultValue;
                    }
                    else
                    {
                        obj.value = "";
                    }
                    obj.focus();
                    obj.select();
                    if(obj.VerifyType == "DateTime")
                    {
                        return false;
                    }                                                                  
                    if(!NoNullVerify(obj.ExceptionMessageTwo))
                    {                             
                        ymPrompt.alert(obj.ExceptionMessageTwo);
                    }
                    else if(!NoNullVerify(obj.ItemNameID))
                    {                        
                        var message = document.getElementById("messageTwo").value;
                        var name = document.getElementById(obj.ItemNameID).innerText;
                        name = name.substring(0,name.length-1);
                        ymPrompt.alert(name+message);
                    }
                    else
                    {
                        ymPrompt.alert("Error!");
                    }  
                                                                             
                    return false;                        
                }                    
            }                       
        }                              
    }           
    return true; 
}
 
/*数据验证*/        
/*  obj  如果是按钮调用则需要传入需要判断控件*/
/*  type 比较类型 */
function Verify(obj,type)
{         
    var reg;      
    switch(type)
    {
        case "NoNull":   
            return !NoNullVerify(obj.value);
            break;
        case "Email":   
            reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/        
            break;
        case "Phone": 
            reg = /^((\(\d{3}\)|\d{3}-)?\d{8}|(1)\d{10})$/        
            break;
        case "PostCode":        
            reg = /^\d{6}$/
            break;
        case "LoginName":          
            reg = /[\w\-]{3,16}/               
            break;
        case "Integer":
            reg = /^\d+$/ 
            break;
        case "Num":               
            reg = /^(([0-9]+[.][0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*[.][0-9]+)|([0-9]*[1-9][0-9]*))$/
            break;    
        case "DateTime":               
            return TimeVerify(obj);
            break;                              
        default :          
            return true;
            break;                        
    }    
    var dataValue;                                             
    if(obj == null)            
    {                        
        /*自身触发事件*/
        obj = event.srcElement;                                
    }
    dataValue = obj.value;    
    if(!reg.test(dataValue))
    {                    
        return false;
    }
    return true;    
}

/*非空验证*/
function NoNullVerify(dataValue)
{
    if(dataValue == null || dataValue == "")
    {           
        /*为空*/             
        return true;
    }
    else
    {
        /*不为空*/
        return false;
    }    
}

/* 时间验证*/
function TimeVerify(obj)
{
    if(obj == null)            
    {                        
        /*自身触发事件*/
        obj = event.srcElement;                                
    }
    var dataValue = obj.value;
    var message = "";
    var reg=/^((\d{2}(([02468][048])|([13579][26]))[\-\/]?((((0?[13578])|(1[02]))[\-\/]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/]?((((0?[13578])|(1[02]))[\-\/]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/
    if(!reg.test(dataValue))
    {        
        message = "请按照正确的年份格式输入 \n   如：2008-08-08 \n       2008/08/08";                
    }            
    else if(dataValue.substring(0,4)<1990)
    {
        /*年份必须大于1990*/
        message = "输入的年份必须大于1990年";        
    }
    if(message == "")
    {
        return true;    
    }
    else    
    {
        ymPrompt.alert(message);
        return false;
    }    
}

/*鼠标移开验证*/
function BlurVerify()
{
    var obj = event.srcElement;     
    if(obj.value !="" && obj.value != null )
    {        
        if(!Verify(null,obj.VerifyType))
        {
            if(!NoNullVerify(obj.ExceptionMessageTwo))
            {
                ymPrompt.alert(obj.ExceptionMessageTwo);
            }
            else if(!NoNullVerify(obj.ItemNameID))
            {
                var message = document.getElementById("messageTwo").value;
                var name = document.getElementById(obj.ItemNameID).innerText;
                ymPrompt.alert(name+message);
            }
            else
            {                                
                ymPrompt.alert("Error!");
            }
            if(!NoNullVerify(obj.DefaultValue))
            {
                obj.value = obj.DefaultValue;
            }
            else
            {
                obj.value = "";
            }                
            obj.focus();
            obj.select();                                                                                               
        }
    }     
}

/*弹出窝轮速查*/
function ShowWarrantQuery(code)
{
    if(code!='&nbsp;')
    {
        var url = 'WarrantInfo.aspx?Code='+code;
        url = encodeURI(url);
        window.open(url,'','width=1020,height=720,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no');
    }
}

/*弹出牛熊证速查*/
function ShowBullBearQuery(code)
{
    if(code!='&nbsp;')
    {
        var url = 'BullBearInfo.aspx?Code='+code;
        url = encodeURI(url);
        window.open(url,'','width=1020,height=720,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no');
    }
}

/*弹出使用帮助页面*/
function ShowUseHelper(url)
{    
    url = encodeURI(url);
    window.open(url,'','width=980,height=680,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no');         
}

//设置访问的间隔时间
function SetTimeVerity()
{
    setInterval("VerityLogin()",4000);
}
//判断用户的登陆状态
function VerityAction(result)
{
    if(result)
    {
    }
    else
    {  
        ymPrompt.alert("您的帐号已经在别的地方登陆。"); 
        PageMethods.RedirectToLoginPage(RedirectionPage);
    }
}

//调用页面方法
function VerityLogin()
{
    try
    {
        PageMethods.VerityUserState(VerityAction);
    }
    catch(e)
    {
        alert("Session丢失或远程服务器重置！");
    }
}

function RedirectionPage(uri)
{
    window.parent.location.href=uri;
}

/*数据字典*/
function BeginShowToolTipText(message,height,width) 
{
    var objterm = document.getElementById("TermParentPanel");
    objterm.style.display = "block";
    objterm.style.visibility="hidden";
    var obj = document.getElementById("termPanel");
    if (document.body.clientWidth < parseInt(event.clientX) + parseInt(width) + 80) 
    {
        obj.style.left = parseInt(document.body.clientWidth) - parseInt(width) - 80;
    }
    else 
    {
        obj.style.left = event.clientX + 10;
    }
    if (document.body.clientHeight < parseInt(event.clientY) + parseInt(height) + 10) 
    {
        obj.style.top = parseInt(document.body.clientHeight) - parseInt(height) - 10;
    }
    else 
    {
        obj.style.top = event.clientY + 10;
    }
    obj.style.backgroundImage = 'url("")';
    obj.innerText = message;
    obj.style.align="left";
    obj.style.valign="bottom";
    obj.style.visibility="visible";
    obj.style.position="absolute";
    obj.style.display = "block";
    obj.style.width = width;
    obj.style.height = height;
}

function BeginShowToolTipHTML(message,height,width) 
{
    var objterm = document.getElementById("TermParentPanel");
    objterm.style.display = "block";
    objterm.style.visibility="hidden";
    var obj = document.getElementById("termPanel");
    if (document.body.clientWidth < parseInt(event.clientX) + parseInt(width) + 80) 
    {
        obj.style.left = parseInt(document.body.clientWidth) - parseInt(width) - 80;
    }
    else 
    {
        obj.style.left = event.clientX + 10;
    }
    if (document.body.clientHeight < parseInt(event.clientY) + parseInt(height) + 10) 
    {
        obj.style.top = parseInt(document.body.clientHeight) - parseInt(height) - 10;
    }
    else 
    {
        obj.style.top = event.clientY + 10;
    }
    obj.innerHTML = message;
    obj.style.align="left";
    obj.style.valign="bottom";
    obj.style.visibility="visible";
    obj.style.position="absolute";
    obj.style.display = "block";
    obj.style.width = width;
    obj.style.height = height;     
}       
             
function EndShowToolTip()
{            
    var objterm = document.getElementById("TermParentPanel");
    objterm.style.display = "none";
    var obj = document.getElementById("termPanel");
    obj.style.display = "none";
}

var termArray = new Array();
 /*显示术语提示信息*/
function GetTerm(keyCode)
{
            if(keyCode == null || keyCode =="")
            {
                return;
            }            
                
            var isHave = false;   
            var message; 
            var array;
            /*已查看过该术语提示信息*/            
            for(var i = 0;i<termArray.length;i++)
            {
                var code = termArray[i][0];
                if(code == keyCode)
                {
                    message = termArray[i][1];
                    array = message.split("||");  
                    isHave = true;                    
                    break;
                }
            }            
            if(!isHave)
            {            
                /*不存在则查询*/
                var requestUrl = "../Js/TermRelationQueryByKeyCode.aspx?KeyCode=" + keyCode;            
                message = SendHttpRequest(requestUrl);  
                if(message==null || message =="")
                {
                    return;
                }                                     
                /*没有找到该术语*/
                array = message.split("||");  
                if(message == "Exception" || array.length !=7)
                {                
                    return;
                }            
                /*保存*/
                var term = new Array();
                term[0] = array[0];
                term[1] = message;
                termArray[termArray.length] = term;    
            }
            if(array[3]=="0")
            {                
                BeginShowToolTipText(array[2],parseInt(array[4]),parseInt(array[5]));
            }
            else
            {
                BeginShowToolTipHTML(array[2],parseInt(array[4]),parseInt(array[5]));
            }            
}
         
         
/*封闭右键*/
document.oncontextmenu = function()
{
    return false;
}

//Frame内的页面，如果KM提供的web service报错， 转到系统维护中页面
function ShowMaintainingPage()
{
    window.parent.frames["framemain"].children["right"].src = "Maintaining.aspx";   
} 

//普通页面，如果KM提供的web service报错， 转到系统维护中页面
function ShowDirectMaintainingPage()
{
    window.location.href = "../Maintaining.aspx";   
}  
