function fnPage(iPage)
{
	var obj = document.form1;
	
	obj.method = "get";
	obj.action = document.location.pathname;
	
	obj["srh[page]"].value = iPage;
	obj.submit();
}

function fnEmail(obj, objSelect, szEmail)
{
	obj[szEmail].value = objSelect.value;
	
	if(obj[szEmail].value == "") obj[szEmail].focus();
}

function fnSearchZip(objForm, szDong, select_name, idAddr1, idAddr2)
{
	if(objForm[szDong].value == "" || objForm[szDong].value == objForm[szDong].getAttribute("ovalue")){
		alert(objForm[szDong].getAttribute("ovalue"));
		objForm[szDong].value = "";
		objForm[szDong].focus();
		return;
	}
	
	if(document.ajaxHTTP){
		if(document.ajaxHTTP.readyState != 0){
			document.ajaxHTTP.abort();
		}
	}else{
		document.ajaxHTTP = zXmlHttp.createRequest();
	}
	
	document.ajaxHTTP.open("get","/lib/ajax.html?q_action=zip&q_dong=" + objForm[szDong].value,true);

	document.ajaxHTTP.onreadystatechange = function()
	{
		if(document.ajaxHTTP.readyState == 4){
			if(document.ajaxHTTP.status == 200){
				var aAjax = eval("(" + document.ajaxHTTP.responseText + ")");
				
				for(i=0;i<aAjax["info"].length;i++){
					var opt = new Option(aAjax["info"][i].sido+" "+aAjax["info"][i].gugun+" "+aAjax["info"][i].dong+" "+aAjax["info"][i].note1+" "+aAjax["info"][i].note2, aAjax["info"][i].zipcodeno);
					objForm[select_name].add(opt);
				}
				
				document.getElementById(idAddr1).style.display = "";
				document.getElementById(idAddr2).style.display = "none";
			}
		}
	}

	document.ajaxHTTP.send(null);
}

function fnSelectZip(objForm, objSelect, szZip, szAddr1, szAddr2, idAddr1, idAddr2)
{
	if(objSelect.selectedIndex == 0){
		objForm[szZip].value = "";
		objForm[szAddr1].value = "";
		objForm[szAddr2].value = "";
	}else{
		objForm[szZip].value = objSelect.value;
		objForm[szAddr1].value = objSelect[objSelect.selectedIndex].text;
	}
	
	document.getElementById(idAddr1).style.display = "none";
	document.getElementById(idAddr2).style.display = "";
}

function fnBatchImageResize(szLimitText, limitImageSize)
{
	for(var i=0; i <document.images.length;i++){
		if(document.images[i].src.indexOf(szLimitText) != -1){
			if(document.images[i].width > limitImageSize) document.images[i].width = limitImageSize;
		}
	}
}

function fnCopyFromObject(obj)
{
	if (window.clipboardData) {
  		window.clipboardData.setData("Text", obj.value);
 	} else if (window.netscape) {
  		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  		if (!clip) return;
  		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  		if (!trans) return;
  		trans.addDataFlavor('text/unicode');
  		var str = new Object();
  		var len = new Object();
  		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  		str.data = obj.value;
  		trans.setTransferData("text/unicode",str,obj.value.length*2);
  		var clipid = Components.interfaces.nsIClipboard;
  		if (!clipid) return false;
  		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù.¿øÇÏ´Â °÷¿¡ Ctrl-V¸¦ ÀÌ¿ëÇÏ¿© ºÙ¿© ³Ö±â¸¦ ÇÏ½Ã¸é µË´Ï´Ù.");
	//obj = _F("frmForm2");
	/*if(obj["rdo"][0].checked){
		window.open("http://www.naver.net");
	}else if(obj["rdo"][1].checked){
		window.open("http://www.daum.com");
	}
*/
	return;
}

function fnTop()
{
	window.scrollTo(0, 0);
}

function uploadFile(type)
{
    var wnd = open("/include/upload.php?q_type="+type, 'wndUploadFile', 'width=360px, height=200px');
    if (wnd) wnd.focus();
}

// =====================================================================
// Trim
// =====================================================================
function fnTrim(str){
   str = str.replace(/^\s*/,'').replace(/\s*$/, '');
   return str;
}


function fnLogin()
{
	if(!confirm("·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?")) return;
	
	var objForm = document.createElement("FORM");
	objForm.setAttribute("name", "frmLogin");
	objForm.setAttribute("method", "get");
	objForm.setAttribute("action", "/user/login.html");
	
	var objInput = document.createElement("INPUT");
	objInput.setAttribute("type", "hidden");
	objInput.setAttribute("name", "q_url");
	objInput.setAttribute("value", login_url);
	
	
	objForm.appendChild(objInput);
	document.body.appendChild(objForm);
	
	objForm.submit();
}


function setCookie( name, value, expiredays ) 
{ 
	var todayDate = new Date(); 
	todayDate.setDate( todayDate.getDate() + expiredays ); 
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
}


function ReadCookie(name) {
	var label = name + "=" ;
	var labelLen = label.length ;
	var cLen = document.cookie.length
	var i = 0;
	while (i < cLen){
		var j = i + labelLen
		if (document.cookie.substring(i,j) == label) {
			var cEnd = document.cookie.indexOf(";",j)
			if (cEnd == -1){
			cEnd = document.cookie.length
			}
			return unescape(document.cookie.substring(j,cEnd))
		}
		i++
	}
	return ""
}


function fnGetByteLen(str) {
    var ibyte = 0;

    for (var i = 0; i < str.length; i++) {
        var tmp = escape(str.charAt(i));
        if (tmp.length == 1) ibyte++;
        else if (tmp.indexOf("%u") != -1) ibyte += 2;
        else if (tmp.indexOf("%") != -1) ibyte += tmp.length/3;
    }

    return ibyte;
}

function fnEmailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    //alert("The username doesn't seem to be valid.")
	    return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
	 for (var i=1;i<=4;i++) {
	   if (IPArray[i]>255) {
	       //alert("Destination IP address is invalid!")
	return false
	   }
	    }
	    return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
	    return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
