if ( ! Array.prototype.push ) {
	Array.prototype.push = function () {
		var l = this.length;
		for ( var i = 0; i < arguments.length; i++ ) {
			this[l+i] = arguments[i];
		}
		return this.length;
	}
}

function IsIE() {
	if( navigator.userAgent.indexOf("MSIE") == -1 ) {
		return false;
	}
	return true;
}

function list_over(t1, bool)
{
	var oTD = eval("document.all.m" + t1);
	var len = oTD.length;
	var borderStyle = "1 solid #b8d659";
	var borderStyle2 = "1 solid #ffffff";

	if (bool){
		for(var i =0; i < len ; i++){
			oTD[i].style.borderTop = borderStyle;
			oTD[i].style.borderBottom = borderStyle;
			oTD[i].style.cursor = "default";
		}
		oTD[0].style.borderLeft = borderStyle;
		oTD[len-1].style.borderRight = borderStyle;
	}else{
		for(var i =0; i < len ; i++){
			oTD[i].style.borderTop = borderStyle2;
			oTD[i].style.borderBottom = borderStyle2;
			oTD[i].style.cursor = "default";
		}
		oTD[0].style.borderLeft = borderStyle2;
		oTD[len-1].style.borderRight = borderStyle2;
	}
}

function change_check_box_status(obj,status) {
	if( obj.checked != null ) {
		obj.checked = status;
	} else {
		if( obj.length ){
			for( var i = 0; i< obj.length; i++ )
				obj[i].checked = status;
		}
	}
}

function SpamKeywordcheckall(formname,checkname,thestate){
	var el_collection=eval("document.forms."+formname+"."+checkname);
	if(el_collection != null)
	{
		if(el_collection.length){
			for (c=0;c<el_collection.length;c++)
				if(el_collection[c].disabled==false)
				el_collection[c].checked=thestate;
		}
		else{
			el_collection.checked=thestate;
		}
	}
}

flag=true;
function Display_tip(index , view, flag) {

	if(view == 'show'){
		if(flag) {
			if (navigator.userAgent.indexOf("MSIE") != -1) {
				document.getElementById('Tip' + index).style.display='';
				flag = false;
			}else {
				location.href = "";
			}
		} else {
			document.getElementById('Tip' + index).style.display='none';
			flag = true;
		}
	} else if(view == 'hide'){
		if (flag){
			document.getElementById('Tip' + index).style.display ='';
		}else{
			document.getElementById('Tip' + index).style.display = "none";
		}
	}
}

function showBoardList(index,bool){
	if (bool){
		document.getElementById('Tip' + index).style.display ='';
	}else{
		document.getElementById('Tip' + index).style.display = "none";
	}
}

function hideLayer(objname) {
	var obj = document.getElementById(objname);
	try {
		obj.style.display = "none";
	} catch(e) {
	}
}

function OpenWindow(p_sURL, p_sName, p_iTopMargin, p_iLefMargin, p_bScrollBars, p_bResizable, p_iWidth, p_iHeight) {
	l_sSpecialty = 'topmargin=' + p_iTopMargin;
	l_sSpecialty = l_sSpecialty + ', leftmargin=' + p_iLefMargin;
	l_sSpecialty = l_sSpecialty + ', scrollbars=' + p_bScrollBars;
	l_sSpecialty = l_sSpecialty + ', resizable=' + p_bResizable;
	l_sSpecialty = l_sSpecialty + ', width=' + p_iWidth;
	l_sSpecialty = l_sSpecialty + ', height=' + p_iHeight;

	return window.open(p_sURL, p_sName, l_sSpecialty);
}

