//=================================
// Title : Javascript functions
// Date : 7/12/2005 3:25PM
// Writer : SooNa, Eun
//=================================

//======================================================
// reading cookies
//======================================================
function getCookie(name)
{
	var Found = false;
	var start, end;
	var i = 0;

 	while (i <= document.cookie.length)
 	{
		start = i;
		end = start + name.length;

 		if (document.cookie.substring(start, end) == name)
 		{
 			Found = true;
 			break;
 		}
 		i++
	}
	
	if (Found == true)
 	{
 		start = end + 1;
 		end = document.cookie.indexOf(";", start);

        if (end < start)
        	end = document.cookie.length;

        return document.cookie.substring(start, end);
    }

    return ""
}


//======================================================
// File Check up
//======================================================
function isJPGFile( fileName ) {
    var fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
    fileSuffix = fileSuffix.toLowerCase();

	var FileOK = false;
    FileArray=new Array(0);
    
    FileArray[0] = "jpg";
    
	for (i=0; i<=0; i++) {
		if (FileArray[i] == fileSuffix) {
			FileOK = true;
			break;
		}
	}        
	
	return FileOK;      
}

function isFile( fileName ) {
    var fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
    fileSuffix = fileSuffix.toLowerCase();

	var FileOK = false;
    FileArray=new Array(1);
    
    FileArray[0] = "jpg";
    FileArray[1] = "gif";        
    
	for (i=0; i<=1; i++) {
		if (FileArray[i] == fileSuffix) {
			FileOK = true;
			break;
		}
	}        
	
	return FileOK;      
}

function strLengthByte(str)
{
	var totLength = 0;
	for (var i=0;i<str.length;i++)
		totLength += strCharByte(escape(str.charAt(i)));
	return totLength;
}

function strCharByte(chStr) {
	if (chStr.substring(0, 2) == '%u')
	{
		if (chStr.substring(2,4) == '00')
			return 1;
		else
			return 2;
	}
	else if (chStr.substring(0,1) == '%')
	{
		if (parseInt(chStr.substring(1,3), 16) > 127)
			return 2;
		else
			return 1;
	}
	else
		return 1;
}

//======================================================
// checking board
//======================================================

function bbs_validate(form) {
if (form.writer.value=="")  {alert("\nPlease, Enter Your name."); form.writer.focus(); return false;}
if (form.email.value != "") {
	var atPos = form.email.value.indexOf('@');
	if (atPos < 1 || atPos == (form.email.value.length - 1))	{
		alert("\nYour email address is not valid.\nPlease, Check your email address."); form.email.focus(); return false;
	}

	var pointPos = form.email.value.indexOf('.');
	if (pointPos < 1 || pointPos == (form.email.value.length - 1))	{
		alert("\Your email address is not valid.\nPlease, Check your email address."); form.email.focus(); return false;
	}

}
if (form.subject.value=="") {alert("\nPlease, Enter a subject."); form.subject.focus(); return false;}
if (form.content.value=="") {alert("\nPlease, Enter a cotent."); form.content.focus(); return false;}
if (form.passwd.value=="")  {alert("\nPlease, Enter a password"); form.passwd.focus(); return false;}
if (form.passwd.value.length > 8 ) {alert("\The maximum of the password is 8 letters."); form.passwd.focus(); return false;}
if (isAlphaNum(form.passwd.value) == false ) {alert("Your password isn\'t valid(only alphabets, digits)"); form.passwd.focus(); return false;}
    
return true;
}

function bbs_del_validate(form) {

	if (form.passwd.value == '' )	{
		alert ("Please, Enter a password.");
		form.passwd.focus();
		return false;
	}
	
	return true;

}

//English & Number
function isAlphaNum( inStr ) {

  if (inStr.length > 0) { 
  
    for (i=0; i < inStr.length; i++) {

	if (!((inStr.charAt(i) >= 'a' && inStr.charAt(i) <= 'z') || (inStr.charAt(i) >= 'A' && inStr.charAt(i) <= 'Z') || (inStr.charAt(i) >= '0' && inStr.charAt(i) <= '9')) ) {
	return false;

	}
	
    }
    
    return true;
  }
  else { return false; }		    
}	

function isFloat( rNumber ) {

   var strlen = rNumber.length;
   var strVal = rNumber;
   var validChar = '0123456789.'; 
   var strDotCnt = 0;

   for (var j = 0; j < strlen; j++ ) {                                    
	if (validChar.indexOf(strVal.charAt(j)) < 0) {
		return false;	
	}
	if (strVal.charAt(j) == ".") {
		strDotCnt = strDotCnt + 1;
	}	
   }	    
   if (strDotCnt>1) {
   	return false;
   }
   else {
   	return true;	
   }	
 } 
 
