﻿


function   ClearWindowStatus()   
{   
    var   olink   =   document.links;   
    for(var   i=0;i<olink.length;i++)   
    {   
            olink[i].onmouseover=function(){window.status='';return   true;}   
            //解决.按住显示链接地址   
            olink[i].onfocus=function(){window.status='';return   true;}   
    }   
} 

function userNameFocus()
{
    var userNameTxt = Ext.get('usernameId'); 
    userNameTxt.focus();
}

function loginCheck()
{
    //添加keyMap
    var elName=Ext.get("usernameId");    
    //添加keyMap
    var elPassword=Ext.get("passwordId");    
    //添加keyMap
    //var elRandCode=Ext.get("randCode");
    if(elName.getValue()=="" || elPassword.getValue()=="" )//|| elRandCode.getValue()==""
    {
        Ext.MessageBox.alert('警告', "请填写完整登录信息！");
        return false;
    }
    return true;
}


function loginKeyMap()
{
     //添加keyMap
    var el=Ext.get("usernameId");
    new Ext.KeyMap(el, {
            key:Ext.EventObject.ENTER,
            fn: function(e){
                    var txt = Ext.get('passwordId'); 
                    txt.focus();
           },
            scope : el
        }
    ); 
    
    //添加keyMap
    var el=Ext.get("passwordId");
    new Ext.KeyMap(el, {
            key:Ext.EventObject.ENTER,
            fn: function(e){
                var txt = Ext.get('randCode'); 
                txt.focus();
                 //Userlogin();
           },
            scope : el
        }
    ); 
    
    //添加keyMap
    var el=Ext.get("randCode");
    new Ext.KeyMap(el, {
            key:Ext.EventObject.ENTER,
            fn: function(e){
                Userlogin();
                //el.setvalue(e);
           },
            scope : el
        }
    ); 

}

