/*	[MHz.Utils.js]
 *  (c) 2006, 2007 MHZ. (http://www.mediamob.co.kr // http://www.openblog.com)
 *	reference >> prototype.js // scriptaculous.js
 *	Last Update : 2007.01.04
 *
 *	How to use ?
 *	---------------------------------------------------------------------------
 *	+ <script src="./lib/prototype/prototype.js" type="text/javascript"></script>
 *	section.001 need prototype lib.
 *	
 *	001. setChangeCssClass(ElementName, ElementClassName);
 *	002. getChangeCssClass(ElementName)
 *	003. removeCssClass(ElementName)
 *	004. getCookie(CookieName)
 *	005. setCookie(CookieValue, CookieName)
 *	006. getSizeOfWindow()
 *		+ return Array();
 *		+ var sixeWindow = getSizeOfWindow();
 *		+ sixeWindow[0] is "X" | sixeWindow[1] is "Y"
 *
 */
 
//<![CDATA[
/* Section.001 cssStyle */
function setChangeCssClass(objElement, objClassName)
{//set className
	var preClassName = Element.classNames($(objElement));
	Element.removeClassName($(objElement),preClassName);
	Element.addClassName($(objElement),objClassName);
}
function getChangeCssClass(objElement)
{//get className
	return Element.classNames($(objElement));
}
function removeCssClass(objElement)
{//remove class
	var preClassName = Element.classNames($(objElement));
	Element.removeClassName($(objElement),preClassName);	
}
/*--------------------------------------------------------------------------*/

/* Section.002 cookie */
function getCookie(s)
{//get cookieNmae//get cookie name of 's'	
	var tmp=document.cookie.split('; ');
	for (var i=0; i<tmp.length;i++)
	{
		var c_name = tmp[i].split('=');
		if (c_name[0]==s){return c_name[1];}
	}
	return false;
}
function setCookie(c,s)
{//set cookieName//set cookie name of 'c' in 's'
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+1);
	document.cookie = c+'='+s+';expires='+expireDate.toGMTString()+';path=/;domain='+window.location.hostname+';';
}
/*--------------------------------------------------------------------------*/

/* Section.003 windowSize */
function getSizeOfWindow()
{//return Array();
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) 
	{// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	var arrayPageSize = new Array(windowWidth,windowHeight);
	return arrayPageSize;
}
/*--------------------------------------------------------------------------*/

/* Section.004 removeHTML */
/*
	HOW TO //
	removeTags(source.value,['br','a']); // [¾È¿¡´Â ³²°Ü¾ß ÇÒ ³»¿ë ÅÂ±×³»¿ë]
*/
function isAlNum(ch){return ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(ch)==-1)?false:true;}

removeTags=function(str,myTags)
{
	var tags=['!--','!doctype','isindex','script','blockquote','style','input','plaintext','body','colgroup','fieldset','frameset','multicol','noframes','noscript','optgroup','textarea','basefont','acronym','address','caption','comment','listing','marquee','noembed','nolayer','bgsound','applet','button','center','iframe','ilayer','legend','nextid','object','option','select','server','spacer','strike','strong','keygen','blink','embed','label','layer','small','table','tbody','tfoot','thead','title','param','frame','abbr','area','cite','code','font','form','head','html','menu','nobr','ruby','samp','span','base','link','meta','bdo','big','del','dfn','dir','div','ins','kbd','map','pre','sub','sup','var','xmp','img','col','wbr','br','dd','dl','dt','em','h1','h2','h3','h4','h5','h6','li','ol','rb','rp','rt','td','th','tr','tt','ul','hr','a','b','i','p','q','s','u'];

	if(myTags)
	{
		for(var i=0;i<myTags.length;i++)
		{
			for(var j=0;j<tags.length;j++)
			{
				if(myTags[i]==tags[j])
				{
					tags.splice(j,1);
					break;
				}
			}
		}
	}

	for(var i=0;i<tags.length;i++)
	{
		str=removeTags.remove(str,tags[i]);
	}
	return str.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#8260;/g,"\/");
};

