/////////////////////////// riss2.0 common function///////////////////////////////////
if(typeof Prototype=='undefined'){
		document.write('<script type="text/javascript" src="/commons/js/prototype.js"><\/script>');
}
/* value check */
var FormValueCheck={
	message: "빈값을 채우세요",
	valueCheck: function(formObj,returnResultArrayFlag,msg){
					if(msg!='undefined' || msg!='')
						this.message=msg;
					var result=new Array();
					var form=$(formObj);
					Form.getElements(formObj).each(function(element){
						if(element.getAttribute('notNull')=='Y'){
							var attr=element.getAttribute('type');
							if(attr=='radio'){
								result=FormValueCheck.checkRadioInputVal(element,result);
							}else{
								if(element.value=='' || element.value=='undefined'){
									result.push(element.name);
								}
							}
						}
					});
					if(returnResultArrayFlag==true){
						return result;
					}else{
						if(result.length>0){
							alert(this.message);
							return false;
						}else{
							return true;
						}
					}
	},
	//checkRadioInputVal: function(obj,result){
	//	var radioObj=document.getElementsByName(obj.name);
	//	if(this.temp_value=='' || this.temp_value!=obj.name){
	//		if(this.radio_check(radioObj)==false){
	//			result.push(obj.name);
	//		}
	//	}
	//	this.temp_value=obj.name;
	//	return result;
	//},
	checkRadioInputVal: function(obj,result){
		var radioObj=document.getElementsByName(obj.name);
		if(this.radio_check(radioObj)==false){
			result.push(obj.name);
		}
		return result;
	},
	radio_check: function(obj){
		var len=obj.length
		for(i=0;i<len;i++){
			if(obj[i].checked){
				return true;
			}
		}
		return false;
	}
};
var ModalPopup={
	bgDiv: document.createElement('div'),
	contentDiv: document.createElement('div'),
//	cLeft: Prototype.Browser.IE6==true?document.documentElement.scrollWidth:document.documentElement.clientWidth,
//	cTop: Prototype.Browser.IE6==true?document.documentElement.scrollHeight:document.documentElement.clientHeight,
	open : function (content, event_flag,options ){
		if(Prototype.Browser.IE6){
			this.cLeft=document.documentElement.scrollWidth;
			this.cTop=document.documentElement.scrollHeight;
		}else{
			this.cLeft=document.documentElement.clientWidth;
			this.cTop=document.documentElement.clientHeight;
		}
	    this.bg_options = Object.extend({
	      duration:  0.3,
	      from: 0.0,
	      to:  0.5,
		  backGround: "#FFFFFF",
		  zindex: 99998,
		  left: "0px",
		  top: "0px",
		  contentX : "0px",
		  contentY : "0px",
		  width: "100%",
		  height: document.body.scrollHeight,
		  position : "fixed"
	    }, options || {});
	    $(this.contentDiv).setAttribute("id","ModalContent");
	    $(this.contentDiv).update(content);
		$(this.bgDiv).setStyle({
			height: document.documentElement.scrollHeight+"px",
			width: this.bg_options.width,
			top: this.bg_options.top,
			left: this.bg_options.left,
			zIndex: this.bg_options.zindex,
			background: this.bg_options.backGround,
			position: 'absolute',
			display: 'none'
		});
		document.body.appendChild(this.bgDiv);
		document.body.appendChild(this.contentDiv);
		$(this.contentDiv).setStyle({
			position: Prototype.Browser.IE6==true?'absolute':this.bg_options.position,
			zIndex: 99999,
			'text-align' : 'center'
		});
		//offset 값을 측정하기 위해 top,left값은 나중에 설정
		//$(this.contentDiv).style.left=((this.cLeft/2)-($(this.contentDiv).offsetWidth/2))+"px";
		$(this.contentDiv).setStyle({
			top: ((this.cTop/2)-($(this.contentDiv).offsetHeight/2))+"px",
			left: ((this.cLeft/2)-($(this.contentDiv).offsetWidth/2))+"px"
		});
		//설정된 내용의 좌표값이 있을경우
		if(this.bg_options.contentX!="0px")
			$(this.contentDiv).setStyle({ left : this.bg_options.contentX});
		if(this.bg_options.contentY!="0px")
			$(this.contentDiv).setStyle({ top : this.bg_options.contentY});
		//effects.js가 import 되지 않았을때 동적으로 불러오기
		if(typeof(Effect)=='undefined'){
		     new Include('/commons/js/effects.js', function(){
		     	         var duration	= ModalPopup.bg_options.duration;
		     	         var from		 	= ModalPopup.bg_options.from;
		     	         var to				= ModalPopup.bg_options.to;
		     	         Effect.Appear(ModalPopup.bgDiv, {duration: duration,
																							      from: from,
																							      to:  to,
		     	         													 			afterFinishInternal : function(effect){}
		     	         													 			});
		     });
		}else{
			Effect.Appear(this.bgDiv, {duration: this.bg_options.duration,
			  												  from: this.bg_options.from,
			  												  to: this.bg_options.to,
			  												  afterFinishInternal : function(effect){}
	     	         								  });
		}
		if(event_flag==true ||typeof event_flag=='undefined' )
			Event.observe(this.bgDiv, 'click', this.close);
		//window가 resize 될경우 위치값 및 백그라운드 크기 다시 계산
		window.onresize=function(){
			ModalPopup.resize();
		};
	},
	close : function (flag){
		if(typeof ModalPopup=='undefined' ||  flag=='false'){
			try{
				if(confirm('알림창을 닫으시겠습니까?')){
			    //The first child of the div is the bold element.
					if(ModalPopup.bgDiv.style.display!='none'){
					   document.body.removeChild(ModalPopup.bgDiv);
					   document.body.removeChild(ModalPopup.contentDiv);
					   window.onresize='';
					}else{
						self.close();
					}
				}
		  }catch(x){
		  	alert(x.message);
		    alert("이미 팝업이 닫혀 있습니다!")
		    document.location.reload();
		  }
		}else{
			try{
				if(ModalPopup.bgDiv.style.display!='none'){
					   document.body.removeChild(ModalPopup.bgDiv);
					   document.body.removeChild(ModalPopup.contentDiv);
					   window.onresize='';
				}else{
					self.close();
				}
			}catch(ex){
				alert(x.message);
			    alert("이미 팝업이 닫혀 있습니다!")
			    document.location.reload();
			}
		}
	},
	resize : function(){
		/*
		$(this.bgDiv).setStyle({
			height: document.documentElement.scrollHeight+"px",
		});
		$(this.contentDiv).setStyle({
			top: ((this.cTop/2)-($(this.contentDiv).offsetHeight/2))+"px"
		});
		$(this.contentDiv).style.left=((document.documentElement.clientWidth/2)-($(this.contentDiv).offsetWidth/2))+"px";
		*/
		$(this.bgDiv).setStyle({
			height: screen.availHeight+"px"
		});
		$(this.contentDiv).setStyle({
			top: ((this.cTop/2)-($(this.contentDiv).offsetHeight/2))+"px"
		});
		$(this.contentDiv).style.left=((screen.availWidth/2)-($(this.contentDiv).offsetWidth/2))+"px";
	}
}
function fileSizeError(){
	ModalPopup.open("파일 사이즈가 허용버위(20M)를 벗어났습니다.");
}
//********************************************
// TextArea입력값에 대한 길이를 체크한다.
// 사용법 : checkTextAreaLength(objId, Name, maxLength, lengthLableId)
//********************************************
var db=""; //임시로 입력값을 저장할 변수
function checkTextAreaLength(objId, Name, maxLength, lengthLableId){
	var value = $(objId).value;
	if (db != value)
	{
        var length = calBytes(value);
		// 입력된 길이를 표시한다.
		$(lengthLableId).innerHTML = length;
		if(length > maxLength){
			alert(Name+"은(는) "+maxLength+"bytes까지만 입력하실 수 있습니다.");
			var cutStr = cutByteString(value, maxLength);
			$(objId).value = cutStr;
		}
    	db = value;
    }
    else
    {
    }
    var inputStr = "checkTextAreaLength('"+objId+"', '"+Name+"', "+maxLength+", '"+lengthLableId+"')";
    setTimeout(inputStr, 10);
}
function findIdPasswd(birth,kname,email){
	new Ajax.Request("/FindIdPasswd.do",{
					 parameters : {
						birth : checkNULL(birth),
						kname : checkNULL(kname),
						email : checkNULL(email)
					 },
					 onSuccess: function(result){ModalPopup.open(result.responseText)},
					 onFailure: function(result){alert(result.status+" : "+result.status.Text)}
	});
}
//******************************
// 라디오버튼 선택값 읽기
// 사용방법 $RF('라디오버튼 ID');
// 리턴값 : 선택된 값이 없다면 null OR 선택값 OR 라디오버튼 ID에 해당하는 객체가 없다면 false
//******************************
function getRadioValue(el) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }
    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}
