﻿
String.prototype.trim = function()
{
	var a = this;
        
	var search = 0;
        
     while ( a.charAt(search) == " ")
     {
		search = search + 1;
     }

	a = a.substring(search, (a.length));
	
    search = a.length - 1;
    
    while (a.charAt(search) ==" ") 
    {
		search = search - 1;
    }
    
    return a.substring(0, search + 1);
} 

function GetNumberFormat(num,cipher)
{
	var times;
	
	var i;
	
	times = 1;
    
    for ( i =0; i < Math.abs(cipher); i++)
	{
		times *= 10;
        
	}
    
    if (cipher < 0) 
    {
		times = 1 / times;
	}

	return Math.round(num * times)/times;

}


function checkNull(oField, strMsg, blnFocus)
{
	var isNotNull = false;
	var fieldType = null;
	var mainField;
	
	if (typeof(oField.type) == 'undefined' && typeof(oField.length) != 'undefined')
		mainField = oField[0];
	else
		mainField = oField;
	fieldType = mainField.type;


	switch (fieldType)
	{
		case "text" :
		case "password" :
		case "file" :
			isNotNull = hasValue(oField);
			break;
		case "textarea" :
			isNotNull = hasEditerValue(oField);
			break;
		case "checkbox" :
		case "radio" :		
			isNotNull = isChecked(oField);
			break;		
		case "select-one" :
		case "select-multiple" :
			isNotNull = isNotSelected(oField);
			break;
	}
	
	if (!isNotNull)
	{
		alert(strMsg);
		if (blnFocus == true)
		{
			mainField.focus();
		}
	}
	
	return isNotNull;
}

function hasValue(oField)
{
	if (oField.value.replace(/(^\s*)|(\s*$)/g, "") == "")
		return false;
	else
		return true;
}

function hasEditerValue(oField)
{
	if (oField.value.replace(/&nbsp;/g, " ").replace(/(^\s*)|(\s*$)/g, "") == "")
		return false;
	else
		return true;
}

function isChecked(oField)
{	
	var checked = false;

	if (typeof(oField.length) != 'undefined')
	{
		for (var i=0; i<oField.length; i++)
			if (oField[i].checked)
				checked = true;
	}
	else
	{
		checked = oField.checked;
	}
	
	return checked;
}

function isNotSelected(oField)
{
	if (oField.selectedIndex == -1)
	{
		return false;
	}
	else
	{
		if (oField.value == -1)
			return false;
		else
			return true;
	}
}

function OpenPopUp(strUrl)                                                                                                                                                                                                                             
{                                                                                                                                                                                                                           
		                                                                                                                                                  
		var gleft = "10";                                                                                                                                                                                          
		var gtop = "10";                                                                                                                                                                                            
		                                                                                                                                                                                                            
		window.open(strUrl,'Popup','width=130, height=110, scrollbars=1 ,toolbar=no, location=no, directories=no, status=no, resizable=no, menubar=no, top=' + parseInt(gtop) + ',left=' + parseInt(gleft));
}    

function CheckStr(strOriginal, strFind, strChange)
{
    var position, strOri_Length;
    position = strOriginal.indexOf(strFind);  
    
    while (position != -1){
      strOriginal = strOriginal.replace(strFind, strChange);
      position    = strOriginal.indexOf(strFind);
    }
  
    strOri_Length = strOriginal.length;
    return strOri_Length;
}

function NotcontainsCharsOnly(input,chars) 
{ 	 
	for (var inx = 0; inx < input.value.length; inx++) 
	{ 
		if (chars.indexOf(input.value.charAt(inx)) == -1) 
		{
			return false; 
		}
	} 
	return true; 
} 

function isAlphaNum(input) 
{ 
	var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	var lowercase = "abcdefghijklmnopqrstuvwxyz"; 
	var number = "0123456789"; 
	
	var chars = uppercase + lowercase + number; 
	return NotcontainsCharsOnly(input,chars); 
} 

