String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

var ImgSize = 575;
var ImgResizeTimerID;

function imageResize() {
	doResize()
	ImgResizeTimerID=setInterval("doResize()", 100)
}

function doResize() {
	for(i = 0; i < document.images.length; i++) {
		if(document.images[i].name == "rainimg_resize") {
			var img = document.images[i];
			if(img.width > ImgSize) {	
				img.height = img.height * (ImgSize / img.width);
				img.width = ImgSize;
			}
		}
	}
	
	if(checkAllResized()) {
		stopResizeTimer();
	}
}

function checkAllResized() {
	for(i = 0; i < document.images.length; i++) {
		if(document.images[i].name == "rainimg_resize") {
			var img = document.images[i];
			if(img.width == 0  || img.width > ImgSize) {
				return false;
			}
		}
	}
	return true;
}

function stopResizeTimer() {
	clearInterval(ImgResizeTimerID);
}

function popupMsg(msg) {
	alert(msg);
}

function showPopup(width, height, url) {
	window.open(url,'PICKUP','width='+width+',height='+height+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
}

function pickupBlog(id, step, table, dir) {
	window.open('/blog/pickup_blog.php?b_cd='+id+'&step='+step+'&table='+table+'&dir='+escapeTxt(dir),'PICKUP','left=0,top=0,width=395,height=270,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
}

function escapeTxt(os){
	var ns='';
	var t;
	var chr='';
	var cc='';
	var tn='';
	for(i=0;i<256;i++){
		tn=i.toString(16);
		if(tn.length<2)tn="0"+tn;
		cc+=tn;
		chr+=unescape('%'+tn);
	}

	cc=cc.toUpperCase();
	os.replace(String.fromCharCode(13)+'',"%13");
	for(q=0;q<os.length;q++){
		t=os.substr(q,1);
		for(i=0;i<chr.length;i++){
			if(t==chr.substr(i,1)){
				t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
				i=chr.length;
			}
		}
		ns+=t;
	}
	return ns;
}

function checkIdenNum(str) {
	var re=new RegExp(/\d{6}(\-|)[1-4]\d{6}$/);
	return re.test(str);
}

function checkEmail(str) {
	var re = new RegExp(/[\w\-\~]+\@[\w\-\~]+(\.[\w\-\~]+)+/g);
	return re.test(str);
}

function checkText(str) {
	if(str.match(/\S/) == null || str.length < 1) {
    return false;
	}
	else {
		return true;
	}
}

function checkTitle(str) {
	if(str.match(/\S/) == null || str.length < 2) {
		return false;
	}
	else {
		return true;
	}
}

function checkName(str) {
	if(str.match(/\S/) == null || str.length < 2) {
    return false;
	}
	else {
		return true;
	}
}

function checkPhoneNumber(str) {
	var re=new RegExp(/0\d+\-\d\d+\-\d\d\d\d/g);
	return re.test(str);
}

function checkCellNumber(str) {
	var re=new RegExp(/01[016789]\-\d\d+\-\d\d\d\d/g);
	return re.test(str);
}

function checkContent(str) {
	trStr = str.trim();
	
	if(trStr.match(/\S/) == null || trStr.length < 10) {
    return false;
	}
	else {
		return true;
	}
}


function CheckStrLength(str, limitLen, limitLine, isAlert)
{
	var temp;
	var f = str.length;
	var msglen = limitLen; //ÃÖ´ë ±æÀÌ
	var tmpstr = "";
	var enter = 0;
	var strlen;
		var aaa = 0;
	for(k=0;k<f;k++)
	{
		temp = str.charAt(k);
		
		if(temp == '\n')// ÀÔ·Â ¶óÀÎ Á¦ÇÑÀ» À§ÇØ ¿£ÅÍÅ° È½¼ö Áõ°¡
		{
			enter++;
		}
		

		if(escape(temp).length > 4) {
			msglen -= 2;
		}
		else {
			msglen--;
		}
		
		if(msglen < 0)
		{
			if(isAlert) {
				alert("ÃÑ ¿µ¹® "+ limitLen +"ÀÚ ÇÑ±Û " + Math.floor(limitLen / 2) + "ÀÚ ±îÁö ¾²½Ç ¼ö ÀÖ½À´Ï´Ù.");
			}
			str = tmpstr;
			return false;
		}
		
		else if(enter > (limitLine - 1))
		{
			if(isAlert) {
				alert("¶óÀÎ¼ö "+ limitLine +"¶óÀÎÀ» ³ÑÀ»¼ö ¾ø½À´Ï´Ù.");
			}
			enter = 0;
			strlen = tmpstr.length - 1;
			str = tmpstr.substring(0,strlen);
			return false;
		}
		
		else
		{
			tmpstr += temp;
		}
	}
	return true;
}


function NICK_openPlayer(si,pi) {
/*
  var url="/player/";
  if (si) url=url+"?si="+si;
  if (pi) url=url+((url.indexOf('?')>0)?"&":"?")+"pi="+pi;
  var url="http://kr.turbonick.nick.com/turbonick/";
  window.open(url,"_blank","width=1020,height=820,scrollbars=1");
*/
  var url="http://www.nick.co.kr/turbonick/";
  window.open(url,"winopen","width=1040,height=700,scrollbars=1");
}
function Nick_openTurbonick(url) {
  //if (!url) var url="http://kr.turbonick.nick.com/turbonick/";
  //window.open(url,"_blank","width=1020,height=820,scrollbars=1");
  
  if (!url) var url="http://www.nick.co.kr/turbonick/";
  window.open(url,"winopen","width=1040,height=700,scrollbars=1");
}
