//해당 페이지로 이동
function goPage (url, target) {
	window.open (url, target);
}
function goParentPage (url, target) {
	parent.window.open (url, target);
}
function logout () {
	target_url = "/ajax.php?user=logout";

	var funcRef = function( msg ) {
		if ( msg )
		{
			// goPage("/index.php", "_self");
			location.href = '/index.php';
		}
	}
	httpRequest( target_url, funcRef );
}

function exclude_user(uno) {
	target_url = "/ajax.php?user=execlude&uno="+uno;

	var funcRef = function( msg ) {
		document.getElementById('exclusion_label_'+uno).outerHTML = "";
	}
	httpRequest( target_url, funcRef );
}

function INPUTBox_focus ( obj, action, str ) {
	switch (action)	{
		case "on" :
			if (obj.value == str || obj.value == "" ) {
				obj.value = "";
			}
			break;
		case "off" :
			if (obj.value == str || obj.value == "" ) {
				obj.value = str;
			}
			break;
	}
}

//새 윈도우를 띄움
function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	var toolbar_str = toolbar ? 'yes' : 'no';
	var menubar_str = menubar ? 'yes' : 'no';
	var statusbar_str = statusbar ? 'yes' : 'no';
	var scrollbar_str = scrollbar ? 'yes' : 'no';
	var resizable_str = resizable ? 'yes' : 'no';

	var w = window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',statusbar='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
	w.focus();
}



function open_wndfocus(url, name){
	name="_self";
	var w = window.open(url, name);
	w.focus();
}
function open_wndfocus_iframe(url, name){
	name="_parent";
	var w = window.open(url, name);
	w.focus();
}
/// 블로그윈도우에서 어미윈도우로 가기
function open_mainwnd(url){
//		if (!window.opener.closed){
//			opener.document.location.href=url;
//			opener.focus();
//
//		}else{
//			var w = window.open(url, 'main_wnd');
//			w.focus();
//		}
		window.open(url, '_self');
}

//iframe 의 높이를 자동으로 조절
function resizeFrame(iframeObj){
		var innerBody = iframeObj.contentWindow.document.body;
		oldEvent = innerBody.onclick;
		innerBody.onclick = function(){ resizeFrame(iframeObj, 1);oldEvent; };

		var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
		iframeObj.style.height = innerHeight;

//		if( arguments[0] != null ){
//			var doc = iframeObj.contentWindow.document;
//			doc.getElementById(arguments[2]).style.display = 'none';
//		}
///		if( !arguments[1] )        /* 특정 사건으로  호출했을 때 스크롤을 그냥 둔다. */
///			this.scrollTo(1,1);
}

//테블의 모서리를 둥글게처리
function roundTable(objID,start,end)
{
	var obj = document.getElementById(objID);
	var Parent, objTmp, Table, TBody, TR, TD;
	var bdcolor, bgcolor, Space;
	var trIDX, tdIDX, MAX;
	var styleWidth, styleHeight;

	// get parent node
	Parent = obj.parentNode;
	objTmp = document.createElement('SPAN');
	Parent.insertBefore(objTmp, obj);
	Parent.removeChild(obj);

	// get attribute
	bdcolor = obj.getAttribute('rborder');
	bgcolor = obj.getAttribute('rbgcolor');
	radius = parseInt(obj.getAttribute('radius'));
	if (radius == null || radius < 1) radius = 1;
	else if (radius > 6) radius = 6;

	MAX = radius * 2 + 1;

	/*	create table {{ 	*/
	Table = document.createElement('TABLE');
	TBody = document.createElement('TBODY');

	Table.cellSpacing = 0;
	Table.cellPadding = 0;

	for (trIDX=start; trIDX < MAX-end; trIDX++) {
		TR = document.createElement('TR');
		Space = Math.abs(trIDX - parseInt(radius));
		for (tdIDX=0; tdIDX < MAX; tdIDX++) {
			TD = document.createElement('TD');
			styleWidth = '1px';
			styleHeight = '1px';
			if (tdIDX == 0 || tdIDX == MAX - 1) styleHeight = null;
			else if (trIDX == 0 || trIDX == MAX - 1) styleWidth = null;
			else if (radius > 2) {
				if (Math.abs(tdIDX - radius) == 1) styleWidth = '2px';
				if (Math.abs(trIDX - radius) == 1) styleHeight = '2px';
			}
			if (styleWidth != null) TD.style.width = styleWidth;
			if (styleHeight != null) TD.style.height = styleHeight;
			if (Space == tdIDX || Space == MAX - tdIDX - 1) TD.style.backgroundColor = bdcolor;
			else if (tdIDX > Space && Space < MAX - tdIDX - 1)  TD.style.backgroundColor = bgcolor;
			if (Space == 0 && tdIDX == radius) TD.appendChild(obj);
			TR.appendChild(TD);
		}
		TBody.appendChild(TR);
	}
	/*
	}}
	*/
	Table.appendChild(TBody);
	// insert table and remove original table
	Parent.insertBefore(Table, objTmp);
}

