//agreement and privacy policy
function popupRule(cont){
	window.open('/main/view_policy.jsp?cont='+cont,'ruleWindow','width=939,height=627, status=yes');
}

//send a memo to a single user
function sendMemo(rcvuid){
    var id = (typeof rcvuid=="undefined" ? "" : rcvuid);
	window.open('/memo/writeMemo.do?m=writeMemo&rec_id='+rcvuid,'memoWindow','status=yes,width=458,height=310');
}

function sendNewMemo(){
	window.open('/memo/writeMemo.do?m=sendNewmemo','memoWindow','status=yes,width=458,height=310');
}

//send a memo to a number of users
function sendMultiMemo(rcvuid, folder, count){
    var id = (typeof rcvuid=="undefined" ? "" : rcvuid);
	window.open('/memo/writeMemo.do?m=writeMemo&rec_id='+rcvuid+'&folder_cd='+folder+'&count='+count,'memoWindow','status=yes,width=458,height=310');
}

//check received memos
function checkMemo(){
	window.open('/memo/viewMemo.do?m=viewMemoBox&p=v','memoWindow','status=yes,width=458, height=310');
}

//report other user's bad words and behavior to admin
function reportToAdmin(rcvuid){
    var id = (typeof rcvuid=="undefined" ? "" : rcvuid);
	window.open('/memo/writeMemo.do?m=accuseUser&rec_id='+rcvuid,'accuseWindow','status=yes,width=458,height=310');
}

//send a request to the administrator for an advertisement by email (for advetiser)
function requestAd(){
	window.open('/requestAd/viewRequestForm.do?m=viewAdForm','requestAdWin','status=yes,width=480,height=380');
}
//check reported items
function checkAccusedMember(){
	window.open('/memo/viewMemo.do?m=viewAccused','accuseWindow','status=yes,width=458,height=310');
}

//add buddy
function popAddBuddy(buddyid){
	window.open('/friend.do?m=prepareInvite&rec_id=' + buddyid,'friendWindow','status=yes,width=313,height=386');
}

//check requests for buddy
function checkFriendship(){
	window.open('/friend.do?m=listInvitation','friendWindow','status=yes,width=458,height=310');
}

//go to the blog of specified user
function goMyHP(userid){
	window.open('/blog/index.do?blogid='+userid, 'blogWindow','resizable=no,width=939,height=627, status=yes');
}
//go to my blog
function goSelfMyHP(userid){
	window.open('/blog/index.do?blogid='+userid, 'myBlogWindow','resizable=no,width=939,height=627, status=yes');
}

//go to the blog of given url
function goMyHPPage(url){
	window.open('/blog/index.do'+url,'_blank','resizable=no,width=939,height=627,status=yes');
}

//manage user
function manageUser(userid) {
	window.open('/member.do?m=manage&userid=' + userid, 'friendWindow', 'status=yes,width=313,height=394');
}

// treat some special characters
// http://www.ietf.org/rfc/rfc2396.txt?number=2396
function escape(str)
{
	if( str == null || str.length == 0 ) return "";
	var result = "";
	var reserved = ";/?:@&=+$,";
	var ch = "";
	for(i = 0; i < str.length; i++)
	{
		ch = str.charAt(i);
		if( reserved.indexOf(ch) != -1 )
			result += "%"+ ch.charCodeAt(0).toString(16);
		else if( ch == " " )
			result += "+";
		else
			result += ch;
	}
	return result;
}

function loginPopup(url)
{
	if (typeof url == "undefined") {
		targeturl = document.location.href;
	} else {
		targeturl = url;
	}
	var win = window.open("/loginForm.do?pop=true&targeturl="+escape(targeturl),"loginPopup","width=300,height=200");
	win.focus();
}

//Replace 
String.prototype.simpleReplace = function(oldStr, newStr) {
	var rStr = oldStr;

	rStr = rStr.replace(/\\/g, "\\\\");
	rStr = rStr.replace(/\^/g, "\\^");
	rStr = rStr.replace(/\$/g, "\\$");
	rStr = rStr.replace(/\*/g, "\\*");
	rStr = rStr.replace(/\+/g, "\\+");
	rStr = rStr.replace(/\?/g, "\\?");
	rStr = rStr.replace(/\./g, "\\.");
	rStr = rStr.replace(/\(/g, "\\(");
	rStr = rStr.replace(/\)/g, "\\)");
	rStr = rStr.replace(/\|/g, "\\|");
	rStr = rStr.replace(/\,/g, "\\,");
	rStr = rStr.replace(/\{/g, "\\{");
	rStr = rStr.replace(/\}/g, "\\}");
	rStr = rStr.replace(/\[/g, "\\[");
	rStr = rStr.replace(/\]/g, "\\]");
	rStr = rStr.replace(/\-/g, "\\-");

  	var re = new RegExp(rStr, "g");
    return this.replace(re, newStr);
}
//trim 
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//trimAll
String.prototype.trimAll = function() {
    return this.replace(/\s*/g, "");
}
//cut
String.prototype.cut = function(start, length) {
    return this.substring(0, start) + this.substr(start + length);
}
//insert
String.prototype.insert = function(index, str) {
    return this.substring(0, index) + str + this.substr(index);
}


