﻿/*
* Copyright (c) 2010 Uni-net, http://www.uni-net.com.tw/
* 
* 此 javascript 檔包含常用的函數供驗證使用。
*/

/// <summary>
/// Pop-up new window.
/// </summary>
function popup(location) {
    var newURL = window.location.protocol + "//" + window.location.host + location;

    windowOpener(400, 1000, "履歴", newURL);

}

/// <summary>
/// Resize window for pop-up.
/// </summary>
function windowOpener(windowHeight, windowWidth, windowName, windowUri) {
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName,
                'scrollbars=yes,resizable=0,toolbar=0,width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}

function popup_flash(location) {
    var windowHeight = 400;
    var windowWidth = 1000;
    var centerWidth = (window.screen.width - 1000) / 2;
    var centerHeight = (window.screen.height - 400) / 2;
    //var newURL = window.location.protocol + "//" + window.location.host + location;
    var flashHmtl = '<div style="position: absolute">'
			                + '<img src="/Content/flash/transparent.gif" style="opacity:0;filter:alpha(opacity=0)" width="' + centerWidth + '" height="' + centerHeight + '">'
			                + '</div>'
			                + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + centerWidth + '" height="' + centerHeight + '">'
			                + '<param name="movie" value="' + location + '"/>'
			                + '<param name="wmode" value="transparent" />'
			                + '<object wmode="transparent" type="application/x-shockwave-flash" data="' + location + '" width="' + centerWidth + '" height="' + centerHeight + '">'
			                + '</object>'
			                + '</object>';
    var newURL = window.location.protocol + "//" + window.location.host + location;		                
    newWindow = window.open(windowUri, windowName,
                'scrollbars=yes,resizable=0,toolbar=0,width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight);
    
    newWindow = window.open('http://www.flash-db.com/index.php','newWin','width=400,height=300,left=0,top=0, toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
    
    newWindow.focus();
    return newWindow.name;
}

/// <summary>
/// 更換Html[<,>]Tag
/// </summary>
function changeHtmlTag(changeString,Encode) {
    var html;
    if (changeString != null) {
        if (Encode) {
            changeString = changeString.replace(/</g, "{{");
            changeString = changeString.replace(/>/g, "}}");
            changeString = changeString.replace(/&#39;/g, "'");
        }
        else {
            changeString = changeString.replace(/{{/g, "<");
            changeString = changeString.replace(/}}/g, ">");
        }
    }
    return changeString;
}


function LTrim(str){ //去掉字符串 的头空格
    var i;
    for(i=0;i<str.length;i++){
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
    }
    str = str.substring(i,str.length);
    return str;
}

function RTrim(str){
    var i;
    for(i=str.length-1;i>=0;i--){
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
    }
    str = str.substring(0,i+1);
    return str;
}

function Trim(str) {
    return LTrim(RTrim(str));
}

