/*
window.onerror = ErrorH; 

function ErrorH(message, url, line) { 
  var str = "" 
  + "Error: " + line + "" + message; 
  window.status = str; 
  return true; 
}
*/

var isIE = (document.all)? true:false;

//삭제관련 함수
  function del(url,msg)
  {
	  if(confirm(msg)){document.location.href = url;}
  }

//글 수정 삭제시
	function form_check()
	{
		var f = document.form;
		if(!f.b_pw.value){alert('비밀번호를 입력해주세요');f.b_pw.focus();return false;}
	}

//글 작성시
	function write_check()
	{
		var f = document.write_form;
		if(!f.category.value){alert('카테고리를 입력해주세요');f.category.focus();return false;}
		if(!f.subject.value){alert('제목을 입력해주세요');f.subject.focus();return false;}
		if(!f.memo.value){alert('내용을 입력해주세요');f.memo.focus();return false;}
	}

	function write_check2()
	{
		var f = document.write_form;
		if(!f.b_name.value){alert('이름을 입력해주세요');f.b_name.focus();return false;}
		if(!f.b_pw.value){alert('비밀번호를 입력해주세요');f.b_pw.focus();return false;}
		if(!f.subject.value){alert('제목을 입력해주세요');f.subject.focus();return false;}
		if(!f.memo.value){alert('내용을 입력해주세요');f.memo.focus();return false;}
	}
//카테고리 등록,수정시 필요한 함수 3개
	function category_check()
	{
		var f = document.category_form;
		var icnt = f['category_no[]'].length;
		var icnt2 = icnt -1;
		for(i=0; i<icnt; i++)
		{
			tts = f.tt.value.split(',');
			if(!f['category_name[]'][i].value && i != icnt2)//분류명을 지웠을경우
			{
				alert('분류명을 넣어주세요');f['category_name[]'][i].focus();return false;
			}
			for(t=0;t<tts.length;t++)
			{
				if(!f['category_name[]'][icnt -1].value && i != icnt2)//분류등록에 분류명이 없고 우선순위가 가장 높을경우
				{
					if(icnt2 == f['category_no[]'][i].value)
					{
						f['category_no[]'][i].value = f['category_no[]'][icnt2].value;
						f['category_no[]'][icnt2].value = icnt2;
						f.tt.value = "";
						alert('분류등록에 분류이름이 없을경우\n\n 최하위 우선순위가 분류에 들어갈수없습니다.');return false;
					}
				}
				if(tts[t] == f['category_no[]'][i].value)//중복되는 값이 있을경우 없겠지만 만약을 위해서
				{
					alert('우선순위에 중복되는 값이 있습니다.');return false;
				}
			}
			f.tt.value += f['category_no[]'][i].value+",";
		}
	}

	function category_check2(no)
	{
		var f = document.category_form;
		f.ttl.value = no;
	}
	function category_check3(no,no2)
	{
		var f = document.category_form;
		if(!f['category_no[]'][no2].value)//우선순위를 지웠을경우
		{
			alert('우선순위를 지우시면 안되져~ 그럼 미오미오');f['category_no[]'][no2].value=f.ttl.value;
		}
		if(f['category_no[]'][no2].value>=f['category_no[]'].length)//가장큰 순위보다 클경우
		{
			alert('가장높은 우선순위보다 숫자가 큽니다');f['category_no[]'][no2].value=f.ttl.value;
		}
		if(isNaN(f['category_no[]'][no2].value))//숫자만 가능하게
		{
			alert('숫자만 가능합니다. 자꾸 문자쓰면 미오 할꼬야!!');f['category_no[]'][no2].value=f.ttl.value;
		}
		for(i=0;i<f['category_no[]'].length;i++)
		{
			if(i == no2){continue;}
			if(no == f['category_no[]'][i].value)
			{
				f['category_no[]'][i].value = f.ttl.value;
			}
		}
	}
//이미지 체크
	function img_check (img,name)
	{
		var ch = /.jpg|.gif/;
		var file = img.value;
		var f = eval("document.user_"+name);
		imgs = eval("img_"+name);
		if(ch.test(file))
		{
			this.imgs.innerHTML = "<img src=\""+img.value+"\" border=0 style=\"cursor:hand;width=50;height=50;\" onclick=\"img_pop(this);\">";
		}
		else
		{
			alert('gif,jpg 파일만 업로드가 가능합니다.');
		}
	}