//°Ô½Ã¹° »çÁø Å©±â Á¶Àý(width°ªÀ¸·Î¸¸ Á¶Àý)
function FixSize(imgorg, maxWidth) {
    
    imag = new Image();
    
    imag.src = imgorg.src;
	imgorg.style.display = "none";
	
    var width = parseInt(imag.width);
    if (width > maxWidth) {
    	imgorg.width = maxWidth;
    }
    
    imgorg.style.display = "inline";
}

//°Ô½Ã¹° »çÁø Å©±â Á¶Àý(width, height°ªÀ¸·Î¸¸ Á¶Àý)
function FixSizeAll(imgorg, maxWidth, maxHeight) {
    
    imag = new Image();
    
    imag.src = imgorg.src;
	imgorg.style.display = "none";
	
    var width = parseInt(imag.width);
    var height = parseInt(imag.height);
    
    if (width <= maxWidth && height <= maxHeight) {
    	imgorg.width  = width;
    	imgorg.height = height;
	} else if (maxWidth >= maxHeight) {
    	if (maxHeight >= height*maxWidth/width) {
    		imgorg.width = maxWidth;
		} else {
			imgorg.width  = parseInt(width*maxHeight/height);
			imgorg.height = maxHeight;
		}
	} else {
		if (maxWidth >= width*maxHeight/height) {
    		imgorg.Height = maxHeight;
		} else {
			imgorg.width = maxWidth;
			imgorg.height  = parseInt(height*maxWidth/width);
		}
	}
	
	imgorg.style.display = "inline";
}
//go to the blog of given url
function goBlogPage(url){
	window.open('/blog/index.do'+url,'_blank','resizable=no,width=939,height=627,status=yes');
}

/*********************************************************************
	±â´É	: »õÃ¢ Á¤Áß¾ÓÀ¸·Î open		
	RETURN	: NONE
	url 	: ÀÌµ¿ÇÒ ÁÖ¼Ò
	winName	: ÆË¾÷ ÀÌ¸§
	w       : ³ÐÀÌ
	h       : ³ôÀÌ
	scroll  : (yes, no, auto)
	pos   	: (right, center, left) center ·Î¼±ÅÃÇÒ°Í
	resize	: (yes, no) Ã¢ »çÀÌÁî Á¶Àý 
	state	: (yes, no) »óÅÂ¹Ù Ç¥½Ã¿©ºÎ
*********************************************************************/
	function newWindow(url, winName, w, h, scroll, pos, resize, status) {

		var win=null; 
		if (pos=="center") { 
			LeftPosition=(screen.width)?(screen.width-w)/2:100 ; 
			TopPosition=(screen.height)?(screen.height-h)/2:100 ;
		}
		else{
			LeftPosition=(screen.width)?(screen.width-w)/2:100 ; 
			TopPosition=(screen.height)?(screen.height-h)/2:100 ;
		}

		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+','+'status='+status ; 

		win=window.open(url,winName,settings); 
		if (win.focus) {
			win.focus();
		}
	} 

function isArray() {
	if (typeof arguments[0] == 'object') {
		var criterion = arguments[0].constructor.toString().match(/array/i);
		return (criterion != null);  
	}return false;
}

// toggle layer's display attribute	
function toggleLayer(ons, offs) {
	if (!isArray(ons)) {
		ons = [ons];
	}
	if (!isArray(offs)) {
		offs = [offs];
	}
	for (var i = 0; i < offs.length; i++) {
		var div = document.getElementById(offs[i]);
		if (div != null) {
			with (div.style) {
				display = 'none';
			}
		}
	}
	for (var i = 0; i < ons.length; i++) {
		var div = document.getElementById(ons[i]);
		if (div != null) {
			with (div.style) {
				display = 'block';
			}
		}
	}
}	