// JavaScript Document
//设置主页
function setHomepage(){
    var Massage;
    switch (PageLanguage) {
        case "zh-CHS":
        default:
            Massage = "您的浏览器不支持这个行为，如果您要启用，请在浏览器的“about:config”中，把 signed.applets.codebase_principal_support 设置成true ";
            break;
        case "EN":
            Massage = "Your browser does not support this behavior, if you want to open your browser's \"about: config\" in the signed.applets.codebase_principal_support set to true";
            break;
    }
    
    if (document.all){ 
        document.body.style.behavior='url(#default#homepage)'; 
        document.body.setHomePage('http://www.eartmusic.com/'); 
    } 
    else if(window.sidebar){ 
        if(window.netscape) 
        { 
            try{ 
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
            } 
            catch(e){
                alert(Massage); 
            } 
        } 
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
        prefs.setCharPref('browser.startup.homepage','http://www.eartmusic.com/'); 
    } 
}
//添加收藏夹
function AddFavorite(){
    var Massage;
    switch (PageLanguage) {
        case "zh-CHS":
        default:
            Massage = "雅特乐器 EARTmusic 中国知名品牌!";
            break;
        case "EN":
            Massage = "HoSen Co., Ltd Eart Music";
            break;
    }

    var title = Massage,
        url="http://www.eartmusic.com/",
        desc = Massage;
    if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))//Gecko
    {
        window.sidebar.addPanel(title,url,desc);
    }
    else//IE
    {
        window.external.AddFavorite(url,title);
    }
}

function OpenWin(url){
    //alert(url);
    window.open(url);
}

function CloseWin(){
    window.opener = null;
    window.open('','_self');
    window.close();
}

function isKeyTrigger(e,keyCode){   
    var argv = isKeyTrigger.arguments;   
    var argc = isKeyTrigger.arguments.length;   
    var bCtrl = false;   
    if(argc > 2){   
        // 如果存在第3个传入参数,则作为是否判断按下ctrl键标志   
        bCtrl = argv[2];   
    }   
    var bAlt = false;   
    if(argc > 3){   
        // 如果存在第4个传入参数,则作为是否判断按下ctrl键标志   
        bAlt = argv[3];   
    }   
  
    var nav4 = window.Event ? true : false;   
  
    if(typeof e == 'undefined') {   
        e = event;   
    }   
  
    if( bCtrl &&    
        !((typeof e.ctrlKey != 'undefined') ?    
            e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)){   
        return false;   
    }   
    if( bAlt &&    
        !((typeof e.altKey != 'undefined') ?    
            e.altKey : e.modifiers & Event.ALT_MASK > 0)){   
        return false;   
    }   
    var whichCode = 0;   
    if (nav4) whichCode = e.which;   
    else if (e.type == "keypress" || e.type == "keydown")   
        whichCode = e.keyCode;   
    else whichCode = e.button;   
  
    return (whichCode == keyCode);   
}

Function.prototype.bind = function(){  
  var self = this;  
  var arg = arguments;  
  return  function(){  
    self.apply(null,arg);  
  }  
} 
String.prototype.Left = function(lngLen){ 
    var temp = this;
    if (lngLen>0){temp = temp.substring(0,lngLen);} 
    return temp;
} 
String.prototype.Right = function(lngLen){
    var temp = this;
    if(temp.length-lngLen>=0&&temp.length>=0&&temp.length-lngLen<=temp.length){
        temp = temp.substring(temp.length-lngLen,temp.length);
    } 
    return temp;
} 
String.prototype.Mid = function(starnum,endnum){ 
    var temp = this,Len = arguments.length == 1?temp.length:endnum;
    if (temp.length>=0){ 
        temp = temp.substring(starnum,Len) 
    }
    return temp;
}
//通过URL地址取绝对路径地址
String.prototype.AbsPath = function(){
    var temp = this;
    temp = temp.replace("//","");
    len = temp.indexOf("/");
    if(len >= 0){temp = temp.Mid(len);}
    else{temp = this;}
    return temp;
}
// Trim() , Ltrim() , RTrim()
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
    return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
    return this.replace(/(\s*$)/g, ""); 
}

String.prototype.TrimAndEnter = function() 
{ 
    return this.replace(/^\s*|[\x00-\x1f]|\s*$/g, ""); 
} 

String.prototype.IsEmail = function() 
{ 
    return this.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/i)==-1?false:true; 
} 