removeTags.remove=function(str,tag)
{
	var op,tp,cp,lt,gt,copy;op=0,lt="&lt;",gt="&gt;";
	str=str.replace(/</g,"&lt;");
	str=str.replace(/>/g,"&gt;");
	str=str.replace(/"/g,"");
	str=str.replace(/'/g,"");
	str=str.replace(/\//g,"&#8260;");
	copy=str;
	str=str.toLowerCase();
	
	while((op=str.indexOf(lt+tag,op))!=-1)
	{
		tp=str.substring(op+lt.length+tag.length,op+lt.length+tag.length+1)
		if(isAlNum(tp)) {op=op+lt.length+tag.length+1;continue;}
		if((cp=str.indexOf(lt+"&#8260;"+tag+gt,op))==-1)
		{
			tp=str.indexOf(gt,op);
			str=str.substring(0,op)+str.substring(tp+4,str.length);
			copy=copy.substring(0,op)+copy.substring(tp+4,copy.length);
		}
		else
		{
			if((tag=="script")||(tag=="style")||(tag=="object"))
			{
				tp=str.indexOf(gt,op);
				str=str.substring(0,op)+str.substring(cp+tag.length+9+6,str.length);
				copy=copy.substring(0,op)+copy.substring(cp+tag.length+9+6,copy.length);
			}
			else
			{
				tp=str.indexOf(gt,op);
				str=str.substring(0,op)+str.substring(tp+4,cp)+str.substring(cp+tag.length+9+6,str.length);
				copy=copy.substring(0,op)+copy.substring(tp+4,cp)+copy.substring(cp+tag.length+9+6,copy.length);				
			}
		}
	}
	return copy;
};
/*--------------------------------------------------------------------------*/
/* Section.005 clearText */
function clearTextBox(element, elementValue)
{
	if(element.value == elementValue){element.value = "";return;}
}

/*--------------------------------------------------------------------------*/
/* Section.006 TAG STRING VAIID */
//SPECIAL CODE VALID
function ValidTag(obj)
{	
	var valid = "/[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\!\,\.\/\?\>\<\:\;\"\'\-\]/";
	var temp;
	for(var i=0; i<obj.length; i++)
	{
		temp = "" + obj.substring(i, i+1);
		if(valid.indexOf(temp) != "-1"){return false;}
	}
	return true;
}
//BLANK CODE VALID
function VaildBlank(obj)
{
	if(obj.length > 0){if(obj.substring(0,1)==' '){return false;}else{return true;}}
	else{return false;}
}


/*--------------------------------------------------------------------------*/
/* Section.007 Window Opener  */

function OpenWin(url, name, width, height, features, replace)
{
	var popWidth = width;
	var popHeight = height;
	var popfeatures;
	
	if(navigator.appName.indexOf("Microsoft") != -1)
	{
		// IEÀÏ °æ¿ì
		var base = navigator.appVersion.indexOf('MSIE');
		var IEVer = navigator.appVersion.substring(base + 4, base + 8);	
		
		if(IEVer < 7.0)
		{
			// IE 6.0 ÀÌÇÏ
			popWidth = popWidth;
			popHeight = popHeight;
		}
		else
		{
			// IE 7.0 
			popWidth = popWidth;
			popHeight = popHeight + 10;
		}
	}
	else
	{
		// FireFoxµî ±âÅ¸ºê¶ó¿ìÁ®
		popWidth = popWidth;
		popHeight = popHeight;
	}
	
	popfeatures = features + ", width=" + popWidth +  ", height=" +popHeight;
	window.open(url, name, popfeatures, replace);
}

function MHzOpenV1Display(id)
{
    if(document.getElementById(id).style.display=='block')
        document.getElementById(id).style.display='none';
    else
        document.getElementById(id).style.display='block';
}
//]]>