/* ============================================================================== */
/* =  ## ÀÌ¹ÌÁö »õÃ¢¶ç¿ì±â
/* ============================================================================== */
function displayImage(picName, windowName, windowWidth, windowHeight)
{
	var winHandle = window.open("" ,windowName,"toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight + ",top=0, left=0")
	if(winHandle != null){
	var htmlString = "<html><head><title>:: BMW Hockenheim Motorrad ::</title></head>" 
	htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
	htmlString += "<p><a href=javascript:window.close()><img src=" + picName + " border=0 alt=Ã¢´Ý±â></a></p>"
	htmlString += "</body></html>"
	winHandle.document.open()
	winHandle.document.write(htmlString)
	winHandle.document.close()
	}
	if(winHandle != null) winHandle.focus()
	return winHandle
}

/* ============================================================================== */
/* =  ## FlashInsert
/* ============================================================================== */
function FlashInsert(FlashIDName, FlashFileName, FlashWidth, FlashHeight, DNSSetting, WMODESetting, FlashBGColor, FlashMenu, QSetting, FlashAlign)
{
	document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write('CODEBASE="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,22,0" ');
	document.write(' ID="'+FlashIDName+'" WIDTH="' + FlashWidth + '" HEIGHT="' + FlashHeight + '" ALIGN="'+FlashAlign+'">');
	document.write('<PARAM NAME="movie" VALUE="'+ FlashFileName +'">');
	document.write('<PARAM NAME="menu" VALUE="'+FlashMenu+'">');
	document.write('<PARAM NAME="quality" VALUE="'+QSetting+'">');
	document.write('<PARAM NAME="bgcolor" VALUE="'+FlashBGColor+'">');
	document.write('<PARAM NAME="wmode" VALUE="'+WMODESetting+'">');
	document.write('<PARAM NAME="allowScriptAccess" VALUE="'+DNSSetting+'">');
	document.write('<EMBED SRC="'+ FlashFileName +'"  NAME="'+FlashIDName+'"');
	document.write(' WIDTH="' + FlashWidth + '" HEIGHT="' + FlashHeight + '" QUALITY="'+QSetting+'" BGCOLOR="'+FlashBGColor+'"');
	document.write(' ALLOWSCRIPTACCESS="'+DNSSetting+'" ALIGN="'+FlashAlign+'" WMODE="'+WMODESetting+'" TYPE="application/x-shockwave-flash" ');
	document.write(' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" >');
	document.write('</EMBED>');
	document.write('</OBJECT>');
}


/* ============================================================================== */
/* =  ## getXMLHttpRequest
/* ============================================================================== */
function getXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e1) { return null; }
		}
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}
var httpRequest = null;

