﻿function strReplace(src, find, repl)
{
   strLength = src.length;
   newstr = "";
   for (i = 0; i < strLength; i++)
   {
      if (src.charAt(i) == find)
         newstr = newstr + repl;
      else
         newstr = newstr + src.charAt(i);
   }
   
   return newstr;
}

function checkArr(obj)
{
   var count = 0;
   
   for (i = 0; i < obj.length; i++)
	   if (obj[i].checked) count++;  
	
	return count;
}

function getLen(obj)
{
   var objvalue;
   
   objvalue = strReplace(obj, " ", "");
	objvalue = strReplace(objvalue, String.fromCharCode(13), "");
	objvalue = strReplace(objvalue, String.fromCharCode(10), "");
	
	return objvalue.length;
}

function checkValidate(obj, errmsg)
{
   var objvalue;
	
	if (obj.type == "text" || obj.type == "select-one" || obj.type == "password" || obj.type == "textarea")
	{
		if (getLen(obj.value) == 0)
		{
			if (errmsg.length > 0) alert(errmsg);
			obj.focus();
			return false;
		}
	}
	else
	{
		var count = 0;
		
		count = checkArr(obj);
		
		if (count == 0) 
		{
			if (errmsg.length > 0) alert(errmsg);
			obj[0].focus();
			return false;
		}
	}
	
	return true;
}

function clickSearchAdd()
{
	win = window.open("search_pup.html", "우편번호찾기", "width=450,height=150");
}

function validateEmail(email) {
  var err=0
  invalidChars = " /:,;"
  if (email == "") {
    return(0);
  }
  else {
    for (i=0; i<invalidChars.length; i++) {
      badChar = invalidChars.charAt(i)
      if (email.indexOf(badChar,0) != -1) {
        err=1;
        break;
      }
    }

    if (!err)
    {
      atPos = email.indexOf("@",1)
      if (atPos == -1) {
        err=1;
      }
      else {
        if (email.indexOf("@",atPos+1) != -1) {
          err=1;
        }
        else {
          periodPos = email.indexOf(".",atPos)
          if (periodPos == -1) {
            err=1;
          }
          else {
            if (periodPos+3 > email.length)
            {
              err=1;
            }
          }
        }
      }
    }
  }
  if (err==1){
    return(1)
  }
  return(0)
}
