 // Format textbox as US phone number.
function phoneFormat(field, e)
{
    var i;
    var kc;
    var digits='0123456789'; 
  
    if(e.keyCode == 8) return true;
    kc = (e.keyCode) ? e.keyCode : e.which
    var c = String.fromCharCode(kc);
        
    // strip current value of invalid characters    
    var s = field.value;
    var n = ''
    for(i=0; i < s.length; i++){
        if (digits.indexOf(s.charAt(i))>=0)
            n = n.concat(s.charAt(i));
    }       
    
    // Format the phone number
    if (n.length > 15)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-' + n.substring(6,10) + ' Ext.' + n.substring(10,15);
    else if (n.length > 10)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-' + n.substring(6,10) + ' Ext.' + n.slice(10);          
    else if (n.length > 6)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-' + n.slice(6);
    else if (n.length > 5)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-';
    else if(n.length > 3)
        field.value = '(' + n.substring(0,3) + ') ' + n.slice(3);
    else
        field.value = n;
   
    return true;
}
//popo a new window
function OpenUrl(value)
{
    window.open (value, "newwindow", "height=300, width=600, top=100,left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
//close a window
function CloseWin()
{
    window.opener.location.href = window.opener.location.href; 
    if (window.opener.progressWindow) 
    { window.opener.progressWindow.close(); } 
    window.close(); 
}
var needCloseConfirm = true;
    function CloseApp()
    {
        CloseWin();
        needCloseConfirm = true;
    }
//popo a new price list
function OpenPriceList(value)
{
    window.open(value, "newwindow", "height=300, width=400, top=100,left=200,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
//popo a new window customer list
function OpenUrlCustomerList(value)
{
    window.open (value, "newwindow", "height=650, width=690, top=100,left=200,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes");
}
//popo a new window
function OpenRightUrl(value)
{
    window.open(value, "newwindow", "height=500, width=600, top=100,left=200,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes");
}

function OpenCalculateUrl(value)
{
    window.open (value, "newwindow", "height=200, width=200, top=100,left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=yes");
}
function doInput(value)
{
	var win = window.showModalDialog("frame.html",value+";Calculate","dialogWidth=200px;dialogHeight=200px;toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
	if(win != null)
	{
		var subtotal=document.getElementById("ctl00_cphPage_subtotalValue").innerText;
		subtotal=subtotal.replace(/\$/,"");
		var strToTalValue=String(parseFloat(win)+parseFloat(subtotal));
		
		document.getElementById("ctl00_cphPage_totalValue").innerText=String(float_n(strToTalValue,2));

        if(document.getElementById("parentTextBox")!=null)
		{
		    document.getElementById("parentTextBox").value = win;
		}
		
		if(document.getElementById("ctl00_cphPage_parentTextBox")!=null)
		{
		    document.getElementById("ctl00_cphPage_parentTextBox").value = win;
		}
		if(document.getElementById("ctl00_cphPage_shippingValue")!=null)
		{
		    document.getElementById("ctl00_cphPage_shippingValue").innerText = win;	
		}
		
		
	}
}
function float_n(num,n)
{
    num=""+num;
    var pos=num.indexOf(".");
    return parseFloat(num.substr(0,pos+n+1));
} 

//popo a new window product list
function OpenUrlProductList(value)
{
    window.open (value, "newwindow", "height=650, width=725, top=100,left=200,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes");
}
function SynchronizationEmail()
{
    document.getElementById("ctl00_cphPage_txtCEmail").value=document.getElementById("ctl00_cphPage_txtAccount").value;
}
function SynchronizationPassword()
{
    document.getElementById("ctl00_cphPage_Ctr_NewPassword").value=document.getElementById("ctl00_cphPage_HF_Password").value;
}
//
function QuantityFormat(field, e)
{
    var i;
    var kc;
    var digits='0123456789'; 
  
    if(e.keyCode == 8) return true;
    kc = (e.keyCode) ? e.keyCode : e.which
    var c = String.fromCharCode(kc);
        
    // strip current value of invalid characters    
    var s = field.value;
    var n = ''
    for(i=0; i < s.length; i++)
    {
        if (digits.indexOf(s.charAt(i))>=0)
        {
         if(s.charAt(0)==0)
         {
            if(s.length==1)
            {
                n='1';
            }
         }
         else
         {
           n = n.concat(s.charAt(i));
         }
        }
        else
        {
         if(i==0)
         {
          n='1';
         }
        }
    }    
    if(s.length==0)
    {
        n='1';
    }
        field.value = n;
   
    return true;
}

function PQuantityFormat(field, e) {
    var i;
    var kc;
    var digits = '0123456789';

    if (e.keyCode == 8) return true;
    kc = (e.keyCode) ? e.keyCode : e.which
    var c = String.fromCharCode(kc);

    // strip current value of invalid characters    
    var s = field.value;
    var n = ''
    for (i = 0; i < s.length; i++) {
        if (digits.indexOf(s.charAt(i)) >= 0) {
            if (s.charAt(0) == 0) {
                if (s.length == 1) {
                    n = '0';
                }
            }
            else {
                n = n.concat(s.charAt(i));
            }
        }
        else {
            if (i == 0) {
                n = '0';
            }
        }
    }
    if (s.length == 0) {
        n = '0';
    }
    field.value = n;

    return true;
}

//显示
function show(id) 
{ 
document.getElementById(id).style.display='block'; 
} 

//隐藏
function hide(id) 
{ 
document.getElementById(id).style.display='none'; 
} 

function setTxt()
{
var t=document.getElementById("ctl00_cphPage_Ctr_ContactNameHidden");
t.select();
window.clipboardData.setData('text',t.createTextRange().text);
}

function setTxtPhone() {
    var t = document.getElementById("ctl00_cphPage_Ctr_PhoneHidden");
    t.select();
    window.clipboardData.setData('text', t.createTextRange().text);
}

function auto_focus() {
if(document.getElementById('ctl00_cphPage_Ctr_KeyWord')!=null) //首先检查employeeid对象是否存在
    document.aspnetForm.ctl00_cphPage_Ctr_KeyWord.focus(); //将光标聚焦

if (document.getElementById('ctl00$cphPage$Ctr_Username') != null) //首先检查employeeid对象是否存在
    document.aspnetForm.ctl00$cphPage$Ctr_Username.focus(); //将光标聚焦

if (document.getElementById('ctl00$cphPage$txtSearch') != null) //首先检查employeeid对象是否存在
    document.aspnetForm.ctl00$cphPage$txtSearch.focus(); //将光标聚焦
}

 // Format textbox as US phone number.
function phoneFormat2(field, e)
{
    var i;
    var kc;
    var digits='0123456789'; 
  
    if(e.keyCode == 8) return true;
    kc = (e.keyCode) ? e.keyCode : e.which
    var c = String.fromCharCode(kc);
        
    // strip current value of invalid characters    
    var s = field.value;
    var n = ''
    for(i=0; i < s.length; i++){
        if (digits.indexOf(s.charAt(i))>=0)
            n = n.concat(s.charAt(i));
    }       
    
    // Format the phone number
    if (n.length > 10)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-' + n.substring(6,10);          
    else if (n.length > 6)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-' + n.slice(6);
    else if (n.length > 5)
        field.value = '(' + n.substring(0,3) + ') ' + n.substring(3,6) + '-';
    else if(n.length > 3)
        field.value = '(' + n.substring(0,3) + ') ' + n.slice(3);
    else
        field.value = n;
   
    return true;
}
function phoneFormatExt(field, e)
{
    var i;
    var kc;
    var digits='0123456789'; 
  
    if(e.keyCode == 8) return true;
    kc = (e.keyCode) ? e.keyCode : e.which
    var c = String.fromCharCode(kc);
        
    // strip current value of invalid characters    
    var s = field.value;
    var n = ''
    for(i=0; i < s.length; i++){
        if (digits.indexOf(s.charAt(i))>=0)
            n = n.concat(s.charAt(i));
    }       
    
    // Format the phone number
        field.value = n;
   
    return true;
}
