﻿//onkeypress="onlyNumber(event)"
function onlyNumber(e)
{
    var isIE = false;
    var isFF = false;
    var isSa = false;

    if((navigator.userAgent.indexOf("MSIE")>0) && (parseInt(navigator.appVersion) >=4))isIE = true;
    if(navigator.userAgent.indexOf("Firefox")>0)isFF = true;
    if(navigator.userAgent.indexOf("Safari")>0)isSa = true;

    var iKeyCode;
    iKeyCode = window.event?e.keyCode:e.which;
    if( !(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13) || (iKeyCode == 46) || (iKeyCode == 45) || (iKeyCode == 37) || (iKeyCode == 39) || (iKeyCode == 8)))
    {   
        if (isIE)
        {
            e.returnValue=false;
        }
        else
        {
            e.preventDefault();
        }
    }

}

function clickImg()
{
if(win == null)
    win = window.open('http://67.228.234.126:8080/login.aspx?web=ignaccount','newWindow','width=600,height=521,center=yes,alwaysRaised=yes,location=no,menubar=no,resizable=yes,scrollbars=no');
else
{
    if(win.closed)
        win = window.open('http://67.228.234.126:8080/login.aspx?web=ignaccount','newWindow','width=600,height=521,center=yes,alwaysRaised=yes,location=no,menubar=no,resizable=yes,scrollbars=no');
    else
        win.focus();
}    
}

var win;

//onkeypress="money(this.value)"
function money(str)
{   
    var   nc=event.keyCode; 
    var   s=str;
    if((nc>=48)   &&   (nc<=57)   )
    {   
        if(s.substring(0,1)=="0" && s.indexOf('.')< 0)
        {
        event.keyCode=0;
        return;
        }
    else
    { 

        if(s.indexOf('.')>0)
        {
            if( s.indexOf('.')<s.length-4)
            {
                event.keyCode=0;   
                return;   
            }
        }
    }
    }
    else if(nc==46)
    {   
        if(s.length<1)
        {
            event.keyCode=0;   
            return;   
        }
        for(var   i=0;i<s.length;i++)
        {   
            if(s.charAt(i)=='.')
            { 
                event.keyCode=0;   
                return;   
            }   
        }   
    }
    else
    {   
        event.keyCode=0;
        return;   
    }   
}

//read COOKIE
function getCookie(cookiename)
{
    var result;
    var mycookie = document.cookie;
    var start2 = mycookie.indexOf(cookiename + "=");
    if(start2>-1)
    {
        start=mycookie.indexOf("=",start2)+1;
        var end = mycookie.indexOf(";",start);
        
        if (end == -1)
        {
            end = mycookie.length;
        }
        
        result = unescape(mycookie.substring(start,end));
    }
    
    return result;
}

//write COOKIE
function setCookie(cookiename, cookievalue, hours)
{
    var date=new Date();
    date.setTime(date.getTime() + Number(hours)*3600*1000);
    document.cookie = cookiename + "=" + cookievalue +"; path=/;expires = " + date.toGMTString();
   
}


//openPage
function openPage(Page,type,game)
{
    setCookie("type",type+"|"+game,1);
    window.location=Page+".html";
}




//huang hang
function hh()
{
    var D=document; 
    F(D.body); 
    function F(n)
    {
        var u,r,c,x; 
        if(n.nodeType==3)
        { 
            u=n.data.search(/\S{10}/); 
            if(u>=0) 
                { 
                    r=n.splitText(u+10); 
                    n.parentNode.insertBefore(D.createElement("WBR"),r); 
                } 
        }
        else if(n.tagName!="STYLE" && n.tagName!="SCRIPT")
        {
            for(c=0;x=n.childNodes[c];++c)
            {
                F(x);
            }
        } 
    } 
}

//ws 2
function ws2(sz)
{
    return Math.round(parseFloat(sz)*100)/100;
}

//account orderserial
function getserialaccount()
{
    var md = new Date();
    var year = md.getYear();
    year = year.toString();
    year = year.substring(2,4);
    
    if(year.length == 1)
    {
        year = "0" + year;
    }
    
    var month = md.getMonth() + 1;
    if(month < 10)
    {
        month = "0" + month;
    }
    
    var day = md.getDate();
    if(day < 10)
    {
        day = "0" + day;
    }
    
    var s = "0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
    var arr = s.split(" ");
     
     var sn4 = "";
    while(sn4.length <=3)
    {
        sn4 += arr[Math.round(Math.random()*100)%36];
    }     
   
    return "IGA" + year + month + day + sn4;
}

//post page
function getNewSubmitForm(sid)
 {      
    var submitForm = document.createElement("form");

    document.body.appendChild(submitForm);

    submitForm.id=sid;                                

    submitForm.method = "POST";               

    submitForm.target="_self";

    return submitForm;

}