function OpenWindowWithoutReturn(p_sURL, p_sName, p_iTopMargin, p_iLefMargin, p_bScrollBars, p_bResizable, p_iWidth, p_iHeight) {
	l_sSpecialty = 'topmargin=' + p_iTopMargin;
	l_sSpecialty = l_sSpecialty + ', leftmargin=' + p_iLefMargin;
	l_sSpecialty = l_sSpecialty + ', scrollbars=' + p_bScrollBars;
	l_sSpecialty = l_sSpecialty + ', resizable=' + p_bResizable;
	l_sSpecialty = l_sSpecialty + ', width=' + p_iWidth;
	l_sSpecialty = l_sSpecialty + ', height=' + p_iHeight;

	window.open(p_sURL, p_sName, l_sSpecialty);
}

function GetStringLength(p_str)
{
	var c;
	var l_sLength = 0;

	for(k = 0;k < p_str.length; k++) {
		c = p_str.charAt(k);
		if(escape(c).length > 4)
			l_sLength += 2;
		else
			l_sLength++;
	}
	return l_sLength;
}

var F_TYPE_NONE = 0;
var F_TYPE_ENG = 1;
var F_TYPE_NUM = 2;
var F_TYPE_EMAIL = 3;
var F_TYPE_ENG_NUM = 4;
var F_TYPE_ENG_NUM_UNDER = 5;
function CheckFormValidation(p_sFormVar, p_sFormName, p_iMaxLength, p_iFormType, p_bEssential, p_bMessage) {
	var l_iStringLength = GetStringLength(p_sFormVar.value)

	if ( p_bEssential ) {
		if( l_iStringLength == 0 ) {
			if (p_bMessage) {
				AlertPrompt( p_sFormVar, "Missing field(" + p_sFormName + ")");
			}
			return( false );
		}
		spacecount = 0;
		for( var i = 0; i < l_iStringLength; i++ ) {
			thisChar = p_sFormVar.value.charAt( i );
			if( thisChar == ' ' ) spacecount++;
		}
		if( spacecount == l_iStringLength ) {
			if (p_bMessage) {
				AlertPrompt( p_sFormVar, "Missing field(" + p_sFormName + ")");
			}
			return( false );
		}
	}

	if ( p_iMaxLength > 0 ) {
		if( l_iStringLength > p_iMaxLength ) {
			if (p_bMessage) {
				AlertPrompt( p_sFormVar, "Over the limit length(" + p_sFormName + ")")
			}
			return( false );
		}
	}

	switch (p_iFormType) {
		case 1 : // Only English
			var regEx = new RegExp("^[a-z]+$", "i");

			if ( regEx.test(p_sFormVar.value) )
			{
				return true;
			}
			else
			{
				if ( p_bMessage )
				{
					window.alert("You can input only english character(s)." + "\n\n" + "\"" + p_sFormVar.value + "\"");
				}
				p_sFormVar.focus();
				return false;
			}
			break;
		case 2 : // Number
			var regEx = new RegExp("^[0-9]+$", "i");

			if ( regEx.test(p_sFormVar.value) )
			{
				return true;
			}
			else
			{
				if ( p_bMessage )
				{
					window.alert("You can input only number." + "\n\n" + "\"" + p_sFormVar.value + "\"");
				}
				p_sFormVar.focus();
				return false;
			}
			break;
		case 3 : // Email
			if ( l_iStringLength > 0 ) {
				ret = checkEmailAddress(p_sFormVar.value, p_bMessage);
				if ( ! ret ) {
					p_sFormVar.focus();
					return false;
				}
			}
			break;
		case 4 : // English&Number
			var regEx = new RegExp("^[a-z0-9]+$", "i");

			if ( regEx.test(p_sFormVar.value) )
			{
				return true;
			}
			else
			{
				if ( p_bMessage )
				{
					window.alert("You can input only english character or number" + "\n\n" + "\"" + p_sFormVar.value + "\"");
				}
				p_sFormVar.focus();
				return false;
			}
			break;
		case 5 : // Engish&Number& _(underline)
			var regEx = new RegExp("^[a-z][a-z0-9_]*$", "i");

			if ( regEx.test(p_sFormVar.value) )
			{
				return true;
			}
			else
			{
				if ( p_bMessage )
				{
					window.alert("You can input only english character, number and underline." + "\n\n" + "\"" + p_sFormVar.value + "\"");
				}
				p_sFormVar.focus();
				return false;
			}
			break;
		default : // unlimmited.
			break;
	}
	return( true );
}

