/**
 * Copyright (c) 2006 Neoplus Co.,Ltd. All rights reserved.
 # ==============================================================================================================
 * System Name : LGTELECOM >> OPEN API PORTAL
 * File Name : /api/js/commonFunc.js
 * Developer : suerte (ko hee jung)
 * Date Info : 2007. 08. 31
 # =============================================================================================================
 * Details  : 공통으로 쓰는 자바스크립트 함수들 
 # =============================================================================================================
**/
var CommonFunc = {
  openPopup: function (mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	/*
		status=1 : ie7부터는 상태바가 무조건 나오기 때문에 동일 사이즈를 유지하기 위해 일괄 적용함. 
	*/
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,status=1'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  },
  fncOpenViewPopup : function (objectId){ 
  
  },
  initWindowSize : function () {
		var Width = 300;
		var Height = 300;
		//window.moveTo(0,0);
	
		window.resizeTo(Width,Height); 
		
		var borderWidth = Width-(document.body?document.body.clientWidth:window.innerWidth); 
		var borderHeight = Height-(document.body?document.body.clientHeight:window.innerHeight); 
		
		var docWidth = (document.body?document.body.scrollWidth:document.width);
		var docHeight = (document.body?document.body.scrollHeight:document.height);
		
		var w = docWidth+borderWidth;
		var h = docHeight+borderHeight;

		window.resizeTo(w,h); 
		
		var winPosLeft = (screen.width - w) / 2; // 새창 Y 좌표
		var winPosTop = (screen.height - h) / 2; // 새창 X 좌표
		
		window.moveTo(winPosLeft,winPosTop);
		
		//alert('현재 창 크기 조절 [X:'+w+', Y:'+h+']');
  }, 
   
   goView : function(gurl) // 상세 보기로 이동하기  .. 파라키터 인코딩해서 보내기..
	{
		var url = encodeURI(gurl);
		location.href=url;
	}, 
	
	goPageURL : function(gurl) // 페이징 이동   .. 파라키터 인코딩해서 보내기..
	{
		var url = encodeURI(gurl);
		location.href=url;
	},
	 
  Version: '1.1.0'
}

var FormCheckFunc = {
	_intValue   : '0123456789',
	_upperValue : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
	_lowerValue : 'abcdefghijklmnopqrstuvwxyz',
	_etcValue   : '~`!@#$%%^&*()-_=+\|[{]};:\'\",<.>/?',
	
	//-------------------------------------------------------------------
	// E-MAIL 주소가 올바르게 입력되었는지 check하는 함수
	//-------------------------------------------------------------------
	IsEmailValid : function (email){
		if (
			email.indexOf('@') >= 1 
			&& email.indexOf('@') == email.lastIndexOf('@') 
			&& email.indexOf('.') > 1 
			&& email.indexOf('.') != (email.indexOf('@')+1) 
			&& email.lastIndexOf('.') != (email.length-1) 
			&& email.indexOf(',') == -1 
			&& email.indexOf(' ' ) == -1 
			&& email.indexOf('\t') == -1 
			&& email.indexOf('\n') == -1 
			&& email.indexOf('\r') == -1 
		) 
			return true;
		else return false;
	},
	//-------------------------------------------------------------------
	//	blank check
	//-------------------------------------------------------------------
	isBlank : function(string){   
 		var result = 0;
 		for(var i=0; i<string.length; i++) {
  			if(string.charAt(i)==" ") result++;
 		}
 		return result;
	},
	//-------------------------------------------------------------------
	// 숫자인지  체크하는 함수
	//-------------------------------------------------------------------	
	  isValidNum : function(field, name) {  
	 	var temp; 
	 	for (var i=0; i<field.value.length; i++) { 
	 		temp = '' + field.value.substring(i, i+1); 
	 		if (this._intValue.indexOf(temp) == "-1") {
	 		    alert( name + '란은 숫자로만 입력해 주세요.'); 
	 		    field.focus(); 
	 		    return false; 
	 		}
	   	} 
	   return true; 
	 },

    /**********************************************
     * 함수명 : justNum+.
     * 기    능 : 문자열이 숫자와 마침표로만 구성되었는지 체크
    ***********************************************/
    justip : function (field) 
    { 
        var valid = '0123456789.';
        var temp; 
        for (var i=0; i<field.length; i++) 
        { 
            temp = '' + field.substring(i, i+1); 
            if (valid.indexOf(temp) == "-1") 
            {
            	return false; 
            }
        } 
        return true; 
    },	  
	//-------------------------------------------------------------------
	// ip를 체크하는 함수
	//-------------------------------------------------------------------
	isValidIPchk :  function (comp){
		    var    i, ip;
		    var    str =  new String(comp);
		
			if ((str == '')||(str.length == 0))
		        return true;
		
			splitIP = str.split(".");
		
			// 숫자 사이에 점이 있는지를 체크
			if (splitIP.length == 1){		
				return false;
			// 숫자 사이에 점이 3개만 있는제 체크
			}else if (splitIP.length != 4){	
				return false;
			// IP 각 파트의 길이 체크
			}else if ( (splitIP[0].length == 0) | (splitIP[1].length == 0) | (splitIP[2].length == 0) | (splitIP[3].length == 0) ){
				return false;
			}
			// IP 각 파트의 길이가 3자리 이상인지 체크
			else if ( (splitIP[0].length > 3) | (splitIP[1].length > 3) | (splitIP[2].length > 3) | (splitIP[3].length > 3) ){
				return false;
			}
			// IP의 각 파트가 255를 초과하는지 체크
			else if ( (splitIP[0] > 255)|(splitIP[0]<1) | (splitIP[1] > 255) | (splitIP[2] > 255) | (splitIP[3] > 255) ){
				return false;
			}
			
			else if  (FormCheckFunc.justip(splitIP[0])==false) {return false;}
			else if  (FormCheckFunc.justip(splitIP[1])==false) {return false;}
			else if  (FormCheckFunc.justip(splitIP[2])==false) {return false;}
			else if  (FormCheckFunc.justip(splitIP[3])==false) {return false;}
			else
				return true;								
	},

	// 체크박스에 체크한거 value 반환하기
	returnCheckbox : function ( field ){
		var retVal;
		var tempret = document.getElementsByName(field);
		
		for (var i=0; i<tempret.length;i++){
			if(tempret[i].checked==true){
				retVal=tempret[i].value;
			}
		}
		return retVal;
	},
	
	Version: '1.1.0'
}

var CommonPopup = {

		OnPreview : function () {
			//alert("OnUpdate");
		},
		viewPop : function (){
		
		},			
		OnCancel : function () {
			//alert("OnCancel");
		},
		Version: '1.1.0'
}