// iframe 자동 리사이징
var NS4;
var IE4;
if (document.all)
{
    IE4 = true;
    NS4 = false;
}
else
{
    IE4 = false;
    NS4 = true;
}

// == Iframe Handling ==
// iframe resize시 최소 width, height
var frmMinWidth;
var frmMinHeight;
var applyMinSize = false;
// iframe resize시 최대 width, height
var frmMaxWidth;
var frmMaxHeight;
var applyMaxSize = false;

function resizeIframe(name)
{
    if (name == null || name == "")
    {
        name = "cafe_main";
    }

    try
    {
        if (IE4)
            var oBody   = document.frames(name).document.body;
        else
            var oBody = document.getElementById(name).contentDocument.body;
            
        var oIFrame = document.getElementById(name);

        var frmWidth  = oBody.scrollWidth;
        var frmHeight = oBody.scrollHeight;

        if (applyMinSize)
        {
            frmWidth  = Math.max(frmWidth, frmMinWidth);
            frmHeight = Math.max(frmHeight, frmMinHeight);
        }
        if (applyMaxSize)
        {
            frmWidth  = Math.min(frmWidth, frmMaxWidth);
            frmHeight = Math.min(frmHeight, frmMaxHeight);
        }

//        if (oIFrame.src.indexOf("BoardList.do")>0&&frmWidth>600)
//        {
//            frmWidth = 600;
//        }

        oIFrame.style.height = frmHeight;
        oIFrame.style.width = frmWidth;
    }
    catch (e) {}
}

function parentResizeIframe(name)
{
    if (parent && parent != this && parent.resizeIframe != null)
    {
        parent.resizeIframe(name);
    }
}

function resizePage(name) 
{
	self.setTimeout("parentResizeIframe('" + name + "')",50);
}

function evalChk(form){
   if (AutoValidate(form) == false) 
   {
        return false ;
   }
   else{
	    return true;
   }
}

function showDiv1(event, divId, offsetX, offsetY){
	if(document.getElementById(divId).style.display=="none"){
		document.getElementById(divId).style.display="";
		document.getElementById(divId).style.visibility="visible";
		document.getElementById(divId).style.left=event.clientX+offsetX;
		document.getElementById(divId).style.top=event.clientY+offsetY;
		return false;
	}
	if(document.getElementById(divId).style.display==""){
		document.getElementById(divId).style.display="none";
		document.getElementById(divId).style.visibility="hidden";
		return false;
	}
}

function showDiv2(event, divId, offsetX, offsetY){
	if(document.getElementById(divId).style.display=="none"){
		document.getElementById(divId).style.display="";
		document.getElementById(divId).style.visibility="visible";
		//document.getElementById(divId).style.left = offsetX;
		document.getElementById(divId).style.top= offsetY;
		return false;
	}
	if(document.getElementById(divId).style.display==""){
		document.getElementById(divId).style.display="none";
		document.getElementById(divId).style.visibility="hidden";
		return false;
	}
}

function showDiv3(divId){
	if(document.getElementById(divId).style.display=="none"){
		document.getElementById(divId).style.display="";
		document.getElementById(divId).style.visibility="visible";
		return false;
	}
	if(document.getElementById(divId).style.display==""){
		document.getElementById(divId).style.display="none";
		document.getElementById(divId).style.visibility="hidden";
		return false;
	}
}

function hiddenDiv(event, divId){
	if(document.getElementById(divId) != null){
		document.getElementById(divId).style.display="none";
		document.getElementById(divId).style.visibility="hidden";
	}
	return false;
}

//사용법 : onblur='length_check(this,100,'주민번호 입력길이 오류')'
function length_check (form_name,db_length,alert_msg)
{
    var formvar = form_name.value;
	var tcnt = 0;
	for(var i = 0; i < form_name.value.length; i++)
	{
		var chr = form_name.value.substr(i,1);
		if( chr > '~' || chr < unescape("%00"))	{
			tcnt = tcnt + 2;
		}
		else if (chr == unescape("%27") || chr == unescape("%22") )	{
		/*따옴표,쌍따옴표*/
			tcnt = tcnt + 2;
		}
		else if (chr == unescape("%5C")) {
		/*백슬래쉬*/
			tcnt = tcnt ;
		}
		else {
			tcnt = tcnt + 1;
		}
	}
	if ( tcnt > db_length ) {
		window.alert(alert_msg);
		form_name.focus();
		return 0;
	}
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function chkByte(objname,maxlength) { 
 var objstr = objname.value; // 입력된 문자열을 담을 변수 
 var objstrlen = objstr.length; // 전체길이 

 // 변수초기화 
 var maxlen = maxlength; // 제한할 글자수 최대크기 
 var i = 0; // for문에 사용 
 var bytesize = 0; // 바이트크기 
 var strlen = 0; // 입력된 문자열의 크기
 var onechar = ""; // char단위로 추출시 필요한 변수 
 var objstr2 = ""; // 허용된 글자수까지만 포함한 최종문자열

 // 입력된 문자열의 총바이트수 구하기
 for(i=0; i< objstrlen; i++) { 
  // 한글자추출 
  onechar = objstr.charAt(i); 
  
  if (escape(onechar).length > 4) { 
   bytesize += 2;     // 한글이면 2를 더한다. 
  } else {  
   bytesize++;      // 그밗의 경우는 1을 더한다.
  } 
  
  if(bytesize <= maxlen)  {   // 전체 크기가 maxlen를 넘지않으면 
   strlen = i + 1;     // 1씩 증가
  }
 }

 // 총바이트수가 허용된 문자열의 최대값을 초과하면 
 if(bytesize > maxlen) { 
  alert( "허용된 문자열의 최대값을 초과했습니다. \n초과된 내용은 자동으로 삭제 됩니다."); 
  objstr2 = objstr.substr(0, strlen); 
  objname.value = objstr2; 
 } 
 objname.focus(); 
} 

//팝업
function PopUpWindowOpen(surl, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open(surl, "PopUpWindow", Future);
	PopUpWindow.focus();
}

function PopUpWindowOpenMovie(surl, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open("/admin/player/player_ucc.jsp?link=" + surl, "PopUpWindow", Future);
	PopUpWindow.focus();
}


function PopUpWindowOpenPost(surl, windowName, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open(surl, windowName, Future);
	PopUpWindow.focus();
}

function PopUpWindowOpenScroll(surl, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open(surl, "PopUpWindow", Future);
	PopUpWindow.focus();
}

$(function() {
	// 이미지 소스를 간단히 변경하기
	$.fn.replaceImage = function(str_before, str_after) {
		//alert($(this).attr("src"));
		$(this).attr("src", $(this).attr("src").replace(str_before, str_after));
		return this;
	};
	// 구 사이트 이미지 소스를 일괄 변경
	try {
		var old_image = $("img[src^='http://www.medison.com']");
		if (old_image.length > 0) {
			$(old_image).each(function(index, element) {
				$(element).replaceImage("http://www.medison.com", "http://www.samsungmedison.com");
			});
		}
	} catch(err) {
		//
	}
})