function AlertPrompt(p_Ctrl, p_sAlertMessage) {
    alert(p_sAlertMessage);
    p_Ctrl.focus();
    return;
}

function checkEmailAddress(p_sMailAddress, p_bMessage)
{
	var regEx = new RegExp("^([a-z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-z0-9_\\-]+\\.)+))([a-z]{2,4}|[0-9]{1,3})(\\]?)$", "i");

	if ( regEx.test(p_sMailAddress) )
	{
		return true;
	}
	else
	{
		if ( p_bMessage )
		{
			window.alert("Wrong e-mail address!!" + "\n\n" + "\"" + p_sMailAddress + "\"");
		}
		return false;
	}
}

function ResponseConfirm(p_sConfirmMessage, p_sURL) {
	if ( confirm(p_sConfirmMessage) ) {
		location.href = p_sURL;
	}
}

function noaction() {}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}
function getCookie2(Name1, Name2) {
	var l_sStr = getCookie(Name1);
	var search = Name2 + "="
	offset = l_sStr.indexOf(search)
	if (offset != -1) { // if exists
		offset += search.length
		// set index of beginning of value
		end = l_sStr.indexOf("&", offset)
		// set index of end of cookie value
		if (end == -1)
			end = l_sStr.length
		return unescape(l_sStr.substring(offset, end))
	}
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function delCookie(name)	{
	document.cookie = name + "=;expires=Fri, 31 Dec 1987 23:59:59 GMT;";
}
function CheckNull(elementName,message)
{
	if(IsNullString(elementName.value))
	{
		alert( "You must input field " + message);
		elementName.focus();
		return false;
	}
	else return true;
}

function IsNullString(string)
{
        for(var i=0; i<string.length; i++)
                if(string.charAt(i)!=' ' && string.charAt(i)!='\r' && string.charAt(i)!='\n'
			&& string.charAt(i)!='\t' && string.charAt(i)!='\b') return false;

        return true;
}

function IsPositiveInt(string)
{
	if(string=="") return false;
	else for(var i=0; i<string.length; i++) if(isNaN(parseInt(string.charAt(i)))) return false;

	return true;
}

function checkEmailAddressWithCheckbox (p_oCheckbox,p_oEmailBox)
{
  var l_sEmail

  l_sEmail =  p_oEmailBox.value;


  if (p_oCheckbox.checked) {
   	 if (checkEmailAddress(l_sEmail, true))
     {
		 return true;
  	 }
	 else
	 {
		 p_oEmailBox.focus();
  	  	 return false;
	 }
  }

  else
  {
	return true;
  }
}

function IsValidObject(p_oVal)
{
	if( p_oVal == undefined || typeof(p_oVal) == undefined )
		return false;
	return true;
}

function IsValidString(p_sVal)
{
	if( IsValidObject(p_sVal) == false )
		return false;

	if( p_sVal == null || p_sVal == "")
		return false;

	return true;
}

function MakeOptionTag( p_sPrev, p_sText, p_sValue, p_sSelValue)
{
	var l_sResult = "";
	if( IsValidString(p_sValue) == false )
		p_sValue = "";

	if( IsValidString(p_sSelValue) == false )
		p_sSelValue = "";

	if( String(p_sValue) == String(p_sSelValue) )
		l_sResult = p_sPrev + "<option value=\"" + p_sValue + "\" selected>" + p_sText + "</option>";
	else
		l_sResult = p_sPrev + "<option value=\"" + p_sValue + "\">" + p_sText + "</option>";

	return l_sResult;
}

function Space_All(str)
{
	var index, len
	while(true)
	{
		index = str.indexOf(" ")
		if (index == -1) break
		len = str.length
		str = str.substring(0, index) + str.substring((index+1),len);
	}
	return str;
}

function Trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function LeftTrim(str)
{
	return str.replace(/^\s+/,"");
}

function RightTrim(str)
{
	return str.replace(/\s+$/,"");
}

function encodeURI(strVal)
{
	if(encodeURIComponent){
	    return encodeURIComponent(strVal);
	}
	if(escape){
	    return escape(strVal);
	}
}

function insertAddrbook(name, email){
	//OpenWindowWithoutReturn('http://addrbook.daum.net/plus/web.do?command=insertAddr&name='+encodeURIComponent(name)+'&email='+encodeURIComponent(email), 'spam_ip_block', 0, 0, 'no', 'no', 600, 680);
	OpenWindowWithoutReturn('/lycos/addrbook/CreateAddr.lycos?ptype=popup_insert&command=insertAddr&name='+encodeURIComponent(name)+'&email='+encodeURIComponent(email), 'spam_ip_block', 0, 0, 'no', 'no', 525, 650);
}

function OpenAddrbook2()
{
	OpenWindowWithoutReturn('/lycos/addrbook/GetAddrBook.lycos', 'addr_pop', 0, 0, 'yes', 'yes', 640, 650);
}

function OpenDeleteGroup(grpseq)
{
	OpenWindowWithoutReturn('/lycos/addrbook/DeleteGroup.lycos?grpseq='+grpseq, 'deleteGroup_pop', 0, 0, 'no', 'no', 400, 140);
}

function OpenDeleteAddr(addrseq,grpseq)
{
	OpenWindowWithoutReturn('/lycos/addrbook/DeleteAddr.lycos?addrseqlist='+addrseq +'&grpseq='+grpseq, 'deleteGroup_pop', 0, 0, 'no', 'no', 400, 140);
}


function underconstruction() {
		alert('Underconstruction');
}

function getUTF8(src_str) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<src_str.length) {
    c= src_str.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=src_str.length) continue;
      s= src_str.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponent2(inpram) {
  var s = getUTF8(inpram);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}