function isAlphaNumDashValCheck(str) 
{ 
	var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	var lowercase = "abcdefghijklmnopqrstuvwxyz-_.()"; 
	var number = "0123456789"; 
	
	var chars = uppercase + lowercase + number; 
	
	for (var inx = 0; inx < str.length; inx++) 
	{ 
		if (chars.indexOf(str.charAt(inx)) == -1) 
		{
			return false; 
		}
	} 
	
	return true; 
} 

function isNum(input) 
{ 
	var number = "0123456789"; 
	
	var chars = number; 
	return NotcontainsCharsOnly(input,chars); 
}

function isAlpha(input) 
{ 
	var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	var lowercase = "abcdefghijklmnopqrstuvwxyz";
	
	var chars = uppercase + lowercase; 
	return NotcontainsCharsOnly(input,chars); 
}

function substringKor2(str,lengths)
{
	var len = 0;
	var newStr = '';
  
	for (var i=0;i<str.length; i++) 
	{
		var n = str.charCodeAt(i);
		var nv = str.charAt(i);
		if ((n>= 0)&&(n<256)) len ++;
		else len += 2;
		if (len>lengths) break;
		else newStr = newStr + nv;
	}
	return newStr;
}
			
function intStrLen(str)
{
  var len = 0;
  
  var n;
  
  for (var i=0;i<str.length; i++) 
  {
	n = str.charCodeAt(i);
	
    	if ((n>= 0)&&(n<256)) 
    	{
		len ++;
    	} 
    	else 
	{
     	len += 2;
	}
  }
  
  return len;
}

function DeleteTag(Word) 
{
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
	{
		b = a;
	}
	d = Word.substring((b + 1), len);
	Word = c + d;
	tagCheck = Word.indexOf("<");
	if(tagCheck != -1)
	{
		Word = DeleteTag(Word);
	}
	return Word;
}


function CheckFeildMaxLen(sinput, intLimit)
{
	var frm = document.frm;
	
	if (!blnCheckFieldLen(sinput, intLimit, intLimit + "byte不能超過.")) 
	{
		sinput.value = substringKor2(sinput.value, intLimit);
	}
}

function blnCheckFieldLen(fldInput, intMaxLen, strMsg)
{
	var blnCheck = false;
	
	var intContentLen = 0;
    	
    	for (var i=0; i<fldInput.value.length; i++) 
    	{
        intContentLen += (fldInput.value.charCodeAt(i) > 128) ? 2 : 1;
	}
	
	if (intContentLen >= 0 && intContentLen <= intMaxLen)
	{
			blnCheck = true;
	}
		
	if (blnCheck == false)
	{
		alert(strMsg);
		fldInput.focus();
	}
	
	return blnCheck;
}

function intWordLen(str)
{
	var intContentLen = 0;
    	
    	for (var i=0; i < str.length; i++)
    	{
        intContentLen += (str.charCodeAt(i) > 128) ? 2 : 1;
	}
	
	return intContentLen;
}

function GoMyClub(sobj)
{
	if(sobj.value != "")
	{
		top.location.href = "/" + sobj.value;
 	}
} 	

function Resize_Frame(name)
{
	try{
		var FixWidth ,FixHeight;
		var aa=document.getElementById(name);
		var bb=document.getElementById(name).contentWindow.document.body;	//ie && firefox		
		
		//alert(name + aa);
		//alert(name + bb);
		
		FixWidth =bb.scrollWidth + (bb.offsetWidth-bb.clientWidth);
		FixHeight=bb.scrollHeight+ (bb.offsetHeight-bb.clientHeight);
		
		//alert('FixWidth:'+FixWidth +',FixHeight:'+FixHeight);
		
		aa.style.width=FixWidth ;
		aa.style.height=FixHeight;
	}catch(e){
		window.status='';
	}
	setTimeout("Resize_Frame('IfrmBoard')", 2000 )
}

