﻿function ClearFormObjText(formobj,obj)
{
	if (document.forms[formobj].elements[obj].value=='請輸入部落格名稱')
		document.forms[formobj].elements[obj].value='';
}

/* Go To Url */
function goUrl(formobj,url) {

	var isIe = (window.ActiveXObject)?true:false; 
	if (isIe) {
		if (url.search("http://")>=0)
			window.open(url, 'BOgoUrl');
		else if(document.getElementById(url).value.length>0)
			window.open(document.getElementById(url).value, 'BOgoUrl');	
		else
			alert('部落格網址請勿空白');		
	}
	else {
		if (url.search("http://")>=0)
			window.open(url, 'BOgoUrl');
		else if(document.forms[formobj].BlogAddress.value.length>0)
			window.open(document.forms[formobj].BlogAddress.value, 'BOgoUrl');	
		else
			alert('部落格網址請勿空白');
	}
}

/* Copy content */
function ContentCopy(ob) {
var obj=MM_findObj(ob); if (obj) { 
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
}
function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/* Prevent "enter" to submit form */
function noenter() 
{
	if (event.keyCode == 13) 
	{        
		event.cancelBubble = true;
		event.returnValue = false;
    } 
}

function appendWord(formobj,show_obj,str)
{
	var isIe = (window.ActiveXObject)?true:false; 

	if (isIe) {	
		document.getElementById(show_obj).innerHTML = document.getElementById(show_obj).innerHTML + ' ' + str;
	} else {
		document.forms[formobj].vip_req_word.value = document.forms[formobj].vip_req_word.value + ' ' + str;
	}
}

function wordsLeft(formobj, amount, count_obj, show_obj)
{	
	var wordLeft = amount-characCount(formobj, count_obj);

	if (wordLeft<0) {
		//document.forms[formobj].elements[count_obj].innerHTML = document.forms[formobj].elements[count_obj].innerHTML.substring(0, document.forms[formobj].elements[count_obj].innerHTML.length-6);
		wordLeft='超過儲存限制';
	}
	//alert(document.getElementById(show_obj));
	document.getElementById(show_obj).innerHTML = wordLeft;

}
function characCount(formobj, obj) 
{
	var countMe;
	countMe = document.forms[formobj].elements[obj].value;
    var escapedStr = encodeURI(countMe);
    if (escapedStr.indexOf("%") != -1) {
        var count = escapedStr.split("%").length - 1;
		var entercount = escapedStr.split("%0A").length - 1;
        if (count == 0) count++;  //perverse case; can't happen with real UTF-8
        var tmp = escapedStr.length - (count * 3);
        count = count + tmp + (entercount * 3);
    } else {
        count = escapedStr.length;
    }
	return count;
}


/* Set color of an object */
function SetColor(target_obj,from_obj)
{
	var color = document.getElementById(from_obj).value;
	if (color.length > 0 && color.charAt(0) != '#')
		color = '#'+AddZero(color,6);
	document.getElementById(target_obj).style.backgroundColor = color;
}
function SetColorDirect(target_obj,clr)
{
	if (clr.length > 0 && clr.charAt(0) != '#')
		clr = '#'+AddZero(clr,6);
	document.getElementById(target_obj).style.backgroundColor = clr;
}
function SetColorText(target_obj,clr)
{
	if (clr.length > 0 && clr.charAt(0) != '#')
		clr = '#'+AddZero(clr,6);
	var isIe = (window.ActiveXObject)?true:false; 
	if (isIe)
		document.getElementById(target_obj).value = clr;
	else
		document.config_save.BgColor.value = clr;
}

/* Add "0" */
function AddZero(str,len)
{
	var i,ret='';
	for(i=0;i<(len-str.length);i++)
		ret = ret+'0'
	return (ret+str);
}

function GetByte(str) 
{    
    var cArr = str.match(/[^\x00-\xff]/ig);    
	return str.length + (cArr == null ? 0 : cArr.length);    
}
function iFrameHeightAuto(obj) 
{
	var isIe = (window.ActiveXObject)?true:false; 

	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
	var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

	if (isIe)
		h = parent.frames(obj).document.body.scrollHeight;
	else
		h = parent.document.getElementById(obj).contentDocument.body.offsetHeight+FFextraHeight;

	parent.document.getElementById(obj).style.display="block";
	parent.document.getElementById(obj).height = h;

}
function TopiFrameHeight(id, height) 
{
	//alert(parent.document.getElementById(id).name+','+wid);
	parent.document.getElementById(id).style.display="block";
	parent.document.getElementById(id).height = height;
}
function Top2iFrameHeight(obj, h) 
{
	parent.parent.document.getElementById(obj).style.display="block";
	parent.parent.document.getElementById(obj).height = h;
}
function SetFrameWidth(id, wid) 
{
	//alert(parent.document.getElementById(id).name+','+wid);
	document.getElementById(id).style.display="block";
	document.getElementById(id).width = wid;
}
function TopiFrameWidth(id, wid) 
{
	//alert(parent.document.getElementById(id).name+','+wid);
	parent.document.getElementById(id).style.display="block";
	parent.document.getElementById(id).width = wid;
}
function Top2iFrameWidth(id, wid) 
{
	//alert(parent.parent.document.getElementById(id).name+','+wid);
	parent.parent.document.getElementById(id).style.display="block";
	parent.parent.document.getElementById(id).width = wid;
}

function TopHideObject(id)
{
	parent.document.getElementById(id).style.display="none";
}
function TopShowObject(id)
{
	parent.document.getElementById(id).style.display="block";
}
function SetTableWidth(id, wid) 
{
	//alert(parent.document.getElementById(id));
	document.getElementById(id).width = wid;
}
function TopTableWidth(id, wid) 
{
	//alert(parent.document.getElementById(id));
	parent.document.getElementById(id).width = wid;
}
	
