function openCalendar(obj, locale, cal_ymd, cal_type, cal_return_type,format,showLunar){


	    var pass = validateParam(obj, locale, cal_ymd, cal_type, cal_return_type,format);
	    if(!pass){
	    	return;
	    }

		var dateValue = obj.value;		
		
		if(cal_return_type=="L" ){
			dateValue = obj.svalue;
		}
			
		var queryDateStr = getStdDay(dateValue);
		
		if(queryDateStr == "" && cal_ymd){
			queryDateStr = cal_ymd;			
		}
		
		if(!format){
			format="yyyy-mm-dd";			
		}
		
		if(queryDateStr){
			if(queryDateStr.length!=8){
				alert("querydate "+queryDateStr+"is error!");
				return;
			}
		}

		var url = "calendar.nhn?m=viewFrame&returnTfName="+obj.name+"&queryDate="+
		queryDateStr+"&locale="+locale+"&retType="+cal_return_type+"&format="+format+"&showLunar="+showLunar;
		
		//alert("url====="+url);
		
		if(cal_type +"" == "1"){
			url += "&calType="+1;
			loadWindow(url,'calendar',219,250,true);
		}else{
			url += "&calType="+3;
			loadWindow(url,'calendar',610,250,true);			
		}

}

function validateParam(obj, locale, cal_ymd, cal_type, cal_return_type,format){
	var pass = true;
	if(!obj || !obj.name ){
		alert("The first param is error, the input element is not right ");
		pass = false;
	}
	
	var i = 0;
	if(locale){
		 var a = ['KR', 'US', 'CN', 'JP'];
		 for(var i=0; i<a.length; i++){
		 	if(a[i]==locale){
		 		break;
		 	}
		 }
		 if(i==a.length){
		 	alert("The second param must be in ['KR', 'US', 'CN', 'JP']");
		 			pass = false;
		 }
	}else{
		alert("The second param must input");
		pass = false;
	}

	if(cal_ymd){
		if(cal_ymd.length!=8){
			alert("The third param is error, its query day should be formatted ,for example \"yyyymmdd\"");
			pass = false;	
		}
	}
	
	if(cal_type){
		if(cal_type != 1 && cal_type != 3 && cal_type != '1' && cal_type != '3'){
			alert("The fourth param is error, its value should be 1 or 3");
			pass = false;
		}
	}
	
	if(cal_return_type){
		if(cal_return_type != "S" && cal_return_type != "L" ){
			alert("The fifth param is error, its value should be S or L");
			pass = false;					
		}		
		
		if(cal_return_type = "L"  && typeof(obj.svalue)=="undefined"){
			alert("The fifth param is L, then the Input Element of date must have 'svalue' attribute for setting lurar date");
			pass = false;
		}
	}	
	
	if(format){
		if(format.length != 10){
			alert("The sixth param is error, its value should be \"yyyy-mm-dd\" and equeals to 10char  ");	
			pass = false;				
		}
	}		
	return pass;

}

     //42 
    function removeChar(string, char) {
	   	var convString ='';
	   	for (z=0;z<string.length;z++) {
	   		if (string.charAt(z) != char)
	   			convString = convString + string.charAt(z);
	   	}
	   	return convString;
    }
    
    
    //43
    function removeFormat(string) {
   	    result = removeChar(string, ':');
   	    result = removeChar(string, '.');
    	result = removeChar(result, '-');
    	result = removeChar(result, ',');
    	result = removeChar(result, '/');

    	return result;
    }
    

function getStdDay(dateValue){
	if(dateValue){
			//get yyyymmdd date string
			
			dateValue = removeFormat(dateValue);

			return dateValue;
	}
	return "";	
}  

function loadWindow(theURL,winName,theW,theH,showAsModal)
{
  popWin(theURL,winName,theW,theH,showAsModal);
  window.SubWin.opener=this;
}


function popWin(theURL,winName,theW,theH,showAsModal) {
    theTop = (window.screen.height-theH)/2;
    theLeft = (window.screen.width-theW)/2;
    var features = "toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,left=" + theLeft + ",top=" + theTop + ",width=" + theW + ",height=" + theH;
    
    window.SubWin = window.open(theURL,winName,features);
    window.SubWin.focus();
    
    window.onfocus = function(){
        if(window.SubWin && showAsModal){
            if(window.SubWin.closed == true || typeof(window.SubWin.closed) == "undefined"){
	        	//alert("dddd11");
            }else{
	            //alert("dddd222");
                window.SubWin.focus();
            }
        }
    }   
}






