var tmpStr = "";

function checkMaxCharacter(aoItem, maxCharAccept) 
{ 

//var replaceStr = aoItem.value 
//aoItem.value = replaceStr.replace(/\r\n\r\n\r\n|\r\r\r|\n\n\n/g, "\n\r\n");

	if (aoItem.value.length <= maxCharAccept)
		tmpStr = aoItem.value;
	else
	{
		aoItem.value = tmpStr;
		event.returnValue = false; 
	}
}

function limitCharacter(aoItem, maxCharAccept){
	var text=aoItem.value
	if (text.length > maxCharAccept)
	{
		alert('請不要多於'+maxCharAccept+'字');
		aoItem.value = tmpStr;
	}
	else
		tmpStr = text;
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function addtext(aoItem, txt, maxCharAccept) 
{
	var txtLength = txt.length;
	var objRemark = document.all(aoItem);
	if (txt != "，") txtLength = txtLength + 1;
	
	if (objRemark.value.length+txtLength < maxCharAccept)
	{
	  if(txt == "，")
	      objRemark.value = objRemark.value + txt
	  else
	      objRemark.value = objRemark.value + txt + "，"
	}
  return true;
}

function isChar(textObj){


	var newValue = textObj.value;
	var newLength = newValue.length;
	for(var i = 0; i !=newLength; i++) {
		aChar = newValue.substring(i, i+1);
		if( (aChar >= "0" && aChar <= "9") || (aChar >= "a" && aChar <= "z") || (aChar >= "A" && aChar <= "Z") ) {
		}
		else
			return false;
	}
	return true;
}

function illegelChar(textObj){

	var newValue = textObj.value;
	var newLength = newValue.length;
	for(var i = 0; i !=newLength; i++) {
		aChar = newValue.substring(i, i+1);
		if( aChar==">" || aChar=="<")
			return false;
	}
	return true;
}

function format_mark(textObj)
{
	textObj.value = textObj.value.toUpperCase();
	textObj.value = textObj.value.replace(" ","");
}

function isInt(textObj){
	var newValue = textObj.value;
	var newLength = newValue.length;
	for(var i = 0; i !=newLength; i++) {
		aChar = newValue.substring(i, i+1);
		if( aChar < "0" || aChar > "9") {
			return false;
		}
	}
	return true;
}

function checkmail(e)
{
		var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
		var returnval=emailfilter.test(e.value)
		return returnval
}

function reply_message(reply_to, reply_msg, msg_id) 
{
	var objReply = document.all('reply_to_content');
	var reply_message = reply_msg.innerText.replace(/\r\n|\r|\n/g,"，");
	objReply.innerText = "回應由 \"" + reply_to  + "\" 發表的留言：\n「" + ((reply_message.length > 100) ? reply_message.substring(0,100) + "......" : reply_message) + "」"
	document.all('reply_to').value=msg_id;
}


function setHighlight(o,cn)
{
	o.className = cn;
}

function setNormal(o,cn)
{
	o.className = cn;
}

function setClick(o,cn)
{
	o.className = cn;
}


function popUp(URL,w,h) {
	var windowval = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+w+',height='+h+',left=50,top=50';			
 	window.open(URL,'',windowval);
}

//show processing bar
function showDataUploading(obj){
  	obj.style.top = parseInt((document.body.clientHeight/3) +  document.body.scrollTop);
  	obj.style.left = parseInt((document.body.clientWidth/3)  + document.body.scrollLeft);
	obj.style.display = "block";
}

function hideDataUploading(obj){
  obj.style.display = "none";
}

String.prototype.trim = function() 
{   
  return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );   // example: str=str.trim(); 
} 

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function copyToClipboard(one, two) {
two.innerText = one.innerText;
Copied = two.createTextRange();
Copied.execCommand("Copy");
alert('複製完成。\n你可以在其他網頁「貼上」這個廣告的網址。\n方法：按滑鼠右鍵，選「貼上」便可。');
} 