var ErrorColor = "#ffb8e6"
var switchblock = 500;

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.RealLength = function()
{
	return this.replace(/[^\x00-\xff]/g,'aa').length;
}	

//顯示錯誤訊息
function showErrorMessage(sFieldName, sErrorMessage)
{
    if(sFieldName != "")
    { 
	    var aField  = sFieldName.split("~+");
	    
	    for(var i = 0; i < (aField.length - 1); i++)
	    {
			var elename = document.getElementById(aField[i]);
			elename.style.backgroundColor = ErrorColor;
			if(i == 0)
			{
			   document.getElementById(aField[i]).focus();
			}
		}	
	}	
	var sShow = sErrorMessage.replace("@@##$$", '\n');
	
    alert(sShow);		
}

// 讓錯誤訊息能閃爍
var cStatus=0;

function setMsgColor()
{
	if(cStatus==0)
	{
		ShowMessage.style.color="black";
		cStatus=1;
	}
	else
	{
		ShowMessage.style.color="white";	
		cStatus=0;
	}
}

// 利用Regular Expression檢查Email格式
function CheckMail(sMail)
{
    if(sMail != "")
    {
		var aMail = sMail.split(";");
		var MailRE = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		var Err  = "";
		for(var i = 0; i <= (aMail.length - 1); i++)
	    {
			if(!MailRE.test(aMail[i]))
			{
				Err += aMail[i] + "\n";							
			}
	    }	
	    if(Err != "")	
	    {
			alert('E-Mail:\n' + Err + '格式錯誤!');
			return false;
		}
		else
		{
			return true;			
	    }
    }
}