function parent_Resize_Frame(name)
{
	if (parent && parent != this && parent.Resize_Frame != null)
	{
		parent.Resize_Frame(name);
	}
}

function ImageView(strurl)
{                                                                                                                                                                                           
	window.open('/Board/ImagePopupView.asp?fileurl=' + strurl,'OpenFileViewer','width=100, height=100, scrollbars=1 ,toolbar=no, location=no, directories=no, status=no, resizable=yes, menubar=no, top=100,left=90');
} 

function ConfirmLogin(intdepth, strMemberDir, strUrl)
{
	alert("必須要登入才能使用的功能.");
	/*
	if(confirm("必須要登入才能使用的功能."))
  	{
		if(intdepth == 1)
		{
			document.location.href = "http://www.mfonline.com.tw/Login/LoginPage.asp?ReturnURL=http:\/\/club.mfonline.com.tw/" +  strUrl;
		}
		else if(intdepth == 2)
		{
			parent.document.location.href = "http://www.mfonline.com.tw/Login/LoginPage.asp?ReturnURL=http:\/\/club.mfonline.com.tw/" +  strUrl;
		}
		else if(intdepth == 3)
		{
			parent.parent.document.location.href = "http://www.mfonline.com.tw/Login/LoginPage.asp?ReturnURL=http:\/\/club.mfonline.com.tw/" +  strUrl;
		}		
	} 
	*/
}

function ConfirmMakeNickName(intdepth, strMemberDir, strUrl, sbln)
{
	if(confirm("要先設定暱稱才能使用的功能.\n \n要現在設定嗎?"))
  	{
		if(intdepth == 1)
		{
			document.location.href = strAbsoluteDir + "Account/registAccountFrm.asp?strPageMode=update&strEditMode=N&strTransfer=http://" + self.location.hostname + "/" + strUrl + "&strQueryString=";
		}
		else if(intdepth == 2)
		{
			parent.document.location.href = strAbsoluteDir + "Account/registAccountFrm.asp?strPageMode=update&strEditMode=N&strTransfer=http://" + self.location.hostname + "/" + strUrl + "&strQueryString=";
		}
		else if(intdepth == 3)
		{
			parent.parent.document.location.href = strAbsoluteDir + "Account/registAccountFrm.asp?strPageMode=update&strEditMode=N&strTransfer=http://" + self.location.hostname + "/" + strUrl + "&strQueryString=";
		}		
	}
	else
	{
		if(sbln)
		{
			if(intdepth == 1)
			{
				document.location.href = "/" + strUrl;
			}
			else if(intdepth == 2)
			{
				parent.document.location.href = "/" + strUrl;
			}
			else if(intdepth == 3)
			{
				parent.parent.document.location.href = "/" + strUrl;
			}		
		}
	} 
}

function ConfirmClubJoin(intdepth, intclubtype, strclubname, intClubSeq, strUrl, sbln)
{
	var strMsg = "";
	
	if(sbln)
	{
		strMsg = "需要加入俱樂部才能使用.\n \n";
	}
	
	if(intclubtype == 1)
	{
		strMsg = strMsg + "[" + strclubname + "]要現在加入嗎?";
	}
	else
	{
		strMsg = strMsg + "[" + strclubname + "]必須要通過俱樂部版主核可才能加入.\n\n要現在申請加入嗎?";
	}
	
	if(confirm(strMsg))
  	{
		if(intdepth == 1)
		{
			document.all.IfrmBoard.src = "/Club/ClubJoin.asp?clubseq=" + intClubSeq + "&cluburl=" + strUrl;
		}
		else if(intdepth == 2)
		{
			document.location.href = "/Club/ClubJoin.asp?clubseq=" + intClubSeq + "&cluburl=" + strUrl;
		}
		else if(intdepth == 3)
		{
			parent.document.location.href = "/Club/ClubJoin.asp?clubseq=" + intClubSeq + "&cluburl=" + strUrl;
		}		
	} 
}