function paramEncode( inparam){
	if(typeof encodeURIComponent == "function" ){
	    return encodeURIComponent(inparam);
	} else{
          return encodeURIComponent2(inparam);
    }
}

function existsNonValidChars(p_sTestString, p_bMessage) {	
	var regEx = new RegExp("[@#$%^&*?|\\x5c]", "ig");	
	
	if ( regEx.test(p_sTestString) )
	{
		 r = p_sTestString.match(regEx);			
		if( p_bMessage ) {
			alert( "Cannot use special characters(@#$%^&*?|\\).");
		}
		return true;
	}
	else
	{		
		return false;
	}	

}

function PreventSubmitOnEnter()
{
    if(event.keyCode==13)
    {
        return false;
    }
}
function skipEnter()
{
    var inputs = document.getElementsByTagName("INPUT")         
    for(var i = 0; i < inputs.length ; i++)
    {               
        if(inputs[i].type == "text")
        {           
            inputs[i].attachEvent("onkeypress", PreventSubmitOnEnter);      
        }
    }
}

function getAdvHeight() {
    var h=0;
    if (navigator.userAgent.indexOf("SV1") > 0){  h=14; }
    else if(navigator.userAgent.indexOf("MSIE 7")>0) { h=45; }
    else if(navigator.userAgent.indexOf("Gecko")>0 && navigator.userAgent.indexOf("Firefox") <= 0 && navigator.userAgent.indexOf("Netscape") <= 0 ){ h=22; }
    else if(navigator.userAgent.indexOf("Firefox") >0 ){  h=18; } 
    else if(navigator.userAgent.indexOf("Netscape") >0 ){ h=-2; }
    else { h=0;} 

    return h;
}
// Browser Detect Javascript
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