//SWF파일을 현시시키는 함수
function showFlashObject (id,width,height,movie,flashvars,wmode)
{
	var s = '<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" width="'+width+'" height="'+height+'" >';
	s = s + '<param name="movie" value="'+movie+'"/>';
	s = s + '<param name="menu" value="false"/>';
	s = s + '<param name="quality" value="high"/>';
	s = s + '<param name="allowScriptAccess" value="sameDomain"/>';
	s = s + '<param name="play" value="true"/>';
	s = s + '<param name="wmode" value="'+wmode+'"/>';
	s = s + '<param name="flashvars" value="'+flashvars+'"/>';
	s = s + '<embed swLiveConnect="true" flashvars="'+flashvars+'" src="'+movie+'" quality="high" bgcolor="" wmode="transparent" width="'+width+'" height="'+height+'" name="'+id+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	s = s + '</embed>';
	s = s + '</object>';
	document.write(s);
}

function post_form ( str_action, formname ) {
	var myform = document.getElementById(formname);
	myform.action = str_action;
	myform.submit();
}

//*********************************************************
//상태띠에 광고문자렬 출력
var endChar = "                ^";

var message = new Array(
	"중국 비지니스 인맥 허브." + endChar,
	"중국 비지니스 정보교류 센터."  + endChar,
	"중국 비지니스 컨설팅 전문가 그룹."  + endChar
);

var scrollSpeed = 50;
var lineDelay   = 500;
var txt = ""
var pos_message = 0;

function scrollText(pos_char, pos_message) {

	if (message[pos_message].charAt(pos_char) != '^') {

		txt = txt + message[pos_message].charAt(pos_char);
		window.status = txt;
		SP  = scrollSpeed;

	} else { //마지막문자가 [^] 이면 초기화

		SP = lineDelay;
		txt   = "";
		if ( pos_char == message[pos_message].length-1 ) pos_char = -1;

		if ( pos_message >= message.length - 1 )
		{
			pos_message = 0;
		} else {
			pos_message++;
		}
	}
	pos_char++;
	setTimeout("scrollText('"+pos_char+"','"+pos_message+"')",SP);
}

//scrollText(0,pos_message);

function resizeImage(imgid)
{
	var obj = document.getElementById('userImg'+imgid);

	if(obj.width > 500)
	{
		obj.width = 500;
	}
}

function country_select ( val, childName ){

	var city = document.getElementById(childName);

	if ( val == 1) //중국이면
	{
		city.style.display = 'inline';
		target_url = "/ajax.php?country=china";
		server_requerst (target_url, city)

	} else if ( val == 2) //조선이면
	{
		city.style.display = 'inline';
		target_url = "/ajax.php?country=northkorea";
		server_requerst (target_url, city)

	} else if ( val == 3) //남조선이면
	{
		city.style.display = 'inline';
		target_url = "/ajax.php?country=southkorea";
		server_requerst (target_url, city)

	} else {
		city.style.display = 'none';
	}
}


function Add_To_Bookmark()
{
	if (document.all)
		window.external.AddFavorite(document.location.href, document.title);
}

function Add_To_Favorite()
{
	add_url="http://www.bn4china.com/"
	add_title="BN4China - Business Network for China | 최초 중국 비지니스 인맥 커뮤니티"
	if (document.all)
	window.external.AddFavorite(add_url,add_title)
}
function pop_view(url){
	open_window('BigPhoto', url,100,100,300,300,0,0,0,0,1);
}
function GoTop() {
	window.scrollTo(0,0);
}