/* check all */
/*
function checkAll(control, check_box){
	try{
		if (check_box) {
			if (check_box.length) {
		        for (i=0;i<check_box.length;i++) {
 		            if (!check_box[i].disabled) {
 		            	check_box[i].checked = control.checked;
 						jQuery(check_box).trigger('updateState');
 		            }
 		        }
			}
			else {
				check_box.checked = control.checked;
				jQuery(check_box).trigger('updateState');
			}
		}
 }catch(ex){alert(ex.message);}
}
*/
/***
 * 이미지 흑백으로 만들기(prototype 사용)
 *  - Usages -
 * var img = $('my-image');
 * img.src = grayscale(img);
 *
 * img.writeAttribute('src', '/images/smail.gif').observe('load', function() {
 * 	img.stopObserve('load').src = grayscale(img);
 * });
 *
 */
function grayscale(img) {
  var width = img.getWidth(), height =  img.getHeight();
  // You'll get some string error if you fail to specify the dimensions
  var canvas = new Element("canvas", {width: width, height: height});
  var context = canvas.getContext("2d");
  context.drawImage(img, 0, 0);
  // This function cannot be called if the image is not rom the same domain.
  // You'll get security error if you do.
  var imgData = context.getImageData(0, 0, width, height);
  // This loop gets every pixels on the image
  for (var x = 0, i; x < width; x++)
    for (var y = 0; y < height; y++)
      imgData.data[(i=x*4+y*4*width)] = imgData.data[i+1] = imgData.data[i+2] =
        (imgData.data[i] + imgData.data[i+1] + imgData.data[i+2]) / 3;
  context.putImageData(imgData, 0, 0, 0, 0, width, height);
  return canvas.toDataURL();
}
//아이디 비밀번호 찾기 레이어
function findIdPwd(){
	jQuery.ajax({
		url: "/FindIdPasswd.do",
		success : function(html){
					ModalPopup.open(html, true, {backGround: '#000'});
				},
		error: function(result){
					alert("조회시 일시적인 문제가 발생하였습니다.\n다시 시도해 주세요.");
				}
	});
	new Ajax.Request("/FindIdPasswd.do",{
		onSuccess : function(result){
					ModalPopup.open(result.responseText, true, {backGround: '#000'});
		},
		onFailure: function(result){alert("조회시 일시적인 문제가 발생하였습니다.\n다시 시도해 주세요.");}
});
}
document.write('<script type="text/javascript" src="/commons/js/commonFunction.js"><\/script>');