function FormatNumber(srcStr,nAfterDot)        //nAfterDot小数位数
       {
　　        var srcStr,nAfterDot;
　　        var resultStr,nTen;
　　        srcStr = ""+srcStr+"";
　　        strLen = srcStr.length;
　　        dotPos = srcStr.indexOf(".",0);
　　        
　　        
　　        if (dotPos == -1){
　　            if(nAfterDot==0) return srcStr;
　　            
　　　　        resultStr = srcStr+".";
　　　　        for (i=0;i<nAfterDot;i++){
　　　　　　        resultStr = resultStr+"0";
　　　　        }
　　　　        return resultStr;
　　        }
　　        else{
　　　　        if ((strLen - dotPos - 1) >= nAfterDot){
　　　　　　        nAfter = dotPos + nAfterDot + 1;
　　　　　　        nTen =1;
　　　　　　        for(j=0;j<nAfterDot;j++){
　　　　　　　　        nTen = nTen*10;
　　　　　　        }
　　　　　　        resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　　　　        return resultStr;
　　　　        }
　　　　        else{
　　　　　　        resultStr = srcStr;
　　　　　　        for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　　　　        resultStr = resultStr+"0";
　　　　　　        }
　　　　　　        return resultStr;
　　　　        }
　　        }
        }
        
    
        
     
    //此字段用来判断是否第一次设置价格
    var firstSetPrice=false;
    //var thisPushContract="";
    function SetContractPriceFromFlash(contract,newPrice,salePrice,buyPrice)
    {  
        if(newPrice==undefined) 
        {       
            //flash设置合约号的请求
            SetContractValueFromFlash(contract,newPrice,salePrice,buyPrice);            
        }else
        {
            //flash设置合约价格的请求
            SetPriceFromFlash(contract,newPrice,salePrice,buyPrice)
            //alert("contract:"+contract+"newPrice:"+newPrice+"salePrice:"+salePrice+"buyPrice:"+buyPrice);
        }
    }

    var tempContract="";
    var tempContractPrice="";
    function SetContractValueFromFlash(contract,newPrice,salePrice,buyPrice)
    {
        var comboContract= SouthOrderForm.getForm().findField('comboContract');  
        //报价方式     
        var comboPriceType=SouthOrderForm.getForm().findField('comboPriceTypeId');  
        //开平
        var comboOrderType= SouthOrderForm.getForm().findField('comboOrderType'); 
        //数量 
        var txtCount= SouthOrderForm.getForm().findField('txtCount');
        //来自flash主动
        if((ContractStoreTemp.find('value',contract,0,false,true)!=-1 && contract!=comboContract.getValue())
        || comboContract.getValue()=="")
        {
            
            firstSetPrice=true;
            comboContract.setValue(contract);    
            tempContract=contract;
            //可开 txtAvailable
            var txtAvailable= SouthOrderForm.getForm().findField('txtAvailable');
            txtAvailable.setValue('');
        
            comboPriceType.setValue("2"); 
            if(FromHolding)
            {
                FromHolding=false; 
            }else
            {   //开仓
                comboOrderType.setValue("0");
                txtCount.setValue("1"); 
            }
            
        }
        //来自holding
        else if(ContractStoreTemp.find('value',contract,0,false,true)!=-1 && FromHolding==true)
        {
            firstSetPrice=true;
            comboContract.setValue(contract);  
        }
        else
        {   //如果是不存在的合约
            if(ContractStoreTemp.find('value',contract,0,false,true)==-1){
                reSetOrderForm();
             }
            return;
        }
     }
     
    function SetPriceFromFlash(contract,newPrice,salePrice,buyPrice)
    {
        var comboContract= SouthOrderForm.getForm().findField('comboContract'); 
        //如果是当前选中的合约号并且是当此推送的合约号则设置，否者放弃（可能会推送其他的合约号的价格过来）
        if(firstSetPrice==true
        && comboContract.getValue()==contract)
        {
            var txtPrice= SouthOrderForm.getForm().findField('txtPrice'); 
            //报价方式  市价   
            var comboPriceType=SouthOrderForm.getForm().findField('comboPriceTypeId');  
            
            if((newPrice==undefined || newPrice =="0") && comboPriceType.getValue()=="2") 
            {
                txtPrice.setValue(""); 
                txtPrice.enable();                    
                firstSetPrice=false;
                ContractPrice=txtPrice.getValue();
                return;
            }
            if(newPrice!="" && newPrice !="0")
              {  
                 //报价方式  限价时   
                var comboPriceType=SouthOrderForm.getForm().findField('comboPriceTypeId');  
                if(comboPriceType.getValue()=="2")
                {   
                    txtPrice.setValue(""); 
                    if(contract.toString().indexOf("au") ==-1)
                    {
                        txtPrice.setValue(FormatNumber(newPrice,0)); 
                        tempContractPrice= FormatNumber(newPrice,0);
                    }
                    else
                    {
                        txtPrice.setValue(FormatNumber(newPrice,2)); 
                        tempContractPrice= FormatNumber(newPrice,2);
                    }
//                    txtPrice.setValue(FormatNumber(newPrice,0)); 
//                    tempContractPrice= FormatNumber(newPrice,0);
                    txtPrice.enable();                    
                    firstSetPrice=false;
                    //给出价类型变换时调用
                    ContractPrice=txtPrice.getValue();
                }
              }   
        }else
        {
            return;
        }
        //动态设置买价和卖价
//            var txtSalePrice= SouthOrderForm.getForm().findField('txtSalePrice'); 
//            txtSalePrice.setValue(""); 
//            if(salePrice==undefined) return;
//            if(salePrice!="" && salePrice !="0")
//              {  
//                txtSalePrice.setValue(FormatNumber(salePrice,0));  
//                //txtSalePrice.enable();
//              }   
//              
//              
//            var txtBuyPrice= SouthOrderForm.getForm().findField('txtBuyPrice'); 
//            txtBuyPrice.setValue(""); 
//            if(buyPrice==undefined) return;
//            if(buyPrice!="" && buyPrice !="0")
//              {  
//                txtBuyPrice.setValue(FormatNumber(buyPrice,0));  
//                //txtPrice.enable();
//              }   
    }
    
function getOs()
{ 
    if(navigator.userAgent.indexOf("MSIE")>0) { 
         return "1"; //MSIE
    } 
    if(navigator.userAgent.indexOf("Firefox")>0){ 
         return "2"; //Firefox
    } 
    if(navigator.userAgent.indexOf("Safari")>0) { 
         return "3"; //Safari
    }  
    if(navigator.userAgent.indexOf("Camino")>0){ 
         return "4"; //Camino
    } 
    if(navigator.userAgent.indexOf("Gecko")>0){ 
         return "5";//Gecko 
    } 
    if(navigator.userAgent.indexOf('Opera') > 0){
         return "6";//Opera 
    }
   
} 

function setFlashContractFromTop(dataContract)
{
    if(getOs()=="1")
   {
       FlashIframe.setFlashContract(dataContract);
   }
   else if(getOs()=="2")
   {
        document.getElementById('FlashIframe').contentWindow.setFlashContract(dataContract);  
   }
}
