function checkEmail(email) {
	
	var a = email.indexOf("@");

	email_account = email.substring(0,a);
	email_domain = email.substring(a+1);

	if(!checkEmailAccount(email_account))
	{
		return false;
	}
	if(!checkEmailDomain(email_domain))
	{
		return false;
	}

	return true;

}

function checkEmailAccount(email) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
	var t = email;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag
	var len = t.length;

	if ( t.length > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( SpecialFlag == false ) {
			BadFlag = false
			ValidFlag = true
		}

	}
	
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}

function checkEmailDomain(email) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.";
	var t = email;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag = true
	var len = t.length;
	
	if ( t.length > 0 && t.indexOf(".") > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )
			if ( atChr == "." ) atCount = atCount + 1

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( ( atCount > 0 ) && (SpecialFlag == false ) ) {


			BadFlag = false

			if ( t.substring( 1, 2 ) == "." ) BadFlag = true
			if ( t.substring( t.length-1, t.length) == "." ) BadFlag = true
			ValidFlag = true
		}
	}
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}

function checkDigitAlpha(id) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var t = id;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag = true
	var len = t.length;
	
	if ( t.length > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( SpecialFlag == false ) {


			BadFlag = false
			ValidFlag = true
		}
	}
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}


function checkDigit(id) {
	
	var comp="0123456789";

	if ( id.length > 0 ) {
		
		for(var i=0;i<id.length;i++ ) {
			
			if(comp.indexOf(id.substring(i,i+1))<0)
			{
				return false;
			}
		}
		
		return true;

	} else {
		
		return false;
	}
}


function checkNumber(field, totField)
{
  if(!checkDigit(field.value))
  {
    field.value = field.value.substring(0, field.value.length - 1);
  }
}

function checkjumin(jumin)
{
	if(jumin.length != 13)
	{
		return false;
	}
	else
	{
		a = new Array(6)
		b = new Array(7)
		tot=0
		c=0
		for(i=1;i<7;i++) 
		{
				a[i]=jumin.substring(i-1,i)
				b[i]=jumin.substring(5+i,6+i)
				if(i<3) 
				{
				c=Number(b[i])*(i+7)
				}
				else if(i>=3) 
				{
				c=Number(b[i])*((i+9)%10)
				}
				tot = tot + Number(a[i])*(i+1) + c
		}
		b[7]=jumin.substring(12,13)
		if(Number(b[7]) != ((11-(tot%11))%10)) 
		{
				return false;
		}
	}
	
	return true;
}

function optionSelected(id, val) {
  var someNodeList = $(id).getElementsByTagName('option');
  var nodes = $A(someNodeList);

  nodes.each(function(node){
    if(node.value == val) {
      node.selected = true;
    } else {
      node.selected = false;
    }
  });
}

function set_cookie( name, value, expiredays ) {
  var todayDate = new Date();
  todayDate.setDate( todayDate.getDate() + expiredays );
  document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function get_cookie(name) {
  var nameOfCookie = name + "=";
  var x = 0;
  while ( x <= document.cookie.length ) {
    var y = (x+nameOfCookie.length);
    if ( document.cookie.substring( x, y ) == nameOfCookie ) {
      if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
      endOfCookie = document.cookie.length;
      return unescape( document.cookie.substring( y, endOfCookie ) );
    }
    x = document.cookie.indexOf( " ", x ) + 1;
    if ( x == 0 )
      break;
  }
  return "";
}