//Number
function isNum( inStr ) {

  if (inStr.length > 0) { 

  for (i=0; i < inStr.length; i++) {

    if (!(inStr.charAt(i) >= '0' && inStr.charAt(i) <= '9')) {
    return false; 
    }
	
  }
  
  return true;
}
else { return false; }		    
}

//ÀÌ¸áÀÇ À¯È¿¼º Ã¼Å©
function isEmail(inStr){
var chkcnt;
chkcnt = 0;
	if (inStr.length > 0) {
	    for(i=0; i<inStr.length; i++){	    
	       if(inStr.charAt(i)=='@') {
	       	chkcnt = chkcnt+1
	       }
	       if(inStr.charAt(i)=='.') {
	       	chkcnt = chkcnt+1
	       }   
	       
	       if ((inStr.charAt(i)==',') || (inStr.charAt(i)=='!') || (inStr.charAt(i)=='*') || (inStr.charAt(i)=='$') || (inStr.charAt(i)=='%') || (inStr.charAt(i)=='^') || (inStr.charAt(i)=='&') || (inStr.charAt(i)=='`') || (inStr.charAt(i)=='#')) {
	       	chkcnt = chkcnt-1	       	
	       }	
	    }   
	    
	    if ((chkcnt == 2) || (chkcnt == 3)) {
	    	
				if (inStr.indexOf(" ") != -1) {
					return false;
				} 
					
				if (inStr.indexOf("@") < 1) {
					return false; 
				} 
				if (inStr.indexOf(".") == -1) {
					return false;
				}	
				if (inStr.indexOf(".") - inStr.indexOf("@") == 1) {
					//alert("'@' ´ÙÀ½¿¡ ¹Ù·Î '.'ÀÌ ¿Ã¼ö ¾ø½À´Ï´Ù."); 
					return false;
				}	
				if (inStr.charAt(inStr.length-1) == '.') {
					//alert("'.'Àº EmailÁÖ¼Ò ³¡¿¡ ¿Ã ¼ö ¾ø½À´Ï´Ù."); 
					return false;
				}
				if (inStr.charAt(inStr.length-1) == '@') {
					//alert("'@'Àº EmailÁÖ¼Ò ³¡¿¡ ¿Ã ¼ö ¾ø½À´Ï´Ù."); 
					return false;
				} 			
				for(i=0;i<inStr.length;i++) {
					c = inStr.charAt(i);
					if((c < '0' || c > '9')&&(c < 'a' || c > 'z')&&(c < 'A' || c > 'Z')&&(c != '.')&&(c != '-')&&(c != '_')&&(c != '@')) {
						//alert("E-mailÀº ¿µ¾î, ¼ýÀÚ, '-', '_', '.'¸¸ °¡´É ÇÕ´Ï´Ù.");
						return false;
					}
				}		
			//ÀÌ¸ÞÀÏ °Ë»ç ³¡	    	
	    	return true;    
	    }
	    else {
	    	return false;
	    }
	}
	
	else { 
		return false; 
	}
}

function CheckEmail(inStr)
{
	var Bool = false;
	var i, ch;
	
	if (inStr.length > 0) {	
		for (i=0; i< inStr.length; i++)
		{
			ch = inStr.charAt(i);
			if (ch == "@")
			{
	      		Bool = true; 
	      		break;
	   		}
		}
		if (Bool == false) {
			return false;
		}	
		Bool = false;
	
		for (i=0; i< inStr.length; i++)
		{
			ch = inStr.charAt(i);
			if (ch == ".")
			{
	      		Bool = true; 
	      		break;
	      	}
		}
		if (Bool == false) {
			return false;
		}	
		return true;	
	}	
	else {
		return false;	
	}	
}

//======================================================
// printing
//======================================================

function MakeWinPrint(temp)
{
    window.open(temp, 'MakeWinPrint', 'width=677,height=500,scrollbars=1');  
}

//======================================================
// roll & over
//======================================================

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//======================================================
// new windows
//======================================================
function opensh(urlc,wsize,hsize,scroll,resize){

e4 = (document.all) ? 1 : 0;

   shwin = window.open(urlc,"INIT","width="+wsize+","+"height="+hsize+",resizable="+resize+","+"status=0,menubar=0,scrollbars="+scroll+","+"left=20,top=10");
   if(shwin && (shwin.opener == null)) shwin.opener=window;
   if(!e4) shwin.focus();
   	
}   

function MM_openBrWindow(theURL,winName,features) {
	
	window.open(theURL,winName,features);
	
}