function sendRequest(url, params, callback, method, arg)
{
	httpRequest = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';
	if (httpMethod != 'GET' && httpMethod != 'POST') {
		httpMethod = 'GET';
	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if (httpMethod == 'GET' && httpParams != null) {
		httpUrl = httpUrl + "?" + httpParams;
	}
	httpRequest.open(httpMethod, httpUrl, true);
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.onreadystatechange = function()
	{
		callback(arg);
	}
	httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}


/* ============================================================================== */
/* =  ## show&hide Layers
/* ============================================================================== */
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


/* ============================================================================== */
/* =  ## Æ÷Ä¿½ºÀÌµ¿
/* ============================================================================== */
function nextFocus(arg1, arg2, num)
{
	var input1 = document.getElementById(arg1);
	var input2 = document.getElementById(arg2);
	if(input1.value.length == num)
	{
		input2.focus();
	}
}


/* ============================================================================== */
/* =  ## »õÃ¢¶ç¿ì±â
/* ============================================================================== */
function winOpen(url, name, width, height, top, left, scroll, type)
{
	if(!type)
	{
		myTop  = top;
		myLeft = left;
	}else{
		myLeft = (screen.width-width)/2;
		myTop  = (screen.height-height)/2;
	}
	window.open(url, name, 'location=no, directories=no, resizable=no, status=1, toolbar=no, menubar=no, width=' + width + ', height=' + height + ', top=' + myTop + ', left=' + myLeft + ', scrollbars=' + scroll);
	return false;
}


/* ============================================================================== */
/* =  ## ¼¿·ºÆ®¹Ú½º Á¤º¸°¡Á®¿À±â
/* ============================================================================== */
function setSelectedValue(listBox,itemValue)
{
	var idx = 0;
	for(var i=0; i<listBox.options.length; i++)
	{
		if(listBox.options[i].value == itemValue)
		{
			idx = i;
		}
	}
	listBox.selectedIndex = idx;
}


/* ============================================================================== */
/* =  ## ·Î±×ÀÎ
/* ============================================================================== */
function check_login(form)
{
	if(!form.user_id.value)
	{
		alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.user_id.focus();
		return;
	}

	if(!form.pass.value)
	{
		alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.pass.focus();
		return;
	}
	form.action = "member/login_check.php";
	form.submit();
}


/* ============================================================================== */
/* =  ## È¸¿ø°¡ÀÔ
/* ============================================================================== */
function check_join(form)
{
	if(!form.user_id.value)
	{
		alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.user_id.focus();
		return;
	}

	if(!form.pass1.value)
	{
		alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.pass1.focus();
		return;
	}

	if(!form.pass2.value)
	{
		alert('ºñ¹Ð¹øÈ£È®ÀÎÀ» ÀÔ·ÂÇÏ¼¼¿ä!');
		form.pass2.focus();
		return;
	}

	if(form.pass1.value != form.pass2.value)
	{
		alert('ºñ¹Ð¹øÈ£°¡ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù!');
		form.pass1.select();
		form.pass1.focus();
		return;
	}

	if(form.pass1.value.length < 4 || form.pass1.value.length > 10)
	{
		alert('ºñ¹Ð¹øÈ£´Â ÃÖ¼Ò 4ÀÚ ÀÌ»ó, 10ÀÚ ÀÌÇÏÀÇ ¼ýÀÚ ¶Ç´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù!');
		form.pass1.select();
		form.pass1.focus();
		return;
	}

	if(!form.post1.value)
	{
		alert('¿ìÆí¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.post1.focus();
		return;
	}

	if(!form.post2.value)
	{
		alert('¿ìÆí¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.post2.focus();
		return;
	}

	if(!form.addr.value)
	{
		alert('ÁÖ¼Ò¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.addr.focus();
		return;
	}

	if(!form.tel1.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel1.focus();
		return;
	}

	if(!form.tel2.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel2.focus();
		return;
	}

	if(!form.tel3.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel3.focus();
		return;
	}


	if(!form.phone1.value)
	{
		alert('ÀÌµ¿ÀüÈ­¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone1.focus();
		return;
	}

	if(!form.phone2.value)
	{
		alert('ÀÌµ¿ÀüÈ­¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone2.focus();
		return;
	}

	if(!form.phone3.value)
	{
		alert('ÀÌµ¿ÀüÈ­¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone3.focus();
		return;
	}

	if(!form.email.value)
	{
		alert('ÀÌ¸ÞÀÏÀ» ÀÔ·ÂÇÏ¼¼¿ä!');
		form.email.focus();
		return;
	}

	if(form.email.value.indexOf("/")!=-1 || form.email.value.indexOf(";") !=-1)
	{
		alert("E-MailÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		form.email.focus();
		return;
	}

	if((form.email.value.length != 0) && (form.email.value.search(/(\S+)@(\S+)\.(\S+)/) == -1))
	{
		alert("E-MailÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		form.email.focus();
		return;
	}

	if(!form.model.value)
	{
		alert('º¸À¯¸ðµ¨À» ÀÔ·ÂÇÏ¼¼¿ä!');
		form.model.focus();
		return;
	}

	if(!form.buy_dateY.value)
	{
		alert('±¸ÀÔ½Ã±â¸¦ ¼±ÅÃÇÏ¼¼¿ä!');
		form.buy_dateY.focus();
		return;
	}

	if(!form.buy_dateM.value)
	{
		alert('±¸ÀÔ½Ã±â¸¦ ¼±ÅÃÇÏ¼¼¿ä!');
		form.buy_dateM.focus();
		return;
	}

	form.submit();
}


/* ============================================================================== */
/* =  ## È¸¿ø¼öÁ¤
/* ============================================================================== */
function check_edit(form)
{
	if(form.pass1.value != form.pass2.value)
	{
		alert('ºñ¹Ð¹øÈ£°¡ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù!');
		form.pass1.select();
		form.pass1.focus();
		return;
	}

	if(form.pass1.value && form.pass1.value.length < 4 || form.pass1.value.length > 10)
	{
		alert('ºñ¹Ð¹øÈ£´Â ÃÖ¼Ò 4ÀÚ ÀÌ»ó, 10ÀÚ ÀÌÇÏÀÇ ¼ýÀÚ ¶Ç´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù!');
		form.pass1.select();
		form.pass1.focus();
		return;
	}

	if(!form.tel1.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel1.focus();
		return;
	}

	if(!form.tel2.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel2.focus();
		return;
	}

	if(!form.tel3.value)
	{
		alert('ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.tel3.focus();
		return;
	}

	if(!form.phone1.value)
	{
		alert('ÇÚµåÆù¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone1.focus();
		return;
	}

	if(!form.phone2.value)
	{
		alert('ÇÚµåÆù¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone2.focus();
		return;
	}

	if(!form.phone3.value)
	{
		alert('ÇÚµåÆù¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		form.phone3.focus();
		return;
	}

	if(!form.email.value)
	{
		alert('ÀÌ¸ÞÀÏÀ» ÀÔ·ÂÇÏ¼¼¿ä!');
		form.email.focus();
		return;
	}

	if(form.email.value.indexOf("/")!=-1 || form.email.value.indexOf(";") !=-1)
	{
		alert("E-MailÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		form.email.focus();
		return;
	}

	if((form.email.value.length != 0) && (form.email.value.search(/(\S+)@(\S+)\.(\S+)/) == -1))
	{
		alert("E-MailÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		form.email.focus();
		return;
	}

	if(!form.model.value)
	{
		alert('º¸À¯¸ðµ¨À» ÀÔ·ÂÇÏ¼¼¿ä!');
		form.model.focus();
		return;
	}

	if(!form.buy_dateY.value)
	{
		alert('±¸ÀÔ½Ã±â¸¦ ¼±ÅÃÇÏ¼¼¿ä!');
		form.buy_dateY.focus();
		return;
	}

	if(!form.buy_dateM.value)
	{
		alert('±¸ÀÔ½Ã±â¸¦ ¼±ÅÃÇÏ¼¼¿ä!');
		form.buy_dateM.focus();
		return;
	}

	form.submit();
}


/* ============================================================================== */
/* =  ## ÀüÃ¼°Ô½Ã¹°
/* ============================================================================== */
// ÀüÃ¼°Ô½Ã¹° ¼±ÅÃ
function checkAll(total)
{
	var chk_list_all = document.getElementById('chk_list_all');
	for(var i=1; i<=total; i++)
	{
		var chk_list = document.getElementById('chk_list'+i);
		if(chk_list_all.checked == true)
		{
			chk_list.checked = true;
		}else{
			chk_list.checked = false;
		}
	}
}

// ÀüÃ¼°Ô½Ã¹° »èÁ¦
function check_chk_list(form, total)
{
	var flag = 0;
	for(var i=1; i<=total; i++)
	{
		var chk_list = document.getElementById('chk_list'+i);
		if(chk_list.checked == true)
		{
			flag++;
		}
	}

	if(flag == 0)
	{
		alert('»èÁ¦ÇÒ °Ô½Ã¹°À» Ã¼Å©ÇØ ÁÖ¼¼¿ä!');
		return;
	}else{
		if(confirm('Ã¼Å©µÈ °Ô½Ã¹°À» ¸ðµÎ »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?'))
		{
			form.submit();
		}
	}
}


/* ============================================================================== */
/* =  ## ÄÚ¸àÆ® Ajax
/* ============================================================================== */
// ÆÐ½º¿öµåÃ¢
function show_chk_passwd(type, bID, cID)
{
	document.getElementById('show_passwd_cID_'+cID).style.display = "block";
	var pass = document.getElementById('pass_'+cID);
	pass.value = "";
	pass.focus();

	var passwd_ok = document.getElementById('passwd_ok_cID_'+cID);
	passwd_ok.onclick = function()
	{
		chk_passwd(type, document.getElementById('pass_'+cID).value, bID, cID);
	}
}

// ÆÐ½º¿öµåÃ¼Å©
function chk_passwd(type, pass, bID, cID)
{
	if(!pass)
	{
		alert('ÆÐ½º¿öµå¸¦ ÀÔ·ÂÇÏ¼¼¿ä!');
		var pass = document.getElementById('pass_'+cID);
		pass.focus();
		return
	}
	var params = "bID=" + bID + "&cID=" + cID + "&pass=" + pass + "&type=" + type;
	sendRequest('./board/c_passwd_chk.php', params, c_type_proc, "POST", cID);
}

// È¸¿øÃ¼Å©
function chk_member(type, bID, cID)
{
	var params = "bID=" + bID + "&cID=" + cID + "&type=" + type;
	sendRequest('./board/c_passwd_chk.php', params, c_type_proc, "POST", cID);
}

// ¼öÁ¤,»èÁ¦ ±¸ºÐÃ³¸®
function c_type_proc(cID)
{
	if(httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var result = httpRequest.responseText;
			var arr = result.split("|");
			if(arr[0] == "success")
			{
				// ¼öÁ¤¸ðµå
				if(arr[1] == 'edit')
				{
					document.getElementById('show_passwd_cID_'+cID).style.display = "none";
					document.getElementById('secret_cID_' + cID).style.display = "none";
					document.getElementById('edit_cID_' + cID).style.display = "block";
					document.getElementById('btn_default_cID_' + cID).style.display = "none";
					document.getElementById('btn_edit_cID_' + cID).style.display = "block";

					// ÀúÀå¹öÆ°
					var btn_edit_save = document.getElementById('btn_edit_save_cID_'+cID);
					btn_edit_save.onclick = function()
					{
						if(confirm('¼öÁ¤ÇÏ½Ã°Ú½À´Ï±î?'))
						{
							var comment = document.getElementById('content_cID_' + cID).value;
							var params = "bID=" + arr[3] + "&cID=" + cID + "&pass=" + arr[2] + "&comment=" + comment;
							sendRequest('./board/c_edit_proc.php', params, c_edit_result, "POST", cID);
						}
					}

					// Ãë¼Ò¹öÆ°
					var btn_edit_cancel = document.getElementById('btn_edit_cancel_cID_'+cID);
					btn_edit_cancel.onclick = function()
					{
						document.getElementById('secret_cID_' + cID).style.display = "block";
						document.getElementById('edit_cID_' + cID).style.display = "none";
						document.getElementById('btn_default_cID_' + cID).style.display = "block";
						document.getElementById('btn_edit_cID_' + cID).style.display = "none";
					}
				}

				// »èÁ¦¸ðµå
				else
				{
					if(confirm('»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?'))
					{
						var params = "bID=" + arr[3] + "&cID=" + cID + "&pass=" + arr[2];
						sendRequest('./board/c_delete_proc.php', params, c_delete_result, "POST", null);
					}else{
						document.getElementById('show_passwd_cID_'+cID).style.display = "none";
					}
				}
			}else{
				alert("ÆÐ½º¿öµå°¡ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù!");
				var pass = document.getElementById('pass_'+cID);
				pass.value = "";
				pass.focus();
			}
		}
	}
}

// »èÁ¦ °á°ú°ª
function c_delete_result()
{
	if(httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var result = httpRequest.responseText;
			if(result == "success")
			{
				window.location.reload();
			}else{
				alert(result);
			}
		}
	}
}

// ¼öÁ¤ °á°ú°ª
function c_edit_result(cID)
{
	if(httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var result = httpRequest.responseText;
			var arr = result.split("|");
			if(arr[0] == "success")
			{
				var comment = document.getElementById('secret_cID_'+cID);
				comment.innerHTML = arr[1];

				document.getElementById('secret_cID_' + cID).style.display = "block";
				document.getElementById('edit_cID_' + cID).style.display = "none";
				document.getElementById('btn_default_cID_' + cID).style.display = "block";
				document.getElementById('btn_edit_cID_' + cID).style.display = "none";
			}else{
				alert(result);
			}
		}
	}
}