//클릭시 팝업으로 보여주기
	function img_pop(image) {
	var width = 1;
	var height = 1;
	ypwindow = window.open("", "Image_Mlang", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width="+width+",height="+height+",top=100,left=100");
	ypwindow.document.open();
	ypwindow.document.write("<html><head><title>Snow Board 이미지 미리보기</title></head>");
	ypwindow.document.write("<body leftmargin=0 topmargin=0 onclick=self.close();>");
	ypwindow.document.write("<script>function resize(w,h){w = w+35;h=h+55;top.resizeTo(w,h);mw = (screen.width-w)/2;mh = (screen.height-h)/2;if(mw<0){mw=0;}if(mh<0){mh=0;}top.moveTo(mw,mh)}</script>");
	ypwindow.document.write("<img src=\""+image.src+"\" onload=resize(this.width,this.height)>");
	ypwindow.document.write("</body></html>");
	ypwindow.document.close(); 
	}


//갤러리일경우 클릭시 팝업으로 보여주기
	function img_bbs(image) {
	var width = 1;
	var height = 1;
	ypwindow = window.open("", "Image_Mlang", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width="+width+",height="+height+",top=100,left=100");
	ypwindow.document.open();
	ypwindow.document.write("<html><head><title>Snow Board 이미지 미리보기</title></head>");
	ypwindow.document.write("<body leftmargin=0 topmargin=0 onclick=self.close();>");
	ypwindow.document.write("<script>function resize(w,h){w = w+35;h=h+55;top.resizeTo(w,h);mw = (screen.width-w)/2;mh = (screen.height-h)/2;if(mw<0){mw=0;}if(mh<0){mh=0;}top.moveTo(mw,mh)}</script>");
	ypwindow.document.write("<img src=\""+image+"\" onload=resize(this.width,this.height)>");
	ypwindow.document.write("</body></html>");
	ypwindow.document.close(); 
	}

//회원레이어
	document.write("<div id=\"member_layer\" style=\"position:absolute;\"></div><div id=\"member_layer2\" style=\"position:absolute;\"></div>");
	function yp_layer(wuser_id,user_id,url,e)
	{
		var f = document.getElementById("member_layer");
		f.style.display = "block";
		if(document.all)
		{
			x = event.clientX;
			y = event.clientY+document.body.scrollTop;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}
		f.style.top = y;
		f.style.left = x-20;
		yp_layer_fun(url+"member/member_layer.php?wuser_id="+wuser_id+"&user_id="+user_id,"member_layer");
	}
	function yp_layer_memo(url,div_id)
	{
		var of = document.getElementById("member_layer");
		var f = document.getElementById(div_id);

		f.style.display = "block";
		f.style.top = of.style.top;
		f.style.left = parseInt(of.style.left)+100;
		yp_layer_fun(url,div_id);
	}
	function yp_layer_memo_send(url,obj,div_id)
	{
		var va = "";
		cnt = obj.length;
		for(i=0;i<cnt;i++)
		{
			if(obj[i].title && !obj[i].value)
			{
				alert(obj[i].title);
				obj[i].focus();
				return false;
			}
			va += obj[i].name+"="+obj[i].value+"&";
		}
		if(document.all)
		{
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			http = new XMLHttpRequest();
		}
		http.open("POST", url, true);
		http.onreadystatechange = function(){yp_friend_open(div_id);yp_layer_close('member_layer2');}
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.send(va);
		return false;
	}
	function yp_layer_open(div_id)
	{
		var f = document.getElementById(div_id);
		if(f.style.display == "none")
		{
			f.style.display = "block";
		}
	}
	function yp_layer_close(div_id)
	{
		var f = document.getElementById(div_id);
		f.style.display = "none";
		f.innerHTML = "";
	}
	function yp_layer_fun(url,div_id) 
	{
		if(document.all)
		{
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			http = new XMLHttpRequest();
		}
		http.open("GET", url, true);
		http.onreadystatechange = function(){yp_layer_open(div_id);}
		http.send(null);
	} 

	function yp_layer_open(div_id) 
	{
		if (http.readyState == 4) {
			var textout = http.responseText;
			document.getElementById(div_id).innerHTML = textout;
		}
	}
	function yp_friend_fun(url) 
	{
		if(document.all)
		{
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			http = new XMLHttpRequest();
		}
		http.open("GET", url, true);
		http.onreadystatechange = yp_friend_open;
		http.send(null);
	} 
	function yp_friend_open() 
	{
		if (http.readyState == 4) {
			var textout = http.responseText;
			alert(textout);
		}
	}
  function popup_window(form,user_id) {
    window.open('../bbs/edit.php?form='+form+'&wuser_id='+user_id, 'popup', 'width=600, height=500, menubar=no, scrollbars=no, toolbar=no, location=no, resizable=no, top=, left=');
  }

  function popup(url,s,w,h,t,l) {
	var f = eval("document.write_form."+s+".value")
    window.open(url+f, 'popup', 'width='+w+', height='+h+', menubar=no, scrollbars=no, toolbar=no, location=no, resizable=no, top='+t+', left='+l+'');
  }

  function popups(url,w,h,t,l) {
    window.open(url, 'popup', 'width='+w+', height='+h+', menubar=no, scrollbars=no, toolbar=no, location=no, resizable=no, top='+t+', left='+l+'');
  }
  function popupy(url,w,h,t,l) {
    window.open(url, 'popup', 'width='+w+', height='+h+', menubar=no, scrollbars=yes, toolbar=no, location=no, resizable=no, top='+t+', left='+l+'');
  }

//검색관련
	function search_check()
	{
		var f = document.fsearch;
		if(!f.sn.value){alert('검색어를 입력해주세요');f.sn.focus();return false;}
	}

//에러표시하기

	function YP_error(msg)
	{
		alert(msg);
	}

//회원글보기관련
	function user_write_link(url,id,u_no,no)
	{
		opener.location.href = url+"?wuser_id="+id+"&u_no="+u_no+"&no="+no;
	}

//복사관련
function list_copy(obj) {
	
	var text = obj.innerText;
	if (window.clipboardData) 
	{
		window.clipboardData.setData('Text',text);
		document.execCommand("Copy");
		window.clipboardData.getData("Text");
		alert(text+' 가 복사되었습니다.');
	}
}

function list_copys(theField,no) {
	var td = eval("document."+no+".trackback_copy.createTextRange()");
	var ts = eval("document."+no+".trackback_copy.select()");
	var tv = eval("document."+no+".trackback_copy.value");
    var doc = td;
    ts;
    doc.execCommand('copy');
	alert(tv+' 가 복사되었습니다.');
}

function copy_ypboard(s,msg) 
{
	var cnt = s.length;
	if(isIE)
	{
		var doc = document.body.createTextRange(); 
		doc.moveToElementText(s);
		doc.select(); 
		doc.execCommand('copy');
		alert(msg);
	}
	else
	{

	}
}

function secession(url)
{
	if(confirm("탈퇴하시면 같은 아이디로는 가입하실수 없고 모든 정보가 사라집니다."))
	{
		location.href=url+'member/secession.php';
	}
}

function email_link_fun(url) 
{
	if(document.all)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	var f = document.test;


	http.open("GET", url, true);
	http.onreadystatechange = emailopen;
	http.send(null);
} 

function emailopen() 
{
	if (http.readyState == 4) {
		var textout = http.responseText;
		location.href = "mailto:"+textout;
	}
}

function siren_fun(url,wuser_id,nos)
{
	window.open(url+"bbs/siren.php?wuser_id="+wuser_id+"&no="+nos,"siren","menubar=no, scrollbars=no, toolbar=no, location=no, resizable=no");
}
function ax_get_submit(url,obj,fc)
{
	var va = "";
	cnt = obj.length;
	for(i=0;i<cnt;i++)
	{
		if(obj[i].title && !obj[i].value)
		{
			alert(obj[i].title);
			obj[i].focus();
			return false;
		}
		va += obj[i].name+"="+obj[i].value+"&";
	}
	if(document.all)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	http.open("GET", url+va, true);
	http.onreadystatechange = eval(fc);
	http.send(null);
	return false;
}
function ax_post_submit(url,obj,fc)
{
	var va = "";
	cnt = obj.length;
	for(i=0;i<cnt;i++)
	{
		if(obj[i].title && !obj[i].value)
		{
			alert(obj[i].title);
			obj[i].focus();
			return false;
		}
		va += obj[i].name+"="+obj[i].value+"&";
	}
	if(document.all)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	http.open("POST", url, true);
	http.onreadystatechange = eval(fc);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(va);
	return false;
}
function ax_post_submit2(url,va,fc) 
{
	if(document.all)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	http.open("POST", url, true);
	http.onreadystatechange = eval(fc);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(va);
	return false;
} 
function member_chat(url)
{
}

function ax_fun_g(url,open_fun) 
{
	if(document.all)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	http.open("GET", url, true);
	http.onreadystatechange = eval(open_fun);
	http.send(null);
} 
function chat_open() 
{
	if (http.readyState == 4) {
		var textout = http.responseText;
		if(textout=="no")
		{
			alert('회원님이 현재 접속중이지 않습니다.');return false;
		}
		else if(textout)
		{
			top.location.replace(textout);
		}
	}
}