function createNewFormElement(inputForm, elementName, elementValue)
{

     var newElement = document.createElement("input");
     newElement.setAttribute("name", elementName);
     newElement.setAttribute("type", "hidden");
     newElement.value = elementValue;

     inputForm.appendChild(newElement);

     return newElement;
}


function createFormAndSubmit(item_name, amount, currency_code)
{

    var submitForm = getNewSubmitForm("Paypalform");
    createNewFormElement(submitForm, "cmd", "_ext-enter");
    createNewFormElement(submitForm, "redirect_cmd", "_xclick");
    createNewFormElement(submitForm, "business", ppemail);
    createNewFormElement(submitForm, "item_name", item_name);
    createNewFormElement(submitForm, "return", "http://www.ignaccount.com");
    createNewFormElement(submitForm, "cancle_return", "http://www.ignaccount.com");
    createNewFormElement(submitForm, "amount",amount);
    createNewFormElement(submitForm, "notify_url",ipn);
    createNewFormElement(submitForm, "image_url",ppimg);
    createNewFormElement(submitForm,"currency_code",currency_code);
    submitForm.action= "paymoney.aspx";
    submitForm.submit();
}



// moneytype
function getmoneytype(tp)
{
    var result = "USD";
    
    if(tp == "$")
    {
        result = "USD";
    }
    
    if(tp == "€")
    {
        result = "EUR";
    }
    
    if(tp == "£")
    {
        result = "GBP";
    }
    
    if(tp == "A$")
    {
        result = "AUD";
    }
    
    if(tp == "C$")
    {
        result = "CAD";
    }
    return result;
}

//check email
function checkemail(email)
{
    var result;
    var res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;  
    var re = new RegExp(res);
    if(!re.test(email.strip()))
    {
        result = false;
    } 
    else
    {
        result = true;
    }
    return result;
}

//ddl clear
function ddlclear(ddlid)
{
    var rowcount = document.getElementById(ddlid).length;
    for(var h = 0; h < rowcount; h++)
    {
        document.getElementById(ddlid).removeChild(document.getElementById(ddlid).rows.item(0));
    }

}

//ddl databind
function ddldatabind(ddlid, xmlhttp, colname)
{
    var ddl = document.getElementById(ddlid);
    ddlclear(ddlid);
    
    var result = xmlhttp.responseXML;
    
    if(xmlhttp.responseText != "<NewDataSet />")
    { 
        var list = result.getElementsByTagName("Table");
        for(var i = 0; i < list.length; i++)
        {
            var op = document.createElement("option"); 
            
            var optext = pricelist[i].getElementsByTagName(colname)[0].childNodes[0].nodeValue;
            op.appendChild(document.createTextNode(optext));
            
            ddl.appendChild(op);
        }
    }
}

//getuid
function getuid()
{
    var uid = 0;
    
    var uinfo = getCookie("customerinfo");
    
    if(uinfo != null)
    {
        var arr = uinfo.split("|||");
        uid = arr[0];
    }
    
    uid = parseInt(uid);
    
    if(uid == null || isNaN(uid))
    {
        uid = 0;
    }
    uid = parseInt(uid);
    
    if(isNaN(uid))
    {
        uid = 0;
    }
    return uid;
}

//get visit
//getuid

function getpid()
{
    var pid = 0;
    
    var pid = getCookie("pid");
    
    if(pid == null)
    {
        pid = "0";
    }
        
    if(isNaN(pid))
    {
        pid = 0;
    }
    return pid;
}

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串   
    var strss = "?";
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            strss += strs[i].split("=")[0] + "=" + strs[i].split("=")[1] + "&";
        }
    }
    if (strss == "?") {
        strss = "";
    }
    return strss;
}  

function setvisit()
{
    var pid = getpid();
    var uid = getuid();
    var refurl = document.referrer + GetRequest();
    var cururl = document.URL;

    //当用户不在buy页面时,清除数据
    if (cururl.indexOf("buywow") < 0) {
        setCookie("NaviID", "", -1);
        setCookie("AccountID", "", -1);  //帐号搜索
        setCookie("searchvalue", "", -1);
    }
    
    if(refurl == null)
    {
        refurl = "";
    }
    
    var url = "ashx/visit.ashx?pid=" + pid + "&uid=" + uid + "&refurl=" + escape(refurl) + "&cururl=" + escape(cururl);
        
    var myAjax = new Ajax.Request(   
                                    url,   
                                    {
                                        method: "get", 
                                        onComplete: setvisitdo
                                    }   
                               ); 
}
function setvisitdo(xmlhttp)
{
    var result = xmlhttp.responseText;
    if(getpid("pid") == 0)
    {
        setCookie("pid",result,2.0);
    }
}