function UserInfoJustOneInit(strContentDir, strUserSeq)
{
	var JSid = parseInt((Math.random()*10000000));
	GetUserInfoJustOne.src =strContentDir+"Common/viewJSUserIntroJustOne.asp?userseq=" + strUserSeq + "&RND=" + JSid;
}

function UserInfoRowInit(strContentDir, strUserSeq)
{
	var JSid = parseInt((Math.random()*10000000));
	GetUserInfoRow.src =strContentDir+"Common/viewJSUserIntroRow.asp?userseqs=" + strUserSeq + "&RND=" + JSid;
}

function UserMessageInit(strContentDir, intSel)
{
	var JSid = parseInt((Math.random()*10000000));
	GetUserMessageCnt.src =strContentDir+"Common/viewJSMyMessageCount.asp?sel=" + intSel + "&RND=" + JSid;
}

function GoBottomLink(sthis)
{
	if(sthis.value != "")
	{
		window.open(sthis.value, "_blank");
	}
}

function ClearAllRightMenu()
{
	if(typeof(document.all.IfrmBoard) != "undefined")
	{
		if(typeof(IfrmBoard.ViewRightMenu) != "undefined")
		{
			IfrmBoard.ViewRightMenu(2);	
		}
		
		if(typeof(IfrmBoard.ViewMyPlus) != "undefined")
		{
			IfrmBoard.ViewMyPlus(2);	
		}
		
		if(typeof(IfrmBoard.IfrmComments) != "undefined")
		{
			if(typeof(IfrmBoard.IfrmComments.ViewRightMenu) != "undefined")
			{
				IfrmBoard.IfrmComments.ViewRightMenu(2);	
			}
		}
		
		if(typeof(IfrmBoard.IfrmOneline) != "undefined")
		{
			if(typeof(IfrmBoard.IfrmOneline.ViewRightMenu) != "undefined")
			{
				IfrmBoard.IfrmOneline.ViewRightMenu(2);	
			}
		}
	}

	if(typeof(document.all.IfrmComments) != "undefined")
	{
		if(typeof(IfrmComments.ViewRightMenu) != "undefined")
		{
			IfrmComments.ViewRightMenu(2);	
		}
	}

	if(typeof(document.all.IfrmOneline) != "undefined")
	{
		if(typeof(IfrmOneline.ViewRightMenu) != "undefined")
		{
			IfrmOneline.ViewRightMenu(2);	
		}
	}

	if (top.location != self.location)
	{
		if(typeof(parent.parent.ViewRightMenu) != "undefined")
		{
			parent.parent.ViewRightMenu(2);	
		}
		
		if(typeof(parent.ViewRightMenu) != "undefined")
		{
			parent.ViewRightMenu(2);	
		}
		
		if(typeof(parent.ViewMyPlus) != "undefined")
		{
			parent.ViewMyPlus(2);	
		}
	}
}

function CheckTopURLAndGoURL(strContentDir, strGoURL)
{
	if (top.location == self.location)
	{
		var str = "";
		
		str += "<form name='frmCheckTopURL' method='post' action='" + strGoURL +">";
		str += "<input type='hidden' name='hidUrl' value=\"" + strGoURL + "\">";
		str += "</form>";
		str += "<script language='javascript'>document.frmCheckTopURL.submit();</script>";
		
		document.writeln(str);
	}
	else
	{
		document.location.href = strGoURL;
	}
}


function GoClubURL(strURL)
{
	if (top.location == self.location)
	{
		document.location.href = strURL;
	}
	else
	{
		top.document.location.href = strURL;
	}	
}

function ViewClubAgreement()
{
	var winW = 600;
	var winH = 508;
		
	var winL = (screen.width - winW) / 2;
	var winT = (screen.height - winH) / 2;
		
	window.open("/Common/agreement.asp", "ViewClubAgreement", "width=" + winW + ",height=" + winH + ",scrollbars=no,resizable=no,top=" + winT + ", left=" + winL);
}


