﻿function showOrHiddenUnit(){    
    var headId = document.getElementById("unitParent");
    var bodyId = document.getElementById("hiddenUnitMenu"); 
    
    if(headId.className == "up"){
        headId.className = "down";
        $(bodyId).hide();//slideUp
        headId.title = "收縮";
    }
    else{
        headId.className = "up";
        $(bodyId).show();
        headId.title = "展開";
    }
}
function showOrHidden(id){
    var headId = document.getElementById("tbHead"+id);
    var bodyId = document.getElementById(id); 
    if(headId != null || bodyId !=null ){
        if(headId.className == "up"){
            headId.className = "down";
            $(bodyId).hide(); //slideUp();
            headId.innerHTML = id;
        }
        else{
            headId.className = "up";
            $(bodyId).show();
            headId.innerHTML = "";
        }
    }
}
function showLoading(msg, img){
    if(msg == null || msg == undefined) msg = "正在作業中...";
    if(img == null) img = 1;
    var imgPath = (img == 1) ? "/images/loadingAnimation.gif" : "/images/loadingAnimation2.gif";
    
    if($("#Win_overlay")[0] == null){ $("body").append("<div id=\"Win_overlay\" class=\"Win_overlayBG\"></div>");}
    if($("#Win_load")[0] == null){ $("body").append("<div id=\"Win_load\"><img alt=\"loading...\" src=\""+ imgPath +"\" /><p style=\"color:#FF8000;\">"+ msg +"</p></div>");}
    $("#Win_overlay").show();   
    $("#Win_load").show();
}

function hideLoading(){
   $("#Win_load").fadeOut("slow",function(){ $('#Win_load,#Win_overlay').trigger("hide").hide();});
}

function showSuccess(msg, form, errorMsgId, returnUrl, timeout){
    if(form == null) form = document.forms[0];
    if(errorMsgId == null) errorMsgId = "msgShower";
    if(msg == null) msg = "作業成功";
    if(timeout == null) timeout = 2000;
    
    $("#Win_load").hide();
    
    if(msg.toLowerCase().indexOf("error:")>-1){
        $('#Win_overlay').hide();
        msg = msg.substring(6,msg.length);
        $("#"+errorMsgId).addClass('error').html( msg ).show("slow");
        return;
    }
    
    $("#Win_body").html(msg);
    if($("#Win_success")[0] == null){ $("body").append("<div id=\"Win_success\"><p style=\"margin: 20px;\" id='Win_body'>"+ msg +"</p></div>"); } 
    $('#Win_success').show();   
    //$("#"+errorMsgId).removeClass('error').addClass('success').text(msg).show();
    
    if($("#"+form)[0] != null) $("#"+form)[0].reset();
    
    setTimeout("hideMsg('"+returnUrl+"')",timeout);
}
function hideMsg(returnUrl){
    $("#Win_success").fadeOut("slow",function(){ $('#Win_success,#Win_overlay,#Win_load').trigger("hide").hide();}); //slideUp("slow",function(){})
    if(returnUrl == "reload") window.location.reload();
    else window.location.href = returnUrl;
}

/* 顯示錯誤提示 */
function showError(el){
    if(el == null) el = "msgShower";
    $("#Win_load").fadeOut("slow",function(){ $('#Win_overlay,#Win_load').trigger("hide").hide();});
    $("#"+el).addClass('error').text("抱歉! 網路或伺服器錯誤，請稍候再試。").show();
}

function showConfirm(text){
    if(text == null || text == undefined) text = "您確定要删除吗？";
    if($("#Win_overlay")[0] == null){ $("body").append("<div id=\"Win_overlay\" class=\"Win_overlayBG\"></div>"); }
    if($("#Win_confirm")[0] == null){ $("body").append("<div id=\"Win_confirm\">	<div id=\"Win_confirm_title\" class='wintitle'><strong>系統消息</strong><span><img id=\"Win_confirm_close\" alt='关闭' src=\"/ejt/images/win_close.gif\"></span>	</div>	<div class=\"wincnt\">		<dl class=\"winpic\">			<dt><img src=\"/ejt/images/question.gif\" alt=\"？\"></dt><dd id=\"ir_Confirm_content\">"+ text +"</dd></dl><div class=\"winsingle\"><input id=\"yes\" class=\"winbtn\" value=\"確 定\" type=\"button\"> 			<input id=\"no\" class=\"winbtn\" value=\"取 消\" type=\"button\"></div></div></div>"); }
    $("#Win_overlay").show();
    $('#Win_confirm').show();
    $('#yes').focus();
    document.onkeyup = function(e){ 	
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if(keycode == 27){ // close
			closeWin();
		}	
	};
    $("#Win_confirm_close").click(function(){ closeWin(); });
}
function closeWin(){
   $('#Win_confirm,#Win_overlay').trigger("hide").hide();
}
function getParamValue(url, paramName){
    var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
    var oMatch = oRegex.exec(url) ;

    if ( oMatch && oMatch.length > 1 )
        return unescape( oMatch[1] ) ;
    else
        return '' ;
}
function getParamValue(paramName){
    var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
    var oMatch = oRegex.exec(document.URL) ;

    if ( oMatch && oMatch.length > 1 )
        return unescape( oMatch[1] ) ;
    else
        return '' ;
}
function checkEmail(email){
    var re = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
    return re.test(email);
}
function del(url, msg){
    if(msg == null || msg == undefined) msg = "您確定要删除吗？";
    
    if(confirm(msg)){
        location.href = url;
    }
    else{
        return false;
    }
}