var Xpos = 0;
var Ypos = 0;
var Ygravity = 0.85;
var scrollPos = 0;
var oldScrollPos = 0;

function FloatMenu() {

	var floater = document.getElementById('floater');
	docWidth = document.body.clientWidth;
	docHeight = document.body.clientHeight;
	oldScrollPos = scrollPos;
	scrollPos = document.body.scrollTop;

	Xpos = (docWidth / 2) + 335;
	Yboundary = ( ( scrollPos + docHeight) - floater.offsetHeight ) - 150;

	if (floater.offsetTop < Yboundary - 1)
		Ypos += 2;

	if (floater.offsetTop > Yboundary + 1)
		Ypos -= 2;
	Ypos *= Ygravity;

	 // Slow object down
	floater.style.pixelLeft = Xpos;

	floater.style.pixelTop += Ypos;

	docWidth1 = document.body.clientWidth;
}


/// 이모티콘 앉히는 코드 [ = 0, ] = 1;
function saveCurrentPos (objTextArea) {
   if (objTextArea.createTextRange)
         objTextArea.currentPos = document.selection.createRange().duplicate();
}

function onClickImoticon(ino, objName){
	var chStr = ")";
	var res;
//		for (var ist = 0; ist < 5; ist++){
//			res = ino % 2; ino = Math.floor(ino / 2);
//			if (res == 0) chStr = "[" + chStr; else chStr = "]" + chStr;
//		}
//		chStr = "("+chStr;
	ino = ino+1;	chStr = "(["+ino+"])";
	var obj = document.getElementById(objName);
	if (obj.createTextRange && obj.currentPos) {
         var currentPos = obj.currentPos;
         currentPos.text =
           currentPos.text.charAt(currentPos.text.length - 1) == ' ' ?
             chStr + ' ' : chStr;
   }
   else
   		obj.value += chStr;


	obj.focus();
}


/// 입력복스들에 대해서 입력제한 검사 리용함수들 (인맥링크 개발시 추가)
	function objvalid_check(obj, msg, checkVal, maxLen){
		var val = obj.value;

		if (checkVal == '0'){
			if ( CheckNumber(obj.value) == false){
				obj.focus(); alert("숫자로 입력해야 합니다."); return false;
			}
		}
		if (checkVal=="") 	val = val.replace(/^\s+|\s+$/g,"");

		if ( val == checkVal ){
			obj.focus(); alert(msg); return false;
		}
		if ( maxLen != 0 && val.length > maxLen ){
			obj.focus(); alert("문자열의 길이는 "+maxLen+"글자를 초과할수 없습니다."); return false;
		}

		return true;

	}

	function CheckChar(str) {
		  var error_c=0, i, val;
		  for(i=0; i <str.length; i++){
		  	val = str.charAt(i);
		    if(!((val>=0 && val<=9) || (val>='a' && val<='z') || (val>='A' && val<='Z'))) return false;
		  }
		  return true;
	}
	function CheckNumber(str) {
		  var error_c=0, i, val;
		  for(i=0; i <str.length; i++){
			  	val = str.charAt(i);
			    if( val < '0' || val>'9') {
			    	return false;
			    }
		  }
		  return true;
	}
	/// 체크복사  전체선택을 위하여
	function is_one_checked(chk_name, isval){
		// 체크복스중에서 적어도 하나의 상태가 isval와 같으면 참을 귀환
		var chk = document.getElementsByName(chk_name );
		if(chk != null){
			for(var i=0; i < chk.length;i++) {
			if(chk[i].checked == isval)
				return true;
			}
		}
		return false;
	}
	function AllChk( chkAll ,  txt_name) {
	  var isAllCheck = chkAll.checked;
	  isAllCheck = !isAllCheck;
	  var chk = document.getElementsByName(txt_name );
	  if(chk != null){
	   for(var i=0; i < chk.length;i++) {
	    if(isAllCheck == true){
	     chk[i].checked = false;
	    }else{
	      chk[i].checked = true;
	     }
	   }
	  }

	 }