﻿//필드 유효성 검사(숫자)
function NumField()
{
    if ((event.keyCode < 48) || (event.keyCode > 57)) {
        event.returnValue = false;
    }
}

//string trim functions
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function MoveFocus(objFrom, objTo)
{
	if (objFrom == null || objTo == null) return;
	
    if ( objFrom.value.length >= objFrom.getAttribute("maxlength") && event.keyCode >= 48 && event.keyCode <= 57 )
    {
        objTo.focus();
    }
}

function chkRegnum(val1,val2){
	if (!(val1) || !(val2))
	{   
	    return false;
	}
	
	var  j=9;
	var  id_chk=0;
	tmp = false;
	var str=val1+val2;
	if(str.length!=0){
	   object =  new Array(13)
	   for(var i=0;i < 13;i++) {
	           object[i] = str.substring(i,i+1)
	   }
	   var chkdigit = str.substring(12, 13);
	   for(var i=0;i < 12;i++){
	   	if( i == 8 )
	        j = 9;
	        object[i]=object[i]*j;
	        j--;
	        id_chk +=object[i];
	   }
	   if(((id_chk%11 == 0) && (chkdigit == 1)) || ((id_chk%11 ==10)&& (chkdigit ==0)));
	   
	   else if((id_chk %11 != 0) && (id_chk % 11 != 10 ) && (id_chk % 11 == chkdigit));
	   
	   else{
	        return false;
	   }
	}

	return true;	
}

/*
	Password Validator 0.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
	
	Downloaded at http://blog.stevenlevithan.com/archives/javascript-password-validator
*/
function validatePassword (pw, options) {
	// default options (allows any password)
	var o = {
		lower:    0,
		upper:    0,
		alpha:    0, /* lower + upper */
		numeric:  0,
		special:  0,
		length:   [0, Infinity],
		custom:   [ /* regexes and/or functions */ ],
		badWords: [],
		badSequenceLength: 0,
		noQwertySequences: false,
		noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (pw.length < o.length[0] || pw.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((pw.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce word ban (case insensitive)
	for (i = 0; i < o.badWords.length; i++) {
		if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
			return false;
	}

	// enforce the no sequential, identical characters rule
	if (o.noSequential && /([\S\s])\1/.test(pw))
		return false;

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + pw.slice(0, start);
		for (i = start; i < pw.length; i++) {
			seq = seq.slice(1) + pw.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}

	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(pw))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(pw))
				return false;
		}
	}

	// great success!
	return true;
}

function checkDupID(szObjName)
{
    window.open('FindIDFrm.aspx?objname='+szObjName,'findid','scrollbars=no,width=360,height=310,top=200,left=200');
}

function checkExistID(szObjName)
{
    window.open('FindExistIDFrm.aspx?objname='+szObjName,'findexistid','scrollbars=no,width=360,height=280,top=200,left=200');
}

function findSchool(szFormName, szObjName1, szObjName2)
{
    window.open("/tss/common/SchoolSearch.aspx?frm="+szFormName+"&name="+szObjName1+"&idx="+szObjName2, 'schoolsearch', 'toolbar=no, menubar=no, scrollbars=no, width=517,height=450');
}

function findAddress(szFormName)
{
    window.open("/Tss/Common/ZipCodeSearch.aspx?formId="+szFormName, 'zipsearch', 'toolbar=no, menubar=no, scrollbars=no, width=517,height=450');
}

function requestAddSchool()
{
    window.open("http://support.studymania.com/tss/support/ContactOneToOne.aspx", "schooladdrequest", "");
}