// 使用 UTF-8 編碼
base = 'http://wwww.miniworld.com.tw/';

function MM_swapImgRestore() 
{ 
    var i,x,a=document.MM_sr; 
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
        x.src=x.oSrc;
}

function MM_preloadImages() 
{
    var d=document; 
    if(d.images) { 
        if(!d.MM_p) 
            d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
        for(i=0; i<a.length; i++)
            if(a[i].indexOf("#")!=0) { 
                d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
            }
    }
}

function MM_findObj(n, d) 
{
    var p,i,x;  
    if(!d) 
        d=document; 
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) 
        x=d.all[n]; 
    for(i=0;!x&&i<d.forms.length;i++) 
        x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
        x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) 
        x=d.getElementById(n); 
    return x;
}

function MM_swapImage() 
{
    var i,j=0,x,a=MM_swapImage.arguments; 
    document.MM_sr=new Array; 
    for(i=0;i<(a.length-2);i+=3)
        if((x=MM_findObj(a[i]))!=null) {
            document.MM_sr[j++]=x; 
            if(!x.oSrc) 
                x.oSrc=x.src; 
            x.src=a[i+2];
        }
}

function MM_openBrWindow(theURL,winName,features) 
{
    window.open(theURL,winName,features);
}

/** 
 * resize image and keep proportion
 */
function img_resize(img, max_img_w, max_img_h) {
    if ((img.width > max_img_w) || (img.height > max_img_h)) { 
        if (img.width > img.height) {
            img.width = max_img_w; 
            img.height = parseInt(img.height*img.width/max_img_w); 
        } else {
            img.height = max_img_h;
            img.width = parseInt(img.width*img.height/max_img_h);
        }
    }
}

/**
 * popup hompy window
 */
var hompywindow = '';
function popupHompy(url) {
    var name = "miniWorld";
    var argv = "menubar=no,scrollbars=no,width=1000,height=665";
    if (!hompywindow.closed && hompywindow.location) {
        hompywindow.location.href = url;
    } else {
        hompywindow = window.open(url,name,argv);
        if (!hompywindow.opener) hompywindow.opener = self;
    }
    if (window.focus) { hompywindow.focus(); }
    return false;
}

/**
 * pupular-b img change
 */
function popularimg_change1(obj) {
    obj.src = "http://f.mwsrv.com/img/popular2_2.gif";
    obj.parentNode.parentNode.nextSibling.childNodes[0].childNodes[0].src = "http://f.mwsrv.com/img/popular2_3.gif";
}
function popularimg_change2(obj) {
    obj.src = "http://f.mwsrv.com/img/popular2_03.gif";
    obj.parentNode.parentNode.previousSibling.childNodes[0].childNodes[0].src = "http://f.mwsrv.com/img/popular2_02.gif";
}

function copyText(obj){
  var text = document.getElementById(obj).value;
    if(window.clipboardData){ //For IE
       window.clipboardData.setData("Text",text);
    }
    else if(window.netscape){ //For FireFox
            try{ 
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch(e){ 
                alert('您的FireFox預設關閉使用剪貼簿的功能。\n請在網址列輸入「about:config」，並搜尋「signed.applets.codebase_principal_support」後，雙擊設定為true後再重試');
                return false;
            }

	    var clip,trans,str={},clipid;
	    if(!(clip=Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard)))
	        return;
	    if(!(trans=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable)))
	        return;
	    trans.addDataFlavor("text/unicode");
	    str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	    str.data=text;
	    trans.setTransferData("text/unicode",str,text.length*2);
	    clipid=Components.interfaces.nsIClipboard;
	    try{
	        clip.setData(trans,null,clipid.kGlobalClipboard);
	    }
	    catch(e){
	        return false
	    }
    }
}

function checkEmail(string) {
    re = /^[^\s]+@[^\s]+\.[^\s]{2,3}$/;
    if (re.test(string)){
      return true;
    }
    else{
      alert("這不是正確的Email格式！");
      return false;
    }
}
